Class PathRetryThrottle

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

public final class PathRetryThrottle extends Object
Back-off for a path search that keeps getting the NPC nowhere. A retry runs the same search against the same world, so something has to change before it can answer differently. This counts the attempts that delivered no usable path and holds the motion still for a while once they pass the allowance the role grants.

The first few retries carry no delay. That covers a partial path that gets the NPC closer on each try, which is progress even though the search never reached the goal.

The caller owns the clock and calls advance(double) once per tick. The counts and the delay live here, so nothing mirrors them.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PathRetryThrottle(double delayMin, double delayMax, int ignoredRetryCount)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(double dt)
    Moves the clock on by one tick.
    void
    Starts a delay, unless one already runs or the retries are still free.
    int
     
    double
    Time the throttle has been active.
    boolean
    True while a delay runs, so the caller must not search again yet.
    boolean
    True once the retries have used up the free allowance, which is when a delay applies.
    void
    Counts one attempt that left the NPC where it was.
    void
    Drops the count, the delay and the accumulated time, so the next search starts clean.

    Methods inherited from class Object

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

    • PathRetryThrottle

      public PathRetryThrottle(double delayMin, double delayMax, int ignoredRetryCount)
      Parameters:
      delayMin - shortest delay a retry can draw, in seconds
      delayMax - longest delay a retry can draw, in seconds. Zero turns the delay off
      ignoredRetryCount - retries that carry no delay
  • Method Details

    • advance

      public void advance(double dt)
      Moves the clock on by one tick. Counts the time spent throttling up, and the delay down.
    • isDelayed

      public boolean isDelayed()
      True while a delay runs, so the caller must not search again yet.
    • isThrottling

      public boolean isThrottling()
      True once the retries have used up the free allowance, which is when a delay applies.
    • recordRetry

      public void recordRetry()
      Counts one attempt that left the NPC where it was.
    • armDelay

      public void armDelay()
      Starts a delay, unless one already runs or the retries are still free.
    • reset

      public void reset()
      Drops the count, the delay and the accumulated time, so the next search starts clean.
    • getRetryCount

      public int getRetryCount()
    • getThrottledTime

      public double getThrottledTime()
      Time the throttle has been active. A nav state reports it, and a sensor can match on it.