| 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/game.cpp $ |
| 21 | * $Revision: 190 $ |
| 22 | * $Date: 9/14/01 4:47p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Game management |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/game.cpp $ |
| 28 | * |
| 29 | * 190 9/14/01 4:47p Matt |
| 30 | * Cleaned up problems when screen bit depth set to 32. |
| 31 | * |
| 32 | * 189 10/21/99 3:42p Matt |
| 33 | * Mac merge |
| 34 | * |
| 35 | * 188 10/14/99 1:08p Chris |
| 36 | * Added another custom bounce force field texture slot |
| 37 | * |
| 38 | * 187 10/13/99 2:19p Chris |
| 39 | * Added the ability to disable wind for powerups on a level |
| 40 | * |
| 41 | * 186 10/13/99 10:41a Chris |
| 42 | * Added 'special forcefields' that have custom bounce factors |
| 43 | * |
| 44 | * 185 10/08/99 4:28p Chris |
| 45 | * Added the forcefield and glass breaking override options |
| 46 | * |
| 47 | * 184 8/11/99 5:32p Jeff |
| 48 | * changes to fix addon tablefile support so it works correctly |
| 49 | * |
| 50 | * 183 5/07/99 7:22p Jason |
| 51 | * changes for cards with low videomemory |
| 52 | * |
| 53 | * 181 5/03/99 2:07a Samir |
| 54 | * make sure Frametime is not 0 in GetFPS. |
| 55 | * |
| 56 | * 180 5/02/99 11:04p Matt |
| 57 | * Cleaned up HUD font code, now that we have only two sizes of HUD fonts. |
| 58 | * |
| 59 | * 179 5/01/99 1:58a Samir |
| 60 | * game window width and height get properly saved since we always used to |
| 61 | * reset the width and height whenever SM_GAME was passed to |
| 62 | * SetScreenMode. The only time it should change is when we change |
| 63 | * resolutions. |
| 64 | * |
| 65 | * 178 4/27/99 7:02p Samir |
| 66 | * took out annoying mprintf. |
| 67 | * |
| 68 | * 177 4/27/99 5:18p Samir |
| 69 | * properly handle switch into cinematic resolution if previous screen |
| 70 | * mode was SM_NULL. |
| 71 | * |
| 72 | * 176 4/26/99 4:32p Samir |
| 73 | * suspend controls when leaving game. |
| 74 | * |
| 75 | * 175 4/26/99 11:33a Samir |
| 76 | * switch resolution of screen for cinematic under glide in release only. |
| 77 | * |
| 78 | * 174 4/23/99 10:22p Kevin |
| 79 | * Fixed savegame doorways bug! |
| 80 | * |
| 81 | * 173 4/14/99 2:50a Jeff |
| 82 | * fixed some case mismatched #includes |
| 83 | * |
| 84 | * 172 4/09/99 7:04p Jason |
| 85 | * changed some texture defines |
| 86 | * |
| 87 | * 171 4/08/99 5:59p Jason |
| 88 | * check for 16bit mode when initializing renderer |
| 89 | * |
| 90 | * 170 4/05/99 5:25p Samir |
| 91 | * Glide exempt from cinematics resolution switch. |
| 92 | * |
| 93 | * 169 4/02/99 11:32p Jeff |
| 94 | * able to turn off IGC in debug mode. Better handling of cinematics |
| 95 | * quick exit if playing via alt-p |
| 96 | * |
| 97 | * 168 4/02/99 3:03p Samir |
| 98 | * shut down renderer for full screen cinematics. |
| 99 | * |
| 100 | * 167 3/29/99 7:29p Jason |
| 101 | * made renderer handle default resolution more gracefully |
| 102 | * |
| 103 | * 166 3/19/99 12:54p Jeff |
| 104 | * base support for requesting the number of teams for a multiplayer game |
| 105 | * |
| 106 | * 165 3/09/99 12:04p Samir |
| 107 | * resize screen when changing resolutions in game to full screen. |
| 108 | * |
| 109 | * 164 3/05/99 5:43p Luke |
| 110 | * Samir: use rend width instead of scr_width to determine font |
| 111 | * resolution. |
| 112 | * |
| 113 | * 163 3/02/99 6:25p Samir |
| 114 | * more hires font madness. |
| 115 | * |
| 116 | * 162 2/28/99 3:23a Samir |
| 117 | * added superhires fonts. |
| 118 | * |
| 119 | * 161 2/25/99 8:54p Jeff |
| 120 | * Inventory supports level change persistant items. Inventory supports |
| 121 | * time-out objects. Inventory Reset changed (takes a level of reset |
| 122 | * now). Quad lasers stay across level change (single player). Guidebot |
| 123 | * bug fixed (now back in ship on level start). Quads time out when |
| 124 | * spewed. Invulnerability and cloak powerups no longer use game |
| 125 | * event/callbacks, so they can be saved in game saves (moved to |
| 126 | * MakePlayerInvulnerable and MakeObjectInvisible) |
| 127 | * |
| 128 | * 160 2/18/99 11:54a Kevin |
| 129 | * made screenshot filename always use 3 digits |
| 130 | * |
| 131 | * 159 2/17/99 7:05p Kevin |
| 132 | * OEM build setup |
| 133 | * |
| 134 | * 158 2/17/99 2:45p Kevin |
| 135 | * Adde movie making capabilities to the demo playback system |
| 136 | * |
| 137 | * 157 2/16/99 12:00p Samir |
| 138 | * added new video resolution swtich test. |
| 139 | * |
| 140 | * 156 2/15/99 7:48p Jeff |
| 141 | * new pilot file class and read/write system checked in...should be more |
| 142 | * robust than old |
| 143 | * |
| 144 | * 155 2/15/99 3:10p Kevin |
| 145 | * fixed dumb bug with shutting down renderer |
| 146 | * |
| 147 | * 154 2/12/99 6:46p Jeff |
| 148 | * fixed start frame/end frame stack bug |
| 149 | * |
| 150 | * 153 2/11/99 1:21a Jeff |
| 151 | * made function to switch a player into AI mode, converted code that did |
| 152 | * this to call this function. |
| 153 | * |
| 154 | * 152 2/10/99 2:41p Chris |
| 155 | * Added debug info |
| 156 | * |
| 157 | * 151 2/09/99 9:58a Chris |
| 158 | * Massive BOA update :) Terrain happy now. Vis happy now. Sound happy |
| 159 | * now. |
| 160 | * |
| 161 | * 150 2/08/99 7:50p Jeff |
| 162 | * made StartFrame/EndFrame stack based...no longer have to worry about |
| 163 | * preserving current frame settings to restore |
| 164 | * |
| 165 | * 149 2/08/99 12:03a Jeff |
| 166 | * added a function to get the current StartFrame parameters (from last |
| 167 | * call to StartFrame) |
| 168 | * |
| 169 | * 148 2/04/99 12:35p Jeff |
| 170 | * moved cinematic stop to when level is ending, so it will catch it |
| 171 | * before dlls unloaded |
| 172 | * |
| 173 | * 147 2/04/99 11:28a Jeff |
| 174 | * shutdown cinematics when exiting the game |
| 175 | * |
| 176 | * 146 2/01/99 12:57p Jeff |
| 177 | * fixed bug with turning off OF_DESTROYABLE flag in StartEndLevelSequence |
| 178 | * (changing wrong flag) |
| 179 | * |
| 180 | * 145 1/31/99 9:05p Jeff |
| 181 | * removed old boss introduction cinematics...now done in new ingame |
| 182 | * cinematics system |
| 183 | * |
| 184 | * 144 1/31/99 7:25p Matt |
| 185 | * Renamed a bunch of functions to have HUD capitalized |
| 186 | * |
| 187 | * 143 1/29/99 6:29p Samir |
| 188 | * implemented hud scrollback for hud messages. |
| 189 | * |
| 190 | * 142 1/29/99 2:08p Jeff |
| 191 | * localization |
| 192 | * |
| 193 | * 141 1/29/99 12:47p Matt |
| 194 | * Rewrote the doorway system |
| 195 | * |
| 196 | * 140 1/27/99 2:58p Jason |
| 197 | * fixed center small view |
| 198 | * |
| 199 | * 139 1/24/99 3:54a Jeff |
| 200 | * fixed boss-intro cinematic...pretty much complete (besides for the hack |
| 201 | * to get it to face the target) |
| 202 | * |
| 203 | * 138 1/23/99 6:24p Chris |
| 204 | * Max delta velocity!!!!!!!!!! |
| 205 | * |
| 206 | * 137 1/23/99 3:01a Jeff |
| 207 | * tried to get boss intro stuff working |
| 208 | * |
| 209 | * 136 1/22/99 8:44p Chris |
| 210 | * A few small tweaks to the endlevel path stuff |
| 211 | * |
| 212 | * 135 1/22/99 6:53p Chris |
| 213 | * Fixed LoadandBind Aux notify problems, fixed static path problems, |
| 214 | * fixed AIF_FORCE_AWARE Problems, improved path code |
| 215 | * |
| 216 | * 134 1/22/99 3:59p Jason |
| 217 | * added 256x256 textures to help with terrain skies |
| 218 | * |
| 219 | * 133 1/20/99 3:45a Jeff |
| 220 | * updated Boss Introduction sequence functions, all but path following is |
| 221 | * complete |
| 222 | * |
| 223 | * 132 1/15/99 7:52p Chris |
| 224 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 225 | * |
| 226 | * 131 1/10/99 10:23p Jeff |
| 227 | * added initial start/end boss intro function |
| 228 | * |
| 229 | * 130 1/08/99 2:55p Samir |
| 230 | * Ripped out OSIRIS1. |
| 231 | * |
| 232 | * 129 12/30/98 6:51p Matt |
| 233 | * Fixed compile warnings |
| 234 | * |
| 235 | * 128 12/29/98 4:30p Jason |
| 236 | * added add-on data functionality |
| 237 | * |
| 238 | * 127 12/15/98 10:00a Chris |
| 239 | * |
| 240 | * 126 12/14/98 1:07p Chris |
| 241 | * Allowed OSIRIS to change AI types |
| 242 | * |
| 243 | * 125 10/23/98 12:51p Samir |
| 244 | * took out unnecessary calle to SetHudMode. |
| 245 | * |
| 246 | * 124 10/22/98 2:40p Samir |
| 247 | * redid HUD sequencing so multiplayer hud stuff works. |
| 248 | * |
| 249 | * 123 10/21/98 7:04p Samir |
| 250 | * moved init hud and cockpit to init level |
| 251 | * |
| 252 | * 122 10/21/98 5:29p Samir |
| 253 | * set mask controllers at start of game. |
| 254 | * |
| 255 | * 121 10/21/98 11:14a Samir |
| 256 | * added generic code to skip rendering while in game controller config or |
| 257 | * telcom. |
| 258 | * |
| 259 | * 120 10/20/98 7:36p Matt |
| 260 | * At the start of the endlevel sequence, move the player to the first |
| 261 | * node on the path. |
| 262 | * |
| 263 | * 119 10/19/98 2:50p Samir |
| 264 | * added function to cleanup ui windows. |
| 265 | * |
| 266 | * 118 10/17/98 2:46p Jason |
| 267 | * better error string reports |
| 268 | * |
| 269 | * 117 10/16/98 11:55a Kevin |
| 270 | * Made dlls loadable in a hog |
| 271 | * |
| 272 | * 116 10/15/98 10:42a Matt |
| 273 | * Changed _DEBUG/RELEASE inconsistancy with slew |
| 274 | * |
| 275 | * 115 10/14/98 7:30p Matt |
| 276 | * Changed StartEndlevelSeqence to take a time parameter for how long to |
| 277 | * delay before ending the level. |
| 278 | * |
| 279 | * 114 10/14/98 6:39p Samir |
| 280 | * save screen size for game. |
| 281 | * |
| 282 | * 113 10/14/98 4:37p Chris |
| 283 | * Improved endlevel path following again |
| 284 | * |
| 285 | * 112 10/14/98 4:18p Chris |
| 286 | * Improved end level path stuff |
| 287 | * |
| 288 | * 111 10/14/98 12:44a Matt |
| 289 | * Cleaned up endlevel sequence system (though it still doesn't work -- |
| 290 | * ChrisP is going to look at the path-following). |
| 291 | * |
| 292 | * 110 10/11/98 5:50p Jeff |
| 293 | * changed warning/error when the multiplayer dll can't be loaded |
| 294 | * |
| 295 | * 109 10/11/98 3:03a Jeff |
| 296 | * made the game handle the Multiplayer D3M file refusing to load (because |
| 297 | * it's init failed for some reason) |
| 298 | * |
| 299 | * 108 10/08/98 7:28p Samir |
| 300 | * revamped sequencing. |
| 301 | * |
| 302 | * 107 10/08/98 3:36p Jason |
| 303 | * fixes for the demo |
| 304 | * |
| 305 | * 107 10/08/98 3:36p Jason |
| 306 | * fixes for the demo |
| 307 | * |
| 308 | * 106 10/02/98 12:07p Jason |
| 309 | * fixed buggy resolution switching |
| 310 | * |
| 311 | * 105 9/22/98 6:48p Matt |
| 312 | * Stop and Start time around screenshot |
| 313 | * |
| 314 | * 104 9/22/98 3:55p Samir |
| 315 | * moved simple callback to NewUI system. |
| 316 | * |
| 317 | * 103 9/22/98 12:02p Matt |
| 318 | * Fixed compile warnings |
| 319 | * |
| 320 | * 102 9/18/98 1:27p Jason |
| 321 | * cleaned up renderer initting |
| 322 | * |
| 323 | * 101 9/14/98 6:28p Jason |
| 324 | * first pass at getting dedicated server working |
| 325 | * |
| 326 | * 100 9/11/98 6:40p Jason |
| 327 | * added smoke puffs |
| 328 | * |
| 329 | * 99 9/01/98 4:11p Samir |
| 330 | * moved screenshot code from gameloop to game.cpp |
| 331 | * |
| 332 | * 98 8/18/98 1:00a Samir |
| 333 | * use current pilot ship for cockpit. |
| 334 | * |
| 335 | * 97 7/21/98 6:50p Jeff |
| 336 | * don't initialize or close renderer if set screen mode hasn't been |
| 337 | * called yet in debug handlers. |
| 338 | * |
| 339 | * 96 7/16/98 12:06p Jason |
| 340 | * added special flags to room structure |
| 341 | * |
| 342 | * 95 6/29/98 6:42p Samir |
| 343 | * Properly handle controller pausing and resumption. |
| 344 | * |
| 345 | * 94 6/22/98 12:00p Chris |
| 346 | * Working on sound system to make it in a nice shape. |
| 347 | * |
| 348 | * 93 6/16/98 10:38a Jeff |
| 349 | * localization, strings pulled out to stringtable.h and d3.str |
| 350 | * |
| 351 | * 92 6/11/98 1:58p Jeff |
| 352 | * ignore last check in comment...it should say ".d3m files renamed to |
| 353 | * .dll files" |
| 354 | * |
| 355 | * 91 6/11/98 1:57p Jeff |
| 356 | * updated for PLR so that phantom players show |
| 357 | * |
| 358 | * 90 5/26/98 10:51p Samir |
| 359 | * set hud mode to current hud mode when setting game screen mode. |
| 360 | * |
| 361 | * 89 5/15/98 5:35p Samir |
| 362 | * allow usage of hires and lores fonts. |
| 363 | * |
| 364 | * 88 5/11/98 4:40p Chris |
| 365 | * AI info is now a malloc'ed pointer |
| 366 | * |
| 367 | * 87 5/11/98 2:47p Samir |
| 368 | * reset res change flag. |
| 369 | * |
| 370 | * 86 5/08/98 12:55p Samir |
| 371 | * improved ui handling when switch screen modes. |
| 372 | * |
| 373 | * 85 5/06/98 4:33p Samir |
| 374 | * set screen mode for game changes to various resolutions. |
| 375 | * |
| 376 | * 84 5/05/98 5:17p Samir |
| 377 | * set screen mode is a bit more efficient when initializing renderer and |
| 378 | * setting screen sizes. |
| 379 | * |
| 380 | * 83 5/05/98 3:02p Jason |
| 381 | * attempting to add different screen resolutions |
| 382 | * |
| 383 | * 82 4/24/98 1:53a Samir |
| 384 | * took care of a lot of scripting memory leaks. |
| 385 | * |
| 386 | * 81 4/16/98 6:51a Samir |
| 387 | * moved cockpit init/free code to once per game instead of level. |
| 388 | * |
| 389 | * 80 4/15/98 11:34a Samir |
| 390 | * no more PostLevelResults. |
| 391 | * |
| 392 | * 79 4/14/98 9:18p Samir |
| 393 | * redid post level results. |
| 394 | * |
| 395 | * 78 4/02/98 7:59p Samir |
| 396 | * Created a simple clear screen UI callback. |
| 397 | * |
| 398 | * 77 4/02/98 11:11a Samir |
| 399 | * better managed SetScreenMode. |
| 400 | * |
| 401 | * 76 3/27/98 4:01p Jason |
| 402 | * added external game dlls |
| 403 | * |
| 404 | * 75 3/19/98 9:19p Samir |
| 405 | * removed dependency of hud.h on game.h. |
| 406 | * |
| 407 | * 74 3/18/98 5:45p Jason |
| 408 | * more multiplayer script integration |
| 409 | * |
| 410 | * 73 3/17/98 2:40p Samir |
| 411 | * reorg of hud/gauge system. |
| 412 | * |
| 413 | * 72 3/13/98 6:55p Chris |
| 414 | * DEBUG to _DEBUG |
| 415 | * |
| 416 | * 71 3/13/98 5:21p Craig |
| 417 | * |
| 418 | * 70 3/13/98 1:28p Jason |
| 419 | * fixed UseHardware variable bug |
| 420 | * |
| 421 | * 69 3/13/98 1:22p Jason |
| 422 | * Moved UseHardware flag to the renderer lib where it belongs |
| 423 | * |
| 424 | * 68 3/13/98 12:09p Samir |
| 425 | * made changes to reflect new cockpit.cpp and cockpit.h |
| 426 | * |
| 427 | * 67 3/11/98 4:58p Chris |
| 428 | * Changed Show_game_sphere to 3 types |
| 429 | * |
| 430 | * 66 3/10/98 5:15p Chris |
| 431 | * DEL+B shows the bounding-sphere of an object |
| 432 | * |
| 433 | * 65 2/25/98 2:05p Jason |
| 434 | * did FOV and object visibility changes |
| 435 | * |
| 436 | * 64 2/18/98 1:11a Samir |
| 437 | * Some game window mess. |
| 438 | * |
| 439 | * 63 2/14/98 10:48p Jason |
| 440 | * got preferred rendering working |
| 441 | * |
| 442 | * 61 2/13/98 10:57a Samir |
| 443 | * Changed some gamescript initialization. |
| 444 | * |
| 445 | * 60 2/12/98 5:08p Matt |
| 446 | * Reset cockpit mode when starting a level. Unfortunately, this involved |
| 447 | * some semi-major mucking with game sequencing. |
| 448 | * |
| 449 | * 59 2/12/98 4:28p Matt |
| 450 | * Added function to start endlevel in-game "cutscene" |
| 451 | * |
| 452 | * 58 2/11/98 5:55p Samir |
| 453 | * Now InitD3XDebug and CloseD3XDebug are called when you enter and leave |
| 454 | * the game. This as well as ui_Init and ui_Close |
| 455 | * |
| 456 | * 57 2/11/98 4:35p Samir |
| 457 | * SetGameMode fully implented takes a script. |
| 458 | * |
| 459 | * 56 2/10/98 11:28a Samir |
| 460 | * Added gamemode info support |
| 461 | * |
| 462 | * 55 2/10/98 10:21a Matt |
| 463 | * Added ifdef around some editor code |
| 464 | * |
| 465 | * 54 2/09/98 3:20p Matt |
| 466 | * Added missile camera system |
| 467 | * |
| 468 | * 53 2/08/98 5:01p Samir |
| 469 | * New game sequencing changes. |
| 470 | * |
| 471 | * 52 2/06/98 6:07p Jason |
| 472 | * made multiplayer objects get deleted in single-player mode |
| 473 | * |
| 474 | * 51 2/03/98 6:42p Samir |
| 475 | * SetScreenMode cleaner. |
| 476 | * |
| 477 | * 50 2/02/98 7:34p Samir |
| 478 | * Moved D3X Initialization to PlayGame. |
| 479 | * |
| 480 | * 49 1/28/98 3:24p Samir |
| 481 | * Put error message if SetScreenMode fails!. |
| 482 | * |
| 483 | * 48 1/28/98 12:00p Jason |
| 484 | * more changes for multiplayer |
| 485 | * |
| 486 | * 47 1/26/98 5:27p Chris |
| 487 | * The sound system was not getting re-initialized between levels |
| 488 | * |
| 489 | * 46 1/22/98 7:48p Samir |
| 490 | * Clear out Gametime FIRST in InitThisLevel. |
| 491 | * |
| 492 | * 45 1/21/98 1:11p Jason |
| 493 | * incremental checkin for multiplayer |
| 494 | * |
| 495 | * 44 1/20/98 7:24p Samir |
| 496 | * Reset events at start of level. |
| 497 | * |
| 498 | * 43 1/20/98 6:01p Jason |
| 499 | * first pass at getting multiplayer deaths working |
| 500 | * |
| 501 | * 42 1/18/98 4:22p Samir |
| 502 | * Changed some UI initialization stuff. |
| 503 | * |
| 504 | * 41 1/10/98 2:55p Jason |
| 505 | * changed some things for multiplayer |
| 506 | * |
| 507 | * 40 1/08/98 12:15p Samir |
| 508 | * Initialize UI when screen mode is set. |
| 509 | * |
| 510 | * 39 1/06/98 2:44p Jason |
| 511 | * another pass for multiplayer |
| 512 | * |
| 513 | * 38 1/05/98 4:36p Chris |
| 514 | * Added working ambient sounds to objects. |
| 515 | * |
| 516 | * 37 1/05/98 10:34a Samir |
| 517 | * Some more StartFrame nonsense. |
| 518 | * |
| 519 | * 36 12/29/97 5:44p Samir |
| 520 | * Took out references to grViewport and old 2d library. |
| 521 | * |
| 522 | * 35 12/19/97 12:27p Samir |
| 523 | * Commented out post level results screen. |
| 524 | * |
| 525 | * 34 12/18/97 3:49p Jason |
| 526 | * a new first pass at networking! |
| 527 | * |
| 528 | * 33 11/12/97 5:48p Chris |
| 529 | * Added sizeof() elements in SoarInit |
| 530 | * |
| 531 | * 32 11/10/97 12:35p Samir |
| 532 | * Added SM_CINEMATIC screen mode, and make sure we don't reinit renderer |
| 533 | * for hardware rendering between two screen modes that use hardware. |
| 534 | * |
| 535 | * 31 10/28/97 6:36p Samir |
| 536 | * Moved SetCockpitMode to gauges.cpp |
| 537 | * |
| 538 | * 30 10/28/97 12:46p Samir |
| 539 | * Moved SetCockpitMode to new gauges.cpp |
| 540 | * |
| 541 | * 29 10/21/97 3:17p Samir |
| 542 | * Letterbox now less obvious. |
| 543 | * |
| 544 | * 28 10/16/97 7:36p Samir |
| 545 | * In editor mode, when switching screen modes, make sure we use the game |
| 546 | * window specified in gameeditor.cpp (should move this code to |
| 547 | * gameditor.cpp) |
| 548 | * |
| 549 | * 27 10/16/97 4:52p Samir |
| 550 | * Sped up stats text display. |
| 551 | * |
| 552 | * 26 10/16/97 2:32p Samir |
| 553 | * Fixed up some timing problems. |
| 554 | * |
| 555 | * 25 10/14/97 6:53p Chris |
| 556 | * Added the initial SOAR support |
| 557 | * |
| 558 | * 24 10/13/97 10:16a Samir |
| 559 | * Added some more result-screen stats. |
| 560 | * |
| 561 | * 23 10/10/97 3:56p Samir |
| 562 | * Added a cockpit mode selection function. |
| 563 | * |
| 564 | * 22 10/08/97 6:35p Samir |
| 565 | * Resets player physics when starting new ship. |
| 566 | * |
| 567 | * 21 10/03/97 11:58a Samir |
| 568 | * Added stats screen. |
| 569 | * |
| 570 | * 20 10/02/97 12:36p Samir |
| 571 | * Redid game sequencing flow. |
| 572 | * |
| 573 | * 19 9/22/97 6:18p Matt |
| 574 | * Removed include of stub.h |
| 575 | * |
| 576 | * 18 9/17/97 4:20p Samir |
| 577 | * Don't reinit screen when sarting a new level, unless we specify so. |
| 578 | * |
| 579 | * 17 9/17/97 4:14p Jason |
| 580 | * fixed frametime bug |
| 581 | * |
| 582 | * 16 9/17/97 1:22p Samir |
| 583 | * BIG SEGMENT RIPOUT |
| 584 | * |
| 585 | * 15 9/12/97 4:08p Samir |
| 586 | * Cleaned up screen mode changing. |
| 587 | * |
| 588 | * 14 9/10/97 1:55p Samir |
| 589 | * Initialize script at start of each level |
| 590 | * |
| 591 | * 13 9/05/97 3:53p Samir |
| 592 | * Fixed some more initial player stats. |
| 593 | * |
| 594 | * 12 9/05/97 2:37p Samir |
| 595 | * Some more default values for player object set in InitThisLevel |
| 596 | * |
| 597 | * 11 9/05/97 1:21p Samir |
| 598 | * Moved around a bunch of initialization code to InitThisLevel which is |
| 599 | * located in game.cpp. This is called every time you die, start a |
| 600 | * level, etc. |
| 601 | * |
| 602 | * 10 8/12/97 1:13p Chris |
| 603 | * Added AABBs. |
| 604 | * |
| 605 | * 9 8/11/97 7:16p Chris |
| 606 | * BOA now works on rooms :) |
| 607 | * |
| 608 | * 8 8/11/97 5:55p Chris |
| 609 | * Got rid of a Chrishack. :) Added MakeBoa in a correct manner. |
| 610 | * |
| 611 | * 7 7/24/97 10:38a Samir |
| 612 | * When we change screen modes, we set the mouse bounds to the screen |
| 613 | * size. |
| 614 | * |
| 615 | * 6 7/17/97 4:34p Chris |
| 616 | * Made sure the orientations get orthagonalized. Yikes. No more |
| 617 | * degenerating orientations. :) |
| 618 | * |
| 619 | * 5 7/15/97 7:29p Chris |
| 620 | * Added a sound for helicopter blades. |
| 621 | * |
| 622 | * 4 7/15/97 5:35p Chris |
| 623 | * New AI code |
| 624 | * |
| 625 | * 23 6/16/97 2:34p Jason |
| 626 | * added 3dfx support |
| 627 | * |
| 628 | * 22 6/13/97 11:24a Samir |
| 629 | * Changes to 2d implemented. |
| 630 | * |
| 631 | * 21 6/13/97 11:19a Jason |
| 632 | * checked in for samir |
| 633 | * |
| 634 | * 20 6/11/97 2:24p Samir |
| 635 | * Changed gameos to new system |
| 636 | * |
| 637 | * 19 6/05/97 6:10p Jason |
| 638 | * added support for zbuffering and bilinear filtering |
| 639 | * |
| 640 | * 18 5/27/97 5:41p Jason |
| 641 | * added toggling of opengl renderer |
| 642 | * |
| 643 | * 17 5/27/97 4:39p Jason |
| 644 | * changes to support OpenGL |
| 645 | * |
| 646 | * 16 5/22/97 4:03p Samir |
| 647 | * SetScreenMode added. |
| 648 | * |
| 649 | * 15 5/19/97 7:02 PM Jeremy |
| 650 | * added initplayernewship to initgame |
| 651 | * |
| 652 | * 14 4/23/97 1:06p Samir |
| 653 | * Implemented Suspend and Resume Controls as well as newer control system |
| 654 | * |
| 655 | * $NoKeywords: $ |
| 656 | */ |
| 657 | |
| 658 | #include "game.h" |
| 659 | #include "ddvid.h" |
| 660 | #include "ddio.h" |
| 661 | #include "pserror.h" |
| 662 | #include "program.h" |
| 663 | #include "descent.h" |
| 664 | #include "object.h" |
| 665 | #include "trigger.h" |
| 666 | #include "player.h" |
| 667 | #include "slew.h" |
| 668 | #include "controls.h" |
| 669 | #include "renderer.h" |
| 670 | #include "doorway.h" |
| 671 | #include "hud.h" |
| 672 | #include "multi.h" |
| 673 | #include "gamefont.h" |
| 674 | #include "newui.h" |
| 675 | #include "gamesequence.h" |
| 676 | #include "cinematics.h" |
| 677 | #include "SmallViews.h" |
| 678 | #include "Mission.h" |
| 679 | #include "cfile.h" |
| 680 | #include "gameloop.h" |
| 681 | #include "cockpit.h" |
| 682 | #include "game2dll.h" |
| 683 | #include "config.h" |
| 684 | #include "stringtable.h" |
| 685 | #include "ship.h" |
| 686 | #include "pilot.h" |
| 687 | #include "args.h" |
| 688 | #include "gamepath.h" |
| 689 | #include "AIGoal.h" |
| 690 | #include "aipath.h" |
| 691 | #include "dedicated_server.h" |
| 692 | #include "objinfo.h" |
| 693 | #include <string.h> |
| 694 | #include "osiris_share.h" |
| 695 | #include "demofile.h" |
| 696 | |
| 697 | #include <NewBitmap.h> |
| 698 | |
| 699 | /////////////////////////////////////////////////////////////////////////////// |
| 700 | // Variables |
| 701 | |
| 702 | // Vars for game 3D window |
| 703 | int Game_window_x, Game_window_y, Game_window_w, Game_window_h; |
| 704 | int Max_window_w, Max_window_h; |
| 705 | |
| 706 | // The game mode we're in (ie multiplayer vs. single, etc) |
| 707 | int Game_mode = 0; |
| 708 | |
| 709 | int sound_override_force_field = -1; |
| 710 | int sound_override_glass_breaking = -1; |
| 711 | |
| 712 | int force_field_bounce_texture[MAX_FORCE_FIELD_BOUNCE_TEXTURES] = {-1, -1, -1}; |
| 713 | float force_field_bounce_multiplier[MAX_FORCE_FIELD_BOUNCE_TEXTURES] = {1.0f, 1.0f, 1.0f}; |
| 714 | |
| 715 | bool Level_powerups_ignore_wind = false; |
| 716 | |
| 717 | // what renderer? |
| 718 | renderer_type PreferredRenderer = RENDERER_OPENGL; |
| 719 | |
| 720 | // Rendering options |
| 721 | rendering_state Render_state; |
| 722 | renderer_preferred_state Render_preferred_state; |
| 723 | int Render_preferred_bitdepth; |
| 724 | |
| 725 | // How hard is this game? |
| 726 | int Difficulty_level = 0; |
| 727 | |
| 728 | #ifdef _DEBUG |
| 729 | int Game_show_sphere = 0; |
| 730 | int Game_show_portal_vis_pnts = 0; |
| 731 | int Game_update_attach = 1; |
| 732 | int Game_do_walking_sim = 1; |
| 733 | int Game_do_vis_sim = 1; |
| 734 | int Game_do_flying_sim = 1; |
| 735 | int Game_do_ai_movement = 1; |
| 736 | int Game_do_ai_vis = 1; |
| 737 | #endif |
| 738 | |
| 739 | // How much of the mine has been explored? |
| 740 | int Num_rooms_explored = 0; |
| 741 | |
| 742 | // Save and restores per level |
| 743 | int Num_player_saves = 0; |
| 744 | int Num_player_restores = 0; |
| 745 | |
| 746 | // Missile camera |
| 747 | int Missile_camera_window = SVW_LEFT; // will default to -1 when interface is in |
| 748 | |
| 749 | // contains all relevent information for gamemode pertaining to d3x system. |
| 750 | gamemode Gamemode_info; |
| 751 | |
| 752 | /////////////////////////////////////////////////////////////////////////////// |
| 753 | // Game setup |
| 754 | /////////////////////////////////////////////////////////////////////////////// |
| 755 | |
| 756 | bool InitGameScript(); |
| 757 | void CloseGameScript(); |
| 758 | |
| 759 | float GetFPS() { |
| 760 | if (Frametime == 0.0f) { |
| 761 | Frametime = 0.1f; |
| 762 | } |
| 763 | return 1.0 / Frametime; |
| 764 | } |
| 765 | |
| 766 | /////////////////////////////////////////////////////////////////////////////// |
| 767 | // Game Execution |
| 768 | /////////////////////////////////////////////////////////////////////////////// |
| 769 | |
| 770 | // Setup the game screen |
| 771 | void InitGameScreen(int w, int h) { |
| 772 | if (w > Max_window_w) |
| 773 | w = Max_window_w; |
| 774 | if (h > Max_window_h) |
| 775 | h = Max_window_h; |
| 776 | |
| 777 | Game_window_w = w; |
| 778 | Game_window_h = h; |
| 779 | |
| 780 | Game_window_x = (Max_window_w - Game_window_w) / 2; |
| 781 | Game_window_y = (Max_window_h - Game_window_h) / 2; |
| 782 | } |
| 783 | |
| 784 | // Setup whatever needs to be setup for game mode |
| 785 | bool InitGame() { |
| 786 | #ifdef _DEBUG |
| 787 | // Put player in flying mode |
| 788 | SlewStop(Player_object); |
| 789 | #endif |
| 790 | |
| 791 | InitHUD(); |
| 792 | |
| 793 | if (!InitGameScript()) // initializes game script |
| 794 | return false; |
| 795 | |
| 796 | Frametime = 0.1f; |
| 797 | Skip_render_game_frame = false; |
| 798 | |
| 799 | // reset controllers. |
| 800 | Controller->mask_controllers((Current_pilot.read_controller & READF_JOY) ? true : false, |
| 801 | (Current_pilot.read_controller & READF_MOUSE) ? true : false); |
| 802 | |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | #ifdef EDITOR |
| 807 | bool Game_being_played_from_quick_play = false; |
| 808 | void QuickPlayGame() { |
| 809 | if (InitGame()) { |
| 810 | Game_being_played_from_quick_play = true; |
| 811 | QuickStartMission(); |
| 812 | |
| 813 | // Run the game (note, if this call returns false, we couldn't play a level. Display an error maybe? |
| 814 | GameSequencer(); |
| 815 | QuickEndMission(); |
| 816 | } else { |
| 817 | } |
| 818 | Game_being_played_from_quick_play = false; |
| 819 | |
| 820 | // Close down some game stuff |
| 821 | // close down any systems not needed outside game. |
| 822 | CloseGameScript(); |
| 823 | CloseHUD(); |
| 824 | DoorwayDeactivateAll(); // deactivate doorways |
| 825 | ui_RemoveAllWindows(); // remove any ui windows left open. |
| 826 | SuspendControls(); |
| 827 | } |
| 828 | #endif |
| 829 | |
| 830 | void PlayGame() { |
| 831 | // Initialize misc game |
| 832 | if (InitGame()) { |
| 833 | // Run the game (note, if this call returns false, we couldn't play a level. Display an error maybe? |
| 834 | GameSequencer(); |
| 835 | } else { |
| 836 | SetFunctionMode(MENU_MODE); |
| 837 | |
| 838 | // if they were going into a multiplayer game than we need to handle cleaning all that up |
| 839 | if (Game_mode & GM_MULTI) { |
| 840 | SetGameMode(GM_NORMAL); |
| 841 | for (int i = 0; i < MAX_PLAYERS; i++) { |
| 842 | NetPlayers[i].flags &= ~NPF_CONNECTED; |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | // Close down some game stuff |
| 848 | // close down any systems not needed outside game. |
| 849 | |
| 850 | // we must pop the pages before closing the mission, since we need to have the mn3 hog file open |
| 851 | mng_ClearAddonTables(); |
| 852 | |
| 853 | ResetMission(); |
| 854 | CloseGameScript(); |
| 855 | CloseHUD(); |
| 856 | // DoorwayDeactivateAll(); // deactivate doorways |
| 857 | ui_RemoveAllWindows(); // remove any ui windows left open. |
| 858 | SuspendControls(); |
| 859 | } |
| 860 | |
| 861 | /////////////////////////////////////////////////////////////////////////////// |
| 862 | // Sets the game mode. this will reinitialize the game mode script. |
| 863 | /////////////////////////////////////////////////////////////////////////////// |
| 864 | |
| 865 | void SetGamemodeScript(const char *scrfilename, int num_teams) { |
| 866 | if (scrfilename != NULL) |
| 867 | strcpy(Gamemode_info.scriptname, scrfilename); |
| 868 | else |
| 869 | Gamemode_info.scriptname[0] = 0; |
| 870 | Gamemode_info.requested_num_teams = num_teams; |
| 871 | } |
| 872 | |
| 873 | void RenderBlankScreen(void); |
| 874 | bool InitGameScript() { |
| 875 | // initialize gamemode script here. |
| 876 | if (Gamemode_info.scriptname[0]) { |
| 877 | //@@ char d3xname[255]; |
| 878 | char dllname[255]; |
| 879 | |
| 880 | snprintf(dllname, sizeof(dllname), "%s", Gamemode_info.scriptname); |
| 881 | |
| 882 | if (!LoadGameDLL(dllname, Gamemode_info.requested_num_teams)) { |
| 883 | if (!Dedicated_server) { |
| 884 | void (*old_callback)(); |
| 885 | old_callback = GetUICallback(); |
| 886 | SetUICallback(RenderBlankScreen); |
| 887 | ShowProgressScreen(TXT_LOADMODULEERR); |
| 888 | DoMessageBox(TXT_ERROR, TXT_INITMODULEERR, MSGBOX_OK); |
| 889 | SetUICallback(old_callback); |
| 890 | } |
| 891 | return false; |
| 892 | } |
| 893 | } |
| 894 | return true; |
| 895 | } |
| 896 | |
| 897 | void CloseGameScript() { |
| 898 | // free any gamemode info. |
| 899 | FreeGameDLL(); |
| 900 | } |
| 901 | |
| 902 | // call this to set the game mode |
| 903 | void SetGameMode(int mode) { |
| 904 | // do any gamemode specific code here. |
| 905 | |
| 906 | Game_mode = mode; |
| 907 | } |
| 908 | |
| 909 | /////////////////////////////////////////////////////////////////////////////// |
| 910 | // Sets screen mode |
| 911 | /////////////////////////////////////////////////////////////////////////////// |
| 912 | |
| 913 | static int Screen_mode = SM_NULL; |
| 914 | |
| 915 | int GetScreenMode() { return Screen_mode; } |
| 916 | |
| 917 | // use to sync to debug break handlers |
| 918 | int rend_initted = 0; |
| 919 | int Low_vidmem = 0; |
| 920 | |
| 921 | void SetScreenMode(int sm, bool force_res_change) { |
| 922 | static int old_sm = SM_NULL; |
| 923 | static int rend_width = 0, rend_height = 0; |
| 924 | rendering_state rs; |
| 925 | |
| 926 | if (sm == SM_CINEMATIC) { |
| 927 | // force cinematic to menu |
| 928 | sm = SM_MENU; |
| 929 | } |
| 930 | |
| 931 | if (Dedicated_server) |
| 932 | return; |
| 933 | |
| 934 | if (old_sm == sm && !force_res_change) |
| 935 | return; |
| 936 | |
| 937 | // close down any systems previously opened and that must be closed (like software->hardware, etc.) |
| 938 | // make sure renderer is initialized |
| 939 | // also set any preferred renderer states. |
| 940 | if (sm == SM_NULL) { // || (sm == SM_CINEMATIC && Renderer_type == RENDERER_OPENGL)) { |
| 941 | if (rend_initted) { |
| 942 | rend_Close(); |
| 943 | rend_initted = 0; |
| 944 | } |
| 945 | } else if (sm == SM_CINEMATIC) { // && (Renderer_type == RENDERER_OPENGL || Renderer_type == RENDERER_DIRECT3D)) { |
| 946 | if (rend_initted) { |
| 947 | rend_Close(); |
| 948 | rend_initted = 0; |
| 949 | } |
| 950 | } |
| 951 | else { |
| 952 | int scr_width, scr_height, scr_bitdepth; |
| 953 | |
| 954 | if (sm == SM_GAME) { |
| 955 | scr_width = Video_res_list[Game_video_resolution].width; |
| 956 | scr_height = Video_res_list[Game_video_resolution].height; |
| 957 | scr_bitdepth = Render_preferred_bitdepth; |
| 958 | } else { |
| 959 | scr_width = FIXED_SCREEN_WIDTH; |
| 960 | scr_height = FIXED_SCREEN_HEIGHT; |
| 961 | scr_bitdepth = 32; |
| 962 | } |
| 963 | |
| 964 | if (!rend_initted) { |
| 965 | |
| 966 | Render_preferred_state.width = scr_width; |
| 967 | Render_preferred_state.height = scr_height; |
| 968 | Render_preferred_state.bit_depth = scr_bitdepth; |
| 969 | |
| 970 | rend_initted = rend_Init(PreferredRenderer, Descent, &Render_preferred_state); |
| 971 | rend_width = rend_height = 0; |
| 972 | } else { |
| 973 | |
| 974 | // If bitdepth changed but not initting, switch bitdepth |
| 975 | if (Render_preferred_state.bit_depth != scr_bitdepth) { |
| 976 | Render_preferred_state.bit_depth = scr_bitdepth; |
| 977 | rend_SetPreferredState(&Render_preferred_state); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | if (!rend_initted) { |
| 982 | Error(rend_GetErrorMessage()); |
| 983 | } else { |
| 984 | int t = FindArg("-ForceStateLimited"); |
| 985 | if (t) { |
| 986 | StateLimited = (atoi((const char *)GameArgs[t + 1]) != 0); |
| 987 | } |
| 988 | |
| 989 | if (rend_initted == -1) { |
| 990 | // We're using the default, so change some values for the menus |
| 991 | rend_initted = 1; |
| 992 | mprintf(0, "Changing menu settings to default!\n"); |
| 993 | Game_video_resolution = RES_640X480; |
| 994 | Render_preferred_state.bit_depth = 32; |
| 995 | scr_width = 640; |
| 996 | scr_height = 480; |
| 997 | } |
| 998 | |
| 999 | if (rend_width != scr_width || rend_height != scr_height) { |
| 1000 | Render_preferred_state.width = scr_width; |
| 1001 | Render_preferred_state.height = scr_height; |
| 1002 | Render_preferred_state.bit_depth = scr_bitdepth; |
| 1003 | |
| 1004 | mprintf(0, "Setting rend_width=%d height=%d\n", scr_width, scr_height); |
| 1005 | int retval = rend_SetPreferredState(&Render_preferred_state); |
| 1006 | |
| 1007 | if (retval == -1) { |
| 1008 | // We're using the default, so change some values for the menus |
| 1009 | rend_initted = 1; |
| 1010 | mprintf(0, "Changing menu settings to default!\n"); |
| 1011 | Game_video_resolution = RES_640X480; |
| 1012 | Render_preferred_state.bit_depth = 32; |
| 1013 | scr_width = 640; |
| 1014 | scr_height = 480; |
| 1015 | Render_preferred_state.width = scr_width; |
| 1016 | Render_preferred_state.height = scr_height; |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | if (rend_initted) { |
| 1023 | // Get the amount of video memory |
| 1024 | Low_vidmem = rend_LowVidMem(); |
| 1025 | |
| 1026 | if (FindArg("-hividmem")) |
| 1027 | Low_vidmem = 0; |
| 1028 | |
| 1029 | // get current render width and height. |
| 1030 | rend_GetRenderState(&rs); |
| 1031 | rend_width = rs.screen_width; |
| 1032 | rend_height = rs.screen_height; |
| 1033 | |
| 1034 | // sets up the screen resolution for the system |
| 1035 | if (!UseHardware) { |
| 1036 | ddvid_SetVideoMode(rend_width, rend_height, BPP_16, true); |
| 1037 | } else { |
| 1038 | if (PreferredRenderer == RENDERER_OPENGL) { |
| 1039 | ddvid_SetVideoMode(rend_width, rend_height, BPP_16, false); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | // chose font. |
| 1044 | SelectHUDFont(rend_width); |
| 1045 | |
| 1046 | // Setup the screen |
| 1047 | Max_window_w = rend_width; |
| 1048 | Max_window_h = rend_height; |
| 1049 | |
| 1050 | InitGameScreen(Max_window_w, Max_window_h); |
| 1051 | |
| 1052 | // initialize ui system again |
| 1053 | ui_SetScreenMode(Max_window_w, Max_window_h); |
| 1054 | |
| 1055 | mprintf(0, "rend_width=%d height=%d\n", Max_window_w, Max_window_h); |
| 1056 | } |
| 1057 | |
| 1058 | // assign current screen mode |
| 1059 | Screen_mode = sm; |
| 1060 | old_sm = sm; |
| 1061 | |
| 1062 | // Adjust mouse mapping to current screen |
| 1063 | // do screen mode stuff |
| 1064 | switch (sm) { |
| 1065 | case SM_GAME: { |
| 1066 | ui_HideCursor(); |
| 1067 | SetUICallback(NULL); |
| 1068 | int gw, gh; |
| 1069 | Current_pilot.get_hud_data(NULL, NULL, NULL, &gw, &gh); |
| 1070 | if (force_res_change) { |
| 1071 | gw = Max_window_w; |
| 1072 | gh = Max_window_h; |
| 1073 | } |
| 1074 | InitGameScreen(gw, gh); |
| 1075 | // need to do this since the pilot w,h could change. |
| 1076 | Current_pilot.set_hud_data(NULL, NULL, NULL, &Game_window_w, &Game_window_h); |
| 1077 | break; |
| 1078 | } |
| 1079 | |
| 1080 | case SM_MENU: { |
| 1081 | // sets up the menu screen |
| 1082 | SetUICallback(DEFAULT_UICALLBACK); |
| 1083 | ui_ShowCursor(); |
| 1084 | break; |
| 1085 | } |
| 1086 | |
| 1087 | case SM_CINEMATIC: { |
| 1088 | SetMovieProperties(0, 0, FIXED_SCREEN_WIDTH, FIXED_SCREEN_HEIGHT, (rend_initted) ? Renderer_type : RENDERER_NONE); |
| 1089 | break; |
| 1090 | } |
| 1091 | |
| 1092 | case SM_NULL: { |
| 1093 | // cleans up |
| 1094 | return; |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | mprintf(0, "NEW rend_width=%d height=%d\n", Max_window_w, Max_window_h); |
| 1099 | |
| 1100 | // mark res change as false. |
| 1101 | |
| 1102 | #ifdef EDITOR |
| 1103 | extern unsigned hGameWnd; |
| 1104 | // HACK!!! In editor, to get things working fine, reassert window handle attached to game screen |
| 1105 | // is the topmost window, since in the editor, if we're fullscreen the parent window is still |
| 1106 | // the editor window, the screen would belong to the editor window. |
| 1107 | tLnxAppInfo appinfo; |
| 1108 | Descent->get_info(&appinfo); |
| 1109 | // LGT - Disabled: not using ddvid |
| 1110 | // ddvid_SetVideoHandle(hGameWnd); |
| 1111 | #endif |
| 1112 | } |
| 1113 | |
| 1114 | // These functions are called to start and end a rendering frame |
| 1115 | struct tFrameStackFrame { |
| 1116 | int x1, x2, y1, y2; |
| 1117 | bool clear; |
| 1118 | tFrameStackFrame *next; |
| 1119 | tFrameStackFrame *prev; |
| 1120 | }; |
| 1121 | tFrameStackFrame *FrameStackRoot = NULL; |
| 1122 | tFrameStackFrame *FrameStackPtr = NULL; |
| 1123 | tFrameStackFrame FrameStack[8]; |
| 1124 | int FrameStackDepth = 0; |
| 1125 | |
| 1126 | void FramePush(int x1, int y1, int x2, int y2, bool clear) { |
| 1127 | tFrameStackFrame *curr = FrameStackPtr; |
| 1128 | |
| 1129 | if (!curr) { |
| 1130 | ASSERT(!FrameStackRoot); |
| 1131 | |
| 1132 | // we need to allocate for the root |
| 1133 | // curr = FrameStackRoot = FrameStackPtr = (tFrameStackFrame *)mem_malloc(sizeof(tFrameStackFrame)); |
| 1134 | curr = FrameStackRoot = FrameStackPtr = &FrameStack[0]; |
| 1135 | if (!curr) { |
| 1136 | Error("Out of memory\n"); |
| 1137 | } |
| 1138 | |
| 1139 | curr->prev = NULL; |
| 1140 | curr->next = NULL; |
| 1141 | } else { |
| 1142 | // add on to the end of the list |
| 1143 | curr->next = FrameStackPtr = &FrameStack[FrameStackDepth]; |
| 1144 | // curr->next = FrameStackPtr = (tFrameStackFrame *)mem_malloc(sizeof(tFrameStackFrame)); |
| 1145 | if (!curr->next) { |
| 1146 | Error("Out of memory\n"); |
| 1147 | } |
| 1148 | curr->next->prev = curr; // setup previous frame |
| 1149 | curr = curr->next; |
| 1150 | curr->next = NULL; |
| 1151 | } |
| 1152 | |
| 1153 | // at this point curr should be a valid frame, with prev and next set |
| 1154 | curr->x1 = x1; |
| 1155 | curr->x2 = x2; |
| 1156 | curr->y1 = y1; |
| 1157 | curr->y2 = y2; |
| 1158 | curr->clear = clear; |
| 1159 | FrameStackDepth++; |
| 1160 | // DAJ |
| 1161 | if (FrameStackDepth > 7) { |
| 1162 | mprintf(2, "FrameStack Overflow\n"); |
| 1163 | Int3(); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | void FramePop(int *x1, int *y1, int *x2, int *y2, bool *clear) { |
| 1168 | if (!FrameStackRoot || !FrameStackPtr) { |
| 1169 | mprintf(0, "StartFrame/EndFrame mismatch\n"); |
| 1170 | Int3(); |
| 1171 | *clear = true; |
| 1172 | *x1 = Game_window_x; |
| 1173 | *y1 = Game_window_y; |
| 1174 | *x2 = *x1 + Game_window_w; |
| 1175 | *y2 = *y1 + Game_window_h; |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | tFrameStackFrame *frame = FrameStackPtr; |
| 1180 | |
| 1181 | *x1 = FrameStackPtr->x1; |
| 1182 | *x2 = FrameStackPtr->x2; |
| 1183 | *y1 = FrameStackPtr->y1; |
| 1184 | *y2 = FrameStackPtr->y2; |
| 1185 | *clear = FrameStackPtr->clear; |
| 1186 | |
| 1187 | if (frame == FrameStackRoot) { |
| 1188 | // we're popping off the root |
| 1189 | // DAJ mem_free(FrameStackRoot); |
| 1190 | FrameStackRoot = NULL; |
| 1191 | FrameStackPtr = NULL; |
| 1192 | } else { |
| 1193 | // we're just going back a frame, but still have a stack |
| 1194 | FrameStackPtr = FrameStackPtr->prev; // pop back a frame |
| 1195 | FrameStackPtr->next = NULL; |
| 1196 | // DAJ mem_free(frame); |
| 1197 | } |
| 1198 | FrameStackDepth--; |
| 1199 | } |
| 1200 | |
| 1201 | // peeks at the current frame |
| 1202 | // returns false if there is no current frame |
| 1203 | bool FramePeek(int *x1, int *y1, int *x2, int *y2, bool *clear) { |
| 1204 | if (!FrameStackPtr) |
| 1205 | return false; |
| 1206 | |
| 1207 | *x1 = FrameStackPtr->x1; |
| 1208 | *x2 = FrameStackPtr->x2; |
| 1209 | *y1 = FrameStackPtr->y1; |
| 1210 | *y2 = FrameStackPtr->y2; |
| 1211 | *clear = FrameStackPtr->clear; |
| 1212 | return true; |
| 1213 | } |
| 1214 | |
| 1215 | void StartFrame(bool clear) { |
| 1216 | StartFrame(Game_window_x, Game_window_y, Game_window_x + Game_window_w, Game_window_y + Game_window_h, clear); |
| 1217 | } |
| 1218 | |
| 1219 | void StartFrame(int x, int y, int x2, int y2, bool clear, bool push_on_stack) { |
| 1220 | static float last_fov = -1; |
| 1221 | // Check to see if our FOV has changed since last frame |
| 1222 | if (last_fov != Render_FOV) { |
| 1223 | // Figure out new zoom factor |
| 1224 | float num = (Render_FOV / 2); |
| 1225 | num = (3.14 * (float)num / 180.0); |
| 1226 | Render_zoom = tan(num); |
| 1227 | |
| 1228 | last_fov = Render_FOV; |
| 1229 | } |
| 1230 | |
| 1231 | if (push_on_stack) { |
| 1232 | // push this frame onto the stack |
| 1233 | FramePush(x, y, x2, y2, clear); |
| 1234 | } |
| 1235 | |
| 1236 | rend_StartFrame(x, y, x2, y2); |
| 1237 | |
| 1238 | grtext_SetParameters(0, 0, (x2 - x), (y2 - y)); |
| 1239 | } |
| 1240 | |
| 1241 | // retrives the settings of the last call to StartFrame |
| 1242 | bool GetFrameParameters(int *x1, int *y1, int *x2, int *y2) { |
| 1243 | return false; |
| 1244 | /* |
| 1245 | if(!Frame_inside) |
| 1246 | return false; |
| 1247 | *x1 = Frame_x1; |
| 1248 | *y1 = Frame_y1; |
| 1249 | *x2 = Frame_x2; |
| 1250 | *y2 = Frame_y2; |
| 1251 | return true; |
| 1252 | */ |
| 1253 | } |
| 1254 | |
| 1255 | void EndFrame() { |
| 1256 | //@@Frame_inside = false; |
| 1257 | rend_EndFrame(); |
| 1258 | |
| 1259 | // pop off frame |
| 1260 | int x1, x2, y1, y2; |
| 1261 | bool clear; |
| 1262 | |
| 1263 | FramePop(&x1, &y1, &x2, &y2, &clear); // pop off frame just ending |
| 1264 | |
| 1265 | // see if there is a frame on the stack...if so, restore it's settings |
| 1266 | if (FramePeek(&x1, &y1, &x2, &y2, &clear)) { |
| 1267 | // restore this frame |
| 1268 | StartFrame(x1, y1, x2, y2, clear, false); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | // Does a screenshot and tells the bitmap lib to save out the picture as a tga |
| 1273 | void DoScreenshot() { |
| 1274 | int count; |
| 1275 | char str[255], filename[255]; |
| 1276 | CFILE *infile; |
| 1277 | int done = 0; |
| 1278 | int width = 640, height = 480; |
| 1279 | |
| 1280 | if (UseHardware) { |
| 1281 | rendering_state rs; |
| 1282 | rend_GetRenderState(&rs); |
| 1283 | width = rs.screen_width; |
| 1284 | height = rs.screen_height; |
| 1285 | } |
| 1286 | |
| 1287 | StopTime(); |
| 1288 | |
| 1289 | // Tell our renderer lib to take a screen shot |
| 1290 | auto screenshot = rend_Screenshot(); |
| 1291 | |
| 1292 | if (!screenshot || screenshot->getData() == nullptr) { |
| 1293 | AddHUDMessage(TXT_ERRSCRNSHT); |
| 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // Find a valid filename |
| 1298 | count = 1; |
| 1299 | while (!done) { |
| 1300 | snprintf(str, sizeof(str), "Screenshot%.3d.png", count); |
| 1301 | ddio_MakePath(filename, Base_directory_write, str, NULL); |
| 1302 | infile = (CFILE *)cfopen(filename, "rb"); |
| 1303 | if (infile == NULL) { |
| 1304 | done = 1; |
| 1305 | continue; |
| 1306 | } else |
| 1307 | cfclose(infile); |
| 1308 | |
| 1309 | count++; |
| 1310 | if (count > 999) |
| 1311 | break; |
| 1312 | } |
| 1313 | |
| 1314 | // Now save it |
| 1315 | screenshot->saveAsPNG(filename); |
| 1316 | |
| 1317 | if (Demo_flags != DF_PLAYBACK) { |
| 1318 | AddHUDMessage(TXT_SCRNSHT, filename); |
| 1319 | } |
| 1320 | |
| 1321 | StartTime(); |
| 1322 | } |