accuracy?
This commit is contained in:
parent
e796a55a75
commit
c7da84bb9f
6 changed files with 130 additions and 73 deletions
91
src/Draw.cpp
91
src/Draw.cpp
|
@ -30,6 +30,9 @@
|
|||
RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
|
||||
RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
|
||||
|
||||
int magnification;
|
||||
bool fullscreen;
|
||||
|
||||
SURFACE surf[SURFACE_ID_MAX];
|
||||
|
||||
FontObject *gFont;
|
||||
|
@ -64,6 +67,48 @@ bool Flip_SystemTask()
|
|||
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)
|
||||
{
|
||||
char str[16];
|
||||
|
@ -109,7 +154,7 @@ bool MakeSurface_Generic(int bxsize, int bysize, int surf_no)
|
|||
else
|
||||
{
|
||||
//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)
|
||||
{
|
||||
|
@ -117,7 +162,7 @@ bool MakeSurface_Generic(int bxsize, int bysize, int surf_no)
|
|||
}
|
||||
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)
|
||||
{
|
||||
|
@ -197,7 +242,7 @@ static bool LoadBitmap(SDL_RWops *fp, int surf_no, bool create_surface)
|
|||
}
|
||||
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_FreeSurface(converted_surface);
|
||||
surf[surf_no].needs_updating = true;
|
||||
|
@ -307,7 +352,7 @@ void BackupSurface(int surf_no, RECT *rect)
|
|||
|
||||
//Get rects
|
||||
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);
|
||||
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 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
|
||||
SDL_Rect destRect = {x * gWindowScale, y * gWindowScale, frameRect.w, frameRect.h};
|
||||
SDL_Rect destRect = {x * magnification, y * magnification, frameRect.w, frameRect.h};
|
||||
|
||||
//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_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)
|
||||
{
|
||||
//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);
|
||||
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);
|
||||
surf[to].needs_updating = true;
|
||||
|
@ -372,7 +417,7 @@ void CortBox(RECT *rect, uint32_t col)
|
|||
{
|
||||
//Get 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
|
||||
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
|
||||
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_green = (col & 0x00FF00) >> 8;
|
||||
|
@ -445,15 +490,15 @@ void InitTextObject(const char *font_name)
|
|||
unsigned int fontWidth, fontHeight;
|
||||
|
||||
// The original did this, but Windows would downscale it to 5/10 anyway.
|
||||
/* if (gWindowScale == 1)
|
||||
/* if (magnification == 1)
|
||||
{
|
||||
fontWidth = 6;
|
||||
fontHeight = 12;
|
||||
}
|
||||
else
|
||||
{*/
|
||||
fontWidth = 5 * gWindowScale;
|
||||
fontHeight = 10 * gWindowScale;
|
||||
fontWidth = 5 * magnification;
|
||||
fontHeight = 10 * magnification;
|
||||
// }
|
||||
|
||||
#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_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_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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -513,17 +558,3 @@ void EndTextObject()
|
|||
UnloadFont(gFont);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ extern SDL_Renderer *gRenderer;
|
|||
extern RECT grcGame;
|
||||
extern RECT grcFull;
|
||||
|
||||
extern int gWindowWidth;
|
||||
extern int gWindowHeight;
|
||||
extern int gWindowScale;
|
||||
extern int magnification;
|
||||
extern bool fullscreen;
|
||||
|
||||
enum Surface_Ids
|
||||
{
|
||||
|
@ -54,7 +53,7 @@ struct SURFACE
|
|||
extern SURFACE surf[SURFACE_ID_MAX];
|
||||
|
||||
bool Flip_SystemTask();
|
||||
bool StartDirectDraw();
|
||||
bool StartDirectDraw(int lMagnification, int lColourDepth);
|
||||
void EndDirectDraw();
|
||||
void ReleaseSurface(int s);
|
||||
bool MakeSurface(SDL_RWops *rw, int surf_no);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#include "CommonDefines.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include <SDL_gamecontroller.h>
|
||||
#include <SDL.h>
|
||||
#include "WindowsWrapper.h"
|
||||
|
||||
#include "Input.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.
|
||||
|
||||
|
@ -17,6 +17,7 @@ void ReleaseDirectInput()
|
|||
//Close opened joystick (if exists)
|
||||
if (joystick)
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = nullptr;
|
||||
}
|
||||
|
@ -25,7 +26,9 @@ void ReleaseDirectInput()
|
|||
bool InitDirectInput()
|
||||
{
|
||||
//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);
|
||||
|
||||
|
|
81
src/Main.cpp
81
src/Main.cpp
|
@ -26,14 +26,10 @@ char gDataPath[PATH_LENGTH];
|
|||
|
||||
int gJoystickButtonTable[8];
|
||||
|
||||
int gWindowWidth;
|
||||
int gWindowHeight;
|
||||
int gWindowScale;
|
||||
SDL_Window *gWindow;
|
||||
SDL_Renderer *gRenderer;
|
||||
|
||||
bool gbUseJoystick = false;
|
||||
bool bFullscreen = false;
|
||||
bool bFps = false;
|
||||
|
||||
bool bActive = true;
|
||||
|
@ -97,7 +93,7 @@ int main(int argc, char *argv[])
|
|||
//Get executable's path
|
||||
strcpy(gModulePath, SDL_GetBasePath());
|
||||
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
|
||||
strcpy(gDataPath, gModulePath);
|
||||
|
@ -110,7 +106,7 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
//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
|
||||
CONFIG config;
|
||||
|
@ -234,7 +230,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
//Get window dimensions and colour depth
|
||||
int colourDepth = 16;
|
||||
int windowWidth;
|
||||
int windowHeight;
|
||||
int colourDepth;
|
||||
|
||||
switch (config.display_mode)
|
||||
{
|
||||
|
@ -243,50 +241,69 @@ int main(int argc, char *argv[])
|
|||
//Set window dimensions
|
||||
if (config.display_mode == 1)
|
||||
{
|
||||
gWindowWidth = WINDOW_WIDTH;
|
||||
gWindowHeight = WINDOW_HEIGHT;
|
||||
gWindowScale = 1;
|
||||
windowWidth = WINDOW_WIDTH;
|
||||
windowHeight = WINDOW_HEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
gWindowWidth = WINDOW_WIDTH * 2;
|
||||
gWindowHeight = WINDOW_HEIGHT * 2;
|
||||
gWindowScale = 2;
|
||||
windowWidth = WINDOW_WIDTH * 2;
|
||||
windowHeight = WINDOW_HEIGHT * 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;
|
||||
|
||||
case 0:
|
||||
case 3:
|
||||
case 4:
|
||||
//Set window dimensions
|
||||
gWindowWidth = WINDOW_WIDTH * 2;
|
||||
gWindowHeight = WINDOW_HEIGHT * 2;
|
||||
gWindowScale = 2;
|
||||
windowWidth = WINDOW_WIDTH * 2;
|
||||
windowHeight = WINDOW_HEIGHT * 2;
|
||||
|
||||
//Set colour depth
|
||||
if (config.display_mode)
|
||||
//Create window
|
||||
gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
|
||||
|
||||
if (gWindow)
|
||||
{
|
||||
if (config.display_mode == 3)
|
||||
colourDepth = 24;
|
||||
else if (config.display_mode == 4)
|
||||
colourDepth = 32;
|
||||
}
|
||||
else
|
||||
//Set colour depth
|
||||
switch (config.display_mode)
|
||||
{
|
||||
case 0:
|
||||
colourDepth = 16;
|
||||
break;
|
||||
case 3:
|
||||
colourDepth = 24;
|
||||
break;
|
||||
case 4:
|
||||
colourDepth = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
bFullscreen = true;
|
||||
StartDirectDraw(2, colourDepth);
|
||||
|
||||
fullscreen = true;
|
||||
SDL_ShowCursor(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Create window
|
||||
gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, gWindowWidth, gWindowHeight, bFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
|
||||
|
||||
|
||||
if (gWindow)
|
||||
{
|
||||
//Initialize rendering
|
||||
StartDirectDraw();
|
||||
|
||||
//Check debug things
|
||||
if (CheckFileExists("fps"))
|
||||
bFps = true;
|
||||
|
@ -314,7 +331,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
//Set rects
|
||||
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
|
||||
MakeSurface_File("Loading", SURFACE_ID_LOADING);
|
||||
|
@ -347,16 +364,16 @@ int main(int argc, char *argv[])
|
|||
EndDirectSound();
|
||||
EndTextObject();
|
||||
EndDirectDraw();
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Quit();
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <algorithm>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <SDL_audio.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "Sound.h"
|
||||
#include "Organya.h"
|
||||
|
@ -217,6 +217,10 @@ SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
|
|||
|
||||
bool InitDirectSound()
|
||||
{
|
||||
//Init sound
|
||||
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
||||
|
||||
//Open audio device
|
||||
SDL_AudioSpec want, have;
|
||||
|
||||
//Set specifications we want
|
||||
|
@ -245,6 +249,9 @@ bool InitDirectSound()
|
|||
|
||||
void EndDirectSound()
|
||||
{
|
||||
//Quit sub-system
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
|
||||
//Close audio device
|
||||
SDL_CloseAudioDevice(audioDevice);
|
||||
|
||||
|
|
|
@ -959,7 +959,7 @@ int TextScriptProc()
|
|||
else if (IS_COMMAND('S','P','S'))
|
||||
{
|
||||
SetNoise(2, x);
|
||||
gTS.p_read += 8;
|
||||
gTS.p_read += 4;
|
||||
}
|
||||
else if (IS_COMMAND('C','P','S'))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue