shithub: cstory

Download patch

ref: c7da84bb9f531ca5648c725463bc5caef05c5007
parent: e796a55a75d6b4adf5611165e193b14f8ce3c024
author: cuckydev <cuckydev@users.noreply.github.com>
date: Tue Feb 12 15:58:42 EST 2019

accuracy?

--- a/src/Draw.cpp
+++ b/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 @@
 	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 @@
 		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 @@
 			}
 			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 @@
 					}
 					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 @@
 
 	//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 @@
 	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 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 @@
 {
 	//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 @@
 {
 	//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,7 +490,7 @@
 	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;
@@ -452,8 +497,8 @@
 	}
 	else
 	{*/
-		fontWidth = 5 * gWindowScale;
-		fontHeight = 10 * gWindowScale;
+		fontWidth = 5 * magnification;
+		fontHeight = 10 * magnification;
 //	}
 	
 #ifdef WINDOWS
@@ -493,7 +538,7 @@
 	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 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;
 }
 
@@ -512,18 +557,4 @@
 	//Destroy font
 	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);
 }
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -9,9 +9,8 @@
 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 @@
 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);
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -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 @@
 	//Close opened joystick (if exists)
 	if (joystick)
 	{
+		SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
 		SDL_JoystickClose(joystick);
 		joystick = nullptr;
 	}
@@ -25,7 +26,9 @@
 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);
 			
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -26,14 +26,10 @@
 
 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 @@
 	//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 @@
 #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 @@
 		}
 
 		//Get window dimensions and colour depth
-		int colourDepth = 16;
+		int windowWidth;
+		int windowHeight;
+		int colourDepth;
 		
 		switch (config.display_mode)
 		{
@@ -243,16 +241,27 @@
 				//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:
@@ -259,34 +268,42 @@
 			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;
+					//Set colour depth
+					switch (config.display_mode)
+					{
+						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;
 		}
 		
 		//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 @@
 
 			//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 @@
 				EndDirectSound();
 				EndTextObject();
 				EndDirectDraw();
-				
-				SDL_Quit();
 			}
 		}
 	}
 	else
 	{
+		SDL_Quit();
 		return -1;
 	}
 	
+	SDL_Quit();
 	return 0;
 }
 
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -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 @@
 
 bool InitDirectSound()
 {
+	//Init sound
+	SDL_InitSubSystem(SDL_INIT_AUDIO);
+	
+	//Open audio device
 	SDL_AudioSpec want, have;
 	
 	//Set specifications we want
@@ -245,6 +249,9 @@
 
 void EndDirectSound()
 {
+	//Quit sub-system
+	SDL_QuitSubSystem(SDL_INIT_AUDIO);
+	
 	//Close audio device
 	SDL_CloseAudioDevice(audioDevice);
 	
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -959,7 +959,7 @@
 					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'))
 					{
--