convert line ends
[canaan.git] / prj / cam / src / dark / drksloop.cpp
blobc4b72882d3e5a4b1bd717427c74b919244cfe56f
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/dark/drksloop.cpp,v 1.38 1999/12/22 18:45:25 PATMAC Exp $
8 #include <lg.h>
9 #include <loopapi.h>
10 #include <config.h>
12 #include <dispbase.h>
13 #include <loopmsg.h>
14 #include <dbasemsg.h>
16 #include <simloop.h>
17 #include <drkloop.h>
18 #include <drkwbow.h>
19 #include <drkwswd.h>
20 #include <physloop.h>
21 #include <biploop.h>
22 #include <objloop.h>
23 #include <uiloop.h>
24 #include <gamemode.h>
25 #include <plyrloop.h>
27 #include <headmove.h>
28 #include <drkgame.h>
29 #include <playrobj.h>
30 #include <simstate.h>
31 #include <simflags.h>
32 #include <simtime.h>
33 #include <prjctile.h>
34 #include <particle.h>
35 #include <picklock.h>
37 #include <drkplinv.h>
38 #include <drkinvui.h>
40 #include <drkreact.h>
41 #include <drksound.h>
43 #include <appagg.h>
44 #include <scrptapi.h>
46 #include <drkamap.h>
48 // Must be last header
49 #include <dbmem.h>
51 /////////////////////////////////////////////////////////////
52 // DARK SIMULATION LOOP CLIENT
53 ////////////////////////////////////////////////////////////
55 //////////////////
56 // CONSTANTS
58 // These are just here to separate out boiler-plate code and leave it untouched
61 #define MY_FACTORY DarkSimLoopFactory
62 #define MY_GUID LOOPID_DarkSim
64 // My context data
65 typedef void Context;
67 // My state
68 typedef struct _StateRecord
70 Context* context; // a pointer to the context data I got.
71 // State fields go here
72 BOOL in_game_mode;
73 BOOL is_first_game_frame;
74 } StateRecord;
76 ////////////////////////////////////////
78 // LOOP/DISPATCH callback
79 // Here's where we do the dirty work.
83 static void db_message(DispatchData* msg)
85 msgDatabaseData data;
86 data.raw = msg->data;
88 AutoAppIPtr(Inventory);
89 pInventory->DatabaseNotify(msg->subtype,data.load);
91 DarkAutomapDatabaseNotify( msg->subtype, data.load );
93 switch (DB_MSG(msg->subtype))
95 case kDatabasePostLoad:
96 case kDatabaseDefault:
97 InitProjectileArchetype();
98 InitParticleArchetype();
99 DarkReactionsPostLoad();
100 break;
105 #pragma off(unreferenced)
106 static eLoopMessageResult LGAPI _LoopFunc(void* data, eLoopMessage msg, tLoopMessageData hdata)
108 // useful stuff for most clients
109 eLoopMessageResult result = kLoopDispatchContinue;
110 StateRecord* state = (StateRecord*)data;
111 LoopMsg info;
113 info.raw = hdata;
115 switch(msg)
117 case kMsgAppInit:
118 dark_init_game();
119 break;
121 case kMsgAppTerm:
122 dark_term_game();
123 break;
125 case kMsgEnterMode:
126 case kMsgResumeMode:
127 state->in_game_mode = IsEqualGUID(*info.mode->to.pID, LOOPID_GameMode);
128 if (state->in_game_mode)
129 { // center so mouse look around will work
130 headmoveInit();
131 dark_start_gamemode(msg == kMsgResumeMode);
132 if ( msg == kMsgEnterMode ) {
133 state->is_first_game_frame = TRUE;
136 break;
138 case kMsgExitMode:
139 case kMsgSuspendMode:
140 if (state->in_game_mode)
142 dark_end_gamemode(msg == kMsgSuspendMode);
143 state->in_game_mode = FALSE;
145 break;
147 case kMsgNormalFrame:
148 if (SimStateCheckFlags(kSimGameSpec))
150 dark_sim_update_frame();
151 DrkSoundFrame();
152 UpdateBowAttack(GetSimFrameTime());
153 UpdateWeaponAttack();
154 PickLockPerFrameCallback(GetSimFrameTime());
156 if ( state->in_game_mode && state->is_first_game_frame ) {
157 state->is_first_game_frame = FALSE;
158 DarkAutomapFirstFrameInit();
160 break;
162 case kMsgDatabase:
163 db_message(info.dispatch);
164 break;
166 case kMsgEnd:
167 free(state);
168 break;
170 return result;
173 ////////////////////////////////////////////////////////////
175 // Loop client factory function.
178 #pragma off(unreferenced)
179 static ILoopClient* LGAPI _CreateClient(const sLoopClientDesc* desc, tLoopClientData data)
181 StateRecord* state;
182 // allocate space for our state, and fill out the fields
183 state = (StateRecord*)malloc(sizeof(StateRecord));
184 state->context = (Context*)data;
185 state->is_first_game_frame = FALSE;
187 return CreateSimpleLoopClient(_LoopFunc,state,desc);
189 #pragma on(unreferenced)
191 ///////////////
192 // DESCRIPTOR
195 sLoopClientDesc DarkSimLoopClientDesc =
197 &MY_GUID, // GUID
198 "Dark Simulation", // NAME
199 kPriorityNormal, // PRIORITY
200 kMsgEnd | kMsgsMode | kMsgsFrameMid | kMsgsAppOuter | kMsgDatabase, // INTERESTS
202 kLCF_Callback,
203 _CreateClient,
205 NO_LC_DATA,
208 {kConstrainAfter, &LOOPID_Physics, kMsgsFrame},
209 {kConstrainBefore, &LOOPID_SimFinish, kMsgsFrame},
210 {kConstrainAfter, &LOOPID_UI, kMsgsMode},
211 {kConstrainAfter, &LOOPID_Game, kMsgsMode},
212 {kConstrainAfter, &LOOPID_ObjSys, kMsgDatabase},
213 {kConstrainAfter, &LOOPID_Biped, kMsgsAppOuter},
214 {kConstrainBefore, &LOOPID_Biped, kMsgsFrame},
215 {kConstrainAfter, &LOOPID_Player, kMsgsFrame},
216 {kNullConstraint} // terminator