2012-07-16 17:47:06 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-02-10 22:07:57 +01:00
|
|
|
* See COPYING for further information.
|
2012-07-16 17:47:06 +02: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>.
|
2012-07-16 17:47:06 +02:00
|
|
|
*/
|
2011-07-02 11:39:36 +02:00
|
|
|
|
|
|
|
#include "gameovermenu.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
|
|
|
|
#include "global.h"
|
2017-02-24 22:58:27 +01:00
|
|
|
#include "ingamemenu.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "menu.h"
|
2020-04-26 21:27:13 +02:00
|
|
|
#include "stats.h"
|
2011-07-02 11:39:36 +02:00
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
typedef struct GameoverMenuContext {
|
|
|
|
IngameMenuContext base;
|
|
|
|
GameoverMenuAction *output;
|
|
|
|
} GameoverMenuContext;
|
|
|
|
|
|
|
|
static void set_action(MenuData *m, void *arg) {
|
|
|
|
GameoverMenuContext *ctx = m->context;
|
|
|
|
*ctx->output = (uintptr_t)arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MenuEntry *add_action_entry(MenuData *m, char *text, GameoverMenuAction action, bool enabled) {
|
|
|
|
return add_menu_entry(m, text, enabled ? set_action : NULL, (void*)action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MenuEntry *add_quickload_entry(MenuData *m, const GameoverMenuParams *params) {
|
|
|
|
if(!params->quickload_shown) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return add_action_entry(m, "Load Quicksave", GAMEOVERMENU_ACTION_QUICKLOAD, params->quickload_enabled);
|
2011-07-02 11:39:36 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
static void free_gameover_menu(MenuData *m) {
|
|
|
|
mem_free(m->context);
|
2011-07-02 11:39:36 +02:00
|
|
|
}
|
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
MenuData *create_gameover_menu(const GameoverMenuParams *params) {
|
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
|
|
|
MenuData *m = alloc_menu();
|
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
auto ctx = ALLOC(GameoverMenuContext, {
|
|
|
|
.output = params->output,
|
|
|
|
});
|
|
|
|
|
|
|
|
*ctx->output = GAMEOVERMENU_ACTION_DEFAULT;
|
|
|
|
|
2017-02-24 22:58:27 +01:00
|
|
|
m->draw = draw_ingame_menu;
|
2017-12-26 12:07:40 +01:00
|
|
|
m->logic = update_ingame_menu;
|
2024-05-03 04:18:27 +02:00
|
|
|
m->end = free_gameover_menu;
|
2012-08-17 20:58:23 +02:00
|
|
|
m->flags = MF_Transient | MF_AlwaysProcessInput;
|
2017-02-24 22:58:27 +01:00
|
|
|
m->transition = TransEmpty;
|
2024-05-03 04:18:27 +02:00
|
|
|
m->context = ctx;
|
|
|
|
|
|
|
|
add_quickload_entry(m, params);
|
2017-02-10 22:07:57 +01:00
|
|
|
|
2017-02-10 22:26:46 +01:00
|
|
|
if(global.stage->type == STAGE_SPELL) {
|
2024-05-03 04:18:27 +02:00
|
|
|
ctx->base.title = "Spell Failed";
|
2017-02-10 22:07:57 +01:00
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
add_action_entry(m, "Restart", GAMEOVERMENU_ACTION_RESTART, true)
|
|
|
|
->transition = TransFadeBlack;
|
|
|
|
add_action_entry(m, "Give up", GAMEOVERMENU_ACTION_QUIT, true)
|
|
|
|
->transition = TransFadeBlack;
|
2017-02-10 22:26:46 +01:00
|
|
|
} else {
|
2024-05-03 04:18:27 +02:00
|
|
|
ctx->base.title = "Game Over";
|
2017-02-10 22:26:46 +01:00
|
|
|
|
|
|
|
char s[64];
|
2020-04-26 21:27:13 +02:00
|
|
|
int c = MAX_CONTINUES - global.plr.stats.total.continues_used;
|
2024-05-03 04:18:27 +02:00
|
|
|
bool have_continues = c > 0;
|
|
|
|
|
|
|
|
if(have_continues) {
|
|
|
|
snprintf(s, sizeof(s), "Continue (%i)", c);
|
|
|
|
} else {
|
|
|
|
snprintf(s, sizeof(s), "Continue");
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action_entry(m, s, GAMEOVERMENU_ACTION_CONTINUE, have_continues);
|
|
|
|
add_action_entry(m, "Restart the Game", GAMEOVERMENU_ACTION_RESTART, true)
|
|
|
|
->transition = TransFadeBlack;
|
|
|
|
add_action_entry(m, have_continues ? "Give up" : "Return to Title", GAMEOVERMENU_ACTION_QUIT, true)
|
|
|
|
->transition = TransFadeBlack;
|
|
|
|
}
|
2017-02-10 22:26:46 +01:00
|
|
|
|
2024-05-03 04:18:27 +02:00
|
|
|
while(!dynarray_get(&m->entries, m->cursor).action) {
|
|
|
|
++m->cursor;
|
2017-02-10 22:26:46 +01:00
|
|
|
}
|
2017-02-24 22:58:27 +01:00
|
|
|
|
2023-04-07 05:47:47 +02:00
|
|
|
set_transition(TransEmpty, 0, m->transition_out_time, NO_CALLCHAIN);
|
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
|
|
|
return m;
|
2011-07-02 11:39:36 +02:00
|
|
|
}
|