-
-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: Selection Raytrace Throttle
Tsu edited this page May 31, 2026
·
1 revision
This feature reduces per-tick selection raytracing cost for idle players.
In ServerSystemEntitySimulation.OnServerTick, Stratum tracks last traced position/rotation per client and only retraces when needed.
bool moved = (dx * dx + dy * dy + dz * dz) > StratumSelectionPosThresholdSq;
bool turned = dyaw > StratumSelectionRotThreshold || dpitch > StratumSelectionRotThreshold;
bool ticksElapsed = (stratumSelectionTickIndex - selState.LastTraceTickIndex) >= StratumSelectionMaxSkipTicks;
bool shouldTrace = moved || turned || ticksElapsed;
if (shouldTrace)
{
selState.LastTraceTickIndex = stratumSelectionTickIndex;
...
server.RayTraceForSelection(player, ref entityPlayer.BlockSelection, ref entityPlayer.EntitySelection, stratumSelectionBlockFilter, stratumSelectionEntityFilter);
stratumSelectionTraces++;
}Threshold constants:
private const int StratumSelectionMaxSkipTicks = 3;
private const double StratumSelectionPosThresholdSq = 0.0025;
private const float StratumSelectionRotThreshold = 0.015f;OnBeingLookedAt(...) still runs each tick for the current cached selection.
if (entityPlayer.BlockSelection != null)
{
bool firstTick = ...;
server.BlockAccessor.GetBlock(entityPlayer.BlockSelection.Position).OnBeingLookedAt(player, entityPlayer.BlockSelection, firstTick);
}So this throttles tracing work, not the whole interaction flow.
patches/VintagestoryLib/Vintagestory.Server/ServerSystemEntitySimulation.cs.patchVintagestoryLib/Vintagestory.Server/ServerSystemEntitySimulation.cs