From 7f257f2740e42c17f6448be08d71c57a5c1df5ed Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 12 Feb 2018 18:26:47 +0000 Subject: [PATCH] Set config defaults in init.c --- src/game/game.c | 2 -- src/system/controls.c | 27 ---------------- src/system/init.c | 73 ++++++++++++++++++++++++++++++++++++++++--- src/system/init.h | 3 +- 4 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/game/game.c b/src/game/game.c index 0612953..b79e61d 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -35,8 +35,6 @@ void initGame(void) game.timePlayed = 0; loadMetaInfo(); - - initControls(); } void addRescuedMIA(char *name) diff --git a/src/system/controls.c b/src/system/controls.c index 49c73f0..5fb39c6 100644 --- a/src/system/controls.c +++ b/src/system/controls.c @@ -20,33 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "controls.h" -void initControls(void) -{ - int i; - - app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A; - app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D; - app.config.keyControls[CONTROL_UP] = SDL_SCANCODE_W; - app.config.keyControls[CONTROL_DOWN] = SDL_SCANCODE_S; - app.config.keyControls[CONTROL_JUMP] = SDL_SCANCODE_I; - app.config.keyControls[CONTROL_FIRE] = SDL_SCANCODE_J; - app.config.keyControls[CONTROL_JETPACK] = SDL_SCANCODE_L; - app.config.keyControls[CONTROL_MAP] = SDL_SCANCODE_M; - app.config.keyControls[CONTROL_PAUSE] = SDL_SCANCODE_TAB; - - /* can't use memset here, as it doesn't work */ - for (i = 0 ; i < CONTROL_MAX ; i++) - { - app.config.joypadControls[i] = -1; - } - - app.config.joypadControls[CONTROL_JUMP] = 1; - app.config.joypadControls[CONTROL_FIRE] = 3; - app.config.joypadControls[CONTROL_JETPACK] = 2; - app.config.joypadControls[CONTROL_MAP] = 6; - app.config.joypadControls[CONTROL_PAUSE] = 7; -} - int isControl(int type) { int key, btn; diff --git a/src/system/init.c b/src/system/init.c index 6333541..7ce437e 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void loadConfig(void); static void initJoypad(void); +static void showLoadingStep(float step, float maxSteps); void init18N(int argc, char *argv[]) { @@ -94,8 +95,6 @@ void initSDL(void) } initJoypad(); - - initControls(); } static void initJoypad(void) @@ -127,7 +126,6 @@ void initGameSystem(void) initLookups, initGraphics, initFonts, - initControls, initAtlas, initSounds, initSprites, @@ -138,18 +136,85 @@ void initGameSystem(void) for (i = 0 ; i < numInitFuns ; i++) { - /*showLoadingStep(i + 1, numInitFuns);*/ + showLoadingStep(i + 1, numInitFuns); initFuncs[i](); } } +/* + * Just in case the initial loading takes a while on the target machine. The rest of the loading a pretty quick by comparison. + */ +static void showLoadingStep(float step, float maxSteps) +{ + SDL_Rect r; + + prepareScene(); + + r.w = SCREEN_WIDTH - 400; + r.h = 14; + r.x = (SCREEN_WIDTH / 2) - r.w / 2; + r.y = (SCREEN_HEIGHT / 2) - r.h / 2; + + SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); + SDL_RenderDrawRect(app.renderer, &r); + + r.w *= (step / maxSteps); + r.x += 2; + r.y += 2; + r.w -= 4; + r.h -= 4; + + SDL_SetRenderDrawColor(app.renderer, 128, 196, 255, 255); + SDL_RenderFillRect(app.renderer, &r); + + presentScene(); + + SDL_Delay(1); +} + + +static void initDefaultConfig(void) +{ + int i; + + app.config.hudInventory = 1; + app.config.blood = 1; + + app.config.musicVolume = 80; + app.config.soundVolume = 100; + + app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A; + app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D; + app.config.keyControls[CONTROL_UP] = SDL_SCANCODE_W; + app.config.keyControls[CONTROL_DOWN] = SDL_SCANCODE_S; + app.config.keyControls[CONTROL_JUMP] = SDL_SCANCODE_I; + app.config.keyControls[CONTROL_FIRE] = SDL_SCANCODE_J; + app.config.keyControls[CONTROL_JETPACK] = SDL_SCANCODE_L; + app.config.keyControls[CONTROL_MAP] = SDL_SCANCODE_TAB; + app.config.keyControls[CONTROL_PAUSE] = SDL_SCANCODE_P; + + /* can't use memset here, as it doesn't work */ + for (i = 0 ; i < CONTROL_MAX ; i++) + { + app.config.joypadControls[i] = -1; + } + + app.config.joypadControls[CONTROL_JUMP] = 1; + app.config.joypadControls[CONTROL_FIRE] = 3; + app.config.joypadControls[CONTROL_JETPACK] = 2; + app.config.joypadControls[CONTROL_MAP] = 6; + app.config.joypadControls[CONTROL_PAUSE] = 7; +} + static void loadConfig(void) { int i; cJSON *root, *controlsJSON, *node; char *text; + initDefaultConfig(); + if (fileExists(getSaveFilePath(CONFIG_FILENAME))) { text = readFile(getSaveFilePath(CONFIG_FILENAME)); diff --git a/src/system/init.h b/src/system/init.h index fa2ca3f..1bbf7bb 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -35,7 +35,6 @@ extern void initFonts(void); extern void initAtlas(void); extern void initSounds(void); extern void initSprites(void); -extern void initControls(void); extern void initEntityFactory(void); extern void destroyLookups(void); extern void destroyFonts(void); @@ -48,5 +47,7 @@ extern char *readFile(const char *filename); extern long lookup(const char *name); extern int writeFile(const char *filename, const char *data); extern char *getLookupName(const char *prefix, long num); +extern void prepareScene(void); +extern void presentScene(void); extern App app;