* WIP some projectile effects * fix segfault * Laser smoothing and glow via post-processing blur magic TODO: make it optional * fix memory corruption * fix memory corruption for realsies now * fix color_get_hsl for out-of-range colors * some more bullet flare tweaks * some lame clear effect workarounds * spawn bullet flares after frame 0; looks better and fixes some problems * New baryon explosion; fix petal_explosion; leanify everything * Add missing bullet flare sprite, rebuild main atlas * improve batching efficiency with bullet spawn flares * forgot git add * Group projectiles/particles by shader where possible * Another take on baryon explosion; make fg framebuffers 16bit * WIP some settings for toasters * remove stupid debug log * microoptimization that probably does nothing anyway * somewhat more intuitive quality settings * Whitelist more particles (MarisaB is on hold) * Whitelist (and fix) some more stage6 particles (mostly ToE) * Add a spell name background * Experimental radial healthbar for bosses * healthbar tweaks * thiccer healthbars in response to feedback * remove healthbar survival timer; just fade out on survivals * Add linear healthbars option; WIP other boss HUD tweaks * Use the proper spell card name format * New font and some random garbage to go along with it * Generate static font outlines for use in text shaders * Use outlines in overlay text shader * Complete boss HUD/healthbar fading logic * fix boss timer limit * stage5 bombs explosion effect * split PFLAG_NOSPAWNZOOM into PFLAG_NOSPAWNFLARE and PFLAG_NOSPAWNFADE; introduce PFLAG_NOSPAWNEFFECTS which disables both (it's just the two values OR'd together) simplify vampiric vapor bullet spawning effect * Remove spawn fade-in from super-fast stage5 fairy projectiles (limiters) * lower particle density in v.vapor in minimal mode * graze effect tweaks * fix text shortening, tweak replay menu layout * stupid debug spam * revisit grazing effects again * dumb debug spam again * improve boss attack timer * overlay effect for boss deaths (similar to the player one) * spice up spellcard declaration (HUD) * don't spawn boss death overlay if fleed * modify Exo2 font to use tabular figures * adjust replay menu for the font change * draw timer & power with standard font (phasing out the numbers font) * WIP new HUD; random fixes/tweaks * hud: move difficulty indicator * hud: move debug stuff around * preloads, mostly * fix youmuA batching conflict * shitty workaround for the shitty screenshake shit * remove extraspell lag by stopping to draw stagebg sooner which is possible because extra spells have a different spellcard_intro timing. Fun fact of the day: the duration of spellcard_intro is always ATTACK_START_DELAY_EXTRA even for normal spells! * new stain particle * i disabled background rendering… * "batch" marisa_b masterspark draws * remove these once a new atlas is generated * make toe quick again * hopefully fix all occurences of changed stain and ScaleFade behavior * tweaking reimu_a and toe boson launch effects * make lhc fast again * softer involnerability effect * fix stage 1 snow on the water bug (and improve performance) translated the time to the future a bit because it only seemed to be an issue for small time values * remove unnecessary spawnflare from toe * tone down extra spell start effect * experimental ReimuB gap shader optimization * fix python3 shebangs * generate simple blur shaders w/ hardcoded kernels * New loading screen * lasers: fix incorrect draw hook registration * add webp support for atlas generator * Use ImageMagick for atlas composition (adds 16-bit support) * Atlas maintenance * make the vampiric vapor bullets less prone to invisibility * Revert a few particles to the quadratic fade curve * experimental baryon effect * improve baryon sprites * disable the baryon effect on minimal postprocessing setting
205 lines
5.3 KiB
C
205 lines
5.3 KiB
C
/*
|
|
* This software is licensed under the terms of the MIT-License
|
|
* See COPYING for further information.
|
|
* ---
|
|
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
|
|
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
|
|
*/
|
|
|
|
#include "taisei.h"
|
|
|
|
#include "entity.h"
|
|
#include "util.h"
|
|
#include "renderer/api.h"
|
|
#include "global.h"
|
|
|
|
typedef struct EntityDrawHook EntityDrawHook;
|
|
typedef LIST_ANCHOR(EntityDrawHook) EntityDrawHookList;
|
|
|
|
struct EntityDrawHook {
|
|
LIST_INTERFACE(EntityDrawHook);
|
|
EntityDrawHookCallback callback;
|
|
void *arg;
|
|
};
|
|
|
|
static struct {
|
|
EntityInterface **array;
|
|
uint num;
|
|
uint capacity;
|
|
uint32_t total_spawns;
|
|
|
|
struct {
|
|
EntityDrawHookList pre_draw;
|
|
EntityDrawHookList post_draw;
|
|
} hooks;
|
|
} entities;
|
|
|
|
static void add_hook(EntityDrawHookList *list, EntityDrawHookCallback cb, void *arg) {
|
|
EntityDrawHook *hook = calloc(1, sizeof(*hook));
|
|
hook->callback = cb;
|
|
hook->arg = arg;
|
|
alist_append(list, hook);
|
|
}
|
|
|
|
static void remove_hook(EntityDrawHookList *list, EntityDrawHookCallback cb) {
|
|
for(EntityDrawHook *hook = list->first; hook; hook = hook->next) {
|
|
if(hook->callback == cb) {
|
|
alist_unlink(list, hook);
|
|
free(hook);
|
|
return;
|
|
}
|
|
}
|
|
|
|
UNREACHABLE;
|
|
}
|
|
|
|
static void call_hooks(EntityDrawHookList *list, EntityInterface *ent) {
|
|
for(EntityDrawHook *hook = list->first; hook; hook = hook->next) {
|
|
hook->callback(ent, hook->arg);
|
|
}
|
|
}
|
|
|
|
#define FOR_EACH_ENT(ent) for(EntityInterface **_ent = entities.array, *ent = *entities.array; _ent < entities.array + entities.num; ent = *(++_ent))
|
|
|
|
void ent_init(void) {
|
|
memset(&entities, 0, sizeof(entities));
|
|
entities.capacity = 4096;
|
|
entities.array = calloc(entities.capacity, sizeof(EntityInterface*));
|
|
}
|
|
|
|
void ent_shutdown(void) {
|
|
if(entities.num) {
|
|
log_warn("%u entities were not properly unregistered", entities.num);
|
|
}
|
|
|
|
FOR_EACH_ENT(ent) {
|
|
ent_unregister(ent);
|
|
}
|
|
|
|
free(entities.array);
|
|
|
|
assert(entities.hooks.post_draw.first == NULL);
|
|
assert(entities.hooks.pre_draw.first == NULL);
|
|
}
|
|
|
|
void ent_register(EntityInterface *ent, EntityType type) {
|
|
assert(type > _ENT_TYPE_ENUM_BEGIN && type < _ENT_TYPE_ENUM_END);
|
|
ent->type = type;
|
|
ent->index = entities.num++;
|
|
ent->spawn_id = ++entities.total_spawns;
|
|
|
|
if(ent->spawn_id == 0) {
|
|
// This is not really an error, but it may result in weird draw order
|
|
// in some corner cases. If this overflow ever actually occurs, though,
|
|
// then you've probably got much bigger problems.
|
|
log_debug("spawn_id just overflowed. You might be spawning stuff waaaay too often");
|
|
}
|
|
|
|
if(entities.capacity < entities.num) {
|
|
entities.capacity *= 2;
|
|
entities.array = realloc(entities.array, entities.capacity * sizeof(EntityInterface*));
|
|
}
|
|
|
|
entities.array[ent->index] = ent;
|
|
|
|
assert(ent->index < entities.num);
|
|
assert(entities.array[ent->index] == ent);
|
|
}
|
|
|
|
void ent_unregister(EntityInterface *ent) {
|
|
EntityInterface *sub = entities.array[--entities.num];
|
|
assert(ent->index <= entities.num);
|
|
assert(entities.array[ent->index] == ent);
|
|
entities.array[sub->index = ent->index] = sub;
|
|
}
|
|
|
|
static int ent_cmp(const void *ptr1, const void *ptr2) {
|
|
const EntityInterface *ent1 = *(const EntityInterface**)ptr1;
|
|
const EntityInterface *ent2 = *(const EntityInterface**)ptr2;
|
|
|
|
int r = (ent1->draw_layer > ent2->draw_layer) - (ent1->draw_layer < ent2->draw_layer);
|
|
|
|
if(r == 0) {
|
|
// Same layer? Put whatever spawned later on top, then.
|
|
r = (ent1->spawn_id > ent2->spawn_id) - (ent1->spawn_id < ent2->spawn_id);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
void ent_draw(EntityPredicate predicate) {
|
|
call_hooks(&entities.hooks.pre_draw, NULL);
|
|
qsort(entities.array, entities.num, sizeof(EntityInterface*), ent_cmp);
|
|
|
|
if(predicate) {
|
|
FOR_EACH_ENT(ent) {
|
|
ent->index = _ent - entities.array;
|
|
assert(entities.array[ent->index] == ent);
|
|
|
|
if(ent->draw_func && predicate(ent)) {
|
|
call_hooks(&entities.hooks.pre_draw, ent);
|
|
r_state_push();
|
|
ent->draw_func(ent);
|
|
r_state_pop();
|
|
call_hooks(&entities.hooks.post_draw, ent);
|
|
}
|
|
}
|
|
} else {
|
|
FOR_EACH_ENT(ent) {
|
|
ent->index = _ent - entities.array;
|
|
assert(entities.array[ent->index] == ent);
|
|
|
|
if(ent->draw_func) {
|
|
call_hooks(&entities.hooks.pre_draw, ent);
|
|
r_state_push();
|
|
ent->draw_func(ent);
|
|
r_state_pop();
|
|
call_hooks(&entities.hooks.post_draw, ent);
|
|
}
|
|
}
|
|
}
|
|
|
|
call_hooks(&entities.hooks.post_draw, NULL);
|
|
}
|
|
|
|
DamageResult ent_damage(EntityInterface *ent, const DamageInfo *damage) {
|
|
if(ent->damage_func == NULL) {
|
|
return DMG_RESULT_INAPPLICABLE;
|
|
}
|
|
|
|
DamageResult res = ent->damage_func(ent, damage);
|
|
|
|
if(res == DMG_RESULT_OK) {
|
|
player_register_damage(&global.plr, ent, damage);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
void ent_area_damage(complex origin, float radius, const DamageInfo *damage) {
|
|
for(Enemy *e = global.enemies.first; e; e = e->next) {
|
|
if(cabs(origin - e->pos) < radius) {
|
|
ent_damage(&e->ent, damage);
|
|
}
|
|
}
|
|
|
|
if(global.boss && cabs(origin - global.boss->pos) < radius) {
|
|
ent_damage(&global.boss->ent, damage);
|
|
}
|
|
}
|
|
|
|
void ent_hook_pre_draw(EntityDrawHookCallback callback, void *arg) {
|
|
add_hook(&entities.hooks.pre_draw, callback, arg);
|
|
}
|
|
|
|
void ent_unhook_pre_draw(EntityDrawHookCallback callback) {
|
|
remove_hook(&entities.hooks.pre_draw, callback);
|
|
}
|
|
|
|
void ent_hook_post_draw(EntityDrawHookCallback callback, void *arg) {
|
|
add_hook(&entities.hooks.post_draw, callback, arg);
|
|
}
|
|
|
|
void ent_unhook_post_draw(EntityDrawHookCallback callback) {
|
|
remove_hook(&entities.hooks.post_draw, callback);
|
|
}
|