Design

Simulation Scheduling

As described in Game-Loop RFC, action simulation will be realized using a quantum approach: Simulated time will be incremented globally by steps. All action occuring inside this quantum will be simulated during the same global simulation pass.

Note that there is no hard correspondance between game time and real time. Under heavy load, simulated time will slow down. Under such conditions, Server response time should stay globally constant, but simulated quanta length will become smaller.

Quantum length need only to be fixed at the beginning of the simulation pass. This mean quantum length can be dynamicly determined according to game load by the server.

Controllers and Decision Tree

The purpose of this section is to describe how an Entity controller communicates its will to the game.

Each entity controller will have to maintain a list of the actions the entity is trying to do in the immediate future. This 'TODO-List' will be called here a Decision Tree (DT).

The Decision Tree is part of the Entity model. It will be accessible to both the action simulation code and the entity controller with different level of priviledges. In other words, the object will present two different interfaces, one for the controller (limited access) and one to the interaction engine (full access).

The controller will access through the DT:

The action simulation engine will at each turn:

Action lookup

The design that we came up with makes use of the following design patterns. Next, we motivate this choice.

Actions are implemented using the Command pattern. This will insure:

The Command pattern already gives us much of the required flexibility. However, we also need the Dynamic Linkage pattern to be able to add an Action to an Action Pool at runtime or even dynamically modify an Action implementation. The Dynamic Linkage pattern allows us to dynamically load Actions without requiring that the game engine or Actions know each other. We will however need to refine this pattern a little bit to adapt it to our needs. Moreover, by using a special Class loader, we will be able to load Actions from a local or remote repository. For more information on the Dynamic Linkage pattern, see "Patterns in Java, volume 1" by Mark Grand.

We still have to address memory and interactivity requirements. We need to be able to share Actions between a large number of Entities in a memory- and speed-efficient way. A possible solution is to use the Object Pool pattern (as described by Mark Grand, see above). An Object Pool manages reusable instances. In our case, Action Pools will be implemented as Object Pools. How does it work and why is it efficient? Not too complex:

It could be also possible to use the Cache Management pattern (see Grand), to decrease lookup and increase speed performance but this will increase memory requirements.

This system seems to answer our needs rather efficiently. However, we will need to experiment to find if it keeps it promises when implemented.

Action simulation

Once the pertinent Action object has been found, control is transferred to it by the game through the perform command. This function is the base of the command pattern. As parameters, it takes:

Concrete action simulation will be done by:

DT Action objects provided by Instances (and then Java compiled) will be able to use the following interfaces:

Some actions will require coordination between two or more entities. For example Buying something requires that the shopkeeper is able to sell its products and not busy doing something else. Joining a group requires that the existing group is offering the newcomer to join.

In such cases, two actions will work in pair. The "Buy" action will only succeed if the shopkeeper is performing the "Sell" action. The Buy action will simply look at the current action of the Shopkeeper entity. If it finds a "Sell" Action there, It will contact this action, using a second method: Object [] interact(Object []).

For example, the interaction between the buyers and sellers could looks like:

This proposal is just a beginning to define real interactions between entities. More use cases need to be reviewed, like:

Action interruption

Another difficult point to design in which case an action being performed will be interrupted. We can do the following remarks: