shithub: cstory

Download patch

ref: e5caff593c599ab4b07df0df4183d8adc069f77b
parent: 132d3c511072eb4d380c3f5c5c7dd1a7029dbeaf
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Feb 18 15:40:07 EST 2019

Removed the SDL dependency from Draw.h

Should make compiling with VC++ 2003 simpler

--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -1,12 +1,15 @@
+#include "Back.h"
+
+#include <stdio.h>
 #include "WindowsWrapper.h"
 
 #include "Tags.h"
-#include "Back.h"
 #include "Frame.h"
 #include "Game.h"
 #include "Draw.h"
 #include "Stage.h"
 #include "Map.h"
+#include "File.h"
 
 BACK gBack;
 int gWaterY;
@@ -16,21 +19,48 @@
 	//Get width and height
 	char path[PATH_LENGTH];
 	sprintf(path, "%s/%s.pbm", gDataPath, fName);
-	
-	SDL_Surface *temp = SDL_LoadBMP(path);
-	if (!temp)
+
+	FILE *fp = fopen(path, "rb");
+	if (fp == NULL)
 	{
 		sprintf(path, "%s/%s.bmp", gDataPath, fName);
-		temp = SDL_LoadBMP(path);
-		if (!temp)
+		fp = fopen(path, "rb");
+		if (fp == NULL)
 			return false;
 	}
 
-	gBack.partsW = temp->w;
-	gBack.partsH = temp->h;
-	
-	SDL_FreeSurface(temp);
-	
+#ifdef FIX_BUGS	// TODO: Maybe we need a 'BETTER_PORTABILITY' flag
+	if (fgetc(fp) != 'B' || fgetc(fp) != 'M')
+	{
+		fclose(fp);
+		return false;
+	}
+
+	fseek(fp, 18, SEEK_SET);
+
+	gBack.partsW = File_ReadLE32(fp);
+	gBack.partsH = File_ReadLE32(fp);
+	fclose(fp);
+#else
+	// This is ridiculously platform-dependant:
+	// It should break on big-endian CPUs, and platforms
+	// where short isn't 16-bit and long isn't 32-bit.
+	short bmp_header_buffer[7];
+	long bmp_header_buffer2[10];
+
+	fread(bmp_header_buffer, 14, 1, fp);
+
+	// Check if this is a valid bitmap file
+	if (bmp_header_buffer[0] != 0x4D42)	// 'MB' (we use hex to prevent a compiler warning)
+		return false;	// The original game forgets to close fp
+
+	fread(bmp_header_buffer2, 40, 1, fp);
+	fclose(fp);
+
+	gBack.partsW = bmp_header_buffer2[1];
+	gBack.partsH = bmp_header_buffer2[2];
+#endif
+
 	//Set background stuff and load texture
 	gBack.flag = 1;
 	if (!ReloadBitmap_File(fName, SURFACE_ID_LEVEL_BACKGROUND))
--- a/src/Bullet.cpp
+++ b/src/Bullet.cpp
@@ -1,4 +1,7 @@
 #include "Bullet.h"
+
+#include <string.h>
+
 #include "Draw.h"
 #include "Caret.h"
 #include "NpChar.h"
--- a/src/Caret.cpp
+++ b/src/Caret.cpp
@@ -1,8 +1,9 @@
-#include <string>
+#include "Caret.h"
 
+#include <string.h>
+
 #include "WindowsWrapper.h"
 
-#include "Caret.h"
 #include "Draw.h"
 #include "Triangle.h"
 #include "Game.h"
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -27,6 +27,17 @@
 #include "Tags.h"
 #include "Resource.h"
 
+struct SURFACE
+{
+	bool in_use;
+	bool needs_updating;
+	SDL_Surface *surface;
+	SDL_Texture *texture;
+};
+
+SDL_Window *gWindow;
+SDL_Renderer *gRenderer;
+
 RECT grcGame = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -1,11 +1,7 @@
 #pragma once
 #include <stdint.h>
 #include "WindowsWrapper.h"
-#include <SDL_render.h>
 
-extern SDL_Window *gWindow;
-extern SDL_Renderer *gRenderer;
-
 extern RECT grcGame;
 extern RECT grcFull;
 
@@ -48,13 +44,7 @@
 	SURFACE_ID_MAX = 40,
 } Surface_Ids;
 
-struct SURFACE
-{
-	bool in_use;
-	bool needs_updating;
-	SDL_Surface *surface;
-	SDL_Texture *texture;
-};
+struct SURFACE;
 
 extern SURFACE surf[SURFACE_ID_MAX];
 
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -1,11 +1,14 @@
+#include "Ending.h"
+
 #include <stdint.h>
-#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
 #include "Tags.h"
 #include "Generic.h"
-#include "Ending.h"
 #include "Flags.h"
 #include "KeyControl.h"
 #include "Escape.h"
--- a/src/Fade.cpp
+++ b/src/Fade.cpp
@@ -1,4 +1,4 @@
-#include <string>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -21,13 +21,14 @@
 #include "Triangle.h"
 #include "Resource.h"
 
+// These two are defined in Draw.cpp. This is a bit of a hack.
+extern SDL_Window *gWindow;
+extern SDL_Renderer *gRenderer;
+
 char gModulePath[PATH_LENGTH];
 char gDataPath[PATH_LENGTH];
 
 int gJoystickButtonTable[8];
-
-SDL_Window *gWindow;
-SDL_Renderer *gRenderer;
 
 bool gbUseJoystick = false;
 bool bFps = false;
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -1,6 +1,7 @@
 #include <stddef.h>
 #include <stdint.h>
-#include <string>
+#include <stdlib.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/MapName.cpp
+++ b/src/MapName.cpp
@@ -1,5 +1,5 @@
 #include <stdint.h>
-#include <string>
+#include <string.h>
 
 #include "CommonDefines.h"
 #include "MapName.h"
--- a/src/MiniMap.cpp
+++ b/src/MiniMap.cpp
@@ -1,4 +1,5 @@
 #include <stdint.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/MyChar.cpp
+++ b/src/MyChar.cpp
@@ -1,5 +1,5 @@
-#include <string>
 #include <stdint.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -1,3 +1,5 @@
+#include "SDL.h"
+
 #include "Sound.h"
 #include "MyChar.h"
 #include "MycParam.h"
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -1,6 +1,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/Stage.cpp
+++ b/src/Stage.cpp
@@ -1,4 +1,5 @@
 #include <stdint.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "WindowsWrapper.h"
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -1,5 +1,7 @@
 #include <stdint.h>
-#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "WindowsWrapper.h"