Skip to content

Commit

Permalink
lasers: improve collision; move to lasers/
Browse files Browse the repository at this point in the history
Moved quantization out of the draw code. The laser is now quantized once
per frame, and the segment data is used for both collisions and
rendering. Player motion is now accounted for as well, preventing
phasing through thin lasers. The overall result is more precise *and*
faster collision detection.
  • Loading branch information
Akaricchi committed Aug 25, 2021
1 parent 20b360f commit 1ae8811
Show file tree
Hide file tree
Showing 15 changed files with 963 additions and 726 deletions.
415 changes: 0 additions & 415 deletions src/laser.c

This file was deleted.

80 changes: 2 additions & 78 deletions src/laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,7 @@

#include "taisei.h"

#include "util.h"
#include "projectile.h"
#include "resource/shader_program.h"
#include "entity.h"
#include "laserdraw.h"

typedef LIST_ANCHOR(Laser) LaserList;

typedef cmplx (*LaserPosRule)(Laser* l, float time);
typedef void (*LaserLogicRule)(Laser* l, int time);

DEFINE_ENTITY_TYPE(Laser, {
cmplx pos;
cmplx args[4];

// NOTE: in the future we may reuse this to customize the SDF application shader
ShaderProgram *shader attr_deprecated("Specialized shape shaders are no longer supported");

LaserPosRule prule;
LaserLogicRule lrule;

// NOTE: this field is considered private
LaserRenderData _renderdata;

Color color;

int birthtime;
int next_graze;
float timespan;
float deathtime;
float timeshift;
float speed;
float width;
float width_exponent;
float collision_step;
uint clear_flags;

uchar unclearable : 1;
uchar collision_active : 1;
});

#define create_lasercurve1c(p, time, deathtime, clr, rule, a0) create_laser(p, time, deathtime, clr, rule, 0, a0, 0, 0, 0)
#define create_lasercurve2c(p, time, deathtime, clr, rule, a0, a1) create_laser(p, time, deathtime, clr, rule, 0, a0, a1, 0, 0)
#define create_lasercurve3c(p, time, deathtime, clr, rule, a0, a1, a2) create_laser(p, time, deathtime, clr, rule, 0, a0, a1, a2, 0)
#define create_lasercurve4c(p, time, deathtime, clr, rule, a0, a1, a2, a3) create_laser(p, time, deathtime, clr, rule, 0, a0, a1, a2, a3)

void delete_lasers(void);
void process_lasers(void);

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(cmplx pos, float time, float deathtime, const Color *color, LaserPosRule prule, LaserLogicRule lrule, cmplx a0, cmplx a1, cmplx a2, cmplx a3);

bool laser_is_active(Laser *l);
bool laser_is_clearable(Laser *l);
bool clear_laser(Laser *l, uint flags);

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);

void laser_make_static(Laser *l);
void laser_charge(Laser *l, int t, float charge, float width);

void static_laser(Laser *l, int t);

bool laser_intersects_circle(Laser *l, Circle circle);
bool laser_intersects_ellipse(Laser *l, Ellipse ellipse);

DECLARE_EXTERN_TASK(laser_charge, {
BoxedLaser laser;
float charge_delay;
float target_width;
});
// TODO remove this stub header
#include "lasers/laser.h"

#endif // IGUARD_laser_h
Loading

0 comments on commit 1ae8811

Please sign in to comment.