accuracy?

This commit is contained in:
cuckydev 2019-02-12 20:58:42 -05:00
parent e796a55a75
commit c7da84bb9f
6 changed files with 130 additions and 73 deletions

View file

@ -30,6 +30,9 @@
RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
int magnification;
bool fullscreen;
SURFACE surf[SURFACE_ID_MAX]; SURFACE surf[SURFACE_ID_MAX];
FontObject *gFont; FontObject *gFont;
@ -64,6 +67,48 @@ bool Flip_SystemTask()
return true; return true;
} }
bool StartDirectDraw(int lMagnification, int lColourDepth)
{
//Initialize rendering
SDL_InitSubSystem(SDL_INIT_VIDEO);
//Create renderer
if (gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED))
{
switch (lMagnification)
{
case 0:
magnification = 1;
fullscreen = false;
break;
case 1:
magnification = 2;
fullscreen = false;
break;
case 2:
magnification = 2;
fullscreen = true;
SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN);
break;
}
}
return true;
}
void EndDirectDraw()
{
//Quit sub-system
SDL_QuitSubSystem(SDL_INIT_VIDEO);
//Release all surfaces
for (int i = 0; i < SURFACE_ID_MAX; i++)
ReleaseSurface(i);
}
static bool IsEnableBitmap(SDL_RWops *fp) static bool IsEnableBitmap(SDL_RWops *fp)
{ {
char str[16]; char str[16];
@ -109,7 +154,7 @@ bool MakeSurface_Generic(int bxsize, int bysize, int surf_no)
else else
{ {
//Create surface //Create surface
surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * gWindowScale, bysize * gWindowScale, 0, SDL_PIXELFORMAT_RGBA32); surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * magnification, bysize * magnification, 0, SDL_PIXELFORMAT_RGBA32);
if (surf[surf_no].surface == NULL) if (surf[surf_no].surface == NULL)
{ {
@ -117,7 +162,7 @@ bool MakeSurface_Generic(int bxsize, int bysize, int surf_no)
} }
else else
{ {
surf[surf_no].texture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, bxsize * gWindowScale, bysize * gWindowScale); surf[surf_no].texture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, bxsize * magnification, bysize * magnification);
if (surf[surf_no].texture == NULL) if (surf[surf_no].texture == NULL)
{ {
@ -197,7 +242,7 @@ static bool LoadBitmap(SDL_RWops *fp, int surf_no, bool create_surface)
} }
else else
{ {
SDL_Rect dst_rect = {0, 0, converted_surface->w * gWindowScale, converted_surface->h * gWindowScale}; SDL_Rect dst_rect = {0, 0, converted_surface->w * magnification, converted_surface->h * magnification};
SDL_BlitScaled(converted_surface, NULL, surf[surf_no].surface, &dst_rect); SDL_BlitScaled(converted_surface, NULL, surf[surf_no].surface, &dst_rect);
SDL_FreeSurface(converted_surface); SDL_FreeSurface(converted_surface);
surf[surf_no].needs_updating = true; surf[surf_no].needs_updating = true;
@ -307,7 +352,7 @@ void BackupSurface(int surf_no, RECT *rect)
//Get rects //Get rects
SDL_Rect frameRect = RectToSDLRect(rect); SDL_Rect frameRect = RectToSDLRect(rect);
frameRect = {frameRect.x * gWindowScale, frameRect.y * gWindowScale, frameRect.w * gWindowScale, frameRect.h * gWindowScale}; frameRect = {frameRect.x * magnification, frameRect.y * magnification, frameRect.w * magnification, frameRect.h * magnification};
SDL_BlitSurface(surface, &frameRect, surf[surf_no].surface, &frameRect); SDL_BlitSurface(surface, &frameRect, surf[surf_no].surface, &frameRect);
surf[surf_no].needs_updating = true; surf[surf_no].needs_updating = true;
@ -328,13 +373,13 @@ static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, int surf_no, bool
SDL_Rect clipRect = RectToSDLRect(rcView); SDL_Rect clipRect = RectToSDLRect(rcView);
SDL_Rect frameRect = RectToSDLRect(rect); SDL_Rect frameRect = RectToSDLRect(rect);
frameRect = {frameRect.x * gWindowScale, frameRect.y * gWindowScale, frameRect.w * gWindowScale, frameRect.h * gWindowScale}; frameRect = {frameRect.x * magnification, frameRect.y * magnification, frameRect.w * magnification, frameRect.h * magnification};
//Get dest rect //Get dest rect
SDL_Rect destRect = {x * gWindowScale, y * gWindowScale, frameRect.w, frameRect.h}; SDL_Rect destRect = {x * magnification, y * magnification, frameRect.w, frameRect.h};
//Set cliprect //Set cliprect
clipRect = {clipRect.x * gWindowScale, clipRect.y * gWindowScale, clipRect.w * gWindowScale, clipRect.h * gWindowScale}; clipRect = {clipRect.x * magnification, clipRect.y * magnification, clipRect.w * magnification, clipRect.h * magnification};
SDL_RenderSetClipRect(gRenderer, &clipRect); SDL_RenderSetClipRect(gRenderer, &clipRect);
SDL_SetTextureBlendMode(surf[surf_no].texture, transparent ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE); SDL_SetTextureBlendMode(surf[surf_no].texture, transparent ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE);
@ -360,9 +405,9 @@ void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, int surf_no) //No Transp
void Surface2Surface(int x, int y, RECT *rect, int to, int from) void Surface2Surface(int x, int y, RECT *rect, int to, int from)
{ {
//Get rects //Get rects
SDL_Rect rcSet = {x * gWindowScale, y * gWindowScale, (rect->right - rect->left) * gWindowScale, (rect->bottom - rect->top) * gWindowScale}; SDL_Rect rcSet = {x * magnification, y * magnification, (rect->right - rect->left) * magnification, (rect->bottom - rect->top) * magnification};
SDL_Rect frameRect = RectToSDLRect(rect); SDL_Rect frameRect = RectToSDLRect(rect);
frameRect = {frameRect.x * gWindowScale, frameRect.y * gWindowScale, frameRect.w * gWindowScale, frameRect.h * gWindowScale}; frameRect = {frameRect.x * magnification, frameRect.y * magnification, frameRect.w * magnification, frameRect.h * magnification};
SDL_BlitSurface(surf[from].surface, &frameRect, surf[to].surface, &rcSet); SDL_BlitSurface(surf[from].surface, &frameRect, surf[to].surface, &rcSet);
surf[to].needs_updating = true; surf[to].needs_updating = true;
@ -372,7 +417,7 @@ void CortBox(RECT *rect, uint32_t col)
{ {
//Get rect //Get rect
SDL_Rect destRect = RectToSDLRect(rect); SDL_Rect destRect = RectToSDLRect(rect);
destRect = {destRect.x * gWindowScale, destRect.y * gWindowScale, destRect.w * gWindowScale, destRect.h * gWindowScale}; destRect = {destRect.x * magnification, destRect.y * magnification, destRect.w * magnification, destRect.h * magnification};
//Set colour and draw //Set colour and draw
SDL_SetRenderDrawColor(gRenderer, (col & 0xFF0000) >> 16, (col & 0x00FF00) >> 8, col & 0x0000FF, 0xFF); SDL_SetRenderDrawColor(gRenderer, (col & 0xFF0000) >> 16, (col & 0x00FF00) >> 8, col & 0x0000FF, 0xFF);
@ -383,7 +428,7 @@ void CortBox2(RECT *rect, uint32_t col, int surf_no)
{ {
//Get rect //Get rect
SDL_Rect destRect = RectToSDLRect(rect); SDL_Rect destRect = RectToSDLRect(rect);
destRect = {destRect.x * gWindowScale, destRect.y * gWindowScale, destRect.w * gWindowScale, destRect.h * gWindowScale}; destRect = {destRect.x * magnification, destRect.y * magnification, destRect.w * magnification, destRect.h * magnification};
const unsigned char col_red = (col & 0xFF0000) >> 16; const unsigned char col_red = (col & 0xFF0000) >> 16;
const unsigned char col_green = (col & 0x00FF00) >> 8; const unsigned char col_green = (col & 0x00FF00) >> 8;
@ -445,15 +490,15 @@ void InitTextObject(const char *font_name)
unsigned int fontWidth, fontHeight; unsigned int fontWidth, fontHeight;
// The original did this, but Windows would downscale it to 5/10 anyway. // The original did this, but Windows would downscale it to 5/10 anyway.
/* if (gWindowScale == 1) /* if (magnification == 1)
{ {
fontWidth = 6; fontWidth = 6;
fontHeight = 12; fontHeight = 12;
} }
else else
{*/ {*/
fontWidth = 5 * gWindowScale; fontWidth = 5 * magnification;
fontHeight = 10 * gWindowScale; fontHeight = 10 * magnification;
// } // }
#ifdef WINDOWS #ifdef WINDOWS
@ -493,7 +538,7 @@ void PutText(int x, int y, const char *text, uint32_t color)
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGBA32); SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGBA32);
SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGBA32, surface->pixels, surface->pitch); SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGBA32, surface->pixels, surface->pitch);
DrawText(gFont, surface, x * gWindowScale, y * gWindowScale, color, text, strlen(text)); DrawText(gFont, surface, x * magnification, y * magnification, color, text, strlen(text));
SDL_Texture *screen_texture = SDL_CreateTextureFromSurface(gRenderer, surface); SDL_Texture *screen_texture = SDL_CreateTextureFromSurface(gRenderer, surface);
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
@ -503,7 +548,7 @@ void PutText(int x, int y, const char *text, uint32_t color)
void PutText2(int x, int y, const char *text, uint32_t color, int surf_no) void PutText2(int x, int y, const char *text, uint32_t color, int surf_no)
{ {
DrawText(gFont, surf[surf_no].surface, x * gWindowScale, y * gWindowScale, color, text, strlen(text)); DrawText(gFont, surf[surf_no].surface, x * magnification, y * magnification, color, text, strlen(text));
surf[surf_no].needs_updating = true; surf[surf_no].needs_updating = true;
} }
@ -513,17 +558,3 @@ void EndTextObject()
UnloadFont(gFont); UnloadFont(gFont);
gFont = nullptr; gFont = nullptr;
} }
bool StartDirectDraw()
{
//Create renderer
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
return true;
}
void EndDirectDraw()
{
//Release all surfaces
for (int i = 0; i < SURFACE_ID_MAX; i++)
ReleaseSurface(i);
}

View file

@ -9,9 +9,8 @@ extern SDL_Renderer *gRenderer;
extern RECT grcGame; extern RECT grcGame;
extern RECT grcFull; extern RECT grcFull;
extern int gWindowWidth; extern int magnification;
extern int gWindowHeight; extern bool fullscreen;
extern int gWindowScale;
enum Surface_Ids enum Surface_Ids
{ {
@ -54,7 +53,7 @@ struct SURFACE
extern SURFACE surf[SURFACE_ID_MAX]; extern SURFACE surf[SURFACE_ID_MAX];
bool Flip_SystemTask(); bool Flip_SystemTask();
bool StartDirectDraw(); bool StartDirectDraw(int lMagnification, int lColourDepth);
void EndDirectDraw(); void EndDirectDraw();
void ReleaseSurface(int s); void ReleaseSurface(int s);
bool MakeSurface(SDL_RWops *rw, int surf_no); bool MakeSurface(SDL_RWops *rw, int surf_no);

View file

@ -2,13 +2,13 @@
#include "CommonDefines.h" #include "CommonDefines.h"
#include <stdint.h> #include <stdint.h>
#include <SDL_gamecontroller.h> #include <SDL.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Input.h" #include "Input.h"
#include "Tags.h" #include "Tags.h"
#define JOYSTICK_DEADZONE 0x2000 #define JOYSTICK_DEADZONE 10000
SDL_Joystick *joystick; //This may be a name that was given by Simon, but it fits the rest of Pixel's names so it's fine. SDL_Joystick *joystick; //This may be a name that was given by Simon, but it fits the rest of Pixel's names so it's fine.
@ -17,6 +17,7 @@ void ReleaseDirectInput()
//Close opened joystick (if exists) //Close opened joystick (if exists)
if (joystick) if (joystick)
{ {
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
joystick = nullptr; joystick = nullptr;
} }
@ -25,7 +26,9 @@ void ReleaseDirectInput()
bool InitDirectInput() bool InitDirectInput()
{ {
//Open first available joystick //Open first available joystick
for (int i = 0; i < SDL_NumJoysticks(); ++i) SDL_InitSubSystem(SDL_INIT_JOYSTICK);
for (int i = 0; i < SDL_NumJoysticks(); i++)
{ {
joystick = SDL_JoystickOpen(i); joystick = SDL_JoystickOpen(i);

View file

@ -26,14 +26,10 @@ char gDataPath[PATH_LENGTH];
int gJoystickButtonTable[8]; int gJoystickButtonTable[8];
int gWindowWidth;
int gWindowHeight;
int gWindowScale;
SDL_Window *gWindow; SDL_Window *gWindow;
SDL_Renderer *gRenderer; SDL_Renderer *gRenderer;
bool gbUseJoystick = false; bool gbUseJoystick = false;
bool bFullscreen = false;
bool bFps = false; bool bFps = false;
bool bActive = true; bool bActive = true;
@ -97,7 +93,7 @@ int main(int argc, char *argv[])
//Get executable's path //Get executable's path
strcpy(gModulePath, SDL_GetBasePath()); strcpy(gModulePath, SDL_GetBasePath());
if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\') if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\')
gModulePath[strlen(gModulePath) - 1] = 0; //String cannot end in slash or stuff will probably break (original does this through a windows.h provided function) gModulePath[strlen(gModulePath) - 1] = '\0'; //String cannot end in slash or stuff will probably break (original does this through a windows.h provided function)
//Get path of the data folder //Get path of the data folder
strcpy(gDataPath, gModulePath); strcpy(gDataPath, gModulePath);
@ -110,7 +106,7 @@ int main(int argc, char *argv[])
#endif #endif
//Initialize SDL //Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER) >= 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) >= 0)
{ {
//Load configuration //Load configuration
CONFIG config; CONFIG config;
@ -234,7 +230,9 @@ int main(int argc, char *argv[])
} }
//Get window dimensions and colour depth //Get window dimensions and colour depth
int colourDepth = 16; int windowWidth;
int windowHeight;
int colourDepth;
switch (config.display_mode) switch (config.display_mode)
{ {
@ -243,50 +241,69 @@ int main(int argc, char *argv[])
//Set window dimensions //Set window dimensions
if (config.display_mode == 1) if (config.display_mode == 1)
{ {
gWindowWidth = WINDOW_WIDTH; windowWidth = WINDOW_WIDTH;
gWindowHeight = WINDOW_HEIGHT; windowHeight = WINDOW_HEIGHT;
gWindowScale = 1;
} }
else else
{ {
gWindowWidth = WINDOW_WIDTH * 2; windowWidth = WINDOW_WIDTH * 2;
gWindowHeight = WINDOW_HEIGHT * 2; windowHeight = WINDOW_HEIGHT * 2;
gWindowScale = 2;
} }
//Create window
gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
if (gWindow)
{
if (config.display_mode == 1)
StartDirectDraw(0, 0);
else
StartDirectDraw(1, 0);
break;
}
break; break;
case 0: case 0:
case 3: case 3:
case 4: case 4:
//Set window dimensions //Set window dimensions
gWindowWidth = WINDOW_WIDTH * 2; windowWidth = WINDOW_WIDTH * 2;
gWindowHeight = WINDOW_HEIGHT * 2; windowHeight = WINDOW_HEIGHT * 2;
gWindowScale = 2;
//Set colour depth //Create window
if (config.display_mode) gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
if (gWindow)
{ {
if (config.display_mode == 3) //Set colour depth
colourDepth = 24; switch (config.display_mode)
else if (config.display_mode == 4) {
colourDepth = 32; case 0:
colourDepth = 16;
break;
case 3:
colourDepth = 24;
break;
case 4:
colourDepth = 32;
break;
}
StartDirectDraw(2, colourDepth);
fullscreen = true;
SDL_ShowCursor(0);
break;
} }
else
colourDepth = 16;
bFullscreen = true;
SDL_ShowCursor(0);
break; break;
} }
//Create window //Create window
gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, gWindowWidth, gWindowHeight, bFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
if (gWindow) if (gWindow)
{ {
//Initialize rendering
StartDirectDraw();
//Check debug things //Check debug things
if (CheckFileExists("fps")) if (CheckFileExists("fps"))
bFps = true; bFps = true;
@ -314,7 +331,7 @@ int main(int argc, char *argv[])
//Set rects //Set rects
RECT loading_rect = {0, 0, 64, 8}; RECT loading_rect = {0, 0, 64, 8};
RECT clip_rect = {0, 0, gWindowWidth, gWindowHeight}; RECT clip_rect = {0, 0, windowWidth, windowHeight};
//Load the "LOADING" text //Load the "LOADING" text
MakeSurface_File("Loading", SURFACE_ID_LOADING); MakeSurface_File("Loading", SURFACE_ID_LOADING);
@ -347,16 +364,16 @@ int main(int argc, char *argv[])
EndDirectSound(); EndDirectSound();
EndTextObject(); EndTextObject();
EndDirectDraw(); EndDirectDraw();
SDL_Quit();
} }
} }
} }
else else
{ {
SDL_Quit();
return -1; return -1;
} }
SDL_Quit();
return 0; return 0;
} }

View file

@ -3,7 +3,7 @@
#include <algorithm> #include <algorithm>
#include <stdint.h> #include <stdint.h>
#include <SDL_audio.h> #include <SDL.h>
#include "Sound.h" #include "Sound.h"
#include "Organya.h" #include "Organya.h"
@ -217,6 +217,10 @@ SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
bool InitDirectSound() bool InitDirectSound()
{ {
//Init sound
SDL_InitSubSystem(SDL_INIT_AUDIO);
//Open audio device
SDL_AudioSpec want, have; SDL_AudioSpec want, have;
//Set specifications we want //Set specifications we want
@ -245,6 +249,9 @@ bool InitDirectSound()
void EndDirectSound() void EndDirectSound()
{ {
//Quit sub-system
SDL_QuitSubSystem(SDL_INIT_AUDIO);
//Close audio device //Close audio device
SDL_CloseAudioDevice(audioDevice); SDL_CloseAudioDevice(audioDevice);

View file

@ -959,7 +959,7 @@ int TextScriptProc()
else if (IS_COMMAND('S','P','S')) else if (IS_COMMAND('S','P','S'))
{ {
SetNoise(2, x); SetNoise(2, x);
gTS.p_read += 8; gTS.p_read += 4;
} }
else if (IS_COMMAND('C','P','S')) else if (IS_COMMAND('C','P','S'))
{ {