Skip to content

Instantly share code, notes, and snippets.

@ironchefpython
Created May 12, 2012 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironchefpython/2668340 to your computer and use it in GitHub Desktop.
Save ironchefpython/2668340 to your computer and use it in GitHub Desktop.

Event Architecture

Events are the primary mechanism for initiating and handling actions in Terasology. Events can be generated by keyboard or mouse input, by console commands or interacting with UI elements, by the game world through collisions or npc actions, or on-demand by mods. When Systems register to handle events, they can access properties of the event, as well call methods to cancel or consume the event.

Event Lifecycle

Each Event goes through a predictable lifecycle that contols which handers will have access to the event. First a qualification phase, where the event can be cancelled, then an execution phase where the event can be consumed, and finally a post-execution phase.

Qualification Phase

The qualification phase occurs "before" the event will occur. At this point the The Event.cancel() method can be invoked, and once the event is cancelled is will no longer propogate through any further handlers.

Execution Phase

The execution phase occurs while the event is occuring. At this point the cancel method is no longer available, and if invoked will throw an error. Any event handler can however call the Event.consume() method, indicating that the action of the method has been accomplished and thus will not be processed by any further execution handlers.

Post-Execution Phase

The post execution phase occurs after the event has occured. At this point neither the cancel nor the consume method is available, and all post-execution handlers are guaranteed to execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment