Cafu Engine
cf::GameSys::WorldT Class Reference

This class holds the hierarchy of game entities that populate a game world. More...

#include "World.hpp"

Inheritance diagram for cf::GameSys::WorldT:

Classes

class  InitErrorT
 A class that is thrown on WorldT initialization errors. More...
 

Public Types

enum  RealmT { RealmServer, RealmClient, RealmMapEditor, RealmOther }
 A value that indicates where and to which purpose a game world is instantiated. More...
 
enum  InitFlagsT { InitFlag_InlineCode = 1, InitFlag_OnlyStatic = 2, InitFlag_AsPrefab = 4 }
 Flags for initializing a world from a map script. More...
 

Public Member Functions

 WorldT (RealmT Realm, UniScriptStateT &ScriptState, ModelManagerT &ModelMan, cf::GuiSys::GuiResourcesT &GuiRes, cf::ClipSys::CollModelManI &CollModelMan, cf::ClipSys::ClipWorldT *ClipWorld, PhysicsWorldT *PhysicsWorld)
 Constructor for creating an entity hierarchy (== "a world") from the given script file. More...
 
RealmT GetRealm () const
 Returns the realm of this world, indicating where and to which purpose the world has been instantiated. More...
 
UniScriptStateTGetScriptState ()
 Returns the script state of this world. More...
 
float GetMillimetersPerWorldUnit () const
 Returns how many millimeters one world unit is large. More...
 
IntrusivePtrT< EntityTGetRootEntity () const
 Returns the root entity of this world. More...
 
unsigned int GetNextEntityID (unsigned int ForcedID=UINT_MAX)
 Returns the ID that the next newly created entity should get. More...
 
ModelManagerTGetModelMan () const
 Returns the manager for all models that are used in this world. More...
 
cf::GuiSys::GuiResourcesTGetGuiResources () const
 Returns the resource provider for commonly used GUI fonts and models. More...
 
cf::ClipSys::CollModelManIGetCollModelMan () const
 Returns the manager for all collision models that are used in this world. More...
 
cf::ClipSys::ClipWorldTGetClipWorld () const
 The clip world, where entities can register their collision models and run collision detection queries. More...
 
PhysicsWorldTGetPhysicsWorld () const
 The physics world, where entities can register their rigid bodies and run collision detection queries. More...
 
void Render () const
 Renders this world. More...
 
bool ProcessDeviceEvent (const CaKeyboardEventT &KE)
 Processes a keyboard event by forwarding it to the entity that currently has the input focus. More...
 
bool ProcessDeviceEvent (const CaMouseEventT &ME)
 Processes a mouse event by forwarding it to the entity that currently has the input focus. More...
 
void OnClientFrame (float t)
 Advances the entity one frame (one "clock-tick") on the client. More...
 
const cf::TypeSys::TypeInfoTGetType () const
 
- Public Member Functions inherited from RefCountedT
unsigned int GetRefCount () const
 

Static Public Member Functions

static void InitScriptState (UniScriptStateT &ScriptState)
 Initializes the given script state for use with WorldT instances. More...
 
static IntrusivePtrT< EntityTLoadScript (IntrusivePtrT< WorldT > World, const std::string &ScriptName, int Flags=0)
 Assigns the given world to the global "world" and loads the given script in order to initialize it. More...
 
static void * CreateInstance (const cf::TypeSys::CreateParamsT &Params)
 

Static Public Attributes

static const cf::TypeSys::TypeInfoT TypeInfo
 

Additional Inherited Members

- Protected Member Functions inherited from RefCountedT
 RefCountedT (const RefCountedT &)
 
RefCountedToperator= (const RefCountedT &)
 

Detailed Description

This class holds the hierarchy of game entities that populate a game world.

The root of the hierarchy is the map entity, all other entities are direct or indirect children of it. The world also holds shared resources that all entities commonly use, such as the script state and the model manager.

Member Enumeration Documentation

Flags for initializing a world from a map script.

Enumerator
InitFlag_InlineCode 

Normally, the ScriptName parameter to the WorldT ctor is a filename. If this is set, it is treated as inline script code.

InitFlag_OnlyStatic 

If set, only the static data will be loaded. User-defined scripts with custom, initial behaviour are not run.

InitFlag_AsPrefab 

This must be set if the map script is loaded for use as a prefab. Can only be used if the world is in realm RealmMapEditor.

A value that indicates where and to which purpose a game world is instantiated.

The details of a world sometimes depend on its realm:

  • prefabs can only be loaded into worlds in the Map Editor,
  • client interpolations only need to be accounted for on the clients,
  • the human player's "think" code sometimes must know whether it is running on the server or in a prediction step on the client.

Constructor & Destructor Documentation

WorldT::WorldT ( RealmT  Realm,
cf::UniScriptStateT ScriptState,
ModelManagerT ModelMan,
cf::GuiSys::GuiResourcesT GuiRes,
cf::ClipSys::CollModelManI CollModelMan,
cf::ClipSys::ClipWorldT ClipWorld,
PhysicsWorldT PhysicsWorld 
)

Constructor for creating an entity hierarchy (== "a world") from the given script file.

Parameters
RealmThe realm of this world, indicating where and to which purpose the world is instantiated.
ScriptStateThe caller will use this world with this script state (binds the world to it).
ModelManThe manager for all models that are used in this world.
GuiResThe provider for resources (fonts and models) for all GUIs in this world.
CollModelManThe manager for all collision models that are used in this world.
ClipWorldThe clip world, where entities can register their collision models and run collision detection queries. Can be NULL, e.g. in CaWE or the map compile tools.
PhysicsWorldThe physics world, where entities can register their rigid bodies and run collision detection queries. Can be NULL, e.g. in CaWE or the map compile tools.

Member Function Documentation

cf::ClipSys::ClipWorldT* cf::GameSys::WorldT::GetClipWorld ( ) const
inline

The clip world, where entities can register their collision models and run collision detection queries.

Can be NULL, e.g. in CaWE or the map compile tools.

cf::ClipSys::CollModelManI& cf::GameSys::WorldT::GetCollModelMan ( ) const
inline

Returns the manager for all collision models that are used in this world.

cf::GuiSys::GuiResourcesT& cf::GameSys::WorldT::GetGuiResources ( ) const
inline

Returns the resource provider for commonly used GUI fonts and models.

All GUIs that are created in this world share their font and model resources via the returned GuiResourcesT instance.

float cf::GameSys::WorldT::GetMillimetersPerWorldUnit ( ) const
inline

Returns how many millimeters one world unit is large.

Used whenever we have to deal with concrete units of measurement such as millimeters or meters (e.g. for physics computations, radiometric units (e.g. W/m^2), the acoustic Doppler effect, etc.). FIXME: The same constant is currently also defined (as const double METERS_PER_WORLD_UNIT = 0.0254) in CollisionModelStaticT::BulletAdapterT, PhysicsWorldT::TraceBoundingBox(), and the Sound Systems.

ModelManagerT& cf::GameSys::WorldT::GetModelMan ( ) const
inline

Returns the manager for all models that are used in this world.

unsigned int WorldT::GetNextEntityID ( unsigned int  ForcedID = UINT_MAX)

Returns the ID that the next newly created entity should get.

PhysicsWorldT* cf::GameSys::WorldT::GetPhysicsWorld ( ) const
inline

The physics world, where entities can register their rigid bodies and run collision detection queries.

Can be NULL, e.g. in CaWE or the map compile tools.

RealmT cf::GameSys::WorldT::GetRealm ( ) const
inline

Returns the realm of this world, indicating where and to which purpose the world has been instantiated.

IntrusivePtrT<EntityT> cf::GameSys::WorldT::GetRootEntity ( ) const
inline

Returns the root entity of this world.

UniScriptStateT& cf::GameSys::WorldT::GetScriptState ( )
inline

Returns the script state of this world.

void WorldT::InitScriptState ( cf::UniScriptStateT ScriptState)
static

Initializes the given script state for use with WorldT instances.

IntrusivePtrT< EntityT > WorldT::LoadScript ( IntrusivePtrT< WorldT World,
const std::string &  ScriptName,
int  Flags = 0 
)
static

Assigns the given world to the global "world" and loads the given script in order to initialize it.

Parameters
WorldThe world to init.
ScriptNameThe file name of the script to load.
FlagsA combination of the flags in InitFlagsT.
Exceptions
Throwsan InitErrorT object on problems loading the script.
Returns
The root entity as loaded from the given script.
void WorldT::OnClientFrame ( float  t)

Advances the entity one frame (one "clock-tick") on the client.

At the time of this writing, this method is only called from the Map Editor's ViewWindow3DT::OnPaint() method, because in the Cafu Engine, the Ca3DEWorldTs keep explicit lists of entities and run the script state's coroutines and the entities' OnClientFrame() methods themselves:

It typically updates eye-candy that is not sync'ed over the network. EntityT::OnClientFrame() is called by this method for each entity in this world.

Parameters
tThe time in seconds since the last client frame.
bool WorldT::ProcessDeviceEvent ( const CaKeyboardEventT KE)

Processes a keyboard event by forwarding it to the entity that currently has the input focus.

Parameters
KEThe keyboard event to process.
Returns
true if the device has been successfully processed, false otherwise.
bool WorldT::ProcessDeviceEvent ( const CaMouseEventT ME)

Processes a mouse event by forwarding it to the entity that currently has the input focus.

Parameters
METhe mouse event to process.
Returns
true if the device has been successfully processed, false otherwise.
void WorldT::Render ( ) const

Renders this world.

Note that this method does not setup any of the MatSys's model, view or projection matrices: it's up to the caller to do that.


The documentation for this class was generated from the following files: