From 6b89d7e8e734ea98d2362ea30086d07404c256a2 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 28 Mar 2020 13:56:49 +0000 Subject: [PATCH] Tidy #defines --- src/battle/ai.h | 10 ++--- src/battle/battle.h | 8 ++-- src/battle/bullets.h | 8 ++-- src/battle/capitalShips.h | 4 +- src/battle/debris.h | 4 +- src/battle/effects.h | 2 +- src/battle/entities.h | 6 +-- src/battle/hud.h | 2 +- src/battle/jumpgate.h | 2 +- src/battle/messageBox.h | 2 +- src/battle/mine.h | 6 +-- src/battle/player.h | 4 +- src/battle/quadtree.h | 4 +- src/battle/rope.h | 2 +- src/challenges/challengeHome.h | 14 +++---- src/galaxy/galacticMap.h | 16 +++---- src/game/credits.h | 2 +- src/game/options.h | 4 +- src/game/stats.h | 2 +- src/game/title.h | 12 +++--- src/game/trophies.h | 2 +- src/system/sound.h | 4 +- src/system/text.h | 6 +-- src/system/widgets.h | 2 +- tools/tidyHeaders.sh | 76 +++++++++++++++++++++++----------- 25 files changed, 115 insertions(+), 89 deletions(-) diff --git a/src/battle/ai.h b/src/battle/ai.h index 263ffd8..4cab502 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -20,11 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define AI_EVADE 0 -#define AI_FALLBACK 1 -#define AI_HUNT 2 -#define TURN_SPEED 4 -#define TURN_THRESHOLD 2 +#define AI_EVADE 0 +#define AI_FALLBACK 1 +#define AI_HUNT 2 +#define TURN_SPEED 4 +#define TURN_THRESHOLD 2 extern void addHudMessage(SDL_Color c, char *format, ...); extern void applyFighterBrakes(void); diff --git a/src/battle/battle.h b/src/battle/battle.h index 0ee1775..7ccfdf6 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -22,10 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../json/cJSON.h" -#define SHOW_BATTLE 0 -#define SHOW_MENU 1 -#define SHOW_OBJECTIVES 2 -#define SHOW_OPTIONS 3 +#define SHOW_BATTLE 0 +#define SHOW_MENU 1 +#define SHOW_OBJECTIVES 2 +#define SHOW_OPTIONS 3 extern void awardTrophy(char *id); extern void blitScaled(AtlasImage *atlasImage, int x, int y, int w, int h, int center); diff --git a/src/battle/bullets.h b/src/battle/bullets.h index 80c7209..f403988 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -22,10 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../json/cJSON.h" -#define INITIAL_BULLET_DRAW_CAPACITY 32 -#define MISSILE_LIFE (FPS * 30) -#define TURN_SPEED 2 -#define TURN_THRESHOLD 3 +#define INITIAL_BULLET_DRAW_CAPACITY 32 +#define MISSILE_LIFE (FPS * 30) +#define TURN_SPEED 2 +#define TURN_THRESHOLD 3 extern void addBulletHitEffect(int x, int y, int r, int g, int b); extern void addMissileEngineEffect(Bullet *b); diff --git a/src/battle/capitalShips.h b/src/battle/capitalShips.h index d796e61..fdd8534 100644 --- a/src/battle/capitalShips.h +++ b/src/battle/capitalShips.h @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../json/cJSON.h" -#define TURN_SPEED 0.1 -#define TURN_THRESHOLD 2 +#define TURN_SPEED 0.1 +#define TURN_THRESHOLD 2 extern void addDebris(int x, int y, int amount); extern void addLargeEngineEffect(void); diff --git a/src/battle/debris.h b/src/battle/debris.h index 9b09c90..61526cd 100644 --- a/src/battle/debris.h +++ b/src/battle/debris.h @@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../json/cJSON.h" -#define INITIAL_DEBRIS_DRAW_CAPACITY 32 -#define MAX_DEBRIS_TEXTURES 6 +#define INITIAL_DEBRIS_DRAW_CAPACITY 32 +#define MAX_DEBRIS_TEXTURES 6 extern void addDebrisFire(int x, int y); extern void blitRotated(AtlasImage *atlasImage, int x, int y, float angle); diff --git a/src/battle/effects.h b/src/battle/effects.h index caf2f5f..3a7309a 100644 --- a/src/battle/effects.h +++ b/src/battle/effects.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define INITIAL_EFFECT_DRAW_CAPACITY 128 +#define INITIAL_EFFECT_DRAW_CAPACITY 128 extern void blitScaled(AtlasImage *atlasImage, int x, int y, int w, int h, int center); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); diff --git a/src/battle/entities.h b/src/battle/entities.h index 78a11d8..03ffce1 100644 --- a/src/battle/entities.h +++ b/src/battle/entities.h @@ -20,9 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define DISABLED_GLOW_MAX 255 -#define DISABLED_GLOW_MIN 128 -#define DISABLED_GLOW_SPEED 3 +#define DISABLED_GLOW_MAX 255 +#define DISABLED_GLOW_MIN 128 +#define DISABLED_GLOW_SPEED 3 extern void addToQuadtree(Entity *e, Quadtree *root); extern void awardTrophy(char *id); diff --git a/src/battle/hud.h b/src/battle/hud.h index 599696d..c513db0 100644 --- a/src/battle/hud.h +++ b/src/battle/hud.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define MAX_HUD_MESSAGES 6 +#define MAX_HUD_MESSAGES 6 extern void blit(AtlasImage *atlasImage, int x, int y, int center); extern void blitRotated(AtlasImage *atlasImage, int x, int y, float angle); diff --git a/src/battle/jumpgate.h b/src/battle/jumpgate.h index 4ee9cbf..b2e966f 100644 --- a/src/battle/jumpgate.h +++ b/src/battle/jumpgate.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define ESCAPE_DISTANCE 256 +#define ESCAPE_DISTANCE 256 extern void addDebris(int x, int y, int amount); extern void addSmallExplosion(void); diff --git a/src/battle/messageBox.h b/src/battle/messageBox.h index d6566a4..3815ea8 100644 --- a/src/battle/messageBox.h +++ b/src/battle/messageBox.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define MSG_BOX_TEXT_WIDTH 600 +#define MSG_BOX_TEXT_WIDTH 600 extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern int getWrappedTextHeight(char *text, int size); diff --git a/src/battle/mine.h b/src/battle/mine.h index 07dc08d..d88306d 100644 --- a/src/battle/mine.h +++ b/src/battle/mine.h @@ -20,9 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define DAMAGE_RANGE 250 -#define SYSTEM_POWER 50 -#define TRIGGER_RANGE 150 +#define DAMAGE_RANGE 250 +#define SYSTEM_POWER 50 +#define TRIGGER_RANGE 150 extern void addMineExplosion(void); extern void awardTrophy(char *id); diff --git a/src/battle/player.h b/src/battle/player.h index 4b644ea..22bf895 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" #include "../json/cJSON.h" -#define MAX_SELECTABLE_PLAYERS 8 -#define MAX_SELECTABLE_TARGETS 8 +#define MAX_SELECTABLE_PLAYERS 8 +#define MAX_SELECTABLE_TARGETS 8 extern void addECMEffect(Entity *ent); extern void addHudMessage(SDL_Color c, char *format, ...); diff --git a/src/battle/quadtree.h b/src/battle/quadtree.h index b7a36a3..ffc108e 100644 --- a/src/battle/quadtree.h +++ b/src/battle/quadtree.h @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define QT_INITIAL_CAPACITY 8 -#define QT_MAX_DEPTH 5 +#define QT_INITIAL_CAPACITY 8 +#define QT_MAX_DEPTH 5 extern void *resize(void *array, int oldSize, int newSize); diff --git a/src/battle/rope.h b/src/battle/rope.h index dcc832f..5db16fb 100644 --- a/src/battle/rope.h +++ b/src/battle/rope.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define ROPE_DISTANCE 128 +#define ROPE_DISTANCE 128 extern void addHudMessage(SDL_Color c, char *format, ...); extern Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore); diff --git a/src/challenges/challengeHome.h b/src/challenges/challengeHome.h index 7c7cc72..29cb5e4 100644 --- a/src/challenges/challengeHome.h +++ b/src/challenges/challengeHome.h @@ -20,13 +20,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define CHALLENGES_PER_PAGE 14 -#define SHOW_CHALLENGES 0 -#define SHOW_FIGHTER_DB 5 -#define SHOW_MENU 1 -#define SHOW_OPTIONS 2 -#define SHOW_STATS 3 -#define SHOW_TROPHIES 4 +#define CHALLENGES_PER_PAGE 14 +#define SHOW_CHALLENGES 0 +#define SHOW_FIGHTER_DB 5 +#define SHOW_MENU 1 +#define SHOW_OPTIONS 2 +#define SHOW_STATS 3 +#define SHOW_TROPHIES 4 extern void autoSizeWidgetButtons(char *group, int recenter); extern void awardChallengeTrophies(void); diff --git a/src/galaxy/galacticMap.h b/src/galaxy/galacticMap.h index ad347fd..1462d9c 100644 --- a/src/galaxy/galacticMap.h +++ b/src/galaxy/galacticMap.h @@ -20,14 +20,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define MAX_LISTED_MISSIONS 9 -#define SHOW_FIGHTER_DB 6 -#define SHOW_GALAXY 0 -#define SHOW_MENU 2 -#define SHOW_OPTIONS 3 -#define SHOW_STAR_SYSTEM 1 -#define SHOW_STATS 4 -#define SHOW_TROPHIES 5 +#define MAX_LISTED_MISSIONS 9 +#define SHOW_FIGHTER_DB 6 +#define SHOW_GALAXY 0 +#define SHOW_MENU 2 +#define SHOW_OPTIONS 3 +#define SHOW_STAR_SYSTEM 1 +#define SHOW_STATS 4 +#define SHOW_TROPHIES 5 extern void autoSizeWidgetButtons(char *group, int recenter); extern void awardCampaignTrophies(void); diff --git a/src/game/credits.h b/src/game/credits.h index b27e758..fd3d886 100644 --- a/src/game/credits.h +++ b/src/game/credits.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" #include "../json/cJSON.h" -#define CREDIT_LINE_LIMIT (UI_WIDTH - 300) +#define CREDIT_LINE_LIMIT (UI_WIDTH - 300) extern void blit(AtlasImage *atlasImage, int x, int y, int centered); extern void drawBackground(SDL_Texture *texture); diff --git a/src/game/options.h b/src/game/options.h index 25e065b..b67044a 100644 --- a/src/game/options.h +++ b/src/game/options.h @@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "SDL2/SDL_mixer.h" -#define SHOW_CONTROLS 1 -#define SHOW_MAIN 0 +#define SHOW_CONTROLS 1 +#define SHOW_MAIN 0 extern void drawControls(void); extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); diff --git a/src/game/stats.h b/src/game/stats.h index 73671bc..ac0ade9 100644 --- a/src/game/stats.h +++ b/src/game/stats.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define STATS_PER_PAGE 9 +#define STATS_PER_PAGE 9 extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...); extern void drawWidgets(char *groupName); diff --git a/src/game/title.h b/src/game/title.h index 4bba94d..e750a5c 100644 --- a/src/game/title.h +++ b/src/game/title.h @@ -20,12 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define NUM_FIGHTERS 12 -#define SHOW_FIGHTER_DB 4 -#define SHOW_OPTIONS 2 -#define SHOW_STATS 1 -#define SHOW_TITLE 0 -#define SHOW_TROPHIES 3 +#define NUM_FIGHTERS 12 +#define SHOW_FIGHTER_DB 4 +#define SHOW_OPTIONS 2 +#define SHOW_STATS 1 +#define SHOW_TITLE 0 +#define SHOW_TROPHIES 3 extern void addEngineEffect(void); extern void autoSizeWidgetButtons(char *group, int recenter); diff --git a/src/game/trophies.h b/src/game/trophies.h index cda143a..ac61eb7 100644 --- a/src/game/trophies.h +++ b/src/game/trophies.h @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "time.h" -#define TROPHIES_PER_PAGE 4 +#define TROPHIES_PER_PAGE 4 extern void awardPandoranCraftTrophy(void); extern void blit(AtlasImage *atlasImage, int x, int y, int centered); diff --git a/src/system/sound.h b/src/system/sound.h index 6df1680..28530f8 100644 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "SDL2/SDL_mixer.h" -#define MAX_BATTLE_SOUND_DISTANCE 1500 -#define MIN_BATTLE_SOUND_DISTANCE 100 +#define MAX_BATTLE_SOUND_DISTANCE 1500 +#define MIN_BATTLE_SOUND_DISTANCE 100 extern float getAngle(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2); diff --git a/src/system/text.h b/src/system/text.h index e21960d..61f9cc2 100644 --- a/src/system/text.h +++ b/src/system/text.h @@ -26,9 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define FONT_SIZE 32 -#define FONT_TEXTURE_SIZE 512 -#define MAX_WORD_LENGTH 128 +#define FONT_SIZE 32 +#define FONT_TEXTURE_SIZE 512 +#define MAX_WORD_LENGTH 128 extern char *getFileLocation(char *filename); extern unsigned long hashcode(const char *str); diff --git a/src/system/widgets.h b/src/system/widgets.h index 487d412..f4d7e6a 100644 --- a/src/system/widgets.h +++ b/src/system/widgets.h @@ -33,9 +33,9 @@ extern char **getFileList(char *dir, int *count); extern long lookup(char *name); extern void playSound(int id); extern char *readFile(char *filename); +extern void setAtlasColor(int r, int g, int b, int a); extern void updateControlButton(char *name); extern void updateControlKey(char *name); -extern void setAtlasColor(int r, int g, int b, int a); extern App app; extern Colors colors; diff --git a/tools/tidyHeaders.sh b/tools/tidyHeaders.sh index 26bc1d6..8d38d5e 100755 --- a/tools/tidyHeaders.sh +++ b/tools/tidyHeaders.sh @@ -28,10 +28,10 @@ function funcSort($a, $b) { $a = str_replace("*", "", $a); $b = str_replace("*", "", $b); - + $aParts = explode(" ", $a); $bParts = explode(" ", $b); - + return strcmp($aParts[2], $bParts[2]); } @@ -40,9 +40,9 @@ function updateExterns($header, $defines, $functions, $structs) asort($defines); usort($functions, "funcSort"); asort($structs); - + $newHeader = []; - + foreach ($header as $line) { $newHeader[] = $line; @@ -53,7 +53,7 @@ function updateExterns($header, $defines, $functions, $structs) $newHeader[] = "\n"; $newHeader = array_merge($newHeader, $defines); } - + if (count($functions) > 0) { $newHeader[] = "\n"; @@ -79,32 +79,32 @@ function cleanHeader($headerFile) $bodyFile = $headerFile; $bodyFile[strlen($bodyFile) - 1] = 'c'; - + if (file_exists($bodyFile)) { $header = file($headerFile); $body = file_get_contents($bodyFile); - $isMain = strpos($body, "int main(int argc, char *argv[])"); + $isMain = strpos($body, "int main("); $lines = []; $defines = []; $functions = []; $structs = []; - + $i = 0; $hasChanges = false; - + foreach ($header as $line) { if ((preg_match("/extern|define/", $line) || preg_match("/;$/", $line))) { preg_match($func_pattern, $line, $matches); - + if (count($matches) == 3) { unset($header[$i]); - + $extern = $matches[2]; - + if (!preg_match_all("/\b${extern}\b/", $body)) { if (!$hasChanges) @@ -119,17 +119,17 @@ function cleanHeader($headerFile) $functions[] = $line; } } - + preg_match($struct_pattern, $line, $matches); if (count($matches) == 2) { unset($header[$i]); - + $extern = $matches[1]; - + $externs[] = $extern; - + if (!$isMain) { if (!preg_match_all("/\b${extern}\b/", $body)) @@ -151,17 +151,17 @@ function cleanHeader($headerFile) $structs[] = $line; } } - + preg_match($define_pattern, $line, $matches); if (count($matches) == 2) { unset($header[$i]); - + $extern = $matches[1]; - + $externs[] = $extern; - + if (strstr($body, "$extern") === FALSE) { if (!$hasChanges) @@ -177,7 +177,7 @@ function cleanHeader($headerFile) } } } - + $i++; } @@ -192,13 +192,15 @@ function cleanHeader($headerFile) } } while ($wasBlank); - + $defines = array_unique($defines); $functions = array_unique($functions); $structs = array_unique($structs); - + + $defines = alignDefines($defines); + $header = updateExterns($header, $defines, $functions, $structs); - + if ($UPDATE_FILES) { file_put_contents($headerFile, $header); @@ -206,12 +208,36 @@ function cleanHeader($headerFile) } } +function alignDefines($defines) +{ + $newAligns = []; + $largest = 0; + $defineName; + $defineValue; + + foreach ($defines as $define) + { + sscanf($define, "%*s %s", $defineName); + + $largest = max($largest, strlen($defineName) + 4); + } + + foreach ($defines as $define) + { + sscanf($define, "%*s %s %[^\n]", $defineName, $defineValue); + + $newAligns[] = "#define " . str_pad($defineName, $largest, " ") . $defineValue . "\n"; + } + + return $newAligns; +} + function recurseDir($dir) { if ($dir != "../src/json") { $files = array_diff(scandir($dir), array('..', '.')); - + foreach ($files as $file) { if (is_dir("$dir/$file"))