Wartbed:Manual/Models and Actors

From Dark Omen Wiki

< Wartbed:Manual
Revision as of 15:33, 24 January 2010 by Mikademus (Talk | contribs)
Jump to: navigation, search


WARTBED is intended to be capable of representing a wide range of tactical wargames. This requires both a strict standardisation and great flexibility. WARTBED provides a framework of standardised and consistent abstractions that modules are implemented in terms of. These classes can be specialised but the essential core mechanics of all real-time tactical games are captured--individuals, units, formations, targeting and orders--as well as enforcing a strict Model-View-Controller architecture.

Overview

At the core of a WARTBED simulation are implementations of the Model base class: all entities that are part of the game universe are Models. The mvc::Model class is a pure base class, as is its counter-part View, which is inherited from by any class that represents a Model for the player, graphically, auditory or in other ways. They are included by this directive:

#include "WARTBED/wb_MVC.h"

Though modules can derive directly from these, most game entities will tend to be of Actor or Prop types, which are Models extended to be integrated with the Target, Order and order::Queue classes. These are located in this file,

#include "WARTBED/wb_Models.h"

which in turn includes wb_MVC-Core.h and wb_Orders.h, and in extension also wb_Target.h.

Models, Views and Controllers

A Model is a class that is part of the universe simulation. If it is made apparent to the player it is through a View object. If it can be interacted with by the player it is through a Controller object.

This is a hypothetical example for how Model and Views might be used:

class Airplane : public wb::mvc::Model
{
    MATRIX4 world_matrix;
 
    void update( double delta_T );
};
 
 
class Sprite : public wb::mvc::View
{
    Spritesheet sprite;
 
    Sprite( wb::mvc::Model &rEntity, std::string const &rSpriteFilename ) 
        : View(rEntity) 
        , sprite(rSpriteFilename)
        {
        }
 
    void update();
};
 
 
...
 
 
Airplane spitfire;
 
entities.push_back( spitfire );
render_queue.push_back( Sprite(spitfire, "spitfire.spritesheet") );

Models, Actors and Props

This section discusses
  • Model: All entities that are part of the simulated game universe
  • Progressive: An interface that specifies a class that can be updated with elapsed time since last
  • Orderable: An interface that specified a class that can receive (be issued) orders
  • Prop: All entities of Model type that can be interacted with but cannot take independent action
  • Actor: All entities of Model type that can interact with other entities of their own volition, and that can receive orders

An Actor is anything in a game that has volition and intentionality, that is, that can move independently and can focus on targets. More technically, in the WARTBED framework an Actor is a class of wb::mvc::Model ancestry that fulfils the wb::Progressive and wb::Orderable interfaces. Both Individuals and Groups (f.i. soldiers and regiments) are Actors even though Groups consist of individuals, and orders given to them will be delegated to these.

A Prop is a Model that has no volition and no intentionality: Props inherit Progressive but not Orderable. F.i. a tree or house, but also the ground, is a Prop. Props extends Model by adding a few data members and is the base class for Actor, allowing them to be automatically updated and managed separately from "pure" Models. Both Props and Actors are Models, but whereas Actors can independently interact with other entities in its universe, Props can only indirectly interacts with the simulation. Nonetheless, as all Models they can signal their context (Views and Controllers), as for instance the ground might want to do it a shell explodes on it:

pGround->sendMessage( "BOOM goes the ground!" );

Building on the previous example, source using the Actor and Prop classes might take this form:

class Airplane : public wb::Actor
{
    MATRIX4 world_matrix;
};
 
class Cloud : public wb::Prop
{
};
 
 
...
 
 
Airplane spitfire;
Airplane lancaster;
Cloud cloud1, cloud2;
 
entities.push_back( lancaster );
entities.push_back( spitfire );
entities.push_back( cloud1 );
entities.push_back( cloud2 );
 
render_queue.push_back( Sprite(spitfire, "spitfire.spritesheet") );
render_queue.push_back( Sprite(cloud1, "cloud.png") );
render_queue.push_back( Sprite(cloud2, "cloud.png") );
 
lancaster.issueOrder( order::MoveTo(0,0,1000) );
lancaster.issueOrder( order::MoveTo(1000,0,1000), add_to_queue );
spitfire.issueOrder( order::MoveTo(lancaster) );
 
for (vector<wb::mvc::Model>::iterator i = entities.begin(); i != entities.end(); ++i)
{
    Progressive *pP = dynamic_cast<Progressive *>( &*i );
 
    if (pP) 
        pP->update( elapsed_time );
}
Personal tools
communication