Tidy #defines

This commit is contained in:
Steve 2020-03-28 13:56:49 +00:00
parent 7e14550cc1
commit 6b89d7e8e7
25 changed files with 115 additions and 89 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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, ...);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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, ...);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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"))