Skip to content

Commit

Permalink
Enforce explicit form and .proto usage for PROJECTILE/PARTICLE calls
Browse files Browse the repository at this point in the history
Remove kludge code converting sprite names to prototypes
  • Loading branch information
Akaricchi committed Apr 11, 2019
1 parent ce1eeca commit fd09bf0
Show file tree
Hide file tree
Showing 14 changed files with 1,051 additions and 389 deletions.
17 changes: 15 additions & 2 deletions src/boss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,21 @@ void process_boss(Boss **pboss) {
);
}

PARTICLE("blast", boss->pos, 0, .timeout = 60, .args = { 0, 3.0 }, .draw_rule = GrowFade);
PARTICLE("blast", boss->pos, 0, .timeout = 70, .args = { 0, 2.5 }, .draw_rule = GrowFade);
PARTICLE(
.proto = pp_blast,
.pos = boss->pos,
.timeout = 60,
.args = { 0, 3.0 },
.draw_rule = GrowFade,
);

PARTICLE(
.proto = pp_blast,
.pos = boss->pos,
.timeout = 70,
.args = { 0, 2.5 },
.draw_rule = GrowFade,
);
}

play_sound_ex("bossdeath", BOSS_DEATH_DELAY * 2, false);
Expand Down
3 changes: 1 addition & 2 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,11 @@ static int player_death_effect(Projectile *p, int t) {
if(t == EVENT_DEATH) {
for(int i = 0; i < 12; ++i) {
PARTICLE(
.sprite = "blast",
.proto = pp_blast,
.pos = p->pos + 2 * frand() * cexp(I*M_PI*2*frand()),
.color = RGBA(0.15, 0.2, 0.5, 0),
.timeout = 12 + i + 2 * nfrand(),
.draw_rule = GrowFade,
.args = { 0, 20 + i },
.angle = M_PI*2*frand(),
.flags = PFLAG_NOREFLECT,
.layer = LAYER_OVERLAY,
Expand Down
2 changes: 1 addition & 1 deletion src/plrmodes/reimu.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int reimu_common_ofuda(Projectile *p, int t) {

PARTICLE(
// .sprite_ptr = p->sprite,
.sprite = "hghost",
.sprite_ptr = get_sprite("proj/hghost"),
.color = &p->color,
.timeout = 12,
.pos = p->pos + p->args[0] * 0.3,
Expand Down
1 change: 0 additions & 1 deletion src/plrmodes/reimu_a.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ static int reimu_spirit_bomb_orb(Projectile *p, int t) {
for(int i = 0; i < 3; ++i) {
PARTICLE(
.sprite = "blast",
.size = 64 * (I+1),
.color = color_mul_scalar(reimu_spirit_orb_color(&(Color){0}, i), 2),
.pos = p->pos + 30 * cexp(I*2*M_PI/3*(i+t*0.1)),
.timeout = 40,
Expand Down
26 changes: 14 additions & 12 deletions src/plrmodes/youmu_a.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void myon_proj_draw(Projectile *p, int t) {
youmu_common_draw_proj(p, &p->color, 1);
}

static Projectile* youmu_mirror_myon_proj(char *tex, complex pos, double speed, double angle, double aoffs, double upfactor, float dmg) {
static Projectile* youmu_mirror_myon_proj(ProjPrototype *proto, complex pos, double speed, double angle, double aoffs, double upfactor, float dmg) {
complex dir = cexp(I*(M_PI/2 + aoffs)) * upfactor + cexp(I * (angle + aoffs)) * (1 - upfactor);
dir = dir / cabs(dir);

Expand All @@ -200,7 +200,7 @@ static Projectile* youmu_mirror_myon_proj(char *tex, complex pos, double speed,

return PROJECTILE(
.color = &c,
.sprite = tex,
.proto = proto,
.pos = pos,
.rule = myon_proj,
.args = { speed*dir },
Expand Down Expand Up @@ -274,27 +274,27 @@ static int youmu_mirror_myon(Enemy *e, int t) {
int dmg_side = 41 - 3 * p;

if(plr->power >= 100 && !((global.frames+0) % 6)) {
youmu_mirror_myon_proj("youmu", e->pos, v2, a, r1*1, u, dmg_side);
youmu_mirror_myon_proj("youmu", e->pos, v2, a, -r1*1, u, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v2, a, r1*1, u, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v2, a, -r1*1, u, dmg_side);
}

if(plr->power >= 200 && !((global.frames+3) % 6)) {
youmu_mirror_myon_proj("youmu", e->pos, v1, a, r2*2, 0, dmg_side);
youmu_mirror_myon_proj("youmu", e->pos, v1, a, -r2*2, 0, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v1, a, r2*2, 0, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v1, a, -r2*2, 0, dmg_side);
}

if(plr->power >= 300 && !((global.frames+0) % 6)) {
youmu_mirror_myon_proj("youmu", e->pos, v2, a, r1*3, 0, dmg_side);
youmu_mirror_myon_proj("youmu", e->pos, v2, a, -r1*3, 0, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v2, a, r1*3, 0, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v2, a, -r1*3, 0, dmg_side);
}

if(plr->power >= 400 && !((global.frames+3) % 6)) {
youmu_mirror_myon_proj("youmu", e->pos, v1, a, r2*4, u, dmg_side);
youmu_mirror_myon_proj("youmu", e->pos, v1, a, -r2*4, u, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v1, a, r2*4, u, dmg_side);
youmu_mirror_myon_proj(pp_youmu, e->pos, v1, a, -r2*4, u, dmg_side);
}

if(!((global.frames+3) % 6)) {
youmu_mirror_myon_proj("youmu", e->pos, v1, a, 0, 0, dmg_center);
youmu_mirror_myon_proj(pp_youmu, e->pos, v1, a, 0, 0, dmg_center);
}
}

Expand All @@ -319,7 +319,9 @@ static int youmu_mirror_self_proj(Projectile *p, int t) {
}

static Projectile* youmu_mirror_self_shot(Player *plr, complex ofs, complex vel, float dmg, double turntime) {
return PROJECTILE("youmu", plr->pos + ofs, 0,
return PROJECTILE(
.proto = pp_youmu,
.pos = plr->pos + ofs,
.type = PROJ_PLAYER,
.damage = dmg,
.shader = "sprite_default",
Expand Down
20 changes: 16 additions & 4 deletions src/plrmodes/youmu_b.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ static int youmu_trap(Projectile *p, int t) {
float a = (i / (float)cnt) * M_PI * 2;
complex dir = cexp(I*(a));

PROJECTILE("youmu", p->pos, RGBA(1, 1, 1, 0.85), youmu_homing,
PROJECTILE(
.proto = pp_youmu,
.pos = p->pos,
.color = RGBA(1, 1, 1, 0.85),
.rule = youmu_homing,
.args = { 5 * (1 + charge) * dir, aim, dur + charge*I, creal(p->pos) - VIEWPORT_H*I },
.type = PROJ_PLAYER,
.damage = dmg,
Expand Down Expand Up @@ -367,7 +371,7 @@ static void youmu_haunting_power_shot(Player *plr, int p) {
complex dir = cexp(I*carg(sign*p*spread-speed*I));

PROJECTILE(
.sprite = "hghost",
.proto = pp_hghost,
.pos = plr->pos,
.rule = youmu_asymptotic,
.color = RGB(0.7 + 0.3 * (1-np), 0.8 + 0.2 * sqrt(1-np), 1.0),
Expand All @@ -392,7 +396,11 @@ static void youmu_haunting_shot(Player *plr) {
int pdmg = 120 - 18 * 4 * (1 - pow(1 - pwr / 4.0, 1.5));
complex aim = 0.15*I;

PROJECTILE("youhoming", plr->pos, RGB(1, 1, 1), youmu_trap,
PROJECTILE(
.proto = pp_youhoming,
.pos = plr->pos,
.color = RGB(1, 1, 1),
.rule = youmu_trap,
.args = { -30.0*I, 120, pcnt+pdmg*I, aim },
.type = PROJ_PLAYER,
.damage = 1000,
Expand All @@ -402,7 +410,11 @@ static void youmu_haunting_shot(Player *plr) {
}
} else {
if(!(global.frames % 6)) {
PROJECTILE("hghost", plr->pos, RGB(0.75, 0.9, 1), youmu_homing,
PROJECTILE(
.proto = pp_hghost,
.pos = plr->pos,
.color = RGB(0.75, 0.9, 1),
.rule = youmu_homing,
.args = { -10.0*I, 0.02*I, 60, VIEWPORT_W*0.5 },
.type = PROJ_PLAYER,
.damage = 120,
Expand Down
28 changes: 0 additions & 28 deletions src/projectile.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,6 @@ static ProjArgs defaults_part = {
};

static void process_projectile_args(ProjArgs *args, ProjArgs *defaults) {
// Detect the deprecated way to spawn projectiles and remap it to prototypes,
// if possible. This is so that I can conserve the remains of my sanity by
// not having to convert every single PROJECTILE call in the game manually
// and in one go. So, TODO: convert every single PROJECTILE call in the game
// and remove this mess.

if(!args->proto && args->sprite && args->size == 0) {
static struct {
const char *name;
ProjPrototype *proto;
} proto_map[] = {
#define PP(name) { #name, &_pp_##name },
#include "projectile_prototypes/all.inc.h"
};

for(int i = 0; i < sizeof(proto_map)/sizeof(*proto_map); ++i) {
if(!strcmp(args->sprite, proto_map[i].name)) {
args->proto = proto_map[i].proto;
args->sprite = NULL;
break;
}
}
}

if(args->proto && args->proto->process_args) {
args->proto->process_args(args->proto, args);
return;
Expand Down Expand Up @@ -124,10 +100,6 @@ static void process_projectile_args(ProjArgs *args, ProjArgs *defaults) {
}
}

if(args->type == PROJ_ENEMY && args->proto) {
// args->proto = pp_crystal;
}

assert(args->type <= PROJ_PLAYER);
}

Expand Down
24 changes: 12 additions & 12 deletions src/projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ struct Projectile {
};

typedef struct ProjArgs {
const char *sprite;
complex pos;
ProjPrototype *proto;
const Color *color;
ProjRule rule;
complex args[RULE_ARGC];
float angle;
ProjFlags flags;
BlendMode blend;
ProjDrawRule draw_rule;
const char *sprite;
Sprite *sprite_ptr;
const char *shader;
ShaderProgram *shader_ptr;
ProjPrototype *proto;
const ShaderCustomParams *shader_params;
ProjectileList *dest;
ProjType type;
Sprite *sprite_ptr;
ProjRule rule;
complex args[RULE_ARGC];
ProjDrawRule draw_rule;
complex pos;
complex size; // affects default draw order, out-of-viewport culling, and grazing
complex collision_size; // affects collision with player (TODO: make this work for player projectiles too?)
ProjType type;
ProjFlags flags;
BlendMode blend;
float angle;
float damage;
DamageType damage_type;
int max_viewport_dist;
Expand All @@ -133,7 +133,7 @@ typedef struct ProjArgs {
// XXX: this is in frames of course, but needs to be float
// to avoid subtle truncation and integer division gotchas.
float timeout;
} /* attr_designated_init */ ProjArgs;
} attr_designated_init ProjArgs;

struct ProjPrototype {
void (*preload)(ProjPrototype *proto);
Expand Down
Loading

0 comments on commit fd09bf0

Please sign in to comment.