2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/framewrk/init.cpp,v 1.107 2000/02/25 22:58:18 mwhite Exp $
87 // must be last header
95 EXTERN BOOL
CheckForCD(void);
97 //------------------------------------------------------------
98 // CONFIG INITIALIZATION
101 #define CONFIG_FILE "cam.cfg"
102 #define GAME_CFG_VAR "game"
103 #define INCLUDE_PREFIX "include_"
104 void AppShutdownConfig(void);
106 //----------------------------------------
108 static uint
app_read_cfg(char* )
110 return CONFIG_DFT_HI_PRI
;
114 //------------------------------------------------------------
119 static void init_monochrome()
121 static initialized
= FALSE
;
134 bool is_mono
=!config_is_defined("mono_no_screen");
136 // for now, we know NT cant do Mono's
137 if ((buf
=getenv("OS"))!=NULL
)
138 if (stricmp(buf
,"Windows_NT")==0)
140 mono_win_init(is_mono
);
143 mono_win_init(FALSE
);
150 mono_set_flags(MONO_FLG_WRAPCLEAR
,NULL
);
151 config_get_raw("monolog",monofname
,256);
152 if (strcmp(monofname
,"")==0)
153 strcpy(monofname
,"monolog.txt");
154 if (config_is_defined("monolog"))
155 mono_logon(monofname
, MONO_LOG_NEW
, MONO_LOG_ALLWIN
);
156 mono_to_debugger
= !config_is_defined("nomonodebug");
159 //------------------------------------------------------------
163 static void pick_game(void)
166 if (config_get_raw(GAME_CFG_VAR
,buf
,sizeof(buf
)))
167 AppSelectGame(buf
); // select the game we named
169 AppSelectGame(NULL
); // select the default game
172 // for programmers only, load prog.cfg so we can find game.cfg and other
174 config_load("prog.cfg");
178 // Include "game.cfg"
181 config_get_raw("game",game
,sizeof(game
));
183 // punt trailing space
185 for (s
= game
+ strlen(game
) - 1; s
>= game
&& isspace(*s
); s
--)
191 Verify(find_file_in_config_path(path
,game
,"include_path"));
197 //------------------------------------------------------------
198 // CUSTOM PURE-VIRTUAL TRAP
200 #if defined(_MSC_VER)
201 EXTERN
int __cdecl
_purecall(void)
203 CriticalMsg("Pure-virtual function call!");
209 //------------------------------------------------------------
210 // DEBUG/SPEW SUPPORT
222 if (kb_get_cooked (&code
) && (code
& KB_FLAG_DOWN
))
224 return code
^ KB_FLAG_DOWN
;
231 #define ScriptPrintString mprintf
233 #define ScriptPrintString NULL
236 //------------------------------------------------------------
237 // MINIMUM DISK SPACE
240 #define MIN_STARTUP_DISK_MB 35
242 //------------------------------------------------------------
243 // CORE ENGINE AGGREGATE OBJECT CREATION
246 tResult LGAPI
CoreEngineCreateObjects(int argc
, const char *argv
[])
254 // config sys initializes NOW so that it can be used to create objects
257 config_read_file(CONFIG_FILE
,app_read_cfg
);
261 // must come after pick_game
262 process_config_includes(INCLUDE_PREFIX
);
264 process_config_includes("editor_"INCLUDE_PREFIX
);
267 config_parse_commandline(g_argc
,g_argv
,NULL
);
269 AtExit(AppShutdownConfig
);
271 // now that we have config, lets go make sure we can run
273 if (!config_is_defined("skip_starting_checks"))
275 if (!CheckForDiskspaceAndMessage(NULL
,MIN_STARTUP_DISK_MB
))
276 Exit(1,NULL
); // CheckFor does a message box
279 Exit(1,NULL
); // message already printed in LoadDirectX itself
282 // umm, ship only or something?
285 #ifndef DONT_CHECK_CD
286 // Is the CD in the drive? - in ship, we always check this
288 if (!config_is_defined("skip_starting_checks"))
295 // Next let's do fault
299 if (!config_is_defined("nofault"))
300 ex_startup(EXM_DIVIDE_ERR
);
303 #if defined(_MSC_VER) && !defined(SHIP)
304 int cw
= _controlfp( 0, 0 );
306 if (config_is_defined("fp_fault_over"))
308 if (config_is_defined("fp_fault_under"))
310 if (config_is_defined("fp_fault_divzero"))
311 cw
&= ~EM_ZERODIVIDE
;
312 if (config_is_defined("fp_fault_denorm"))
315 _controlfp( cw
, MCW_EM
);
319 // From this point on, all we're doing is adding COM objects to the
320 // app aggregate. They initialize in constrained priority order.
324 // Get display device from config
325 eDisplayDeviceKind dispkind
= kDispDebug
;
326 config_get_int("display",&dispkind
);
328 // Get other options from config
329 int opt
= kGameShellDefault
& ~(kLockFrame
| kFlushOnEndFrame
);
330 if (config_is_defined("multithread"))
331 opt
|= kMultithreadedShell
;
333 // Use the convenience macro to create all the basic game components
334 CoreGameLibrariesCreate(APPNAME
, argc
, argv
, dispkind
, opt
);
335 ScriptManCreate(GetSimTime
, ScriptPrintString
);
343 InputManagerCreate();
347 PropertyManagerCreate();
349 TraitManagerCreate();
350 ObjectSystemCreate();
360 MoviePlayer1Create();
366 InputBinderCreate (&g_pInputBinder
);
367 AsyncReadQueueCreate();
371 // @TODO: move these out to an "engine features" app object creation function,
372 // that is called by the systems that use engfeat?
375 #ifdef NEW_NETWORK_ENABLED
377 ObjectNetworkingCreate();
378 ScriptNetworkingCreate();
381 ResSharedCacheCreate();
384 // start recording or playing back
385 if (config_get_raw("record",buffer
,38)) {
386 RecorderCreate(kRecRecord
, buffer
);
387 } else if (config_get_raw("playback",buffer
,38)) {
388 RecorderCreate(kRecPlayback
, buffer
);
391 // set the API switch
398 //------------------------------------------------------------
399 // CORE INIT FUNCTION
401 tResult LGAPI
CoreEngineAppInit()
403 pGameShell
= AppGetObj(IGameShell
);
407 #ifdef WE_CARED_ABOUT_DBG
409 DbgInstallGetch (KeyGetch
);
411 if (config_is_defined ("dbg"))
417 if (config_is_defined("breakkey"))
418 BreakKeyActivate(VK_F12
,VK_F11
);
420 if (config_is_defined("heapcheck"))
421 HeapCheckActivate(VK_F9
);
425 // set default screen mode
426 sScrnMode mode
= { 0 };
427 ScrnModeGetConfig(&mode
,"");
428 ScrnModeSetDefault(&mode
);
431 DispatchMsgAllClients(kMsgAppInit
,NULL
,kDispatchForward
);
434 //input binding stuff. load all contexts from "default.bnd" and "<game>.bnd"
435 g_pInputBinder
->Init (NULL
, NULL
);
438 // pop dialog box about dxdrivers
441 // initialize the random number lib
442 // note fullwise: we retardedly could be calling this twice,
443 // since the net lib wants to init it as well
444 // if we didn't suck we would give this a better seed
445 RandInit(tm_get_millisec());
450 //------------------------------------------------------------
451 // CORE ENGINE APP EXIT
454 tResult LGAPI
CoreEngineAppExit()
457 g_pInputBinder
->Term ();
458 DispatchMsgAllClients(kMsgAppTerm
,NULL
,kDispatchReverse
);
460 SafeRelease(pGameShell
);
465 //------------------------------------------------------------
466 // Config Sys Shutdown
469 static config_write_spec ConfigWritableTable
[] =
474 static bool write_func(char* filename
, char* var
)
476 if (config_write_to_same_file(filename
,var
))
480 char buf
[2]; // don't really need the whole filename
481 // did the var come from a file
482 config_get_origin(var
,buf
,sizeof(buf
));
486 return config_default_writable(filename
,var
);
489 void AppShutdownConfig(void)
491 config_set_writable_table(ConfigWritableTable
);
492 config_write_file(CONFIG_FILE
,write_func
);
496 //------------------------------------------------------------
497 // INITIALIZATION GLOBALS
500 const char ** g_argv
;
503 sLoopInstantiator
* gPrimordialMode
= NULL
;
510 typedefs:("config_write_spec" "uint" "ushort")