using Unity.Mathematics;
namespace ProjectM.Simulation
{
///
/// Pure, deterministic respawn-timer math (no RNG, no wall-clock) — unit-testable in EditMode without a netcode
/// world (mirrors / ). Ticks are the server's monotonic
/// simulation ticks; a stored value of 0 means "no respawn pending / alive". Comparisons use a wrap-safe signed-delta (modular) compare — matching
/// semantics — so they hold across the uint tick wraparound.
///
public static class RespawnMath
{
///
/// The tick at which a death at should respawn, given
/// (clamped to >= 1). Never returns 0 (0 is the "no respawn pending"
/// sentinel), so a death exactly at tick 0 still schedules a recovery.
///
public static uint RespawnTick(uint deathTick, int delayTicks)
{
uint delay = (uint)math.max(1, delayTicks);
uint t = deathTick + delay;
return t == 0u ? 1u : t;
}
///
/// True when has reached/passed a scheduled (and one
/// is actually scheduled, i.e. non-zero).
///
public static bool IsDue(uint now, uint respawnTick)
{
// Wrap-safe modular compare (signed delta), NOT a raw `now >= respawnTick` (which is unsafe at the
// uint tick wraparound). Matches NetworkTick.IsNewerThan; keeps this helper pure-uint + unit-testable.
return respawnTick != 0u && (int)(now - respawnTick) >= 0;
}
}
}