Skip to content

Commit

Permalink
TGMC-ifies LERP(), moves to DEFINES
Browse files Browse the repository at this point in the history
  • Loading branch information
Doubleumc committed Jan 11, 2024
1 parent ae64bd1 commit c044b78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/_math.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@

/// Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive
#define SIGN(x) ( ((x) > 0) - ((x) < 0) )

/// Performs a linear interpolation between a and b. Note that amount=0 returns a, amount=1 returns b, and amount=0.5 returns the mean of a and b.
#define LERP(a, b, amount) ( amount ? ((a) + ((b) - (a)) * (amount)) : a )
12 changes: 3 additions & 9 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@

return FALSE

//#define LERP(a, b, t) (a + (b - a) * CLAMP01(t))
#define LERP_UNCLAMPED(a, b, t) (a + (b - a) * t)

/// Animates the projectile across the process'ed flight.
/obj/projectile/proc/animate_flight(turf/start_turf, start_pixel_x, start_pixel_y, delta_time)
//Get pixelspace coordinates of start and end of visual path
Expand All @@ -301,8 +298,8 @@
var/vis_current = vis_travelled + speed * (time_carry * 0.1) //speed * (time_carry * 0.1) for remainder time movement, visually "catching up" to where it should be
var/vis_interpolant = vis_current / vis_length

var/pixel_x_lerped = LERP_UNCLAMPED(pixel_x_source, pixel_x_target, vis_interpolant)
var/pixel_y_lerped = LERP_UNCLAMPED(pixel_y_source, pixel_y_target, vis_interpolant)
var/pixel_x_lerped = LERP(pixel_x_source, pixel_x_target, vis_interpolant)
var/pixel_y_lerped = LERP(pixel_y_source, pixel_y_target, vis_interpolant)

//Convert pixelspace to pixel offset relative to current loc

Expand All @@ -319,7 +316,7 @@

var/dist_current = distance_travelled + speed * (time_carry * 0.1) //speed * (time_carry * 0.1) for remainder time fade-in
var/alpha_interpolant = dist_current - 1 //-1 so it transitions from transparent to opaque between dist 1-2
var/alpha_new = LERP_UNCLAMPED(0, 255, alpha_interpolant)
var/alpha_new = LERP(0, 255, alpha_interpolant)

//Animate the visuals from starting position to new position

Expand All @@ -332,9 +329,6 @@
var/anim_time = delta_time * 0.1
animate(src, pixel_x = pixel_x_rel_new, pixel_y = pixel_y_rel_new, alpha = alpha_new, time = anim_time, flags = ANIMATION_END_NOW)

//#undef LERP
#undef LERP_UNCLAMPED

/// Flies the projectile forward one single turf
/obj/projectile/proc/fly()
SHOULD_NOT_SLEEP(TRUE)
Expand Down

0 comments on commit c044b78

Please sign in to comment.