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