| 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/GameLoop.cpp $ |
| 21 | * $Revision: 400 $ |
| 22 | * $Date: 4/19/00 5:10p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Main loop for Descent 3 |
| 26 | * |
| 27 | * $Log: /DescentIII/main/GameLoop.cpp $ |
| 28 | * |
| 29 | * 400 4/19/00 5:10p Matt |
| 30 | * From Duane for 1.4 |
| 31 | * Added checks, asserts, and fixes for bad return values |
| 32 | * Mac key code change (KEY_PAGEDOWN) |
| 33 | * |
| 34 | * 399 4/06/00 9:25a Matt |
| 35 | * Fixed a screen clear problem on at ATI Rage Fury Maxx in dual-chip mode |
| 36 | * by forcing the screen to clear four times (instead of three). |
| 37 | * |
| 38 | * 398 3/30/00 11:48a Jeff |
| 39 | * an ivibe call was nestled in a DEBUG block |
| 40 | * |
| 41 | * 397 3/29/00 2:24p Jeff |
| 42 | * moved call to vibe_quarterframe before rendering |
| 43 | * |
| 44 | * 396 3/20/00 12:08p Matt |
| 45 | * Merge of Duane's post-1.3 changes. |
| 46 | * Made PageDown key pause on Mac (Mac only) |
| 47 | * |
| 48 | * 395 1/27/00 12:04p Jeff |
| 49 | * updated IntelliVIBE to match new specs |
| 50 | * |
| 51 | * 394 1/26/00 9:20p Jeff |
| 52 | * added support for IntelliVIBE DLL |
| 53 | * |
| 54 | * 393 10/24/99 9:34a Chris |
| 55 | * |
| 56 | * 392 10/22/99 6:04p Jeff |
| 57 | * fixed bugs and compiler errors resulting from mac code merge |
| 58 | * |
| 59 | * 391 10/22/99 1:26p Matt |
| 60 | * Mac merge |
| 61 | * |
| 62 | * 390 10/15/99 5:56p 3dsmax |
| 63 | * In terrain sound system, treat heights above 255 as 255. |
| 64 | * |
| 65 | * 389 9/20/99 5:30p Jeff |
| 66 | * added pretty powerup particles for Katmai systems |
| 67 | * |
| 68 | * 388 8/31/99 5:30p Jason |
| 69 | * network statistics code |
| 70 | * |
| 71 | * 387 7/26/99 1:17p Jeff |
| 72 | * need to call startframe/endframe for renderstats |
| 73 | * |
| 74 | * 386 7/22/99 8:59p Jeff |
| 75 | * added texture upload for render stats |
| 76 | * |
| 77 | * 385 7/20/99 1:18p Samir |
| 78 | * save state of rearviews between game through the pilot file. |
| 79 | * |
| 80 | * 384 7/15/99 6:39p Jeff |
| 81 | * added outlinemode cheat code and rendering stats cheat |
| 82 | * |
| 83 | * 383 7/13/99 10:02a Jeff |
| 84 | * call mulitplayer event to translate text taunts |
| 85 | * |
| 86 | * 382 5/23/99 3:04a Jason |
| 87 | * fixed bug with player rankings not being updated correctly |
| 88 | * |
| 89 | * 381 5/23/99 12:35a Chris |
| 90 | * FVI check now ignores rendered portals |
| 91 | * |
| 92 | * 380 5/21/99 5:08a Chris |
| 93 | * Corrected the Region Vis mprintf |
| 94 | * |
| 95 | * 379 5/20/99 10:10p Samir |
| 96 | * don't allow certain keys for death (like savegame, guidebot, markers). |
| 97 | * |
| 98 | * 378 5/17/99 6:06p Chris |
| 99 | * Adding robot debug code |
| 100 | * |
| 101 | * 377 5/12/99 1:18p Samir |
| 102 | * play music during game too when in menus. |
| 103 | * |
| 104 | * 376 5/11/99 10:58a Kevin |
| 105 | * Added del-PAD_7 to kill off all robots of a certain type (the first |
| 106 | * type found) |
| 107 | * |
| 108 | * 375 5/10/99 10:22p Ardussi |
| 109 | * changes to compile on Mac |
| 110 | * |
| 111 | * 374 5/10/99 5:40p Jeff |
| 112 | * no saving during a cinematic |
| 113 | * |
| 114 | * 373 5/09/99 10:07p Jeff |
| 115 | * added guidebot shortcuts |
| 116 | * |
| 117 | * 372 5/09/99 3:07p Jason |
| 118 | * added a way to track FVI rays |
| 119 | * |
| 120 | * 371 5/07/99 6:21p Jeff |
| 121 | * hooked up fvi to debug graph |
| 122 | * |
| 123 | * 370 5/05/99 5:45p Samir |
| 124 | * fixed DEL-F10 player ship change. |
| 125 | * |
| 126 | * 369 5/04/99 9:26p Jeff |
| 127 | * debug key to turn off spewers |
| 128 | * |
| 129 | * 368 5/01/99 4:59p Jason |
| 130 | * made rearview work correctly |
| 131 | * |
| 132 | * 367 4/30/99 12:02p Matt |
| 133 | * Keep the rear view up between levels, but close the other camera views. |
| 134 | * |
| 135 | * 366 4/25/99 6:14p Kevin |
| 136 | * added "-timetest file.dem" to behave like gamegauge does |
| 137 | * |
| 138 | * 365 4/24/99 8:43p Samir |
| 139 | * when shrinking screen hud messages get rendered in black region. |
| 140 | * |
| 141 | * 364 4/24/99 7:22p Jason |
| 142 | * fixed respawn problem |
| 143 | * |
| 144 | * 363 4/21/99 11:05a Kevin |
| 145 | * new ps_rand and ps_srand to replace rand & srand |
| 146 | * |
| 147 | * 362 4/20/99 11:45a Samir |
| 148 | * added autosave |
| 149 | * |
| 150 | * 361 4/16/99 6:02p Jason |
| 151 | * fixed crash bugs with dev release |
| 152 | * |
| 153 | * 360 4/16/99 6:00p Kevin |
| 154 | * Bunches of Demo stuff |
| 155 | * |
| 156 | * 359 4/16/99 12:04p Jason |
| 157 | * fixed players respawning too fast |
| 158 | * |
| 159 | * 358 4/15/99 11:58p Jeff |
| 160 | * include soar.h to make Linux happy |
| 161 | * |
| 162 | * 357 4/15/99 1:39a Jeff |
| 163 | * changes for linux compile |
| 164 | * |
| 165 | * 356 4/14/99 2:50a Jeff |
| 166 | * fixed some case mismatched #includes |
| 167 | * |
| 168 | * 355 4/12/99 7:14p Samir |
| 169 | * added multiple pages per mono window. |
| 170 | * |
| 171 | * 354 4/12/99 1:13a Matt |
| 172 | * Added guidebot view to small windows (& simplified code to set marker |
| 173 | * views). |
| 174 | * |
| 175 | * 353 4/10/99 5:56p Matt |
| 176 | * Cleaned up object initialization code, including create object & load |
| 177 | * object. |
| 178 | * |
| 179 | * 352 4/07/99 12:30p Matt |
| 180 | * Added code for failed missions. |
| 181 | * |
| 182 | * 351 4/04/99 8:15p Jeff |
| 183 | * added debug graph stuff |
| 184 | * |
| 185 | * 350 4/02/99 11:33p Jeff |
| 186 | * able to turn off IGC in debug mode. Better handling of cinematics |
| 187 | * quick exit if playing via alt-p |
| 188 | * |
| 189 | * 349 3/27/99 4:45p Samir |
| 190 | * reinstate pause music when pausing game. |
| 191 | * |
| 192 | * 348 3/23/99 9:07p Samir |
| 193 | * turn on and off music when pausing and resuming game, if appropriate. |
| 194 | * |
| 195 | * 347 3/23/99 2:50p Samir |
| 196 | * made HUD_disabled available to all builds. |
| 197 | * |
| 198 | * 346 3/22/99 4:26p Samir |
| 199 | * added toggles for guided missile view and reticle. |
| 200 | * |
| 201 | * 345 3/08/99 9:07p Samir |
| 202 | * dont flush controller if object doesn't exist. |
| 203 | * |
| 204 | * 344 3/08/99 5:13p Jason |
| 205 | * added delay to player respawn after death |
| 206 | * |
| 207 | * 343 3/05/99 5:23p Jason |
| 208 | * fixed text taunts to actually work |
| 209 | * |
| 210 | * 342 3/05/99 1:34p Jeff |
| 211 | * don't allow saving/loading of games during cinematics |
| 212 | * |
| 213 | * 341 3/04/99 4:56p Jason |
| 214 | * moved function call to correct spot |
| 215 | * |
| 216 | * 340 3/04/99 4:53p Jason |
| 217 | * added LOD manipulation function calls |
| 218 | * |
| 219 | * 339 3/02/99 9:37p Matt |
| 220 | * In all-weapons cheat, give the player the max ammo for each weapon, |
| 221 | * instead of 5000. This means that non-ammo weapons won't get ammo. |
| 222 | * |
| 223 | * 338 3/02/99 6:39p Jeff |
| 224 | * level goals working in save/load game |
| 225 | * |
| 226 | * 337 3/02/99 2:50p Samir |
| 227 | * hud observer mode works with rest of hud. |
| 228 | * |
| 229 | * 336 3/01/99 4:17p Jeff |
| 230 | * added net flag whether buddy bot allowed |
| 231 | * |
| 232 | * 335 3/01/99 12:23a Samir |
| 233 | * reset return value for DLL upon going into CallGameDLL with key event |
| 234 | * (at the request of Jeff). |
| 235 | * |
| 236 | * 334 2/24/99 12:25p Jeff |
| 237 | * fixed guided missile/mass driver reticle/view problems when going into |
| 238 | * a cinematic |
| 239 | * |
| 240 | * 333 2/21/99 12:28p Matt |
| 241 | * Added terrain sound system |
| 242 | * |
| 243 | * 332 2/18/99 10:29a Jason |
| 244 | * fixed zbuffer problem |
| 245 | * |
| 246 | * 331 2/17/99 12:38p Kevin |
| 247 | * Added -framecap <fps> to limit frame and fixed timer bug and old |
| 248 | * framerate limiter code. |
| 249 | * |
| 250 | * 330 2/16/99 5:24p Kevin |
| 251 | * Converted timer to use 64bit int. |
| 252 | * |
| 253 | * 329 2/15/99 7:49p Jeff |
| 254 | * new pilot file class and read/write system checked in...should be more |
| 255 | * robust than old |
| 256 | * |
| 257 | * 328 2/13/99 12:31a Jeff |
| 258 | * debug key fixups (now in alphabetical order) |
| 259 | * |
| 260 | * 327 2/12/99 6:47p Jeff |
| 261 | * removed tilde as telcom key |
| 262 | * |
| 263 | * 326 2/12/99 3:54a Jeff |
| 264 | * added function to restart a level, and a cheat key to do so (del-alt-e) |
| 265 | * |
| 266 | * 325 2/10/99 6:55p Jeff |
| 267 | * added proxmines to the game |
| 268 | * |
| 269 | * 324 2/10/99 2:41p Chris |
| 270 | * Added debug info |
| 271 | * |
| 272 | * 323 2/09/99 12:09p Jason |
| 273 | * rewriting indoor engine... |
| 274 | * |
| 275 | * 322 2/09/99 9:58a Chris |
| 276 | * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy |
| 277 | * now. |
| 278 | * |
| 279 | * 321 2/09/99 1:29a Jeff |
| 280 | * added code to let D3 process multiplayer games in the background if |
| 281 | * game is not in focus. |
| 282 | * |
| 283 | * 320 2/08/99 6:39p Jason |
| 284 | * first pass at new indoor engine |
| 285 | * |
| 286 | * 319 2/05/99 7:23p Kevin |
| 287 | * OEM Changes |
| 288 | * |
| 289 | * 318 1/31/99 8:48p Jeff |
| 290 | * new in game cinematics system finished |
| 291 | * |
| 292 | * 317 1/31/99 7:25p Matt |
| 293 | * Renamed a bunch of functions to have HUD capitalized |
| 294 | * |
| 295 | * 316 1/31/99 3:44p Matt |
| 296 | * Streamlined game sequencing |
| 297 | * |
| 298 | * 315 1/30/99 4:42p Jeff |
| 299 | * changed keys for telcom |
| 300 | * |
| 301 | * 314 1/29/99 6:29p Jason |
| 302 | * first pass at adding bumpmaps |
| 303 | * |
| 304 | * 313 1/29/99 6:29p Samir |
| 305 | * implemented hud scrollback for hud messages. |
| 306 | * |
| 307 | * 312 1/28/99 6:17p Jason |
| 308 | * added markers |
| 309 | * |
| 310 | * 311 1/28/99 2:22p Samir |
| 311 | * simplified music system for D3. |
| 312 | * |
| 313 | * 310 1/28/99 11:32a Jason |
| 314 | * added marker cameras |
| 315 | * |
| 316 | * 309 1/27/99 6:54p Keneta |
| 317 | * fixed merge problwm |
| 318 | * |
| 319 | * 308 1/27/99 6:08p Jason |
| 320 | * first pass at markers |
| 321 | * |
| 322 | * 307 1/27/99 6:05p Samir |
| 323 | * added scrollback for game messages on HUD. |
| 324 | * |
| 325 | * 306 1/27/99 6:02p Jeff |
| 326 | * test keys for audio taunts |
| 327 | * |
| 328 | * 305 1/22/99 5:15p Jeff |
| 329 | * added a key to toggle osiris debug messages |
| 330 | * |
| 331 | * 304 1/22/99 4:06p Jeff |
| 332 | * added hud messages that can be sent to just teammates or individual |
| 333 | * people |
| 334 | * |
| 335 | * 303 1/21/99 7:02p Jason |
| 336 | * took out liquid effect from key c |
| 337 | * |
| 338 | * 302 1/21/99 3:34p Jason |
| 339 | * added liquid code |
| 340 | * |
| 341 | * 301 1/20/99 3:45a Jeff |
| 342 | * added call to update any in-game cinematics (boss introduction |
| 343 | * cinematics) |
| 344 | * |
| 345 | * 300 1/19/99 11:25a Jason |
| 346 | * added room (fog and wind) changing functions |
| 347 | * |
| 348 | * 299 1/15/99 7:52p Chris |
| 349 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 350 | * |
| 351 | * 298 1/15/99 7:16p Kevin |
| 352 | * Added GameGauge Configuration & code |
| 353 | * |
| 354 | * 297 1/13/99 12:43p Jason |
| 355 | * fixed flickering exit menu screen |
| 356 | * |
| 357 | * 296 1/11/99 4:08p Jason |
| 358 | * added multiplayer taunt macros |
| 359 | * |
| 360 | * 295 1/08/99 2:55p Samir |
| 361 | * Ripped out OSIRIS1. |
| 362 | * |
| 363 | * 294 1/04/99 12:48p Jason |
| 364 | * fixed clear screen problems with triple buffer |
| 365 | * |
| 366 | * 293 12/21/98 9:44a Chris |
| 367 | * Ambient life stuff is all tied in to game sequencing |
| 368 | * |
| 369 | * 292 12/18/98 10:42a Jeff |
| 370 | * call to process osiris's timers added in GameFrame |
| 371 | * |
| 372 | * 291 12/17/98 12:08p Jeff |
| 373 | * first checkin of new implementation of OSIRIS (old OSIRIS no longer |
| 374 | * works) |
| 375 | * |
| 376 | * 290 12/16/98 12:04p Kevin |
| 377 | * GameSpy! |
| 378 | * |
| 379 | * 289 12/15/98 6:41p Jason |
| 380 | * took out mprintf |
| 381 | * |
| 382 | * 288 12/07/98 11:30a Kevin |
| 383 | * Added some features from the 1.1 demo patch |
| 384 | * |
| 385 | * 287 12/07/98 10:35a Jason |
| 386 | * added adjustable FOV |
| 387 | * |
| 388 | * 286 12/01/98 3:34p Matt |
| 389 | * Got rear view working. |
| 390 | * |
| 391 | * 285 11/24/98 3:57p Kevin |
| 392 | * Demo system immprovements |
| 393 | * |
| 394 | * 284 11/24/98 10:41a Kevin |
| 395 | * Demo system |
| 396 | * |
| 397 | * 283 11/23/98 4:52p Kevin |
| 398 | * Demo system enhancments |
| 399 | * |
| 400 | * 282 11/19/98 5:40p Kevin |
| 401 | * Demo system |
| 402 | * |
| 403 | * 281 11/19/98 12:43p Samir |
| 404 | * added functions to start ui menu immediately without using |
| 405 | * Game_interface_mode |
| 406 | * |
| 407 | * 280 11/18/98 2:54p Jason |
| 408 | * added snow effect |
| 409 | * |
| 410 | * 279 11/16/98 4:15p Samir |
| 411 | * added death. |
| 412 | * |
| 413 | * 278 11/13/98 2:28p Samir |
| 414 | * new music system. |
| 415 | * |
| 416 | * 276 11/10/98 5:18p Jeff |
| 417 | * removed force feedback test keys |
| 418 | * |
| 419 | * 275 11/09/98 3:08p Kevin |
| 420 | * Added demo code |
| 421 | * |
| 422 | * 274 11/06/98 7:00p Jeff |
| 423 | * first round of new force feedback installed |
| 424 | * |
| 425 | * 273 11/05/98 7:35p Samir |
| 426 | * StartTime function altered to return if timer paused == 0;. |
| 427 | * |
| 428 | * 272 11/05/98 5:54p Kevin |
| 429 | * Demo system work |
| 430 | * |
| 431 | * 271 11/03/98 6:43p Jeff |
| 432 | * new low-level & high level Force Feedback system implemented, handles |
| 433 | * window losing focus, etc. |
| 434 | * |
| 435 | * 270 10/29/98 11:08a Samir |
| 436 | * don't allow sizing of letterbox screens. |
| 437 | * |
| 438 | * 269 10/24/98 2:16p Samir |
| 439 | * processbuttons doesn't call lowlevel input code anymore. |
| 440 | * |
| 441 | * 268 10/21/98 11:14a Samir |
| 442 | * added generic code to skip rendering while in game controller config or |
| 443 | * telcom. |
| 444 | * |
| 445 | * 267 10/20/98 12:42p Matt |
| 446 | * Made the small views work on the cockpit. |
| 447 | * |
| 448 | * 266 10/19/98 7:51p Kevin |
| 449 | * performance testing |
| 450 | * |
| 451 | * 265 10/19/98 7:18p Matt |
| 452 | * Added system to support different types of damage to the player and |
| 453 | * have these different types make different sounds. |
| 454 | * |
| 455 | * 264 10/19/98 2:48p Jeff |
| 456 | * changed define for rtp performance...just define USE_RTP in |
| 457 | * rtperformance.h in order to enable it |
| 458 | * |
| 459 | * 263 10/19/98 1:10p Kevin |
| 460 | * Took demo recording out of demo build |
| 461 | * |
| 462 | * 262 10/19/98 11:57a Chris |
| 463 | * Update the sound system to use the import volume |
| 464 | * |
| 465 | * 261 10/18/98 7:26p Samir |
| 466 | * added ability to poll mouse and joystick for input in death screen. |
| 467 | * clear screen when toggling console screen. |
| 468 | * |
| 469 | * 260 10/17/98 5:50p Jeff |
| 470 | * hooked in rtperformance (run time performance) library |
| 471 | * |
| 472 | * 259 10/17/98 12:46p Kevin |
| 473 | * Beta 4 fixes |
| 474 | * |
| 475 | * 258 10/16/98 3:39p Chris |
| 476 | * Improved the object linking system and AI and physics |
| 477 | * |
| 478 | * 257 10/16/98 2:44p Kevin |
| 479 | * working on getting demo compiling |
| 480 | * |
| 481 | * 256 10/16/98 2:24p Jason |
| 482 | * changes for the demo |
| 483 | * |
| 484 | * 255 10/16/98 12:44a Jeff |
| 485 | * created frametime info log stuff |
| 486 | * |
| 487 | * 254 10/15/98 8:19p Samir |
| 488 | * damn stupid bug when growing window. |
| 489 | * |
| 490 | * 253 10/14/98 6:41p Samir |
| 491 | * if in UI system, clear screen every frame to prevent hall of mirrors. |
| 492 | * |
| 493 | * 252 10/14/98 4:27p Samir |
| 494 | * must press spacebar to quit death. |
| 495 | * |
| 496 | * 251 10/12/98 10:16a Matt |
| 497 | * Took out D3XDebugIO() call. which didn't really do anything, so I could |
| 498 | * use the backquote key elsewhere. |
| 499 | * |
| 500 | * 250 10/11/98 3:00a Jeff |
| 501 | * TelCom now calls GameFrame() if it's being run in multiplayer, so calls |
| 502 | * were put into GameFrame to handle certain cases when it's in TelCom |
| 503 | * |
| 504 | * 249 10/09/98 12:22p Jeff |
| 505 | * DemoCheats() |
| 506 | * |
| 507 | * 248 10/08/98 3:38p Jeff |
| 508 | * DEL-E doesn't work in multiplayer games |
| 509 | * |
| 510 | * 247 10/08/98 3:12p Matt |
| 511 | * Fixed toggle outline key, and added key to turn on all outline options. |
| 512 | * |
| 513 | * 246 10/06/98 5:45p Kevin |
| 514 | * Added new configuration for demo |
| 515 | * |
| 516 | * 245 10/06/98 3:07p Jeff |
| 517 | * fixed del-x cheat code so it adds counter measures right |
| 518 | * |
| 519 | * 244 10/06/98 2:59p Jason |
| 520 | * added timedemo function |
| 521 | * |
| 522 | * 243 10/05/98 7:23p Jason |
| 523 | * implemented destroyable lights (first draft) |
| 524 | * |
| 525 | * 242 10/05/98 12:09p Kevin |
| 526 | * Converted projects to VC6 and demo file stuff added |
| 527 | * |
| 528 | * 241 10/05/98 11:08a Jason |
| 529 | * implemented player message log |
| 530 | * |
| 531 | * 238 9/29/98 10:44a Jeff |
| 532 | * renamed gunbouy to gunboy |
| 533 | * |
| 534 | * 237 9/25/98 4:50p Jeff |
| 535 | * |
| 536 | * 236 9/24/98 12:57p Jason |
| 537 | * more state limited optimizations |
| 538 | * |
| 539 | * 235 9/22/98 12:40p Matt |
| 540 | * Cleaned up the object per-frame processing code. |
| 541 | * |
| 542 | * 234 9/21/98 11:10a Jeff |
| 543 | * Calls to init/close forcefeedback |
| 544 | * |
| 545 | * 233 9/18/98 7:38p Jeff |
| 546 | * |
| 547 | * 232 9/18/98 1:27p Jason |
| 548 | * cleaned up renderer initting |
| 549 | * |
| 550 | * 231 9/17/98 3:03p Jason |
| 551 | * added lightning and invul hit effects |
| 552 | * |
| 553 | * 229 9/16/98 5:38p Jason |
| 554 | * made dedicated server bail on key events |
| 555 | * |
| 556 | * 228 9/16/98 5:10p Jason |
| 557 | * added first pass at thrid-person camera system |
| 558 | * |
| 559 | * 227 9/14/98 6:28p Jason |
| 560 | * first pass at getting dedicated server working |
| 561 | * |
| 562 | * 226 9/10/98 12:01p Chris |
| 563 | * Made matcen:DoRenderFrame() functional |
| 564 | * |
| 565 | * 225 9/08/98 4:56p Chris |
| 566 | * Matcens rev.5 almost functional |
| 567 | * |
| 568 | * 224 9/03/98 12:11p Chris |
| 569 | * Adding matcen support |
| 570 | * |
| 571 | * 223 9/01/98 4:11p Samir |
| 572 | * moved screenshot code from gameloop to game.cpp |
| 573 | * |
| 574 | * 222 8/31/98 6:50p Jeff |
| 575 | * made inventory and countermeasure keys customizable |
| 576 | * |
| 577 | * 221 8/31/98 5:44p Matt |
| 578 | * Added a key (Del-N) to restart a level |
| 579 | * |
| 580 | * 220 8/26/98 4:30p Jason |
| 581 | * added directional lights (headlight for player) |
| 582 | * |
| 583 | * 219 8/25/98 11:27p Matt |
| 584 | * Added key to toggle fog. |
| 585 | * |
| 586 | * 218 8/25/98 3:08p Samir |
| 587 | * Del-F10 does ship (and cockpit) transitions. |
| 588 | * |
| 589 | * 217 8/25/98 1:40p Jason |
| 590 | * fixed message bug |
| 591 | * |
| 592 | * 216 8/25/98 12:36p Jason |
| 593 | * added specular debug key |
| 594 | * |
| 595 | * 215 8/24/98 6:07p Samir |
| 596 | * change cockpits with ships. |
| 597 | * |
| 598 | * 214 8/24/98 10:40a Jason |
| 599 | * fixed some rendering problems |
| 600 | * |
| 601 | * 213 8/18/98 5:54p Jeff |
| 602 | * added countermeasures and afterburner when you DEL-X |
| 603 | * |
| 604 | * 212 8/18/98 3:02p Samir |
| 605 | * added game saving and loading. |
| 606 | * |
| 607 | * 211 8/17/98 6:40p Matt |
| 608 | * Added ambient sound system |
| 609 | * |
| 610 | * 210 8/16/98 12:20a Jeff |
| 611 | * moved out actual energy->shields to player function...keypress still |
| 612 | * handled here though |
| 613 | * |
| 614 | * 209 8/15/98 11:23p Matt |
| 615 | * Re-added keyboard flush when the game dll is swallowing keys. |
| 616 | * |
| 617 | * 208 8/15/98 10:53p Matt |
| 618 | * Rewrote key handling routines to deal with keys pressed while dead, and |
| 619 | * to generally clean things up a bit. |
| 620 | * |
| 621 | * 207 8/15/98 5:16p Matt |
| 622 | * Added new Base_directory variable. Got rid of D3_LOCAL check and |
| 623 | * 'local directory' registry variable. |
| 624 | * |
| 625 | * 206 8/14/98 5:28p Jeff |
| 626 | * test key added |
| 627 | * |
| 628 | * 205 8/14/98 4:57p Jeff |
| 629 | * |
| 630 | * 204 8/13/98 7:23p Jeff |
| 631 | * moved in UI system |
| 632 | * |
| 633 | * 203 8/13/98 3:10p Jeff |
| 634 | * keyflush if multiplayer dll requests so |
| 635 | * |
| 636 | * 202 8/12/98 2:54p Matt |
| 637 | * Renamed the slash and backslash key constants. |
| 638 | * |
| 639 | * 201 8/10/98 5:51p Samir |
| 640 | * new keys for music system. |
| 641 | * |
| 642 | * 200 8/10/98 12:16p Chris |
| 643 | * Added AI_NumHostileAlert |
| 644 | * |
| 645 | * 199 8/07/98 7:12p Samir |
| 646 | * changed d3xexecscript. |
| 647 | * |
| 648 | * 198 8/04/98 10:26a Kevin |
| 649 | * Custom sound and bmp exchange system |
| 650 | * |
| 651 | * 197 7/28/98 5:40p Samir |
| 652 | * added call to music system per frame. |
| 653 | * |
| 654 | * 196 7/27/98 5:59p Jason |
| 655 | * added piggyback mode plus multiplayer colors |
| 656 | * |
| 657 | * 195 7/24/98 5:30p Samir |
| 658 | * took out extranneous stream cheats. |
| 659 | * |
| 660 | * 194 7/24/98 4:45p Jason |
| 661 | * added notification if any subsystem takes more than .2 seconds to |
| 662 | * execute |
| 663 | * |
| 664 | * 193 7/23/98 11:43a Jeff |
| 665 | * fixed observer mode bug |
| 666 | * |
| 667 | * 192 7/22/98 3:16p Jason |
| 668 | * added observer mode |
| 669 | * |
| 670 | * 191 7/21/98 10:25a Kevin |
| 671 | * commented out heapcheck |
| 672 | * |
| 673 | * 190 7/20/98 7:00p Sean |
| 674 | * SOMEONE: Added a heapcheck call |
| 675 | * |
| 676 | * 189 7/09/98 8:33p Samir |
| 677 | * changes for new streaming interface. |
| 678 | * |
| 679 | * 188 7/08/98 6:00p Jeff |
| 680 | * handles inventory use in a multiplayer game |
| 681 | * |
| 682 | * 187 7/06/98 7:17p Jeff |
| 683 | * added keys for countermeasures (temporary...probably want these |
| 684 | * configurable) |
| 685 | * |
| 686 | * 186 6/30/98 6:36p Chris |
| 687 | * Added rev .1 of multiplayer animations - BTW It is totally not done. |
| 688 | * |
| 689 | * 185 6/30/98 6:14p Samir |
| 690 | * Call DoUIFrameWithoutInput instead of DoUIFrame. |
| 691 | * |
| 692 | * 184 6/25/98 5:22p Kevin |
| 693 | * Req/Send gametime to clients |
| 694 | * |
| 695 | * 183 6/25/98 12:42p Jeff |
| 696 | * Added exit game confirmation |
| 697 | * |
| 698 | * 182 6/24/98 5:59p Chris |
| 699 | * |
| 700 | * 181 6/24/98 5:55p Chris |
| 701 | * Added simple support for on the fly mixer/quality switching - Kills all |
| 702 | * sounds (which is incorrect). |
| 703 | * |
| 704 | * 180 6/24/98 5:20p Matt |
| 705 | * Added key for pause; Cleaned up key handling; ripped out some E3 demo |
| 706 | * code. |
| 707 | * |
| 708 | * 179 6/24/98 4:39p Chris |
| 709 | * Improved the multiple mixer support |
| 710 | * |
| 711 | * 178 6/24/98 12:09p Chris |
| 712 | * Update |
| 713 | * |
| 714 | * 177 6/24/98 11:12a Jeff |
| 715 | * fixed accidental checkin |
| 716 | * |
| 717 | * 176 6/24/98 11:14a Chris |
| 718 | * Added more support and bug fixes |
| 719 | * |
| 720 | * 175 6/22/98 12:00p Chris |
| 721 | * Working on sound system to make it in a nice shape. |
| 722 | * |
| 723 | * 174 6/19/98 6:42p Jason |
| 724 | * made specular mapping a config detail item |
| 725 | * |
| 726 | * 173 6/19/98 6:21p Chris |
| 727 | * Moved Del+F5 to DEL+F6 and F6 to Del+F11 |
| 728 | * |
| 729 | * 172 6/19/98 6:05p Jeff |
| 730 | * call to update voices to handle the voice queue |
| 731 | * |
| 732 | * 171 6/19/98 3:03p Chris |
| 733 | * Made CheckAndForceSoundDataAlloc a SoundSystem function - useful for |
| 734 | * multiple mixers. Added IsSoundPlaying to the high level sound lib. |
| 735 | * |
| 736 | * 170 6/18/98 5:21p Jeff |
| 737 | * put in call to update streaming audio buffers in the game loop |
| 738 | * |
| 739 | * 169 6/18/98 1:09p Chris |
| 740 | * |
| 741 | * 168 6/16/98 5:27p Chris |
| 742 | * Revision version 1.0 (should all be functional for 16 bit mono samples) |
| 743 | * |
| 744 | * 167 6/16/98 3:48p Chris |
| 745 | * Updated the sound system and added the start of sound streaming |
| 746 | * |
| 747 | * 166 6/16/98 10:38a Jeff |
| 748 | * localization, strings pulled out to stringtable.h and d3.str |
| 749 | * |
| 750 | * 165 6/04/98 4:52p Jeff |
| 751 | * Added a suspend/resume controls call on return from EVT_CLIENT_KEYPRESS |
| 752 | * if the DLL requests it |
| 753 | * |
| 754 | * 164 6/02/98 11:01a Jason |
| 755 | * Post E3 Checkin |
| 756 | * |
| 757 | * 163 6/01/98 11:00a Jeff |
| 758 | * Moved the call to the multiplayer EVT_CLIENT_KEYPRESS up in the |
| 759 | * function |
| 760 | * |
| 761 | * 162 5/27/98 12:35a Samir |
| 762 | * level restart for E3 by default on, this time. |
| 763 | * |
| 764 | * 161 5/26/98 10:51p Samir |
| 765 | * ability to activate/deactivate restart level sequence timer. |
| 766 | * |
| 767 | * |
| 768 | * 159 5/26/98 5:03p Samir |
| 769 | * Set E3 time limit for level to 15 minutes. |
| 770 | * |
| 771 | * 158 5/26/98 1:20p Samir |
| 772 | * added special weapons key for E3! |
| 773 | * |
| 774 | * 157 5/26/98 11:36a Matt |
| 775 | * Changed small view system to allow the popup window in any of the three |
| 776 | * positions, to allow any window to be the "bigger" size, and to restore |
| 777 | * the old view when a popup view goes away. |
| 778 | * |
| 779 | * 156 5/25/98 8:29p Samir |
| 780 | * Added E3_DEMO define for E3 stuff like game time limits and special |
| 781 | * keys. |
| 782 | * |
| 783 | * 155 5/25/98 3:46p Jason |
| 784 | * added better light glows |
| 785 | * |
| 786 | * 154 5/22/98 8:36p Samir |
| 787 | * added E3 keyboard lock to hide the not so cool looking stuff in D3 |
| 788 | * |
| 789 | * 153 5/22/98 3:27p Jason |
| 790 | * added specular lighting |
| 791 | * |
| 792 | * 152 5/19/98 10:44a Jeff |
| 793 | * changed D3_QUICK to D3_FAST |
| 794 | * |
| 795 | * 151 5/18/98 4:36p Jeff |
| 796 | * TelCom uses Game_interface_mode variable now |
| 797 | * |
| 798 | * $NoKeywords: $ |
| 799 | */ |
| 800 | |
| 801 | #include <stdlib.h> |
| 802 | #include <string.h> |
| 803 | #include <stdio.h> |
| 804 | #include "gameloop.h" |
| 805 | #include "game.h" |
| 806 | #include "render.h" |
| 807 | #include "descent.h" |
| 808 | #include "slew.h" |
| 809 | #include "mono.h" |
| 810 | #include "doorway.h" |
| 811 | #include "weapon.h" |
| 812 | #include "hlsoundlib.h" |
| 813 | #include "multi.h" |
| 814 | #include "player.h" |
| 815 | #include "damage.h" |
| 816 | #include "ship.h" |
| 817 | #include "objinit.h" |
| 818 | #include "gameevent.h" |
| 819 | #include "gametexture.h" |
| 820 | #include "AIMain.h" |
| 821 | #include "ddvid.h" |
| 822 | #include "ddio.h" |
| 823 | #include "hud.h" |
| 824 | #include "terrain.h" |
| 825 | #include "BOA.h" |
| 826 | #include "lighting.h" |
| 827 | #include "findintersection.h" |
| 828 | #include "soar.h" |
| 829 | #include "multi.h" |
| 830 | #include "hud.h" |
| 831 | #include "bsp.h" |
| 832 | #include "gauges.h" |
| 833 | #include "SmallViews.h" |
| 834 | #include "newui.h" |
| 835 | #include "Inventory.h" |
| 836 | #include "physics.h" |
| 837 | #include "Controller.h" |
| 838 | #include "controls.h" |
| 839 | #include "gamesequence.h" |
| 840 | #include "cockpit.h" |
| 841 | #include "help.h" |
| 842 | #include "game.h" |
| 843 | #include "aipath.h" |
| 844 | #include "game2dll.h" |
| 845 | #include "Mission.h" |
| 846 | #include "object_lighting.h" |
| 847 | #include "fireball.h" |
| 848 | #include "weather.h" |
| 849 | #include "stringtable.h" |
| 850 | #include "streamaudio.h" |
| 851 | #include "voice.h" |
| 852 | #include "soundload.h" |
| 853 | #include "sounds.h" |
| 854 | #include "ambient.h" |
| 855 | #include "ship.h" |
| 856 | #include "config.h" |
| 857 | #include "matcen.h" |
| 858 | #include "dedicated_server.h" |
| 859 | #include "D3ForceFeedback.h" |
| 860 | #include "levelgoal.h" |
| 861 | #include "demofile.h" |
| 862 | #include "pilot.h" |
| 863 | #include "rtperformance.h" |
| 864 | #include "demofile.h" |
| 865 | #include "d3music.h" |
| 866 | // #include "gamespy.h" |
| 867 | #include "osiris_dll.h" |
| 868 | #include "aiambient.h" |
| 869 | #include "marker.h" |
| 870 | #include "gamecinematics.h" |
| 871 | #include "postrender.h" |
| 872 | #include "debuggraph.h" |
| 873 | #include "gamesave.h" |
| 874 | #include "psrand.h" |
| 875 | #include "spew.h" |
| 876 | #include "grtext.h" |
| 877 | #include "gamefont.h" |
| 878 | #include "renderobject.h" |
| 879 | #include "buddymenu.h" |
| 880 | |
| 881 | #ifdef EDITOR |
| 882 | #include "editor\d3edit.h" |
| 883 | #endif |
| 884 | |
| 885 | extern bool Display_renderer_stats; |
| 886 | |
| 887 | // Current zoom factor (this is the tan of 29.25, which is half our FOV of 58.5) |
| 888 | float Render_FOV = D3_DEFAULT_FOV; |
| 889 | float Render_zoom = D3_DEFAULT_ZOOM; |
| 890 | |
| 891 | // How long (in seconds) the last frame took |
| 892 | float Frametime = .1f; |
| 893 | |
| 894 | // How long (in seconds) since the game started |
| 895 | float Gametime; |
| 896 | |
| 897 | int Timedemo_frame = -1; |
| 898 | |
| 899 | // How many frames have been renered. |
| 900 | // NOTE: this is a count of 3d frames, not game frames |
| 901 | int FrameCount = 0; |
| 902 | |
| 903 | bool HUD_disabled = 0; |
| 904 | #ifdef _DEBUG |
| 905 | int DoAI = 1; |
| 906 | bool System_locked = false; |
| 907 | int Stream_type = 0; |
| 908 | #else |
| 909 | int Stream_type = 0; |
| 910 | #define DoAI 1 |
| 911 | #endif |
| 912 | |
| 913 | bool Tracking_FVI = false; |
| 914 | |
| 915 | // Set this to force window clear |
| 916 | int Clear_screen = 0; |
| 917 | |
| 918 | // determines if game is paused. |
| 919 | bool Game_paused = false; |
| 920 | |
| 921 | // Used for limiting the framerate |
| 922 | int Min_allowed_frametime = 0; |
| 923 | |
| 924 | // determines if we're rendering the main view |
| 925 | bool Rendering_main_view = false; |
| 926 | bool Skip_render_game_frame = false; |
| 927 | bool Menu_interface_mode = false; |
| 928 | |
| 929 | int frames_one_second = 0; |
| 930 | int min_one_second = 0x7fffffff; |
| 931 | int max_one_second = 0; |
| 932 | |
| 933 | int64_t last_timer = 0; |
| 934 | |
| 935 | // contains information for the music system. |
| 936 | tMusicSeqInfo Game_music_info; |
| 937 | |
| 938 | // Defines for changing the window size |
| 939 | #define WINDOW_W_DELTA ((Max_window_w / 16) & ~1) |
| 940 | #define WINDOW_H_DELTA ((Max_window_h / 16) & ~1) |
| 941 | |
| 942 | #define WINDOW_MIN_W ((Max_window_w * 10) / 22) |
| 943 | #define WINDOW_MIN_H ((Max_window_h * 10) / 22) |
| 944 | |
| 945 | // Functions |
| 946 | void ApplyShadowsToRooms(); |
| 947 | void StartGameMenu(); |
| 948 | void EndGameMenu(); |
| 949 | void ProcessGuidebotKeys(int key); |
| 950 | |
| 951 | // Make the 3D window larger |
| 952 | void GrowWindow() { |
| 953 | if (GetHUDMode() == HUD_LETTERBOX) |
| 954 | return; |
| 955 | |
| 956 | Game_window_w += WINDOW_W_DELTA; |
| 957 | Game_window_h += WINDOW_H_DELTA; |
| 958 | |
| 959 | if (Game_window_h > Max_window_h) |
| 960 | Game_window_h = Max_window_h; |
| 961 | |
| 962 | if (Game_window_w > Max_window_w) |
| 963 | Game_window_w = Max_window_w; |
| 964 | |
| 965 | Game_window_x = (Max_window_w - Game_window_w) / 2; |
| 966 | Game_window_y = (Max_window_h - Game_window_h) / 2; |
| 967 | |
| 968 | Current_pilot.set_hud_data(NULL, NULL, NULL, &Game_window_w, &Game_window_h); |
| 969 | |
| 970 | Clear_screen = 4; |
| 971 | |
| 972 | ResizeCockpit(); |
| 973 | } |
| 974 | |
| 975 | // Make the 3D window smaller |
| 976 | void ShrinkWindow() { |
| 977 | if (GetHUDMode() == HUD_LETTERBOX) |
| 978 | return; |
| 979 | |
| 980 | if (Game_window_w > WINDOW_MIN_W) { |
| 981 | |
| 982 | Game_window_w -= WINDOW_W_DELTA; |
| 983 | Game_window_h -= WINDOW_H_DELTA; |
| 984 | |
| 985 | if (Game_window_w < WINDOW_MIN_W) |
| 986 | Game_window_w = WINDOW_MIN_W; |
| 987 | |
| 988 | if (Game_window_h < WINDOW_MIN_H) |
| 989 | Game_window_h = WINDOW_MIN_H; |
| 990 | |
| 991 | Game_window_x = (Max_window_w - Game_window_w) / 2; |
| 992 | Game_window_y = (Max_window_h - Game_window_h) / 2; |
| 993 | |
| 994 | Clear_screen = 4; |
| 995 | |
| 996 | ResizeCockpit(); |
| 997 | |
| 998 | Current_pilot.set_hud_data(NULL, NULL, NULL, &Game_window_w, &Game_window_h); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | // Data and code for camera views |
| 1003 | |
| 1004 | #define CV_NONE 0 // View not active |
| 1005 | #define CV_REARVIEW 1 // Rear view |
| 1006 | #define CV_MARKER1 2 // Marker view |
| 1007 | #define CV_MARKER2 3 // Marker view |
| 1008 | #define CV_MARKER3 4 // Marker view |
| 1009 | #define CV_MARKER4 5 // Marker view |
| 1010 | #define CV_MARKER5 6 // Marker view |
| 1011 | #define CV_MARKER6 7 // Marker view |
| 1012 | #define CV_MARKER7 8 // Last marker view |
| 1013 | #define CV_MARKER8 9 // Last marker view |
| 1014 | #define CV_GUIDEBOT 10 // Guide-Bot |
| 1015 | // #define CV_COOP 3 //View from a coop player |
| 1016 | |
| 1017 | #define NUM_CAMERA_VIEWS 3 |
| 1018 | |
| 1019 | int Camera_view_mode[NUM_CAMERA_VIEWS]; |
| 1020 | |
| 1021 | // Selects the next mode for this view |
| 1022 | void SelectNextCameraView(int window) { |
| 1023 | int current = Camera_view_mode[window]; |
| 1024 | |
| 1025 | // If the window has gone away because there's no object, then the current state is none |
| 1026 | if (GetSmallViewer(window) == OBJECT_HANDLE_NONE) |
| 1027 | current = CV_NONE; |
| 1028 | |
| 1029 | switch (current) { |
| 1030 | case CV_NONE: |
| 1031 | Camera_view_mode[window] = CV_REARVIEW; |
| 1032 | CreateSmallView(window, Player_object->handle, SVF_REARVIEW, 0.0, D3_DEFAULT_ZOOM, -1, TXT_VIEW_REAR); |
| 1033 | if (window == 0) |
| 1034 | Current_pilot.lrearview_enabled = true; // set to true. |
| 1035 | else if (window == 2) |
| 1036 | Current_pilot.rrearview_enabled = true; |
| 1037 | break; |
| 1038 | |
| 1039 | case CV_REARVIEW: { |
| 1040 | object *objp = ObjGet(Buddy_handle[Player_num]); |
| 1041 | if (window == 0) |
| 1042 | Current_pilot.lrearview_enabled = false; // leaving rearview |
| 1043 | else if (window == 2) |
| 1044 | Current_pilot.rrearview_enabled = false; |
| 1045 | |
| 1046 | if (objp && objp->type == OBJ_ROBOT) { // Not hidden |
| 1047 | Camera_view_mode[window] = CV_GUIDEBOT; |
| 1048 | CreateSmallView(window, objp->handle, 0, 0.0, D3_DEFAULT_ZOOM, -1, TXT_VIEW_GUIDEBOT); |
| 1049 | break; |
| 1050 | } |
| 1051 | // If no GB, then fall into next case |
| 1052 | } |
| 1053 | case CV_GUIDEBOT: |
| 1054 | case CV_MARKER1: |
| 1055 | case CV_MARKER2: |
| 1056 | case CV_MARKER3: |
| 1057 | case CV_MARKER4: |
| 1058 | case CV_MARKER5: |
| 1059 | case CV_MARKER6: |
| 1060 | case CV_MARKER7: |
| 1061 | case CV_MARKER8: { |
| 1062 | if (window == 0) |
| 1063 | Current_pilot.lrearview_enabled = false; // leaving rearview |
| 1064 | else if (window == 2) |
| 1065 | Current_pilot.rrearview_enabled = false; |
| 1066 | |
| 1067 | if (Players[Player_num].num_markers > 0) { |
| 1068 | int num = (current == CV_GUIDEBOT) ? 0 : (current - CV_MARKER1) + 1; |
| 1069 | int max = (Game_mode & GM_MULTI) ? 2 : 8; // Why no symbolic constants? Ask Jason. |
| 1070 | int id = Player_num * 2 + num; |
| 1071 | |
| 1072 | if (num < max) { |
| 1073 | int i; |
| 1074 | |
| 1075 | // Search for the marker |
| 1076 | for (i = 0; i <= Highest_object_index; i++) { |
| 1077 | if ((Objects[i].type == OBJ_MARKER) && (Objects[i].id == id)) |
| 1078 | break; |
| 1079 | } |
| 1080 | |
| 1081 | if (i <= Highest_object_index) { |
| 1082 | char buf[25]; |
| 1083 | snprintf(buf, sizeof(buf), TXT_VIEW_MARKER, num + 1); |
| 1084 | |
| 1085 | CreateSmallView(window, Objects[i].handle, 0, 0.0, D3_DEFAULT_ZOOM, -1, buf); |
| 1086 | Camera_view_mode[window] = CV_MARKER1 + num; |
| 1087 | |
| 1088 | break; |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | // If couldn't find marker or have cycled though all, close window |
| 1093 | Camera_view_mode[window] = CV_NONE; |
| 1094 | CloseSmallView(window); |
| 1095 | break; |
| 1096 | } |
| 1097 | default: |
| 1098 | Int3(); // all cases should be handled |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | // Turn off all camera views |
| 1103 | // If total reset is true, set all views to none, otherwise kill object view but keep rear views. |
| 1104 | void InitCameraViews(bool total_reset) { |
| 1105 | for (int i = 0; i < NUM_CAMERA_VIEWS; i++) { |
| 1106 | if (total_reset || (Camera_view_mode[i] != CV_REARVIEW)) { |
| 1107 | Camera_view_mode[i] = CV_NONE; |
| 1108 | } else { // is rear view, so keep it |
| 1109 | Camera_view_mode[i] = CV_REARVIEW; |
| 1110 | CreateSmallView(i, Player_object->handle, SVF_REARVIEW, 0.0, D3_DEFAULT_ZOOM, -1, TXT_VIEW_REAR); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | void RestoreCameraRearviews() { |
| 1116 | if (Camera_view_mode[0] != CV_REARVIEW) { |
| 1117 | if (Current_pilot.lrearview_enabled) { |
| 1118 | Camera_view_mode[0] = CV_REARVIEW; |
| 1119 | CreateSmallView(0, Player_object->handle, SVF_REARVIEW, 0.0, D3_DEFAULT_ZOOM, -1, TXT_VIEW_REAR); |
| 1120 | } |
| 1121 | } |
| 1122 | if (Camera_view_mode[2] != CV_REARVIEW) { |
| 1123 | if (Current_pilot.rrearview_enabled) { |
| 1124 | Camera_view_mode[2] = CV_REARVIEW; |
| 1125 | CreateSmallView(2, Player_object->handle, SVF_REARVIEW, 0.0, D3_DEFAULT_ZOOM, -1, TXT_VIEW_REAR); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | void ProcessButtons() { |
| 1131 | // If dead, any key not handled above will eand the death sequence |
| 1132 | // this shouldn't be called in ReadPlayerControls since the player is DEAD! |
| 1133 | if (Players[Player_num].flags & PLAYER_FLAGS_DEAD) { |
| 1134 | int x, y; |
| 1135 | PollControls(); |
| 1136 | if (Controller->get_joy_raw_values(&x, &y) || Controller->get_mouse_raw_values(&x, &y)) { |
| 1137 | // death. |
| 1138 | mprintf(0, "here?"); |
| 1139 | |
| 1140 | if (Total_time_dead < DEATH_RESPAWN_TIME) |
| 1141 | return; |
| 1142 | |
| 1143 | mprintf(0, "Respawning joystick death. Death time=%f\n", Total_time_dead); |
| 1144 | |
| 1145 | if (Game_mode & GM_MULTI) |
| 1146 | MultiSendEndPlayerDeath(); // couldn't this be called from withing EndPlayerDeath()? |
| 1147 | else |
| 1148 | EndPlayerDeath(Player_num); |
| 1149 | // Clear keyboard |
| 1150 | ResetPersistentHUDMessage(); |
| 1151 | ddio_KeyFlush(); |
| 1152 | if (Controller) { |
| 1153 | Controller->flush(); |
| 1154 | } |
| 1155 | } |
| 1156 | return; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | #define GBC_FIND_ACTIVE_GOAL_0 3 // Find next primary |
| 1161 | #define GBC_FIND_SPEW 19 // Find Spew |
| 1162 | #define GBC_FIND_POWERUP 20 // Find Powerup |
| 1163 | #define GBC_FIND_ENERGY_CENTER 21 // Find energy |
| 1164 | #define GBC_ESCORT_SHIP 35 // Escort Ship |
| 1165 | #define GBC_EXTINGUISH 36 // Use Extinguisher |
| 1166 | #define GBC_GO_WINGNUT 37 // Use Wingnut Powerup |
| 1167 | #define GBC_RTYPE 39 // Use Gaurdian Powerup |
| 1168 | #define GBC_ANTI_VIRUS 40 // Use Anti-virus Powerup |
| 1169 | #define GBC_RETURN_TO_SHIP 43 // Return to ship |
| 1170 | // Handles guidebot shortcut keys |
| 1171 | void ProcessGuidebotKeys(int key) { |
| 1172 | if (!(key & KEY_SHIFTED)) |
| 1173 | return; |
| 1174 | key &= ~KEY_SHIFTED; |
| 1175 | |
| 1176 | // check to make sure our Guidebot is out of the ship |
| 1177 | object *buddy = ObjGet(Buddy_handle[Player_num]); |
| 1178 | if (!buddy || buddy->type != OBJ_ROBOT) { |
| 1179 | // not out of the ship |
| 1180 | mprintf(0, "Guidebot: mrmph mmrump..mrmph...LET ME OUT OF YOUR SHIP!\n"); |
| 1181 | return; |
| 1182 | } |
| 1183 | int command_id = -1; |
| 1184 | |
| 1185 | switch (key) { |
| 1186 | case KEY_1: |
| 1187 | command_id = GBC_FIND_ACTIVE_GOAL_0; |
| 1188 | break; |
| 1189 | case KEY_2: |
| 1190 | command_id = GBC_FIND_SPEW; |
| 1191 | break; |
| 1192 | case KEY_3: |
| 1193 | command_id = GBC_FIND_POWERUP; |
| 1194 | break; |
| 1195 | case KEY_4: |
| 1196 | command_id = GBC_FIND_ENERGY_CENTER; |
| 1197 | break; |
| 1198 | case KEY_5: |
| 1199 | command_id = GBC_ESCORT_SHIP; |
| 1200 | break; |
| 1201 | case KEY_6: |
| 1202 | command_id = GBC_EXTINGUISH; |
| 1203 | break; |
| 1204 | case KEY_7: |
| 1205 | command_id = GBC_GO_WINGNUT; |
| 1206 | break; |
| 1207 | case KEY_8: |
| 1208 | command_id = GBC_RTYPE; |
| 1209 | break; |
| 1210 | case KEY_9: |
| 1211 | command_id = GBC_ANTI_VIRUS; |
| 1212 | break; |
| 1213 | case KEY_0: |
| 1214 | command_id = GBC_RETURN_TO_SHIP; |
| 1215 | break; |
| 1216 | default: |
| 1217 | // nope |
| 1218 | return; |
| 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | // Process the command |
| 1223 | gb_com command; |
| 1224 | command.action = COM_DO_ACTION; |
| 1225 | command.index = command_id; |
| 1226 | command.ptr = NULL; |
| 1227 | |
| 1228 | if ((!(Game_mode & GM_MULTI)) || (Netgame.local_role != LR_CLIENT)) { |
| 1229 | AINotify(buddy, AIN_USER_DEFINED, (void *)&command); |
| 1230 | } else { |
| 1231 | MultiSendGuidebotMenuSelection(&command); |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | // Deals with a normal (non-debug) key. Once the key is handled, this function returns |
| 1236 | |
| 1237 | void ProcessNormalKey(int key) { |
| 1238 | // First do keys that work normally even when dead |
| 1239 | switch (key) { |
| 1240 | |
| 1241 | // ingnore the modifier keys |
| 1242 | case KEY_LALT: |
| 1243 | case KEY_RALT: |
| 1244 | case KEY_LSHIFT: |
| 1245 | case KEY_RSHIFT: |
| 1246 | case KEY_LCTRL: |
| 1247 | case KEY_RCTRL: |
| 1248 | return; |
| 1249 | |
| 1250 | case KEY_ESC: |
| 1251 | Game_interface_mode = GAME_EXIT_CONFIRM; |
| 1252 | return; |
| 1253 | |
| 1254 | case KEY_PAUSE: |
| 1255 | Game_interface_mode = GAME_PAUSE_INTERFACE; |
| 1256 | return; |
| 1257 | |
| 1258 | case KEY_F1: |
| 1259 | Game_interface_mode = GAME_HELP_INTERFACE; |
| 1260 | return; |
| 1261 | |
| 1262 | case KEY_F2: |
| 1263 | Game_interface_mode = GAME_OPTIONS_INTERFACE; |
| 1264 | return; |
| 1265 | |
| 1266 | case KEY_F8: |
| 1267 | if (Game_mode & GM_MULTI) { |
| 1268 | StartHUDInputMessage(); |
| 1269 | return; |
| 1270 | } |
| 1271 | break; |
| 1272 | |
| 1273 | case KEY_SHIFTED + KEY_F8: |
| 1274 | ToggleGameMessageConsole(); |
| 1275 | Clear_screen = 4; |
| 1276 | break; |
| 1277 | |
| 1278 | case KEY_SHIFTED + KEY_F9: |
| 1279 | ToggleHUDMessageConsole(); |
| 1280 | Clear_screen = 4; // clears screen. |
| 1281 | break; |
| 1282 | |
| 1283 | // #ifndef DEMO |
| 1284 | case KEY_F5: |
| 1285 | Game_interface_mode = GAME_TOGGLE_DEMO; |
| 1286 | return; |
| 1287 | case KEY_ALTED + KEY_F5: |
| 1288 | DemoAbort(true); |
| 1289 | return; |
| 1290 | // #endif |
| 1291 | // case KEY_SHIFTED+KEY_LAPOSTRO: Game_interface_mode = GAME_TELCOM_CARGO;return; |
| 1292 | // case KEY_ALTED+KEY_LAPOSTRO: Game_interface_mode = GAME_TELCOM_BRIEFINGS; return; |
| 1293 | case KEY_SHIFTED + KEY_TAB: |
| 1294 | Game_interface_mode = GAME_TELCOM_BRIEFINGS; |
| 1295 | return; |
| 1296 | case KEY_ALTED + KEY_F3: |
| 1297 | if (!Cinematic_inuse) { |
| 1298 | Game_interface_mode = GAME_LOAD_INTERFACE; |
| 1299 | return; |
| 1300 | } |
| 1301 | break; |
| 1302 | |
| 1303 | case KEY_CTRLED + KEY_F8: |
| 1304 | if (Game_mode & GM_MULTI) { |
| 1305 | StartTeamHUDInputMessage(); |
| 1306 | return; |
| 1307 | } |
| 1308 | break; |
| 1309 | case KEY_CTRLED + KEY_1: |
| 1310 | case KEY_CTRLED + KEY_2: |
| 1311 | case KEY_CTRLED + KEY_3: |
| 1312 | case KEY_CTRLED + KEY_4: |
| 1313 | case KEY_CTRLED + KEY_5: |
| 1314 | case KEY_CTRLED + KEY_6: |
| 1315 | case KEY_CTRLED + KEY_7: |
| 1316 | case KEY_CTRLED + KEY_8: { |
| 1317 | int index = key & ~KEY_CTRLED; |
| 1318 | index = index - KEY_1; |
| 1319 | |
| 1320 | if (Game_mode & GM_MULTI) { |
| 1321 | char str[80]; |
| 1322 | |
| 1323 | mprintf(0, "Printing message %d!\n", index); |
| 1324 | |
| 1325 | int save_do = Doing_input_message; |
| 1326 | int save_len = HudInputMessageLen; |
| 1327 | strcpy(str, HudInputMessage); |
| 1328 | |
| 1329 | // strcpy (HudInputMessage,Current_pilot.taunts[index]); |
| 1330 | // decode the text macro by sending it off to the DLL |
| 1331 | // for processesing |
| 1332 | DLLInfo.input_string = Current_pilot.taunts[index]; |
| 1333 | DLLInfo.special_data = (uint8_t *)HudInputMessage; |
| 1334 | DLLInfo.iParam = MAX_HUD_INPUT_LEN; |
| 1335 | CallGameDLL(EVT_CLIENT_DECODETEXTMACRO, &DLLInfo); |
| 1336 | |
| 1337 | Doing_input_message = 1; |
| 1338 | SendOffHUDInputMessage(); |
| 1339 | strcpy(HudInputMessage, str); |
| 1340 | HudInputMessageLen = save_len; |
| 1341 | Doing_input_message = save_do; |
| 1342 | } |
| 1343 | |
| 1344 | break; |
| 1345 | } |
| 1346 | |
| 1347 | case KEY_PRINT_SCREEN: |
| 1348 | case KEY_SHIFTED + KEY_PRINT_SCREEN: |
| 1349 | mprintf(0, "Doing screenshot!\n"); |
| 1350 | DoScreenshot(); |
| 1351 | return; |
| 1352 | |
| 1353 | case KEY_SHIFTED + KEY_MINUS: |
| 1354 | case KEY_MINUS: |
| 1355 | ShrinkWindow(); |
| 1356 | return; |
| 1357 | |
| 1358 | case KEY_SHIFTED + KEY_EQUAL: |
| 1359 | case KEY_EQUAL: |
| 1360 | GrowWindow(); |
| 1361 | return; |
| 1362 | case KEY_SPACEBAR: |
| 1363 | if (Players[Player_num].flags & PLAYER_FLAGS_DEAD) { |
| 1364 | |
| 1365 | if (Total_time_dead < DEATH_RESPAWN_TIME) |
| 1366 | return; |
| 1367 | |
| 1368 | if (Game_mode & GM_MULTI) |
| 1369 | MultiSendEndPlayerDeath(); // couldn't this be called from withing EndPlayerDeath()? |
| 1370 | else |
| 1371 | EndPlayerDeath(Player_num); |
| 1372 | |
| 1373 | // Clear keyboard |
| 1374 | ResetPersistentHUDMessage(); |
| 1375 | ddio_KeyFlush(); |
| 1376 | if (Controller) { |
| 1377 | Controller->flush(); |
| 1378 | } |
| 1379 | |
| 1380 | return; |
| 1381 | } |
| 1382 | } |
| 1383 | if (Demo_flags == DF_PLAYBACK) { |
| 1384 | switch (key) { |
| 1385 | case KEY_C: { |
| 1386 | // goto next player |
| 1387 | int viewer_objnum = Viewer_object - Objects; |
| 1388 | int found = 0; |
| 1389 | |
| 1390 | for (int i = viewer_objnum + 1; i <= Highest_object_index && !found; i++, i %= (Highest_object_index + 1)) { |
| 1391 | if (Objects[i].type == OBJ_CAMERA) { |
| 1392 | found = 1; |
| 1393 | Viewer_object = &Objects[i]; |
| 1394 | } |
| 1395 | } |
| 1396 | } break; |
| 1397 | case KEY_P: { |
| 1398 | // goto next player |
| 1399 | int viewer_objnum = Viewer_object - Objects; |
| 1400 | int found = 0; |
| 1401 | |
| 1402 | for (int i = viewer_objnum + 1; i <= Highest_object_index && !found; i++, i %= (Highest_object_index + 1)) { |
| 1403 | if (Objects[i].type == OBJ_PLAYER) { |
| 1404 | found = 1; |
| 1405 | Viewer_object = &Objects[i]; |
| 1406 | } |
| 1407 | } |
| 1408 | } break; |
| 1409 | case KEY_R: { |
| 1410 | // goto next robot |
| 1411 | int viewer_objnum = Viewer_object - Objects; |
| 1412 | int found = 0; |
| 1413 | |
| 1414 | for (int i = viewer_objnum + 1; i <= Highest_object_index && !found; i++, i %= (Highest_object_index + 1)) { |
| 1415 | if (Objects[i].type == OBJ_ROBOT) { |
| 1416 | found = 1; |
| 1417 | Viewer_object = &Objects[i]; |
| 1418 | } |
| 1419 | } |
| 1420 | } break; |
| 1421 | case KEY_SPACEBAR: |
| 1422 | // Reset view |
| 1423 | Viewer_object = Player_object; |
| 1424 | break; |
| 1425 | case KEY_DOWN: |
| 1426 | Game_paused = true; |
| 1427 | Demo_paused = true; |
| 1428 | break; |
| 1429 | case KEY_RIGHT: |
| 1430 | Demo_do_one_frame = true; |
| 1431 | break; |
| 1432 | case KEY_CTRLED + KEY_LEFT: { |
| 1433 | char sztmp[_MAX_PATH * 2]; |
| 1434 | strcpy(sztmp, Demo_fname); |
| 1435 | DemoAbort(); |
| 1436 | Game_interface_mode = GAME_DEMO_LOOP; |
| 1437 | Demo_restart = true; |
| 1438 | strcpy(Demo_fname, sztmp); |
| 1439 | } break; |
| 1440 | case KEY_UP: |
| 1441 | Game_paused = false; |
| 1442 | Demo_paused = false; |
| 1443 | break; |
| 1444 | default: |
| 1445 | break; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | // If dead, any key not handled above will eand the death sequence |
| 1450 | if (Players[Player_num].flags & PLAYER_FLAGS_DEAD) { |
| 1451 | return; |
| 1452 | } |
| 1453 | |
| 1454 | // If dying, only the keys handled above do anything, so bail |
| 1455 | if (Players[Player_num].flags & PLAYER_FLAGS_DYING) |
| 1456 | return; |
| 1457 | |
| 1458 | // These keys only work when not dying or dead |
| 1459 | ProcessGuidebotKeys(key); |
| 1460 | |
| 1461 | switch (key) { |
| 1462 | case KEY_SHIFTED + KEY_F1: |
| 1463 | SelectNextCameraView(0); |
| 1464 | return; |
| 1465 | case KEY_SHIFTED + KEY_F2: |
| 1466 | SelectNextCameraView(2); |
| 1467 | return; |
| 1468 | // case KEY_SHIFTED+KEY_F3: SelectNextCameraView(2); return; |
| 1469 | |
| 1470 | case KEY_1: |
| 1471 | SelectWeapon(0); |
| 1472 | return; |
| 1473 | case KEY_2: |
| 1474 | SelectWeapon(1); |
| 1475 | return; |
| 1476 | case KEY_3: |
| 1477 | SelectWeapon(2); |
| 1478 | return; |
| 1479 | case KEY_4: |
| 1480 | SelectWeapon(3); |
| 1481 | return; |
| 1482 | case KEY_5: |
| 1483 | SelectWeapon(4); |
| 1484 | return; |
| 1485 | case KEY_6: |
| 1486 | SelectWeapon(5); |
| 1487 | return; |
| 1488 | case KEY_7: |
| 1489 | SelectWeapon(6); |
| 1490 | return; |
| 1491 | case KEY_8: |
| 1492 | SelectWeapon(7); |
| 1493 | return; |
| 1494 | case KEY_9: |
| 1495 | SelectWeapon(8); |
| 1496 | return; |
| 1497 | case KEY_0: |
| 1498 | SelectWeapon(9); |
| 1499 | return; |
| 1500 | |
| 1501 | case KEY_F3: |
| 1502 | if (GetHUDMode() != HUD_OBSERVER) |
| 1503 | ToggleHUDMode(); |
| 1504 | return; |
| 1505 | case KEY_F12: |
| 1506 | Marker_message = 1; |
| 1507 | StartHUDInputMessage(); |
| 1508 | break; |
| 1509 | case KEY_F4: { |
| 1510 | if ((!(Game_mode & GM_MULTI)) || (Netgame.flags & NF_ALLOWGUIDEBOT)) { |
| 1511 | Game_interface_mode = GAME_BUDDY_INTERFACE; |
| 1512 | } |
| 1513 | return; |
| 1514 | } break; |
| 1515 | case KEY_F9: |
| 1516 | // quick save key! |
| 1517 | if (!Cinematic_inuse) { |
| 1518 | StartGameMenu(); |
| 1519 | QuickSaveGame(); |
| 1520 | EndGameMenu(); |
| 1521 | } |
| 1522 | break; |
| 1523 | case KEY_ALTED + KEY_F2: |
| 1524 | if (!Cinematic_inuse) { |
| 1525 | Game_interface_mode = GAME_SAVE_INTERFACE; |
| 1526 | return; |
| 1527 | } |
| 1528 | break; |
| 1529 | } |
| 1530 | } |
| 1531 | bool Force_one_texture = false; |
| 1532 | |
| 1533 | #ifdef _DEBUG |
| 1534 | static int test_kill_objs = 0; |
| 1535 | |
| 1536 | void InitTestSystems() { test_kill_objs = 0; } |
| 1537 | |
| 1538 | // Tells others that we are cheating |
| 1539 | void SendCheaterText() { |
| 1540 | // Notify other players that you're using debug/test keys. We may want to change this to |
| 1541 | // only send the message for some keys. |
| 1542 | if (Game_mode & GM_MULTI) { |
| 1543 | char str[255]; |
| 1544 | snprintf(str, sizeof(str), TXT_CHEATER, Players[Player_num].callsign); |
| 1545 | |
| 1546 | if (Netgame.local_role == LR_SERVER) |
| 1547 | MultiSendMessageFromServer(GR_RGB(255, 0, 0), str); |
| 1548 | else |
| 1549 | MultiSendMessageToServer(0, str); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | #include "osiris_dll.h" |
| 1554 | #include "audiotaunts.h" |
| 1555 | |
| 1556 | void InitObjectScripts(object *obj, bool call_evt_created = true); |
| 1557 | |
| 1558 | #ifdef _DEBUG |
| 1559 | extern bool Cinematics_enabled; |
| 1560 | #endif |
| 1561 | |
| 1562 | // Deal with keys that only work for testing & debugging (eg., slew) |
| 1563 | void ProcessTestKeys(int key) { |
| 1564 | static int ffret = -1; |
| 1565 | int i; |
| 1566 | |
| 1567 | // Debug break |
| 1568 | if (key == KEY_SHIFTED + KEY_BACKSP) |
| 1569 | Int3(); |
| 1570 | |
| 1571 | // Handle slew keys |
| 1572 | if (Player_object->control_type == CT_SLEW) { |
| 1573 | switch (key) // Special for slew keys. Add all new debugging keys to the second switch statement. |
| 1574 | { |
| 1575 | case KEY_PAD5: |
| 1576 | SlewStop(Player_object); |
| 1577 | break; |
| 1578 | case KEY_PAD0: |
| 1579 | SlewResetOrient(Player_object); |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | if (key == (KEY_SHIFTED + KEY_LBRACKET)) { |
| 1585 | MultiSendRequestPlayTaunt(0); |
| 1586 | } |
| 1587 | |
| 1588 | if (key == (KEY_SHIFTED + KEY_RBRACKET)) { |
| 1589 | MultiSendRequestPlayTaunt(1); |
| 1590 | } |
| 1591 | |
| 1592 | // All other debug/test keys require the DEBUGGED modifier, so bail if it's not set |
| 1593 | if (!(key & KEY_DEBUGGED)) |
| 1594 | return; |
| 1595 | |
| 1596 | switch (key & ~KEY_DEBUGGED) // for simplicity, do swich on keycode without the flag |
| 1597 | { |
| 1598 | |
| 1599 | /* |
| 1600 | ************************************************** |
| 1601 | Keys A-Z |
| 1602 | ************************************************** |
| 1603 | */ |
| 1604 | case KEY_A: |
| 1605 | |
| 1606 | DoAI = !DoAI; |
| 1607 | AddHUDMessage("AI turned %s.", DoAI ? "on" : "off"); |
| 1608 | break; |
| 1609 | |
| 1610 | case KEY_B: |
| 1611 | Game_show_sphere = (Game_show_sphere + 1) % 4; |
| 1612 | |
| 1613 | if (Game_show_sphere == 0) |
| 1614 | AddHUDMessage("No visible spheres."); |
| 1615 | else if (Game_show_sphere == 1) |
| 1616 | AddHUDMessage("Wall collision spheres(only encompass first anim frame)."); |
| 1617 | else if (Game_show_sphere == 2) |
| 1618 | AddHUDMessage("Spheres for FVI(encompass all anims)."); |
| 1619 | else if (Game_show_sphere == 3) |
| 1620 | AddHUDMessage("Object size spheres."); |
| 1621 | |
| 1622 | break; |
| 1623 | |
| 1624 | case KEY_C: |
| 1625 | SendCheaterText(); |
| 1626 | if (Player_object->effect_info->type_flags & EF_CLOAKED) { |
| 1627 | MakeObjectVisible(Player_object); |
| 1628 | AddHUDMessage("You escape the darkness!"); |
| 1629 | } else { |
| 1630 | MakeObjectInvisible(Player_object, 10000); |
| 1631 | AddHUDMessage("You enter the darkness!"); |
| 1632 | } |
| 1633 | break; |
| 1634 | |
| 1635 | case (KEY_C + KEY_SHIFTED): { |
| 1636 | Cinematics_enabled = !Cinematics_enabled; |
| 1637 | |
| 1638 | AddHUDMessage("Game Cinematics: %s", Cinematics_enabled ? "enabled" : "disabled"); |
| 1639 | } break; |
| 1640 | |
| 1641 | case KEY_D: { |
| 1642 | |
| 1643 | int GetRankIndex(int pnum, char *rankbuf); |
| 1644 | void ChangeRankIndex(int old_index, int pnum); |
| 1645 | |
| 1646 | int oldrank = GetRankIndex(1, NULL); |
| 1647 | Players[1].rank += 100; |
| 1648 | ChangeRankIndex(oldrank, 1); |
| 1649 | |
| 1650 | break; |
| 1651 | } |
| 1652 | |
| 1653 | case KEY_SHIFTED + KEY_D: { |
| 1654 | int done = 0; |
| 1655 | for (i = 0; i <= Highest_room_index && !done; i++) { |
| 1656 | for (int t = 0; t < Rooms[i].num_faces && !done; t++) { |
| 1657 | if (GameTextures[Rooms[i].faces[t].tmap].flags & TF_LIGHT) { |
| 1658 | DestroyLight(i, t); |
| 1659 | done = 1; |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | break; |
| 1664 | } |
| 1665 | |
| 1666 | case KEY_E: |
| 1667 | // ends level prematurely |
| 1668 | // this is only for single player |
| 1669 | if (Game_mode & GM_MULTI) { |
| 1670 | AddHUDMessage("Press F6 to end a multiplayer level"); |
| 1671 | } else { |
| 1672 | SetGameState(GAMESTATE_LVLEND); |
| 1673 | } |
| 1674 | break; |
| 1675 | |
| 1676 | case KEY_E + KEY_ALTED: |
| 1677 | // restart level |
| 1678 | if ((!(Game_mode & GM_MULTI)) || Netgame.local_role == LR_SERVER) { |
| 1679 | SetGameState(GAMESTATE_LVLFAILED); |
| 1680 | } |
| 1681 | break; |
| 1682 | |
| 1683 | case KEY_F: |
| 1684 | Hud_stat_mask ^= STAT_FPS; |
| 1685 | break; |
| 1686 | |
| 1687 | /*case KEY_G: |
| 1688 | { |
| 1689 | char dmb_msg[100]; |
| 1690 | mprintf(0,"Current Gametime is %f\n",Gametime); |
| 1691 | snprintf(dmb_msg,sizeof(dmb_msg),"Current Gametime is %f\n",Gametime); |
| 1692 | AddHUDMessage(dmb_msg); |
| 1693 | } |
| 1694 | break;*/ |
| 1695 | |
| 1696 | case KEY_G: { |
| 1697 | if (Player_object->type == OBJ_OBSERVER) { |
| 1698 | if (Game_mode & GM_MULTI) |
| 1699 | MultiSendRequestToObserve(OBSERVER_MODE_ROAM, 0, 0); |
| 1700 | else |
| 1701 | PlayerStopObserving(Player_num); |
| 1702 | |
| 1703 | } else { |
| 1704 | if (Game_mode & GM_MULTI) |
| 1705 | MultiSendRequestToObserve(OBSERVER_MODE_ROAM, 1, 0); |
| 1706 | else |
| 1707 | PlayerSwitchToObserver(Player_num, OBSERVER_MODE_ROAM); |
| 1708 | } |
| 1709 | } break; |
| 1710 | |
| 1711 | case KEY_H: |
| 1712 | HUD_disabled = !HUD_disabled; |
| 1713 | if (!HUD_disabled) |
| 1714 | AddHUDMessage(TXT_HUDENABLED); |
| 1715 | break; |
| 1716 | |
| 1717 | case KEY_I: |
| 1718 | |
| 1719 | SendCheaterText(); |
| 1720 | if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) { |
| 1721 | MakePlayerVulnerable(Player_num); |
| 1722 | AddHUDMessage("Your mother wont protect you now!"); |
| 1723 | } else { |
| 1724 | MakePlayerInvulnerable(Player_num, 10000); |
| 1725 | AddHUDMessage("You're a wimp!"); |
| 1726 | } |
| 1727 | break; |
| 1728 | |
| 1729 | case KEY_J: { |
| 1730 | object *obj = &Objects[Player_num]; |
| 1731 | for (i = 0; i < 21; i++) { |
| 1732 | if (obj->dynamic_wb[i].flags & DWBF_QUAD) { |
| 1733 | obj->dynamic_wb[i].flags &= ~DWBF_QUAD; |
| 1734 | AddHUDMessage("Quad Flag Turned Off"); |
| 1735 | } else { |
| 1736 | obj->dynamic_wb[i].flags |= DWBF_QUAD; |
| 1737 | AddHUDMessage("Quad Flag Turned On"); |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | } break; |
| 1742 | |
| 1743 | case KEY_K: { |
| 1744 | if (Game_mode & GM_MULTI) |
| 1745 | break; |
| 1746 | |
| 1747 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 1748 | if (test_kill_objs == 0 && Objects[i].type == OBJ_ROBOT) { |
| 1749 | DoAI = 0; |
| 1750 | ObjDelete(i); |
| 1751 | AddHUDMessage("All robots dead!"); |
| 1752 | } else if (test_kill_objs == 1 && Objects[i].type == OBJ_CLUTTER) { |
| 1753 | ObjDelete(i); |
| 1754 | AddHUDMessage("All clutter gone!"); |
| 1755 | } else if (test_kill_objs == 2 && Objects[i].type == OBJ_POWERUP) { |
| 1756 | ObjDelete(i); |
| 1757 | AddHUDMessage("All powerups gone!"); |
| 1758 | } |
| 1759 | } |
| 1760 | test_kill_objs++; |
| 1761 | |
| 1762 | test_kill_objs = test_kill_objs % 3; |
| 1763 | |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | case KEY_L: |
| 1768 | Terrain_LOD_engine_off = !Terrain_LOD_engine_off; |
| 1769 | AddHUDMessage("Terrain LOD engine turned %s", Terrain_LOD_engine_off ? "OFF" : "ON"); |
| 1770 | break; |
| 1771 | |
| 1772 | case KEY_M: |
| 1773 | Render_portals = 1 - Render_portals; |
| 1774 | break; |
| 1775 | |
| 1776 | case KEY_N: |
| 1777 | if (Current_level && Current_level->filename) { |
| 1778 | vector player_pos = Player_object->pos; |
| 1779 | matrix player_orient = Player_object->orient; |
| 1780 | int player_roomnum = Player_object->roomnum; |
| 1781 | |
| 1782 | // Load the level |
| 1783 | LoadAndStartCurrentLevel(); |
| 1784 | |
| 1785 | // Restore player position |
| 1786 | ObjSetPos(Player_object, &player_pos, player_roomnum, &player_orient, true); |
| 1787 | } |
| 1788 | break; |
| 1789 | |
| 1790 | case KEY_O: |
| 1791 | Outline_mode ^= OM_ON; |
| 1792 | AddHUDMessage("Outline mode turned %s", OUTLINE_ON(0) ? "ON" : "OFF"); |
| 1793 | break; |
| 1794 | |
| 1795 | case KEY_O + KEY_SHIFTED: |
| 1796 | Outline_mode = OM_ON + OM_ALL; |
| 1797 | AddHUDMessage("All outline options turned on."); |
| 1798 | break; |
| 1799 | |
| 1800 | case KEY_P: |
| 1801 | MakeTestPath(&Player_object->roomnum, &Player_object->pos); |
| 1802 | break; |
| 1803 | |
| 1804 | case KEY_Q: |
| 1805 | if (StateLimited) { |
| 1806 | StateLimited = 0; |
| 1807 | AddHUDMessage("State limited turned off."); |
| 1808 | } else { |
| 1809 | StateLimited = 1; |
| 1810 | AddHUDMessage("State limited turned on."); |
| 1811 | } |
| 1812 | break; |
| 1813 | |
| 1814 | case KEY_R: |
| 1815 | if (Weather.flags & WEATHER_FLAGS_SNOW) { |
| 1816 | Weather.flags &= ~WEATHER_FLAGS_SNOW; |
| 1817 | AddHUDMessage("Snow turned off."); |
| 1818 | } else { |
| 1819 | Weather.flags |= WEATHER_FLAGS_SNOW; |
| 1820 | AddHUDMessage("Snow turned on."); |
| 1821 | } |
| 1822 | break; |
| 1823 | |
| 1824 | case KEY_S: |
| 1825 | if (Sound_system.IsActive()) { |
| 1826 | AddHUDMessage("Sound system off."); |
| 1827 | Sound_system.KillSoundLib(false); |
| 1828 | } else { |
| 1829 | AddHUDMessage("Sound system on."); |
| 1830 | Sound_system.InitSoundLib(Descent, Sound_mixer, Sound_quality, false); |
| 1831 | } |
| 1832 | break; |
| 1833 | |
| 1834 | case KEY_S + KEY_SHIFTED: { |
| 1835 | // extern spewinfo SpewEffects[MAX_SPEW_EFFECTS]; |
| 1836 | int count; |
| 1837 | |
| 1838 | AddHUDMessage("Spewers Killed"); |
| 1839 | |
| 1840 | for (count = 0; count < MAX_SPEW_EFFECTS; count++) { |
| 1841 | SpewEffects[count].inuse = 0; |
| 1842 | } |
| 1843 | |
| 1844 | } break; |
| 1845 | |
| 1846 | case KEY_T: |
| 1847 | if (Timedemo_frame == -1) |
| 1848 | Timedemo_frame = 0; |
| 1849 | break; |
| 1850 | |
| 1851 | case KEY_U: |
| 1852 | AIPath_test_end_room = Player_object->roomnum; |
| 1853 | AIPath_test_end_pos = Player_object->pos; |
| 1854 | break; |
| 1855 | |
| 1856 | case KEY_V: |
| 1857 | // TODO: should this actually be a fallthrough? |
| 1858 | |
| 1859 | case KEY_W: |
| 1860 | if (Weather.flags & WEATHER_FLAGS_LIGHTNING) { |
| 1861 | Weather.flags &= ~WEATHER_FLAGS_LIGHTNING; |
| 1862 | AddHUDMessage("Lighting turned off."); |
| 1863 | |
| 1864 | } else { |
| 1865 | Weather.flags |= WEATHER_FLAGS_LIGHTNING; |
| 1866 | Weather.lightning_sequence = 0; |
| 1867 | Weather.lightning_rand_value = 70; |
| 1868 | Weather.lightning_interval_time = .01f; |
| 1869 | AddHUDMessage("Lighting turned on."); |
| 1870 | } |
| 1871 | break; |
| 1872 | |
| 1873 | case KEY_X: { |
| 1874 | SendCheaterText(); |
| 1875 | Players[Player_num].energy = 200.0f; |
| 1876 | Players[Player_num].weapon_flags = 0xFFFFFFFF; |
| 1877 | int i; |
| 1878 | |
| 1879 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) |
| 1880 | Players[Player_num].weapon_ammo[i] = Ships[Players[Player_num].ship_index].max_ammo[i]; |
| 1881 | |
| 1882 | Players[Player_num].afterburn_time_left = AFTERBURN_TIME; |
| 1883 | |
| 1884 | AddHUDMessage("All weapons!"); |
| 1885 | |
| 1886 | // add all the countermeasures |
| 1887 | if (Game_mode & GM_MULTI) |
| 1888 | break; |
| 1889 | int c_id, b_id, s_id, g_id, p_id; |
| 1890 | c_id = FindWeaponName("Chaff"); |
| 1891 | b_id = FindWeaponName("Betty"); |
| 1892 | s_id = FindWeaponName("SeekerMine"); |
| 1893 | g_id = FindWeaponName("Gunboy"); |
| 1894 | p_id = FindWeaponName("ProxMine"); |
| 1895 | |
| 1896 | int c_pid, b_pid, s_pid, g_pid, p_pid; |
| 1897 | c_pid = FindObjectIDName("chaff"); |
| 1898 | b_pid = FindObjectIDName("Betty4pack"); |
| 1899 | s_pid = FindObjectIDName("Seeker3pack"); |
| 1900 | g_pid = FindObjectIDName("gunboypowerup"); |
| 1901 | p_pid = FindObjectIDName("ProxMinepowerup"); |
| 1902 | |
| 1903 | if (c_pid == -1) |
| 1904 | c_pid = FindObjectIDName("Shield"); |
| 1905 | if (b_pid == -1) |
| 1906 | b_pid = FindObjectIDName("Energy"); |
| 1907 | if (s_pid == -1) |
| 1908 | s_pid = FindObjectIDName("Shield"); |
| 1909 | if (g_pid == -1) |
| 1910 | g_pid = FindObjectIDName("Energy"); |
| 1911 | if (p_pid == -1) |
| 1912 | p_pid = FindObjectIDName("Shield"); |
| 1913 | |
| 1914 | object *objp = &Objects[Players[Player_num].objnum]; |
| 1915 | for (i = 0; i < 30; i++) { |
| 1916 | if (c_id != -1) |
| 1917 | Players[Player_num].counter_measures.Add(OBJ_WEAPON, c_id, objp, OBJ_POWERUP, c_pid); |
| 1918 | if (b_id != -1) |
| 1919 | Players[Player_num].counter_measures.Add(OBJ_WEAPON, b_id, objp, OBJ_POWERUP, b_pid); |
| 1920 | if (s_id != -1) |
| 1921 | Players[Player_num].counter_measures.Add(OBJ_WEAPON, s_id, objp, OBJ_POWERUP, s_pid); |
| 1922 | if (g_id != -1) |
| 1923 | Players[Player_num].counter_measures.Add(OBJ_WEAPON, g_id, objp, OBJ_POWERUP, g_pid); |
| 1924 | if (p_id != -1) |
| 1925 | Players[Player_num].counter_measures.Add(OBJ_WEAPON, p_id, objp, OBJ_POWERUP, p_pid); |
| 1926 | } |
| 1927 | |
| 1928 | break; |
| 1929 | } |
| 1930 | |
| 1931 | case KEY_Y: |
| 1932 | Physics_player_verbose = 1 - Physics_player_verbose; |
| 1933 | if (Physics_player_verbose) |
| 1934 | AddHUDMessage("Verbose player physics info\n"); |
| 1935 | else |
| 1936 | AddHUDMessage("Player physics info off\n"); |
| 1937 | break; |
| 1938 | |
| 1939 | case KEY_Z: { |
| 1940 | // Inventory test |
| 1941 | int id, objnum; |
| 1942 | |
| 1943 | id = FindObjectIDName("Betty4Pack"); |
| 1944 | objnum = ObjCreate(OBJ_POWERUP, id, Player_object->roomnum, &Player_object->pos, &Player_object->orient); |
| 1945 | |
| 1946 | if (objnum != -1) { |
| 1947 | if (Game_mode & GM_MULTI) |
| 1948 | MultiSendObject(&Objects[objnum], false); |
| 1949 | |
| 1950 | InitObjectScripts(&Objects[objnum], true); |
| 1951 | Players[Player_num].inventory.AddObject(Objects[objnum].handle, true); |
| 1952 | } |
| 1953 | } break; |
| 1954 | |
| 1955 | case KEY_Z + KEY_ALTED: { |
| 1956 | // look for a betty4pack and remove the sucker |
| 1957 | int id; |
| 1958 | id = FindObjectIDName("Betty4Pack"); |
| 1959 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 1960 | if (Objects[i].type == OBJ_DUMMY && Objects[i].dummy_type == OBJ_POWERUP && Objects[i].id == id) { |
| 1961 | // here's a betty |
| 1962 | mprintf(0, "Killing a betty\n"); |
| 1963 | SetObjectDeadFlag(&Objects[i], true); |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | } break; |
| 1968 | /* |
| 1969 | ************************************************** |
| 1970 | Keypad Keys |
| 1971 | ************************************************** |
| 1972 | */ |
| 1973 | |
| 1974 | case KEY_PAD0: { |
| 1975 | Game_update_attach = 1 - Game_update_attach; |
| 1976 | |
| 1977 | if (Game_update_attach) { |
| 1978 | mprintf(0, "Update attach on\n"); |
| 1979 | } else { |
| 1980 | mprintf(0, "Update attach off\n"); |
| 1981 | } |
| 1982 | } break; |
| 1983 | |
| 1984 | case KEY_PAD1: { |
| 1985 | Game_do_flying_sim = 1 - Game_do_flying_sim; |
| 1986 | if (Game_do_flying_sim) { |
| 1987 | mprintf(0, "Game_do_flying_sim on\n"); |
| 1988 | } else { |
| 1989 | mprintf(0, "Game_do_flying_sim off\n"); |
| 1990 | } |
| 1991 | } break; |
| 1992 | |
| 1993 | case KEY_PAD2: { |
| 1994 | Game_do_walking_sim = 1 - Game_do_walking_sim; |
| 1995 | if (Game_do_walking_sim) { |
| 1996 | mprintf(0, "Game_do_walking_sim on\n"); |
| 1997 | } else { |
| 1998 | mprintf(0, "Game_do_walking_sim off\n"); |
| 1999 | } |
| 2000 | } break; |
| 2001 | |
| 2002 | case KEY_PAD3: { |
| 2003 | Game_do_vis_sim = 1 - Game_do_vis_sim; |
| 2004 | if (Game_do_vis_sim) { |
| 2005 | mprintf(0, "Game_do_vis_sim on\n"); |
| 2006 | } else { |
| 2007 | mprintf(0, "Game_do_vis_sim off\n"); |
| 2008 | } |
| 2009 | } break; |
| 2010 | |
| 2011 | case KEY_PAD4: { |
| 2012 | Game_do_ai_movement = 1 - Game_do_ai_movement; |
| 2013 | if (Game_do_ai_movement) { |
| 2014 | mprintf(0, "Game_do_ai_movement on\n"); |
| 2015 | } else { |
| 2016 | mprintf(0, "Game_do_ai_movement off\n"); |
| 2017 | } |
| 2018 | } break; |
| 2019 | |
| 2020 | case KEY_PAD5: { |
| 2021 | Game_do_ai_vis = 1 - Game_do_ai_vis; |
| 2022 | if (Game_do_ai_vis) { |
| 2023 | mprintf(0, "Game_do_ai_vis on\n"); |
| 2024 | } else { |
| 2025 | mprintf(0, "Game_do_ai_vis off\n"); |
| 2026 | } |
| 2027 | } break; |
| 2028 | |
| 2029 | case KEY_PAD6: { |
| 2030 | if (AI_debug_robot_do) { |
| 2031 | AI_debug_robot_do = false; |
| 2032 | mprintf(0, "AI Debug Info Off\n"); |
| 2033 | } else { |
| 2034 | AI_debug_robot_do = true; |
| 2035 | mprintf(0, "AI Debug Info On\n"); |
| 2036 | } |
| 2037 | } break; |
| 2038 | |
| 2039 | case KEY_PAD7: { |
| 2040 | bool killed_something = false; |
| 2041 | int killed_count = 0; |
| 2042 | int i, a; |
| 2043 | for (i = 0; i < MAX_OBJECTS; i++) { |
| 2044 | if (Objects[i].type == OBJ_ROBOT || (Objects[i].type == OBJ_BUILDING && Objects[i].ai_info)) { |
| 2045 | // Now, kill all robots of this type! |
| 2046 | AddHUDMessage("Killing all %s robots!", Object_info[Objects[i].id].name); |
| 2047 | for (a = 0; a < MAX_OBJECTS; a++) { |
| 2048 | if (Objects[a].id == Objects[i].id) { |
| 2049 | SetObjectDeadFlag(&Objects[a]); |
| 2050 | killed_something = true; |
| 2051 | killed_count++; |
| 2052 | } |
| 2053 | } |
| 2054 | /* |
| 2055 | SetObjectDeadFlag(&Objects[i]); |
| 2056 | AddHUDMessage("Killed object %d!",i); |
| 2057 | |
| 2058 | if(killed_count>4) |
| 2059 | break; |
| 2060 | */ |
| 2061 | } |
| 2062 | if (killed_something) |
| 2063 | break; |
| 2064 | } |
| 2065 | if (!killed_something) |
| 2066 | AddHUDMessage("Nothing to kill!"); |
| 2067 | else |
| 2068 | mprintf(0, "Killed %d objects of type %s!\n", killed_count, Object_info[Objects[i].id].name); |
| 2069 | } break; |
| 2070 | /* |
| 2071 | ************************************************** |
| 2072 | Number Keys |
| 2073 | ************************************************** |
| 2074 | */ |
| 2075 | |
| 2076 | case KEY_1: { |
| 2077 | // goto prev viewer |
| 2078 | int viewer_objnum = Viewer_object - Objects; |
| 2079 | int found = 0; |
| 2080 | |
| 2081 | for (i = viewer_objnum - 1; i >= 0 && !found; i--, i < 0 ? i = Highest_object_index : i = i) { |
| 2082 | if (Objects[i].type == OBJ_POWERUP || Objects[i].type == OBJ_PLAYER || Objects[i].type == OBJ_ROBOT || |
| 2083 | Objects[i].type == OBJ_CLUTTER || Objects[i].type == OBJ_BUILDING || Objects[i].type == OBJ_MARKER) { |
| 2084 | found = 1; |
| 2085 | Viewer_object = &Objects[i]; |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | AddHUDMessage("Viewer set to previous object."); |
| 2090 | |
| 2091 | } break; |
| 2092 | |
| 2093 | case KEY_2: { |
| 2094 | // reset viewer |
| 2095 | AddHUDMessage("Viewer set to player object."); |
| 2096 | Viewer_object = Player_object; |
| 2097 | } break; |
| 2098 | |
| 2099 | case KEY_3: { |
| 2100 | // goto next viewer |
| 2101 | int viewer_objnum = Viewer_object - Objects; |
| 2102 | int found = 0; |
| 2103 | |
| 2104 | for (i = viewer_objnum + 1; i <= Highest_object_index && !found; i++, i %= (Highest_object_index + 1)) { |
| 2105 | if (Objects[i].type == OBJ_POWERUP || Objects[i].type == OBJ_PLAYER || Objects[i].type == OBJ_ROBOT || |
| 2106 | Objects[i].type == OBJ_CLUTTER || Objects[i].type == OBJ_BUILDING || Objects[i].type == OBJ_MARKER) { |
| 2107 | found = 1; |
| 2108 | Viewer_object = &Objects[i]; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | AddHUDMessage("Viewer set to next object."); |
| 2113 | } break; |
| 2114 | |
| 2115 | case KEY_4: |
| 2116 | if (Tracking_FVI) |
| 2117 | Tracking_FVI = false; |
| 2118 | else |
| 2119 | Tracking_FVI = true; |
| 2120 | |
| 2121 | AddHUDMessage("Tracking FVI now set to %s.", Tracking_FVI ? "on" : "off"); |
| 2122 | |
| 2123 | break; |
| 2124 | |
| 2125 | case KEY_6: |
| 2126 | Render_FOV -= 1; |
| 2127 | AddHUDMessage("FOV is now %f", Render_FOV); |
| 2128 | break; |
| 2129 | |
| 2130 | case KEY_7: |
| 2131 | Render_FOV += 1; |
| 2132 | AddHUDMessage("FOV is now %f", Render_FOV); |
| 2133 | break; |
| 2134 | |
| 2135 | case KEY_8: |
| 2136 | Render_FOV = D3_DEFAULT_FOV; |
| 2137 | AddHUDMessage("FOV has been reset to %f", Render_FOV); |
| 2138 | break; |
| 2139 | |
| 2140 | case KEY_9: |
| 2141 | Force_one_texture = !Force_one_texture; |
| 2142 | break; |
| 2143 | |
| 2144 | /* |
| 2145 | ************************************************** |
| 2146 | Function Keys |
| 2147 | ************************************************** |
| 2148 | */ |
| 2149 | |
| 2150 | case KEY_F5: |
| 2151 | D3MusicToggle(); |
| 2152 | break; |
| 2153 | |
| 2154 | case KEY_F6: { |
| 2155 | vector test_pos; |
| 2156 | fvi_info hit_info; |
| 2157 | fvi_query fq; |
| 2158 | int fate; |
| 2159 | int this_key = key & ~KEY_DEBUGGED; |
| 2160 | |
| 2161 | test_pos = Player_object->pos + Player_object->orient.fvec * 1000000.0f; |
| 2162 | |
| 2163 | fq.p0 = &Player_object->pos; |
| 2164 | fq.startroom = Player_object->roomnum; |
| 2165 | fq.p1 = &test_pos; |
| 2166 | fq.rad = 0.0; |
| 2167 | fq.thisobjnum = OBJNUM(Player_object); |
| 2168 | fq.ignore_obj_list = NULL; |
| 2169 | if (this_key == KEY_F6) |
| 2170 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_RENDER_THROUGH_PORTALS; |
| 2171 | else |
| 2172 | fq.flags = 0; |
| 2173 | |
| 2174 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 2175 | |
| 2176 | switch (fate) { |
| 2177 | case HIT_NONE: |
| 2178 | mprintf(0, "Hit nothing\n"); |
| 2179 | break; |
| 2180 | case HIT_WALL: |
| 2181 | mprintf(0, "Hit wall\n"); |
| 2182 | break; |
| 2183 | case HIT_OBJECT: |
| 2184 | mprintf(0, "Hit Object %d\n", hit_info.hit_object); |
| 2185 | break; |
| 2186 | case HIT_TERRAIN: |
| 2187 | mprintf(0, "Hit Terrain %d\n", CELLNUM(hit_info.hit_room)); |
| 2188 | break; |
| 2189 | case HIT_OUT_OF_TERRAIN_BOUNDS: |
| 2190 | mprintf(0, "Hit nothing: Leaving Terrain\n"); |
| 2191 | break; |
| 2192 | case HIT_SPHERE_2_POLY_OBJECT: |
| 2193 | mprintf(0, "Hit Poly_object\n"); |
| 2194 | break; |
| 2195 | default: |
| 2196 | mprintf(0, "Hit %d not printed, add to list\n", fate); |
| 2197 | break; |
| 2198 | } |
| 2199 | |
| 2200 | if (fate) { |
| 2201 | int objnum; |
| 2202 | |
| 2203 | objnum = ObjCreate(OBJ_DEBUG_LINE, 1, Player_object->roomnum, &Player_object->pos, NULL); |
| 2204 | if (objnum >= 0) { // DAJ -1FIX |
| 2205 | Objects[objnum].rtype.line_info.end_pos = hit_info.hit_pnt; |
| 2206 | Objects[objnum].size = vm_VectorDistance(&Player_object->pos, &hit_info.hit_pnt); |
| 2207 | ObjSetAABB(&Objects[objnum]); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | Sound_system.CheckAndForceSoundDataAlloc(SOUND_REFUELING); |
| 2212 | Sound_system.PlayStream(0, SoundFiles[Sounds[SOUND_REFUELING].sample_index].sample_8bit, |
| 2213 | SoundFiles[Sounds[SOUND_REFUELING].sample_index].sample_length, SIF_STREAMING_8_M, 1.0, |
| 2214 | NULL); |
| 2215 | } break; |
| 2216 | |
| 2217 | case KEY_F7: |
| 2218 | // Toggle Music Debug Info!! |
| 2219 | Music_debug_verbose = !Music_debug_verbose; |
| 2220 | break; |
| 2221 | |
| 2222 | case KEY_F8: |
| 2223 | D3MusicSetRegion((D3MusicGetRegion() > 0) ? 0 : 1); |
| 2224 | break; |
| 2225 | |
| 2226 | case KEY_F9: { |
| 2227 | vector vec = Player_object->pos + (Player_object->orient.fvec * 20); |
| 2228 | if (BSPRayOccluded(&Player_object->pos, &vec, MineBSP.root)) |
| 2229 | mprintf(0, "Occluded!\n"); |
| 2230 | else |
| 2231 | mprintf(0, "NOT occluded!\n"); |
| 2232 | } break; |
| 2233 | |
| 2234 | case KEY_F10: |
| 2235 | int ObjInitTypeSpecific(object * objp, bool reinitializing); |
| 2236 | FreeCockpit(); |
| 2237 | CloseShipHUD(); |
| 2238 | Players[0].ship_index = GetNextShip(Players[0].ship_index); |
| 2239 | AddHUDMessage("Player ship set to %s\n", Ships[Players[0].ship_index].name); |
| 2240 | ObjInitTypeSpecific(Player_object, 0); // reset physics, model, etc. |
| 2241 | InitShipHUD(Players[0].ship_index); |
| 2242 | InitCockpit(Players[0].ship_index); |
| 2243 | if (GetHUDMode() == HUD_COCKPIT) |
| 2244 | SetHUDMode(HUD_COCKPIT); |
| 2245 | else if (GetHUDMode() == HUD_FULLSCREEN) |
| 2246 | SetHUDMode(HUD_FULLSCREEN); |
| 2247 | break; |
| 2248 | |
| 2249 | case KEY_F11: |
| 2250 | /* |
| 2251 | if(Player_object->control_type != CT_SOAR) |
| 2252 | { |
| 2253 | AddHUDMessage("SOAR ON. Auto-pilot engaged."); |
| 2254 | |
| 2255 | SetObjectControlType(Player_object, CT_SOAR); |
| 2256 | SoarCreateAgent(OBJNUM(Player_object), 0); |
| 2257 | } |
| 2258 | else |
| 2259 | { |
| 2260 | AddHUDMessage("SOAR OFF. Manual control returned."); |
| 2261 | |
| 2262 | SoarDestroyAgent(OBJNUM(Player_object), 0); |
| 2263 | SetObjectControlType(Player_object, CT_FLYING); |
| 2264 | } |
| 2265 | break; |
| 2266 | |
| 2267 | case KEY_F12: |
| 2268 | */ |
| 2269 | { |
| 2270 | char test[MAX_MATCEN_NAME_LEN]; |
| 2271 | bool f_name_changed; |
| 2272 | |
| 2273 | strcpy(test, "test"); |
| 2274 | |
| 2275 | int m_id = CreateMatcen(test, &f_name_changed); |
| 2276 | |
| 2277 | if (m_id >= 0) { |
| 2278 | int id = FindObjectIDName("Tubbs"); |
| 2279 | int p = 100; |
| 2280 | float t = 5.0f; |
| 2281 | int m = 5; |
| 2282 | |
| 2283 | mprintf(0, "Matcen alive!\n"); |
| 2284 | |
| 2285 | vector centerPt = Player_object->pos + (Player_object->orient.fvec * 2.0f); |
| 2286 | Matcen[m_id]->SetAttachType(MT_ROOM); |
| 2287 | Matcen[m_id]->SetAttach(Player_object->roomnum); |
| 2288 | Matcen[m_id]->SetCreateRoom(Player_object->roomnum); |
| 2289 | Matcen[m_id]->SetCreatePnt(¢erPt); |
| 2290 | Matcen[m_id]->SetControlType(MPC_WHILE_PLAYER_NEAR); |
| 2291 | |
| 2292 | Matcen[m_id]->SetMaxProd(12); |
| 2293 | Matcen[m_id]->SetNumProdTypes(3); |
| 2294 | Matcen[m_id]->SetMaxAliveChildren(1); |
| 2295 | Matcen[m_id]->SetProdInfo(0, &id, &p, &t, &m); |
| 2296 | id = FindObjectIDName("Sixgun"); |
| 2297 | Matcen[m_id]->SetProdInfo(1, &id, &p, &t, &m); |
| 2298 | id = FindObjectIDName("bladescaled"); |
| 2299 | Matcen[m_id]->SetProdInfo(2, &id, &p, &t, &m); |
| 2300 | |
| 2301 | Matcen[m_id]->SetStatus(MSTAT_ACTIVE | MSTAT_RANDOM_PROD_ORDER, true); |
| 2302 | } else { |
| 2303 | mprintf(0, "Nope!\n"); |
| 2304 | } |
| 2305 | } |
| 2306 | break; |
| 2307 | |
| 2308 | /* |
| 2309 | ************************************************** |
| 2310 | Other Keys |
| 2311 | ************************************************** |
| 2312 | */ |
| 2313 | case KEY_TAB: |
| 2314 | Game_interface_mode = GAME_DEBUGGRAPH_INTERFACE; |
| 2315 | break; |
| 2316 | |
| 2317 | case KEY_COMMA: |
| 2318 | rtp_StartLog(); |
| 2319 | break; |
| 2320 | |
| 2321 | case KEY_PERIOD: |
| 2322 | rtp_StopLog(); |
| 2323 | break; |
| 2324 | |
| 2325 | case KEY_LAPOSTRO: |
| 2326 | Show_osiris_debug = !Show_osiris_debug; |
| 2327 | AddHUDMessage("%s osiris debug messages", (Show_osiris_debug) ? "Enabling" : "Disabling"); |
| 2328 | break; |
| 2329 | |
| 2330 | case KEY_BACKSLASH: |
| 2331 | // attempt to restore video |
| 2332 | if (DebugBreak_callback_stop) |
| 2333 | (*DebugBreak_callback_stop)(); |
| 2334 | if (DebugBreak_callback_resume) |
| 2335 | (*DebugBreak_callback_resume)(); |
| 2336 | break; |
| 2337 | |
| 2338 | case KEY_SPACEBAR: |
| 2339 | if (Player_object->control_type == CT_FLYING) { |
| 2340 | SetObjectControlType(Player_object, CT_SLEW); |
| 2341 | Player_object->movement_type = MT_NONE; |
| 2342 | SlewStop(Player_object); |
| 2343 | AddHUDMessage("Slew on"); |
| 2344 | } else { |
| 2345 | SlewStop(Player_object); |
| 2346 | SetObjectControlType(Player_object, CT_FLYING); |
| 2347 | Player_object->movement_type = MT_PHYSICS; |
| 2348 | AddHUDMessage("Physics on"); |
| 2349 | } |
| 2350 | break; |
| 2351 | |
| 2352 | case KEY_BACKSP: { |
| 2353 | if (!ROOMNUM_OUTSIDE(Player_object->roomnum)) { |
| 2354 | int i; |
| 2355 | |
| 2356 | Game_show_portal_vis_pnts = 1 - Game_show_portal_vis_pnts; |
| 2357 | |
| 2358 | mprintf(0, "Vis info for room %d\n", Player_object->roomnum); |
| 2359 | |
| 2360 | for (i = 0; i <= Highest_room_index; i++) { |
| 2361 | if (BOA_IsVisible(i, Player_object->roomnum)) { |
| 2362 | mprintf(0, "%d can see you in %d\n", i, Player_object->roomnum); |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | for (i = Highest_room_index + 1; i <= Highest_room_index + 8; i++) { |
| 2367 | if (BOA_IsVisible(i, Player_object->roomnum)) { |
| 2368 | mprintf(0, "Terrain %d can see you in %d\n", i - Highest_room_index - 1, Player_object->roomnum); |
| 2369 | } |
| 2370 | } |
| 2371 | } |
| 2372 | } break; |
| 2373 | } |
| 2374 | } |
| 2375 | #endif |
| 2376 | |
| 2377 | // Sends this key to the multiplayer game DLL |
| 2378 | // Return: true means to handle the key normally |
| 2379 | // false means to do no further processing on this key |
| 2380 | bool SendKeyToGameDLL(int key) { |
| 2381 | DLLInfo.input_key = key; |
| 2382 | |
| 2383 | DLLInfo.iRet = 0; |
| 2384 | CallGameDLL(EVT_CLIENT_KEYPRESS, &DLLInfo); |
| 2385 | |
| 2386 | if (DLLInfo.iRet != 0) { |
| 2387 | |
| 2388 | ddio_KeyFlush(); // keep the controls stuff from getting any keys |
| 2389 | return 0; // Don't process this key |
| 2390 | } |
| 2391 | |
| 2392 | // Handle key normally |
| 2393 | return 1; |
| 2394 | } |
| 2395 | |
| 2396 | void DemoCheats(int key); |
| 2397 | // Get and handle all pending keys |
| 2398 | void ProcessKeys() { |
| 2399 | int key; |
| 2400 | |
| 2401 | if (Dedicated_server) |
| 2402 | return; // No key processing for dedicated server! |
| 2403 | |
| 2404 | // if we are in some menu then don't process game keys! |
| 2405 | if (Game_interface_mode != GAME_INTERFACE || Menu_interface_mode) |
| 2406 | return; |
| 2407 | |
| 2408 | // Process all pending keys |
| 2409 | while ((key = ddio_KeyInKey()) != 0) { |
| 2410 | |
| 2411 | // Where does this belong? |
| 2412 | // do d3x debugging console |
| 2413 | // D3XDebugIO(key); |
| 2414 | |
| 2415 | // If inputting a multiplayer message, send keys there |
| 2416 | if (Doing_input_message) { |
| 2417 | DoHUDInputMessageKey(key); |
| 2418 | continue; |
| 2419 | } |
| 2420 | |
| 2421 | // If multiplayer, send the key to the game DLL |
| 2422 | if (Game_mode & GM_MULTI) { |
| 2423 | if (!SendKeyToGameDLL(key)) // returns true if should keep processing this key |
| 2424 | continue; // the DLL says not process this key |
| 2425 | } |
| 2426 | |
| 2427 | // Handle normal key |
| 2428 | ProcessNormalKey(key); |
| 2429 | |
| 2430 | // Handle debugging & test keys |
| 2431 | #ifdef _DEBUG |
| 2432 | ProcessTestKeys(key); |
| 2433 | #endif |
| 2434 | |
| 2435 | // #ifdef DEMO |
| 2436 | DemoCheats(key); |
| 2437 | // #endif |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | // Render the world into a game window |
| 2442 | // Parameters: viewer - if not null, this object disabled from rendering. Not used otherwise. |
| 2443 | // viewer_eye - where we're rendering from |
| 2444 | // viewer_roomnum - the roomnum viewer_eye is in |
| 2445 | // viewer_orient - the oriention for this view |
| 2446 | // zoom - the zoom for this view |
| 2447 | // rear_view - if true, we're looking out the rear of this object |
| 2448 | |
| 2449 | #ifdef _DEBUG |
| 2450 | extern void DrawRoomVisPnts(object *obj); |
| 2451 | #endif |
| 2452 | |
| 2453 | void GameRenderWorld(object *viewer, vector *viewer_eye, int viewer_roomnum, matrix *viewer_orient, float zoom, |
| 2454 | bool rear_view) { |
| 2455 | matrix temp_orient, save_orient; |
| 2456 | |
| 2457 | // Get the viewer orientation |
| 2458 | if (rear_view) { |
| 2459 | temp_orient.fvec = -viewer_orient->fvec; |
| 2460 | temp_orient.rvec = -viewer_orient->rvec; |
| 2461 | temp_orient.uvec = viewer_orient->uvec; |
| 2462 | viewer_orient = &temp_orient; |
| 2463 | save_orient = viewer->orient; |
| 2464 | viewer->orient = temp_orient; |
| 2465 | } |
| 2466 | |
| 2467 | // Start the 3D |
| 2468 | g3_StartFrame(viewer_eye, viewer_orient, zoom); |
| 2469 | |
| 2470 | // Reset fog,zbuffer |
| 2471 | Num_fogged_rooms_this_frame = 0; |
| 2472 | rend_SetZBufferState(1); |
| 2473 | rend_SetZBufferWriteMask(1); |
| 2474 | |
| 2475 | // Reset our postrenderings |
| 2476 | ResetPostrenderList(); |
| 2477 | |
| 2478 | // Render! |
| 2479 | if (ROOMNUM_OUTSIDE(viewer_roomnum)) |
| 2480 | RenderTerrain(0); |
| 2481 | else { |
| 2482 | bool flag_automap = (viewer != NULL) ? (viewer->type != OBJ_ROBOT) : 0; |
| 2483 | RenderMine(viewer_roomnum, flag_automap, 0); |
| 2484 | |
| 2485 | #ifdef _DEBUG |
| 2486 | if (Game_show_portal_vis_pnts) { |
| 2487 | DrawRoomVisPnts(Player_object); |
| 2488 | } |
| 2489 | #endif |
| 2490 | } |
| 2491 | |
| 2492 | // Done with 3D |
| 2493 | PostRender(viewer_roomnum); |
| 2494 | g3_EndFrame(); |
| 2495 | |
| 2496 | // Restore viewer orientation |
| 2497 | if (rear_view) |
| 2498 | viewer->orient = save_orient; |
| 2499 | } |
| 2500 | |
| 2501 | // Render into the big window |
| 2502 | void GameDrawMainView() { |
| 2503 | extern bool Guided_missile_smallview; // smallviews.cpp |
| 2504 | |
| 2505 | bool rear_view = 0; |
| 2506 | object *save_view; |
| 2507 | |
| 2508 | // Start rendering |
| 2509 | StartFrame(false); |
| 2510 | |
| 2511 | // Set guided view |
| 2512 | if (!Cinematic_inuse && Players[Player_num].guided_obj != NULL && !Guided_missile_smallview) { |
| 2513 | save_view = Viewer_object; |
| 2514 | Viewer_object = Players[Player_num].guided_obj; |
| 2515 | |
| 2516 | } else if ((Viewer_object == Player_object) && (Players[Player_num].flags & PLAYER_FLAGS_REARVIEW)) |
| 2517 | rear_view = 1; |
| 2518 | |
| 2519 | // Draw the world |
| 2520 | Rendering_main_view = true; |
| 2521 | GameRenderWorld(Viewer_object, &Viewer_object->pos, Viewer_object->roomnum, &Viewer_object->orient, Render_zoom, |
| 2522 | rear_view); |
| 2523 | Rendering_main_view = false; |
| 2524 | |
| 2525 | // Restore viewer object if guided |
| 2526 | if (!Cinematic_inuse && Players[Player_num].guided_obj != NULL && !Guided_missile_smallview) |
| 2527 | Viewer_object = save_view; |
| 2528 | |
| 2529 | // Room changes |
| 2530 | DoRoomChangeFrame(); |
| 2531 | |
| 2532 | // Draw Matcen Effects |
| 2533 | DoMatcensRenderFrame(); |
| 2534 | |
| 2535 | // Draw any render events |
| 2536 | ProcessRenderEvents(); |
| 2537 | |
| 2538 | // We're done with this window |
| 2539 | EndFrame(); |
| 2540 | } |
| 2541 | |
| 2542 | // Added by Samir |
| 2543 | #define HUD_RENDER_ZOOM 0.56f |
| 2544 | |
| 2545 | // Do Cockpit/Hud |
| 2546 | void GameDrawHud() { |
| 2547 | // Start frame and 3d frame |
| 2548 | StartFrame(false); |
| 2549 | g3_StartFrame(&Viewer_object->pos, &Viewer_object->orient, HUD_RENDER_ZOOM); |
| 2550 | |
| 2551 | // render HUD |
| 2552 | RenderHUDFrame(); |
| 2553 | |
| 2554 | // End frame |
| 2555 | g3_EndFrame(); |
| 2556 | EndFrame(); |
| 2557 | |
| 2558 | // render auxillary consoles |
| 2559 | StartFrame(0, 0, Max_window_w, Max_window_h, false); |
| 2560 | g3_StartFrame(&Viewer_object->pos, &Viewer_object->orient, HUD_RENDER_ZOOM); |
| 2561 | |
| 2562 | RenderAuxHUDFrame(); |
| 2563 | |
| 2564 | // End frame |
| 2565 | g3_EndFrame(); |
| 2566 | EndFrame(); |
| 2567 | } |
| 2568 | |
| 2569 | // Draw a frame of the game |
| 2570 | void GameRenderFrame(void) { |
| 2571 | bool no_render = false; |
| 2572 | AI_NumRendered = 0; |
| 2573 | AI_NumHostileAlert = 0; |
| 2574 | |
| 2575 | if (Dedicated_server) |
| 2576 | return; |
| 2577 | |
| 2578 | #ifndef RELEASE |
| 2579 | Mine_depth = 0; |
| 2580 | #endif |
| 2581 | |
| 2582 | // increase our timing for the powerup sparkles, used globally by all |
| 2583 | Last_powerup_sparkle_time += Frametime; |
| 2584 | |
| 2585 | PreUpdateAllLightGlows(); |
| 2586 | |
| 2587 | // Don't render if receiving data |
| 2588 | if ((Game_mode & GM_MULTI) && NetPlayers[Player_num].sequence != NETSEQ_PLAYING) { |
| 2589 | no_render = true; |
| 2590 | ShowProgressScreen(TXT_RECEIVINGDATA, NULL, 0); |
| 2591 | } |
| 2592 | |
| 2593 | // Generate "shaken" view for player |
| 2594 | if (!Game_paused) |
| 2595 | ShakePlayer(); |
| 2596 | |
| 2597 | rend_SetZBufferState(1); |
| 2598 | rend_SetZBufferWriteMask(1); |
| 2599 | |
| 2600 | // clear screen if needed |
| 2601 | if (Clear_screen) { |
| 2602 | StartFrame(0, 0, Max_window_w, Max_window_h, false); |
| 2603 | rend_ClearScreen(GR_BLACK); |
| 2604 | EndFrame(); |
| 2605 | Clear_screen--; |
| 2606 | } |
| 2607 | |
| 2608 | // Render the mine |
| 2609 | if (!no_render) { |
| 2610 | // render preliminary hud view (for dirty rectangles) |
| 2611 | if (Small_hud_flag) { // small hud flag is set in RenderHUDFrame in GameDrawHud. |
| 2612 | StartFrame(0, 0, Max_window_w, Max_window_h, false); |
| 2613 | RenderPreHUDFrame(); |
| 2614 | EndFrame(); |
| 2615 | } |
| 2616 | |
| 2617 | // Draw the big 3d view |
| 2618 | GameDrawMainView(); |
| 2619 | |
| 2620 | // Do the small views. These should be before GameDrawHUD() for the small windows |
| 2621 | DrawSmallViews(); |
| 2622 | |
| 2623 | // Do Cockpit/Hud |
| 2624 | if (!HUD_disabled) |
| 2625 | GameDrawHud(); |
| 2626 | |
| 2627 | // Render Ingame Cinematics |
| 2628 | Cinematic_RenderFrame(); |
| 2629 | |
| 2630 | // Process the debug visual graph |
| 2631 | DebugGraph_Render(); |
| 2632 | |
| 2633 | if (Display_renderer_stats) { |
| 2634 | // display some rendering stats |
| 2635 | tRendererStats stats; |
| 2636 | rend_GetStatistics(&stats); |
| 2637 | grtext_SetFont(HUD_FONT); |
| 2638 | |
| 2639 | char buffer[128]; |
| 2640 | int x, y, height; |
| 2641 | |
| 2642 | x = 15; |
| 2643 | y = 240; |
| 2644 | StartFrame(0, 0, Game_window_w, Game_window_h); |
| 2645 | rend_StartFrame(0, 0, Game_window_w, Game_window_h, 0); |
| 2646 | height = grfont_GetHeight(HUD_FONT) + 1; |
| 2647 | snprintf(buffer, sizeof(buffer), "Polys=%d", stats.poly_count); |
| 2648 | RenderHUDText(GR_RGB(255, 40, 40), 255, 1, x, y, buffer); |
| 2649 | y += height; |
| 2650 | snprintf(buffer, sizeof(buffer), "Verts=%d", stats.vert_count); |
| 2651 | RenderHUDText(GR_RGB(255, 40, 40), 255, 1, x, y, buffer); |
| 2652 | y += height; |
| 2653 | snprintf(buffer, sizeof(buffer), "Uploads=%d", stats.texture_uploads); |
| 2654 | RenderHUDText(GR_RGB(255, 40, 40), 255, 1, x, y, buffer); |
| 2655 | y += height; |
| 2656 | grtext_Flush(); |
| 2657 | EndFrame(); |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | // Do UI Frame |
| 2662 | if (Game_interface_mode == GAME_INTERFACE && !Menu_interface_mode) { |
| 2663 | DoUIFrameWithoutInput(); |
| 2664 | rend_Flip(); |
| 2665 | } |
| 2666 | |
| 2667 | // Restore normal view |
| 2668 | if (!Game_paused) |
| 2669 | UnshakePlayer(); |
| 2670 | |
| 2671 | // Done with the dynamic lights |
| 2672 | ClearDynamicLightmaps(); |
| 2673 | |
| 2674 | // Increment frame count |
| 2675 | FrameCount++; |
| 2676 | frames_one_second++; |
| 2677 | |
| 2678 | // Update our glows |
| 2679 | PostUpdateAllLightGlows(); |
| 2680 | |
| 2681 | // Reset our powerup sparkle time if it has overflowed |
| 2682 | while (Last_powerup_sparkle_time >= POWERUP_SPARKLE_INTERVAL) { |
| 2683 | Last_powerup_sparkle_time -= POWERUP_SPARKLE_INTERVAL; |
| 2684 | } |
| 2685 | } |
| 2686 | |
| 2687 | void GameProcessMusic() { |
| 2688 | // the last game state in the sequencer. |
| 2689 | extern tGameState Last_game_state; |
| 2690 | |
| 2691 | if (Last_game_state == GAMESTATE_LVLSTART) { |
| 2692 | Game_music_info.started_level = true; |
| 2693 | } else { |
| 2694 | Game_music_info.started_level = false; |
| 2695 | } |
| 2696 | |
| 2697 | // player_damaged set in damage.cpp DecreasePlayerShields. |
| 2698 | |
| 2699 | if ((Players[Player_num].flags & PLAYER_FLAGS_DYING) || (Players[Player_num].flags & PLAYER_FLAGS_DEAD)) { |
| 2700 | Game_music_info.player_dead = true; |
| 2701 | } else { |
| 2702 | Game_music_info.player_dead = false; |
| 2703 | } |
| 2704 | |
| 2705 | Game_music_info.n_hostiles = AI_NumHostileAlert; |
| 2706 | Game_music_info.frametime = Frametime; |
| 2707 | |
| 2708 | D3MusicDoFrame(&Game_music_info); |
| 2709 | } |
| 2710 | |
| 2711 | // variables for Frametime system |
| 2712 | |
| 2713 | // timer_GetMSTime() |
| 2714 | // float last_timer=0.0; |
| 2715 | int timer_paused = 0; |
| 2716 | |
| 2717 | // Stop the Frametime clock |
| 2718 | void StopTime() { |
| 2719 | if (!timer_paused) { |
| 2720 | last_timer = timer_GetMSTime() - last_timer; |
| 2721 | if (last_timer < 0) { |
| 2722 | // Int3(); |
| 2723 | last_timer = 0; |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | timer_paused++; |
| 2728 | } |
| 2729 | |
| 2730 | // Restart the Frametime clock |
| 2731 | void StartTime() { |
| 2732 | if (timer_paused == 0) |
| 2733 | return; |
| 2734 | |
| 2735 | timer_paused--; |
| 2736 | |
| 2737 | ASSERT(timer_paused >= 0); |
| 2738 | |
| 2739 | if (!timer_paused) |
| 2740 | last_timer = timer_GetMSTime() - last_timer; |
| 2741 | } |
| 2742 | |
| 2743 | float Min_frametime = 500; |
| 2744 | float Max_frametime = 0; |
| 2745 | float Avg_frametime = 0; |
| 2746 | uint32_t Frames_counted = 0; |
| 2747 | |
| 2748 | // Compute how long last frame took |
| 2749 | void CalcFrameTime(void) { |
| 2750 | int64_t current_timer; |
| 2751 | |
| 2752 | if (timer_paused) |
| 2753 | return; |
| 2754 | |
| 2755 | current_timer = timer_GetMSTime(); |
| 2756 | if (current_timer >= last_timer) { |
| 2757 | Frametime = static_cast<float>(current_timer - last_timer) / 1000.0f; |
| 2758 | } else { |
| 2759 | Frametime = 0.0f; |
| 2760 | } |
| 2761 | |
| 2762 | last_timer = current_timer; |
| 2763 | |
| 2764 | if (Min_frametime > Frametime) { |
| 2765 | mprintf(0, "This was the fastest frame yet!\n"); |
| 2766 | Min_frametime = Frametime - Demo_frame_ofs; |
| 2767 | } else if (Max_frametime < Frametime) { |
| 2768 | mprintf(0, "This was the slowest frame yet!\n"); |
| 2769 | Max_frametime = Frametime - Demo_frame_ofs; |
| 2770 | } |
| 2771 | Frames_counted++; |
| 2772 | Avg_frametime += (Frametime - Demo_frame_ofs); |
| 2773 | } |
| 2774 | |
| 2775 | // called before first call to StopTime, StartTime or CalcFrameTime |
| 2776 | void InitFrameTime(void) { |
| 2777 | |
| 2778 | if (timer_paused) { |
| 2779 | mprintf(1, "Timer paused in InitFrameTime()\n"); |
| 2780 | } |
| 2781 | last_timer = timer_GetMSTime(); |
| 2782 | timer_paused = 0; |
| 2783 | } |
| 2784 | |
| 2785 | // Pauses game |
| 2786 | void PauseGame() { |
| 2787 | mprintf(0, "Game paused.\n"); |
| 2788 | Game_paused = true; |
| 2789 | |
| 2790 | D3MusicPause(); |
| 2791 | Sound_system.PauseSounds(); |
| 2792 | StopTime(); |
| 2793 | } |
| 2794 | |
| 2795 | // resumes game operation. |
| 2796 | void ResumeGame() { |
| 2797 | StartTime(); |
| 2798 | Game_paused = false; |
| 2799 | Sound_system.ResumeSounds(); |
| 2800 | D3MusicResume(); |
| 2801 | mprintf(0, "Game resumed.\n"); |
| 2802 | } |
| 2803 | |
| 2804 | // Data for terrain sound |
| 2805 | terrain_sound_band Terrain_sound_bands[NUM_TERRAIN_SOUND_BANDS]; |
| 2806 | int Terrain_sound_handles[NUM_TERRAIN_SOUND_BANDS]; |
| 2807 | float Terrain_sound_fade; // used for transitions between inside & outside |
| 2808 | |
| 2809 | #define FADE_TIME 1.0 |
| 2810 | |
| 2811 | // Update the sound on the terrain |
| 2812 | void UpdateTerrainSound() { |
| 2813 | // Update fade in/out (for inside/outside transitions) |
| 2814 | if (OBJECT_OUTSIDE(Player_object)) { |
| 2815 | if (Terrain_sound_fade < 1.0) { // fading in |
| 2816 | Terrain_sound_fade += Frametime / FADE_TIME; |
| 2817 | if (Terrain_sound_fade > 1.0) |
| 2818 | Terrain_sound_fade = 1.0; |
| 2819 | } |
| 2820 | } else { |
| 2821 | if (Terrain_sound_fade > 0.0) { // fading out |
| 2822 | Terrain_sound_fade -= Frametime / FADE_TIME; |
| 2823 | if (Terrain_sound_fade < 0.0) |
| 2824 | Terrain_sound_fade = 0.0; |
| 2825 | } else |
| 2826 | return; // already faded out |
| 2827 | } |
| 2828 | |
| 2829 | // Get player altitude |
| 2830 | int alt = Player_object->pos.y / TERRAIN_HEIGHT_INCREMENT; |
| 2831 | if (alt > 255) { |
| 2832 | alt = 255; |
| 2833 | } |
| 2834 | |
| 2835 | // Update each sound |
| 2836 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) { |
| 2837 | terrain_sound_band *tb = &Terrain_sound_bands[b]; |
| 2838 | if (tb->sound_index != -1) { |
| 2839 | float volume; |
| 2840 | |
| 2841 | if ((alt < tb->low_alt) || (alt > tb->high_alt)) |
| 2842 | volume = 0.0; |
| 2843 | else |
| 2844 | volume = |
| 2845 | tb->low_volume + ((tb->high_volume - tb->low_volume) * (alt - tb->low_alt) / (tb->high_alt - tb->low_alt)); |
| 2846 | |
| 2847 | Sound_system.Update2dSound(Terrain_sound_handles[b], volume * Terrain_sound_fade, 0.0); |
| 2848 | } |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | // Clear out all the terrain sound bands |
| 2853 | void ClearTerrainSound() { |
| 2854 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) { |
| 2855 | Terrain_sound_bands[b].sound_index = -1; |
| 2856 | Terrain_sound_bands[b].low_alt = 0; |
| 2857 | Terrain_sound_bands[b].high_alt = 0; |
| 2858 | Terrain_sound_bands[b].low_volume = 0.0; |
| 2859 | Terrain_sound_bands[b].high_volume = 0.0; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | // Starts the sound on the terrain |
| 2864 | void StartTerrainSound() { |
| 2865 | // Set to be full on or full off |
| 2866 | if (OBJECT_OUTSIDE(Player_object)) |
| 2867 | Terrain_sound_fade = 1.0; |
| 2868 | else |
| 2869 | Terrain_sound_fade = Frametime / FADE_TIME; // will fade to zero first time |
| 2870 | |
| 2871 | // Start the sounds |
| 2872 | for (int b = 0; b < NUM_TERRAIN_SOUND_BANDS; b++) { |
| 2873 | terrain_sound_band *tb = &Terrain_sound_bands[b]; |
| 2874 | if (tb->sound_index != -1) { |
| 2875 | Terrain_sound_handles[b] = Sound_system.Play2dSound(tb->sound_index); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | // Set the volumes |
| 2880 | UpdateTerrainSound(); |
| 2881 | } |
| 2882 | |
| 2883 | // The main loop for D3. It renders, gets input, etc. for one frame |
| 2884 | extern bool Skip_render_game_frame; |
| 2885 | void GameFrame(void) { |
| 2886 | #ifdef USE_RTP |
| 2887 | INT64 curr_time; |
| 2888 | #endif |
| 2889 | |
| 2890 | bool is_game_idle = !Descent->active(); |
| 2891 | |
| 2892 | if (Tracking_FVI) { |
| 2893 | mprintf(0, "Beginning frame!\n"); |
| 2894 | } |
| 2895 | |
| 2896 | // Begin Gameloop stuff |
| 2897 | Physics_normal_counter = 0; |
| 2898 | Physics_normal_looping_counter = 0; |
| 2899 | Physics_walking_counter = 0; |
| 2900 | Physics_walking_looping_counter = 0; |
| 2901 | Physics_vis_counter = 0; |
| 2902 | |
| 2903 | FVI_counter = 0; |
| 2904 | FVI_room_counter = 0; |
| 2905 | |
| 2906 | #ifdef _DEBUG |
| 2907 | // Dump networking stats to virtual window |
| 2908 | tNetworkStatus netstat; |
| 2909 | static tNetworkStatus old_netstat; |
| 2910 | static bool netstat_init = false; |
| 2911 | static float netstat_time = 0; |
| 2912 | |
| 2913 | nw_GetNetworkStats(&netstat); |
| 2914 | mprintf_at(5, 0, 0, "TCP/IP Network Stats:"); |
| 2915 | mprintf_at(5, 1, 0, "TCP: tx: %d/%d rtx: %d/%d rx: %d/%d", netstat.tcp_total_packets_sent, |
| 2916 | netstat.tcp_total_bytes_sent, netstat.tcp_total_packets_resent, netstat.tcp_total_bytes_resent, |
| 2917 | netstat.tcp_total_packets_rec, netstat.tcp_total_bytes_rec); |
| 2918 | mprintf_at(5, 2, 0, "UDP: tx: %d/%d rx: %d/%d", netstat.udp_total_packets_sent, netstat.udp_total_bytes_sent, |
| 2919 | netstat.udp_total_packets_rec, netstat.udp_total_bytes_rec); |
| 2920 | |
| 2921 | if (!netstat_init) { |
| 2922 | netstat_time = timer_GetTime(); |
| 2923 | |
| 2924 | old_netstat = netstat; |
| 2925 | netstat_init = true; |
| 2926 | } else { |
| 2927 | float newt = timer_GetTime(); |
| 2928 | if (netstat_time + 0.5f <= newt) { |
| 2929 | // time to update |
| 2930 | float tcp_rx, tcp_rtx, tcp_tx; |
| 2931 | float udp_rx, udp_tx; |
| 2932 | float time_diff = newt - netstat_time; |
| 2933 | |
| 2934 | tcp_rx = ((float)(netstat.tcp_total_bytes_rec - old_netstat.tcp_total_bytes_rec)) / time_diff; |
| 2935 | tcp_tx = ((float)(netstat.tcp_total_bytes_sent - old_netstat.tcp_total_bytes_sent)) / time_diff; |
| 2936 | tcp_rtx = ((float)(netstat.tcp_total_bytes_resent - old_netstat.tcp_total_bytes_resent)) / time_diff; |
| 2937 | |
| 2938 | udp_rx = ((float)(netstat.udp_total_bytes_rec - old_netstat.udp_total_bytes_rec)) / time_diff; |
| 2939 | udp_tx = ((float)(netstat.udp_total_bytes_sent - old_netstat.udp_total_bytes_sent)) / time_diff; |
| 2940 | |
| 2941 | mprintf_at(5, 3, 0, "TCP/s: TX: % 5.1f RTX: % 5.1f RX: % 5.1f", tcp_tx, tcp_rtx, tcp_rx); |
| 2942 | mprintf_at(5, 4, 0, "UDP/s: TX: % 5.1f RX: % 5.1f", udp_tx, udp_rx); |
| 2943 | |
| 2944 | old_netstat = netstat; |
| 2945 | netstat_time = newt; |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | #endif |
| 2950 | // clear out music struct |
| 2951 | memset(&Game_music_info, 0, sizeof(Game_music_info)); |
| 2952 | |
| 2953 | // if in user interface, clear screen every frame for small game windows. |
| 2954 | if (Game_interface_mode != GAME_INTERFACE || Menu_interface_mode) |
| 2955 | Clear_screen = 4; |
| 2956 | |
| 2957 | // Setup sound for new frame |
| 2958 | Sound_system.BeginSoundFrame(); |
| 2959 | UpdateVoices(); |
| 2960 | |
| 2961 | #ifdef USE_RTP |
| 2962 | RTP_GETCLOCK(curr_time); |
| 2963 | #endif |
| 2964 | |
| 2965 | if ((!Game_paused) || (Demo_do_one_frame)) { |
| 2966 | // if we are recording a demo, all moved objects will be written |
| 2967 | if (!Skip_render_game_frame) { |
| 2968 | DemoWriteChangedObjects(); |
| 2969 | } |
| 2970 | // Demo Frame (do this first so all subsequent demo items are marked for this frame) |
| 2971 | if (!Skip_render_game_frame) { |
| 2972 | DemoStartNewFrame(); |
| 2973 | } |
| 2974 | if (Demo_flags == DF_PLAYBACK) { |
| 2975 | DemoFrame(); |
| 2976 | } |
| 2977 | |
| 2978 | if (!is_game_idle) { |
| 2979 | // Get and process keys |
| 2980 | RTP_tSTARTTIME(processkeys_time, curr_time); |
| 2981 | ProcessKeys(); |
| 2982 | ProcessButtons(); |
| 2983 | RTP_tENDTIME(processkeys_time, curr_time); |
| 2984 | } |
| 2985 | |
| 2986 | // Global AI Frame Stuff -- must be before ObjMoveAll |
| 2987 | RTP_tSTARTTIME(aiframeall_time, curr_time); |
| 2988 | if (DoAI) { |
| 2989 | AIFrameAll(); |
| 2990 | } |
| 2991 | a_life.DoFrame(); |
| 2992 | RTP_tENDTIME(aiframeall_time, curr_time); |
| 2993 | |
| 2994 | // ApplyShadowsToRooms (); |
| 2995 | |
| 2996 | // Move objects for this frame |
| 2997 | RTP_tSTARTTIME(objframe_time, curr_time); |
| 2998 | ObjDoFrameAll(); |
| 2999 | RTP_tENDTIME(objframe_time, curr_time); |
| 3000 | |
| 3001 | RTP_tSTARTTIME(matcenframe_time, curr_time); |
| 3002 | DoMatcensFrame(); |
| 3003 | RTP_tENDTIME(matcenframe_time, curr_time); |
| 3004 | |
| 3005 | // Checks for goal completion |
| 3006 | RTP_tSTARTTIME(levelgoal_time, curr_time); |
| 3007 | Level_goals.DoFrame(); |
| 3008 | RTP_tENDTIME(levelgoal_time, curr_time); |
| 3009 | |
| 3010 | // Do doorways |
| 3011 | RTP_tSTARTTIME(doorframe_time, curr_time); |
| 3012 | DoorwayDoFrame(); |
| 3013 | RTP_tENDTIME(doorframe_time, curr_time); |
| 3014 | |
| 3015 | // Do player frame |
| 3016 | RTP_tSTARTTIME(playerframe_time, curr_time); |
| 3017 | DoPlayerFrame(); |
| 3018 | RTP_tENDTIME(playerframe_time, curr_time); |
| 3019 | |
| 3020 | // Weather frame |
| 3021 | RTP_tSTARTTIME(weatherframe_time, curr_time); |
| 3022 | DoWeatherForFrame(); |
| 3023 | RTP_tENDTIME(weatherframe_time, curr_time); |
| 3024 | |
| 3025 | // Ambient sounds |
| 3026 | RTP_tSTARTTIME(ambsound_frame_time, curr_time); |
| 3027 | DoAmbientSounds(); |
| 3028 | RTP_tENDTIME(ambsound_frame_time, curr_time); |
| 3029 | |
| 3030 | // Terrain sound |
| 3031 | UpdateTerrainSound(); |
| 3032 | |
| 3033 | // Call the interval script for the level script |
| 3034 | //@$-D3XExecScript(Current_level->d3xthread, Current_mission.cur_level, REF_LEVELTYPE, EVT_INTERVAL, 0, 0); |
| 3035 | tOSIRISEventInfo ei; |
| 3036 | ei.evt_interval.frame_time = Frametime; |
| 3037 | ei.evt_interval.game_time = Gametime; |
| 3038 | Osiris_CallLevelEvent(EVT_INTERVAL, &ei); |
| 3039 | Osiris_ProcessTimers(); |
| 3040 | |
| 3041 | // Process any in-game cinematics |
| 3042 | Cinematic_Frame(); |
| 3043 | |
| 3044 | } else { |
| 3045 | Sleep(3); |
| 3046 | } |
| 3047 | |
| 3048 | // do music always. |
| 3049 | RTP_tSTARTTIME(musicframe_time, curr_time); |
| 3050 | GameProcessMusic(); |
| 3051 | RTP_tENDTIME(musicframe_time, curr_time); |
| 3052 | |
| 3053 | if ((Demo_paused) && (Demo_flags == DF_PLAYBACK) && !is_game_idle) { |
| 3054 | Demo_do_one_frame = false; |
| 3055 | ProcessKeys(); |
| 3056 | } |
| 3057 | |
| 3058 | // Always do multiplayer frames before render frame |
| 3059 | // |
| 3060 | // Do multiplayer stuff |
| 3061 | RTP_tSTARTTIME(multiframe_time, curr_time); |
| 3062 | MultiDoFrame(); |
| 3063 | RTP_tENDTIME(multiframe_time, curr_time); |
| 3064 | |
| 3065 | #ifdef USE_RTP |
| 3066 | RTP_GETCLOCK(curr_time); // update the current time, since something has happened since ENDFTIME |
| 3067 | #endif |
| 3068 | |
| 3069 | if (!is_game_idle) { |
| 3070 | RTP_tSTARTTIME(renderframe_time, curr_time); |
| 3071 | if (!Skip_render_game_frame) { |
| 3072 | // Render the frame |
| 3073 | GameRenderFrame(); |
| 3074 | } |
| 3075 | RTP_tENDTIME(renderframe_time, curr_time); |
| 3076 | } |
| 3077 | |
| 3078 | if (!Game_paused) { |
| 3079 | // Do pending events |
| 3080 | RTP_tSTARTTIME(normalevent_time, curr_time); |
| 3081 | ProcessNormalEvents(); |
| 3082 | RTP_tENDTIME(normalevent_time, curr_time); |
| 3083 | |
| 3084 | // float start_delay = timer_GetTime(); |
| 3085 | // Slow down the game if the user asked us to |
| 3086 | |
| 3087 | int64_t current_timer; |
| 3088 | uint32_t sleeptime; |
| 3089 | current_timer = timer_GetMSTime(); |
| 3090 | if ((current_timer - last_timer) < Min_allowed_frametime) { |
| 3091 | sleeptime = (uint32_t)Min_allowed_frametime - (current_timer - last_timer); |
| 3092 | // mprintf(0,"Sleeping for %d ms\n",sleeptime); |
| 3093 | Sleep(sleeptime); |
| 3094 | } |
| 3095 | |
| 3096 | static int graph_id = -2; |
| 3097 | if (graph_id == -2) { |
| 3098 | graph_id = DebugGraph_Add((float)0.0f, (float)260.0f, "Framerate"); |
| 3099 | } |
| 3100 | if (graph_id >= 0) { |
| 3101 | float fps; |
| 3102 | |
| 3103 | if (Frametime > 0) { |
| 3104 | fps = 1.0 / Frametime; |
| 3105 | DebugGraph_Update(graph_id, fps); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | // Compute how long frame took |
| 3110 | CalcFrameTime(); |
| 3111 | |
| 3112 | // Update Gametime |
| 3113 | Gametime += Frametime; |
| 3114 | } |
| 3115 | |
| 3116 | // End Gameloop Loop stuff |
| 3117 | Sound_system.EndSoundFrame(); |
| 3118 | DoDestroyedLightsForFrame(); |
| 3119 | |
| 3120 | // Clear lod stuff |
| 3121 | ClearLODOffs(); |
| 3122 | |
| 3123 | static int fvi_graph_id = -2; |
| 3124 | if (fvi_graph_id == -2) { |
| 3125 | fvi_graph_id = DebugGraph_Add(0, 1000, "FVI Calls"); |
| 3126 | } |
| 3127 | if (fvi_graph_id >= 0) { |
| 3128 | DebugGraph_Update(fvi_graph_id, FVI_counter); |
| 3129 | } |
| 3130 | |
| 3131 | #ifdef USE_RTP |
| 3132 | RTP_RECORDVALUE(frame_time, Frametime); |
| 3133 | rtp_RecordFrame(); |
| 3134 | |
| 3135 | /* |
| 3136 | if (frame_info.ai_time>.1) |
| 3137 | mprintf(0,"NOTE: AI frame took longer than .1 seconds! %f\n",frame_info.ai_time); |
| 3138 | if (frame_info.render_time>.1) |
| 3139 | mprintf(0,"NOTE: Render frame took longer than .1 seconds! %f\n",frame_info.render_time); |
| 3140 | if (frame_info.multi_time>.1) |
| 3141 | mprintf(0,"NOTE: Multi frame took longer than .1 seconds! %f\n",frame_info.multi_time); |
| 3142 | if (frame_info.obj_time>.1) |
| 3143 | mprintf(0,"NOTE: Object frame took longer than .1 seconds! %f\n",frame_info.obj_time); |
| 3144 | */ |
| 3145 | #endif |
| 3146 | |
| 3147 | mprintf_at(1, 0, 39, "Pn %05d, L %05d", Physics_normal_counter, Physics_normal_looping_counter); |
| 3148 | mprintf_at(1, 1, 39, "Pw %05d, L %05d", Physics_walking_counter, Physics_walking_looping_counter); |
| 3149 | mprintf_at(1, 2, 39, "Pv %05d", Physics_vis_counter); |
| 3150 | mprintf_at(1, 3, 39, "Fc %05d, R %05d", FVI_counter, FVI_room_counter); |
| 3151 | |
| 3152 | #ifdef D3_FAST |
| 3153 | if (FrameCount > 20) |
| 3154 | SetFunctionMode(MENU_MODE); |
| 3155 | else { |
| 3156 | int key; |
| 3157 | int rand_num = ps_rand() % 4; |
| 3158 | |
| 3159 | if (rand_num == 0) |
| 3160 | key = KEY_LCTRL; |
| 3161 | else if (rand_num == 1) |
| 3162 | key = KEY_SPACEBAR; |
| 3163 | else if (rand_num == 2) |
| 3164 | key = KEY_A; |
| 3165 | else |
| 3166 | key = KEY_Z; |
| 3167 | |
| 3168 | ddio_UpdateKeyState(key, timer_GetTime(), 1); |
| 3169 | ddio_UpdateKeyState(key, timer_GetTime() + .5f, 0); |
| 3170 | } |
| 3171 | #endif |
| 3172 | |
| 3173 | if (Tracking_FVI) { |
| 3174 | mprintf(0, "Ending frame!\n"); |
| 3175 | } |
| 3176 | |
| 3177 | if (!is_game_idle) { |
| 3178 | Descent->defer(); |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | // game menu functions |
| 3183 | void StartGameMenu() { |
| 3184 | SetUICallback(GameFrame); |
| 3185 | SuspendControls(); |
| 3186 | Menu_interface_mode = true; |
| 3187 | |
| 3188 | // reset bail flag. |
| 3189 | Multi_bail_ui_menu = false; |
| 3190 | |
| 3191 | if (!(Game_mode & GM_MULTI)) { |
| 3192 | PauseGame(); |
| 3193 | } |
| 3194 | |
| 3195 | ui_ShowCursor(); |
| 3196 | } |
| 3197 | |
| 3198 | void EndGameMenu() { |
| 3199 | ui_HideCursor(); |
| 3200 | |
| 3201 | if (!(Game_mode & GM_MULTI)) { |
| 3202 | ResumeGame(); |
| 3203 | } |
| 3204 | |
| 3205 | Menu_interface_mode = false; |
| 3206 | |
| 3207 | ResumeControls(); |
| 3208 | SetUICallback(NULL); |
| 3209 | Clear_screen = 4; |
| 3210 | } |