Don't redefine standard complex macro; use a new cmplx typedef

This also introduces `float32`, `float64`, and `real` typedefs to be
used in place of `float` and `double` later. `real` is for game code and
other places where we don't particularly care about the precision and
format of the underlying type, and is currently defined to `double`.
`float32` and `float64` should replace `float` and `double` respectively
This commit is contained in:
Andrei Alexeyev 2019-11-22 05:37:11 +02:00
parent 78191b3015
commit 80b1026d08
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
68 changed files with 520 additions and 494 deletions

View file

@ -31,7 +31,7 @@ typedef struct SpellBonus {
static void calc_spell_bonus(Attack *a, SpellBonus *bonus);
Boss* create_boss(char *name, char *ani, complex pos) {
Boss* create_boss(char *name, char *ani, cmplx pos) {
Boss *boss = calloc(1, sizeof(Boss));
boss->name = strdup(name);
@ -401,7 +401,7 @@ static void draw_spell_warning(Font *font, float y_pos, float f, float opacity)
float flash = 0.2 + 0.8 * pow(psin(M_PI + 5 * M_PI * f), 0.5);
f = 0.15 * f + 0.85 * (0.5 * pow(2 * f - 1, 3) + 0.5);
opacity *= 1 - 2 * fabs(f - 0.5);
complex pos = (VIEWPORT_W + msg_width) * f - msg_width * 0.5 + I * y_pos;
cmplx pos = (VIEWPORT_W + msg_width) * f - msg_width * 0.5 + I * y_pos;
draw_boss_text(ALIGN_CENTER, creal(pos), cimag(pos), msg, font, color_mul_scalar(RGBA(1, flash, flash, 1), opacity));
}
@ -409,12 +409,12 @@ static void draw_spell_warning(Font *font, float y_pos, float f, float opacity)
static void draw_spell_name(Boss *b, int time, bool healthbar_radial) {
Font *font = get_font("standard");
complex x0 = VIEWPORT_W/2+I*VIEWPORT_H/3.5;
cmplx x0 = VIEWPORT_W/2+I*VIEWPORT_H/3.5;
float f = clamp((time - 40.0) / 60.0, 0, 1);
float f2 = clamp(time / 80.0, 0, 1);
float y_offset = 26 + healthbar_radial * -15;
float y_text_offset = 5 - font_get_metrics(font)->descent;
complex x = x0 + ((VIEWPORT_W - 10) + I*(y_offset + y_text_offset) - x0) * f*(f+1)*0.5;
cmplx x = x0 + ((VIEWPORT_W - 10) + I*(y_offset + y_text_offset) - x0) * f*(f+1)*0.5;
int strw = text_width(font, b->current->name, 0);
float opacity_noplr = b->hud.spell_opacity * b->hud.global_opacity;
@ -810,8 +810,8 @@ static void boss_rule_extra(Boss *boss, float alpha) {
for(int i = 0; i < cnt; ++i) {
float a = i*2*M_PI/cnt + global.frames / 100.0;
complex dir = cexp(I*(a+global.frames/50.0));
complex vel = dir * 3;
cmplx dir = cexp(I*(a+global.frames/50.0));
cmplx vel = dir * 3;
float v = max(0, alpha - 1);
float psina = psin(a);

View file

@ -76,7 +76,7 @@ typedef struct AttackInfo {
BossRule rule;
BossRule draw_rule;
complex pos_dest;
cmplx pos_dest;
int bonus_rank;
} AttackInfo;
@ -105,7 +105,7 @@ typedef struct Attack {
typedef struct Boss {
ENTITY_INTERFACE_NAMED(struct Boss, ent);
complex pos;
cmplx pos;
Attack *attacks;
Attack *current;
@ -149,7 +149,7 @@ typedef struct Boss {
} hud;
} Boss;
Boss* create_boss(char *name, char *ani, complex pos) attr_nonnull(1, 2) attr_returns_nonnull;
Boss* create_boss(char *name, char *ani, cmplx pos) attr_nonnull(1, 2) attr_returns_nonnull;
void free_boss(Boss *boss) attr_nonnull(1);
void process_boss(Boss **boss) attr_nonnull(1);

View file

@ -8,7 +8,6 @@
#include "taisei.h"
#include <stdio.h>
#include "color.h"
#define COLOR_OP(c1, op, c2) do { \

View file

@ -57,8 +57,8 @@ static void fix_pos0_visual(Enemy *e) {
e->pos0_visual = x + y * I;
}
Enemy *create_enemy_p(EnemyList *enemies, complex pos, float hp, EnemyVisualRule visual_rule, EnemyLogicRule logic_rule,
complex a1, complex a2, complex a3, complex a4) {
Enemy *create_enemy_p(EnemyList *enemies, cmplx pos, float hp, EnemyVisualRule visual_rule, EnemyLogicRule logic_rule,
cmplx a1, cmplx a2, cmplx a3, cmplx a4) {
if(IN_DRAW_CODE) {
log_fatal("Tried to spawn an enemy while in drawing code");
}
@ -142,21 +142,21 @@ void delete_enemies(EnemyList *enemies) {
alist_foreach(enemies, _delete_enemy, NULL);
}
static complex enemy_visual_pos(Enemy *enemy) {
static cmplx enemy_visual_pos(Enemy *enemy) {
double t = (global.frames - enemy->birthtime) / 30.0;
if(t >= 1 || enemy->hp == ENEMY_IMMUNE) {
return enemy->pos;
}
complex p = enemy->pos - enemy->pos0;
cmplx p = enemy->pos - enemy->pos0;
p += t * enemy->pos0 + (1 - t) * enemy->pos0_visual;
return p;
}
static void call_visual_rule(Enemy *e, bool render) {
complex tmp = e->pos;
cmplx tmp = e->pos;
e->pos = enemy_visual_pos(e);
e->visual_rule(e, global.frames - e->birthtime, render);
e->pos = tmp;
@ -216,7 +216,7 @@ int enemy_flare(Projectile *p, int t) { // a[0] velocity, a[1] ref to enemy
void BigFairy(Enemy *e, int t, bool render) {
if(!render) {
if(!(t % 5)) {
complex offset = (frand()-0.5)*30 + (frand()-0.5)*20.0*I;
cmplx offset = (frand()-0.5)*30 + (frand()-0.5)*20.0*I;
PARTICLE(
.sprite = "smoothdot",

View file

@ -36,9 +36,9 @@ enum {
struct Enemy {
ENTITY_INTERFACE_NAMED(Enemy, ent);
complex pos;
complex pos0;
complex pos0_visual;
cmplx pos;
cmplx pos0;
cmplx pos0_visual;
long birthtime;
@ -51,7 +51,7 @@ struct Enemy {
float spawn_hp;
float hp;
complex args[RULE_ARGC];
cmplx args[RULE_ARGC];
float alpha;
#ifdef ENEMY_DEBUG
@ -65,8 +65,8 @@ struct Enemy {
#define create_enemy1c(p,h,d,l,a1) create_enemy_p(&global.enemies,p,h,d,l,a1,0,0,0)
Enemy *create_enemy_p(
EnemyList *enemies, complex pos, float hp, EnemyVisualRule draw_rule, EnemyLogicRule logic_rule,
complex a1, complex a2, complex a3, complex a4
EnemyList *enemies, cmplx pos, float hp, EnemyVisualRule draw_rule, EnemyLogicRule logic_rule,
cmplx a1, cmplx a2, cmplx a3, cmplx a4
);
#ifdef ENEMY_DEBUG

View file

@ -185,7 +185,7 @@ DamageResult ent_damage(EntityInterface *ent, const DamageInfo *damage) {
return res;
}
void ent_area_damage(complex origin, float radius, const DamageInfo *damage, EntityAreaDamageCallback callback, void *callback_arg) {
void ent_area_damage(cmplx origin, float radius, const DamageInfo *damage, EntityAreaDamageCallback callback, void *callback_arg) {
for(Enemy *e = global.enemies.first; e; e = e->next) {
if(
cabs(origin - e->pos) < radius &&

View file

@ -82,7 +82,7 @@ typedef void (*EntityDrawFunc)(EntityInterface *ent);
typedef bool (*EntityPredicate)(EntityInterface *ent);
typedef DamageResult (*EntityDamageFunc)(EntityInterface *target, const DamageInfo *damage);
typedef void (*EntityDrawHookCallback)(EntityInterface *ent, void *arg);
typedef void (*EntityAreaDamageCallback)(EntityInterface *ent, complex ent_origin, void *arg);
typedef void (*EntityAreaDamageCallback)(EntityInterface *ent, cmplx ent_origin, void *arg);
#define ENTITY_INTERFACE_BASE(typename) struct { \
LIST_INTERFACE(typename); \
@ -144,7 +144,7 @@ void ent_register(EntityInterface *ent, EntityType type) attr_nonnull(1);
void ent_unregister(EntityInterface *ent) attr_nonnull(1);
void ent_draw(EntityPredicate predicate);
DamageResult ent_damage(EntityInterface *ent, const DamageInfo *damage) attr_nonnull(1, 2);
void ent_area_damage(complex origin, float radius, const DamageInfo *damage, EntityAreaDamageCallback callback, void *callback_arg) attr_nonnull(3);
void ent_area_damage(cmplx origin, float radius, const DamageInfo *damage, EntityAreaDamageCallback callback, void *callback_arg) attr_nonnull(3);
void ent_area_damage_ellipse(Ellipse ellipse, const DamageInfo *damage, EntityAreaDamageCallback callback, void *callback_arg) attr_nonnull(2);
void ent_hook_pre_draw(EntityDrawHookCallback callback, void *arg);

View file

@ -11,6 +11,7 @@
#include "eventloop_private.h"
#include "events.h"
#include "global.h"
#include <emscripten.h>
static FrameTimes frame_times;

View file

@ -20,7 +20,7 @@ void fpscounter_reset(FPSCounter *fps) {
fps->frametimes[i] = frametime;
}
fps->fps = HRTIME_RESOLUTION / (long double)frametime;
fps->fps = HRTIME_RESOLUTION / (float64x)frametime;
fps->frametime = frametime;
fps->last_update_time = time_get();
}
@ -38,7 +38,7 @@ void fpscounter_update(FPSCounter *fps) {
avg += fps->frametimes[i];
}
fps->fps = HRTIME_RESOLUTION / (avg / (long double)log_size);
fps->fps = HRTIME_RESOLUTION / (avg / (float64x)log_size);
fps->frametime = avg / log_size;
fps->last_update_time = time_get();
}

View file

@ -12,6 +12,7 @@
#include "taisei.h"
#include <SDL.h>
#include "events.h"
#include "config.h"

View file

@ -46,7 +46,7 @@ static const char* item_indicator_sprite_name(ItemType type) {
[ITEM_SURGE - ITEM_FIRST] = NULL,
[ITEM_VOLTAGE - ITEM_FIRST] = "item/voltage_indicator",
};
uint index = type - 1;
assert(index < ARRAY_SIZE(map));
@ -69,7 +69,7 @@ static void ent_draw_item(EntityInterface *ent) {
Item *i = ENT_CAST(ent, Item);
const int indicator_display_y = 6;
float y = cimag(i->pos);
if(y < 0) {
Sprite *s = item_indicator_sprite(i->type);
@ -85,12 +85,12 @@ static void ent_draw_item(EntityInterface *ent) {
}
}
float alpha = 1;
if(i->type == ITEM_PIV && !i->auto_collect) {
alpha *= clamp(2.0 - (global.frames - i->birthtime) / 60.0, 0.1, 1.0);
}
Color *c = RGBA_MUL_ALPHA(1, 1, 1, alpha);
r_draw_sprite(&(SpriteParams) {
@ -101,7 +101,7 @@ static void ent_draw_item(EntityInterface *ent) {
}
Item* create_item(complex pos, complex v, ItemType type) {
Item* create_item(cmplx pos, cmplx v, ItemType type) {
if((creal(pos) < 0 || creal(pos) > VIEWPORT_W)) {
// we need this because we clamp the item position to the viewport boundary during motion
// e.g. enemies that die offscreen shouldn't spawn any items inside the viewport
@ -135,7 +135,7 @@ void delete_item(Item *item) {
objpool_release(stage_object_pools.items, alist_unlink(&global.items, item));
}
Item *create_clear_item(complex pos, uint clear_flags) {
Item *create_clear_item(cmplx pos, uint clear_flags) {
ItemType type = ITEM_PIV;
if(clear_flags & CLEAR_HAZARDS_SPAWN_VOLTAGE) {
@ -166,23 +166,23 @@ void delete_items(void) {
}
}
static complex move_item(Item *i) {
static cmplx move_item(Item *i) {
int t = global.frames - i->birthtime;
complex lim = 0 + 2.0*I;
cmplx lim = 0 + 2.0*I;
complex oldpos = i->pos;
cmplx oldpos = i->pos;
if(i->auto_collect && i->collecttime <= global.frames && global.frames - i->birthtime > 20) {
i->pos -= (7+i->auto_collect)*cexp(I*carg(i->pos - global.plr.pos));
} else {
i->pos = i->pos0 + log(t/5.0 + 1)*5*(i->v + lim) + lim*t;
complex v = i->pos - oldpos;
cmplx v = i->pos - oldpos;
double half = item_sprite(i->type)->w/2.0;
bool over = false;
if((over = creal(i->pos) > VIEWPORT_W-half) || creal(i->pos) < half) {
complex normal = over ? -1 : 1;
cmplx normal = over ? -1 : 1;
v -= 2 * normal * (creal(normal)*creal(v));
v = 1.5*creal(v) - I*fabs(cimag(v));
@ -280,7 +280,7 @@ void process_items(void) {
}
}
complex deltapos = move_item(item);
cmplx deltapos = move_item(item);
int v = may_collect ? collision_item(item) : 0;
if(v == 1) {
@ -346,7 +346,7 @@ int collision_item(Item *i) {
return 0;
}
static void spawn_item_internal(complex pos, ItemType type, float collect_value) {
static void spawn_item_internal(cmplx pos, ItemType type, float collect_value) {
tsrand_fill(2);
Item *i = create_item(pos, (12 + 6 * afrand(0)) * (cexp(I*(3*M_PI/2 + anfrand(1)*M_PI/11))) - 3*I, type);
@ -355,15 +355,15 @@ static void spawn_item_internal(complex pos, ItemType type, float collect_value)
}
}
void spawn_item(complex pos, ItemType type) {
void spawn_item(cmplx pos, ItemType type) {
spawn_item_internal(pos, type, -1);
}
void spawn_and_collect_item(complex pos, ItemType type, float collect_value) {
void spawn_and_collect_item(cmplx pos, ItemType type, float collect_value) {
spawn_item_internal(pos, type, collect_value);
}
static void spawn_items_internal(complex pos, float collect_value, SpawnItemsArgs groups[]) {
static void spawn_items_internal(cmplx pos, float collect_value, SpawnItemsArgs groups[]) {
for(SpawnItemsArgs *g = groups; g->type > 0; ++g) {
for(uint i = 0; i < g->count; ++i) {
spawn_item_internal(pos, g->type, collect_value);
@ -372,12 +372,12 @@ static void spawn_items_internal(complex pos, float collect_value, SpawnItemsArg
}
#undef spawn_items
void spawn_items(complex pos, SpawnItemsArgs groups[]) {
void spawn_items(cmplx pos, SpawnItemsArgs groups[]) {
spawn_items_internal(pos, -1, groups);
}
#undef spawn_and_collect_items
void spawn_and_collect_items(complex pos, float collect_value, SpawnItemsArgs groups[]) {
void spawn_and_collect_items(cmplx pos, float collect_value, SpawnItemsArgs groups[]) {
spawn_items_internal(pos, collect_value, groups);
}

View file

@ -42,35 +42,35 @@ struct Item {
int birthtime;
int collecttime;
complex pos;
complex pos0;
cmplx pos;
cmplx pos0;
int auto_collect;
ItemType type;
float pickup_value;
complex v;
cmplx v;
};
Item *create_item(complex pos, complex v, ItemType type);
Item *create_item(cmplx pos, cmplx v, ItemType type);
void delete_item(Item *item);
void delete_items(void);
Item* create_clear_item(complex pos, uint clear_flags);
Item* create_clear_item(cmplx pos, uint clear_flags);
int collision_item(Item *p);
void process_items(void);
void spawn_item(complex pos, ItemType type);
void spawn_and_collect_item(complex pos, ItemType type, float collect_value);
void spawn_item(cmplx pos, ItemType type);
void spawn_and_collect_item(cmplx pos, ItemType type, float collect_value);
typedef struct SpawnItemsArgs {
ItemType type;
int count;
} SpawnItemsArgs;
void spawn_items(complex pos, SpawnItemsArgs groups[]);
void spawn_and_collect_items(complex pos, float collect_value, SpawnItemsArgs groups[]);
void spawn_items(cmplx pos, SpawnItemsArgs groups[]);
void spawn_and_collect_items(cmplx pos, float collect_value, SpawnItemsArgs groups[]);
#define spawn_items(pos, ...) \
spawn_items(pos, ((SpawnItemsArgs[]) { __VA_ARGS__, { 0 } }))

View file

@ -134,7 +134,7 @@ void lasers_free(void) {
static void ent_draw_laser(EntityInterface *ent);
Laser *create_laser(complex pos, float time, float deathtime, const Color *color, LaserPosRule prule, LaserLogicRule lrule, complex a0, complex a1, complex a2, complex a3) {
Laser *create_laser(cmplx pos, float time, float deathtime, const Color *color, LaserPosRule prule, LaserLogicRule lrule, cmplx a0, cmplx a1, cmplx a2, cmplx a3) {
Laser *l = alist_push(&global.lasers, (Laser*)objpool_acquire(stage_object_pools.lasers));
l->birthtime = global.frames;
@ -173,12 +173,12 @@ Laser *create_laser(complex pos, float time, float deathtime, const Color *color
return l;
}
Laser *create_laserline(complex pos, complex dir, float charge, float dur, const Color *clr) {
Laser *create_laserline(cmplx pos, cmplx dir, float charge, float dur, const Color *clr) {
return create_laserline_ab(pos, (pos)+(dir)*VIEWPORT_H*1.4/cabs(dir), cabs(dir), charge, dur, clr);
}
Laser *create_laserline_ab(complex a, complex b, float width, float charge, float dur, const Color *clr) {
complex m = (b-a)*0.005;
Laser *create_laserline_ab(cmplx a, cmplx b, float width, float charge, float dur, const Color *clr) {
cmplx m = (b-a)*0.005;
return create_laser(a, 200, dur, clr, las_linear, static_laser, m, charge + I*width, 0, 0);
}
@ -272,8 +272,8 @@ static void draw_laser_curve_generic(Laser *l) {
r_vertex_buffer_invalidate(lasers.vbuf);
for(uint i = 0; i < instances; ++i) {
complex pos = l->prule(l, i * 0.5 + timeshift);
complex delta = pos - l->prule(l, i * 0.5 + timeshift - 0.1);
cmplx pos = l->prule(l, i * 0.5 + timeshift);
cmplx delta = pos - l->prule(l, i * 0.5 + timeshift - 0.1);
LaserInstancedAttribs attr;
attr.pos[0] = creal(pos);
@ -438,7 +438,7 @@ void process_lasers(void) {
if(!((global.frames - laser->birthtime) % 2) || kill_now) {
double t = max(0, (global.frames - laser->birthtime)*laser->speed - laser->timespan + laser->timeshift);
complex p = laser->prule(laser, t);
cmplx p = laser->prule(laser, t);
double x = creal(p);
double y = cimag(p);
@ -570,7 +570,7 @@ bool laser_intersects_circle(Laser *l, Circle circle) {
return laser_intersects_ellipse(l, ellipse);
}
complex las_linear(Laser *l, float t) {
cmplx las_linear(Laser *l, float t) {
if(t == EVENT_BIRTH) {
l->shader = r_shader_get_optional("lasers/linear");
l->collision_step = max(3, l->timespan/10);
@ -580,7 +580,7 @@ complex las_linear(Laser *l, float t) {
return l->pos + l->args[0]*t;
}
complex las_accel(Laser *l, float t) {
cmplx las_accel(Laser *l, float t) {
if(t == EVENT_BIRTH) {
l->shader = r_shader_get_optional("lasers/accelerated");
l->collision_step = max(3, l->timespan/10);
@ -590,7 +590,7 @@ complex las_accel(Laser *l, float t) {
return l->pos + l->args[0]*t + 0.5*l->args[1]*t*t;
}
complex las_weird_sine(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
cmplx las_weird_sine(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
// XXX: this used to be called "las_sine", but it's actually not a proper sine wave
// do we even still need this?
@ -603,7 +603,7 @@ complex las_weird_sine(Laser *l, float t) { // [0] = velocity; [1] =
return l->pos + cexp(I * (carg(l->args[0]) + l->args[1] * sin(s) / s)) * t * cabs(l->args[0]);
}
complex las_sine(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
cmplx las_sine(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
// this is actually shaped like a sine wave
if(t == EVENT_BIRTH) {
@ -611,18 +611,18 @@ complex las_sine(Laser *l, float t) { // [0] = velocity; [1] = sin
return 0;
}
complex line_vel = l->args[0];
complex line_dir = line_vel / cabs(line_vel);
complex line_normal = cimag(line_dir) - I*creal(line_dir);
complex sine_amp = l->args[1];
complex sine_freq = l->args[2];
complex sine_phase = l->args[3];
cmplx line_vel = l->args[0];
cmplx line_dir = line_vel / cabs(line_vel);
cmplx line_normal = cimag(line_dir) - I*creal(line_dir);
cmplx sine_amp = l->args[1];
cmplx sine_freq = l->args[2];
cmplx sine_phase = l->args[3];
complex sine_ofs = line_normal * sine_amp * sin(sine_freq * t + sine_phase);
cmplx sine_ofs = line_normal * sine_amp * sin(sine_freq * t + sine_phase);
return l->pos + t * line_vel + sine_ofs;
}
complex las_sine_expanding(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
cmplx las_sine_expanding(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
// XXX: this is also a "weird" one
if(t == EVENT_BIRTH) {
@ -630,7 +630,7 @@ complex las_sine_expanding(Laser *l, float t) { // [0] = velocity; [1] = sine am
return 0;
}
complex velocity = l->args[0];
cmplx velocity = l->args[0];
double amplitude = creal(l->args[1]);
double frequency = creal(l->args[2]);
double phase = creal(l->args[3]);
@ -642,14 +642,14 @@ complex las_sine_expanding(Laser *l, float t) { // [0] = velocity; [1] = sine am
return l->pos + cexp(I * (angle + amplitude * sin(s))) * t * speed;
}
complex las_turning(Laser *l, float t) { // [0] = vel0; [1] = vel1; [2] r: turn begin time, i: turn end time
cmplx las_turning(Laser *l, float t) { // [0] = vel0; [1] = vel1; [2] r: turn begin time, i: turn end time
if(t == EVENT_BIRTH) {
l->shader = r_shader_get_optional("lasers/turning");
return 0;
}
complex v0 = l->args[0];
complex v1 = l->args[1];
cmplx v0 = l->args[0];
cmplx v1 = l->args[1];
float begin = creal(l->args[2]);
float end = cimag(l->args[2]);
@ -657,12 +657,12 @@ complex las_turning(Laser *l, float t) { // [0] = vel0; [1] = vel1; [2] r: turn
a = 1.0 - (0.5 + 0.5 * cos(a * M_PI));
a = 1.0 - pow(1.0 - a, 2);
complex v = v1 * a + v0 * (1 - a);
cmplx v = v1 * a + v0 * (1 - a);
return l->pos + v * t;
}
complex las_circle(Laser *l, float t) {
cmplx las_circle(Laser *l, float t) {
if(t == EVENT_BIRTH) {
l->shader = r_shader_get_optional("lasers/circle");
return 0;

View file

@ -19,14 +19,14 @@
typedef struct Laser Laser;
typedef LIST_ANCHOR(Laser) LaserList;
typedef complex (*LaserPosRule)(Laser* l, float time);
typedef cmplx (*LaserPosRule)(Laser* l, float time);
typedef void (*LaserLogicRule)(Laser* l, int time);
struct Laser {
ENTITY_INTERFACE_NAMED(Laser, ent);
complex pos;
complex args[4];
cmplx pos;
cmplx args[4];
ShaderProgram *shader;
LaserPosRule prule;
@ -56,10 +56,10 @@ struct Laser {
void lasers_preload(void);
void lasers_free(void);
Laser *create_laserline(complex pos, complex dir, float charge, float dur, const Color *clr);
Laser *create_laserline_ab(complex a, complex b, float width, float charge, float dur, const Color *clr);
Laser *create_laserline(cmplx pos, cmplx dir, float charge, float dur, const Color *clr);
Laser *create_laserline_ab(cmplx a, cmplx b, float width, float charge, float dur, const Color *clr);
Laser *create_laser(complex pos, float time, float deathtime, const Color *color, LaserPosRule prule, LaserLogicRule lrule, complex a0, complex a1, complex a2, complex a3);
Laser *create_laser(cmplx pos, float time, float deathtime, const Color *color, LaserPosRule prule, LaserLogicRule lrule, cmplx a0, cmplx a1, cmplx a2, cmplx a3);
void delete_lasers(void);
void process_lasers(void);
@ -67,13 +67,13 @@ bool laser_is_active(Laser *l);
bool laser_is_clearable(Laser *l);
bool clear_laser(Laser *l, uint flags);
complex las_linear(Laser *l, float t);
complex las_accel(Laser *l, float t);
complex las_sine(Laser *l, float t);
complex las_weird_sine(Laser *l, float t);
complex las_sine_expanding(Laser *l, float t);
complex las_turning(Laser *l, float t);
complex las_circle(Laser *l, float t);
cmplx las_linear(Laser *l, float t);
cmplx las_accel(Laser *l, float t);
cmplx las_sine(Laser *l, float t);
cmplx las_weird_sine(Laser *l, float t);
cmplx las_sine_expanding(Laser *l, float t);
cmplx las_turning(Laser *l, float t);
cmplx las_circle(Laser *l, float t);
float laser_charge(Laser *l, int t, float charge, float width);
void static_laser(Laser *l, int t);

View file

@ -9,6 +9,7 @@
#include "taisei.h"
#include <stdio.h>
#include "menu.h"
#include "common.h"
#include "options.h"

View file

@ -8,7 +8,6 @@
#include "taisei.h"
#include <time.h>
#include "global.h"
#include "menu.h"
#include "options.h"

View file

@ -8,7 +8,6 @@
#include "taisei.h"
#include <time.h>
#include "savereplay.h"
#include "mainmenu.h"
#include "global.h"

View file

@ -126,13 +126,13 @@ bool player_add_power(Player *plr, short pdelta) {
return player_set_power(plr, plr->power + plr->power_overflow + pdelta);
}
void player_move(Player *plr, complex delta) {
void player_move(Player *plr, cmplx delta) {
delta *= player_property(plr, PLR_PROP_SPEED);
complex lastpos = plr->pos;
cmplx lastpos = plr->pos;
double x = clamp(creal(plr->pos) + creal(delta), PLR_MIN_BORDER_DIST, VIEWPORT_W - PLR_MIN_BORDER_DIST);
double y = clamp(cimag(plr->pos) + cimag(delta), PLR_MIN_BORDER_DIST, VIEWPORT_H - PLR_MIN_BORDER_DIST);
plr->pos = x + y*I;
complex realdir = plr->pos - lastpos;
cmplx realdir = plr->pos - lastpos;
if(cabs(realdir)) {
plr->lastmovedir = realdir / cabs(realdir);
@ -450,7 +450,7 @@ static int powersurge_trail(Projectile *p, int t) {
return ACTION_ACK;
}
complex v = (global.plr.pos - p->pos) * 0.05;
cmplx v = (global.plr.pos - p->pos) * 0.05;
p->args[0] += (v - p->args[0]) * (1 - t / p->timeout);
p->pos += p->args[0];
@ -1202,7 +1202,7 @@ static bool player_applymovement_gamepad(Player *plr) {
return false;
}
complex direction = (
cmplx direction = (
gamepad_normalize_axis_value(plr->axis_lr) +
gamepad_normalize_axis_value(plr->axis_ud) * I
);
@ -1277,7 +1277,7 @@ void player_applymovement(Player *plr) {
return;
}
complex direction = 0;
cmplx direction = 0;
if(up) direction -= 1.0*I;
if(down) direction += 1.0*I;
@ -1333,7 +1333,7 @@ void player_fix_input(Player *plr) {
}
}
void player_graze(Player *plr, complex pos, int pts, int effect_intensity, const Color *color) {
void player_graze(Player *plr, cmplx pos, int pts, int effect_intensity, const Color *color) {
if(++plr->graze >= PLR_MAX_GRAZE) {
log_debug("Graze counter overflow");
plr->graze = PLR_MAX_GRAZE;
@ -1452,7 +1452,7 @@ static void scoretext_update(StageText *txt, int t, float a) {
#define SCORETEXT_PIV_BIT ((uintptr_t)1 << ((sizeof(uintptr_t) * 8) - 1))
static StageText *find_scoretext_combination_candidate(complex pos, bool is_piv) {
static StageText *find_scoretext_combination_candidate(cmplx pos, bool is_piv) {
for(StageText *stxt = stagetext_list_head(); stxt; stxt = stxt->next) {
if(
stxt->custom.update == scoretext_update &&
@ -1467,7 +1467,7 @@ static StageText *find_scoretext_combination_candidate(complex pos, bool is_piv)
return NULL;
}
static void add_score_text(Player *plr, complex location, uint points, bool is_piv) {
static void add_score_text(Player *plr, cmplx location, uint points, bool is_piv) {
float rnd = nfrand();
StageText *stxt = find_scoretext_combination_candidate(location, is_piv);
@ -1527,7 +1527,7 @@ static void add_score_text(Player *plr, complex location, uint points, bool is_p
}
}
void player_add_points(Player *plr, uint points, complex location) {
void player_add_points(Player *plr, uint points, cmplx location) {
plr->points += points;
while(plr->points >= plr->extralife_threshold) {
@ -1538,7 +1538,7 @@ void player_add_points(Player *plr, uint points, complex location) {
add_score_text(plr, location, points, false);
}
void player_add_piv(Player *plr, uint piv, complex location) {
void player_add_piv(Player *plr, uint piv, cmplx location) {
uint v = plr->point_item_value + piv;
if(v > PLR_MAX_PIV || v < plr->point_item_value) {
@ -1579,7 +1579,7 @@ void player_register_damage(Player *plr, EntityInterface *target, const DamageIn
return;
}
complex pos = NAN;
cmplx pos = NAN;
if(target != NULL) {
switch(target->type) {
@ -1669,9 +1669,9 @@ void player_preload(void) {
// FIXME: where should this be?
complex plrutil_homing_target(complex org, complex fallback) {
cmplx plrutil_homing_target(cmplx org, cmplx fallback) {
double mindst = INFINITY;
complex target = fallback;
cmplx target = fallback;
if(global.boss && boss_is_vulnerable(global.boss)) {
target = global.boss->pos;

View file

@ -92,10 +92,10 @@ typedef struct PowerSurgeBonus {
struct Player {
ENTITY_INTERFACE_NAMED(Player, ent);
complex pos;
complex velocity;
complex deathpos;
complex lastmovedir;
cmplx pos;
cmplx velocity;
cmplx deathpos;
cmplx lastmovedir;
struct PlayerMode *mode;
AniPlayer ani;
@ -190,11 +190,11 @@ bool player_should_shoot(Player *plr, bool extra);
bool player_set_power(Player *plr, short npow);
bool player_add_power(Player *plr, short pdelta);
void player_move(Player*, complex delta);
void player_move(Player*, cmplx delta);
void player_realdeath(Player*);
void player_death(Player*);
void player_graze(Player *plr, complex pos, int pts, int effect_intensity, const Color *color);
void player_graze(Player *plr, cmplx pos, int pts, int effect_intensity, const Color *color);
void player_event(Player *plr, uint8_t type, uint16_t value, bool *out_useful, bool *out_cheat);
bool player_event_with_replay(Player *plr, uint8_t type, uint16_t value);
@ -205,8 +205,8 @@ void player_add_life_fragments(Player *plr, int frags);
void player_add_bomb_fragments(Player *plr, int frags);
void player_add_lives(Player *plr, int lives);
void player_add_bombs(Player *plr, int bombs);
void player_add_points(Player *plr, uint points, complex location);
void player_add_piv(Player *plr, uint piv, complex location);
void player_add_points(Player *plr, uint points, cmplx location);
void player_add_piv(Player *plr, uint piv, cmplx location);
void player_add_voltage(Player *plr, uint voltage);
bool player_drain_voltage(Player *plr, uint voltage);
void player_extend_powersurge(Player *plr, float pos, float neg);
@ -233,6 +233,6 @@ void player_damage_hook(Player *plr, EntityInterface *target, DamageInfo *dmg);
void player_preload(void);
// FIXME: where should this be?
complex plrutil_homing_target(complex org, complex fallback);
cmplx plrutil_homing_target(cmplx org, cmplx fallback);
#endif // IGUARD_player_h

View file

@ -102,7 +102,7 @@ static void draw_masterspark_ring(int t, float width) {
});
}
static void draw_masterspark_beam(complex origin, complex size, float angle, int t, float alpha) {
static void draw_masterspark_beam(cmplx origin, cmplx size, float angle, int t, float alpha) {
r_mat_mv_push();
r_mat_mv_translate(creal(origin), cimag(origin), 0);
r_mat_mv_rotate(angle, 0, 0, 1);

View file

@ -24,8 +24,8 @@ void marisa_common_shot(Player *plr, float dmg);
void marisa_common_slave_visual(Enemy *e, int t, bool render);
typedef struct MarisaBeamInfo {
complex origin;
complex size;
cmplx origin;
cmplx size;
float angle;
int t;
} MarisaBeamInfo;

View file

@ -20,16 +20,16 @@ static int _laser_renderer_ref;
typedef struct MarisaLaserData {
struct {
complex first;
complex last;
cmplx first;
cmplx last;
} trace_hit;
complex prev_pos;
cmplx prev_pos;
float lean;
} MarisaLaserData;
static void draw_laser_beam(complex src, complex dst, double size, double step, double t, Texture *tex, Uniform *u_length) {
complex dir = dst - src;
complex center = (src + dst) * 0.5;
static void draw_laser_beam(cmplx src, cmplx dst, double size, double step, double t, Texture *tex, Uniform *u_length) {
cmplx dir = dst - src;
cmplx center = (src + dst) * 0.5;
r_mat_mv_push();
@ -49,7 +49,7 @@ static void draw_laser_beam(complex src, complex dst, double size, double step,
r_mat_mv_pop();
}
static void trace_laser(Enemy *e, complex vel, float damage) {
static void trace_laser(Enemy *e, cmplx vel, float damage) {
ProjCollisionResult col;
ProjectileList lproj = { .first = NULL };
@ -323,7 +323,7 @@ static void marisa_laser_flash_draw(Projectile *p, int t) {
Color *c = color_mul_scalar(COLOR_COPY(&p->color), 1 - t / p->timeout);
c->r *= (1 - t / p->timeout);
complex pos = p->pos;
cmplx pos = p->pos;
pos += p->args[0] * 10;
r_draw_sprite(&(SpriteParams) {
@ -355,11 +355,11 @@ static int marisa_laser_slave(Enemy *e, int t) {
return 1;
}
complex target_pos = global.plr.pos + (1 - global.plr.focus/30.0)*e->pos0 + (global.plr.focus/30.0)*e->args[0];
cmplx target_pos = global.plr.pos + (1 - global.plr.focus/30.0)*e->pos0 + (global.plr.focus/30.0)*e->args[0];
e->pos += (target_pos - e->pos) * 0.5;
MarisaLaserData *ld = REF(e->args[3]);
complex pdelta = e->pos - ld->prev_pos;
cmplx pdelta = e->pos - ld->prev_pos;
ld->prev_pos = e->pos;
ld->lean += (-0.01 * creal(pdelta) - ld->lean) * 0.2;
@ -369,7 +369,7 @@ static int marisa_laser_slave(Enemy *e, int t) {
f = smoothreclamp(f, 0, 1, 0, 1);
float factor = (1.0 + 0.7 * psin(t/15.0)) * -(1-f) * !!angle;
complex dir = -cexp(I*(angle*factor + ld->lean + M_PI/2));
cmplx dir = -cexp(I*(angle*factor + ld->lean + M_PI/2));
trace_laser(e, 5 * dir, creal(e->args[1]));
PARTICLE(
@ -429,8 +429,8 @@ static void masterspark_damage(Enemy *e) {
float r = 96 * masterspark_width();
float growth = 0.25;
complex v = e->args[0] * cexp(-I*M_PI*0.5);
complex p = global.plr.pos - 30 * I + r * v;
cmplx v = e->args[0] * cexp(-I*M_PI*0.5);
cmplx p = global.plr.pos - 30 * I + r * v;
Rect vp_rect, seg_rect;
vp_rect.top_left = 0;
@ -447,7 +447,7 @@ static void masterspark_damage(Enemy *e) {
r *= 1 + growth;
growth *= 0.75;
complex o = (1 + I);
cmplx o = (1 + I);
seg_rect.top_left = p - o * r;
seg_rect.bottom_right = p + o * r;
@ -472,14 +472,14 @@ static int masterspark(Enemy *e, int t2) {
return 1;
e->args[0] *= cexp(I*(0.005*creal(global.plr.velocity) + nfrand() * 0.005));
complex diroffset = e->args[0];
cmplx diroffset = e->args[0];
float t = player_get_bomb_progress(&global.plr);
if(t >= 3.0/4.0) {
global.shake_view = 8 * (1 - t * 4 + 3);
} else if(t2 % 2 == 0) {
complex dir = -cexp(1.5*I*sin(t2*M_PI*1.12))*I;
cmplx dir = -cexp(1.5*I*sin(t2*M_PI*1.12))*I;
Color *c = HSLA(-t*5.321,1,0.5,0.5*frand());
uint flags = PFLAG_NOREFLECT;
@ -557,7 +557,7 @@ static void marisa_laser_bomb(Player *plr) {
e->ent.draw_layer = LAYER_PLAYER_FOCUS - 1;
}
static Enemy* marisa_laser_spawn_slave(Player *plr, complex pos, complex a0, complex a1, complex a2, complex a3) {
static Enemy* marisa_laser_spawn_slave(Player *plr, cmplx pos, cmplx a0, cmplx a1, cmplx a2, cmplx a3) {
Enemy *e = create_enemy_p(&plr->slaves, pos, ENEMY_IMMUNE, marisa_laser_slave_visual, marisa_laser_slave, a0, a1, a2, a3);
e->pos = plr->pos;
return e;

View file

@ -57,7 +57,7 @@ static int marisa_star_projectile(Projectile *p, int t) {
}
double centerfac = tanh(t/10.); // interpolate between player center and slave center
complex center = global.plr.pos*(1-centerfac) + e->args[2]*centerfac;
cmplx center = global.plr.pos*(1-centerfac) + e->args[2]*centerfac;
double brightener = -1/(1+sqrt(0.03*fabs(creal(p->pos-center))));
p->color = *RGBA(0.3+(1-focus)*0.7+brightener,0.8+brightener,1.0-(1-focus)*0.7+brightener,0.2+brightener);
@ -88,7 +88,7 @@ static int marisa_star_slave(Enemy *e, int t) {
for(int i = 0; i < 2; ++i) {
if(player_should_shoot(&global.plr, true) && !((global.frames+2*i) % 5)) {
float fac = e->args[0]/M_PI/2;
complex v = (1-2*i);
cmplx v = (1-2*i);
v = creal(v)/cabs(v);
v *= 1-0.9*fac;
v -= I*0.04*t*(4-3*fac);
@ -115,7 +115,7 @@ static int marisa_star_slave(Enemy *e, int t) {
e->ent.draw_layer = LAYER_PLAYER_SLAVE;
}
complex d = global.plr.pos-e->args[2];
cmplx d = global.plr.pos-e->args[2];
e->args[2] += (2+2*!global.plr.focus)*d/(cabs(d)+2);
e->pos = e->args[2] + 80*sin(angle)+45*I;
@ -158,7 +158,7 @@ static int marisa_star_orbit(Enemy *e, int t) {
}
double r = 100*pow(tanh(t/20.),2);
complex dir = e->args[1]*r*cexp(I*(sqrt(1000+t*t+0.03*t*t*t))*0.04);
cmplx dir = e->args[1]*r*cexp(I*(sqrt(1000+t*t+0.03*t*t*t))*0.04);
e->pos = global.plr.pos+dir;
float fadetime = 3./4;
@ -258,7 +258,7 @@ static void marisa_star_bomb(Player *plr) {
play_sound("bomb_marisa_b");
for(int i = 0; i < NUM_MARISTAR_SLAVES; i++) {
complex dir = cexp(2*I*M_PI/NUM_MARISTAR_SLAVES*i);
cmplx dir = cexp(2*I*M_PI/NUM_MARISTAR_SLAVES*i);
Enemy *e = create_enemy2c(plr->pos, ENEMY_BOMB, marisa_star_orbit_visual, marisa_star_orbit, i ,dir);
e->ent.draw_layer = LAYER_PLAYER_FOCUS - 1;
}

View file

@ -154,7 +154,7 @@ static int reimu_spirit_homing(Projectile *p, int t) {
p->args[3] = plrutil_homing_target(p->pos, p->args[3]);
double v = cabs(p->args[0]);
complex aimdir = cexp(I*carg(p->args[3] - p->pos));
cmplx aimdir = cexp(I*carg(p->args[3] - p->pos));
double aim = reimu_spirit_homing_aimfactor(t, p->args[1]);
p->args[0] += v * 0.25 * aim * aimdir;
@ -174,10 +174,10 @@ static Color *reimu_spirit_orb_color(Color *c, int i) {
}
static void reimu_spirit_bomb_orb_visual(Projectile *p, int t) {
complex pos = p->pos;
cmplx pos = p->pos;
for(int i = 0; i < 3; i++) {
complex offset = (10 + pow(t, 0.5)) * cexp(I * (2 * M_PI / 3*i + sqrt(1 + t * t / 300.0)));
cmplx offset = (10 + pow(t, 0.5)) * cexp(I * (2 * M_PI / 3*i + sqrt(1 + t * t / 300.0)));
Color c;
r_draw_sprite(&(SpriteParams) {
@ -307,21 +307,21 @@ static int reimu_spirit_bomb_orb(Projectile *p, int t) {
play_sound("redirect");
}
complex target_circle = global.plr.pos + 10 * sqrt(t) * p->args[0]*(1 + 0.1 * sin(0.2*t));
cmplx target_circle = global.plr.pos + 10 * sqrt(t) * p->args[0]*(1 + 0.1 * sin(0.2*t));
p->args[0] *= cexp(I*0.12);
double circlestrength = 1.0 / (1 + exp(t-circletime));
p->args[3] = plrutil_homing_target(p->pos, p->args[3]);
complex target_homing = p->args[3];
complex homing = target_homing - p->pos;
complex v = 0.3 * (circlestrength * (target_circle - p->pos) + 0.2 * (1-circlestrength) * (homing + 2*homing/(cabs(homing)+0.01)));
cmplx target_homing = p->args[3];
cmplx homing = target_homing - p->pos;
cmplx v = 0.3 * (circlestrength * (target_circle - p->pos) + 0.2 * (1-circlestrength) * (homing + 2*homing/(cabs(homing)+0.01)));
p->args[2] += (v - p->args[2]) * 0.1;
p->pos += p->args[2];
for(int i = 0; i < 3 /*&& circlestrength < 1*/; i++) {
complex trail_pos = p->pos + 10 * cexp(I*2*M_PI/3*(i+t*0.1));
complex trail_vel = global.plr.pos - trail_pos;
cmplx trail_pos = p->pos + 10 * cexp(I*2*M_PI/3*(i+t*0.1));
cmplx trail_vel = global.plr.pos - trail_pos;
trail_vel *= 3 * circlestrength / cabs(trail_vel);
PARTICLE(
@ -439,7 +439,7 @@ static void reimu_spirit_slave_shot(Enemy *e, int t) {
.shader = "sprite_default",
);
} else if(!(st % 12)) {
complex v = -10 * I * cexp(I*cimag(e->args[0]));
cmplx v = -10 * I * cexp(I*cimag(e->args[0]));
PROJECTILE(
.proto = pp_ofuda,
@ -546,7 +546,7 @@ static void reimu_spirit_yinyang_unfocused_visual(Enemy *e, int t, bool render)
}
}
static inline Enemy* reimu_spirit_spawn_slave(Player *plr, complex pos, complex a0, complex a1, complex a2, complex a3, EnemyVisualRule visual) {
static inline Enemy* reimu_spirit_spawn_slave(Player *plr, cmplx pos, cmplx a0, cmplx a1, cmplx a2, cmplx a3, EnemyVisualRule visual) {
Enemy *e = create_enemy_p(&plr->slaves, pos, ENEMY_IMMUNE, visual, reimu_spirit_slave, a0, a1, a2, a3);