Stendhal code design

From Arianne
Revision as of 15:08, 17 December 2007 by imported>Hendrik Brummermann (Coding Standards)
Jump to navigation Jump to search

Client

Base Client

The base client ([ideally] free of any specific UI) is StendhalClient. It is responsible for interacting with the server, maintaining private user information/state, and dispatching object events.


Entities

Entity's are created using EntityFactory.createEntity(). In this method, the appropriete implementation class is created, and initialize.

Example:

RPObject object = ...

Entity entity = EntityFactory.createEntity(object);

// Force the view to be created
entity.getView();

  ...

// Done with entity - free up resources
entity.release();


The design is being transitioned to a Model-View-Controller (MVC) like framework. This will allow different visual implementations (like 2D, 3D, 4D?) to be plugged in with minimal (or no) changes of the model class.


Model/Controller

This contains all logical entity data, and is responsible for tracking all entity specific attribute changes in the RPObject that it wraps. Currently this also handles some of the UI controller functions.

The initialize() method is called with the RPObject that it will represent. This method is called after the constructor returns, but before anything else is [externally] called. When the client no longer needs the entity, it should call release(), which should handling any cleanup that garbage collection only is insufficient.

The class gets notified of object changes via the RPObjectChangeListener interface that it implements. This will be called for all changes to it's object (and immediate slot objects).

Methods

  • getArea()

This returns the "ground" area that the entity occupies, as it is in the server (with real-time motion adjustments made by the client).

  • update(delta)

This is called periodically so that the entity can update any active state. It is passed the number of milliseconds since the last call.


View

The current view implementation is Entity2DView. This is responsible for rendering an entity in a 2D view.

Sound System

TBW...

UI

The user interface (UI) is responsible for bringing together the base client and user interaction. The base class is StendhalUI, and is extended by an appropriete implementation (currently j2DClient).



Server

Coding Standards

we try to follow sun java code convention.

Despite this:

  • We use tab for all indentation.
  • We do not stick too closely to line length.

We always use blocks in if-statements and loops, even if the block only consists of one single statement:

if (condition) {
    method();
}