Assets class final
One game's assets: which keys have been declared, the Asset handle each one produced, and whether that handle's payload has been decoded yet.
Per-Game instance state (Game.assets), not a static - it rides the
Isolate.spawn deep copy, so both copies address the same asset by the
same integer without any snapshot/restore.
Declaring and loading are two separate steps
Declaring (AssetDescriptor.has, which routes here through declare)
creates the handle and assigns its address in this table. It is
synchronous, allocation-cheap, needs no loader, and runs on both isolate
copies in the same order, because that order is the address assignment.
Loading (load) reads the key's AssetSource and hands the bytes to
the key's AssetLoader. Decoding generally needs Flutter and dart:ui, so
it happens on the main isolate only. The game isolate ends up holding a
declared, addressed, unloaded handle - which is exactly right: it never
reads a payload, it only ever writes the address into a component row, and
the main isolate unpacks that address into the decoded thing when it draws.
Constructors
- Assets()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
load<
T> (AssetKey< T> key) → Future<Asset< T> > -
Reads
key's source, decodes it through the key's loader, and completes with the loaded handle. A no-op returning the same handle if it is already loaded. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
of<
T> () → IntRepresentation< Asset< T> > -
The IntRepresentation a
DataPointer<Asset<T>>field binds to. -
publishInfoForTesting(
int address, AssetInfo? info) → void -
adoptInfo, for a test in another package. -
reset(
) → void - Test-only escape hatch: drops every declaration, releases every payload, and forgets any in-flight decode, addresses included.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryGet<
T> (AssetKey< T> key) → Asset<T> ? -
The handle declared for
key, ornullif nothing has declared it (or it has since been unloaded) - a non-throwing peek. -
tryGetAt(
int address) → Asset< Object?> ? -
The handle at
address, or null - what a cross-isolate message resolves against, since it carries an address rather than a key. -
unload<
T> (AssetKey< T> key) → void -
Unloads
key: frees its address (anyDataPointerrow still holding it will fail loudly on next read - unloading something still referenced is a caller bug, not something this silently tolerates), releases whatever the decode produced, and drops the declaration. A no-op ifkeyisn't currently declared. -
unloadAll(
) → void - Unloads everything currently declared - app shutdown, or a test starting over.
-
unregisterAddress(
int address) → void - Frees an address without going through a key - the "this asset was unloaded out from under a row that still names it" case, which of's view then reports loudly instead of silently unpacking to whatever was registered next.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited