sim.h

Engine/source/console/sim.h

More...

Namespaces:

namespace

Public Defines

define
DeclareNamedGroup(set) extern  *g##set;inline  *get##set() { return g##set; }
define
DeclareNamedSet(set) extern  *g##set;inline  *get##set() { return g##set; }
define
ImplementNamedGroup(set)  *g##set;
define
ImplementNamedSet(set)  *g##set;

Public Enumerations

enum
SimObjectsConstants {
  DataBlockObjectIdFirst = 3
  DataBlockObjectIdBitSize = 14
  DataBlockObjectIdLast = DataBlockObjectIdFirst + (1 << DataBlockObjectIdBitSize) - 1
  MessageObjectIdFirst = DataBlockObjectIdLast + 1
  MessageObjectIdBitSize = 6
  MessageObjectIdLast = MessageObjectIdFirst + (1 << MessageObjectIdBitSize) - 1
  DynamicObjectIdFirst = MessageObjectIdLast + 1
  InvalidEventId = 0
  RootGroupId = 0xFFFFFFFF
}

Definition of some basic Sim system constants.

Public Typedefs

SimObjectId 
SimTime 

Detailed Description

Public Defines

DeclareNamedGroup(set) extern  *g##set;inline  *get##set() { return g##set; }
DeclareNamedSet(set) extern  *g##set;inline  *get##set() { return g##set; }
ImplementNamedGroup(set)  *g##set;
ImplementNamedSet(set)  *g##set;

Public Enumerations

SimObjectsConstants

Enumerator

DataBlockObjectIdFirst = 3
DataBlockObjectIdBitSize = 14
DataBlockObjectIdLast = DataBlockObjectIdFirst + (1 << DataBlockObjectIdBitSize) - 1
MessageObjectIdFirst = DataBlockObjectIdLast + 1
MessageObjectIdBitSize = 6
MessageObjectIdLast = MessageObjectIdFirst + (1 << MessageObjectIdBitSize) - 1
DynamicObjectIdFirst = MessageObjectIdLast + 1
InvalidEventId = 0
RootGroupId = 0xFFFFFFFF

Definition of some basic Sim system constants.

These constants define the range of ids assigned to datablocks (DataBlockObjectIdFirst - DataBlockObjectIdLast), and the number of bits used to store datablock IDs.

Normal Sim objects are given the range of IDs starting at DynamicObjectIdFirst and going to infinity. Sim objects use a SimObjectId to represent their ID; this is currently a U32.

The RootGroupId is assigned to gRootGroup, in which most SimObjects are addded as child members. See simManager.cc for details, particularly Sim::initRoot() and following.

Public Typedefs

