From e9c62ea9a3451bfca3319c94bddeb493cba0c637 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 10 Jan 2021 09:14:37 -0800 Subject: [PATCH] Clean up unnecessary exports and add static keywords This patch cleans up unnecessary exports from header files (there were only a few), as well as adds the static keyword to all symbols that aren't exported and are specific to a file. This helps the linker out in not doing any unnecessary work, speeding it up and avoiding silent symbol conflicts (otherwise two symbols with the same name (and type/signature in C++) would quietly resolve as okay by the linker). --- desktop_version/src/FileSystemUtils.cpp | 16 +++++----- desktop_version/src/Game.cpp | 2 +- desktop_version/src/GraphicsResources.cpp | 2 +- desktop_version/src/GraphicsUtil.cpp | 8 ++--- desktop_version/src/GraphicsUtil.h | 2 -- desktop_version/src/Input.cpp | 8 ++--- desktop_version/src/Music.cpp | 4 +-- desktop_version/src/Render.cpp | 10 +++--- desktop_version/src/UtilityClass.cpp | 2 +- desktop_version/src/editor.cpp | 16 +++++----- desktop_version/src/editor.h | 11 ------- desktop_version/src/main.cpp | 38 +++++++++++------------ desktop_version/src/preloader.cpp | 10 +++--- 13 files changed, 58 insertions(+), 71 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index d40e7e98..df78da55 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -28,12 +28,12 @@ #define MAX_PATH PATH_MAX #endif -char saveDir[MAX_PATH] = {'\0'}; -char levelDir[MAX_PATH] = {'\0'}; +static char saveDir[MAX_PATH] = {'\0'}; +static char levelDir[MAX_PATH] = {'\0'}; -void PLATFORM_getOSDirectory(char* output); -void PLATFORM_migrateSaveData(char* output); -void PLATFORM_copyFile(const char *oldLocation, const char *newLocation); +static void PLATFORM_getOSDirectory(char* output); +static void PLATFORM_migrateSaveData(char* output); +static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation); int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath) { @@ -345,7 +345,7 @@ std::vector FILESYSTEM_getLevelDirFileNames() return list; } -void PLATFORM_getOSDirectory(char* output) +static void PLATFORM_getOSDirectory(char* output) { #ifdef _WIN32 /* This block is here for compatibility, do not touch it! */ @@ -358,7 +358,7 @@ void PLATFORM_getOSDirectory(char* output) #endif } -void PLATFORM_migrateSaveData(char* output) +static void PLATFORM_migrateSaveData(char* output) { char oldLocation[MAX_PATH]; char newLocation[MAX_PATH]; @@ -521,7 +521,7 @@ void PLATFORM_migrateSaveData(char* output) #endif } -void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) +static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) { char *data; size_t length, bytes_read, bytes_written; diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 09c5a9eb..93ae8298 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -26,7 +26,7 @@ #define strcasecmp stricmp #endif -bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button) +static bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button) { if (*pText == '0' || *pText == 'a' || diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index a006d791..52fa5d42 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -24,7 +24,7 @@ extern "C" ); } -SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool noAlpha = false) +static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool noAlpha = false) { //Temporary storage for the image that's loaded SDL_Surface* loadedImage = NULL; diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index 773385ec..b601dbdb 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -42,7 +42,7 @@ SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, i return preSurface; } -void DrawPixel( SDL_Surface *_surface, int x, int y, Uint32 pixel ) +static void DrawPixel( SDL_Surface *_surface, int x, int y, Uint32 pixel ) { int bpp = _surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ @@ -294,9 +294,9 @@ void BlitSurfaceTinted( } -int oldscrollamount = 0; -int scrollamount = 0; -bool isscrolling = 0; +static int oldscrollamount = 0; +static int scrollamount = 0; +static bool isscrolling = 0; void UpdateFilter() { diff --git a/desktop_version/src/GraphicsUtil.h b/desktop_version/src/GraphicsUtil.h index 66e0f8c8..996ffb57 100644 --- a/desktop_version/src/GraphicsUtil.h +++ b/desktop_version/src/GraphicsUtil.h @@ -13,8 +13,6 @@ void setRect(SDL_Rect& _r, int x, int y, int w, int h); SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height ); -void DrawPixel( SDL_Surface *surface, int x, int y, Uint32 pixel ); - Uint32 ReadPixel( SDL_Surface *surface, int x, int y ); SDL_Surface * ScaleSurface( SDL_Surface *Surface, int Width, int Height, SDL_Surface * Dest = NULL ); diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index b838df01..8e1945a2 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -15,7 +15,7 @@ #include "Script.h" #include "UtilityClass.h" -void updatebuttonmappings(int bind) +static void updatebuttonmappings(int bind) { for ( SDL_GameControllerButton i = SDL_CONTROLLER_BUTTON_A; @@ -173,7 +173,7 @@ void updatebuttonmappings(int bind) } } -void menuactionpress() +static void menuactionpress() { switch (game.currentmenuname) { @@ -2059,7 +2059,7 @@ void gameinput() } } -void mapmenuactionpress(); +static void mapmenuactionpress(); void mapinput() { @@ -2247,7 +2247,7 @@ void mapinput() } } -void mapmenuactionpress() +static void mapmenuactionpress() { switch (game.menupage) { diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 01eba0cb..370d2daf 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -8,7 +8,7 @@ #include "Map.h" #include "UtilityClass.h" -void songend(); +static void songend(); musicclass::musicclass() { @@ -158,7 +158,7 @@ void musicclass::init() } } -void songend() +static void songend() { extern musicclass music; music.songEnd = SDL_GetPerformanceCounter(); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index daced15b..20b8bf5e 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -12,13 +12,13 @@ #include "UtilityClass.h" #include "Version.h" -int tr; -int tg; -int tb; +static int tr; +static int tg; +static int tb; // Macro-like inline function used in maprender() // Used to keep some text positions the same in Flip Mode -int inline FLIP(int ypos) +static int inline FLIP(int ypos) { if (graphics.flipmode) { @@ -46,7 +46,7 @@ static inline void drawslowdowntext() } } -void menurender() +static void menurender() { int temp = 50; diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 5ab7535f..361be6da 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -6,7 +6,7 @@ #include /* Used by UtilityClass::GCString to generate a button list */ -const char *GCChar(SDL_GameControllerButton button) +static const char *GCChar(SDL_GameControllerButton button) { if (button == SDL_CONTROLLER_BUTTON_A) { diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 268cb5a5..61ca5f1b 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -60,7 +60,7 @@ editorclass::editorclass() } // comparison, not case sensitive. -bool compare_nocase (std::string first, std::string second) +static bool compare_nocase (std::string first, std::string second) { unsigned int i=0; while ( (i(time_ - timePrev); @@ -482,7 +482,7 @@ void inline deltaloop() } } -void inline fixedloop() +static void inline fixedloop() { // Update network per frame. NETWORK_update(); diff --git a/desktop_version/src/preloader.cpp b/desktop_version/src/preloader.cpp index 5f4e22d0..0d6a0acd 100644 --- a/desktop_version/src/preloader.cpp +++ b/desktop_version/src/preloader.cpp @@ -4,12 +4,12 @@ #include "KeyPoll.h" #include "UtilityClass.h" -int pre_fakepercent=0, pre_transition=30; -bool pre_startgame=false; -int pre_darkcol=0, pre_lightcol=0, pre_curcol=0, pre_coltimer=0, pre_offset=0; +static int pre_fakepercent=0, pre_transition=30; +static bool pre_startgame=false; +static int pre_darkcol=0, pre_lightcol=0, pre_curcol=0, pre_coltimer=0, pre_offset=0; -int pre_frontrectx=30, pre_frontrecty=20, pre_frontrectw=260, pre_frontrecth=200; -int pre_temprectx=0, pre_temprecty=0, pre_temprectw=320, pre_temprecth=240; +static int pre_frontrectx=30, pre_frontrecty=20, pre_frontrectw=260, pre_frontrecth=200; +static int pre_temprectx=0, pre_temprecty=0, pre_temprectw=320, pre_temprecth=240; void preloaderinput() {