convert line ends
[canaan.git] / prj / cam / src / sim / objloop.cpp
blob58b3f5b1f37b6f3706d4fb420e1640068b1948bb
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/sim/objloop.cpp,v 1.32 2000/02/19 12:36:58 toml Exp $
8 #include <lg.h>
9 #include <loopapi.h>
11 #include <loopmsg.h>
13 #include <appagg.h>
14 #include <iobjsys.h>
15 #include <objloop.h>
16 #include <eosapp.h>
17 #include <objpos.h>
18 #include <editmode.h>
19 #include <gamemode.h>
20 #include <dbasemsg.h>
21 #include <dispbase.h>
22 #include <objnotif.h>
23 #include <pfacinit.h>
24 #include <phref.h>
25 #include <linkint.h>
27 #include <simloop.h>
28 #include <physloop.h>
29 #include <wrloop.h>
31 #include <objsys.h>
32 #include <command.h>
33 #include <scalprop.h>
34 #include <mnamprop.h>
35 #include <mnumprop.h>
36 #include <collprop.h>
37 #include <partprop.h>
38 #include <litprop.h>
39 #include <elitprop.h>
42 #include <proptest.h>
43 #include <memall.h>
44 #include <dbmem.h> // must be last header!
46 /////////////////////////////////////////////////////////////
47 // OBJECT SYSTEM LOOP CLIENT
48 ////////////////////////////////////////////////////////////
50 static IObjectSystem* ObjSys;
51 static ILinkManagerInternal* LinkMan;
53 //////////////////
54 // CONSTANTS
58 #define MY_GUID LOOPID_ObjSys
60 typedef void Context;
62 // My state
63 typedef struct _StateRecord
65 Context* context;
66 } StateRecord;
69 ////////////////////////////////////////
70 // VERIFY LINK LOCK COUNT
73 static void verify_links()
75 #ifdef PLAYTEST
77 long count = LinkMan->GetLockCount();
78 AssertMsg1(count == 0,"Link Lock Count is %d\n",count);
80 #endif // PLAYTEST
86 ////////////////////////////////////////
87 // DATABASE MESSAGE HANDLER
90 #define DB_TO_OBJNOTIF(x) ((x)|kObjNotifyDatabase) // DB and obj notify messages are coincidentally the same
92 static void db_message(DispatchData* msg)
94 #ifdef PLAYTEST
95 static BOOL first_reset = TRUE;
96 if (!first_reset)
97 verify_links();
98 else
99 first_reset = FALSE;
100 #endif
102 IObjectSystem_DatabaseNotify(ObjSys,DB_TO_OBJNOTIF(msg->subtype),msg->data);
104 switch (DB_MSG(msg->subtype))
106 case kDatabaseReset:
108 ObjDeleteAllRefs();
110 break;
112 case kDatabaseLoad:
114 if (msg->subtype & kDBMap) // only do this when wr_num_cells has changed
116 // I realize that this shouldn't really be here, but constraints
117 // blew up when I tried to put it in physloop and put it after
118 // WR for database messages. Plus it's like 39 hours till E3
119 // right now. (cc)
120 PhysRefSystemResize();
123 break;
125 case kDatabasePostLoad:
127 if (msg->subtype & kObjPartConcrete)
129 ObjBuildAllRefs();
131 ObjAnimLightReset();
133 break;
137 ////////////////////////////////////////
139 // LOOP/DISPATCH callback
140 // Here's where we do the dirty work.
143 #pragma off(unreferenced)
144 static eLoopMessageResult LGAPI _LoopFunc(void* data, eLoopMessage msg, tLoopMessageData hdata)
146 // useful stuff for most clients
147 eLoopMessageResult result = kLoopDispatchContinue;
148 StateRecord* state = (StateRecord*)data;
149 LoopMsg info;
151 info.raw = hdata;
153 switch(msg)
155 case kMsgAppInit:
156 ObjSys = AppGetObj(IObjectSystem);
157 LinkMan = AppGetObj(ILinkManagerInternal);
158 PropertyInterfacesInit();
159 ScalePropInit();
160 ModelNamePropInit();
161 ModelNumberPropInit();
162 CollisionTypePropInit();
163 ParticlePropInit();
164 LightPropInit();
165 AnimLightPropInit();
166 ExtraLightPropInit();
167 proptest_init();
168 ObjPosInit();
169 EOSInit();
171 break;
173 case kMsgAppTerm:
174 SafeRelease(ObjSys);
175 SafeRelease(LinkMan);
176 LightPropRelease();
177 AnimLightPropRelease();
178 ModelNamePropTerm();
179 ModelNumberPropTerm();
180 ObjPosTerm();
181 EOSTerm();
182 PropertyInterfacesTerm();
183 break;
185 case kMsgNormalFrame:
186 ObjPosSynchronize();
187 verify_links();
188 break;
190 case kMsgExitMode:
191 break;
193 case kMsgDatabase:
194 db_message(info.dispatch);
195 break;
197 case kMsgEnd:
198 Free(state);
199 break;
201 return result;
204 ////////////////////////////////////////////////////////////
206 // Loop client factory function.
209 #pragma off(unreferenced)
210 static ILoopClient* LGAPI _CreateClient(sLoopClientDesc * pDesc, tLoopClientData data)
212 StateRecord* state;
213 // allocate space for our state, and fill out the fields
214 state = (StateRecord*)Malloc(sizeof(StateRecord));
215 state->context = (Context*)data;
217 return CreateSimpleLoopClient(_LoopFunc,state,&ObjSysLoopClientDesc);
219 #pragma on(unreferenced)
221 ///////////////
222 // DESCRIPTOR
226 sLoopClientDesc ObjSysLoopClientDesc =
228 &MY_GUID,
229 "Object system client",
230 kPriorityNormal,
231 kMsgEnd|kMsgDatabase|kMsgsFrame|kMsgsAppOuter|kMsgsMode,
233 kLCF_Callback,
234 _CreateClient,
236 NO_LC_DATA,
239 { kConstrainBefore, &LOOPID_SimFinish, kMsgsFrame},
240 { kConstrainAfter, &LOOPID_Physics, kMsgsFrame},
241 { kConstrainAfter, &LOOPID_Wr, kMsgDatabase},
243 {kNullConstraint} // terminator