Skip to content

Feature: Body Temperature Tick Throttling

Tsu edited this page May 31, 2026 · 1 revision

This feature spreads expensive body-temperature updates with configurable intervals and per-entity jitter.

Where It Lives

Main patch:

  • patches/VSSurvivalMod/Entity/Behavior/BehaviorBodyTemperature.cs.patch

New Threshold Fields

The patch introduces server-side interval thresholds per entity:

float stratumUpdateThreshold = 2f;
float stratumHeatSourceThreshold = 5f;
float stratumFreezingAnimThreshold = 1f;
float stratumDamageCheckThreshold = 10f;

Config-Driven Thresholds with Jitter

On initialization, the behavior reflectively reads Performance.BodyTemperature config and applies jitter:

float upd = (float)bt.GetType().GetProperty("UpdateIntervalSeconds").GetValue(bt);
float heat = (float)bt.GetType().GetProperty("HeatSourceIntervalSeconds").GetValue(bt);
float anim = (float)bt.GetType().GetProperty("FreezingAnimIntervalSeconds").GetValue(bt);
float dmg = (float)bt.GetType().GetProperty("DamageCheckIntervalSeconds").GetValue(bt);
float jit = (float)bt.GetType().GetProperty("JitterPercent").GetValue(bt);
float jitter = 1f + ((float)entity.World.Rand.NextDouble() * 2f - 1f) * jit;

Applied thresholds:

stratumUpdateThreshold = upd * jitter;
stratumHeatSourceThreshold = heat * jitter;
stratumFreezingAnimThreshold = anim * jitter;
stratumDamageCheckThreshold = dmg * jitter;

Fast-Path Early Return

OnGameTick now exits early when no accumulator reached its threshold:

if (freezingAnimAccum <= stratumFreezingAnimThreshold && slowaccum <= stratumHeatSourceThreshold && veryslowaccum <= stratumDamageCheckThreshold && accum <= stratumUpdateThreshold)
{
    return;
}

This skips repeated position and environment work on ticks where nothing is due.

Threshold Replacements in Existing Logic

Hardcoded intervals are replaced with threshold fields:

  • veryslowaccum > 10 -> veryslowaccum > stratumDamageCheckThreshold
  • slowaccum > 3 -> slowaccum > stratumHeatSourceThreshold
  • accum > 1 -> accum > stratumUpdateThreshold
  • freezing animation runs by stratumFreezingAnimThreshold

Related Files

  • patches/VSSurvivalMod/Entity/Behavior/BehaviorBodyTemperature.cs.patch
  • VSSurvivalMod/Entity/Behavior/BehaviorBodyTemperature.cs
  • sources/VintagestoryLib/Vintagestory/Server/StratumConfig.cs (Performance.BodyTemperature)

Clone this wiki locally