From e5caff593c599ab4b07df0df4183d8adc069f77b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 18 Feb 2019 20:40:07 +0000 Subject: [PATCH] Removed the SDL dependency from Draw.h Should make compiling with VC++ 2003 simpler --- src/Back.cpp | 52 ++++++++++++++++++++++++++++++++++++++---------- src/Bullet.cpp | 3 +++ src/Caret.cpp | 5 +++-- src/Draw.cpp | 11 ++++++++++ src/Draw.h | 12 +---------- src/Ending.cpp | 7 +++++-- src/Fade.cpp | 2 +- src/Main.cpp | 7 ++++--- src/Map.cpp | 3 ++- src/MapName.cpp | 2 +- src/MiniMap.cpp | 1 + src/MyChar.cpp | 2 +- src/MycParam.cpp | 2 ++ src/NpChar.cpp | 1 + src/Stage.cpp | 1 + src/TextScr.cpp | 4 +++- 16 files changed, 81 insertions(+), 34 deletions(-) diff --git a/src/Back.cpp b/src/Back.cpp index ab65af7f..bfc3ec5f 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -1,12 +1,15 @@ +#include "Back.h" + +#include #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 @@ bool InitBack(char *fName, int type) //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)) diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 94a4831a..c198a8a9 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -1,4 +1,7 @@ #include "Bullet.h" + +#include + #include "Draw.h" #include "Caret.h" #include "NpChar.h" diff --git a/src/Caret.cpp b/src/Caret.cpp index 55b49c7f..f8b0b563 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -1,8 +1,9 @@ -#include +#include "Caret.h" + +#include #include "WindowsWrapper.h" -#include "Caret.h" #include "Draw.h" #include "Triangle.h" #include "Game.h" diff --git a/src/Draw.cpp b/src/Draw.cpp index 6fbce920..32ee95e2 100644 --- 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}; diff --git a/src/Draw.h b/src/Draw.h index dc834463..48580e57 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -1,10 +1,6 @@ #pragma once #include #include "WindowsWrapper.h" -#include - -extern SDL_Window *gWindow; -extern SDL_Renderer *gRenderer; extern RECT grcGame; extern RECT grcFull; @@ -48,13 +44,7 @@ typedef enum Surface_Ids 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]; diff --git a/src/Ending.cpp b/src/Ending.cpp index 1a045e42..793663f8 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -1,11 +1,14 @@ +#include "Ending.h" + #include -#include +#include +#include +#include #include "WindowsWrapper.h" #include "Tags.h" #include "Generic.h" -#include "Ending.h" #include "Flags.h" #include "KeyControl.h" #include "Escape.h" diff --git a/src/Fade.cpp b/src/Fade.cpp index cb25119d..4c439944 100644 --- a/src/Fade.cpp +++ b/src/Fade.cpp @@ -1,4 +1,4 @@ -#include +#include #include "WindowsWrapper.h" diff --git a/src/Main.cpp b/src/Main.cpp index 49ee65c7..da8b0195 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -21,14 +21,15 @@ #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; diff --git a/src/Map.cpp b/src/Map.cpp index 307297aa..1cf765a3 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include "WindowsWrapper.h" diff --git a/src/MapName.cpp b/src/MapName.cpp index cd9a4842..015d8908 100644 --- a/src/MapName.cpp +++ b/src/MapName.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "CommonDefines.h" #include "MapName.h" diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index f0f03856..e588b26a 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -1,4 +1,5 @@ #include +#include #include "WindowsWrapper.h" diff --git a/src/MyChar.cpp b/src/MyChar.cpp index bb0b0854..4a05c8a0 100644 --- a/src/MyChar.cpp +++ b/src/MyChar.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include "WindowsWrapper.h" diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 3918f6ca..c02db6ea 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -1,3 +1,5 @@ +#include "SDL.h" + #include "Sound.h" #include "MyChar.h" #include "MycParam.h" diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 6f3d6907..a34c7835 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "WindowsWrapper.h" diff --git a/src/Stage.cpp b/src/Stage.cpp index 70abc405..425057ca 100644 --- a/src/Stage.cpp +++ b/src/Stage.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "WindowsWrapper.h" diff --git a/src/TextScr.cpp b/src/TextScr.cpp index e8050bae..6cd68665 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -1,5 +1,7 @@ #include -#include +#include +#include +#include #include "WindowsWrapper.h"