2010-10-12 10:55:23 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2011-03-17 21:13:11 +01:00
|
|
|
* See COPYING for further information.
|
2011-03-05 13:44:21 +01:00
|
|
|
* ---
|
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>.
|
2010-10-12 10:55:23 +02:00
|
|
|
*/
|
|
|
|
|
2021-08-12 23:09:01 +02:00
|
|
|
#pragma once
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "cli.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "dialog.h"
|
2011-04-26 12:04:45 +02:00
|
|
|
#include "enemy.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "framerate.h"
|
2011-04-29 10:26:37 +02:00
|
|
|
#include "item.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "lasers/laser.h"
|
|
|
|
#include "projectile.h"
|
2012-07-27 19:11:45 +02:00
|
|
|
#include "random.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "replay/state.h"
|
2020-05-16 22:41:54 +02:00
|
|
|
#include "stageinfo.h"
|
2017-02-11 13:22:14 +01:00
|
|
|
|
2024-05-17 04:41:28 +02:00
|
|
|
#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,
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2010-11-28 07:31:26 +01:00
|
|
|
VIEWPORT_X = 40,
|
|
|
|
VIEWPORT_Y = 20,
|
|
|
|
VIEWPORT_W = 480,
|
|
|
|
VIEWPORT_H = 560,
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2023-08-30 14:20:20 +02:00
|
|
|
MAX_CONTINUES = 5,
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2011-04-26 12:04:45 +02:00
|
|
|
EVENT_DEATH = -8999,
|
|
|
|
EVENT_BIRTH,
|
2017-03-27 16:06:03 +02:00
|
|
|
|
2011-06-25 12:41:40 +02:00
|
|
|
FPS = 60,
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
GAMEOVER_SCORE_DELAY = 60,
|
|
|
|
};
|
|
|
|
|
2019-04-11 11:30:20 +02:00
|
|
|
#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 }
|
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
typedef enum GameoverType {
|
|
|
|
GAMEOVER_NONE,
|
2011-06-25 12:41:40 +02:00
|
|
|
GAMEOVER_DEFEAT = 1,
|
2012-01-06 21:52:55 +01:00
|
|
|
GAMEOVER_WIN,
|
2012-08-04 06:37:59 +02:00
|
|
|
GAMEOVER_ABORT,
|
2017-02-26 13:17:48 +01:00
|
|
|
GAMEOVER_RESTART,
|
2019-02-22 00:56:03 +01:00
|
|
|
GAMEOVER_SCORESCREEN = -1,
|
|
|
|
GAMEOVER_TRANSITIONING = -2,
|
|
|
|
} GameoverType;
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2011-06-13 18:48:36 +02:00
|
|
|
typedef struct {
|
2017-04-19 23:08:11 +02:00
|
|
|
int8_t diff; // this holds values of type Difficulty, but should be signed to prevent obscure overflow errors
|
2011-06-24 19:16:05 +02:00
|
|
|
Player plr;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2018-06-01 20:40:18 +02:00
|
|
|
ProjectileList projs;
|
|
|
|
ProjectileList particles;
|
|
|
|
EnemyList enemies;
|
|
|
|
ItemList items;
|
|
|
|
LaserList lasers;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-10-04 07:07:04 +02:00
|
|
|
int frames; // stage global timer
|
2017-10-15 22:39:42 +02:00
|
|
|
int stage_start_frame;
|
2017-10-04 07:07:04 +02:00
|
|
|
|
2017-02-05 19:25:18 +01:00
|
|
|
int frameskip;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2011-04-08 18:59:03 +02:00
|
|
|
Boss *boss;
|
2011-05-08 13:48:25 +02:00
|
|
|
Dialog *dialog;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
GameoverType gameover;
|
|
|
|
int gameover_time;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2017-12-26 12:07:40 +01:00
|
|
|
struct {
|
|
|
|
FPSCounter logic;
|
|
|
|
FPSCounter render;
|
|
|
|
FPSCounter busy;
|
|
|
|
} fps;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2021-05-30 03:26:21 +02:00
|
|
|
struct {
|
|
|
|
ReplayState input, output;
|
|
|
|
} replay;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
uint voltage_threshold;
|
|
|
|
|
2012-07-27 19:11:45 +02:00
|
|
|
RandomState rand_game;
|
|
|
|
RandomState rand_visual;
|
2017-02-10 11:39:42 +01:00
|
|
|
|
|
|
|
StageInfo *stage;
|
2017-09-11 21:09:30 +02:00
|
|
|
|
2018-04-18 01:17:28 +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;
|
2010-10-12 10:55:23 +02:00
|
|
|
} Global;
|
|
|
|
|
|
|
|
extern Global global;
|
|
|
|
|
2017-04-03 01:30:12 +02:00
|
|
|
void init_global(CLIAction *cli);
|
2010-10-12 10:55:23 +02:00
|
|
|
|
2018-05-19 04:01:16 +02:00
|
|
|
void taisei_quit(void);
|
|
|
|
bool taisei_quit_requested(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);
|
2018-05-19 04:01:16 +02:00
|
|
|
|
2017-09-29 21:03:49 +02:00
|
|
|
// XXX: Move this somewhere?
|
|
|
|
bool gamekeypressed(KeyIndex key);
|