From 1e72995fe7e9f6d3f60dc3dc4c5b7ffc9b7e771d Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 4 May 2020 16:01:08 +0300 Subject: [PATCH 1/4] Move SDL functions to own file This ease logic for main() function. --- CMakeLists.txt | 7 +- src/MacSrc/InitMac.h | 24 ++--- src/MacSrc/SDLFunctions.c | 201 ++++++++++++++++++++++++++++++++++++++ src/MacSrc/Shock.c | 181 ---------------------------------- 4 files changed, 219 insertions(+), 194 deletions(-) create mode 100644 src/MacSrc/SDLFunctions.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 625694de0..2e0b45cd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,9 +143,9 @@ feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:") add_subdirectory(src/Libraries/) set(MAC_SRC + src/MacSrc/SDLFunctions.c src/MacSrc/ShockBitmap.c src/MacSrc/InitMac.c - src/MacSrc/Shock.c src/MacSrc/Prefs.c src/MacSrc/MacTune.c src/MacSrc/SDLSound.c @@ -275,6 +275,10 @@ set(GAME_SRC src/GameSrc/mouselook.c ) +set(SHOCK_SRC + src/MacSrc/Shock.c +) + include_directories( src/Libraries/2D/Source src/Libraries/3D/Source @@ -381,6 +385,7 @@ add_definitions( add_executable(systemshock ${MAC_SRC} + ${SHOCK_SRC} ) add_library(GAME_LIB ${GAME_SRC}) diff --git a/src/MacSrc/InitMac.h b/src/MacSrc/InitMac.h index 06b42b2c0..a11b78689 100644 --- a/src/MacSrc/InitMac.h +++ b/src/MacSrc/InitMac.h @@ -30,18 +30,18 @@ along with this program. If not, see . // Prototypes //-------------------- void InitMac(void); -void FailNIL(void *); +//void FailNIL(void *); // Handle GetResourceFail(long id, short num); -void CheckConfig(void); -void ErrorDie(short stringnum); +//void CheckConfig(void); +//void ErrorDie(short stringnum); void CleanupAndExit(void); -void SetupWindows(WindowPtr *mainWind); -void SetUpMenus(MenuHandle *theMenus, short numMenus); -void StringAlert(short stringnum); -void GetFolders(void); +//void SetupWindows(WindowPtr *mainWind); +//void SetUpMenus(MenuHandle *theMenus, short numMenus); +//void StringAlert(short stringnum); +//void GetFolders(void); void InstallShockTimers(void); -void RemoveShockTimers(void); -void StartShockTimer(void); -void StopShockTimer(void); -void HideMenuBar(void); -void ShowMenuBar(void); +//void RemoveShockTimers(void); +//void StartShockTimer(void); +//void StopShockTimer(void); +//void HideMenuBar(void); +//void ShowMenuBar(void); diff --git a/src/MacSrc/SDLFunctions.c b/src/MacSrc/SDLFunctions.c new file mode 100644 index 000000000..6a1a7cab8 --- /dev/null +++ b/src/MacSrc/SDLFunctions.c @@ -0,0 +1,201 @@ +/* + +Copyright (C) 2015-2018 Night Dive Studios, LLC. +Copyright (C) 2018-2020 Shockolate project + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#include +#include "shockolate_version.h" +#include "InitMac.h" +#include "OpenGL.h" +#include "Prefs.h" +#include "ShockBitmap.h" +#include "Shock.h" +#include "ShockHelp.h" + +#include "amaploop.h" +#include "map.h" +#include "gr2ss.h" +#include "frflags.h" +#include "version.h" + + +SDL_AudioDeviceID device; +SDL_Color gamePalette[256]; +SDL_Palette *sdlPalette; +SDL_Renderer *renderer; +SDL_Window *window; + +bool UseCutscenePalette = FALSE; // see cutsloop.c +bool MouseCaptured = FALSE; +char window_title[128]; + +extern grs_screen *svga_screen; +extern int mlook_enabled; + +void InitSDL() { + SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) { + DEBUG("%s: Init failed", __FUNCTION__); + } + + // TODO: figure out some universal set of settings that work... + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); + + gr_init(); + + extern short svga_mode_data[]; + gr_set_mode(svga_mode_data[gShockPrefs.doVideoMode], TRUE); + + INFO("Setting up screen and render contexts"); + + // Create a canvas to draw to + + SetupOffscreenBitmaps(grd_cap->w, grd_cap->h); + + // Open our window! + + sprintf(window_title, "System Shock - %s", SHOCKOLATE_VERSION); + + window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, grd_cap->w, grd_cap->h, + SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL); + + // Create the palette + + sdlPalette = SDL_AllocPalette(256); + + // Setup the screen + + svga_screen = cit_screen = gr_alloc_screen(grd_cap->w, grd_cap->h); + gr_set_screen(svga_screen); + + gr_alloc_ipal(); + + SDL_ShowCursor(SDL_DISABLE); + + atexit(SDL_Quit); + + SDL_RaiseWindow(window); + + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); + SDL_RenderSetLogicalSize(renderer, grd_cap->w, grd_cap->h); + + // Startup OpenGL + + init_opengl(); + + SDLDraw(); + + SDL_ShowWindow(window); +} + +void SetSDLPalette(int index, int count, uchar *pal) { + static bool gammalut_init = 0; + static uchar gammalut[100 - 10 + 1][256]; + if (!gammalut_init) { + double factor = (can_use_opengl() ? 1.0 : 2.2); // OpenGL uses 2.2 + int i, j; + for (i = 10; i <= 100; i++) { + double gamma = (double)i * 1.0 / 100; + gamma = 1 - gamma; + gamma *= gamma; + gamma = 1 - gamma; + gamma = 1 / (gamma * factor); + for (j = 0; j < 256; j++) + gammalut[i - 10][j] = (uchar)(pow((double)j / 255, gamma) * 255); + } + gammalut_init = 1; + INFO("Gamma LUT init\'ed"); + } + + int gam = gShockPrefs.doGamma; + if (gam < 10) + gam = 10; + if (gam > 100) + gam = 100; + gam -= 10; + + for (int i = index; i < index + count; i++) { + gamePalette[i].r = gammalut[gam][*pal++]; + gamePalette[i].g = gammalut[gam][*pal++]; + gamePalette[i].b = gammalut[gam][*pal++]; + gamePalette[i].a = 0xff; + } + + if (!UseCutscenePalette) { + // Hack black! + gamePalette[255].r = 0x0; + gamePalette[255].g = 0x0; + gamePalette[255].b = 0x0; + gamePalette[255].a = 0xff; + } + + SDL_SetPaletteColors(sdlPalette, gamePalette, 0, 256); + SDL_SetSurfacePalette(drawSurface, sdlPalette); + SDL_SetSurfacePalette(offscreenDrawSurface, sdlPalette); + + if (should_opengl_swap()) + opengl_change_palette(); +} + +void SDLDraw() { + if (should_opengl_swap()) { + sdlPalette->colors[255].a = 0x00; + } + + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, drawSurface); + + if (should_opengl_swap()) { + sdlPalette->colors[255].a = 0xff; + SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + } + + SDL_Rect srcRect = {0, 0, gScreenWide, gScreenHigh}; + SDL_RenderCopy(renderer, texture, &srcRect, NULL); + SDL_DestroyTexture(texture); + + if (should_opengl_swap()) { + opengl_swap_and_restore(); + } else { + SDL_RenderPresent(renderer); + SDL_RenderClear(renderer); + } +} + +void CaptureMouse(bool capture) { + MouseCaptured = (capture && gShockPrefs.goCaptureMouse); + + if (!MouseCaptured && mlook_enabled && SDL_GetRelativeMouseMode() == SDL_TRUE) { + SDL_SetRelativeMouseMode(SDL_FALSE); + + int w, h; + SDL_GetWindowSize(window, &w, &h); + SDL_WarpMouseInWindow(window, w / 2, h / 2); + } else + SDL_SetRelativeMouseMode(MouseCaptured ? SDL_TRUE : SDL_FALSE); +} diff --git a/src/MacSrc/Shock.c b/src/MacSrc/Shock.c index 953620291..688938542 100644 --- a/src/MacSrc/Shock.c +++ b/src/MacSrc/Shock.c @@ -50,13 +50,9 @@ along with this program. If not, see . #include "gr2ss.h" #include "frflags.h" #include "version.h" -#include "shockolate_version.h" #include "Modding.h" -#include -#include - extern uchar game_paused; // I've learned such bad lessons from LG. extern uchar objdata_loaded; extern uchar music_on; @@ -78,13 +74,6 @@ bool gDeadPlayerQuit; bool gGameCompletedQuit; grs_screen *cit_screen; -SDL_Window* window; -SDL_Palette* sdlPalette; -SDL_Renderer* renderer; - -SDL_AudioDeviceID device; - -char window_title[128]; int num_args; char** arg_values; @@ -106,8 +95,6 @@ extern void CreateDefaultKeybindsFile(void); extern void LoadHotkeyKeybinds(void); extern void LoadMoveKeybinds(void); -void InitSDL(); -void SDLDraw(void); errtype CheckFreeSpace(short checkRefNum); @@ -215,171 +202,3 @@ errtype CheckFreeSpace(short checkRefNum) // FIXME: This should probably do something? return (OK); } - -void InitSDL() -{ - SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); - SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) { - DEBUG("%s: Init failed", __FUNCTION__); - } - - // TODO: figure out some universal set of settings that work... - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); - - gr_init(); - - extern short svga_mode_data[]; - gr_set_mode(svga_mode_data[gShockPrefs.doVideoMode], TRUE); - - INFO("Setting up screen and render contexts"); - - // Create a canvas to draw to - - SetupOffscreenBitmaps(grd_cap->w, grd_cap->h); - - // Open our window! - - sprintf(window_title, "System Shock - %s", SHOCKOLATE_VERSION); - - window = SDL_CreateWindow( - window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - grd_cap->w, grd_cap->h, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL); - - - // Create the palette - - sdlPalette = SDL_AllocPalette(256); - - // Setup the screen - - svga_screen = cit_screen = gr_alloc_screen(grd_cap->w, grd_cap->h); - gr_set_screen(svga_screen); - - gr_alloc_ipal(); - - SDL_ShowCursor(SDL_DISABLE); - - atexit(SDL_Quit); - - SDL_RaiseWindow(window); - - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC); - SDL_RenderSetLogicalSize(renderer, grd_cap->w, grd_cap->h); - - // Startup OpenGL - - init_opengl(); - - SDLDraw(); - - SDL_ShowWindow(window); -} - -SDL_Color gamePalette[256]; -bool UseCutscenePalette = FALSE; //see cutsloop.c -void SetSDLPalette(int index, int count, uchar *pal) -{ - static bool gammalut_init = 0; - static uchar gammalut[100-10+1][256]; - if (!gammalut_init) - { - double factor = (can_use_opengl() ? 1.0 : 2.2); //OpenGL uses 2.2 - int i, j; - for (i = 10; i <= 100; i++) - { - double gamma = (double)i * 1.0 / 100; - gamma = 1 - gamma; - gamma *= gamma; - gamma = 1 - gamma; - gamma = 1 / (gamma * factor); - for (j = 0; j < 256; j++) - gammalut[i-10][j] = (uchar)(pow((double)j / 255, gamma) * 255); - } - gammalut_init = 1; - INFO("Gamma LUT init\'ed"); - } - - int gam = gShockPrefs.doGamma; - if (gam < 10) gam = 10; - if (gam > 100) gam = 100; - gam -= 10; - - for (int i = index; i < index+count; i++) - { - gamePalette[i].r = gammalut[gam][*pal++]; - gamePalette[i].g = gammalut[gam][*pal++]; - gamePalette[i].b = gammalut[gam][*pal++]; - gamePalette[i].a = 0xff; - } - - if (!UseCutscenePalette) - { - // Hack black! - gamePalette[255].r = 0x0; - gamePalette[255].g = 0x0; - gamePalette[255].b = 0x0; - gamePalette[255].a = 0xff; - } - - SDL_SetPaletteColors(sdlPalette, gamePalette, 0, 256); - SDL_SetSurfacePalette(drawSurface, sdlPalette); - SDL_SetSurfacePalette(offscreenDrawSurface, sdlPalette); - - if (should_opengl_swap()) - opengl_change_palette(); -} - -void SDLDraw() -{ - if (should_opengl_swap()) { - sdlPalette->colors[255].a = 0x00; - } - - SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, drawSurface); - - if (should_opengl_swap()) { - sdlPalette->colors[255].a = 0xff; - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - } - - SDL_Rect srcRect = { 0, 0, gScreenWide, gScreenHigh }; - SDL_RenderCopy(renderer, texture, &srcRect, NULL); - SDL_DestroyTexture(texture); - - if (should_opengl_swap()) { - opengl_swap_and_restore(); - } else { - SDL_RenderPresent(renderer); - SDL_RenderClear(renderer); - } -} - -bool MouseCaptured = FALSE; - -extern int mlook_enabled; - -void CaptureMouse(bool capture) -{ - MouseCaptured = (capture && gShockPrefs.goCaptureMouse); - - if (!MouseCaptured && mlook_enabled && SDL_GetRelativeMouseMode() == SDL_TRUE) - { - SDL_SetRelativeMouseMode(SDL_FALSE); - - int w, h; - SDL_GetWindowSize(window, &w, &h); - SDL_WarpMouseInWindow(window, w/2, h/2); - } - else SDL_SetRelativeMouseMode(MouseCaptured ? SDL_TRUE : SDL_FALSE); -} From 792ffdb908468b3c97c5fcfd11168caeb06f2130 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 4 May 2020 16:27:24 +0300 Subject: [PATCH 2/4] Now Shockolate it CPP project Initial reorganizing project - moved to ShockSrc main's Shock.cpp file. There will be live new files. Moved some prototypes into corresponding headers. Little hackinsh extern "C" sections. Moved LGS copyrights into top section. --- CMakeLists.txt | 3 +- src/GameSrc/Headers/init.h | 2 +- src/MacSrc/Prefs.h | 4 +++ src/{MacSrc/Shock.c => ShockSrc/Shock.cpp} | 40 +++++++--------------- src/{MacSrc => ShockSrc}/Shock.h | 11 ++---- 5 files changed, 23 insertions(+), 37 deletions(-) rename src/{MacSrc/Shock.c => ShockSrc/Shock.cpp} (85%) rename src/{MacSrc => ShockSrc}/Shock.h (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e0b45cd9..b955f60c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,7 +276,7 @@ set(GAME_SRC ) set(SHOCK_SRC - src/MacSrc/Shock.c + src/ShockSrc/Shock.cpp ) include_directories( @@ -301,6 +301,7 @@ include_directories( src/GameSrc/Headers src/MacSrc src/MusicSrc + src/ShockSrc ${CMAKE_BINARY_DIR}/src/GameSrc/Headers ) diff --git a/src/GameSrc/Headers/init.h b/src/GameSrc/Headers/init.h index 402d2481d..58e2ff33a 100644 --- a/src/GameSrc/Headers/init.h +++ b/src/GameSrc/Headers/init.h @@ -33,7 +33,7 @@ extern grs_bitmap material_maps[MAX_MATERIALS]; extern void init_all(void); extern void free_all(void); extern uchar ppall[]; // pointer to main shadow palette - +errtype load_da_palette(void); void object_data_flush(void); errtype object_data_load(void); extern uchar objdata_loaded; diff --git a/src/MacSrc/Prefs.h b/src/MacSrc/Prefs.h index 9a95c6b3f..66285b274 100644 --- a/src/MacSrc/Prefs.h +++ b/src/MacSrc/Prefs.h @@ -73,6 +73,10 @@ void SetDefaultPrefs(void); int16_t LoadPrefs(void); int16_t SavePrefs(void); +void CreateDefaultKeybindsFile(void); +void LoadHotkeyKeybinds(void); +void LoadMoveKeybinds(void); + //------------------- // Enums //------------------- diff --git a/src/MacSrc/Shock.c b/src/ShockSrc/Shock.cpp similarity index 85% rename from src/MacSrc/Shock.c rename to src/ShockSrc/Shock.cpp index 688938542..925645dd6 100644 --- a/src/MacSrc/Shock.c +++ b/src/ShockSrc/Shock.cpp @@ -1,6 +1,8 @@ /* +Copyright (C) 1994-1995 Looking Glass Technologies, Inc. Copyright (C) 2015-2018 Night Dive Studios, LLC. +Copyright (C) 2018-2020 Shockolate project This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,20 +18,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -//==================================================================================== -// -// System Shock - ©1994-1995 Looking Glass Technologies, Inc. -// -// Shock.c - Mac-specific initialization and main event loop. -// -//==================================================================================== - //-------------------- // Includes //-------------------- -//#include +extern "C" { #include "Shock.h" #include "InitMac.h" #include "OpenGL.h" @@ -42,6 +36,7 @@ along with this program. If not, see . #include "amaploop.h" #include "hkeyfunc.h" +#include "init.h" #include "mainloop.h" #include "setup.h" #include "fullscrn.h" @@ -53,6 +48,13 @@ along with this program. If not, see . #include "Modding.h" +//-------------------- +// Prototypes +//-------------------- +extern void inv_change_fullscreen(uchar on); + +} + extern uchar game_paused; // I've learned such bad lessons from LG. extern uchar objdata_loaded; extern uchar music_on; @@ -78,23 +80,7 @@ int num_args; char** arg_values; extern grs_screen *svga_screen; -extern frc *svga_render_context; - -//-------------------- -// Prototypes -//-------------------- -extern void init_all(void); -extern void inv_change_fullscreen(uchar on); -extern void object_data_flush(void); -//extern Boolean IsFullscreenWareOn(void); -extern errtype load_da_palette(void); -extern void ShockMain(void); - -//see Prefs.c -extern void CreateDefaultKeybindsFile(void); -extern void LoadHotkeyKeybinds(void); -extern void LoadMoveKeybinds(void); - +extern frc *svga_render_context; errtype CheckFreeSpace(short checkRefNum); @@ -172,7 +158,7 @@ int main(int argc, char** argv) return 0; } -bool CheckArgument(char* arg) { +bool CheckArgument(const char* arg) { if(arg == NULL) return false; diff --git a/src/MacSrc/Shock.h b/src/ShockSrc/Shock.h similarity index 93% rename from src/MacSrc/Shock.h rename to src/ShockSrc/Shock.h index 389a1b3a4..281c70db0 100644 --- a/src/MacSrc/Shock.h +++ b/src/ShockSrc/Shock.h @@ -1,6 +1,8 @@ /* +Copyright (C) 1994-1995 Looking Glass Technologies, Inc. Copyright (C) 2015-2018 Night Dive Studios, LLC. +Copyright (C) 2018-2020 Shockolate project This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,13 +18,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -//==================================================================================== -// -// System Shock - ©1994-1995 Looking Glass Technologies, Inc. -// -// Shock.h - Mac-specific initialization and main event loop. -// -//==================================================================================== #include @@ -134,7 +129,7 @@ void InitSDL(); void SetSDLPalette(int index, int count, uchar *pal); void SDLDraw(); void CaptureMouse(bool capture); -bool CheckArgument(char* name); +bool CheckArgument(const char* name); //-------------------- // Public Globals From 0455ca64ffcd2cd1c1fa55d5c808b9b72dd4b5f5 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 4 May 2020 16:38:45 +0300 Subject: [PATCH 3/4] clang-format on Shock.(cpp|h) --- src/ShockSrc/Shock.cpp | 155 ++++++++++++++---------------- src/ShockSrc/Shock.h | 212 ++++++++++++++++++++--------------------- 2 files changed, 179 insertions(+), 188 deletions(-) diff --git a/src/ShockSrc/Shock.cpp b/src/ShockSrc/Shock.cpp index 925645dd6..6f2864728 100644 --- a/src/ShockSrc/Shock.cpp +++ b/src/ShockSrc/Shock.cpp @@ -8,15 +8,15 @@ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . - + */ //-------------------- @@ -52,10 +52,9 @@ extern "C" { // Prototypes //-------------------- extern void inv_change_fullscreen(uchar on); - } -extern uchar game_paused; // I've learned such bad lessons from LG. +extern uchar game_paused; // I've learned such bad lessons from LG. extern uchar objdata_loaded; extern uchar music_on; extern uchar startup_music; @@ -63,128 +62,122 @@ extern uchar startup_music; //-------------------- // Globals //-------------------- -WindowPtr gMainWindow; -MenuHandle gMainMenus[kNumMenus]; -//RgnHandle gCursorRgn; -short gCursorSet; -bool gDone = false; -bool gInForeground = true; -bool gPlayingGame; //¥¥¥ Temp -bool gIsNewGame; -long gGameSavedTime; -bool gDeadPlayerQuit; -bool gGameCompletedQuit; - -grs_screen *cit_screen; +WindowPtr gMainWindow; +MenuHandle gMainMenus[kNumMenus]; +// RgnHandle gCursorRgn; +short gCursorSet; +bool gDone = false; +bool gInForeground = true; +bool gPlayingGame; //¥¥¥ Temp +bool gIsNewGame; +long gGameSavedTime; +bool gDeadPlayerQuit; +bool gGameCompletedQuit; + +grs_screen *cit_screen; int num_args; -char** arg_values; +char **arg_values; extern grs_screen *svga_screen; extern frc *svga_render_context; -errtype CheckFreeSpace(short checkRefNum); - +errtype CheckFreeSpace(short checkRefNum); //------------------------------------------------------------------------------------ // Main function. //------------------------------------------------------------------------------------ -int main(int argc, char** argv) -{ - // Save the arguments for later +int main(int argc, char **argv) { + // Save the arguments for later - num_args = argc; - arg_values = argv; + num_args = argc; + arg_values = argv; - // FIXME externalize this - log_set_quiet(0); - log_set_level(LOG_INFO); + // FIXME externalize this + log_set_quiet(0); + log_set_level(LOG_INFO); - // init mac managers + // init mac managers - InitMac(); + InitMac(); - // Initialize the preferences file. + // Initialize the preferences file. - SetDefaultPrefs(); - LoadPrefs(); + SetDefaultPrefs(); + LoadPrefs(); - //see Prefs.c - CreateDefaultKeybindsFile(); //only if it doesn't already exist - //even if keybinds file still doesn't exist, defaults will be set here + // see Prefs.c + CreateDefaultKeybindsFile(); // only if it doesn't already exist + // even if keybinds file still doesn't exist, defaults will be set here LoadHotkeyKeybinds(); LoadMoveKeybinds(); - + #ifdef TESTING - SetupTests(); + SetupTests(); #endif - // Process some startup arguments + // Process some startup arguments - bool show_splash = !CheckArgument("-nosplash"); + bool show_splash = !CheckArgument("-nosplash"); - // CC: Modding support! This is so exciting. + // CC: Modding support! This is so exciting. - ProcessModArgs(argc, argv); + ProcessModArgs(argc, argv); - // Initialize + // Initialize - init_all(); - setup_init(); + init_all(); + setup_init(); - gPlayingGame = TRUE; - gDeadPlayerQuit = FALSE; - gGameCompletedQuit = FALSE; + gPlayingGame = TRUE; + gDeadPlayerQuit = FALSE; + gGameCompletedQuit = FALSE; - load_da_palette(); - gr_clear(0xFF); + load_da_palette(); + gr_clear(0xFF); - // Draw the splash screen + // Draw the splash screen - INFO("Showing splash screen"); - splash_draw(show_splash); + INFO("Showing splash screen"); + splash_draw(show_splash); - // Start in the Main Menu loop + // Start in the Main Menu loop - _new_mode = _current_loop = SETUP_LOOP; - loopmode_enter(SETUP_LOOP); + _new_mode = _current_loop = SETUP_LOOP; + loopmode_enter(SETUP_LOOP); - // Start the main loop + // Start the main loop - INFO("Showing main menu, starting game loop"); - mainloop(argc, argv); + INFO("Showing main menu, starting game loop"); + mainloop(argc, argv); - status_bio_end(); - stop_music(); + status_bio_end(); + stop_music(); - return 0; + return 0; } -bool CheckArgument(const char* arg) { - if(arg == NULL) - return false; +bool CheckArgument(const char *arg) { + if (arg == NULL) + return false; - for(int i = 1; i < num_args; i++) { - if(strcmp(arg_values[i], arg) == 0) { - return true; - } - } + for (int i = 1; i < num_args; i++) { + if (strcmp(arg_values[i], arg) == 0) { + return true; + } + } - return false; + return false; } //------------------------------------------------------------------------------------ // Handle Quit menu command/apple event. //------------------------------------------------------------------------------------ -void DoQuit(void) -{ - gDone = true; -} +void DoQuit(void) { gDone = true; } -#define NEEDED_DISKSPACE 700000 +#define NEEDED_DISKSPACE 700000 //------------------------------------------------------------------------------------ // See if we have enough free space to save the file. //------------------------------------------------------------------------------------ -errtype CheckFreeSpace(short checkRefNum) -{ - // FIXME: This should probably do something? - return (OK); +errtype CheckFreeSpace(short checkRefNum) { + // FIXME: This should probably do something? + return (OK); } diff --git a/src/ShockSrc/Shock.h b/src/ShockSrc/Shock.h index 281c70db0..d4194616f 100644 --- a/src/ShockSrc/Shock.h +++ b/src/ShockSrc/Shock.h @@ -8,15 +8,15 @@ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . - + */ #include @@ -32,91 +32,91 @@ along with this program. If not, see . // Menus //-------------------- #ifdef TESTING -#define kNumMenus 6 +#define kNumMenus 6 #else -#define kNumMenus 4 +#define kNumMenus 4 #endif -#define mApple 128 // Menu IDs -#define mFile 129 -#define mEdit 130 -#define mOptions 131 +#define mApple 128 // Menu IDs +#define mFile 129 +#define mEdit 130 +#define mOptions 131 #ifdef TESTING -#define mTests 132 -#define mTests2 133 +#define mTests 132 +#define mTests2 133 #endif -#define fileNewGame 1 // File menu item IDs -#define fileOpenGame 2 -#define fileSaveGame 3 -#define fileSaveGameAs 4 -#define filePlayIntro 6 -#define fileResumeGame 8 -#define fileEndGame 9 -#define fileQuit 11 - -#define editUndo 1 // Edit menu item IDs -#define editCut 3 -#define editCopy 4 -#define editPaste 5 -#define editClear 6 - -#define optGameOptions 1 // Options menu item IDs -#define optGraphicsOptions 2 -#define optSoundOptions 3 +#define fileNewGame 1 // File menu item IDs +#define fileOpenGame 2 +#define fileSaveGame 3 +#define fileSaveGameAs 4 +#define filePlayIntro 6 +#define fileResumeGame 8 +#define fileEndGame 9 +#define fileQuit 11 + +#define editUndo 1 // Edit menu item IDs +#define editCut 3 +#define editCopy 4 +#define editPaste 5 +#define editClear 6 + +#define optGameOptions 1 // Options menu item IDs +#define optGraphicsOptions 2 +#define optSoundOptions 3 #ifdef TESTING -#define testBrowseImages 1 // Tests menu item IDs -#define testBrowseFonts 2 -#define testLoadPalette 3 -#define testMoveKeys 5 -#define testMouse 6 -#define testPlayMovie 8 -#define testPlayMovie2x 9 -#define testPlayMovieDblSpd 10 -#define testPlayMovieHalfSpd 11 -#define testPlayIntro 13 -#define testPlayDeath 14 -#define testPlayEndGame 15 -#define testPlayCitadelVM 17 -#define testPlayDetachVM 18 -#define testPlayJettisonVM 19 -#define testPlayLaserMalVM 20 -#define testPlayShieldsVM 21 -#define testPlayAutoDesVM 22 -#define testPlayBark1 24 -#define testPlayBark2 25 -#define testPlayAlog1 26 -#define testPlayAlog2 27 - -#define testLoadLevelR 1 -#define testLoadLevel1 2 -#define testLoadLevel2 3 -#define testLoadLevel3 4 -#define testZoomIn 6 -#define testZoomOut 7 -#define testRender 9 +#define testBrowseImages 1 // Tests menu item IDs +#define testBrowseFonts 2 +#define testLoadPalette 3 +#define testMoveKeys 5 +#define testMouse 6 +#define testPlayMovie 8 +#define testPlayMovie2x 9 +#define testPlayMovieDblSpd 10 +#define testPlayMovieHalfSpd 11 +#define testPlayIntro 13 +#define testPlayDeath 14 +#define testPlayEndGame 15 +#define testPlayCitadelVM 17 +#define testPlayDetachVM 18 +#define testPlayJettisonVM 19 +#define testPlayLaserMalVM 20 +#define testPlayShieldsVM 21 +#define testPlayAutoDesVM 22 +#define testPlayBark1 24 +#define testPlayBark2 25 +#define testPlayAlog1 26 +#define testPlayAlog2 27 + +#define testLoadLevelR 1 +#define testLoadLevel1 2 +#define testLoadLevel2 3 +#define testLoadLevel3 4 +#define testZoomIn 6 +#define testZoomOut 7 +#define testRender 9 #endif //-------------------- // Graphics Defines //-------------------- -#define screenMaxX 640L -#define screenMaxY 480L +#define screenMaxX 640L +#define screenMaxY 480L //-------------------- // File Types //-------------------- -#define kAppFileType 'Shok' -#define kGameFileType 'Sgam' -#define kRsrcFileType 'Sres' +#define kAppFileType 'Shok' +#define kGameFileType 'Sgam' +#define kRsrcFileType 'Sres' //-------------------- // Function Prototypes //-------------------- -typedef void* WindowPtr; // FIXME: get rid of UpdateWindow()? -typedef void* MenuHandle; // FIXME: what's gMainMenus about? -int main(int argc, char** argv); +typedef void *WindowPtr; // FIXME: get rid of UpdateWindow()? +typedef void *MenuHandle; // FIXME: what's gMainMenus about? +int main(int argc, char **argv); void HandleEvents(void); void UpdateWindow(WindowPtr wind); void DoCommand(unsigned long mResult); @@ -129,52 +129,50 @@ void InitSDL(); void SetSDLPalette(int index, int count, uchar *pal); void SDLDraw(); void CaptureMouse(bool capture); -bool CheckArgument(const char* name); +bool CheckArgument(const char *name); //-------------------- // Public Globals //-------------------- -extern WindowPtr gMainWindow; -extern MenuHandle gMainMenus[kNumMenus]; -//extern RgnHandle gCursorRgn; -//extern short gCursorSet; -extern bool gDone; -extern bool gInForeground; -extern bool gIsNewGame; -//extern FSSpec gSavedGameFile; -extern long gGameSavedTime; - -//extern Handle gExtraMemory; -//extern ColorSpec* gOriginalColors; -extern unsigned long gRandSeed; -extern short gMainVRef; +extern WindowPtr gMainWindow; +extern MenuHandle gMainMenus[kNumMenus]; +// extern RgnHandle gCursorRgn; +// extern short gCursorSet; +extern bool gDone; +extern bool gInForeground; +extern bool gIsNewGame; +// extern FSSpec gSavedGameFile; +extern long gGameSavedTime; + +// extern Handle gExtraMemory; +// extern ColorSpec* gOriginalColors; +extern unsigned long gRandSeed; +extern short gMainVRef; // extern Handle gWatchCurs; -extern short gOriginalDepth; -extern short gStartupDepth; -extern short gLastAlertDepth; -extern char *gScreenAddress; -extern long gScreenRowbytes; -extern short gScreenWide, gScreenHigh; -extern short gActiveWide, gActiveHigh; -extern short gActiveLeft, gActiveTop; -//extern Rect gActiveArea, gOffActiveArea; - -//extern Boolean gIsPowerPC; - -extern long gDataDirID; -extern short gDataVref; -extern long gCDDataDirID; -extern short gCDDataVref; -extern long gAlogDirID; -extern short gAlogVref; -extern long gBarkDirID; -extern short gBarkVref; - - -extern grs_screen *cit_screen; -extern SDL_Window* window; - +extern short gOriginalDepth; +extern short gStartupDepth; +extern short gLastAlertDepth; +extern char *gScreenAddress; +extern long gScreenRowbytes; +extern short gScreenWide, gScreenHigh; +extern short gActiveWide, gActiveHigh; +extern short gActiveLeft, gActiveTop; +// extern Rect gActiveArea, gOffActiveArea; + +// extern Boolean gIsPowerPC; + +extern long gDataDirID; +extern short gDataVref; +extern long gCDDataDirID; +extern short gCDDataVref; +extern long gAlogDirID; +extern short gAlogVref; +extern long gBarkDirID; +extern short gBarkVref; + +extern grs_screen *cit_screen; +extern SDL_Window *window; /*#else extern short gOriginalDepth; From d5888a63989cc150b9f9c60799670f5d9b79f739 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Mon, 4 May 2020 17:32:52 +0300 Subject: [PATCH 4/4] Cleaning up unused code in Shock.* Removed unused leftovers from MacOS menus, unused global variables, defines and externs. --- src/GameSrc/damage.c | 1 - src/GameSrc/trigger.c | 1 - src/ShockSrc/Shock.cpp | 39 +----------- src/ShockSrc/Shock.h | 140 ----------------------------------------- 4 files changed, 1 insertion(+), 180 deletions(-) diff --git a/src/GameSrc/damage.c b/src/GameSrc/damage.c index 5d7cee5bc..1fd340214 100644 --- a/src/GameSrc/damage.c +++ b/src/GameSrc/damage.c @@ -402,7 +402,6 @@ int shield_absorb_damage(int damage, ubyte ub, byte shield_absorb, ubyte shield_ uchar alternate_death = FALSE; extern bool gPlayingGame; -extern bool gDeadPlayerQuit; // kill_player() // kills the player, checks for traps and stuff, so on diff --git a/src/GameSrc/trigger.c b/src/GameSrc/trigger.c index 9b64290e6..19c7510cc 100644 --- a/src/GameSrc/trigger.c +++ b/src/GameSrc/trigger.c @@ -1192,7 +1192,6 @@ extern uchar alternate_death; extern bool gPlayingGame; extern bool gDeadPlayerQuit; -extern bool gGameCompletedQuit; errtype trap_cutscene_func(int p1, int p2, int p3, int p4) { short cs = qdata_get(p1); diff --git a/src/ShockSrc/Shock.cpp b/src/ShockSrc/Shock.cpp index 6f2864728..c5833ed9a 100644 --- a/src/ShockSrc/Shock.cpp +++ b/src/ShockSrc/Shock.cpp @@ -30,9 +30,6 @@ extern "C" { #include "Prefs.h" #include "ShockBitmap.h" #include "ShockHelp.h" -#ifdef TESTING -#include "Tests.h" -#endif #include "amaploop.h" #include "hkeyfunc.h" @@ -54,25 +51,11 @@ extern "C" { extern void inv_change_fullscreen(uchar on); } -extern uchar game_paused; // I've learned such bad lessons from LG. -extern uchar objdata_loaded; -extern uchar music_on; -extern uchar startup_music; - //-------------------- // Globals //-------------------- -WindowPtr gMainWindow; -MenuHandle gMainMenus[kNumMenus]; -// RgnHandle gCursorRgn; -short gCursorSet; -bool gDone = false; -bool gInForeground = true; bool gPlayingGame; //¥¥¥ Temp -bool gIsNewGame; -long gGameSavedTime; bool gDeadPlayerQuit; -bool gGameCompletedQuit; grs_screen *cit_screen; int num_args; @@ -80,7 +63,6 @@ char **arg_values; extern grs_screen *svga_screen; extern frc *svga_render_context; -errtype CheckFreeSpace(short checkRefNum); //------------------------------------------------------------------------------------ // Main function. @@ -110,10 +92,6 @@ int main(int argc, char **argv) { LoadHotkeyKeybinds(); LoadMoveKeybinds(); -#ifdef TESTING - SetupTests(); -#endif - // Process some startup arguments bool show_splash = !CheckArgument("-nosplash"); @@ -129,7 +107,6 @@ int main(int argc, char **argv) { gPlayingGame = TRUE; gDeadPlayerQuit = FALSE; - gGameCompletedQuit = FALSE; load_da_palette(); gr_clear(0xFF); @@ -156,7 +133,7 @@ int main(int argc, char **argv) { } bool CheckArgument(const char *arg) { - if (arg == NULL) + if (arg == nullptr) return false; for (int i = 1; i < num_args; i++) { @@ -167,17 +144,3 @@ bool CheckArgument(const char *arg) { return false; } - -//------------------------------------------------------------------------------------ -// Handle Quit menu command/apple event. -//------------------------------------------------------------------------------------ -void DoQuit(void) { gDone = true; } - -#define NEEDED_DISKSPACE 700000 -//------------------------------------------------------------------------------------ -// See if we have enough free space to save the file. -//------------------------------------------------------------------------------------ -errtype CheckFreeSpace(short checkRefNum) { - // FIXME: This should probably do something? - return (OK); -} diff --git a/src/ShockSrc/Shock.h b/src/ShockSrc/Shock.h index d4194616f..7b9597ca3 100644 --- a/src/ShockSrc/Shock.h +++ b/src/ShockSrc/Shock.h @@ -21,109 +21,10 @@ along with this program. If not, see . #include -//-------------------- -// Defines -//-------------------- -//#define TESTING 1 - -//#ifdef IS_REALLY_OSX - -//-------------------- -// Menus -//-------------------- -#ifdef TESTING -#define kNumMenus 6 -#else -#define kNumMenus 4 -#endif - -#define mApple 128 // Menu IDs -#define mFile 129 -#define mEdit 130 -#define mOptions 131 -#ifdef TESTING -#define mTests 132 -#define mTests2 133 -#endif - -#define fileNewGame 1 // File menu item IDs -#define fileOpenGame 2 -#define fileSaveGame 3 -#define fileSaveGameAs 4 -#define filePlayIntro 6 -#define fileResumeGame 8 -#define fileEndGame 9 -#define fileQuit 11 - -#define editUndo 1 // Edit menu item IDs -#define editCut 3 -#define editCopy 4 -#define editPaste 5 -#define editClear 6 - -#define optGameOptions 1 // Options menu item IDs -#define optGraphicsOptions 2 -#define optSoundOptions 3 - -#ifdef TESTING -#define testBrowseImages 1 // Tests menu item IDs -#define testBrowseFonts 2 -#define testLoadPalette 3 -#define testMoveKeys 5 -#define testMouse 6 -#define testPlayMovie 8 -#define testPlayMovie2x 9 -#define testPlayMovieDblSpd 10 -#define testPlayMovieHalfSpd 11 -#define testPlayIntro 13 -#define testPlayDeath 14 -#define testPlayEndGame 15 -#define testPlayCitadelVM 17 -#define testPlayDetachVM 18 -#define testPlayJettisonVM 19 -#define testPlayLaserMalVM 20 -#define testPlayShieldsVM 21 -#define testPlayAutoDesVM 22 -#define testPlayBark1 24 -#define testPlayBark2 25 -#define testPlayAlog1 26 -#define testPlayAlog2 27 - -#define testLoadLevelR 1 -#define testLoadLevel1 2 -#define testLoadLevel2 3 -#define testLoadLevel3 4 -#define testZoomIn 6 -#define testZoomOut 7 -#define testRender 9 -#endif - -//-------------------- -// Graphics Defines -//-------------------- -#define screenMaxX 640L -#define screenMaxY 480L - -//-------------------- -// File Types -//-------------------- -#define kAppFileType 'Shok' -#define kGameFileType 'Sgam' -#define kRsrcFileType 'Sres' - //-------------------- // Function Prototypes //-------------------- -typedef void *WindowPtr; // FIXME: get rid of UpdateWindow()? -typedef void *MenuHandle; // FIXME: what's gMainMenus about? int main(int argc, char **argv); -void HandleEvents(void); -void UpdateWindow(WindowPtr wind); -void DoCommand(unsigned long mResult); -bool DoSaveGame(void); -bool DoSaveGameAs(void); -void DoQuit(void); -void ScrollCredits(void); void InitSDL(); void SetSDLPalette(int index, int count, uchar *pal); @@ -134,53 +35,12 @@ bool CheckArgument(const char *name); //-------------------- // Public Globals //-------------------- -extern WindowPtr gMainWindow; -extern MenuHandle gMainMenus[kNumMenus]; -// extern RgnHandle gCursorRgn; -// extern short gCursorSet; -extern bool gDone; -extern bool gInForeground; -extern bool gIsNewGame; -// extern FSSpec gSavedGameFile; -extern long gGameSavedTime; -// extern Handle gExtraMemory; -// extern ColorSpec* gOriginalColors; extern unsigned long gRandSeed; -extern short gMainVRef; -// extern Handle gWatchCurs; -extern short gOriginalDepth; -extern short gStartupDepth; -extern short gLastAlertDepth; extern char *gScreenAddress; extern long gScreenRowbytes; extern short gScreenWide, gScreenHigh; -extern short gActiveWide, gActiveHigh; -extern short gActiveLeft, gActiveTop; -// extern Rect gActiveArea, gOffActiveArea; - -// extern Boolean gIsPowerPC; - -extern long gDataDirID; -extern short gDataVref; -extern long gCDDataDirID; -extern short gCDDataVref; -extern long gAlogDirID; -extern short gAlogVref; -extern long gBarkDirID; -extern short gBarkVref; extern grs_screen *cit_screen; extern SDL_Window *window; - -/*#else -extern short gOriginalDepth; -extern short gStartupDepth; -extern short gLastAlertDepth; -extern Ptr gScreenAddress; -extern long gScreenRowbytes; -extern short gScreenWide, gScreenHigh; -extern short gActiveWide, gActiveHigh; -extern short gActiveLeft, gActiveTop; -#endif*/