taisei/src/global.h

116 lines
2.1 KiB
C
Raw Permalink Normal View History

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
2024-05-16 23:30:41 +02:00
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
*/
#pragma once
#include "taisei.h"
#include "cli.h"
#include "config.h"
#include "dialog.h"
#include "enemy.h"
#include "framerate.h"
2011-04-29 10:26:37 +02:00
#include "item.h"
#include "lasers/laser.h"
#include "projectile.h"
2012-07-27 19:11:45 +02:00
#include "random.h"
#include "replay/state.h"
#include "stageinfo.h"
#include <SDL.h>
#include <SDL_platform.h>
2012-07-28 22:53:53 +02:00
enum {
// defaults
2012-07-20 21:24:12 +02:00
RESX = 800,
2012-07-28 22:53:53 +02:00
RESY = 600,
VIEWPORT_X = 40,
VIEWPORT_Y = 20,
VIEWPORT_W = 480,
VIEWPORT_H = 560,
2023-08-30 14:20:20 +02:00
MAX_CONTINUES = 5,
EVENT_DEATH = -8999,
EVENT_BIRTH,
FPS = 60,
GAMEOVER_SCORE_DELAY = 60,
};
#define VIEWPORT_OFFSET { VIEWPORT_X, VIEWPORT_Y }
#define VIEWPORT_SIZE { VIEWPORT_W, VIEWPORT_H }
#define VIEWPORT_RECT { VIEWPORT_X, VIEWPORT_Y, VIEWPORT_W, VIEWPORT_H }
typedef enum GameoverType {
GAMEOVER_NONE,
GAMEOVER_DEFEAT = 1,
GAMEOVER_WIN,
2012-08-04 06:37:59 +02:00
GAMEOVER_ABORT,
2017-02-26 13:17:48 +01:00
GAMEOVER_RESTART,
GAMEOVER_SCORESCREEN = -1,
GAMEOVER_TRANSITIONING = -2,
} GameoverType;
typedef struct {
int8_t diff; // this holds values of type Difficulty, but should be signed to prevent obscure overflow errors
Player plr;
ProjectileList projs;
ProjectileList particles;
EnemyList enemies;
ItemList items;
LaserList lasers;
int frames; // stage global timer
2017-10-15 22:39:42 +02:00
int stage_start_frame;
int frameskip;
Boss *boss;
Dialog *dialog;
GameoverType gameover;
int gameover_time;
2017-12-26 12:07:40 +01:00
struct {
FPSCounter logic;
FPSCounter render;
FPSCounter busy;
} fps;
struct {
ReplayState input, output;
} replay;
uint voltage_threshold;
2012-07-27 19:11:45 +02:00
RandomState rand_game;
RandomState rand_visual;
StageInfo *stage;
2017-09-11 21:09:30 +02:00
uint is_practice_mode : 1;
uint is_headless : 1;
uint is_replay_verification : 1;
2023-06-20 00:50:17 +02:00
uint is_kiosk_mode : 1;
} Global;
extern Global global;
void init_global(CLIAction *cli);
void taisei_quit(void);
bool taisei_quit_requested(void);
bool taisei_is_quit_hidden(void);
Emscripten compatibility (#161) * Major refactoring of the main loop(s) and control flow (WIP) run_at_fps() is gone 🦀 Instead of nested blocking event loops, there is now an eventloop API that manages an explicit stack of scenes. This makes Taisei a lot more portable to async environments where spinning a loop forever without yielding control simply is not an option, and that is the entire point of this change. A prime example of such an environment is the Web (via emscripten). Taisei was able to run there through a terrible hack: inserting emscripten_sleep calls into the loop, which would yield to the browser. This has several major drawbacks: first of all, every function that could possibly call emscripten_sleep must be compiled into a special kind of bytecode, which then has to be interpreted at runtime, *much* slower than JITed WebAssembly. And that includes *everything* down the call stack, too! For more information, see https://emscripten.org/docs/porting/emterpreter.html Even though that method worked well enough for experimenting, despite suboptimal performance, there is another obvious drawback: emscripten_sleep is implemented via setTimeout(), which can be very imprecise and is generally not reliable for fluid animation. Browsers actually have an API specifically for that use case: window.requestAnimationFrame(), but Taisei's original blocking control flow style is simply not compatible with it. Emscripten exposes this API with its emscripten_set_main_loop(), which the eventloop backend now uses on that platform. Unfortunately, C is still C, with no fancy closures or coroutines. With blocking calls into menu/scene loops gone, the control flow is reimplemented via so-called (pun intended) "call chains". That is basically an euphemism for callback hell. With manual memory management and zero type-safety. Not that the menu system wasn't shitty enough already. I'll just keep telling myself that this is all temporary and will be replaced with scripts in v1.4. * improve build system for emscripten + various fixes * squish menu bugs * improve emscripten event loop; disable EMULATE_FUNCTION_POINTER_CASTS Note that stock freetype does not work without EMULATE_FUNCTION_POINTER_CASTS; use a patched version from the "emscripten" branch here: https://github.com/taisei-project/freetype2/tree/emscripten * Enable -Wcast-function-type Calling functions through incompatible pointers is nasal demons and doesn't work in WASM. * webgl: workaround a crash on some browsers * emscripten improvements: * Persist state (config, progress, replays, ...) in local IndexDB * Simpler HTML shell (temporary) * Enable more optimizations * fix build if validate_glsl=false * emscripten: improve asset packaging, with local cache Note that even though there are rules to build audio bundles, audio does *not* work yet. It looks like SDL2_mixer can not work without threads, which is a problem. Yet another reason to write an OpenAL backend - emscripten supports that natively. * emscripten: customize the html shell * emscripten: force "show log" checkbox unchecked initially * emscripten: remove quit shortcut from main menu (since there's no quit) * emscripten: log area fixes * emscripten/webgl: workaround for fullscreen viewport issue * emscripten: implement frameskip * emscripter: improve framerate limiter * align List to at least 8 bytes (shut up warnings) * fix non-emscripten builds * improve fullscreen handling, mainly for emscripten * Workaround to make audio work in chromium emscripten-core/emscripten#6511 * emscripten: better vsync handling; enable vsync & disable fxaa by default
2019-03-09 20:32:32 +01:00
void taisei_commit_persistent_data(void);
// XXX: Move this somewhere?
bool gamekeypressed(KeyIndex key);