lasers: remove legacy compat glue
This commit is contained in:
parent
e7c77216d2
commit
84a909bc8c
3 changed files with 1 additions and 147 deletions
|
@ -23,23 +23,11 @@ typedef struct LaserRule {
|
|||
alignas(cmplx) char data[sizeof(cmplx) * 5];
|
||||
} LaserRule;
|
||||
|
||||
typedef cmplx (*LegacyLaserPosRule)(Laser *l, float time);
|
||||
typedef LegacyLaserPosRule LaserPosRule
|
||||
attr_deprecated("For compatibility with legacy rules");
|
||||
|
||||
typedef LIST_ANCHOR(Laser) LaserList;
|
||||
|
||||
DEFINE_ENTITY_TYPE(Laser, {
|
||||
cmplx pos;
|
||||
|
||||
union {
|
||||
LaserRule rule;
|
||||
struct {
|
||||
char _padding[offsetof(LaserRule, data)];
|
||||
cmplx args[(sizeof(LaserRule) - offsetof(LaserRule, data)) / sizeof(cmplx)]
|
||||
attr_deprecated("For compatibility with legacy rules");
|
||||
};
|
||||
};
|
||||
LaserRule rule;
|
||||
|
||||
struct {
|
||||
int segments_ofs;
|
||||
|
@ -65,15 +53,6 @@ DEFINE_ENTITY_TYPE(Laser, {
|
|||
uchar collision_active : 1;
|
||||
});
|
||||
|
||||
#define create_lasercurve1c(p, time, deathtime, clr, rule, a0) \
|
||||
create_laser(p, time, deathtime, clr, laser_rule_compat(rule, a0, 0, 0, 0))
|
||||
#define create_lasercurve2c(p, time, deathtime, clr, rule, a0, a1) \
|
||||
create_laser(p, time, deathtime, clr, laser_rule_compat(rule, a0, a1, 0, 0))
|
||||
#define create_lasercurve3c(p, time, deathtime, clr, rule, a0, a1, a2) \
|
||||
create_laser(p, time, deathtime, clr, laser_rule_compat(rule, a0, a1, a2, 0))
|
||||
#define create_lasercurve4c(p, time, deathtime, clr, rule, a0, a1, a2, a3) \
|
||||
create_laser(p, time, deathtime, clr, laser_rule_compat(rule, a0, a1, a2, a3))
|
||||
|
||||
void lasers_init(void);
|
||||
void lasers_shutdown(void);
|
||||
|
||||
|
|
|
@ -186,110 +186,3 @@ Laser *create_dynamic_laser(
|
|||
INVOKE_TASK(laser_dynamic, &l, pos, time, deathtime, color, out_move);
|
||||
return l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Legacy rules for compatibility (TODO remove)
|
||||
*/
|
||||
|
||||
static cmplx laser_rule_compat_impl(Laser *l, real t, void *ruledata) {
|
||||
LaserRuleCompatData *rd = ruledata;
|
||||
return rd->oldrule(l, t);
|
||||
}
|
||||
|
||||
LaserRule laser_rule_compat(LegacyLaserPosRule oldrule, cmplx a0, cmplx a1, cmplx a2, cmplx a3) {
|
||||
LaserRuleCompatData rd = {
|
||||
.oldrule = oldrule,
|
||||
.args = { a0, a1, a2, a3 },
|
||||
};
|
||||
|
||||
return MAKE_LASER_RULE(laser_rule_compat_impl, rd);
|
||||
}
|
||||
|
||||
IMPL_LASER_RULE_DATAGETTER(laser_get_ruledata_compat,
|
||||
laser_rule_compat_impl, LaserRuleCompatData)
|
||||
|
||||
DIAGNOSTIC(ignored "-Wdeprecated-declarations")
|
||||
|
||||
cmplx las_linear(Laser *l, float t) {
|
||||
if(t == EVENT_BIRTH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return l->pos + l->args[0]*t;
|
||||
}
|
||||
|
||||
cmplx las_accel(Laser *l, float t) {
|
||||
if(t == EVENT_BIRTH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return l->pos + l->args[0]*t + 0.5*l->args[1]*t*t;
|
||||
}
|
||||
|
||||
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) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cmplx line_vel = l->args[0];
|
||||
cmplx line_dir = line_vel / cabs(line_vel);
|
||||
cmplx line_normal = im(line_dir) - I*re(line_dir);
|
||||
cmplx sine_amp = l->args[1];
|
||||
real sine_freq = re(l->args[2]);
|
||||
real sine_phase = re(l->args[3]);
|
||||
|
||||
cmplx sine_ofs = line_normal * sine_amp * sin(sine_freq * t + sine_phase);
|
||||
return l->pos + t * line_vel + sine_ofs;
|
||||
}
|
||||
|
||||
cmplx las_sine_expanding(Laser *l, float t) { // [0] = velocity; [1] = sine amplitude; [2] = sine frequency; [3] = sine phase
|
||||
|
||||
if(t == EVENT_BIRTH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cmplx velocity = l->args[0];
|
||||
real amplitude = re(l->args[1]);
|
||||
real frequency = re(l->args[2]);
|
||||
real phase = re(l->args[3]);
|
||||
|
||||
real angle = carg(velocity);
|
||||
real speed = cabs(velocity);
|
||||
|
||||
real s = (frequency * t + phase);
|
||||
return l->pos + cdir(angle + amplitude * sin(s)) * t * speed;
|
||||
}
|
||||
|
||||
cmplx las_turning(Laser *l, float t) { // [0] = vel0; [1] = vel1; [2] r: turn begin time, i: turn end time
|
||||
if(t == EVENT_BIRTH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
cmplx v0 = l->args[0];
|
||||
cmplx v1 = l->args[1];
|
||||
float begin = re(l->args[2]);
|
||||
float end = im(l->args[2]);
|
||||
|
||||
float a = clamp((t - begin) / (end - begin), 0, 1);
|
||||
a = 1.0 - (0.5 + 0.5 * cos(a * M_PI));
|
||||
a = 1.0 - pow(1.0 - a, 2);
|
||||
|
||||
cmplx v = v1 * a + v0 * (1 - a);
|
||||
|
||||
return l->pos + v * t;
|
||||
}
|
||||
|
||||
cmplx las_circle(Laser *l, float t) {
|
||||
if(t == EVENT_BIRTH) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
real turn_speed = re(l->args[0]);
|
||||
real time_ofs = im(l->args[0]);
|
||||
real radius = re(l->args[1]);
|
||||
|
||||
return l->pos + radius * cdir(turn_speed * (t + time_ofs));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,15 +12,6 @@
|
|||
#include "laser.h"
|
||||
#include "ringbuf.h"
|
||||
|
||||
cmplx las_linear(Laser *l, float t) attr_deprecated("Use laser_rule_linear");
|
||||
cmplx las_accel(Laser *l, float t) attr_deprecated("Use laser_rule_accelerated");
|
||||
cmplx las_sine(Laser *l, float t) attr_deprecated("Use laser_rule_sine");
|
||||
cmplx las_sine_expanding(Laser *l, float t) attr_deprecated("Use laser_rule_sine_expanding");
|
||||
cmplx las_turning(Laser *l, float t) attr_deprecated("No replacement");
|
||||
cmplx las_circle(Laser *l, float t) attr_deprecated("Use laser_rule_arc");
|
||||
|
||||
extern LaserRuleFunc laser_rule_compat_adapter;
|
||||
|
||||
typedef struct LaserRuleLinearData {
|
||||
cmplx velocity;
|
||||
} LaserRuleLinearData;
|
||||
|
@ -65,15 +56,6 @@ typedef struct LaserRuleArcData {
|
|||
LaserRule laser_rule_arc(cmplx radius, real turnspeed, real timeofs);
|
||||
LaserRuleArcData *laser_get_ruledata_arc(Laser *l);
|
||||
|
||||
typedef struct LaserRuleCompatData {
|
||||
cmplx args[4];
|
||||
LegacyLaserPosRule oldrule;
|
||||
} LaserRuleCompatData;
|
||||
|
||||
LaserRule laser_rule_compat(LegacyLaserPosRule oldrule, cmplx a0, cmplx a1, cmplx a2, cmplx a3)
|
||||
attr_deprecated("Use the new rule format (see laser/rules.h)");
|
||||
LaserRuleCompatData *laser_get_ruledata_compat(Laser *l);
|
||||
|
||||
typedef struct LaserRuleDynamicTaskData {
|
||||
MoveParams move;
|
||||
RING_BUFFER(cmplx) history;
|
||||
|
|
Loading…
Reference in a new issue