Enable debug mode by passing -debug.

This commit is contained in:
Steve 2015-12-20 12:25:20 +00:00
parent a22e2a9f8d
commit d8eb896456
11 changed files with 106 additions and 79 deletions

View File

@ -1,6 +1,5 @@
VERSION = 0.5 VERSION = 0.5
REVISION = $(shell date +"%y%m%d") 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 SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test
vpath %.c $(SEARCHPATH) vpath %.c $(SEARCHPATH)

View File

@ -8,7 +8,7 @@ OBJS += unixInit.o
include common.mk 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 += -Wall -ansi -pedantic -Werror -Wstrict-prototypes
CXXFLAGS += -g -lefence CXXFLAGS += -g -lefence

View File

@ -6,7 +6,7 @@ LIBPATH = /usr/x86_64-w64-mingw32/lib
SEARCHPATH += src/plat/win32 SEARCHPATH += src/plat/win32
OBJS += win32Init.o 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 += -Wall -ansi -pedantic -Werror -Wstrict-prototypes
CXXFLAGS += -g -lefence CXXFLAGS += -g -lefence

View File

@ -270,13 +270,11 @@ static void handleKeyboard(void)
battle.status = MS_PAUSED; battle.status = MS_PAUSED;
} }
#if DEBUG if (dev.debug && app.keyboard[SDL_SCANCODE_F10])
if (app.keyboard[SDL_SCANCODE_F10])
{ {
completeMission(); completeMission();
battle.missionFinishedTimer = -FPS; battle.missionFinishedTimer = -FPS;
} }
#endif
} }
static void start(void) static void start(void)

View File

@ -81,5 +81,6 @@ extern void drawDebris(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;
extern Dev dev;
extern Entity *player; extern Entity *player;
extern Game game; extern Game game;

View File

@ -46,13 +46,14 @@ void prepareScene(void)
void presentScene(void) void presentScene(void)
{ {
#if DEBUG if (dev.debug)
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); 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(); drawMouse();

View File

@ -702,26 +702,27 @@ Mission *getMission(char *filename)
int isMissionAvailable(Mission *mission, Mission *prev) int isMissionAvailable(Mission *mission, Mission *prev)
{ {
#if !DEBUG
Mission *reqMission; Mission *reqMission;
if (mission->requires) if (!dev.debug)
{ {
if (strcmp(mission->requires, "PREVIOUS") == 0) if (mission->requires)
{ {
return prev->completed; if (strcmp(mission->requires, "PREVIOUS") == 0)
}
else
{
reqMission = getMission(mission->requires);
if (reqMission != NULL)
{ {
return reqMission->completed; return prev->completed;
}
else
{
reqMission = getMission(mission->requires);
if (reqMission != NULL)
{
return reqMission->completed;
}
} }
} }
} }
#endif
return 1; return 1;
} }

View File

@ -48,5 +48,6 @@ extern char *getFileLocation(char *filename);
extern void updateCapitalShipComponentNames(Entity *parent); extern void updateCapitalShipComponentNames(Entity *parent);
extern Battle battle; extern Battle battle;
extern Dev dev;
extern Entity *player; extern Entity *player;
extern Game game; extern Game game;

View File

@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "main.h" #include "main.h"
static void handleArguments(int argc, char *argv[]);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
float td; float td;
@ -40,14 +42,7 @@ int main(int argc, char *argv[])
initGameSystem(); initGameSystem();
if (argc > 1) handleArguments(argc, argv);
{
loadTestMission(argv[1]);
}
else
{
initTitle();
}
dev.fps = frames = td = 0; dev.fps = frames = td = 0;
then = SDL_GetTicks(); then = SDL_GetTicks();
@ -126,3 +121,32 @@ int main(int argc, char *argv[])
return 0; 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();
}
}

View File

@ -37,6 +37,7 @@ typedef struct GridCell GridCell;
typedef struct ScriptRunner ScriptRunner; typedef struct ScriptRunner ScriptRunner;
typedef struct { typedef struct {
int debug;
int takeScreenshots; int takeScreenshots;
int noAIWeapons; int noAIWeapons;
int showFPS; int showFPS;

View File

@ -22,54 +22,55 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void doDevKeys(void) void doDevKeys(void)
{ {
#if DEBUG if (dev.debug)
if (app.keyboard[SDL_SCANCODE_1])
{ {
dev.playerImmortal = !dev.playerImmortal; if (app.keyboard[SDL_SCANCODE_1])
app.keyboard[SDL_SCANCODE_1] = 0; {
printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal); dev.playerImmortal = !dev.playerImmortal;
} app.keyboard[SDL_SCANCODE_1] = 0;
printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal);
}
if (app.keyboard[SDL_SCANCODE_2]) if (app.keyboard[SDL_SCANCODE_2])
{ {
dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles; dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles;
app.keyboard[SDL_SCANCODE_2] = 0; app.keyboard[SDL_SCANCODE_2] = 0;
printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles); printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles);
} }
if (app.keyboard[SDL_SCANCODE_3]) if (app.keyboard[SDL_SCANCODE_3])
{ {
dev.noAIWeapons = !dev.noAIWeapons; dev.noAIWeapons = !dev.noAIWeapons;
app.keyboard[SDL_SCANCODE_3] = 0; app.keyboard[SDL_SCANCODE_3] = 0;
printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons); printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons);
} }
if (app.keyboard[SDL_SCANCODE_4]) if (app.keyboard[SDL_SCANCODE_4])
{ {
dev.noEntityActions = !dev.noEntityActions; dev.noEntityActions = !dev.noEntityActions;
app.keyboard[SDL_SCANCODE_4] = 0; app.keyboard[SDL_SCANCODE_4] = 0;
printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions); printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions);
} }
if (app.keyboard[SDL_SCANCODE_5]) if (app.keyboard[SDL_SCANCODE_5])
{ {
dev.allImmortal = !dev.allImmortal; dev.allImmortal = !dev.allImmortal;
app.keyboard[SDL_SCANCODE_5] = 0; app.keyboard[SDL_SCANCODE_5] = 0;
printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal); printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal);
} }
if (app.keyboard[SDL_SCANCODE_9]) if (app.keyboard[SDL_SCANCODE_9])
{ {
dev.showFPS = !dev.showFPS; dev.showFPS = !dev.showFPS;
app.keyboard[SDL_SCANCODE_9] = 0; app.keyboard[SDL_SCANCODE_9] = 0;
printf("DEBUG: dev.showFPS=%d\n", dev.showFPS); printf("DEBUG: dev.showFPS=%d\n", dev.showFPS);
} }
if (app.keyboard[SDL_SCANCODE_0]) if (app.keyboard[SDL_SCANCODE_0])
{ {
dev.takeScreenshots = !dev.takeScreenshots; dev.takeScreenshots = !dev.takeScreenshots;
app.keyboard[SDL_SCANCODE_0] = 0; app.keyboard[SDL_SCANCODE_0] = 0;
printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots); printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots);
}
} }
#endif
} }