Wartbed:Manual/Models and Actors

From Dark Omen Wiki

< Wartbed:Manual(Difference between revisions)
Jump to: navigation, search
(Models, Actors and Props: Even more example code)
m (Overview)
 
(6 intermediate revisions not shown)
Line 5: Line 5:
==Overview==
==Overview==
At the core of a WARTBED simulation are implementations of the <tt>Model</tt> 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 <tt>View</tt>, 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:
At the core of a WARTBED simulation are implementations of the <tt>Model</tt> 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 <tt>View</tt>, 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:
-
<div style="margin:2em;"><source lang="cpp">
+
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
-
#include "WARTBED/wb_MVC-Core.h"
+
#include "<wb_MVC.h>
</source></div>
</source></div>
Though modules can derive directly from these, most game entities will tend to be of <tt>Actor</tt> or <tt>Prop</tt> types, which are Models extended to be integrated with the <tt>Target</tt>, <tt>Order</tt> and <tt>order::Queue</tt> classes. These are located in this file,
Though modules can derive directly from these, most game entities will tend to be of <tt>Actor</tt> or <tt>Prop</tt> types, which are Models extended to be integrated with the <tt>Target</tt>, <tt>Order</tt> and <tt>order::Queue</tt> classes. These are located in this file,
-
<div style="margin:2em;"><source lang="cpp">
+
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
-
#include "WARTBED/wb_Models.h"
+
#include "<wb_Models.h>
</source></div>
</source></div>
-
which in turn includes <tt>wb_MVC-Core.h</tt> and <tt>wb_Orders.h</tt>, and in extension also <tt>wb_Target.h</tt>.
+
which in turn includes <tt>wb_MVC.h</tt> and <tt>wb_Orders.h</tt>, and in extension also <tt>wb_Target.h</tt>.
==Models, Views and Controllers==
==Models, Views and Controllers==
 +
<div style="margin:1em; border: 1px solid gray; background:lightgray;"><div style="background:gray;">'''This section discusses'''</div>
 +
<div style="padding:1em; ">
 +
* '''<tt>Model</tt>''': All entities that are part of the simulated game universe
 +
* '''<tt>View</tt>''': Any class that in any way represents a Model, but cannot affect it
 +
* '''<tt>Controller</tt>''': A class that the player can interact with and that can mediate between Models and Views.
 +
