Event buses (as hash tables for speed)

This commit is contained in:
BirDt_ 2026-03-28 19:14:54 +08:00
parent 04a6555cbd
commit f1d6342089
2 changed files with 71 additions and 2 deletions

View file

@ -35,13 +35,13 @@ Like entities, the addition of systems is queued for the beginning of each frame
Systems can access resources via free variables or by being formed as closures. Systems only ever take an entity (a component list) as input.
** Event Buses
An event bus is an association list of symbols and records. They allow for delegating changes sent from other objects.
An event bus is a hash table of symbols and records. They allow for delegating changes sent from other objects.
The event record can contain any arbitrary data. The symbol the record is associated by is unique within the association list.
Event records stay in the bus until removed by another system.
Systems can push and pull events to and from the bus.
Systems can choose to either pop the event off the bus (removing it from further processing) or just peek at the event.
The symbol an event is associated by is essentially an "action". The event bus can have multiple events of the same type (for example, multiple different key presses can occur in a frame). Only one event of each name (for example, only 1 event can be called "jump", which might correspond to a space key press) is allowed in the bus at any one time.
Custom event buses can be created and stored in the ~event-buses~ association list. System can query a particular event bus within that list for a particular event.
Custom event buses can be created and stored in the ~event-buses~ hash table. Systems can query a particular event bus within that list for a particular event.
** Resources
When a resource, such as a font or texture, is loaded from the filesystem, the pointer is stored in an SRFI-69 hash table ~resources~ keyed by the path.