Event_system - hpgDesigns/hpgdesigns-dev.io GitHub Wiki
For the sake of efficiency, an event system
is necessary that will allow execution of various
events in each object, but that will skip events
that have nothing in them to be executed. Also, checks should be done as
far ahead of time as possible and as seldom as possible. At the same
time, it's best not to hard-code those checks, or any special event
behavior, into anything needing recompiled. Lastly, each event will need
its own function skip so return;
doesn't break anything. Take all
of that into consideration, and the result is this system.
Philosophy
Game Maker provided no method of looking up nor modifying event order. Adding events is likewise basically impossible. This is practically a crime. To correct these problems, ENIGMA stores event code in a separate file to allow easy retrieval and modification of such.
Design
The structure of the event iterator system is yet another linked list,
but this time it is single-linked and contains a pointer instances
, to
a double-linked list of instances as described by the Instance
System, rather than a pointer to a single
instance. These iterators introduce a new member, "condition," as well.
The "condition" member is a pointer to a function returning bool
. It
can be NULL
. If the function indicated by condition()
is NULL
, or
it returns true when called, traversal of instances
begins.
While iterating instances
, no further checks are performed by the
iteration system. Instead, checks such as if (visible)
in draw events
are added into each event's code by the ENIGMA compiler, and are not
implemented at the expense of an additional CALL.
To promote extensibility, the compiler reads what code to insert into which event from the resource file events.res.
Removal
Event types themselves--such as keyboard, step, draw, etc--are
typically neither removed nor added. Instances being iterated can be
removed while the instances
iterator is on them, potentially
invalidating the iterator and leading to problems. The method to
correcting this can be found in the Instance System page.