shithub: cstory

Download patch

ref: d2b5872c95e7c0970fdf81e16397ab497763b89b
parent: 5933a1201e25ab2eff8e32a1a241b8429f8ebce9
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri May 24 06:07:30 EDT 2019

Weeded out some bool usage

Cave Story was written in C89. No bools. I've left in Sound.cpp's
though, since that's written in C++98 currently.

--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -250,7 +250,7 @@
 	// Draw black bars
 	if (!(g_GameFlags & 8)) // Detect if credits are running
 	{
-		const bool fromFocus = (gStageNo == 31); // Get if we should only draw around a 320x240 area of the focus point
+		const BOOL fromFocus = (gStageNo == 31); // Get if we should only draw around a 320x240 area of the focus point
 
 		// Get focus rect
 		int focusX = gFrame.x + (WINDOW_WIDTH << 8) - (320 << 8);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -30,8 +30,8 @@
 
 struct SURFACE
 {
-	bool in_use;
-	bool needs_updating;
+	BOOL in_use;
+	BOOL needs_updating;
 	SDL_Surface *surface;
 	SDL_Texture *texture;
 };
@@ -43,7 +43,7 @@
 RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 
 int magnification;
-bool fullscreen;
+BOOL fullscreen;
 
 SURFACE surf[SURFACE_ID_MAX];
 
@@ -55,7 +55,7 @@
 {
 	(void)hWnd;
 
-	while (true)
+	while (TRUE)
 	{
 		if (!SystemTask())
 			return FALSE;
@@ -102,17 +102,17 @@
 		{
 			case 0:
 				magnification = 1;
-				fullscreen = false;
+				fullscreen = FALSE;
 				break;
 
 			case 1:
 				magnification = 2;
-				fullscreen = false;
+				fullscreen = FALSE;
 				break;
 
 			case 2:
 				magnification = 2;
-				fullscreen = true;
+				fullscreen = TRUE;
 				SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN);
 				break;
 		}
@@ -132,7 +132,7 @@
 		ReleaseSurface(i);
 }
 
-static bool IsEnableBitmap(SDL_RWops *fp)
+static BOOL IsEnableBitmap(SDL_RWops *fp)
 {
 	char str[16];
 	const char *extra_text = "(C)Pixel";
@@ -152,7 +152,7 @@
 	{
 		SDL_DestroyTexture(surf[s].texture);
 		SDL_FreeSurface(surf[s].surface);
-		surf[s].in_use = false;
+		surf[s].in_use = FALSE;
 	}
 }
 
@@ -172,7 +172,7 @@
 	}
 	else
 	{
-		if (surf[surf_no].in_use == true)
+		if (surf[surf_no].in_use == TRUE)
 		{
 			printf("Tried to create drawable surface at occupied slot (%d)\n", surf_no);
 		}
@@ -197,7 +197,7 @@
 				}
 				else
 				{
-					surf[surf_no].in_use = true;
+					surf[surf_no].in_use = TRUE;
 					success = TRUE;
 				}
 			}
@@ -234,9 +234,9 @@
 	SDL_UnlockTexture(surf[surf_no].texture);
 }
 
-static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface)
 {
-	bool success = false;
+	BOOL success = FALSE;
 
 	if (surf_no >= SURFACE_ID_MAX)
 	{
@@ -258,15 +258,15 @@
 			}
 			else
 			{
-				if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE))
+				if (create_surface == FALSE || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE))
 				{
 					if (magnification == 1)
 					{
 						SDL_Rect dst_rect = {0, 0, surface->w, surface->h};
 						SDL_BlitSurface(surface, NULL, surf[surf_no].surface, &dst_rect);
-						surf[surf_no].needs_updating = true;
+						surf[surf_no].needs_updating = TRUE;
 						printf(" ^ Successfully loaded\n");
-						success = true;
+						success = TRUE;
 					}
 					else
 					{
@@ -304,9 +304,9 @@
 							}
 
 							SDL_FreeSurface(converted_surface);
-							surf[surf_no].needs_updating = true;
+							surf[surf_no].needs_updating = TRUE;
 							printf(" ^ Successfully loaded\n");
-							success = true;
+							success = TRUE;
 						}
 					}
 				}
