Wartbed:Manual/Models and Actors

From Dark Omen Wiki

(Difference between revisions)
Jump to: navigation, search
(Models, Views and Controllers: Example code)
(Models, Actors and Props: Even more example code)
Line 53: Line 53:
An <tt>Actor</tt> 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 WARBED framework an Actor is a class that fulfills both the <tt>wb::mvc::Model</tt> and <tt>wb::Orderable</tt> 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.  
An <tt>Actor</tt> 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 WARBED framework an Actor is a class that fulfills both the <tt>wb::mvc::Model</tt> and <tt>wb::Orderable</tt> 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 <tt>Prop</tt> is any Model that has ''no volition'' and ''no intentionality''. F.i. a tree or house, but also the ground, is a Prop. Props are only a modest extension to Model, basically adding only a few data members, but is the base class for Actor, allowing them to be managed separately from "pure" Models.
+
A <tt>Prop</tt> is any Model that has ''no volition'' and ''no intentionality''. F.i. a tree or house, but also the ground, is a Prop. Props extend Model by adding a method of signature <tt>void update(double)</tt> (and a few data members), and is the base class for Actor, allowing them to be automatically updated and managed separately from "pure" Models.
 +
 
 +
Building on the previous example, source using the Actor and Prop classes might take this form:
 +
<div style="margin:2em;"><source lang="cpp">
 +
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<Actor>::iterator i = entities.begin(); i != entities.end(); ++i)
 +
    i->update( elapsed_time );
 +
</source></div>
 +
 
[[category:Manual]]
[[category:Manual]]

Revision as of 18:52, 22 January 2010


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-Core.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_basc( Sprite(spitfire, "spitfire.spritesheet") );

Models, Actors and Props

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 WARBED framework an Actor is a class that fulfills both the wb::mvc::Model 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 any Model that has no volition and no intentionality. F.i. a tree or house, but also the ground, is a Prop. Props extend Model by adding a method of signature void update(double) (and a few data members), and is the base class for Actor, allowing them to be automatically updated and managed separately from "pure" Models.

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<Actor>::iterator i = entities.begin(); i != entities.end(); ++i)
    i->update( elapsed_time );
Personal tools
communication