makeEventClear

View sourcemakeEventClear(id: TypeId): SystemFunc

Creates a system that clears one typed Events resource.

The returned system captures id and uses it on every execution to resolve the resource with world.getResourceByTypeId(id). It then calls Events#clear, rotating the write buffer into the readable batch. If the resource is not registered under that ID, the lookup throws an assertion error and clear is not called.

EventPlugin creates and registers this system when its autoClearEvent option is enabled (the default), placing it in the repeating AppSchedule.Update schedule’s CoreSystems.End group. Set autoClearEvent: false when another system owns buffer rotation.

Examples

import { World } from '@wimaengine/ecs'
import { Events, makeEventClear } from '@wimaengine/event'
import { typeidGeneric } from '@wimaengine/type'

class DamageEvent {}
const eventId = typeidGeneric(Events, [DamageEvent])
const world = new World()
world.setResourceByTypeId(eventId, new Events())
const clearEvents = makeEventClear(eventId)
clearEvents(world)
// EventPlugin normally registers the resource and schedules this system.

Parameters

NameDescriptionDefault
id

Generic type ID of the typed Events resource to capture in the returned system.

—

Returns

System that looks up the captured resource and returns undefined after calling Events#clear.