API reference
Class AssetScope
Namespace: MicroEngine.Content
Assembly: MicroEngine.Content.dll
Guide: Assets
An owner of assets: what a game, a level or a scene holds. Every scope that asks for an asset holds it, whichever scope loaded it first, so sibling scopes share one object; disposing a scope (or Release) releases its holds, and an asset is disposed when no scope holds it any more. Child scopes are released with their parent.
public sealed class AssetScope : IDisposableInheritance
Implements
Properties
Count
How many assets this scope and its children hold, an asset several of them share counting once; on the root scope, every asset of the store. Allocates nothing, so it can be checked every frame.
public int Count { get; }Property Value
IsDisposed
Whether the scope was disposed; it can no longer load or hold anything.
public bool IsDisposed { get; }Property Value
Loaded
The assets this scope and its children hold, each once, in the order each scope asked for them.
public IReadOnlyList<AssetRecord> Loaded { get; }Property Value
Name
The scope’s name for diagnostics (null for the root and unnamed scopes).
public string? Name { get; }Property Value
Objects
The objects this scope and its children hold, each once, in the order they were asked for.
public IReadOnlyList<object> Objects { get; }Property Value
Parent
The scope it was created from; null for the store’s root.
public AssetScope? Parent { get; }Property Value
Playing
Whether the game is past its first update; loads from then on count as loads during play (DuringPlay). Setting it sets it on child scopes too; new children inherit it.
public bool Playing { get; set; }Property Value
SlowLoadMilliseconds
A load during play that blocks the game’s thread at least this many milliseconds is reported once (to Log), naming the file (4 by default: a quarter of a 60 Hz frame). Zero or less turns the reports off.
public double SlowLoadMilliseconds { get; set; }Property Value
Store
The store the scope belongs to.
public AssetStore Store { get; }Property Value
Methods
Acquire<T>(in AssetKey)
The asset of key, loaded by its kind’s loader when no scope has it, and held by this scope from
now on. A hit this scope already holds allocates nothing.
public T Acquire<T>(in AssetKey key) where T : classParameters
key AssetKey
Returns
T
Type Parameters
T
Exceptions
The file is missing, wrongly cased or cannot be read as that kind.
No loader of that kind is registered, or it makes something other than a T.
Acquire<T>(in AssetKey, Func<AssetLoadContext, T>)
The asset of key made by load when no scope has it, held by this scope from now on.
public T Acquire<T>(in AssetKey key, Func<AssetLoadContext, T> load) where T : classParameters
key AssetKey
load Func<AssetLoadContext, T>
Returns
T
Type Parameters
T
Exceptions
load failed; the message names the asset.
Add<T>(in AssetKey, T, double, double?)
Stores value, made elsewhere (decoded on a worker, uploaded later), under key,
held by this scope. The store disposes it when the last scope releases it.
public Asset<T> Add<T>(in AssetKey key, T value, double loadMilliseconds, double? blockingMilliseconds = null) where T : classParameters
key AssetKey
Its key.
value T
The asset.
loadMilliseconds double
The whole load, work on other threads included.
blockingMilliseconds double?
The part spent on the game’s thread, which is what a player sees as a hitch; the whole load when null.
Returns
Asset<T>
Type Parameters
T
Exceptions
An asset is already stored under key.
CreateScope(string?)
A child scope; it is released with this one. Use one per level or scene whose assets should be freed when it ends.
public AssetScope CreateScope(string? name = null)Parameters
name string?
Returns
Exceptions
The scope was disposed.
Dispose()
Releases every asset this scope and its children hold, disposing those no other scope holds.
public void Dispose()Get<T>(Asset<T>)
The asset of asset (see Get``1).
public T Get<T>(Asset<T> asset) where T : classParameters
asset Asset<T>
Returns
T
Type Parameters
T
HandleOf<T>(in AssetKey)
The handle of an asset this scope holds under key, or None.
public Asset<T> HandleOf<T>(in AssetKey key) where T : classParameters
key AssetKey
Returns
Asset<T>
Type Parameters
T
HoldLoaded(string, string)
Whether any scope has path loaded as kind (with any options); this scope then holds it.
public bool HoldLoaded(string kind, string path)Parameters
kind string
path string
Returns
IsLoaded(string)
Whether this scope or one of its parents holds anything from path (in any form).
public bool IsLoaded(string path)Parameters
path string
Returns
Load<T>(string, string, object?, long)
The asset of kind kind at path, loaded by the kind’s loader the first time
any scope asks for it and held by this scope from now on.
public Asset<T> Load<T>(string kind, string path, object? options = null, long variant = 0) where T : classParameters
kind string
path string
options object?
variant long
Returns
Asset<T>
Type Parameters
T
Exceptions
The file is missing, wrongly cased or cannot be read as that kind.
No loader of that kind is registered, or it makes something other than a T.
Release(string)
Releases what this scope holds from path (in any form): each asset is disposed unless another
scope still holds it, and loads again if asked for later. What only other scopes hold is not touched.
public bool Release(string path)Parameters
path string
Returns
Whether this scope held anything from the file.
Release<T>(Asset<T>)
Releases this scope’s hold on asset; it is disposed when no scope holds it any more.
public bool Release<T>(Asset<T> asset) where T : classParameters
asset Asset<T>
Returns
Whether this scope held it.
Type Parameters
T
TryAcquire<T>(in AssetKey, out T?)
The asset of key if any scope has it (this scope then holds it); never loads.
public bool TryAcquire<T>(in AssetKey key, out T? value) where T : classParameters
key AssetKey
value T?
Returns
Type Parameters
T