@@ -321,7 +321,7 @@
 	return success;
 }
 
-static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, BOOL create_surface)
 {
 	char path[PATH_LENGTH];
 	SDL_RWops *fp;
@@ -358,7 +358,7 @@
 	return FALSE;
 }
 
-static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, BOOL create_surface)
 {
 	size_t size;
 	const unsigned char *data = FindResource(res, "BITMAP", &size);
@@ -381,22 +381,22 @@
 
 BOOL MakeSurface_File(const char *name, Surface_Ids surf_no)
 {
-	return LoadBitmap_File(name, surf_no, true);
+	return LoadBitmap_File(name, surf_no, TRUE);
 }
 
 BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no)
 {
-	return LoadBitmap_Resource(res, surf_no, true);
+	return LoadBitmap_Resource(res, surf_no, TRUE);
 }
 
 BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no)
 {
-	return LoadBitmap_File(name, surf_no, false);
+	return LoadBitmap_File(name, surf_no, FALSE);
 }
 
 BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no)
 {
-	return LoadBitmap_Resource(res, surf_no, false);
+	return LoadBitmap_Resource(res, surf_no, FALSE);
 }
 
 static SDL_Rect RectToSDLRect(RECT *rect)
@@ -434,18 +434,18 @@
 	SDL_Rect frameRect = RectToSDLRectScaled(rect);
 
 	SDL_BlitSurface(surface, &frameRect, surf[surf_no].surface, &frameRect);
-	surf[surf_no].needs_updating = true;
+	surf[surf_no].needs_updating = TRUE;
 
 	// Free surface
 	SDL_FreeSurface(surface);
 }
 
-static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no, bool transparent)
+static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no, BOOL transparent)
 {
 	if (surf[surf_no].needs_updating)
 	{
 		FlushSurface(surf_no);
-		surf[surf_no].needs_updating = false;
+		surf[surf_no].needs_updating = FALSE;
 	}
 
 	// Get SDL_Rects
@@ -470,12 +470,12 @@
 
 void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // Transparency
 {
-	DrawBitmap(rcView, x, y, rect, surf_no, true);
+	DrawBitmap(rcView, x, y, rect, surf_no, TRUE);
 }
 
 void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // No Transparency
 {
-	DrawBitmap(rcView, x, y, rect, surf_no, false);
+	DrawBitmap(rcView, x, y, rect, surf_no, FALSE);
 }
 
 void Surface2Surface(int x, int y, RECT *rect, int to, int from)
@@ -485,7 +485,7 @@
 	SDL_Rect frameRect = RectToSDLRectScaled(rect);
 
 	SDL_BlitSurface(surf[from].surface, &frameRect, surf[to].surface, &rcSet);
-	surf[to].needs_updating = true;
+	surf[to].needs_updating = TRUE;
 }
 
 unsigned long GetCortBoxColor(unsigned long col)
@@ -517,7 +517,7 @@
 	const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF);
 	const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF);
 	SDL_FillRect(surf[surf_no].surface, &destRect, SDL_MapRGB(surf[surf_no].surface->format, col_red, col_green, col_blue));
-	surf[surf_no].needs_updating = true;
+	surf[surf_no].needs_updating = TRUE;
 }
 
 #ifdef WINDOWS
@@ -638,7 +638,7 @@
 void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no)
 {
 	DrawText(gFont, (unsigned char*)surf[surf_no].surface->pixels, surf[surf_no].surface->pitch, surf[surf_no].surface->w, surf[surf_no].surface->h, x * magnification, y * magnification, color, text, strlen(text));
-	surf[surf_no].needs_updating = true;
+	surf[surf_no].needs_updating = TRUE;
 }
 
 void EndTextObject()
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -10,7 +10,7 @@
 extern RECT grcFull;
 
 extern int magnification;
-extern bool fullscreen;
+extern BOOL fullscreen;
 
 typedef enum Surface_Ids
 {
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -11,6 +11,8 @@
 #include FT_LCD_FILTER_H
 #include FT_BITMAP_H
 
+#include "WindowsWrapper.h"
+
 #include "File.h"
 
 // Uncomment for that authentic pre-Windows Vista feel
@@ -39,7 +41,7 @@
 	FT_Face face;
 	unsigned char *data;
 #ifndef DISABLE_FONT_ANTIALIASING
-	bool lcd_mode;
+	BOOL lcd_mode;
 #endif
 	CachedGlyph *glyph_list_head;
 } FontObject;
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -26,7 +26,7 @@
 	}
 }
 
-bool InitDirectInput()
+BOOL InitDirectInput()
 {
 	// Open first available joystick
 	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
@@ -40,10 +40,10 @@
 			break;
 	}
 
-	return true;
+	return TRUE;
 }
 
-bool GetJoystickStatus(JOYSTICK_STATUS *pStatus)
+BOOL GetJoystickStatus(JOYSTICK_STATUS *pStatus)
 {
 	// Clear status
 	memset(pStatus, 0, sizeof(JOYSTICK_STATUS));
@@ -64,13 +64,13 @@
 		for (int button = 0; button < numButtons; button++)
 			pStatus->bButton[button] = SDL_JoystickGetButton(joystick, button) != 0;
 
-		return true;
+		return TRUE;
 	}
 
-	return false;
+	return FALSE;
 }
 
-bool ResetJoystickStatus()
+BOOL ResetJoystickStatus()
 {
-	return true;
+	return TRUE;
 }
--- a/src/Input.h
+++ b/src/Input.h
@@ -1,18 +1,20 @@
 #pragma once
 
-extern bool gbUseJoystick;
+#include "WindowsWrapper.h"
+
+extern BOOL gbUseJoystick;
 extern int gJoystickButtonTable[8];
 
 struct JOYSTICK_STATUS
 {
-	bool bLeft;
-	bool bRight;
-	bool bUp;
-	bool bDown;
-	bool bButton[32];
+	BOOL bLeft;
+	BOOL bRight;
+	BOOL bUp;
+	BOOL bDown;
+	BOOL bButton[32];
 };
 
 void ReleaseDirectInput();
-bool InitDirectInput();
-bool GetJoystickStatus(JOYSTICK_STATUS *pStatus);
-bool ResetJoystickStatus();
+BOOL InitDirectInput();
+BOOL GetJoystickStatus(JOYSTICK_STATUS *pStatus);
+BOOL ResetJoystickStatus();
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -33,10 +33,10 @@
 int gJoystickButtonTable[8];
 
 int ghWnd;	// Placeholder until we restore the WinAPI code
-bool gbUseJoystick = false;
-bool bFps = false;
+BOOL gbUseJoystick = FALSE;
+BOOL bFps = FALSE;
 
-bool bActive = true;
+BOOL bActive = TRUE;
 
 #ifdef JAPANESE
 const char *lpWindowName = "洞窟物語エンジン2";
@@ -68,7 +68,7 @@
 int GetFramePerSecound()
 {
 	unsigned int current_tick;
-	static bool need_new_base_tick = true;
+	static BOOL need_new_base_tick = TRUE;
 	static int frames_this_second;
 	static int current_frame;
 	static int base_tick;
@@ -76,7 +76,7 @@
 	if (need_new_base_tick)
 	{
 		base_tick = SDL_GetTicks();
-		need_new_base_tick = false;
+		need_new_base_tick = FALSE;
 	}
 
 	current_tick = SDL_GetTicks();
@@ -299,7 +299,7 @@
 
 					StartDirectDraw(2, colourDepth);
 
-					fullscreen = true;
+					fullscreen = TRUE;
 					SDL_ShowCursor(0);
 					break;
 				}
@@ -313,7 +313,7 @@
 		{
 			// Check debug things
 			if (CheckFileExists("fps"))
-				bFps = true;
+				bFps = TRUE;
 
 #ifndef WINDOWS
 			// Load icon
@@ -359,7 +359,7 @@
 				if (config.bJoystick && InitDirectInput())
 				{
 					ResetJoystickStatus();
-					gbUseJoystick = true;
+					gbUseJoystick = TRUE;
 				}
 
 				// Initialize stuff
@@ -390,7 +390,7 @@
 {
 	if (bActive)
 	{
-		bActive = false;
+		bActive = FALSE;
 		StopOrganyaMusic();
 		SleepNoise();
 	}
@@ -402,7 +402,7 @@
 {
 	if (!bActive)
 	{
-		bActive = true;
+		bActive = TRUE;
 		StopOrganyaMusic();
 		PlayOrganyaMusic();
 		ResetNoise();
@@ -446,10 +446,10 @@
 		gKey &= ~key; \
 	break;
 
-bool SystemTask()
+BOOL SystemTask()
 {
 	// Handle window events
-	bool focusGained = true;
+	BOOL focusGained = TRUE;
 
 	while (SDL_PollEvent(NULL) || !focusGained)
 	{
@@ -459,7 +459,7 @@
 		switch (event.type)
 		{
 			case SDL_QUIT:
-				return false;
+				return FALSE;
 				break;
 
 			case SDL_WINDOWEVENT:
@@ -466,12 +466,12 @@
 				switch (event.window.event)
 				{
 					case SDL_WINDOWEVENT_FOCUS_GAINED:
-						focusGained = true;
+						focusGained = TRUE;
 						ActiveWindow();
 						break;
 
 					case SDL_WINDOWEVENT_FOCUS_LOST:
-						focusGained = false;
+						focusGained = FALSE;
 						InactiveWindow();
 						break;
 
@@ -552,7 +552,7 @@
 						DO_KEY_PRESS(KEY_PLUS)
 
 					case SDL_SCANCODE_F5:
-						gbUseJoystick = false;
+						gbUseJoystick = FALSE;
 						break;
 
 					default:
@@ -621,7 +621,7 @@
 						DO_KEY_PRESS(KEY_PLUS)
 
 					case SDLK_F5:
-						gbUseJoystick = false;
+						gbUseJoystick = FALSE;
 						break;
 				}
 				break;
@@ -633,5 +633,5 @@
 	if (gbUseJoystick)
 		JoystickProc();
 
-	return true;
+	return TRUE;
 }
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -30,9 +30,9 @@
 
 int gTrackVol[MAXTRACK];
 int gOrgVolume = 100;
-bool bFadeout = false;
+BOOL bFadeout = FALSE;
 
-bool OrganyaNoteAlloc(unsigned short alloc)
+BOOL OrganyaNoteAlloc(unsigned short alloc)
 {
 	for(int j = 0; j < MAXTRACK; j++)
 	{
@@ -51,7 +51,7 @@
 				}
 			}
 
-			return false;
+			return FALSE;
 		}
 
 		for(int i = 0; i < alloc; i++)
@@ -72,7 +72,7 @@
 
 	//this->track = 0;
 
-	return true;
+	return FALSE;
 }
 
 void OrganyaReleaseNote()
@@ -109,7 +109,7 @@
 	{   8,128, 32 }, //7 Oct
 };
 
-bool MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
+BOOL MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
 {
 	for (int j = 0; j < 8; j++)
 	{
@@ -150,7 +150,7 @@
 		}
 	}
 
-	return true;
+	return TRUE;
 }
 
 //Playing melody tracks
@@ -272,17 +272,17 @@
 }
 
 //Create org wave
-bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi)
+BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi)
 {
 	if(wave_no > 99)
 	{
 		printf("WARNING: track %d has out-of-range wave_no %d\n", track, wave_no);
-		return false;
+		return FALSE;
 	}
 
 	ReleaseOrganyaObject(track);
 	MakeSoundObject8(wave_data[wave_no], track, pipi);
-	return true;
+	return TRUE;
 }
 
 //Dram
@@ -525,7 +525,7 @@
 	SetPlayPointer(0);
 
 	//Set as loaded
-	info.loaded = true;
+	info.loaded = TRUE;
 }
 
 void SetOrganyaPosition(unsigned int x)
@@ -532,7 +532,7 @@
 {
 	SetPlayPointer(x);
 	gOrgVolume = 100;
-	bFadeout = false;
+	bFadeout = FALSE;
 }
 
 unsigned int GetOrganyaPosition()
@@ -546,15 +546,15 @@
 	OrganyaStartTimer(info.wait);
 }
 
-bool ChangeOrganyaVolume(signed int volume)
+BOOL ChangeOrganyaVolume(signed int volume)
 {
 	if (volume >= 0 && volume <= 100)
 	{
 		gOrgVolume = volume;
-		return true;
+		return TRUE;
 	}
 
-	return false;
+	return FALSE;
 }
 
 void StopOrganyaMusic()