</div></div>
A <tt>Model</tt> is a class that is part of the universe simulation. If it is made apparent to the player it is through a <tt>View</tt> object. If it can be interacted with by the player it is through a <tt>Controller</tt> object.
A <tt>Model</tt> is a class that is part of the universe simulation. If it is made apparent to the player it is through a <tt>View</tt> object. If it can be interacted with by the player it is through a <tt>Controller</tt> object.
This is a hypothetical example for how Model and Views might be used:
This is a hypothetical example for how Model and Views might be used:
-
<div style="margin:2em;"><source lang="cpp">
+
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
class Airplane : public wb::mvc::Model
class Airplane : public wb::mvc::Model
{
{
Line 47: Line 53:
entities.push_back( spitfire );
entities.push_back( spitfire );
-
render_queue.push_basc( Sprite(spitfire, "spitfire.spritesheet") );
+
render_queue.push_back( Sprite(spitfire, "spitfire.spritesheet") );
</source></div>
</source></div>
==Models, Actors and Props==
==Models, Actors and Props==
-
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.
+
<div style="margin:1em; border: 1px solid gray; background:lightgray;"><div style="background:gray;">'''This section discusses'''</div>
 +
<div style="padding:1em; ">
 +
* '''<tt>Model</tt>''': All entities that are part of the simulated game universe
 +
* '''<tt>Progressive</tt>''': An interface that specifies a class that can be updated with elapsed time since last
 +
* '''<tt>Orderable</tt>''': An interface that specified a class that can receive (be issued) orders
 +
* '''<tt>Prop</tt>''': All entities of Model type that can be interacted with but cannot take independent action
 +
* '''<tt>Actor</tt>''': All entities of Model type that can interact with other entities of their own volition, and that can receive orders </div></div>
-
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.
+
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 WARTBED framework an <tt>Actor</tt> is a class of <tt>wb::mvc::Model</tt> ancestry that fulfils the <tt>wb::Progressive</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.  
-
Building on the previous example, source using the Actor and Prop classes might take this form:
+
<div style="margin-left: auto; margin-right: auto; width:50%; white-space:pre; font-family: monospace;"><nowiki>
-
<div style="margin:2em;"><source lang="cpp">
+
+--------------+      +------------------+
 +
|  mvc::Model  |      |  wb::Progressive |
 +
+-----------^--+      +--^---------------+
 +
            \          /
 +
              \        /
 +
            +--+------+--+    +-----------------+
 +
            |  wb::Prop  |    |  wb::Orderable  |
 +
            +-----^------+    +---^-------------|
 +
                  \            /
 +
                    \          /
 +
                  +--+---------+--+ 
 +
                  |  wb::Actor  |
 +
                  +---------------+ 
 +
</nowiki></div>
 +
 
 +
A <tt>Prop</tt> is a <tt>Model</tt> that has ''no volition'' and ''no intentionality'': <tt>Prop</tt>s inherit <tt>Progressive</tt> but not <tt>Orderable</tt>. 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:
 +
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
 +
pGround->sendMessage( "BOOM goes the ground!" );
 +
</source></div>
 +
More realistically, a <tt>Model</tt> would send a message indicating that an <tt>Event</tt> has taken place (not to be confused with an ''input event'', which originates from a <tt>Controller</tt> object and is handled by an <tt>EventManager</tt> function in the client code), hypothetically like this:
 +
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
 +
// Events are scheduled for the next WARTBED revision
 +
pGround->sendEvent( EVENT_PTR(new event::Explosion(ImpactPosition)) );
 +
</source></div>
 +
Continuing the discussion about <tt>Model</tt>s in the previous section, classes building on the <tt>Actor</tt> and <tt>Prop</tt> classes might take this form:
 +
<div style="margin:1em; padding:1em; background:rgb(175,200,175);"><source lang="cpp">
class Airplane : public wb::Actor
class Airplane : public wb::Actor
{
{
Line 87: Line 124:
spitfire.issueOrder( order::MoveTo(lancaster) );
spitfire.issueOrder( order::MoveTo(lancaster) );
-
for (vector<Actor>::iterator i = entities.begin(); i != entities.end(); ++i)
+
for (vector<wb::mvc::Model>::iterator i = entities.begin(); i != entities.end(); ++i)
-
     i->update( elapsed_time );
+
{
 +
     Progressive *pP = dynamic_cast<Progressive *>( &*i );
 +
 
 +
    if (pP)
 +
        pP->update( elapsed_time );
 +
}
</source></div>
</source></div>
[[category:Manual]]
[[category:Manual]]

Current revision as of 17:15, 27 February 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 "<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 "<wb_Models.h>

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

Models, Views and Controllers

This section discusses
  • Model: All entities that are part of the simulated game universe
  • View: Any class that in any way represents a Model, but cannot affect it
  • Controller: A class that the player can interact with and that can mediate between Models and Views.

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.

+--------------+ +------------------+ | mvc::Model | | wb::Progressive | +-----------^--+ +--^---------------+ \ / \ / +--+------+--+ +-----------------+ | wb::Prop | | wb::Orderable | +-----^------+ +---^-------------| \ / \ / +--+---------+--+ | wb::Actor | +---------------+

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!" );

More realistically, a Model would send a message indicating that an Event has taken place (not to be confused with an input event, which originates from a Controller object and is handled by an EventManager function in the client code), hypothetically like this:

// Events are scheduled for the next WARTBED revision
pGround->sendEvent( EVENT_PTR(new event::Explosion(ImpactPosition)) );

Continuing the discussion about Models in the previous section, classes building on 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