taisei/src
Andrei Alexeyev 180f9e3856
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 21:32:32 +02:00
..
audio refactor audio (module system like that of renderer) 2019-03-05 21:43:01 +02:00
dialog 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
eventloop Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
menu Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
pch refactor audio (module system like that of renderer) 2019-03-05 21:43:01 +02:00
plrmodes The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
projectile_prototypes Add Reimu Hakurei as a playable character (#106) 2018-08-11 22:13:48 +03:00
renderer Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
resource refactor audio (module system like that of renderer) 2019-03-05 21:43:01 +02:00
rwops WIP: accelerate build with precompiled headers 2019-02-09 12:29:54 +02:00
stages refactor audio (module system like that of renderer) 2019-03-05 21:43:01 +02:00
util Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
vfs Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
aniplayer.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
aniplayer.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
assert.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
boss.c replace item spawning functions with type-safe versions 2019-03-03 13:53:45 +02:00
boss.h show enemy/boss hitboxes in hitbox display mode 2019-03-01 18:10:49 +02:00
cli.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
cli.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
color.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
color.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
config.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
config.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
credits.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
credits.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
dialog.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
dialog.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
difficulty.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
difficulty.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
drawlayers.inc.h Lots of disorganized (mostly) visual overhaul (#156) 2019-01-05 00:59:39 +02:00
ending.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
ending.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
enemy.c replace item spawning functions with type-safe versions 2019-03-03 13:53:45 +02:00
enemy.h show enemy/boss hitboxes in hitbox display mode 2019-03-01 18:10:49 +02:00
entity.c The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
entity.h The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
events.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
events.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
framerate.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
framerate.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
gamepad.c fix gamepad input repeat regression 2019-02-15 02:04:02 +02:00
gamepad.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
global.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
global.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
hashtable.c WIP: accelerate build with precompiled headers 2019-02-09 12:29:54 +02:00
hashtable.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
hashtable.inc.h WIP: accelerate build with precompiled headers 2019-02-09 12:29:54 +02:00
hashtable_incproxy.inc.h Text rendering rewrite and optimizations; some refactoring (#129) 2018-06-30 00:36:51 +03:00
hashtable_predefs.inc.h Lots of disorganized (mostly) visual overhaul (#156) 2019-01-05 00:59:39 +02:00
hirestime.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
hirestime.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
item.c fix all items being autocollected immediately 2019-03-09 18:25:34 +02:00
item.h replace item spawning functions with type-safe versions 2019-03-03 13:53:45 +02:00
laser.c The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
laser.h The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
list.c WIP: accelerate build with precompiled headers 2019-02-09 12:29:54 +02:00
list.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
log.c log: fix colorless console formatter 2019-02-17 21:21:26 +02:00
log.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
main.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
meson.build Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
objectpool.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
objectpool.h Fix a lot of warnings with -O3 and 32bit builds 2019-02-02 13:25:06 +02:00
objectpool_fake.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
objectpool_util.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
objectpool_util.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
player.c improve the Post Death Experience (and code) 2019-03-05 13:50:29 +02:00
player.h improve the Post Death Experience (and code) 2019-03-05 13:50:29 +02:00
plrmodes.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
plrmodes.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
progress.c Logging: colors, non-fatal error level, alt. format for log file 2019-02-15 01:58:40 +02:00
progress.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
projectile.c The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
projectile.h The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
projectile_prototypes.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
random.c Replace RNG with xoshiro256+; update replay format 2019-03-09 18:19:42 +02:00
random.h Replace RNG with xoshiro256+; update replay format 2019-03-09 18:19:42 +02:00
refs.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
refs.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
replay.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
replay.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
stage.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
stage.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
stagedraw.c show enemy/boss hitboxes in hitbox display mode 2019-03-01 18:10:49 +02:00
stagedraw.h The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
stageobjects.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
stageobjects.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
stagetext.c The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
stagetext.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
stageutils.c Move CGLM to submodule and update it 2019-02-22 23:46:54 +02:00
stageutils.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
taisei.h The Powersurge game mechanic and scoring system (#159) 2019-02-22 01:56:03 +02:00
taisei.rc.in Consistent indentation: indent with tabs, align with spaces (#104) 2018-01-12 20:26:07 +02:00
taskmanager.c Logging: colors, non-fatal error level, alt. format for log file 2019-02-15 01:58:40 +02:00
taskmanager.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
transition.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
transition.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
util.h 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
version.c 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
version.h Some compatibility fixes for Elbrus compiler (and others based on EDG front end) (#157) 2019-02-07 10:11:13 +02:00
version_auto.c.in 'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
video.c Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00
video.h Emscripten compatibility (#161) 2019-03-09 21:32:32 +02:00