taisei/src/global.c

79 lines
2 KiB
C

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "global.h"
Global global;
void init_global(CLIAction *cli) {
memset(&global, 0, sizeof(global));
rng_init(&global.rand_game, time(0));
rng_init(&global.rand_visual, time(0));
rng_make_active(&global.rand_visual);
memset(&global.replay, 0, sizeof(Replay));
global.replaymode = REPLAY_RECORD;
global.frameskip = cli->frameskip;
if(cli->type == CLI_VerifyReplay) {
global.is_headless = true;
global.is_replay_verification = true;
global.frameskip = 1;
} else if(global.frameskip) {
log_warn("FPS limiter disabled. Gotta go fast! (frameskip = %i)", global.frameskip);
}
fpscounter_reset(&global.fps.logic);
fpscounter_reset(&global.fps.render);
fpscounter_reset(&global.fps.busy);
}
// Inputdevice-agnostic method of checking whether a game control is pressed.
// ALWAYS use this instead of SDL_GetKeyState if you need it.
// XXX: Move this somewhere?
bool gamekeypressed(KeyIndex key) {
return SDL_GetKeyboardState(NULL)[config_get_int(KEYIDX_TO_CFGIDX(key))] || gamepad_game_key_pressed(key);
}
static SDL_atomic_t quitting;
void taisei_quit(void) {
if(SDL_AtomicCAS(&quitting, 0, 1)) {
log_info("Exit requested");
}
}
bool taisei_quit_requested(void) {
return SDL_AtomicGet(&quitting);
}
void taisei_commit_persistent_data(void) {
config_save();
progress_save();
vfs_sync(VFS_SYNC_STORE, NO_CALLCHAIN);
}
#ifdef DEBUG
#include "audio/audio.h"
static bool _skip_mode;
bool taisei_is_skip_mode_enabled(void) { return _skip_mode; }
void taisei_set_skip_mode(bool state) {
if(_skip_mode && !state && current_bgm.started_at >= 0) {
audio_music_set_position((global.frames - current_bgm.started_at) / (double)FPS);
}
_skip_mode = state;
}
#else
bool taisei_is_skip_mode_enabled(void) { return false; }
void taisei_set_skip_mode(bool state) { }
#endif