taisei/src/global.c
Andrei Alexeyev 173c8c3cc6
replay: general refactor
* Split replay.c into multiple files under replay/; improve logical
  separation of replay-related code.
* Separate replay playback state from data.
* Get rid of global static replay struct and avoid unnecessary replay
  copying.
* Replay playback and recording are now independent and may occur
  simultaneously, although this functionality is not yet exposed. This
  enables replay "re-recording" while synthesizing new desync check
  events, possibly at a different rate from the original replay.
* Rate of recorded desync check events can now be controlled with the
  TAISEI_REPLAY_DESYNC_CHECK_FREQUENCY environment variable. The default
  value is 300 as before.
* Probably other stuff I forgot about.
2021-06-16 01:43:10 +03:00

60 lines
1.5 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);
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);
}