@@ -573,12 +573,12 @@
 
 void SetOrganyaFadeout()
 {
-	bFadeout = true;
+	bFadeout = TRUE;
 }
 
 //Org timer
 SDL_Thread *OrganyaTimer = NULL;
-bool bEndTimer = false;
+BOOL bEndTimer = FALSE;
 
 int OrganyaPlayTimer(void *ptr)
 {
@@ -587,7 +587,7 @@
 	//Set time for next step to play
 	Uint32 NextTick = SDL_GetTicks() + info.wait;
 
-	while (bEndTimer == false)
+	while (bEndTimer == FALSE)
 	{
 		if (info.loaded)
 		{
@@ -615,13 +615,13 @@
 void OrganyaStartTimer(unsigned int wait)
 {
 	OrganyaEndTimer();
-	bEndTimer = false;
+	bEndTimer = FALSE;
 	OrganyaTimer = SDL_CreateThread(OrganyaPlayTimer, "OrganyaPlayTimer", (void*)NULL);
 }
 
 void OrganyaEndTimer()
 {
-	bEndTimer = true; //Tell thread to end
+	bEndTimer = TRUE; //Tell thread to end
 	SDL_WaitThread(OrganyaTimer, NULL); //Wait for thread to end
 	OrganyaTimer = NULL;
 }
--- a/src/Organya.h
+++ b/src/Organya.h
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "WindowsWrapper.h"
+
 //Below are Organya song data structures
 struct NOTELIST {
 	NOTELIST *from; //Previous address
@@ -26,8 +28,8 @@
 //Unique information held in songs
 struct MUSICINFO {
 	unsigned short wait;
-	bool loaded;
-	bool playing;
+	BOOL loaded;
+	BOOL playing;
 	unsigned char line; //Number of lines in one measure
 	unsigned char dot; //Number of dots per line
 	unsigned short alloc_note; //Number of allocated notes
@@ -36,7 +38,7 @@
 	TRACKDATA tdata[16];
 };
 
-bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
+BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
 void OrganyaPlayData();
 void SetPlayPointer(long x);
 void LoadOrganya(const char *name);
@@ -43,7 +45,7 @@
 void SetOrganyaPosition(unsigned int x);
 unsigned int GetOrganyaPosition();
 void PlayOrganyaMusic();
-bool ChangeOrganyaVolume(signed int volume);
+BOOL ChangeOrganyaVolume(signed int volume);
 void StopOrganyaMusic();
 void SetOrganyaFadeout();
 void OrganyaStartTimer(unsigned int wait);
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -8,6 +8,8 @@
 
 #include <SDL.h>
 
+#include "WindowsWrapper.h"
+
 #include "Organya.h"
 #include "PixTone.h"
 
@@ -219,7 +221,7 @@
 //Sound things
 SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
 
-bool InitDirectSound()
+BOOL InitDirectSound()
 {
 	//Init sound
 	SDL_InitSubSystem(SDL_INIT_AUDIO);
@@ -240,7 +242,7 @@
 	if (audioDevice == 0)
 	{
 		printf("Failed to open audio device\nSDL Error: %s\n", SDL_GetError());
-		return false;
+		return FALSE;
 	}
 
 	//Unpause audio device
@@ -248,7 +250,7 @@
 
 	//Start organya
 	StartOrganya();
-	return true;
+	return TRUE;
 }
 
 void EndDirectSound()
--- a/src/Sound.h
+++ b/src/Sound.h
@@ -2,6 +2,8 @@
 
 #include <stddef.h>
 
+#include "WindowsWrapper.h"
+
 #include "PixTone.h"
 
 class SOUNDBUFFER
@@ -91,7 +93,7 @@
 #define SOUND_NO 0x100
 extern SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
 
-bool InitDirectSound();
+BOOL InitDirectSound();
 void EndDirectSound();
 void PlaySoundObject(int no, int mode);
 void ChangeSoundFrequency(int no, unsigned long rate);
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -35,4 +35,4 @@
 	int bottom;
 };
 
-bool SystemTask();
+BOOL SystemTask();