From d8eb896456bcc39905e5bf59edd33fc5b2364989 Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 20 Dec 2015 12:25:20 +0000 Subject: [PATCH] Enable debug mode by passing -debug. --- common.mk | 1 - makefile | 2 +- makefile.win32 | 2 +- src/battle/battle.c | 4 +- src/battle/battle.h | 1 + src/draw/draw.c | 11 ++--- src/galaxy/mission.c | 25 ++++++------ src/galaxy/mission.h | 1 + src/main.c | 40 ++++++++++++++---- src/structs.h | 1 + src/system/dev.c | 97 ++++++++++++++++++++++---------------------- 11 files changed, 106 insertions(+), 79 deletions(-) diff --git a/common.mk b/common.mk index 3313f52..99c15d9 100644 --- a/common.mk +++ b/common.mk @@ -1,6 +1,5 @@ VERSION = 0.5 REVISION = $(shell date +"%y%m%d") -DEBUG = $(shell stat dev 1>/dev/null 2>&1 && echo 1 || echo 0) SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test vpath %.c $(SEARCHPATH) diff --git a/makefile b/makefile index c6eb1b3..aaab585 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,7 @@ OBJS += unixInit.o include common.mk -CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDEBUG=$(DEBUG) -DDATA_DIR=\"$(DATA_DIR)\" +CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" CXXFLAGS += -Wall -ansi -pedantic -Werror -Wstrict-prototypes CXXFLAGS += -g -lefence diff --git a/makefile.win32 b/makefile.win32 index 448a4a3..8fc0df6 100644 --- a/makefile.win32 +++ b/makefile.win32 @@ -6,7 +6,7 @@ LIBPATH = /usr/x86_64-w64-mingw32/lib SEARCHPATH += src/plat/win32 OBJS += win32Init.o -CXXFLAGS += `$(SDLC) --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDEBUG=$(DEBUG) -DDATA_DIR=\"$(DATA_DIR)\" +CXXFLAGS += `$(SDLC) --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" CXXFLAGS += -Wall -ansi -pedantic -Werror -Wstrict-prototypes CXXFLAGS += -g -lefence diff --git a/src/battle/battle.c b/src/battle/battle.c index b8ca07d..0cb641e 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -270,13 +270,11 @@ static void handleKeyboard(void) battle.status = MS_PAUSED; } - #if DEBUG - if (app.keyboard[SDL_SCANCODE_F10]) + if (dev.debug && app.keyboard[SDL_SCANCODE_F10]) { completeMission(); battle.missionFinishedTimer = -FPS; } - #endif } static void start(void) diff --git a/src/battle/battle.h b/src/battle/battle.h index 398fb7b..7f9eb9b 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -81,5 +81,6 @@ extern void drawDebris(void); extern App app; extern Battle battle; +extern Dev dev; extern Entity *player; extern Game game; diff --git a/src/draw/draw.c b/src/draw/draw.c index aeaac23..4ddc88e 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -46,13 +46,14 @@ void prepareScene(void) void presentScene(void) { - #if DEBUG - drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); - if (dev.showFPS) + if (dev.debug) { - drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps); + drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); + if (dev.showFPS) + { + drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps); + } } - #endif drawMouse(); diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index ac47827..ebd5b97 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -702,26 +702,27 @@ Mission *getMission(char *filename) int isMissionAvailable(Mission *mission, Mission *prev) { - #if !DEBUG Mission *reqMission; - if (mission->requires) + if (!dev.debug) { - if (strcmp(mission->requires, "PREVIOUS") == 0) + if (mission->requires) { - return prev->completed; - } - else - { - reqMission = getMission(mission->requires); - - if (reqMission != NULL) + if (strcmp(mission->requires, "PREVIOUS") == 0) { - return reqMission->completed; + return prev->completed; + } + else + { + reqMission = getMission(mission->requires); + + if (reqMission != NULL) + { + return reqMission->completed; + } } } } - #endif return 1; } diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 0bbd7e5..09de96d 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -48,5 +48,6 @@ extern char *getFileLocation(char *filename); extern void updateCapitalShipComponentNames(Entity *parent); extern Battle battle; +extern Dev dev; extern Entity *player; extern Game game; diff --git a/src/main.c b/src/main.c index 6ed4b83..b009fa5 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "main.h" +static void handleArguments(int argc, char *argv[]); + int main(int argc, char *argv[]) { float td; @@ -40,14 +42,7 @@ int main(int argc, char *argv[]) initGameSystem(); - if (argc > 1) - { - loadTestMission(argv[1]); - } - else - { - initTitle(); - } + handleArguments(argc, argv); dev.fps = frames = td = 0; then = SDL_GetTicks(); @@ -126,3 +121,32 @@ int main(int argc, char *argv[]) return 0; } + +static void handleArguments(int argc, char *argv[]) +{ + int i; + int testingMission = 0; + + for (i = 1 ; i < argc ; i++) + { + /* assume this is filename for testing */ + if (argv[i][0] != '-') + { + loadTestMission(argv[i]); + + testingMission = 1; + } + else + { + if (strcmp(argv[i], "-debug") == 0) + { + dev.debug = 1; + } + } + } + + if (!testingMission) + { + initTitle(); + } +} diff --git a/src/structs.h b/src/structs.h index 2d8cd9d..c38e81e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -37,6 +37,7 @@ typedef struct GridCell GridCell; typedef struct ScriptRunner ScriptRunner; typedef struct { + int debug; int takeScreenshots; int noAIWeapons; int showFPS; diff --git a/src/system/dev.c b/src/system/dev.c index fe04806..648a471 100644 --- a/src/system/dev.c +++ b/src/system/dev.c @@ -22,54 +22,55 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void doDevKeys(void) { - #if DEBUG - if (app.keyboard[SDL_SCANCODE_1]) + if (dev.debug) { - dev.playerImmortal = !dev.playerImmortal; - app.keyboard[SDL_SCANCODE_1] = 0; - printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal); + if (app.keyboard[SDL_SCANCODE_1]) + { + dev.playerImmortal = !dev.playerImmortal; + app.keyboard[SDL_SCANCODE_1] = 0; + printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal); + } + + if (app.keyboard[SDL_SCANCODE_2]) + { + dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles; + app.keyboard[SDL_SCANCODE_2] = 0; + printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles); + } + + if (app.keyboard[SDL_SCANCODE_3]) + { + dev.noAIWeapons = !dev.noAIWeapons; + app.keyboard[SDL_SCANCODE_3] = 0; + printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons); + } + + if (app.keyboard[SDL_SCANCODE_4]) + { + dev.noEntityActions = !dev.noEntityActions; + app.keyboard[SDL_SCANCODE_4] = 0; + printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions); + } + + if (app.keyboard[SDL_SCANCODE_5]) + { + dev.allImmortal = !dev.allImmortal; + app.keyboard[SDL_SCANCODE_5] = 0; + printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal); + } + + if (app.keyboard[SDL_SCANCODE_9]) + { + dev.showFPS = !dev.showFPS; + app.keyboard[SDL_SCANCODE_9] = 0; + printf("DEBUG: dev.showFPS=%d\n", dev.showFPS); + } + + if (app.keyboard[SDL_SCANCODE_0]) + { + dev.takeScreenshots = !dev.takeScreenshots; + app.keyboard[SDL_SCANCODE_0] = 0; + printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots); + } } - - if (app.keyboard[SDL_SCANCODE_2]) - { - dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles; - app.keyboard[SDL_SCANCODE_2] = 0; - printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles); - } - - if (app.keyboard[SDL_SCANCODE_3]) - { - dev.noAIWeapons = !dev.noAIWeapons; - app.keyboard[SDL_SCANCODE_3] = 0; - printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons); - } - - if (app.keyboard[SDL_SCANCODE_4]) - { - dev.noEntityActions = !dev.noEntityActions; - app.keyboard[SDL_SCANCODE_4] = 0; - printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions); - } - - if (app.keyboard[SDL_SCANCODE_5]) - { - dev.allImmortal = !dev.allImmortal; - app.keyboard[SDL_SCANCODE_5] = 0; - printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal); - } - - if (app.keyboard[SDL_SCANCODE_9]) - { - dev.showFPS = !dev.showFPS; - app.keyboard[SDL_SCANCODE_9] = 0; - printf("DEBUG: dev.showFPS=%d\n", dev.showFPS); - } - - if (app.keyboard[SDL_SCANCODE_0]) - { - dev.takeScreenshots = !dev.takeScreenshots; - app.keyboard[SDL_SCANCODE_0] = 0; - printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots); - } - #endif }