taisei/src/stage.h

126 lines
4.4 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* 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>.
*/
#pragma once
#include "taisei.h"
2017-02-27 15:27:48 +01:00
#include "projectile.h"
#include "boss.h"
#include "progress.h"
#include "difficulty.h"
#include "util/graphics.h"
#include "dialog.h"
#include "coroutine.h"
#include "dynarray.h"
#include "stageinfo.h"
2017-02-27 15:27:48 +01:00
#define MODERNIZE_THIS_FILE_AND_REMOVE_ME \
PRAGMA(message "This file needs to be modernized") \
DIAGNOSTIC(ignored "-Wdeprecated-declarations")
/* taisei's strange macro language.
*
* sorry, I guess it is bad style, but I hardcode everything and in that case
* you'll find yourself soon in a situation where you have to spread your
* coherent thoughts over frames using masses of redundant ifs.
* I've just invented this thingy to keep track of my sanity.
*
*/
#define TIMER(ptr) int *__timep = ptr; int _i = 0, _ni = 0; _i = _ni = _i;
#define AT(t) if(*__timep == t)
#define FROM_TO(start,end,step) _ni = _ni; _i = (*__timep - (start))/(step); if(*__timep >= (start) && *__timep <= (end) && !((*__timep - (start)) % (step)))
2017-04-03 10:10:58 +02:00
// Like FROM_TO just with two different intervals:
// A pause interval step and an action interval dur. For dur frames something
2017-04-03 10:11:50 +02:00
// happens, then for step frames there is a break.
2017-04-03 10:10:58 +02:00
//
// Lastly, istep is the step inside the action interval. For istep = 2, only
// every second frame of dur is executed.
//
// Finally an example for step = 4, dur = 5, and istep = 2:
//
// A_A_A____A_A_A____A_A_A____...
//
// where A denotes a frame in which the body of FROM_TO_INT gets executed.
#define FROM_TO_INT(start, end, step, dur, istep) \
_i = (*__timep - (start))/(step+dur); _ni = ((*__timep - (start)) % (step+dur))/istep; \
if(*__timep >= (start) && *__timep <= (end) && (*__timep - (start)) % ((dur) + (step)) <= dur && !((*__timep - (start)) % (istep)))
#define GO_AT(obj, start, end, vel) if(*__timep >= (start) && *__timep <= (end)) (obj)->pos += (vel);
#define GO_TO(obj, p, f) (obj)->pos += (f)*((p) - (obj)->pos);
// This is newest addition to the macro zoo! It allows you to loop a sound like
// you loop your French- I mean your danmaku code. Nothing strange going on here.
#define PLAY_FOR(name,start, end) FROM_TO(start,end,2) { play_sfx_loop(name); }
// easy to soundify versions of FROM_TO and friends. Note how I made FROM_TO_INT even more complicated!
#define FROM_TO_SND(snd,start,end,step) PLAY_FOR(snd,start,end); FROM_TO(start,end,step)
#define FROM_TO_INT_SND(snd,start,end,step,dur,istep) FROM_TO_INT(start,end,step,dur,2) { play_sfx_loop(snd); }FROM_TO_INT(start,end,step,dur,istep)
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
void stage_pause(void);
void stage_gameover(void);
void stage_start_bgm(const char *bgm);
typedef enum ClearHazardsFlags {
CLEAR_HAZARDS_BULLETS = (1 << 0),
CLEAR_HAZARDS_LASERS = (1 << 1),
CLEAR_HAZARDS_FORCE = (1 << 2),
CLEAR_HAZARDS_NOW = (1 << 3),
CLEAR_HAZARDS_SPAWN_VOLTAGE = (1 << 4),
CLEAR_HAZARDS_ALL = CLEAR_HAZARDS_BULLETS | CLEAR_HAZARDS_LASERS,
} ClearHazardsFlags;
void stage_clear_hazards(ClearHazardsFlags flags);
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);
void stage_clear_hazards_predicate(bool (*predicate)(EntityInterface *ent, void *arg), void *arg, ClearHazardsFlags flags);
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);
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);
void stage_load_quicksave(void);
#ifdef DEBUG
#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);
#else
#define STAGE_BOOKMARK(name) ((void)0)
#define STAGE_BOOKMARK_DELAYED(delay, name) ((void)0)
INLINE bool stage_is_skip_mode(void) { return false; }
#endif