Class CooperativeFrameBudget
- Namespace
- LansMap.Core.Scheduling
One shared per-frame time budget for the mechanics that spread their own work across several frames: tile upload, cluster hierarchy build, and marker warm-up.
public sealed class CooperativeFrameBudget
- Inheritance
-
objectCooperativeFrameBudget
Remarks
Each mechanic gets a guaranteed floor plus first-come access to a shared pool on top, so no mechanic starves when the others are also busy, and none is capped below its floor when it runs alone. A caller checks in with RequestMs(int, FrameBudgetMechanic, double) before doing work and reports what it actually spent with ReportSpent(FrameBudgetMechanic, double) afterward.
Resets itself lazily the first time it sees a new frameId -
there is no Update to call, and no reset-ordering dependency
across the several components that share one instance. This type
reads no clock: the frame id and every elapsed-ms figure are plain
numbers the caller measured, so it stays usable from plain dotnet
tests with no Unity boot.
Constructors
CooperativeFrameBudget(double, double, double, double)
Builds a ledger with the given total per-frame budget and per-mechanic floors; the difference between the total and the floor sum becomes the shared pool.
public CooperativeFrameBudget(double totalMs, double tileFloorMs, double clusterFloorMs, double warmUpFloorMs)
Parameters
totalMsdoubleTotal per-frame budget, in ms.
tileFloorMsdoubleGuaranteed floor for TileUpload, in ms.
clusterFloorMsdoubleGuaranteed floor for ClusterBuild, in ms.
warmUpFloorMsdoubleGuaranteed floor for MarkerWarmUp, in ms.
Fields
ClusterFloorMs
Default guaranteed floor for ClusterBuild, in ms.
public const double ClusterFloorMs = 0.5
Field Value
DefaultTotalMs
Default total per-frame budget, in ms.
public const double DefaultTotalMs = 3
Field Value
TileFloorMs
Default guaranteed floor for TileUpload, in ms.
public const double TileFloorMs = 1
Field Value
WarmUpFloorMs
Default guaranteed floor for MarkerWarmUp, in ms.
public const double WarmUpFloorMs = 0.25
Field Value
Methods
ReportSpent(FrameBudgetMechanic, double)
Reports what mechanic actually spent against its most
recent grant this frame.
public void ReportSpent(FrameBudgetMechanic mechanic, double actualMs)
Parameters
mechanicFrameBudgetMechanicWhich mechanic is reporting.
actualMsdoubleActual measured spend, in ms.
Remarks
Overshoot past the grant debits the shared pool, possibly negative - later requesters this frame then collapse to their own floor. Undershoot is not credited back; it is simply lost for the rest of the frame.
RequestMs(int, FrameBudgetMechanic, double)
Requests up to requestMs for mechanic
this frame, resetting the ledger first if frameId is new.
public double RequestMs(int frameId, FrameBudgetMechanic mechanic, double requestMs)
Parameters
frameIdintThe caller's own frame counter (e.g.
Time.frameCount).mechanicFrameBudgetMechanicWhich mechanic is asking.
requestMsdoubleHow much the mechanic wants, in ms; negative is treated as zero.
Returns
- double
The granted ms, debited from the mechanic's own remaining floor first, then the shared pool - never more than
requestMs, and never negative.
Remarks
Repeat calls in one frame for the same mechanic (two tile streamers, several warming layers) draw down that mechanic's same remaining balance.