Ketsji

Version: $Id: index.html,v 1.2 2001/08/21 11:06:31 nzc Exp $

Module owner: Nzc ([email protected])

Index

1. Overview
2. Functionality
2.1. Top level view
2.2. Sensors
2.3. Controllers
2.4. Actuators
3. Implementation details

1. Overview

The gamelogic provides a kind of simple eyes and hands on a game scene. Bricks are associated with objects, and are linked together per object. At this moment, the hierarchy is rather flat. There are two ways of extending the logic in a graphical way: opening up controllers and making the internals small state-engines themselves, and embedding sca-chains inside state transition diagrams or petri nets. Extending the gamelogic is in general an easy task (getting the brick to perform its specific functionality might not be, of course...). Adding a brick, including Blender interface and conversions should not cost more than a day.

2. Functionality

The gamelogic is organised along MVC lines. There are three categories of bricks: sensors, controllers, and actuators. A frame holds them together.

2.1. Top level view

The minimal useful setup consists of a sensor and a python controller. If 'plain' logic is used, the minimal setup requires also an actuator. The sensor observes some aspect of the gameworld. The controller decides what to do with this event (a Python controller could interact with the gameworld in unexpected ways, of course). The actuator affects an aspect of the gameworld. Everything else is there to make this possible.

For each frame, the top-level manager does the following

  1. Process all sensors.
  2. Determine which controllers need to fire.
  3. Evaluate all controllers.
  4. Determine which actuators to fire.
  5. Evaluate all actuators.
There is some internal bookkeeping around these things that is local for the top-level logic manager.

The only ordering guarantee in the evaluation of the logic bricks is the ordering of the steps above. That is something to keep in mind when checking what the expected behaviour is. For sensors and controllers, it is not possible to manipulate evaluation order within a single frame by 'smart' ordering of the bricks (on the other hand, you should consider the benefits this gives you). The effect of this behaviour is that the logic system behaves fully concurrently. Actuators can remain active for more than one frame. They are evaluated in the order in which they appear in the UI, top first, and working down from there. There is a list of currently active actuators, to which newly triggered (activated) actuators can be added. An actuator makes its own decision te be removed from the active-list: the list of actuators is tested at the start of a frame update. Each actuator can decide to 'switch off', or to remain active for another round.

2.2. Sensors

Each sensor has an Evaluate() function, that is called when the event managers processes the sensors. The sensors can fire positive and negative events. The basic operation mode is going to fire a positive event when a sensor triggers, and firing again, this time a negative event, when the sensor condition stops. Most sensors will keep firing on in between frames as well, but the details on this differ per sensor. The event type managers determine the exact activation rules per sensor type. The pulse behaviour can be inverted. Sensors can also be set to keep firing only at every nth frame (pulse frequency).

2.3. Controllers

A controller has some logic rules. These can be as simple as "AND all inputs" and may be full-blown Python scripts on the other. A controller fires when it receives events on all its inputs. The firing behaviour is simpler: either everything or nothing. (So, in brief, a controller is a function f: bool -> bool, with f(false) = false predefined. We would like to have a f: bool^n->bool^n, but that is something for later). Python controllers can ofcourse circumvent this evaluation mechanism by directly addressing actuators. This can interfere with high-level settings. For this reason, the frame update must be split (see implementation details). Each controller has a Trigger() method that is called to evaluate the controller rules.

2.4. Actuators

An actuator starts doing its action when any attached controller fires an event. The evaluation order of actuators is taken from the user interface: top first, then working down. An actuator can remain active for multiple consecutive frames. After being triggered, it can behave like a small autonomous machine. It has to indicate itself that its current action has finished, and that it wants to become dormant again. The actions take place in the actuator-evaluation phase; the actuator cannot interrupt the normal control flow of the game. All actuator actions must be structured in such a way that an actuator always leaves behind a consistent gamestate. Each actuator has an Update() function that is called when the actuator needs to do its thing.

3. Implementation details