IsolateSimulation class final
SimulationHandle over an EngineLoop running in an isolate spawned for it — the step off the thread that draws (item 19).
What crosses
- published arrives as PublishedState.toWire after every step and is read back with PublishedState.fromWire: the components and the events are already their codecs' output, so the view decodes exactly what a LocalSimulation's view decodes.
- submit sends the input and its seat. On the other side it is
queued for the next live step and handed to the setup's
applyInput, as LocalSimulation.submit does, so it is on the tape. - ask sends a name and plain arguments; the answer is the one
registered in the loop's
queries, run there between two steps. - rewindTo puts the loop back to a step it kept a capture of.
query is refused. A closure runs only in an isolate that shares its
code, and a view written against this handle should keep working when the
simulation moves further still; it completes with a
SimulationCapabilityException that says to ask by name.
The clock
By default the isolate runs its own clock: a timer at the loop's step
rate, measured against a stopwatch, handed to EngineLoop.frame. With
ownsClock: false it steps only when told, by update — what a test,
or a view that paces the simulation by its own frames, does.
Where it runs
Anywhere dart:isolate does. On the web open refuses, with a
SimulationCapabilityException: a package cannot spawn a worker there.
isSupported says which, and a game that runs in both places keeps one
factory and asks:
final SimulationHandle handle = IsolateSimulation.isSupported
? await IsolateSimulation.open(buildCrypt, arguments: level)
: buildCrypt(level).local();
- Inheritance
-
- Object
- SimulationHandle
- IsolateSimulation
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- ownsClock → bool
-
Whether the isolate steps on its own timer, or only through update.
final
- published → PublishedState
-
The latest state the simulation published; PublishedState.empty
before the first step.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- simulation → SimulationVersion
-
The simulation this handle runs.
no setteroverride
Methods
-
ask(
String name, {Object? arguments}) → Future< Object?> -
Asks the simulation the question registered as
name(SimulationQueryRegistry), witharguments, and answers with what it returned: plain values, wherever the world is.override -
close(
) → Future< void> -
Lets the simulation go. Nothing published after this is delivered.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onPublished(
void listener(PublishedState state)) → Registration -
Calls
listenerwith every state published from now on.override -
query<
R> (R question(SimWorld world)) → Future< R> -
Runs
questionagainst the world where it is, between two steps, and answers with its result. The function must not keep the world, and its answer must be a plain value or immutable.override -
rewindTo(
int step) → Future< void> -
Puts the simulation back to how it was after
stepsteps, through its snapshots. The default refuses: a handle that keeps no history says so.override -
submit(
Object? input, {int seat = 0}) → void -
Hands
inputto the player inseatfor the next step. Plain values only: what an isolate message carries.override -
toString(
) → String -
A string representation of this object.
inherited
-
update(
double seconds) → void -
Runs one frame of
secondsreal seconds in the isolate: what a view pacing a handle opened withownsClock: falsecalls once a frame. The steps it runs publish as they do on the isolate's own clock.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- isSupported → bool
-
Whether this platform can spawn the isolate open needs: false in a
browser.
no setter
Static Methods
-
open(
SimulationFactory factory, {Object? arguments, bool ownsClock = true, String? debugName}) → Future< IsolateSimulation> -
Spawns an isolate, builds the simulation there with
factoryfromarguments, and answers once it has published its first state.