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.
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2011-03-05 13:44:21 +01:00
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, 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
|
|
|
|
2017-02-27 15:27:48 +01:00
|
|
|
#include "projectile.h"
|
|
|
|
#include "boss.h"
|
|
|
|
#include "progress.h"
|
|
|
|
#include "difficulty.h"
|
2018-07-04 10:36:16 +02:00
|
|
|
#include "util/graphics.h"
|
2019-07-03 19:50:43 +02:00
|
|
|
#include "dialog.h"
|
2019-10-11 15:58:51 +02:00
|
|
|
#include "coroutine.h"
|
2020-04-05 04:51:00 +02:00
|
|
|
#include "dynarray.h"
|
2020-05-16 22:41:54 +02:00
|
|
|
#include "stageinfo.h"
|
2017-02-27 15:27:48 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
typedef struct StageClearBonus {
|
|
|
|
uint64_t base;
|
|
|
|
uint64_t lives;
|
|
|
|
uint64_t voltage;
|
|
|
|
uint64_t graze;
|
|
|
|
uint64_t total;
|
|
|
|
bool all_clear;
|
|
|
|
} StageClearBonus;
|
|
|
|
|
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 stage_enter(StageInfo *stage, CallChain next);
|
2017-02-26 13:17:48 +01:00
|
|
|
void stage_finish(int gameover);
|
2012-07-27 12:18:21 +02:00
|
|
|
|
2012-08-17 20:58:23 +02:00
|
|
|
void stage_pause(void);
|
|
|
|
void stage_gameover(void);
|
|
|
|
|
2017-10-02 23:23:02 +02:00
|
|
|
void stage_start_bgm(const char *bgm);
|
|
|
|
|
2018-01-06 10:24:46 +01:00
|
|
|
typedef enum ClearHazardsFlags {
|
|
|
|
CLEAR_HAZARDS_BULLETS = (1 << 0),
|
|
|
|
CLEAR_HAZARDS_LASERS = (1 << 1),
|
|
|
|
CLEAR_HAZARDS_FORCE = (1 << 2),
|
|
|
|
CLEAR_HAZARDS_NOW = (1 << 3),
|
2019-02-22 00:56:03 +01:00
|
|
|
CLEAR_HAZARDS_SPAWN_VOLTAGE = (1 << 4),
|
2018-01-06 10:24:46 +01:00
|
|
|
|
|
|
|
CLEAR_HAZARDS_ALL = CLEAR_HAZARDS_BULLETS | CLEAR_HAZARDS_LASERS,
|
|
|
|
} ClearHazardsFlags;
|
|
|
|
|
|
|
|
void stage_clear_hazards(ClearHazardsFlags flags);
|
2019-11-22 04:37:11 +01:00
|
|
|
void stage_clear_hazards_at(cmplx origin, double radius, ClearHazardsFlags flags);
|
2019-03-26 16:58:38 +01:00
|
|
|
void stage_clear_hazards_in_ellipse(Ellipse e, ClearHazardsFlags flags);
|
2018-08-05 19:58:50 +02:00
|
|
|
void stage_clear_hazards_predicate(bool (*predicate)(EntityInterface *ent, void *arg), void *arg, ClearHazardsFlags flags);
|
2018-01-06 10:24:46 +01:00
|
|
|
|
2019-02-22 00:56:03 +01:00
|
|
|
void stage_set_voltage_thresholds(uint easy, uint normal, uint hard, uint lunatic);
|
|
|
|
|
|
|
|
bool stage_is_cleared(void);
|
|
|
|
|
2019-03-11 00:21:43 +01:00
|
|
|
void stage_unlock_bgm(const char *bgm);
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void stage_begin_dialog(Dialog *d) attr_nonnull_all;
|
|
|
|
|
2020-05-16 22:42:22 +02:00
|
|
|
void stage_shake_view(float strength);
|
|
|
|
float stage_get_view_shake_strength(void);
|
|
|
|
|
2022-02-16 10:26:45 +01:00
|
|
|
void stage_load_quicksave(void);
|
|
|
|
|
2022-12-22 16:55:56 +01:00
|
|
|
CoSched *stage_get_sched(void);
|
|
|
|
|
2019-10-11 15:58:51 +02:00
|
|
|
#ifdef DEBUG
|
2020-06-22 16:41:03 +02:00
|
|
|
#define HAVE_SKIP_MODE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SKIP_MODE
|
|
|
|
void _stage_bookmark(const char *name);
|
|
|
|
#define STAGE_BOOKMARK(name) _stage_bookmark(#name)
|
|
|
|
DECLARE_EXTERN_TASK(stage_bookmark, { const char *name; });
|
|
|
|
#define STAGE_BOOKMARK_DELAYED(delay, name) INVOKE_TASK_DELAYED(delay, stage_bookmark, #name)
|
|
|
|
bool stage_is_skip_mode(void);
|
2019-10-11 15:58:51 +02:00
|
|
|
#else
|
2020-06-22 16:41:03 +02:00
|
|
|
#define STAGE_BOOKMARK(name) ((void)0)
|
|
|
|
#define STAGE_BOOKMARK_DELAYED(delay, name) ((void)0)
|
|
|
|
INLINE bool stage_is_skip_mode(void) { return false; }
|
2019-10-11 15:58:51 +02:00
|
|
|
#endif
|