typedef U32 SimObjectId 
typedef U32 SimTime 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SIM_H_
 25#define _SIM_H_
 26
 27#ifndef _TORQUE_TYPES_H_
 28#include "platform/types.h"
 29#endif
 30#ifndef _TORQUE_STRING_H_
 31#include "core/util/str.h"
 32#endif
 33#ifndef _MODULE_H_
 34#include "core/module.h"
 35#endif
 36#ifndef _CONSOLE_H_
 37#include "console/console.h"
 38#endif
 39
 40// Forward Refs
 41class SimSet;
 42class SimGroup;
 43class SimDataBlockGroup;
 44class SimObject;
 45class SimEvent;
 46class Stream;
 47
 48// Sim Types
 49typedef U32 SimTime;
 50typedef U32 SimObjectId;
 51
 52/// Definition of some basic Sim system constants.
 53///
 54/// These constants define the range of ids assigned to datablocks
 55/// (DataBlockObjectIdFirst - DataBlockObjectIdLast), and the number
 56/// of bits used to store datablock IDs.
 57///
 58/// Normal Sim objects are given the range of IDs starting at
 59/// DynamicObjectIdFirst and going to infinity. Sim objects use
 60/// a SimObjectId to represent their ID; this is currently a U32.
 61///
 62/// The RootGroupId is assigned to gRootGroup, in which most SimObjects
 63/// are addded as child members. See simManager.cc for details, particularly
 64/// Sim::initRoot() and following.
 65enum SimObjectsConstants : U32
 66{
 67   DataBlockObjectIdFirst = 3,
 68   DataBlockObjectIdBitSize = 14,
 69   DataBlockObjectIdLast = DataBlockObjectIdFirst + (1 << DataBlockObjectIdBitSize) - 1,
 70
 71   MessageObjectIdFirst = DataBlockObjectIdLast + 1,
 72   MessageObjectIdBitSize = 6,
 73   MessageObjectIdLast = MessageObjectIdFirst + (1 << MessageObjectIdBitSize) - 1,
 74
 75   DynamicObjectIdFirst = MessageObjectIdLast + 1,
 76   InvalidEventId = 0,
 77   RootGroupId = 0xFFFFFFFF,
 78};
 79
 80//---------------------------------------------------------------------------
 81
 82/// @defgroup simbase_helpermacros Helper Macros
 83///
 84/// These are used for named sets and groups in the manager.
 85/// @{
 86#define DeclareNamedSet(set) extern SimSet *g##set;inline SimSet *get##set() { return g##set; }
 87#define DeclareNamedGroup(set) extern SimGroup *g##set;inline SimGroup *get##set() { return g##set; }
 88#define ImplementNamedSet(set) SimSet *g##set;
 89#define ImplementNamedGroup(set) SimGroup *g##set;
 90/// @}
 91
 92//---------------------------------------------------------------------------
 93
 94namespace Sim
 95{
 96   DeclareNamedSet(ActiveActionMapSet)
 97   DeclareNamedSet(GhostAlwaysSet)
 98   DeclareNamedSet(WayPointSet)
 99   DeclareNamedSet(fxReplicatorSet)
100   DeclareNamedSet(fxFoliageSet)
101   DeclareNamedSet(BehaviorSet)
102   DeclareNamedSet(MaterialSet)
103   DeclareNamedSet(SFXSourceSet);
104   DeclareNamedSet(SFXDescriptionSet);
105   DeclareNamedSet(SFXTrackSet);
106   DeclareNamedSet(SFXEnvironmentSet);
107   DeclareNamedSet(SFXStateSet);
108   DeclareNamedSet(SFXAmbienceSet);
109   DeclareNamedSet(TerrainMaterialSet);
110   DeclareNamedSet(DataBlockSet);
111   DeclareNamedGroup(ActionMapGroup)
112   DeclareNamedGroup(ClientGroup)
113   DeclareNamedGroup(GuiGroup)
114   DeclareNamedGroup(GuiDataGroup)
115   DeclareNamedGroup(TCPGroup)
116   DeclareNamedGroup(ClientConnectionGroup)
117   DeclareNamedGroup(SFXParameterGroup);
118
119   DeclareNamedSet(sgMissionLightingFilterSet);
120   
121   void init();
122   void shutdown();
123   
124   bool isShuttingDown();
125
126   SimDataBlockGroup *getDataBlockGroup();
127   SimGroup* getRootGroup();
128
129   SimObject* findObject(ConsoleValueRef&);
130   SimObject* findObject(SimObjectId);
131   SimObject* findObject(const char* name);
132   SimObject* findObject(const char* fileName, S32 declarationLine);
133   template<class T> inline bool findObject(ConsoleValueRef &ref,T*&t)
134   {
135      t = dynamic_cast<T*>(findObject(ref));
136      return t != NULL;
137   }
138   template<class T> inline bool findObject(SimObjectId iD,T*&t)
139   {
140      t = dynamic_cast<T*>(findObject(iD));
141      return t != NULL;
142   }
143   template<class T> inline bool findObject(const char *objectName,T*&t)
144   {
145      t = dynamic_cast<T*>(findObject(objectName));
146      return t != NULL;
147   }
148
149   SimObject *spawnObject(String spawnClass,
150                          String spawnDataBlock = String::EmptyString,
151                          String spawnName = String::EmptyString,
152                          String spawnProperties = String::EmptyString,
153                          String spawnScript = String::EmptyString);
154
155   void advanceToTime(SimTime time);
156   void advanceTime(SimTime delta);
157   SimTime getCurrentTime();
158   SimTime getTargetTime();
159
160   /// a target time of 0 on an event means current event
161   U32 postEvent(SimObject*, SimEvent*, SimTime targetTime);
162
163   inline U32 postEvent(SimObjectId iD,SimEvent*evt, SimTime targetTime)
164   {
165      return postEvent(findObject(iD), evt, targetTime);
166   }
167   inline U32 postEvent(const char *objectName,SimEvent*evt, SimTime targetTime)
168   {
169      return postEvent(findObject(objectName), evt, targetTime);
170   }
171   inline U32 postCurrentEvent(SimObject*obj, SimEvent*evt)
172   {
173      return postEvent(obj,evt,getCurrentTime());
174   }
175   inline U32 postCurrentEvent(SimObjectId obj,SimEvent*evt)
176   {
177      return postEvent(obj,evt,getCurrentTime());
178   }
179   inline U32 postCurrentEvent(const char *obj,SimEvent*evt)
180   {
181      return postEvent(obj,evt,getCurrentTime());
182   }
183
184   void cancelEvent(U32 eventId);
185   void cancelPendingEvents(SimObject *obj);
186   bool isEventPending(U32 eventId);
187   U32  getEventTimeLeft(U32 eventId);
188   U32  getTimeSinceStart(U32 eventId);
189   U32  getScheduleDuration(U32 eventId);
190
191   /// Appends numbers to inName until an unused SimObject name is created
192   String getUniqueName( const char *inName );
193   /// Appends numbers to inName until an internal name not taken in the inSet is found.
194   String getUniqueInternalName( const char *inName, SimSet *inSet, bool searchChildren );
195   
196   /// Return true if the given name string makes for a valid object name.
197   /// Empty strings and NULL are also treated as valid names (anonymous objects).
198   bool isValidObjectName( const char* name );
199
200   bool saveObject(SimObject *obj, Stream *stream);
201   SimObject *loadObjectStream(Stream *stream);
202
203   bool saveObject(SimObject *obj, const char *filename);
204   SimObject *loadObjectStream(const char *filename);
205}
206
207#endif // _SIM_H_
208