Skip to content

Feature: Selection Raytrace Throttle

Tsu edited this page May 31, 2026 · 1 revision

This feature reduces per-tick selection raytracing cost for idle players.

What It Changes

In ServerSystemEntitySimulation.OnServerTick, Stratum tracks last traced position/rotation per client and only retraces when needed.

Patch Snippet

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;

What Stays The Same

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.

Related Files

  • patches/VintagestoryLib/Vintagestory.Server/ServerSystemEntitySimulation.cs.patch
  • VintagestoryLib/Vintagestory.Server/ServerSystemEntitySimulation.cs

Clone this wiki locally