FrameWorkBudget class final
How long a frame may spend on work that can be spread over frames. Irradiance probe updates and point-shadow faces ask it today; anything else a frame can put off is meant to ask it the same way.
Time, where each of those used to count items. A count is a guess at a cost: four irradiance probes are cheap in a small room and expensive in a field of a thousand, and a scheduler that counts faces cannot know that the face it picks this frame holds the whole level. What a player feels is a frame that took three times as long as the one before it, so the allowance is the thing that decides.
Each piece of work asks allows before it starts and charges what it cost when it ends; spend does both for a closure. A piece is allowed when what the frame has spent plus what a piece has been costing still fits, so the allowance is not overrun by the piece that tips it — the cost is a running average, carried from frame to frame. The first piece of a frame is always allowed, whatever the allowance, so every queue drains even on a device too slow to fit one item: progress over smoothness, one item at a time, rather than nothing ever. An allowance of Duration.zero means no limit, which is what a frame had before this existed.
Constructors
- FrameWorkBudget({Duration allowance = Duration.zero, int clock()?})
-
A budget of
allowanceper frame, no limit when zero, timed byclockin microseconds or by a stopwatch when it is null.
Properties
- allowance → Duration
-
The allowance, against the wall clock; Duration.zero for none.
final
- averageCost → double
-
What a piece of work has been costing lately, in microseconds — for a
profiler, or a caller sizing its own pieces to the allowance.
no setter
- deferred → int
-
How many asked this frame and were told to wait.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- items → int
-
How many pieces of work ran this frame.
no setter
- remaining → int
-
What is left of this frame's allowance; unbounded with none.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- spent → int
-
What this frame has spent so far, in microseconds.
no setter
Methods
-
allows(
) → bool - Whether another piece of work may start now. Counts a refusal.
-
beginFrame(
) → void - Starts a frame: nothing spent, nothing deferred.
-
charge(
int cost) → void -
Records a piece of work that took
costmicroseconds. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
now(
) → int - This allowance's clock, in microseconds: for a piece of work whose cost is measured across code that cannot sit inside one closure handed to spend, and is then charged the difference.
-
spend(
void work()) → bool -
Runs
workif allows says so, charging what it took; false when it did not run. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited