updateAssetChannel

View sourceupdateAssetChannel<T>(asset: Constructor<T>): SystemFunc

Creates the Update system that applies queued reference operations for one typed asset pool.

The factory captures asset and computes the resource ID typeidGeneric(Assets, [asset]). The returned function accepts a World; it resolves that typed Assets resource with World#getResourceByTypeId and calls Assets#update. The factory itself does not create, register, or update an asset pool. A missing typed resource causes the returned function to throw when the world lookup asserts.

Assets#update flushes the pool’s shared AssetChannel and processes its messages in queue order. An acquire increments the matching live entry’s reference count; a release decrements it and removes the entry when that was the final reference, recycling its slot and queuing an AssetDropped event. Stale asset IDs are ignored. These deferred messages are produced by operations such as Handle#clone and Handle#drop; calling the returned function is what applies them to the pool.

AssetPlugin can install equivalent asset-pool processing for its configured constructor. Register the returned function yourself when managing the pool without that plugin.

Examples

import { App } from '@wimaengine/app'
import { AssetPlugin, updateAssetChannel } from '@wimaengine/asset'

class Texture {}

const system = updateAssetChannel(Texture)
const app = new App()
app.registerPlugin(new AssetPlugin({ asset: Texture }))
// AssetPlugin installs equivalent channel processing for Texture.

Type Parameters

T

Parameters

NameDescriptionDefault
asset

Constructor identifying the typed asset pool and its Assets<T> resource ID.

—

Throws

If the returned system cannot find the typed Assets<T> resource in its world.

Returns

Update function that accepts a World and applies that pool’s queued acquire and release messages.