Debian Codegraph @

Descent3/init.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/init.cpp $
21 * $Revision: 323 $
22 * $Date: 10/22/01 12:42p $
23 * $Author: Matt $
24 *
25 * Initialization of D3 systems
26 *
27 * $Log: /DescentIII/Main/init.cpp $
28 *
29 * 323 10/22/01 12:42p Matt
30 * Added MercInstalled() function.
31 *
32 * 322 10/03/01 12:45a Kevin
33 * Smaller version of pxo packets
34 *
35 * 321 9/15/01 1:46p Kevin
36 * Added -nocrashbox to suppress crash dialog box
37 *
38 * 320 9/14/01 4:47p Matt
39 * Cleaned up problems when screen bit depth set to 32.
40 *
41 * 319 9/14/01 12:50p Matt
42 * Took out code that bashed the missile view ot left if it was set to
43 * center. It's now not possible to set the view to center in the config
44 * menu.
45 *
46 * 318 4/19/00 5:36p Matt
47 * Added command-line option to adjust mouse sensitivity
48 *
49 * 317 3/20/00 12:11p Matt
50 * Merge of Duane's post-1.3 changes.
51 * Misc Mac stuff: movie, int'l keyboards, loading screens (Mac only)
52 *
53 * 316 1/26/00 9:20p Jeff
54 * added support for IntelliVIBE DLL
55 *
56 * 315 12/01/99 3:58p Jeff
57 * one last time...linux pregamecdcheck bug fix
58 *
59 * 314 12/01/99 3:30p Jeff
60 * set CD_inserted to 1 for Linux
61 *
62 * 313 11/30/99 5:07p Jeff
63 * no pregame cd check for Linux (for now)
64 *
65 * 312 10/26/99 3:30p Jeff
66 * handle extra.gam addon tablefile
67 *
68 * 311 10/25/99 3:09p Kevin
69 * added -mlooksens
70 *
71 * 310 10/25/99 9:48a Matt
72 * Mac code that should enable the dynamic allocation of lightmap_info
73 * structures. This should be disabled for editor builds.
74 *
75 * 309 10/25/99 12:47a Chris
76 * Fixed a long overdue bug with zero rad wall collison objects and
77 * colliding
78 *
79 * 308 10/22/99 10:52p Matt
80 * Mac merge
81 *
82 * 307 10/22/99 10:43p Jeff
83 * put in a variable to detect whether we are running the editor (needed
84 * in manage system, which can't use EDITOR define)
85 *
86 * 306 10/19/99 4:55p Jeff
87 * removed compiler warning
88 *
89 * 305 10/19/99 12:44p Chris
90 * Fixed a small bug with the registery check
91 *
92 * 304 10/18/99 1:59p Chris
93 * Added the ability to load the merc. hog
94 *
95 * 303 10/17/99 3:55p Jeff
96 * Linux movie stuff
97 *
98 * 302 10/12/99 11:03a Jeff
99 * if there is a -mission command line option, open that mn3 right after
100 * d3.hog for any overridables
101 *
102 * 301 10/06/99 2:04p Kevin
103 * copy protection fix to match the 1.2 full cd
104 *
105 * 300 10/05/99 10:11a Kevin
106 * Don't show tantrum logo on macintosh demo (per GraphSim's Request)
107 *
108 * 299 10/05/99 9:46a Kevin
109 * copy protection can now handle US/AUS & ROW no LL versions in one exe
110 *
111 * 298 9/29/99 8:05a Kevin
112 * Changes to copy protection to allow for us and ROW-NONLL versions to
113 * use the same exe
114 *
115 * 297 9/24/99 12:01p Samir
116 * use directinput when -alternatejoy is selected (like 1.0)
117 *
118 * 296 9/23/99 2:59p Kevin
119 * mac dll hog file
120 *
121 * 295 9/20/99 5:35p Jeff
122 * added -nosparkles command line option to turn off powerup sparkles
123 *
124 * 294 9/18/99 9:21p Jeff
125 * Init motion blur if we are a Katmai
126 *
127 * 293 8/20/99 9:45a Kevin
128 * Rankings changes!
129 *
130 * 292 7/30/99 5:24p Samir
131 * use no joystick emulation by default.
132 *
133 * 291 7/29/99 12:27p Chris
134 * FIxed a mismatched paren
135 *
136 * 290 7/28/99 5:11p Kevin
137 * Mac merges
138 *
139 * 289 7/26/99 5:19p Kevin
140 * fixed copy protection for DVD drives
141 *
142 * 288 7/12/99 6:44p Jeff
143 * create a lock file in the temp directory, if one already exists (for a
144 * program in use), then don't allow the use of the temp directory
145 *
146 * 287 7/08/99 5:44p Jason
147 * added default framecap of 60 to deal with stuttering issues
148 *
149 * 286 7/06/99 5:54p Kevin
150 * more foriegn versions....
151 *
152 * 285 6/24/99 8:10p Jeff
153 * added support for OpenGL renderer
154 *
155 * 284 6/24/99 3:15p Jeff
156 * don't check renderer in Linux if dedicated
157 *
158 * 283 6/22/99 7:03p Jeff
159 * added command line arguments to set renderer for Linux (Glide only
160 * right now)
161 *
162 * 282 6/21/99 2:12p Kevin
163 * South american version changes
164 *
165 * 281 6/17/99 11:34a Kevin
166 *
167 * 280 6/16/99 12:04p Kevin
168 * Warning!!! This is a laserlocked version!
169 *
170 * 279 6/11/99 1:15a Samir
171 * localization issues.
172 *
173 * 278 6/08/99 1:00p Jason
174 * changes for bumpmapping
175 *
176 * 277 6/03/99 8:48a Kevin
177 * fixes for new OEM version....
178 *
179 * 276 5/24/99 6:20a Kevin
180 * fixed dedicated server & copy protection
181 *
182 * 275 5/24/99 2:13a Matt
183 * Fixed -superlowmem switch.
184 *
185 * 274 5/23/99 3:03p Kevin
186 * real dist. checksums
187 *
188 * 273 5/23/99 2:38a Kevin
189 * Lame ass(tm) copy protection
190 *
191 * 272 5/21/99 10:05a Kevin
192 * Added stuff for a future DVD version
193 *
194 * 271 5/19/99 11:47a Kevin
195 * made the parent window of the message box actually be Descent 3.
196 *
197 * 270 5/18/99 10:31a Kevin
198 * made the us version only work with US english and US canadian languages
199 *
200 * 269 5/12/99 2:24p Jeff
201 * Descent3 now has a setable temp directory for all temp files
202 *
203 * 268 5/12/99 1:18p Samir
204 * play music during game too when in menus.
205 *
206 * 267 5/11/99 1:19a Samir
207 * upped music volume, set default to 0.5
208 *
209 * 266 5/10/99 9:25p Jeff
210 * first phase of Rock 'n' Ride support added
211 *
212 * 265 5/10/99 8:49p Jason
213 * added vsync command line switch
214 *
215 * 264 5/10/99 5:35p Kevin
216 * New command line options for heat and scoring API enhancements
217 *
218 * 263 5/07/99 6:54p Jason
219 * fixed some gamegauge issues
220 *
221 * 262 5/07/99 12:04p Samir
222 * added support for foreign keyboards and error text.
223 *
224 * 261 5/06/99 6:11p Kevin
225 * fixes for save/load game syste. Also require CD again and added some
226 * heat.net stuff
227 *
228 * 260 5/05/99 11:16p Kevin
229 * heat.net stuff among other things
230 *
231 * 259 5/05/99 5:46p Samir
232 * took out call to ResumeSounds when restoring from an Alt-tab.
233 *
234 * 258 5/02/99 9:13a Jeff
235 * added system specific hog files (d3-linux.hog for Linux)
236 *
237 * 257 5/01/99 4:24p Jeff
238 * fixed some windows specific code for Linux (*grrrr*)
239 *
240 * 256 4/30/99 10:53p Samir
241 * store pilot settings in a temporary buffer when multitasking.
242 *
243 * 255 4/30/99 5:06p Kevin
244 * misc dedicated server, networking and low memory enhancements
245 *
246 * 254 4/29/99 10:01p Samir
247 * use emulation mode of joystick first.
248 *
249 * 253 4/29/99 5:53p Kevin
250 * Made it so Japanese people can't play D3... well that is only if their
251 * computers have the Japanese language installed. I'm not prejudice or
252 * anything....It's just that Interplay doesn't want the english version
253 * selling in Japan or something like that. :)
254 *
255 * 252 4/29/99 2:28p Kevin
256 * Laserlock implementation
257 *
258 * 251 4/27/99 9:59p Kevin
259 * CD not requred for dedicated server. Also improved demo playback
260 *
261 * 250 4/27/99 2:10p Samir
262 * added code to set the desired sound card given the descriptive name of
263 * a sound card.
264 *
265 * 249 4/26/99 9:11p Matt
266 * Use small font instead of old UI font.
267 *
268 * 248 4/26/99 11:34a Samir
269 * don't resume sounds if game was paused when alt-tabbing back
270 * (ResumeGame will do the trick.)
271 *
272 * 247 4/25/99 6:14p Kevin
273 * added "-timetest file.dem" to behave like gamegauge does
274 *
275 * 246 4/25/99 4:15p Matt
276 * Added code to manually allow the user to specifiy the screen aspect
277 * ratio, to make the game work with wide-screen TVs.
278 *
279 * 245 4/25/99 1:27p Matt
280 * Fixed small bug
281 *
282 * 244 4/22/99 9:53a Kevin
283 * Fixed some dedicated server crashes
284 *
285 * 243 4/20/99 11:44a Jeff
286 * get the language type from the registry
287 *
288 * 242 4/17/99 7:42p Samir
289 * Don't save out renderer and sound mixer in release version since the
290 * launcher should only do this.
291 *
292 * 241 4/17/99 6:15p Samir
293 * replaced gr.h with grdefs.h and fixed resulting compile bugs.
294 *
295 * 240 4/16/99 12:03a Jeff
296 * removed cd check for Linux
297 *
298 * 239 4/15/99 3:48p Samir
299 * set mouse mode when ddio is initialized.
300 *
301 * 238 4/15/99 2:32p Kevin
302 * Added some code for the Demo
303 *
304 * 237 4/15/99 10:57a Kevin
305 * cd check only in release builds
306 *
307 * 236 4/15/99 9:25a Kevin
308 * CD check fixes and updates
309 *
310 * 235 4/14/99 3:07p Kevin
311 * Fixed some multiple CD bugs
312 *
313 * 234 4/14/99 12:35p Samir
314 * localization issues.
315 *
316 * 233 4/14/99 11:48a Matt
317 * Don't set messagebox title for release builds
318 *
319 * 232 4/14/99 2:50a Jeff
320 * fixed some case mismatched #includes
321 *
322 * 231 4/12/99 7:15p Samir
323 * added ability to configure number of sounds played at one time.
324 *
325 * 230 4/09/99 12:02p Samir
326 * joystick changes (Win32 DirectInput support)
327 *
328 * 229 4/06/99 4:15p Nate
329 * Fixed UpdateInitMessage in editor (samir)
330 *
331 * 228 4/06/99 1:53p Samir
332 * added improved progress bar.
333 *
334 * 227 4/05/99 9:53a Kevin
335 * Took out the splash screens Craig made me add while he was smoking
336 * crack.
337 *
338 * 226 4/04/99 8:15p Jeff
339 * added debug graph stuff
340 *
341 * 225 4/03/99 1:24p Jason
342 * changed some wording for loading screen
343 *
344 * 224 4/02/99 7:04p Kevin
345 * Added splash screens do release builds
346 *
347 * 223 4/02/99 5:08p Matt
348 * Added intro movie.
349 *
350 * 222 4/02/99 3:49p Kevin
351 * Added profanity filter code
352 *
353 * 221 4/02/99 1:26p Matt
354 * Changes I made for the OEM version but forgot to check in. Oops.
355 *
356 * 220 3/19/99 4:08p Kevin
357 * Multiple CD installation support
358 *
359 * 219 3/09/99 12:34p Jeff
360 * extract scripts to custom\cache
361 *
362 * 218 3/08/99 3:29p Samir
363 * RestartD3 ddio_Init key emulation = true.
364 *
365 * 217 3/05/99 5:23p Jeff
366 * extract scripts from extra.hog before d3.hog
367 *
368 * 216 3/04/99 1:15p Jeff
369 * erase temporary files that may have been left over from last run
370 *
371 * 215 3/02/99 5:21p Jason
372 * fixed some flip bugs
373 *
374 * 214 3/02/99 2:21p Samir
375 * windows 95 and NT both use same keyboard handler due to flaky
376 * directinput.
377 *
378 * 213 3/02/99 1:49a Mark
379 * put ifdefs around showstaticscreen
380 *
381 * 212 3/02/99 12:16a Jeff
382 *
383 * 211 3/02/99 12:06a Kevin
384 *
385 * 210 3/01/99 11:48p Jeff
386 * fixed prototype placement
387 *
388 * 209 3/01/99 11:47p Kevin
389 *
390 * 208 3/01/99 11:38p Kevin
391 *
392 * 207 3/01/99 9:03p Kevin
393 * OEM Beta 4
394 *
395 * 206 2/19/99 10:31p Samir
396 * added music volume.
397 *
398 * 205 2/17/99 12:38p Kevin
399 * Added -framecap <fps> to limit frame and fixed timer bug and old
400 * framerate limiter code.
401 *
402 * 204 2/16/99 12:00p Samir
403 * added new video resolution swtich test.
404 *
405 * 203 2/16/99 12:36a Kevin
406 * Fixes for release builds of OEM V3 and KAtmai
407 *
408 * 202 2/15/99 3:24p Kevin
409 *
410 * 201 2/15/99 3:23p Kevin
411 * Disabled procedurals for gamegauge
412 *
413 * 200 2/15/99 3:20p Kevin
414 * Fixed bug with dlls in a hog
415 *
416 * 199 2/15/99 1:22p Kevin
417 * Changes for GameGauge
418 *
419 * 198 2/11/99 10:35p Jeff
420 * added support for multiple languages in string table files
421 *
422 * 197 2/10/99 3:29p Jeff
423 * extracted dll manager knows difference between game hogs and miission
424 * hogs
425 *
426 * 196 2/09/99 1:29a Jeff
427 * added code to let D3 process multiplayer games in the background if
428 * game is not in focus.
429 *
430 * 195 2/08/99 2:24p Kevin
431 * Display bundler.mve and bundler.tga if they are included in the OEM
432 * package.
433 *
434 * 194 2/05/99 7:23p Kevin
435 * OEM Changes
436 *
437 * 193 2/04/99 9:46a Kevin
438 * OEM version changes
439 *
440 * 192 1/31/99 8:51p Jeff
441 * new in game cinematics system finished
442 *
443 * 191 1/29/99 5:22p Jeff
444 * localization
445 *
446 * 190 1/27/99 6:08p Jason
447 * first pass at markers
448 *
449 * 189 1/27/99 2:58p Jason
450 * fixed center small view
451 *
452 * 188 1/25/99 6:47p Samir
453 * allow slow keyboard
454 *
455 * 187 1/25/99 11:02a Samir
456 * revamped mouse and key controls.
457 *
458 * 186 1/25/99 12:33a Jeff
459 * save out scorch marks and weapon corona detail settings
460 *
461 * 185 1/21/99 11:15p Jeff
462 * pulled out some structs and defines from header files and moved them
463 * into seperate header files so that multiplayer dlls don't require major
464 * game headers, just those new headers. Side effect is a shorter build
465 * time. Also cleaned up some header file #includes that weren't needed.
466 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
467 * manage.h and multi.h
468 *
469 * 184 1/17/99 10:41p Kevin
470 * Added command line options for setting the renderer in GAMEGAUGE mode.
471 *
472 * 183 1/13/99 3:25p Jason
473 * fixed vsync problem
474 *
475 * 182 1/08/99 2:58p Kevin
476 * Added TCP mprintf support so you can log to a remote machine.
477 *
478 * 181 1/08/99 2:55p Samir
479 * Ripped out OSIRIS1.
480 *
481 * 180 1/07/99 12:28p Samir
482 * Call to InitD3Music added parameter.
483 *
484 * 179 1/05/99 3:59p Kevin
485 *
486 * 178 1/05/99 3:55p Kevin
487 * Added structured exception handling
488 *
489 * 177 1/04/99 5:43p Kevin
490 * new command line args
491 *
492 * 176 12/23/98 6:38p Kevin
493 * All UDP data (except gamespy) now uses one (registered) port number
494 *
495 * 175 12/16/98 12:04p Kevin
496 * GameSpy!
497 *
498 * 174 12/14/98 4:48p Jeff
499 * call to intialize Osiris module manager
500 *
501 * 173 12/10/98 3:41p Jeff
502 * implemented settings for 16 or 32 bit depth (in config)
503 *
504 * 172 12/07/98 11:30a Kevin
505 * Added some features from the 1.1 demo patch
506 *
507 * 171 12/02/98 1:07p Jason
508 * made vsync work correctly, finally
509 *
510 * 170 11/24/98 5:17p Jeff
511 * initialize Pilot Pics
512 *
513 * 169 11/23/98 12:31p Jeff
514 * save out force feedback stuff (bad merge, we lost it earlier)
515 *
516 * 168 11/13/98 2:29p Samir
517 * new music code.
518 *
519 * 166 11/09/98 2:59p Kevin
520 * Added command line option for disabling multiplayer bitmap exchange
521 *
522 * 165 11/03/98 6:43p Jeff
523 * new low-level & high level Force Feedback system implemented, handles
524 * window losing focus, etc.
525 *
526 * 164 10/24/98 2:18p Samir
527 * don't do mouse stuff for dedicated server.
528 *
529 * 163 10/22/98 2:42p Samir
530 * fixed ALT-TAB pause issue.
531 *
532 * 162 10/22/98 1:58p Kevin
533 * Fixed the working directory (-setdir) command
534 *
535 * 161 10/22/98 1:39p Jeff
536 * autolevel is default full
537 *
538 * 160 10/20/98 6:24p Jason
539 * added super low memory mode
540 *
541 * 159 10/20/98 10:56a Sean
542 * fixed #ifdef editor thingy
543 *
544 * 158 10/20/98 12:58a Jeff
545 * added a way to force a lo-resolution timer
546 *
547 * 157 10/20/98 12:10a Samir
548 * this should fix the problem of the mouse not working properly in game.
549 *
550 * 156 10/19/98 6:30p Jeff
551 * changes made for detail variables. Put in preset values. Preset
552 * options. Removed terrain_cast from detail. Put new callbacks in
553 * UIListBox and UISlider
554 *
555 * 153 10/18/98 9:12p Matt
556 * Use new symbolic constant for the program name.
557 *
558 * 152 10/18/98 8:51p Matt
559 * Revamped debug/error system.
560 *
561 * 151 10/18/98 3:36p Jeff
562 * if _DEBUG isn't defined than the rtp_enable/disableflags call gets
563 * compiled out
564 *
565 * 150 10/18/98 2:50p Kevin
566 * Use low memory mode in dedicated server mode.
567 *
568 * 149 10/17/98 5:50p Jeff
569 * hooked in rtperformance (run time performance) library
570 *
571 * 148 10/17/98 12:46p Kevin
572 * Beta 4 fixes
573 *
574 * 147 10/16/98 2:44p Kevin
575 * working on getting demo compiling
576 *
577 * 146 10/16/98 1:54p Kevin
578 * Changes for Demo Beta 4
579 *
580 * 145 10/15/98 1:33p Jeff
581 * removed amount of debris detail level. Added powerup halo detail
582 * level. Added predef detail level settings
583 *
584 * 144 10/15/98 11:58a Kevin
585 * checked for low mem
586 *
587 * 143 10/14/98 4:37p Matt
588 * Made InitD3System() exit with error if there's a problem instead of
589 * returning a status value. Also moved some editor-specific code from
590 * init.cpp to mainfrm.cpp, and cleaned up some other initialization and
591 * error-handling code.
592 *
593 * 142 10/13/98 3:47p Samir
594 * added function to check if a cursor is visible
595 *
596 * 141 10/13/98 3:41p Kevin
597 * bug fixes
598 *
599 * 140 10/13/98 2:49p Matt
600 * Open "extra.hog" (if it exists" at startup so we can put any extra data
601 * in there.
602 *
603 * 139 10/12/98 3:01p Jeff
604 * added vsync and more detail level settings
605 *
606 * 138 10/12/98 2:51p Samir
607 * use main menu background for loading data screen.
608 *
609 * 137 10/09/98 8:47p Samir
610 * don't kill sound library when shutting down game.
611 *
612 * 136 10/08/98 7:27p Samir
613 * don't change defer handlers when shuting down or restarting.
614 *
615 * 135 10/08/98 5:55p Matt
616 * Set main hogfile.
617 *
618 * 134 10/08/98 3:36p Jason
619 * fixes for the demo
620 *
621 * 133 10/08/98 1:23p Samir
622 * shutdown and reinit now do so with ddio systems.
623 *
624 * 132 10/07/98 2:54p Jeff
625 * General UI fixes and additions
626 *
627 * 131 10/07/98 12:55p Jason
628 * fixed some defaults
629 *
630 * 130 10/03/98 11:21p Matt
631 * Added system to seperately control outline mode for mine, terrain, sky,
632 * & objects
633 *
634 * 129 10/01/98 11:57a Matt
635 * Added some mprintf()s
636 *
637 * 128 9/30/98 10:36a Kevin
638 * Added command line launching of URLs and command line directory
639 * specification
640 *
641 * 127 9/25/98 2:53p Jason
642 * added progress bar
643 *
644 * 126 9/25/98 12:31p Samir
645 * in main game, hide cursor when starting.
646 *
647 * 125 9/23/98 3:08p Jeff
648 *
649 * 124 9/22/98 6:58p Samir
650 * Render_floating_triggers is _DEBUG code, so make it so.
651 *
652 * 123 9/22/98 3:55p Samir
653 * ifdef out stuff for non-debug version.
654 *
655 * 122 9/22/98 10:32a Jason
656 * made preferred renderer default to OpenGL
657 *
658 * 121 9/21/98 11:10a Jeff
659 * Calls to init/close forcefeedback
660 *
661 * 120 9/18/98 7:38p Jeff
662 * creation of low-level forcefeedback and beginning of high-level
663 * forcefeedback
664 *
665 * 119 9/18/98 1:27p Jason
666 * cleaned up renderer initting
667 *
668 * 118 9/16/98 6:07p Jason
669 * made dedicated server use standard mouse mode
670 *
671 * 117 9/15/98 4:31p Jason
672 * added more functionality for the dedicated server
673 *
674 * 116 9/14/98 6:28p Jason
675 * first pass at getting dedicated server working
676 *
677 * 115 9/03/98 12:11p Chris
678 * Adding matcen support
679 *
680 * 114 8/31/98 12:39p Samir
681 * added code to resume controllers when restoring game mode.
682 *
683 * 113 8/27/98 6:23p Jeff
684 * changed autoleveling in config so it is a slider...had to convert
685 * global from bool->uint8_t. Added fast headlight and mirrored surfaces to
686 * config menu
687 *
688 * 112 8/19/98 2:19p Jeff
689 * moved detail globals to a struct
690 *
691 * 111 8/17/98 6:40p Matt
692 * Added ambient sound system
693 *
694 * 110 8/15/98 5:16p Matt
695 * Added new Base_directory variable. Got rid of D3_LOCAL check and
696 * 'local directory' registry variable.
697 *
698 * 109 8/10/98 5:52p Samir
699 * took out briefings search path.
700 *
701 * 108 7/31/98 11:51a Jason
702 * added player ship choosing to multiplayer games
703 *
704 * 107 7/24/98 5:32p Samir
705 * added initializer for D3 Music.
706 *
707 * 106 7/13/98 12:42p Samir
708 * don't do initmessage if graphics system not initialized.
709 *
710 * 105 7/08/98 6:27p Samir
711 * stream library integrated with highlevel sound system.
712 *
713 * 104 7/01/98 4:56p Samir
714 * redid init code.
715 *
716 * 103 6/24/98 11:14a Chris
717 * Added more support and bug fixes
718 *
719 * 102 6/23/98 6:00p Chris
720 * DirectSound 16 mixer is active with 8 bit samples
721 *
722 * 101 6/22/98 12:00p Chris
723 * Working on sound system to make it in a nice shape.
724 *
725 * 100 6/19/98 6:42p Jason
726 * made specular mapping a config detail item
727 *
728 * 99 6/19/98 6:04p Jeff
729 * variables to turn on/off voices
730 *
731 * 98 6/18/98 5:22p Jeff
732 * initialize streaming audio system
733 *
734 * 97 6/17/98 3:58p Jeff
735 * put in PilotInit(). String table loaded near begining for Main exe,
736 * after tables are loaded for editor
737 *
738 * 96 6/16/98 3:48p Chris
739 * Updated the sound system and added the start of sound streaming
740 *
741 * 95 6/16/98 11:49a Jeff
742 * string table loaded after manage system
743 *
744 * 94 6/16/98 10:54a Jeff
745 *
746 * 93 6/12/98 5:56p Jeff
747 * Load string tables during init
748 *
749 * 92 6/08/98 3:56p Jeff
750 * added initializing functions for compressed audio and voice systems
751 *
752 * 91 6/02/98 6:03p Jason
753 * added specular lightmaps
754 *
755 * 90 6/02/98 4:37p Samir
756 * multiple joysticks supported.
757 *
758 * 89 6/01/98 11:37a Chris
759 *
760 * 88 5/19/98 3:43p Samir
761 * must move mem_Init after error_Init.
762 *
763 * 87 5/19/98 3:37p Samir
764 * added mem_Init
765 *
766 * 86 5/14/98 11:49a Chris
767 * Bettered the sound paging system
768 *
769 * 85 5/12/98 2:05p Craig
770 * errror
771 *
772 * 84 5/12/98 11:45a Samir
773 * added logfile init.
774 *
775 * 83 5/06/98 6:34p Jeff
776 * Added Terrain casting to config
777 *
778 * 82 5/06/98 4:32p Samir
779 * moved ui init back to it's proper place.
780 *
781 * 81 5/06/98 12:44p Jeff
782 * added saving/restoring video resolution
783 *
784 * 80 5/05/98 5:16p Samir
785 * took out calls to init UI system (that's done now in SetScreenMode)
786 *
787 * 79 5/05/98 3:02p Jason
788 * attempting to add different screen resolutions
789 *
790 * 78 5/04/98 3:42p Matt
791 * Page in all sounds at init time, so you don't have to wait when you're
792 * starting a game
793 *
794 * 77 5/01/98 4:48p Jeff
795 * Added autoleveling into the configuration
796 *
797 * 76 4/28/98 6:42p Matt
798 * If registry says renderer is software, force it to be glide.
799 *
800 * 75 4/28/98 11:56a Jeff
801 * moved things from config (d3.cfg) into the registry
802 *
803 * 74 4/24/98 1:53a Samir
804 * added trigger init and free.
805 *
806 * 73 4/16/98 6:53a Samir
807 * added default script warning system.
808 *
809 * 72 4/16/98 12:23a Samir
810 * fixed bug when checking if script compiled in editor.
811 *
812 * 71 4/14/98 7:31p Matt
813 * Changed code to use ddio_MakePath() instead of sprintf() to create file
814 * spec
815 *
816 * 70 4/10/98 7:48p Samir
817 * make sure to set default values for outlining, etc.
818 *
819 * 69 4/09/98 5:30p Samir
820 * new main menu art.
821 *
822 * 68 4/08/98 7:19p Samir
823 * Added runtime debugging option.
824 *
825 * 67 4/07/98 9:20p Samir
826 * Changes to debug stuff.
827 *
828 * 66 4/06/98 5:13p Chris
829 * Sounds page in at the beginning of a level
830 *
831 * 65 4/02/98 7:58p Samir
832 * make sure to pause game and close/init control system when application
833 * looses focus.
834 *
835 * 64 3/27/98 5:18p Samir
836 * initialize debug break handlers differently for editor.
837 *
838 * 63 3/27/98 3:29p Brent
839 * if joy init fails, don't try initializing joystick. (samir)
840 *
841 * 62 3/27/98 2:44p Samir
842 * Restore joystick initialization.
843 *
844 * 61 3/23/98 8:03p Samir
845 * A bunch of changes to allow for ALT-TAB to work.
846 *
847 * 60 3/20/98 5:51p Jason
848 * more changes for multiplayer
849 *
850 * 59 3/20/98 1:19p Jeff
851 * Changes made to use Default_pilot string for pilot filename to use.
852 *
853 * 58 3/19/98 11:27a Samir
854 * Better error checking.
855 *
856 * 57 3/13/98 1:22p Jason
857 * Moved UseHardware flag to the renderer lib where it belongs
858 *
859 * 56 3/10/98 5:16p Samir
860 * Got debug callbacks working when you hit an Int3.
861 *
862 * 55 3/05/98 6:39p Samir
863 * Initialize ui system with UI_FONT
864 *
865 * 54 3/04/98 12:00p Jason
866 * added default gamma settings
867 *
868 * 53 2/27/98 5:35p Jeff
869 * Added in loading and saving of a game configuration file
870 *
871 * 52 2/18/98 1:33a Jason
872 * don't do mip mapping by default
873 *
874 * 51 2/18/98 1:11a Samir
875 * Some game window mess.
876 *
877 * 50 2/17/98 2:21p Samir
878 * Added d3xdebug.h
879 *
880 * 49 2/14/98 10:48p Jason
881 * got preferred rendering working
882 *
883 * 46 2/11/98 5:55p Samir
884 * Now InitD3XDebug and CloseD3XDebug are called when you enter and leave
885 * the game. This as well as ui_Init and ui_Close
886 *
887 * 45 2/02/98 7:34p Samir
888 * Moved D3X Initialization to PlayGame.
889 *
890 * 44 1/29/98 12:24p Samir
891 * Added logfile support.
892 *
893 * 43 1/27/98 1:20p Samir
894 * Fixed initialization for main game.
895 *
896 * 42 1/13/98 12:31p Samir
897 * only register small font for editor.
898 *
899 * 41 1/02/98 5:32p Chris
900 * More radical changes to the sound system
901 *
902 * 40 12/31/97 1:01a Chris
903 * Removed old dead code
904 *
905 *
906 *
907 * $NoKeywords: $
908 */
909
910 // Initialization routines for Descent3/Editor
911
912 #include <cstring>
913 #include <ctime>
914 #include <filesystem>
915
916 #include "mono.h"
917 #include "gametexture.h"
918 #include "object.h"
919 #include "vecmat.h"
920 #include "init.h"
921 #include "config.h"
922 #include "3d.h"
923 #include "hlsoundlib.h"
924 #include "manage.h"
925 #include "bitmap.h"
926 #include "ddio.h"
927 #include "render.h"
928 #include "descent.h"
929 #include "renderer.h"
930 #include "vclip.h"
931 #include "grdefs.h"
932 #include "pserror.h"
933 #include "lighting.h"
934 #include "polymodel.h"
935 #include "door.h"
936 #include "terrain.h"
937 #include "soundload.h"
938 #include "ship.h"
939 #include "controls.h"
940 #include "Mission.h"
941 #include "findintersection.h"
942 #include "appdatabase.h"
943 #include "room.h"
944 #include "game.h"
945 #include "gamefile.h"
946 #include "TelCom.h"
947 #include "objinfo.h"
948 #include "cinematics.h"
949 #include "lightmap_info.h"
950 #include "fireball.h"
951 #include "networking.h"
952 #include "args.h"
953 #include "pilot.h"
954 #include "gameloop.h"
955 #include "trigger.h"
956 #include "physics.h"
957 #include "special_face.h"
958 #include "voice.h"
959 #include "localization.h"
960 #include "stringtable.h"
961 #include "player.h"
962 #include "psrand.h"
963 #include "ambient.h"
964 #include "matcen.h"
965 #include "dedicated_server.h"
966 #include "D3ForceFeedback.h"
967 #include "newui.h"
968 #include "SmallViews.h"
969 #include "uisys.h"
970 #include "rtperformance.h"
971 #include "d3music.h"
972 #include "PilotPicsAPI.h"
973 #include "osiris_dll.h"
974 #include "mem.h"
975 #include "multi.h"
976 #include "marker.h"
977 #include "gamecinematics.h"
978 #include "debuggraph.h"
979
980 // Uncomment this to allow all languages
981 #define ALLOW_ALL_LANG 1
982
983 #ifdef EDITOR
984 #include "editor\HFile.h"
985 #include "editor\d3edit.h"
986 #include "slew.h"
987 #include "gr.h"
988 #define INIT_MESSAGE(c) SplashMessage c
989 #else
990 void IntroScreen();
991 #define INIT_MESSAGE(c) InitMessage(c)
992 #endif
993
994 #if defined(EDITOR) || defined(NEWEDITOR)
995 bool Running_editor = true; // didn't we have a variable like this somewhere
996 #else
997 bool Running_editor = false; // didn't we have a variable like this somewhere
998 #endif
999
1000 static bool Init_in_editor = false;
1001
1002 // used to update load bar.
1003 static void SetInitMessageLength(const char *c, float amount); // portion of total bar to fill (0 to 1)
1004 extern void UpdateInitMessage(float amount); // amount is 0 to 1
1005 static void SetupTempDirectory(void);
1006 static void DeleteTempFiles(void);
1007 static void PreGameCdCheck();
1008 static void InitIOSystems(bool editor);
1009 static void InitStringTable();
1010 static void InitGraphics(bool editor);
1011 static void InitGameSystems(bool editor);
1012 static void InitDedicatedServer();
1013
1014 #define TEMPBUFFERSIZE 256
1015
1016 // If there's a joystick, this is the stick number. Else, this is -1
1017 char App_ddvid_subsystem[8];
1018
1019 // other info.
1020 static chunked_bitmap Title_bitmap;
1021 static bool Init_systems_init = false;
1022 static bool Graphics_init = false;
1023 static bool Title_bitmap_init = false;
1024 uint8_t Use_motion_blur = 0;
1025
1026 // The "root" directory of the D3 file tree
1027 char Base_directory[_MAX_PATH];
1028 char Base_directory_write[_MAX_PATH];
1029
1030 extern int Min_allowed_frametime;
1031
1032 extern bool Render_powerup_sparkles;
1033 extern int Use_file_xfer;
1034
1035 static const float kDefaultMouselookSensitivity = 9.102f;
1036 static const float kAnglesPerDegree = 65536.0f / 360.0f;
1037 float Mouselook_sensitivity = kAnglesPerDegree * kDefaultMouselookSensitivity;
1038 float Mouse_sensitivity = 1.0f;
1039
1040 int merc_hid = -1;
1041
1042 /*
1043 Initializes all the subsystems that need to be initialized BEFORE application creation.
1044 Returns 1 if all is good, 0 if something is wrong
1045 */
1046 void PreInitD3Systems() {
1047 // initialize error system
1048 bool debugging = false;
1049
1050 #ifndef RELEASE
1051
1052 debugging = (FindArg("-debug") != 0);
1053
1054 if (FindArg("-logfile")) {
1055 char logfile_path[_MAX_PATH];
1056 char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3");
1057 ddio_MakePath(logfile_path, prefPath, "d3.log", NULL);
1058 SDL_free(prefPath);
1059 Debug_Logfile(logfile_path);
1060 }
1061
1062 #endif
1063
1064 #ifdef DAJ_DEBUG
1065 debugging = true;
1066 #endif
1067
1068 error_Init(debugging, PRODUCT_NAME);
1069
1070 if (FindArg("-lowmem"))
1071 Mem_low_memory_mode = true;
1072 if (FindArg("-superlowmem"))
1073 Mem_low_memory_mode = Mem_superlow_memory_mode = true;
1074 if (FindArg("-dedicated"))
1075 Mem_low_memory_mode = true;
1076 mem_Init();
1077 if (FindArg("-himem")) {
1078 Mem_low_memory_mode = false;
1079 Mem_superlow_memory_mode = false;
1080 }
1081 // For the client and the server, this turns off the bitmap exchange system.
1082 if (FindArg("-nomultibmp"))
1083 Use_file_xfer = 0;
1084
1085 int iframelmtarg = FindArg("-limitframe");
1086 if (iframelmtarg) {
1087 Min_allowed_frametime = atoi(GameArgs[iframelmtarg + 1]);
1088 mprintf(0, "Using %d as a minimum frametime\n", Min_allowed_frametime);
1089 } else {
1090 if (FindArg("-dedicated"))
1091 Min_allowed_frametime = 30;
1092 else
1093 Min_allowed_frametime = 0;
1094 }
1095 iframelmtarg = FindArg("-framecap");
1096 if (iframelmtarg) {
1097 Min_allowed_frametime = ((float)1.0 / (float)atoi(GameArgs[iframelmtarg + 1])) * 1000;
1098 mprintf(0, "Using %d as a minimum frametime\n", Min_allowed_frametime);
1099 } else {
1100 // Default to a framecap of 60
1101 Min_allowed_frametime = (1.0 / 60.0) * 1000;
1102 mprintf(0, "Using default framecap of 60\n");
1103 }
1104
1105 // Mouselook sensitivity!
1106 int msensearg = FindArg("-mlooksens");
1107 if (msensearg) {
1108 Mouselook_sensitivity = kAnglesPerDegree * atof(GameArgs[msensearg + 1]);
1109 mprintf(0, "Using mouselook sensitivity of %f\n", Mouselook_sensitivity);
1110 }
1111
1112 // Mouse sensitivity (non-mouselook)
1113 msensearg = FindArg("-mousesens");
1114 if (msensearg) {
1115 Mouse_sensitivity = atof(GameArgs[msensearg + 1]);
1116 mprintf(0, "Using mouse sensitivity of %f\n", Mouse_sensitivity);
1117 }
1118
1119 grtext_Init();
1120
1121 #ifndef RELEASE
1122 SetMessageBoxTitle(PRODUCT_NAME " Message");
1123 #endif
1124 }
1125
1126 void SaveGameSettings() {
1127 char tempbuffer[TEMPBUFFERSIZE];
1128 int tempint;
1129
1130 snprintf(tempbuffer, sizeof(tempbuffer), "%f", Render_preferred_state.gamma);
1131 Database->write("RS_gamma", tempbuffer, strlen(tempbuffer) + 1);
1132
1133 snprintf(tempbuffer, sizeof(tempbuffer), "%f", Sound_system.GetMasterVolume());
1134 Database->write("SND_mastervol", tempbuffer, strlen(tempbuffer) + 1);
1135
1136 snprintf(tempbuffer, sizeof(tempbuffer), "%f", D3MusicGetVolume());
1137 Database->write("MUS_mastervol", tempbuffer, strlen(tempbuffer) + 1);
1138
1139 snprintf(tempbuffer, sizeof(tempbuffer), "%f", Detail_settings.Pixel_error);
1140 Database->write("RS_pixelerror", tempbuffer, strlen(tempbuffer) + 1);
1141
1142 snprintf(tempbuffer, sizeof(tempbuffer), "%f", Detail_settings.Terrain_render_distance / ((float)TERRAIN_SIZE));
1143 Database->write("RS_terraindist", tempbuffer, strlen(tempbuffer) + 1);
1144
1145 Database->write("Dynamic_Lighting", Detail_settings.Dynamic_lighting);
1146
1147 #ifdef _DEBUG
1148 Database->write("Outline_mode", Outline_mode);
1149 Database->write("Lighting_on", Lighting_on);
1150 Database->write("Render_floating_triggers", Render_floating_triggers);
1151 #endif
1152
1153 Database->write("TerrLeveling", Default_player_terrain_leveling);
1154 Database->write("RoomLeveling", Default_player_room_leveling);
1155 // Database->write("Terrain_casting",Detail_settings.Terrain_casting);
1156 Database->write("Specmapping", Detail_settings.Specular_lighting);
1157 Database->write("FastHeadlight", Detail_settings.Fast_headlight_on);
1158 Database->write("MirrorSurfaces", Detail_settings.Mirrored_surfaces);
1159 Database->write("MissileView", Missile_camera_window);
1160 Database->write("RS_vsync", Render_preferred_state.vsync_on);
1161 Database->write("DetailScorchMarks", Detail_settings.Scorches_enabled);
1162 Database->write("DetailWeaponCoronas", Detail_settings.Weapon_coronas_enabled);
1163 Database->write("DetailFog", Detail_settings.Fog_enabled);
1164 Database->write("DetailCoronas", Detail_settings.Coronas_enabled);
1165 Database->write("DetailProcedurals", Detail_settings.Procedurals_enabled);
1166 Database->write("DetailObjectComp", Detail_settings.Object_complexity);
1167 Database->write("DetailPowerupHalos", Detail_settings.Powerup_halos);
1168
1169 Database->write("RS_resolution", Game_video_resolution);
1170
1171 Database->write("RS_bitdepth", Render_preferred_bitdepth);
1172 Database->write("RS_bilear", Render_preferred_state.filtering);
1173 Database->write("RS_mipping", Render_preferred_state.mipping);
1174 Database->write("RS_color_model", Render_state.cur_color_model);
1175 Database->write("RS_light", Render_state.cur_light_state);
1176 Database->write("RS_texture_quality", Render_state.cur_texture_quality);
1177
1178 Database->write("VoicePowerup", PlayPowerupVoice);
1179 Database->write("VoiceAll", PlayVoices);
1180
1181 // Write out force feedback
1182 Database->write("EnableJoystickFF", D3Use_force_feedback);
1183 Database->write("ForceFeedbackAutoCenter", D3Force_auto_center);
1184 uint8_t force_gain;
1185 if (D3Force_gain < 0.0f)
1186 D3Force_gain = 0.0f;
1187 if (D3Force_gain > 1.0f)
1188 D3Force_gain = 1.0f;
1189 force_gain = (uint8_t)((100.0f * D3Force_gain) + 0.5f);
1190 Database->write("ForceFeedbackGain", force_gain);
1191
1192 #ifndef RELEASE // never save this value out in release.
1193 Database->write("SoundMixer", Sound_mixer);
1194 Database->write("PreferredRenderer", PreferredRenderer);
1195 #endif
1196
1197 tempint = Sound_quality;
1198 Database->write("SoundQuality", tempint);
1199
1200 Database->write("SoundQuantity", Sound_system.GetLLSoundQuantity());
1201
1202 if (Default_pilot[0] != '\0')
1203 Database->write("Default_pilot", Default_pilot, strlen(Default_pilot) + 1);
1204 else
1205 Database->write("Default_pilot", " ", 2);
1206 }
1207
1208 /*
1209 Read game variables from the registry
1210 */
1211 void LoadGameSettings() {
1212 char tempbuffer[TEMPBUFFERSIZE], *stoptemp;
1213 int templen = TEMPBUFFERSIZE;
1214 int tempint;
1215
1216 // set defaults
1217 #ifdef _DEBUG
1218 Outline_mode = OM_ALL;
1219 Lighting_on = true;
1220 #endif
1221
1222 Detail_settings.Specular_lighting = false;
1223 Detail_settings.Dynamic_lighting = true;
1224 Detail_settings.Fast_headlight_on = true;
1225 Detail_settings.Mirrored_surfaces = true;
1226 Detail_settings.Scorches_enabled = true;
1227 Detail_settings.Weapon_coronas_enabled = true;
1228 Render_preferred_state.mipping = true;
1229 Render_preferred_state.filtering = true;
1230 Render_preferred_state.bit_depth = 16;
1231 Render_preferred_bitdepth = 16;
1232 Default_player_terrain_leveling = 2;
1233 Default_player_room_leveling = 2;
1234 Render_preferred_state.gamma = 1.5;
1235 PreferredRenderer = RENDERER_OPENGL;
1236
1237 Sound_system.SetLLSoundQuantity(MIN_SOUNDS_MIXED + (MAX_SOUNDS_MIXED - MIN_SOUNDS_MIXED) / 2);
1238 D3MusicSetVolume(0.5f);
1239 Detail_settings.Pixel_error = 8.0;
1240 Sound_system.SetMasterVolume(1.0);
1241 Detail_settings.Terrain_render_distance = 70.0 * TERRAIN_SIZE;
1242 D3Use_force_feedback = true;
1243 D3Force_gain = 1.0f;
1244 D3Force_auto_center = true;
1245 Game_video_resolution = RES_640X480;
1246 PlayPowerupVoice = true;
1247 PlayVoices = true;
1248 Sound_mixer = SOUND_MIXER_SOFTWARE_16;
1249 Sound_quality = SQT_NORMAL;
1250 Missile_camera_window = SVW_LEFT;
1251 Render_preferred_state.vsync_on = true;
1252 Detail_settings.Fog_enabled = true;
1253 Detail_settings.Coronas_enabled = true;
1254 Detail_settings.Procedurals_enabled = true;
1255 Detail_settings.Object_complexity = 1;
1256 Detail_settings.Powerup_halos = true;
1257
1258 ddio_SetKeyboardLanguage(KBLANG_AMERICAN);
1259
1260 if (Database->read("KeyboardType", tempbuffer, &templen)) {
1261 if (stricmp(tempbuffer, "French") == 0) {
1262 ddio_SetKeyboardLanguage(KBLANG_FRENCH);
1263 } else if (stricmp(tempbuffer, "German") == 0) {
1264 ddio_SetKeyboardLanguage(KBLANG_GERMAN);
1265 }
1266 }
1267
1268 templen = TEMPBUFFERSIZE;
1269 if (Database->read("RS_gamma", tempbuffer, &templen)) {
1270 Render_preferred_state.gamma = strtod(tempbuffer, &stoptemp);
1271 }
1272 templen = TEMPBUFFERSIZE;
1273 if (Database->read("SND_mastervol", tempbuffer, &templen)) {
1274 Sound_system.SetMasterVolume(strtod(tempbuffer, &stoptemp));
1275 }
1276 templen = TEMPBUFFERSIZE;
1277 if (Database->read("MUS_mastervol", tempbuffer, &templen)) {
1278 D3MusicSetVolume(strtod(tempbuffer, &stoptemp));
1279 }
1280 templen = TEMPBUFFERSIZE;
1281 if (Database->read("RS_pixelerror", tempbuffer, &templen)) {
1282 Detail_settings.Pixel_error = strtod(tempbuffer, &stoptemp);
1283 }
1284 templen = TEMPBUFFERSIZE;
1285 if (Database->read("RS_terraindist", tempbuffer, &templen)) {
1286 Detail_settings.Terrain_render_distance = strtod(tempbuffer, &stoptemp) * TERRAIN_SIZE;
1287 }
1288 templen = TEMPBUFFERSIZE;
1289 Database->read_int("Dynamic_Lighting", &Detail_settings.Dynamic_lighting);
1290
1291 #ifdef _DEBUG
1292 Database->read_int("Outline_mode", &Outline_mode);
1293 Database->read("Lighting_on", &Lighting_on);
1294 Database->read("Render_floating_triggers", &Render_floating_triggers);
1295 #endif
1296
1297 Database->read_int("TerrLeveling", &Default_player_terrain_leveling);
1298 Database->read_int("RoomLeveling", &Default_player_room_leveling);
1299 Database->read("Specmapping", &Detail_settings.Specular_lighting);
1300 Database->read("RS_bitdepth", &Render_preferred_bitdepth, sizeof(Render_preferred_bitdepth));
1301 Database->read_int("RS_resolution", &Game_video_resolution);
1302 Database->read_int("RS_bilear", &Render_preferred_state.filtering);
1303 Database->read_int("RS_mipping", &Render_preferred_state.mipping);
1304 Database->read_int("RS_color_model", &Render_state.cur_color_model);
1305 Database->read_int("RS_light", &Render_state.cur_light_state);
1306 Database->read_int("RS_texture_quality", &Render_state.cur_texture_quality);
1307 // force feedback stuff
1308 Database->read("EnableJoystickFF", &D3Use_force_feedback);
1309 Database->read("ForceFeedbackAutoCenter", &D3Force_auto_center);
1310 uint8_t force_gain;
1311 Database->read("ForceFeedbackGain", &force_gain, sizeof(force_gain));
1312 if (force_gain > 100)
1313 force_gain = 100;
1314 D3Force_gain = ((float)force_gain) / 100.0f;
1315 Database->read_int("PreferredRenderer", &PreferredRenderer);
1316 Database->read_int("MissileView", &Missile_camera_window);
1317 Database->read("FastHeadlight", &Detail_settings.Fast_headlight_on);
1318 Database->read("MirrorSurfaces", &Detail_settings.Mirrored_surfaces);
1319 Database->read_int("RS_vsync", &Render_preferred_state.vsync_on);
1320
1321 if (FindArg("-vsync"))
1322 Render_preferred_state.vsync_on = true;
1323
1324 //@@ // Base missile camera if in wrong window
1325 //@@ if (Missile_camera_window==SVW_CENTER)
1326 //@@ Missile_camera_window=SVW_LEFT;
1327
1328 Database->read("VoicePowerup", &PlayPowerupVoice);
1329 Database->read("VoiceAll", &PlayVoices);
1330
1331 Database->read("DetailScorchMarks", &Detail_settings.Scorches_enabled);
1332 Database->read("DetailWeaponCoronas", &Detail_settings.Weapon_coronas_enabled);
1333 Database->read("DetailFog", &Detail_settings.Fog_enabled);
1334 Database->read("DetailCoronas", &Detail_settings.Coronas_enabled);
1335 Database->read("DetailProcedurals", &Detail_settings.Procedurals_enabled);
1336 Database->read_int("DetailObjectComp", &tempint);
1337 Detail_settings.Object_complexity = tempint;
1338 if (Detail_settings.Object_complexity < 0 || Detail_settings.Object_complexity > 2)
1339 Detail_settings.Object_complexity = 1;
1340
1341 Database->read("DetailPowerupHalos", &Detail_settings.Powerup_halos);
1342
1343 if (Database->read_int("SoundMixer", &tempint))
1344 Sound_mixer = tempint;
1345
1346 if (Database->read_int("SoundQuality", &tempint))
1347 Sound_quality = tempint;
1348
1349 if (Database->read_int("SoundQuantity", &tempint)) {
1350 Sound_system.SetLLSoundQuantity(tempint);
1351 }
1352
1353 Sound_card_name[0] = 0;
1354 templen = TEMPBUFFERSIZE;
1355 if (Database->read("SoundcardName", tempbuffer, &templen)) {
1356 strcpy(Sound_card_name, tempbuffer);
1357 }
1358
1359 int len = _MAX_PATH;
1360 Database->read("Default_pilot", Default_pilot, &len);
1361
1362 // Now that we have read in all the data, set the detail level if it is a predef setting (custom is ignored in
1363 // function)
1364
1365 int level;
1366 level = DETAIL_LEVEL_MED;
1367
1368 Database->read_int("PredefDetailSetting", &level);
1369 ConfigSetDetailLevel(level);
1370 int widtharg = FindArg("-Width");
1371 int heightarg = FindArg("-Height");
1372 if (widtharg) {
1373 Video_res_list[N_SUPPORTED_VIDRES - 1].width = atoi(GameArgs[widtharg + 1]);
1374 Game_video_resolution = N_SUPPORTED_VIDRES - 1;
1375 }
1376 if (heightarg) {
1377 Video_res_list[N_SUPPORTED_VIDRES - 1].height = atoi(GameArgs[heightarg + 1]);
1378 Game_video_resolution = N_SUPPORTED_VIDRES - 1;
1379 }
1380
1381 // Motion blur
1382 Use_motion_blur = 0;
1383 if (Katmai || FindArg("-motionblur")) {
1384 if (!FindArg("-nomotionblur")) {
1385 Use_motion_blur = 1;
1386 }
1387 }
1388
1389 Render_powerup_sparkles = false;
1390 if (Katmai && !FindArg("-nosparkles")) {
1391 Render_powerup_sparkles = true;
1392 }
1393 }
1394
1395 struct tTempFileInfo {
1396 const char *wildcard;
1397 };
1398 static const tTempFileInfo temp_file_wildcards[] = {{"d3s*.tmp"}, {"d3m*.tmp"}, {"d3o*.tmp"},
1399 {"d3c*.tmp"}, {"d3t*.tmp"}, {"d3i*.tmp"}};
1400 static const int num_temp_file_wildcards = sizeof(temp_file_wildcards) / sizeof(tTempFileInfo);
1401
1402 /*
1403 I/O systems initialization
1404 */
1405 void InitIOSystems(bool editor) {
1406 ddio_init_info io_info;
1407
1408 // Set the base directory
1409 int dirarg = FindArg("-setdir");
1410 int exedirarg = FindArg("-useexedir");
1411 if (dirarg) {
1412 strncpy(Base_directory, GameArgs[dirarg + 1], sizeof(Base_directory) - 1);
1413 Base_directory[sizeof(Base_directory) - 1] = '\0';
1414 } else if (exedirarg) {
1415 char exec_path[_MAX_PATH];
1416 memset(exec_path, 0, sizeof(exec_path));
1417 // Populate exec_path with the executable path
1418 if (!ddio_GetBinaryPath(exec_path, sizeof(exec_path))) {
1419 Error("Failed to get executable path\n");
1420 } else {
1421 std::filesystem::path executablePath(exec_path);
1422 std::string baseDirectoryString = executablePath.parent_path().string();
1423 strncpy(Base_directory, baseDirectoryString.c_str(), sizeof(Base_directory) - 1);
1424 Base_directory[sizeof(Base_directory) - 1] = '\0';
1425 mprintf(0, "Using working directory of %s\n", Base_directory);
1426 }
1427 } else {
1428 ddio_GetWorkingDir(Base_directory, sizeof(Base_directory));
1429 }
1430 char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3");
1431 strncpy(Base_directory_write, prefPath, sizeof(Base_directory_write));
1432 SDL_free(prefPath);
1433
1434 char working_path[_MAX_PATH];
1435 ddio_MakePath(working_path, Base_directory_write, "demo", NULL);
1436 if (!std::filesystem::is_directory(working_path)) {
1437 std::filesystem::create_directory(working_path);
1438 }
1439 ddio_MakePath(working_path, Base_directory_write, "savegame", NULL);
1440 if (!std::filesystem::is_directory(working_path)) {
1441 std::filesystem::create_directory(working_path);
1442 }
1443
1444 ddio_SetWorkingDir(Base_directory);
1445
1446 Descent->set_defer_handler(D3DeferHandler);
1447
1448 #ifndef RELEASE
1449 if (!editor && !FindArg("-windowed")) {
1450 if (Dedicated_server) {
1451 ddio_MouseMode(MOUSE_STANDARD_MODE);
1452 } else {
1453 ddio_MouseMode(MOUSE_EXCLUSIVE_MODE);
1454 }
1455 }
1456 #else
1457 ddio_MouseMode(MOUSE_EXCLUSIVE_MODE);
1458 #endif
1459
1460 // do io init stuff
1461 io_info.obj = Descent;
1462 io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
1463 io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0); WIN95: DirectInput is flaky for some keys.
1464 INIT_MESSAGE(("Initializing DDIO systems."));
1465 if (!ddio_Init(&io_info)) {
1466 Error("I/O initialization failed.");
1467 }
1468
1469 rtp_Init();
1470 RTP_ENABLEFLAGS(RTI_FRAMETIME | RTI_RENDERFRAMETIME | RTI_MULTIFRAMETIME | RTI_MUSICFRAMETIME |
1471 RTI_AMBSOUNDFRAMETIME);
1472 RTP_ENABLEFLAGS(RTI_WEATHERFRAMETIME | RTI_PLAYERFRAMETIME | RTI_DOORFRAMETIME | RTI_LEVELGOALTIME |
1473 RTI_MATCENFRAMETIME);
1474 RTP_ENABLEFLAGS(RTI_OBJFRAMETIME | RTI_AIFRAMETIME | RTI_PROCESSKEYTIME);
1475
1476 // Read in stuff from the registry
1477 INIT_MESSAGE(("Reading settings."));
1478 LoadGameSettings();
1479
1480 // Setup temp directory
1481 INIT_MESSAGE(("Setting up temp directory."));
1482 SetupTempDirectory();
1483 mprintf(0, "Removing any temp files left over from last execution\n");
1484 DeleteTempFiles();
1485
1486 // create directory system.
1487 if (!mng_InitTableFiles()) {
1488 #ifdef EDITOR
1489 Error("Couldn't successfully initialize the table files. I'm shutting down!");
1490 #else
1491 Error(TXT_INITTABLEERR);
1492 #endif
1493 }
1494
1495 // Init hogfiles
1496 INIT_MESSAGE(("Checking for HOG files."));
1497 int d3_hid = -1, extra_hid = -1, sys_hid = -1, extra13_hid = -1;
1498 char fullname[_MAX_PATH];
1499
1500 #ifdef DEMO
1501 // DAJ d3_hid = cf_OpenLibrary("d3demo.hog");
1502 ddio_MakePath(fullname, LocalD3Dir, "d3demo.hog", NULL);
1503 #else
1504 ddio_MakePath(fullname, LocalD3Dir, "d3.hog", NULL);
1505 #endif
1506 d3_hid = cf_OpenLibrary(fullname);
1507
1508 // JC: Steam release uses extra1.hog instead of extra.hog, so try loading it first
1509 // Open this file if it's present for stuff we might add later
1510 ddio_MakePath(fullname, LocalD3Dir, "extra1.hog", NULL);
1511 extra_hid = cf_OpenLibrary(fullname);
1512 if (extra_hid == 0) {
1513 ddio_MakePath(fullname, LocalD3Dir, "extra.hog", NULL);
1514 extra_hid = cf_OpenLibrary(fullname);
1515 }
1516
1517 // JC: Steam release uses extra.hog instead of merc.hog, so try loading it last (so we don't conflict with the above)
1518 // Open mercenary hog if it exists
1519 ddio_MakePath(fullname, LocalD3Dir, "merc.hog", NULL);
1520 merc_hid = cf_OpenLibrary(fullname);
1521 if (merc_hid == 0) {
1522 ddio_MakePath(fullname, LocalD3Dir, "extra.hog", NULL);
1523 merc_hid = cf_OpenLibrary(fullname);
1524 }
1525
1526 // Open this for extra 1.3 code (Black Pyro, etc)
1527 ddio_MakePath(fullname, LocalD3Dir, "extra13.hog", NULL);
1528 extra13_hid = cf_OpenLibrary(fullname);
1529
1530 // last library opened is the first to be searched for dynamic libs, so put
1531 // this one at the end to find our newly build script libraries first
1532 ddio_MakePath(fullname, LocalD3Dir, PRIMARY_HOG, NULL);
1533 sys_hid = cf_OpenLibrary(fullname);
1534
1535 // Check to see if there is a -mission command line option
1536 // if there is, attempt to open that hog/mn3 so it can override such
1537 // things as the mainmenu movie, or loading screen
1538 int mission_arg = FindArg("-mission");
1539 if (mission_arg > 0) {
1540 char path_to_mission[_MAX_PATH];
1541 char filename[256];
1542
1543 // get the true filename
1544 ddio_SplitPath(GameArgs[mission_arg + 1], NULL, filename, NULL);
1545 strcat(filename, ".mn3");
1546
1547 // make the full path (it is forced to be on the harddrive since it contains
1548 // textures and stuff).
1549 ddio_MakePath(path_to_mission, LocalD3Dir, "missions", filename, NULL);
1550 if (cfexist(path_to_mission)) {
1551 cf_OpenLibrary(path_to_mission);
1552 } else {
1553 Int3(); // mission not found
1554 }
1555 }
1556
1557 // Initialize debug graph early incase any system uses it in it's init
1558 INIT_MESSAGE(("Initializing debug graph."));
1559 DebugGraph_Initialize();
1560
1561 // initialize all the OSIRIS systems
1562 // extract from extra.hog first, so it's dll files are listed ahead of d3.hog's
1563 INIT_MESSAGE(("Initializing OSIRIS."));
1564 Osiris_InitModuleLoader();
1565 if (extra13_hid != -1)
1566 Osiris_ExtractScriptsFromHog(extra13_hid, false);
1567 if (extra_hid != -1)
1568 Osiris_ExtractScriptsFromHog(extra_hid, false);
1569 if (merc_hid != -1)
1570 Osiris_ExtractScriptsFromHog(merc_hid, false);
1571 if (sys_hid != -1)
1572 Osiris_ExtractScriptsFromHog(sys_hid, false);
1573 Osiris_ExtractScriptsFromHog(d3_hid, false);
1574 }
1575
1576 // Returns true if Mercenary is installed (inits the Black Pyro and Red GB)
1577 bool MercInstalled() { return merc_hid > 0; }
1578
1579 extern int Num_languages;
1580 void InitStringTable() {
1581
1582 int language = LANGUAGE_ENGLISH;
1583 Database->read("LanguageType", &language, sizeof(language));
1584
1585 if (language < 0 || language >= Num_languages) {
1586 Int3();
1587 language = LANGUAGE_ENGLISH;
1588 }
1589 Localization_SetLanguage(language);
1590
1591 int string_count = LoadStringTables();
1592
1593 if (string_count == 0)
1594 Error("Couldn't find the string table.");
1595 else
1596 mprintf(0, "%d strings loaded from the string tables\n", string_count);
1597 }
1598
1599 void InitGraphics(bool editor) {
1600 // Init our bitmaps, must be called before InitTextures
1601 bm_InitBitmaps();
1602
1603 // Init our textures
1604 if (!InitTextures())
1605 Error("Failed to initialize texture system.");
1606
1607 #ifdef EDITOR
1608 char *driver = "GDIX";
1609
1610 if (!ddgr_Init(Descent, driver, editor ? false : true))
1611 Error("DDGR graphic system init failed.");
1612
1613 // Init our renderer
1614 grSurface::init_system();
1615 rend_Init(RENDERER_OPENGL, Descent, NULL);
1616 Desktop_surf = new grSurface(0, 0, 0, SURFTYPE_VIDEOSCREEN, 0);
1617 #else
1618 strcpy(App_ddvid_subsystem, "GDIX");
1619
1620 if (!Dedicated_server) {
1621 if (!ddvid_Init(Descent, App_ddvid_subsystem))
1622 Error("Graphics initialization failed.\n");
1623 }
1624
1625 INIT_MESSAGE("Loading fonts.");
1626 LoadAllFonts();
1627 #endif
1628 Graphics_init = true;
1629 }
1630
1631 void InitGameSystems(bool editor) {
1632 // initialize possible remote controller.
1633 int adr = FindArg("-rjoy");
1634 if (adr)
1635 Controller_ip = &GameArgs[adr + 1][1];
1636
1637 // do other joint editor/game initialization.
1638 SetInitMessageLength(TXT_INITCOLLATING, 0.4f);
1639 TelComInit();
1640 InitFrameTime();
1641
1642 // Check for aspect ratio override
1643 int t = FindArg("-aspect");
1644 if (t) {
1645 float aspect = atof(GameArgs[t + 1]);
1646 if (aspect > 0.0)
1647 g3_SetAspectRatio(aspect);
1648 }
1649
1650 // Initialize force feedback effects (if we can)
1651 ForceInit();
1652
1653 if (!editor) {
1654 tUIInitInfo uiinit;
1655 uiinit.window_font = SMALL_FONT;
1656 uiinit.w = 640;
1657 uiinit.h = 480;
1658 ui_Init(Descent, &uiinit);
1659 ui_UseCursor("StdCursor.ogf");
1660
1661 NewUIInit();
1662 InitControls();
1663
1664 atexit(CloseControls);
1665 atexit(ui_Close);
1666 }
1667 }
1668
1669 //////////////////////////////////////////////////////////////////////////////
1670 static float Init_messagebar_portion = 0.0f, Init_messagebar_offset = 0.0f;
1671 static const char *Init_messagebar_text = NULL;
1672
1673 // portion of total bar to fill (0 to 1)
1674 void SetInitMessageLength(const char *c, float amount) {
1675 Init_messagebar_text = c;
1676 Init_messagebar_offset += Init_messagebar_portion;
1677 Init_messagebar_portion = amount;
1678 }
1679
1680 // amount is 0 to 1
1681 void UpdateInitMessage(float amount) {
1682 if (Init_in_editor)
1683 return;
1684 InitMessage(Init_messagebar_text, (amount * Init_messagebar_portion) + Init_messagebar_offset);
1685 /*
1686 mprintf(0, "amt=%.2f, portion=%.2f offs=%.2f, prog=%.2f\n",
1687 amount,
1688 Init_messagebar_portion,
1689 Init_messagebar_offset,
1690 (amount*Init_messagebar_portion)+Init_messagebar_offset);
1691 */
1692 }
1693
1694 void InitMessage(const char *c, float progress) {
1695 int x = Game_window_w / 2 - Title_bitmap.pw / 2;
1696 int y = Game_window_h / 2 - Title_bitmap.ph / 2;
1697 int i, rx, ry, rw, rh;
1698
1699 if (Dedicated_server) {
1700 PrintDedicatedMessage("%s\n", c);
1701 return;
1702 }
1703
1704 if (!Graphics_init)
1705 return;
1706
1707 StartFrame();
1708
1709 if (Title_bitmap_init) {
1710 rend_ClearScreen(GR_BLACK);
1711 rend_DrawChunkedBitmap(&Title_bitmap, x, y, 255);
1712 }
1713
1714 if (c) {
1715 g3Point *pntlist[4], points[4];
1716 // Set our four corners to cover the screen
1717 grtext_SetFont(MONITOR9_NEWUI_FONT);
1718 rw = Game_window_w;
1719 rh = grfont_GetHeight(MONITOR9_NEWUI_FONT) + 8;
1720 rx = 0;
1721 ry = Game_window_h - rh;
1722 points[0].p3_sx = rx;
1723 points[0].p3_sy = ry;
1724 points[1].p3_sx = rx + rw;
1725 points[1].p3_sy = ry;
1726 points[2].p3_sx = rx + rw;
1727 points[2].p3_sy = ry + rh;
1728 points[3].p3_sx = rx;
1729 points[3].p3_sy = ry + rh;
1730
1731 for (i = 0; i < 4; i++) {
1732 points[i].p3_z = 0;
1733 points[i].p3_flags = PF_PROJECTED;
1734 pntlist[i] = &points[i];
1735 }
1736
1737 rend_SetZBufferState(0);
1738 rend_SetTextureType(TT_FLAT);
1739 rend_SetAlphaType(AT_CONSTANT);
1740 rend_SetLighting(LS_NONE);
1741 rend_SetFlatColor(GR_BLACK);
1742 rend_SetAlphaValue(230);
1743 rend_DrawPolygon2D(0, pntlist, 4);
1744
1745 if (progress >= 0) {
1746 points[0].p3_sx = rx;
1747 points[0].p3_sy = ry + rh - (rh / 2) + 2;
1748 points[1].p3_sx = rx + ((float)rw * progress);
1749 points[1].p3_sy = ry + rh - (rh / 2) + 2;
1750 points[2].p3_sx = rx + ((float)rw * progress);
1751 points[2].p3_sy = ry + rh;
1752 points[3].p3_sx = rx;
1753 points[3].p3_sy = ry + rh;
1754
1755 rend_SetFlatColor(GR_RGB(255, 0, 0));
1756 rend_SetAlphaValue(230);
1757 rend_DrawPolygon2D(0, pntlist, 4);
1758 }
1759
1760 grtext_SetAlpha(255);
1761 grtext_SetColor(NEWUI_MONITORFONT_COLOR);
1762 // grtext_CenteredPrintf(0, ry, c);
1763 grtext_Puts(0, ry, c);
1764 grtext_Flush();
1765 }
1766
1767 EndFrame();
1768 rend_Flip();
1769 }
1770
1771 //////////////////////////////////////////////////////////////////////////////
1772 #if (defined(OEM) || defined(DEMO) || defined(RELEASE))
1773 void ShowStaticScreen(char *bitmap_filename, bool timed = false, float delay_time = 0.0f);
1774 #endif
1775
1776 void IntroScreen() {
1777 // #if (defined(OEM) || defined(DEMO) )
1778 #ifdef DEMO
1779 ShowStaticScreen("tantrum.ogf", true, 3.0);
1780 ShowStaticScreen("outrage.ogf", true, 3.0);
1781 #else
1782 #endif
1783
1784 #ifdef DEMO
1785 int bm_handle = bm_AllocLoadFileBitmap("demomenu.ogf", 0);
1786 #else
1787 int bm_handle = bm_AllocLoadFileBitmap("oemmenu.ogf", 0);
1788 #endif
1789 mprintf(0, "Intro screen!.\n");
1790
1791 if (bm_handle > -1) {
1792 if (!bm_CreateChunkedBitmap(bm_handle, &Title_bitmap))
1793 Error("Failed to slice up d3.ogf!");
1794
1795 bm_FreeBitmap(bm_handle);
1796
1797 Title_bitmap_init = true;
1798 InitMessage(NULL);
1799 } else {
1800 mprintf(1, "Unable to find d3.tga.\n");
1801 }
1802 }
1803
1804 void InitDedicatedServer() {
1805 Game_mode |= GM_MULTI;
1806 Netgame.local_role = LR_SERVER;
1807
1808 int ok = LoadServerConfigFile();
1809
1810 if (!ok) {
1811 PrintDedicatedMessage(TXT_SHUTTINGDOWN);
1812 Error("Cannot load Dedicated Server config file.");
1813 exit(0);
1814 }
1815 }
1816
1817 /*
1818 The D3 Initialization Mess
1819
1820 This initialization sequence will occur after the application and debug systems
1821 are set up.
1822
1823 From here, we initialize all systems.
1824
1825 Initializes all the subsystems that D3/Editor needs to run.
1826 Returns 1 if all is good, 0 if something is wrong
1827 */
1828 int ServerTimeout = 0;
1829 float LastPacketReceived;
1830
1831 uint16_t Gameport = D3_DEFAULT_PORT;
1832 uint16_t PXOPort = 0;
1833 // Initialiaze everything before data load
1834 void InitD3Systems1(bool editor) {
1835 #if defined(RELEASE)
1836 SetDebugBreakHandlers(NULL, NULL);
1837 #else
1838 SetDebugBreakHandlers(D3DebugStopHandler, D3DebugResumeHandler);
1839 #endif
1840
1841 Init_in_editor = editor;
1842
1843 // Gamespy command to specify the port to listen on
1844 int gameportarg = FindArg("+host");
1845 if (!gameportarg) {
1846 gameportarg = FindArg("-useport");
1847 }
1848 if (gameportarg) {
1849 Gameport = atoi(GameArgs[gameportarg + 1]);
1850 }
1851
1852 int pxoportarg = FindArg("-pxoport");
1853 if (pxoportarg)
1854 PXOPort = atoi(GameArgs[pxoportarg + 1]);
1855
1856 // perform user i/o system initialization
1857 INIT_MESSAGE(("Initializing I/O system."));
1858 InitIOSystems(editor);
1859
1860 // load the string table
1861 InitStringTable();
1862
1863 INIT_MESSAGE(("Initializing GFX"));
1864 InitGraphics(editor);
1865
1866 // initialize data structures
1867 InitObjectInfo();
1868 InitVClips();
1869 InitRooms();
1870
1871 // initialize lighting systems
1872 InitLightmapInfo();
1873 InitSpecialFaces();
1874 InitDynamicLighting();
1875
1876 // Initialize missions
1877 InitMission();
1878
1879 // Initializes the ship structure
1880 InitShips();
1881
1882 // Initializes the fvi structures for quicker operation
1883 InitFVI();
1884
1885 // Initializes the matcens
1886 InitMatcens();
1887
1888 // This function needs be called before ANY 3d stuff can get done. I mean it.
1889 InitMathTables();
1890
1891 // Initialize a random seed.
1892 ps_srand(time(nullptr));
1893
1894 // This function has to be done before any sound stuff is called
1895 InitSounds();
1896
1897 // Allocate memory and stuff for our terrain engine, objects, etc.
1898 InitTerrain();
1899 InitModels();
1900 InitDoors();
1901 InitGamefiles();
1902
1903 // network initialization
1904 if (!FindArg("-nonetwork")) {
1905 nw_InitNetworking();
1906 nw_InitSockets(Gameport);
1907 }
1908
1909 int timeoutarg = FindArg("-timeout");
1910 if (timeoutarg) {
1911 ServerTimeout = atoi(GameArgs[timeoutarg + 1]);
1912 LastPacketReceived = timer_GetTime();
1913 }
1914
1915 // Sound initialization
1916 int soundres = Sound_system.InitSoundLib(Descent, Sound_mixer, Sound_quality, false);
1917
1918 // Initialize Cinematics system
1919 InitCinematics();
1920 }
1921
1922 // Initialize rest of stuff
1923 void InitD3Systems2(bool editor) {
1924 // Initialize In-Game Cinematics system
1925 Cinematic_Init();
1926
1927 // initialize slewing
1928 #ifdef EDITOR
1929 SlewControlInit();
1930 #endif
1931
1932 int tables_loaded = 0;
1933
1934 // load in all data headers.
1935 INIT_MESSAGE((TXT_INITDATA));
1936 tables_loaded = mng_LoadTableFiles(!editor);
1937
1938 if (!tables_loaded)
1939 Error("Cannot load table file.");
1940
1941 INIT_MESSAGE((TXT_INITCOLLATING));
1942
1943 // Initialize the pilot system
1944 PilotInit();
1945
1946 // Setup our object system. By object I mean stuff in our world, not those silly C++ things.
1947 // This call must come after InitTableFiles(), so we have a player ship for the user
1948 InitObjects();
1949
1950 // Fireball initting must come after LoadTableFiles
1951 SetInitMessageLength(TXT_INITCOLLATING, 0.1f);
1952 InitFireballs();
1953 UpdateInitMessage(1.0f);
1954
1955 // initializes triggers
1956 InitTriggers();
1957
1958 // the remaining sound system
1959 InitVoices();
1960 InitD3Music(FindArg("-nomusic") ? false : true);
1961 InitAmbientSoundSystem();
1962
1963 InitGameSystems(editor);
1964
1965 InitPlayers();
1966
1967 SetInitMessageLength(TXT_INITCOLLATING, 0.5f);
1968 InitMarkers();
1969 UpdateInitMessage(1.0f);
1970
1971 PPic_InitDatabase();
1972
1973 // Set next logical function for game.
1974 if (editor)
1975 SetFunctionMode(EDITOR_MODE);
1976 else
1977 SetFunctionMode(MENU_MODE);
1978
1979 if (Dedicated_server)
1980 InitDedicatedServer();
1981
1982 Init_systems_init = true;
1983
1984 // free title screen bitmap.
1985 if (Title_bitmap_init) {
1986 bm_DestroyChunkedBitmap(&Title_bitmap);
1987 Title_bitmap_init = false;
1988 }
1989
1990 // initialize localized text for controller system.
1991 extern void Localize_ctl_bindings();
1992 Localize_ctl_bindings();
1993 }
1994
1995 void SetupTempDirectory(void) {
1996 // NOTE: No string tables are available at this point
1997 //--------------------------------------------------
1998
1999 mprintf(0, "Setting up temp directory\n");
2000
2001 int t_arg = FindArg("-tempdir");
2002 if (t_arg) {
2003 strcpy(Descent3_temp_directory, GameArgs[t_arg + 1]);
2004 } else {
2005 std::error_code ec;
2006 std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
2007 if (ec) {
2008 Error("Could not find temporary directory: \"%s\"", ec.message().c_str() );
2009 exit(1);
2010 }
2011 ddio_MakePath(Descent3_temp_directory, tempPath.u8string().c_str(), "Descent3",
2012 "cache", NULL);
2013 }
2014
2015 std::error_code ec;
2016 std::filesystem::create_directories(Descent3_temp_directory, ec);
2017 if (ec) {
2018 Error("Could not create temporary directory: \"%s\"", Descent3_temp_directory);
2019 exit(1);
2020 }
2021
2022 // verify that temp directory exists
2023 if (!ddio_SetWorkingDir(Descent3_temp_directory)) {
2024 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2025 exit(1);
2026 }
2027
2028 char tempfilename[_MAX_PATH];
2029
2030 // verify that we can write to the temp directory
2031 if (!ddio_GetTempFileName(Descent3_temp_directory, "d3t", tempfilename)) {
2032 mprintf(0, "Unable to get temp file name\n");
2033 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2034 exit(1);
2035 }
2036
2037 // try to create a file in temp directory
2038 CFILE *file = cfopen(tempfilename, "wb");
2039 if (!file) {
2040 // unable to open file for writing
2041 mprintf(0, "Unable to open temp file name for writing\n");
2042 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2043 exit(1);
2044 }
2045
2046 cf_WriteInt(file, 0x56);
2047 cfclose(file);
2048
2049 // now open up the file and make sure it is correct
2050 file = cfopen(tempfilename, "rb");
2051 if (!file) {
2052 // unable to open file for reading
2053 mprintf(0, "Unable to open temp file name for reading\n");
2054 ddio_DeleteFile(tempfilename);
2055 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2056 exit(1);
2057 }
2058
2059 if (cf_ReadInt(file) != 0x56) {
2060 // verify failed
2061 mprintf(0, "Temp file verify failed\n");
2062 cfclose(file);
2063 ddio_DeleteFile(tempfilename);
2064 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2065 exit(1);
2066 }
2067
2068 cfclose(file);
2069
2070 // temp directory is valid!
2071 ddio_DeleteFile(tempfilename);
2072
2073 mprintf(0, "Temp Directory Set To: \"%s\"\n", Descent3_temp_directory);
2074
2075 // Lock the directory
2076 if (!ddio_CreateLockFile(std::filesystem::path(Descent3_temp_directory))) {
2077 mprintf(0, "Lock file NOT created in temp dir %s!\n", Descent3_temp_directory);
2078 Error("Unable to set temporary directory to: \"%s\"\nUnable to create lock file", Descent3_temp_directory);
2079 exit(1);
2080 }
2081 // restore working dir
2082 ddio_SetWorkingDir(Base_directory);
2083 }
2084
2085 void DeleteTempFiles(void) {
2086 char filename[_MAX_PATH];
2087
2088 // delete the d3 temp files in the temp directory
2089 if (ddio_SetWorkingDir(Descent3_temp_directory)) {
2090 int i;
2091 for (i = 0; i < num_temp_file_wildcards; i++) {
2092 if (ddio_FindFileStart(temp_file_wildcards[i].wildcard, filename)) {
2093 do {
2094 ddio_DeleteFile(filename);
2095 } while (ddio_FindNextFile(filename));
2096 }
2097 ddio_FindFileClose();
2098 }
2099 }
2100
2101 // restore directory
2102 ddio_SetWorkingDir(Base_directory);
2103 }
2104
2105 /*
2106 *
2107 * These functions handle shutting down and restarting all systems in D3
2108 *
2109 */
2110
2111 static int Init_old_screen_mode;
2112 static void (*Init_old_ui_callback)() = NULL;
2113 static bool Init_old_control_mode;
2114 static bool Init_ui_cursor_visible;
2115 static bool Init_was_game_paused = false;
2116 static pilot Init_old_pilot;
2117
2118 // TODO: MTS: Unused in project
2119 void ShutdownD3() {
2120 if (!Init_systems_init)
2121 return;
2122
2123 mprintf(0, "Shutting down D3...\n");
2124
2125 // Close forcefeedback effects
2126 ForceShutdown();
2127
2128 // shutdown game systems
2129 Init_old_control_mode = Control_poll_flag;
2130
2131 // JEFF: only pause game if not in multi, so we can background process
2132 if (GetFunctionMode() == GAME_MODE) {
2133 if (!(Game_mode & GM_MULTI)) {
2134 Init_was_game_paused = Game_paused;
2135 if (!Init_was_game_paused) {
2136 PauseGame();
2137 } else {
2138 D3MusicPause();
2139 }
2140 }
2141 } else {
2142 D3MusicPause();
2143 Sound_system.PauseSounds();
2144 }
2145
2146 SaveControlConfig(&Init_old_pilot);
2147 CloseControls();
2148
2149 // shutdown cinematics.
2150
2151 // shutdown screen.
2152 Init_ui_cursor_visible = ui_IsCursorVisible();
2153 Init_old_screen_mode = GetScreenMode();
2154 Init_old_ui_callback = GetUICallback();
2155 SetScreenMode(SM_NULL);
2156 ddvid_Close();
2157
2158 // shutdown IO
2159 ddio_Close();
2160 }
2161
2162 // TODO: MTS: unused in project
2163 // This function restarts all game systems
2164 void RestartD3() {
2165 ddio_init_info io_info;
2166
2167 if (!Init_systems_init)
2168 return;
2169
2170 mprintf(0, "Restarting D3...\n");
2171
2172 if (!FindArg("-windowed")) {
2173 if (Dedicated_server) {
2174 ddio_MouseMode(MOUSE_STANDARD_MODE);
2175 } else {
2176 ddio_MouseMode(MOUSE_EXCLUSIVE_MODE);
2177 }
2178 }
2179
2180 // startup io
2181 io_info.obj = Descent;
2182 io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0);
2183 io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
2184 if (!ddio_Init(&io_info)) {
2185 Error("I/O initialization failed.");
2186 }
2187
2188 // startup screen.
2189 ddvid_Init(Descent, App_ddvid_subsystem);
2190 ddio_KeyFlush();
2191 SetScreenMode(Init_old_screen_mode);
2192 SetUICallback(Init_old_ui_callback);
2193 if (Init_ui_cursor_visible)
2194 ui_ShowCursor();
2195
2196 // startup game systems
2197 InitControls();
2198 LoadControlConfig(&Init_old_pilot);
2199
2200 // resume game sounds and time as needed
2201 if (GetFunctionMode() == GAME_MODE) {
2202 if (!(Game_mode & GM_MULTI)) {
2203 if (!Init_was_game_paused) {
2204 ResumeGame();
2205 } else {
2206 D3MusicResume();
2207 }
2208 }
2209 } else {
2210 Sound_system.ResumeSounds();
2211 D3MusicResume();
2212 }
2213
2214 // resume controller if it was active before alt-tabbing out.
2215 if (Init_old_control_mode) {
2216 ResumeControls();
2217 }
2218
2219 // Restart Force Feedback
2220 ForceRestart();
2221
2222 // startup cinematics.
2223
2224 // startup sound.
2225 // Sound_system.ResumeSounds();
2226 // Sound_system.InitSoundLib(Descent, Sound_mixer, Sound_quality, false);
2227 }