Skip to content

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.

C#
public sealed class AssetScope : IDisposable

Inheritance

object ← AssetScope

Implements

IDisposable

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.

C#
public int Count { get; }

Property Value

int

IsDisposed

Whether the scope was disposed; it can no longer load or hold anything.

C#
public bool IsDisposed { get; }

Property Value

bool

Loaded

The assets this scope and its children hold, each once, in the order each scope asked for them.

C#
public IReadOnlyList<AssetRecord> Loaded { get; }

Property Value

IReadOnlyList<AssetRecord>

Name

The scope’s name for diagnostics (null for the root and unnamed scopes).

C#
public string? Name { get; }

Property Value

string?

Objects

The objects this scope and its children hold, each once, in the order they were asked for.

C#
public IReadOnlyList<object> Objects { get; }

Property Value

IReadOnlyList<object>

Parent

The scope it was created from; null for the store’s root.

C#
public AssetScope? Parent { get; }

Property Value

AssetScope?

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.

C#
public bool Playing { get; set; }

Property Value

bool

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.

C#
public double SlowLoadMilliseconds { get; set; }

Property Value

double

Store

The store the scope belongs to.

C#
public AssetStore Store { get; }

Property Value

AssetStore

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.

C#
public T Acquire<T>(in AssetKey key) where T : class

Parameters

key AssetKey

Returns

T

Type Parameters

T

Exceptions

AssetLoadException

The file is missing, wrongly cased or cannot be read as that kind.

InvalidOperationException

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.

C#
public T Acquire<T>(in AssetKey key, Func<AssetLoadContext, T> load) where T : class

Parameters

key AssetKey

load Func<AssetLoadContext, T>

Returns

T

Type Parameters

T

Exceptions

AssetLoadException

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.

C#
public Asset<T> Add<T>(in AssetKey key, T value, double loadMilliseconds, double? blockingMilliseconds = null) where T : class

Parameters

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

InvalidOperationException

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.

C#
public AssetScope CreateScope(string? name = null)

Parameters

name string?

Returns

AssetScope

Exceptions

ObjectDisposedException

The scope was disposed.

Dispose()

Releases every asset this scope and its children hold, disposing those no other scope holds.

C#
public void Dispose()

Get<T>(Asset<T>)

The asset of asset (see Get``1).

C#
public T Get<T>(Asset<T> asset) where T : class

Parameters

asset Asset<T>

Returns

T

Type Parameters

T

HandleOf<T>(in AssetKey)

The handle of an asset this scope holds under key, or None.

C#
public Asset<T> HandleOf<T>(in AssetKey key) where T : class

Parameters

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.

C#
public bool HoldLoaded(string kind, string path)

Parameters

kind string

path string

Returns

bool

IsLoaded(string)

Whether this scope or one of its parents holds anything from path (in any form).

C#
public bool IsLoaded(string path)

Parameters

path string

Returns

bool

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.

C#
public Asset<T> Load<T>(string kind, string path, object? options = null, long variant = 0) where T : class

Parameters

kind string

path string

options object?

variant long

Returns

Asset<T>

Type Parameters

T

Exceptions

AssetLoadException

The file is missing, wrongly cased or cannot be read as that kind.

InvalidOperationException

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.

C#
public bool Release(string path)

Parameters

path string

Returns

bool

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.

C#
public bool Release<T>(Asset<T> asset) where T : class

Parameters

asset Asset<T>

Returns

bool

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.

C#
public bool TryAcquire<T>(in AssetKey key, out T? value) where T : class

Parameters

key AssetKey

value T?

Returns

bool

Type Parameters

T