2010-10-12 10:55:23 +02:00
|
|
|
/*
|
2011-03-05 13:44:21 +01: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>.
|
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@alienslab.net>.
|
2010-10-12 10:55:23 +02:00
|
|
|
*/
|
|
|
|
|
2019-01-23 21:10:43 +01:00
|
|
|
#ifndef IGUARD_stage_h
|
|
|
|
#define IGUARD_stage_h
|
|
|
|
|
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"
|
2017-02-27 15:27:48 +01:00
|
|
|
|
2011-06-28 19:23:02 +02:00
|
|
|
/* taisei's strange macro language.
|
2017-02-11 04:52:08 +01:00
|
|
|
*
|
2011-06-28 19:23:02 +02:00
|
|
|
* 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.
|
2017-02-11 04:52:08 +01:00
|
|
|
*
|
2011-06-28 19:23:02 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-23 17:37:14 +02:00
|
|
|
#define TIMER(ptr) int *__timep = ptr; int _i = 0, _ni = 0; _i = _ni = _i;
|
2017-02-11 04:52:08 +01:00
|
|
|
#define AT(t) if(*__timep == t)
|
2011-07-04 13:14:33 +02:00
|
|
|
#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.
|
2011-06-28 19:23:02 +02:00
|
|
|
#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)))
|
2011-06-26 13:45:27 +02:00
|
|
|
|
2011-08-23 17:37:14 +02:00
|
|
|
#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);
|
2011-06-26 13:45:27 +02:00
|
|
|
|
2017-09-30 19:33:07 +02:00
|
|
|
// 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_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_loop(snd); }FROM_TO_INT(start,end,step,dur,istep)
|
|
|
|
|
2017-02-26 13:17:48 +01:00
|
|
|
typedef void (*StageProc)(void);
|
2019-02-22 00:56:03 +01:00
|
|
|
typedef bool (*ShaderRule)(Framebuffer*); // true = drawn to color buffer
|
2011-06-25 12:41:40 +02:00
|
|
|
|
2017-02-20 12:41:31 +01:00
|
|
|
// two highest bits of uint16_t, WAY higher than the amount of spells in this game can ever possibly be
|
2017-02-10 11:39:42 +01:00
|
|
|
#define STAGE_SPELL_BIT 0x8000
|
2017-02-20 12:41:31 +01:00
|
|
|
#define STAGE_EXTRASPELL_BIT 0x4000
|
2017-02-10 11:39:42 +01:00
|
|
|
|
|
|
|
typedef enum StageType {
|
|
|
|
STAGE_STORY = 1,
|
|
|
|
STAGE_EXTRA,
|
|
|
|
STAGE_SPELL,
|
2018-08-14 00:48:18 +02:00
|
|
|
STAGE_SPECIAL,
|
2017-02-10 11:39:42 +01:00
|
|
|
} StageType;
|
|
|
|
|
2017-02-27 15:27:48 +01:00
|
|
|
typedef struct StageProcs StageProcs;
|
2017-02-11 10:52:37 +01:00
|
|
|
|
2017-02-27 15:27:48 +01:00
|
|
|
struct StageProcs {
|
2017-02-26 13:17:48 +01:00
|
|
|
StageProc begin;
|
2017-03-09 20:00:15 +01:00
|
|
|
StageProc preload;
|
2017-02-26 13:17:48 +01:00
|
|
|
StageProc end;
|
|
|
|
StageProc draw;
|
|
|
|
StageProc event;
|
2017-11-15 04:45:41 +01:00
|
|
|
StageProc update;
|
2017-02-26 13:17:48 +01:00
|
|
|
ShaderRule *shader_rules;
|
2017-10-01 10:58:45 +02:00
|
|
|
ShaderRule *postprocess_rules;
|
2017-02-27 15:27:48 +01:00
|
|
|
StageProcs *spellpractice_procs;
|
|
|
|
};
|
2017-02-26 13:17:48 +01:00
|
|
|
|
2012-07-14 09:40:37 +02:00
|
|
|
typedef struct StageInfo {
|
2017-02-10 11:39:42 +01:00
|
|
|
uint16_t id; // must match type of ReplayStage.stage in replay.h
|
2017-02-26 13:17:48 +01:00
|
|
|
StageProcs *procs;
|
2017-02-10 11:39:42 +01:00
|
|
|
StageType type;
|
2012-07-14 09:40:37 +02:00
|
|
|
char *title;
|
|
|
|
char *subtitle;
|
2017-02-10 11:39:42 +01:00
|
|
|
AttackInfo *spell;
|
|
|
|
Difficulty difficulty;
|
2017-02-11 10:52:37 +01:00
|
|
|
|
2017-02-11 12:38:50 +01:00
|
|
|
// Do NOT access this directly!
|
|
|
|
// Use stage_get_progress or stage_get_progress_from_info, which will lazy-initialize it and pick the correct offset.
|
|
|
|
StageProgress *progress;
|
2012-07-14 09:40:37 +02:00
|
|
|
} StageInfo;
|
|
|
|
|
2017-02-27 15:27:48 +01:00
|
|
|
extern StageInfo *stages;
|
2017-02-11 13:22:14 +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;
|
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
StageInfo* stage_get(uint16_t);
|
2017-02-10 23:34:48 +01:00
|
|
|
StageInfo* stage_get_by_spellcard(AttackInfo *spell, Difficulty diff);
|
2017-02-11 13:22:14 +01:00
|
|
|
|
|
|
|
StageProgress* stage_get_progress(uint16_t id, Difficulty diff, bool allocate);
|
|
|
|
StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff, bool allocate);
|
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
void stage_init_array(void);
|
2017-02-15 13:53:24 +01:00
|
|
|
void stage_free_array(void);
|
2012-07-14 10:40:21 +02:00
|
|
|
|
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);
|
2018-08-05 19:58:50 +02:00
|
|
|
void stage_clear_hazards_at(complex 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);
|
|
|
|
|
2017-02-10 11:39:42 +01:00
|
|
|
#include "stages/stage1.h"
|
|
|
|
#include "stages/stage2.h"
|
|
|
|
#include "stages/stage3.h"
|
|
|
|
#include "stages/stage4.h"
|
|
|
|
#include "stages/stage5.h"
|
|
|
|
#include "stages/stage6.h"
|
2019-01-23 21:10:43 +01:00
|
|
|
|
|
|
|
#endif // IGUARD_stage_h
|