Skip to content

Engine Design

Chris Dusto edited this page Feb 28, 2016 · 1 revision

Ruby Game Engine

The Ruby Game Engine is a dynamic event-based game engine; it loads a number of different modules, where each module can process some events or issue others, and dispatches all received events to their corresponding handler modules either in a timely manner, or discarding unimportant events to maintain application speed.

Modules

A module can serve any purpose, and is designed to be interchangable with other modules which support the same events (for instance, a module which implements audio over ALSA could be replaced with one which works through OSS). Each module, when loaded, notifies the engine what events it can handle and how suitable it is for each of those events; the engine routes events to event handlers in sequence (from most to least suitable) until either a handler processes the event, or there are no more handlers and an event exception occurs.

Events

An event consists of four parts: the description of the event, the data of the event, the priority of the event, and an optional reference back to the event's issuer. Every event has a description string, usually a camelcase description of the task (e.g. playSound.wave or renderFrame). Priorities are used by the engine to help ensure that the most important events are serviced first, and permits "unimportant" events (ones with a negative priority) to be skipped if the application is falling behind.

The engine maintains a list of all the handlers for a specific event, sorted by suitibility, and passes the event to each handler. The handler then decides either to process the event or pass it to the next handler (which can be useful in some cases, especially if higher handlers are well-optimized for specific tasks while lower handlers are less-optimized but general-purpose). If the least suitible handler for the event does not process the event, an event exception is signalled; this is generally a nonfatal error in production, but it will generate a max-priority engineMessage.eventException event which must be handled (either by a dedicated handler or by an engineMessage handler), or else the application will terminate.

Clone this wiki locally