This class holds the hierarchy of game entities that populate a game world. More...
#include "World.hpp"
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... | |
UniScriptStateT & | GetScriptState () |
Returns the script state of this world. More... | |
float | GetMillimetersPerWorldUnit () const |
Returns how many millimeters one world unit is large. More... | |
IntrusivePtrT< EntityT > | GetRootEntity () 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... | |
ModelManagerT & | GetModelMan () const |
Returns the manager for all models that are used in this world. More... | |
cf::GuiSys::GuiResourcesT & | GetGuiResources () const |
Returns the resource provider for commonly used GUI fonts and models. More... | |
cf::ClipSys::CollModelManI & | GetCollModelMan () const |
Returns the manager for all collision models that are used in this world. More... | |
cf::ClipSys::ClipWorldT * | GetClipWorld () const |
The clip world, where entities can register their collision models and run collision detection queries. More... | |
PhysicsWorldT * | GetPhysicsWorld () 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::TypeInfoT * | GetType () const |
![]() | |
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< EntityT > | LoadScript (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 | |
![]() | |
RefCountedT (const RefCountedT &) | |
RefCountedT & | operator= (const RefCountedT &) |
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.
Flags for initializing a world from a map script.
Enumerator | |
---|---|
InitFlag_InlineCode |
Normally, the |
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 |
A value that indicates where and to which purpose a game world is instantiated.
The details of a world sometimes depend on its realm:
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.
Realm | The realm of this world, indicating where and to which purpose the world is instantiated. |
ScriptState | The caller will use this world with this script state (binds the world to it). |
ModelMan | The manager for all models that are used in this world. |
GuiRes | The provider for resources (fonts and models) for all GUIs in this world. |
CollModelMan | The manager for all collision models that are used in this world. |
ClipWorld | 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. |
PhysicsWorld | 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. |
|
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.
|
inline |
Returns the manager for all collision models that are used in this world.
|
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.
|
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.
|
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.
|
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.
|
inline |
Returns the realm of this world, indicating where and to which purpose the world has been instantiated.
|
inline |
Returns the root entity of this world.
|
inline |
Returns the script state of this world.
|
static |
Initializes the given script state for use with WorldT instances.
|
static |
Assigns the given world to the global "world" and loads the given script in order to initialize it.
World | The world to init. |
ScriptName | The file name of the script to load. |
Flags | A combination of the flags in InitFlagsT. |
Throws | an InitErrorT object on problems loading the 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 Ca3DEWorldT
s 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.
t | The 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.
KE | The keyboard event to process. |
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.
ME | The mouse event to process. |
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.