Set config defaults in init.c

This commit is contained in:
Steve 2018-02-12 18:26:47 +00:00
parent ff74e19f12
commit 7f257f2740
4 changed files with 71 additions and 34 deletions

View File

@ -35,8 +35,6 @@ void initGame(void)
game.timePlayed = 0; game.timePlayed = 0;
loadMetaInfo(); loadMetaInfo();
initControls();
} }
void addRescuedMIA(char *name) void addRescuedMIA(char *name)

View File

@ -20,33 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "controls.h" #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 isControl(int type)
{ {
int key, btn; int key, btn;

View File

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadConfig(void); static void loadConfig(void);
static void initJoypad(void); static void initJoypad(void);
static void showLoadingStep(float step, float maxSteps);
void init18N(int argc, char *argv[]) void init18N(int argc, char *argv[])
{ {
@ -94,8 +95,6 @@ void initSDL(void)
} }
initJoypad(); initJoypad();
initControls();
} }
static void initJoypad(void) static void initJoypad(void)
@ -127,7 +126,6 @@ void initGameSystem(void)
initLookups, initLookups,
initGraphics, initGraphics,
initFonts, initFonts,
initControls,
initAtlas, initAtlas,
initSounds, initSounds,
initSprites, initSprites,
@ -138,18 +136,85 @@ void initGameSystem(void)
for (i = 0 ; i < numInitFuns ; i++) for (i = 0 ; i < numInitFuns ; i++)
{ {
/*showLoadingStep(i + 1, numInitFuns);*/ showLoadingStep(i + 1, numInitFuns);
initFuncs[i](); 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) static void loadConfig(void)
{ {
int i; int i;
cJSON *root, *controlsJSON, *node; cJSON *root, *controlsJSON, *node;
char *text; char *text;
initDefaultConfig();
if (fileExists(getSaveFilePath(CONFIG_FILENAME))) if (fileExists(getSaveFilePath(CONFIG_FILENAME)))
{ {
text = readFile(getSaveFilePath(CONFIG_FILENAME)); text = readFile(getSaveFilePath(CONFIG_FILENAME));

View File

@ -35,7 +35,6 @@ extern void initFonts(void);
extern void initAtlas(void); extern void initAtlas(void);
extern void initSounds(void); extern void initSounds(void);
extern void initSprites(void); extern void initSprites(void);
extern void initControls(void);
extern void initEntityFactory(void); extern void initEntityFactory(void);
extern void destroyLookups(void); extern void destroyLookups(void);
extern void destroyFonts(void); extern void destroyFonts(void);
@ -48,5 +47,7 @@ extern char *readFile(const char *filename);
extern long lookup(const char *name); extern long lookup(const char *name);
extern int writeFile(const char *filename, const char *data); extern int writeFile(const char *filename, const char *data);
extern char *getLookupName(const char *prefix, long num); extern char *getLookupName(const char *prefix, long num);
extern void prepareScene(void);
extern void presentScene(void);
extern App app; extern App app;