Class EasingRamp

java.lang.Object
com.hypixel.hytale.server.npc.util.EasingRamp

public final class EasingRamp extends Object
Speed schedule for one ramp of a charge. A BiasedEasing gives the shape and the phase duration comes from the distance the ramp has to cover, so a full sweep covers that distance.

Progress through the curve is a function of elapsed time, never of position, so the ramp cannot get stuck at its own zero-speed boundary.

An acceleration ramp reads the curve forward, from the slow end up to the fast end. A deceleration ramp reads it backwards, so it leaves fast and arrives slow. Both therefore give a config value the same meaning in either phase.

The EasingCurveMode decides what the curve means:

  • VelocityOverTime reads it as relative speed and commands that speed directly. The curve is traversed over [startOffset, 1] rather than [0, 1], so the ramp bottoms out at the configured minimum relative speed instead of at a standstill.
  • DistanceOverTime reads it as the fraction of the distance covered and commands the speed that closes the gap to that position over the tick. The minimum relative speed becomes the slope at the slow end, solved for when the curve is built. The half time value is mapped onto the fractions a ramp can reach, see curveBiasFor(EasingCurveMode, double). Because the loop is closed on position, the ramp arrives exactly on its distance and recovers from ticks that delivered less than they were asked for.

A ramp also carries the latch: a deceleration ramp only picks up its distance once the charge reaches its zone, and has to re-latch when the path changes under it. An acceleration ramp runs from the start of the charge and is driven straight from the charge clock, so it leaves the latch unused.

  • Method Summary

    Modifier and Type
    Method
    Description
    static EasingRamp
    acceleration(EasingCurveMode mode, double halfTimeValue, double halfTimeSteepness, double endSteepness, double minimumRelativeSpeed)
    Ramp that reads the curve forward, from its slow end up to its fast end.
    void
    advance(double dt)
     
    double
    commandedSpeed(double distance, double travelled, double elapsedTime, double maxSpeed, double dt)
    Speed this ramp asks for, in blocks per second, never above maxSpeed.
    static double
    curveBiasFor(EasingCurveMode mode, double halfTimeValue)
    Bias of the curve that a half time value asks for.
    static EasingRamp
    deceleration(EasingCurveMode mode, double halfTimeValue, double halfTimeSteepness, double endSteepness, double minimumRelativeSpeed)
    Ramp that reads the curve backwards, from its fast end down to its slow end.
    double
    distanceFractionAt(double progress)
    Fraction of the ramp's distance covered at progress through its duration, which is the position profile the ramp follows.
    void
    Leaves the phase, so a later latch(double, double) starts clean.
    double
    durationFor(double distance, double maxSpeed)
    Time a full sweep needs to cover distance.
    double
     
    double
     
    double
     
     
    boolean
     
    boolean
    isScheduleComplete(double maxSpeed)
    Whether the latched schedule has run its full duration.
    void
    latch(double distance, double elapsedTime)
    Picks up distance and starts the phase clock at elapsedTime.
    static double
    zoneOverlapScale(double accelerationDistance, double decelerationDistance, double chargeDistance)
    Factor that shrinks both ramp zones so they meet without overlapping.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • acceleration

      @Nonnull public static EasingRamp acceleration(@Nonnull EasingCurveMode mode, double halfTimeValue, double halfTimeSteepness, double endSteepness, double minimumRelativeSpeed)
      Ramp that reads the curve forward, from its slow end up to its fast end.
    • deceleration

      @Nonnull public static EasingRamp deceleration(@Nonnull EasingCurveMode mode, double halfTimeValue, double halfTimeSteepness, double endSteepness, double minimumRelativeSpeed)
      Ramp that reads the curve backwards, from its fast end down to its slow end.
    • curveBiasFor

      public static double curveBiasFor(@Nonnull EasingCurveMode mode, double halfTimeValue)
      Bias of the curve that a half time value asks for.

      VelocityOverTime reads the value as a speed, where the whole range describes a ramp, so it is the bias as it stands. DistanceOverTime reads it as a fraction of the distance, which CONSTANT_SPEED_DISTANCE_FRACTION bounds, so the value is mapped onto the fractions a ramp can reach. A value of 1 then asks for the even split that only a constant speed delivers, and the default 0.5 asks for the quarter that an even acceleration covers.

      The value fixes one point of the curve and nothing else. The steepness values shape the rest, so 0.5 gives the split of an even acceleration but not its straight speed profile.

      A caller that names a steepness default by hand needs this, because the steepness bounds are relative to the bias and not to the config value.

    • zoneOverlapScale

      public static double zoneOverlapScale(double accelerationDistance, double decelerationDistance, double chargeDistance)
      Factor that shrinks both ramp zones so they meet without overlapping. Without it the two schedules each assume they alone control the speed over their full distance budget, while taking the lower of the two speeds actually lets the still-ramping acceleration curve hold the speed below what the deceleration schedule assumed. That starves the deceleration of distance and leaves it to crawl at its floor speed to make up the shortfall. Shrinking mirrors how ease-in and ease-out are compressed for a short animation.
    • durationFor

      public double durationFor(double distance, double maxSpeed)
      Time a full sweep needs to cover distance. Zero when there is nothing to ramp over, which callers read as "this ramp does not constrain the speed".

      Velocity mode divides the distance by the mean speed of the sweep. Distance mode multiplies by the peak slope instead, which is what puts the fastest speed the ramp commands exactly on maxSpeed.

    • commandedSpeed

      public double commandedSpeed(double distance, double travelled, double elapsedTime, double maxSpeed, double dt)
      Speed this ramp asks for, in blocks per second, never above maxSpeed.

      Velocity mode samples the midpoint of the tick. Distance mode targets the profile position at the end of the tick.

      Acceleration hands over when its schedule ends. Deceleration holds the stop position until the caller ends the phase.

      Parameters:
      distance - distance the ramp has to cover
      travelled - distance covered since the ramp started
      elapsedTime - time since the ramp started, at the end of this tick
      maxSpeed - fastest speed the ramp may command
      dt - length of this tick
    • distanceFractionAt

      public double distanceFractionAt(double progress)
      Fraction of the ramp's distance covered at progress through its duration, which is the position profile the ramp follows.

      Distance mode reads this straight off the curve. Velocity mode integrates its speed profile.

    • isScheduleComplete

      public boolean isScheduleComplete(double maxSpeed)
      Whether the latched schedule has run its full duration.
    • latch

      public void latch(double distance, double elapsedTime)
      Picks up distance and starts the phase clock at elapsedTime.
    • drop

      public void drop()
      Leaves the phase, so a later latch(double, double) starts clean.
    • advance

      public void advance(double dt)
    • isLatched

      public boolean isLatched()
    • getLatchedDistance

      public double getLatchedDistance()
    • getLatchedElapsedTime

      public double getLatchedElapsedTime()
    • getMode

      @Nonnull public EasingCurveMode getMode()
    • getMinimumRelativeSpeed

      public double getMinimumRelativeSpeed()