FS2_Open
Open source remastering of the Freespace 2 engine
freespace.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 
13 #ifdef _WIN32
14  #include <direct.h>
15  #include <io.h>
16  #include <windows.h>
17 #ifndef _MINGW
18  #include <crtdbg.h>
19 #endif // !_MINGW
20 #else
21  #include <unistd.h>
22  #include <sys/stat.h>
23 #endif
24 
25 #include "anim/animplay.h"
26 #include "asteroid/asteroid.h"
27 #include "autopilot/autopilot.h"
28 #include "bmpman/bmpman.h"
29 #include "cfile/cfile.h"
30 #include "cmdline/cmdline.h"
31 #include "cmeasure/cmeasure.h"
32 #include "cutscene/cutscenes.h"
33 #include "cutscene/movie.h"
34 #include "debris/debris.h"
35 #include "debugconsole/console.h"
37 #include "external_dll/trackirpublic.h" // header file for the TrackIR routines (Swifty)
38 #include "fireball/fireballs.h"
39 #include "freespace2/freespace.h"
41 #include "freespace2/levelpaging.h"
42 #include "fs2netd/fs2netd_client.h"
43 #include "gamehelp/contexthelp.h"
44 #include "gamehelp/gameplayhelp.h"
46 #include "gamesnd/eventmusic.h"
47 #include "gamesnd/gamesnd.h"
48 #include "globalincs/alphacolors.h"
50 #include "globalincs/version.h"
51 #include "graphics/font.h"
52 #include "graphics/shadows.h"
53 #include "hud/hud.h"
54 #include "hud/hudconfig.h"
55 #include "hud/hudescort.h"
56 #include "hud/hudlock.h"
57 #include "hud/hudmessage.h"
58 #include "hud/hudparse.h"
59 #include "hud/hudshield.h"
60 #include "hud/hudsquadmsg.h"
61 #include "hud/hudtargetbox.h"
62 #include "iff_defs/iff_defs.h"
63 #include "io/joy.h"
64 #include "io/joy_ff.h"
65 #include "io/key.h"
66 #include "io/mouse.h"
67 #include "io/timer.h"
68 #include "jumpnode/jumpnode.h"
69 #include "lab/lab.h"
70 #include "lab/wmcgui.h" //So that GUI_System can be initialized
71 #include "lighting/lighting.h"
72 #include "localization/localize.h"
73 #include "math/staticrand.h"
74 #include "menuui/barracks.h"
75 #include "menuui/credits.h"
76 #include "menuui/mainhallmenu.h"
77 #include "menuui/optionsmenu.h"
78 #include "menuui/playermenu.h"
79 #include "menuui/readyroom.h"
80 #include "menuui/snazzyui.h"
81 #include "menuui/techmenu.h"
82 #include "menuui/trainingmenu.h"
85 #include "mission/missiongoals.h"
86 #include "mission/missionhotkey.h"
87 #include "mission/missionload.h"
88 #include "mission/missionlog.h"
89 #include "mission/missionmessage.h"
90 #include "mission/missionparse.h"
93 #include "missionui/missionbrief.h"
97 #include "missionui/missionpause.h"
101 #include "missionui/redalert.h"
102 #include "mod_table/mod_table.h"
103 #include "nebula/neb.h"
104 #include "nebula/neblightning.h"
105 #include "network/multi.h"
106 #include "network/multi_dogfight.h"
107 #include "network/multi_endgame.h"
108 #include "network/multi_ingame.h"
109 #include "network/multi_log.h"
110 #include "network/multi_pause.h"
111 #include "network/multi_pxo.h"
112 #include "network/multi_rate.h"
113 #include "network/multi_respawn.h"
114 #include "network/multi_voice.h"
115 #include "network/multimsgs.h"
116 #include "network/multiteamselect.h"
117 #include "network/multiui.h"
118 #include "network/multiutil.h"
119 #include "network/stand_gui.h"
120 #include "object/objcollide.h"
121 #include "object/objectsnd.h"
122 #include "object/waypoint.h"
123 #include "observer/observer.h"
124 #include "osapi/osapi.h"
125 #include "osapi/osregistry.h"
126 #include "parse/encrypt.h"
127 #include "parse/generic_log.h"
128 #include "parse/lua.h"
129 #include "parse/parselo.h"
130 #include "parse/scripting.h"
131 #include "parse/sexp.h"
132 #include "particle/particle.h"
133 #include "pilotfile/pilotfile.h"
134 #include "playerman/managepilot.h"
135 #include "playerman/player.h"
136 #include "popup/popup.h"
137 #include "popup/popupdead.h"
138 #include "radar/radar.h"
139 #include "radar/radarsetup.h"
140 #include "render/3d.h"
141 #include "ship/afterburner.h"
142 #include "ship/awacs.h"
143 #include "ship/ship.h"
144 #include "ship/shipcontrails.h"
145 #include "ship/shipfx.h"
146 #include "ship/shiphit.h"
147 #include "sound/audiostr.h"
148 #include "sound/ds.h"
149 #include "sound/fsspeech.h"
150 #include "sound/sound.h"
151 #include "sound/voicerec.h"
152 #include "starfield/starfield.h"
153 #include "starfield/supernova.h"
154 #include "stats/medals.h"
155 #include "stats/stats.h"
156 #include "weapon/beam.h"
157 #include "weapon/emp.h"
158 #include "weapon/flak.h"
159 #include "weapon/muzzleflash.h"
160 #include "weapon/shockwave.h"
161 #include "weapon/weapon.h"
162 
163 #include <stdexcept>
164 
165 extern int Om_tracker_flag; // needed for FS2OpenPXO config
166 
167 #ifdef WIN32
168 // According to AMD and NV, these _should_ force their drivers into high-performance mode
169 extern "C" {
170  __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
171  __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
172 }
173 #endif
174 
175 #ifdef NDEBUG
176 #ifdef FRED
177 #error macro FRED is defined when trying to build release FreeSpace. Please undefine FRED macro in build settings
178 #endif
179 #endif
180 
181 
182 // Revision history.
183 // Full version:
184 // 1.00.04 5/26/98 MWA -- going final (12 pm)
185 // 1.00.03 5/26/98 MWA -- going final (3 am)
186 // 1.00.02 5/25/98 MWA -- going final
187 // 1.00.01 5/25/98 MWA -- going final
188 // 0.90 5/21/98 MWA -- getting ready for final.
189 // 0.10 4/9/98. Set by MK.
190 //
191 // OEM version:
192 // 1.00 5/28/98 AL. First release to Interplay QA.
193 
194 
195 // This function is defined in code\network\multiutil.cpp so will be linked from multiutil.obj
196 // it's required fro the -missioncrcs command line option - Kazan
197 void multi_spew_pxo_checksums(int max_files, const char *outfile);
198 void fs2netd_spew_table_checksums(char *outfile);
199 
200 extern bool frame_rate_display;
201 
202 bool Env_cubemap_drawn = false;
203 
204 void game_reset_view_clip();
206 void game_post_level_init();
207 void game_do_frame();
208 void game_update_missiontime(); // called from game_do_frame() and navmap_do_frame()
209 void game_reset_time();
210 void game_show_framerate(); // draws framerate in lower right corner
211 
213 
214 typedef struct big_expl_flash {
215  float max_flash_intensity; // max intensity
216  float cur_flash_intensity; // cur intensity
217  int flash_start; // start time
219 
220 #define FRAME_FILTER 16
221 
222 #define DEFAULT_SKILL_LEVEL 1
224 
225 #define EXE_FNAME ("fs2.exe")
226 
227 #define LAUNCHER_FNAME ("Launcher.exe")
228 
229 // JAS: Code for warphole camera.
230 // Needs to be cleaned up.
231 float Warpout_time = 0.0f;
232 int Warpout_forced = 0; // Set if this is a forced warpout that cannot be cancelled.
233 int Warpout_sound = -1;
236 #ifndef NDEBUG
238 #endif
240 object *Last_view_target = NULL;
241 
243 
244 int frame_int = -1;
246 float frametotal = 0.0f;
250 
251 #ifndef NDEBUG
252  int Show_framerate = 1;
253  int Show_mem = 1;
254 #else
255  int Show_framerate = 0;
256  int Show_mem = 0;
257 #endif
258 
259 int Framerate_cap = 120;
260 
261 // to determine if networking should be disabled, needs to be done first thing
263 
264 // for the model page in system
265 extern void model_page_in_start();
266 
267 int Show_cpu = 0;
270 int Game_font = -1;
271 #ifndef NDEBUG
272 static int Show_player_pos = 0; // debug console command to show player world pos on HUD
273 #endif
274 
275 int Debug_octant = -1;
276 
280 bool Time_compression_locked = false; //Can the user change time with shift- controls?
281 
282 // auto-lang stuff
283 int detect_lang();
284 
285 // table checksums that will be used for pilot files
288 
289 // if the ships.tbl the player has is valid
291 
292 // if the weapons.tbl the player has is valid
294 
295 int Test_begin = 0;
296 extern int Player_attacking_enabled;
298 
300 
301 int Fred_running = 0;
302 
303 // required for hudtarget... kinda dumb, but meh
306 
310 
311 int game_zbuffer = 1;
312 static int Game_paused;
313 
314 #define EXPIRE_BAD_CHECKSUM 1
315 #define EXPIRE_BAD_TIME 2
316 
317 extern void ssm_init();
318 extern void ssm_level_init();
319 extern void ssm_process();
320 
321 // static variable to contain the time this version was built
322 // commented out for now until
323 // I figure out how to get the username into the file
324 //LOCAL char freespace_build_time[] = "Compiled on:"__DATE__" "__TIME__" by "__USER__;
325 
326 // defines and variables used for dumping frame for making trailers.
327 #ifndef NDEBUG
328 int Debug_dump_frames = 0; // Set to 0 to not dump frames, else equal hz to dump. (15 or 30 probably)
332 #define DUMP_BUFFER_NUM_FRAMES 1 // store every 15 frames
333 #endif
334 
335 // amount of time to wait after the player has died before we display the death died popup
336 #define PLAYER_DIED_POPUP_WAIT 2500
338 
340 
342 
343 // builtin mission list stuff
346  // single player campaign
347  { "freespace2.fc2", (FSB_FROM_VOLITION | FSB_CAMPAIGN_FILE), "" },
348 
349  // act 1
350  { "sm1-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
351  { "sm1-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
352  { "sm1-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
353  { "sm1-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
354  { "sm1-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
355  { "sm1-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
356  { "sm1-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
357  { "sm1-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
358  { "sm1-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
359  { "sm1-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
360  { "loop1-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
361  { "loop1-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
362  { "loop1-3.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
363  { "training-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
364  { "training-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
365  { "training-3.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
366  { "tsm-104.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
367  { "tsm-105.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
368  { "tsm-106.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_2 },
369 
370  // act 2
371  { "sm2-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
372  { "sm2-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
373  { "sm2-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
374  { "sm2-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
375  { "sm2-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
376  { "sm2-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
377  { "sm2-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
378  { "sm2-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
379  { "sm2-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
380  { "sm2-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
381 
382  // act 3
383  { "sm3-01.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
384  { "sm3-02.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
385  { "sm3-03.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
386  { "sm3-04.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
387  { "sm3-05.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
388  { "sm3-06.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
389  { "sm3-07.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
390  { "sm3-08.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
391  { "sm3-09.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
392  { "sm3-10.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
393  { "loop2-1.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
394  { "loop2-2.fs2", (FSB_FROM_VOLITION | FSB_CAMPAIGN), FS_CDROM_VOLUME_3 },
395 
396  // multiplayer missions
397 
398  // gauntlet
399  { "g-shi.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
400  { "g-ter.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
401  { "g-vas.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
402 
403  // coop
404  { "m-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
405  { "m-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
406  { "m-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
407  { "m-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
408 
409  // dogfight
410  { "mdh-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
411  { "mdh-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
412  { "mdh-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
413  { "mdh-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
414  { "mdh-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
415  { "mdh-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
416  { "mdh-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
417  { "mdh-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
418  { "mdh-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
419  { "mdl-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
420  { "mdl-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
421  { "mdl-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
422  { "mdl-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
423  { "mdl-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
424  { "mdl-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
425  { "mdl-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
426  { "mdl-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
427  { "mdl-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
428  { "mdm-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
429  { "mdm-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
430  { "mdm-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
431  { "mdm-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
432  { "mdm-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
433  { "mdm-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
434  { "mdm-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
435  { "mdm-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
436  { "mdm-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
437  { "osdog.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
438 
439  // TvT
440  { "mt-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
441  { "mt-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
442  { "mt-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
443  { "mt-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
444  { "mt-05.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
445  { "mt-06.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
446  { "mt-07.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
447  { "mt-08.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
448  { "mt-09.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
449  { "mt-10.fs2", (FSB_FROM_VOLITION | FSB_MULTI), "" },
450 
451  // campaign
452  { "templar.fc2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN_FILE), "" },
453  { "templar-01.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
454  { "templar-02.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
455  { "templar-03.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
456  { "templar-04.fs2", (FSB_FROM_VOLITION | FSB_MULTI | FSB_CAMPAIGN), "" },
457 };
458 
459 
460 // Internal function prototypes
461 void game_maybe_draw_mouse(float frametime);
463 void load_animating_pointer(char *filename);
466 void game_shutdown(void);
467 void game_show_event_debug(float frametime);
468 void game_event_debug_init();
469 void game_frame(bool paused = false);
472 void verify_ships_tbl();
473 void verify_weapons_tbl();
476 
477 // loading background filenames
478 static char *Game_loading_bground_fname[GR_NUM_RESOLUTIONS] = {
479  "LoadingBG", // GR_640
480  "2_LoadingBG" // GR_1024
481 };
482 
483 
484 static char *Game_loading_ani_fname[GR_NUM_RESOLUTIONS] = {
485  "Loading", // GR_640
486  "2_Loading" // GR_1024
487 };
488 
489 static char *Game_title_screen_fname[GR_NUM_RESOLUTIONS] = {
490  "PreLoad",
491  "2_PreLoad"
492 };
493 
494 static char *Game_logo_screen_fname[GR_NUM_RESOLUTIONS] = {
495  "PreLoadLogo",
496  "2_PreLoadLogo"
497 };
498 
499 // for title screens
500 static int Game_title_bitmap = -1;
501 static int Game_title_logo = -1;
502 
503 // cdrom stuff
505 int init_cdrom();
506 
507 // How much RAM is on this machine. Set in WinMain
509 
510 // game flash stuff
511 float Game_flash_red = 0.0f;
512 float Game_flash_green = 0.0f;
513 float Game_flash_blue = 0.0f;
514 float Sun_spot = 0.0f;
515 big_expl_flash Big_expl_flash = {0.0f, 0.0f, 0};
516 
517 // game shudder stuff (in ms)
520 float Game_shudder_intensity = 0.0f; // should be between 0.0 and 100.0
521 
522 // EAX stuff
526 
527 
529 {
530  int idx;
531 
532  // look through all existing builtin missions
533  for(idx=0; idx<Game_builtin_mission_count; idx++){
534  if(!stricmp(Game_builtin_mission_list[idx].filename, filename)){
535  return &Game_builtin_mission_list[idx];
536  }
537  }
538 
539  // didn't find it
540  return NULL;
541 }
542 
544 {
545  return DEFAULT_SKILL_LEVEL;
546 }
547 
548 // Resets the flash
550 {
551  Game_flash_red = 0.0f;
552  Game_flash_green = 0.0f;
553  Game_flash_blue = 0.0f;
554  Sun_spot = 0.0f;
555  Big_expl_flash.max_flash_intensity = 0.0f;
556  Big_expl_flash.cur_flash_intensity = 0.0f;
557  Big_expl_flash.flash_start = 0;
558 }
559 
560 float Gf_critical = -1.0f; // framerate we should be above on the average for this mission
561 float Gf_critical_time = 0.0f; // how much time we've been at the critical framerate
562 
564 {
565  // zero critical time
566  Gf_critical_time = 0.0f;
567 
568  // nebula missions
570  Gf_critical = 15.0f;
571  } else {
572  Gf_critical = 25.0f;
573  }
574 }
575 
576 extern float Framerate;
578 {
579  int y_start = gr_screen.center_offset_y + 100;
580 
581  // if the current framerate is above the critical level, add frametime
582  if(Framerate >= Gf_critical){
583  Gf_critical_time += flFrametime;
584  }
585 
586  if (!Show_framerate) {
587  return;
588  }
589 
590  // display if we're above the critical framerate
591  if(Framerate < Gf_critical){
593  gr_string(gr_screen.center_offset_x + 200, y_start, "Framerate warning", GR_RESIZE_NONE);
594 
595  y_start += 10;
596  }
597 
598  // display our current pct of good frametime
599  if(f2fl(Missiontime) >= 0.0f){
600  float pct = (Gf_critical_time / f2fl(Missiontime)) * 100.0f;
601 
602  if(pct >= 85.0f){
604  } else {
606  }
607 
608  gr_printf_no_resize(gr_screen.center_offset_x + 200, y_start, "%d%%", (int)pct);
609 
610  y_start += 10;
611  }
612 }
613 
614 
625 void game_flash( float r, float g, float b )
626 {
627  Game_flash_red += r;
628  Game_flash_green += g;
629  Game_flash_blue += b;
630 
631  if ( Game_flash_red < -1.0f ) {
632  Game_flash_red = -1.0f;
633  } else if ( Game_flash_red > 1.0f ) {
634  Game_flash_red = 1.0f;
635  }
636 
637  if ( Game_flash_green < -1.0f ) {
638  Game_flash_green = -1.0f;
639  } else if ( Game_flash_green > 1.0f ) {
640  Game_flash_green = 1.0f;
641  }
642 
643  if ( Game_flash_blue < -1.0f ) {
644  Game_flash_blue = -1.0f;
645  } else if ( Game_flash_blue > 1.0f ) {
646  Game_flash_blue = 1.0f;
647  }
648 
649 }
650 
655 void big_explosion_flash(float flash)
656 {
657  CLAMP(flash, 0.0f, 1.0f);
658 
659  Big_expl_flash.flash_start = timestamp(1);
660  Big_expl_flash.max_flash_intensity = flash;
661  Big_expl_flash.cur_flash_intensity = 0.0f;
662 }
663 
664 // Amount to diminish palette towards normal, per second.
665 #define DIMINISH_RATE 0.75f
666 #define SUN_DIMINISH_RATE 6.00f
667 
668 int Sun_drew = 0;
669 
670 float sn_glare_scale = 1.7f;
671 DCF(sn_glare, "Sets the sun glare scale (Default is 1.7)")
672 {
673  dc_stuff_float(&sn_glare_scale);
674 }
675 
676 float Supernova_last_glare = 0.0f;
677 bool stars_sun_has_glare(int index);
678 extern bool ls_on;
679 extern bool ls_force_off;
680 void game_sunspot_process(float frametime)
681 {
682  int n_lights, idx;
683  int sn_stage;
684  float Sun_spot_goal = 0.0f;
685 
686  // supernova
687  sn_stage = supernova_active();
688  if(sn_stage){
689  // sunspot differently based on supernova stage
690  switch(sn_stage){
691  // approaching. player still in control
692  case 1:
693  float pct;
694  pct = (1.0f - (supernova_time_left() / SUPERNOVA_CUT_TIME));
695 
696  vec3d light_dir;
697  light_get_global_dir(&light_dir, 0);
698  float dot;
699  dot = vm_vec_dot( &light_dir, &Eye_matrix.vec.fvec );
700 
701  if(dot >= 0.0f){
702  // scale it some more
703  dot = dot * (0.5f + (pct * 0.5f));
704  dot += 0.05f;
705 
706  Sun_spot_goal += (dot * sn_glare_scale);
707  }
708 
709  // draw the sun glow
711  // draw the glow for this sun
713  }
714 
715  Supernova_last_glare = Sun_spot_goal;
716  break;
717 
718  // camera cut. player not in control. note : at this point camera starts out facing the sun. so we can go nice and bright
719  case 2:
720  case 3:
721  Sun_spot_goal = 0.9f;
722  Sun_spot_goal += (1.0f - (supernova_time_left() / SUPERNOVA_CUT_TIME)) * 0.1f;
723 
724  if(Sun_spot_goal > 1.0f){
725  Sun_spot_goal = 1.0f;
726  }
727 
728  Sun_spot_goal *= sn_glare_scale;
729  Supernova_last_glare = Sun_spot_goal;
730  break;
731 
732  // fade to white. display dead popup
733  case 4:
734  case 5:
735  Supernova_last_glare += (2.0f * flFrametime);
736  if(Supernova_last_glare > 2.0f){
737  Supernova_last_glare = 2.0f;
738  }
739 
740  Sun_spot_goal = Supernova_last_glare;
741  break;
742  }
743 
744  Sun_drew = 0;
745  } else {
746  Sun_spot_goal = 0.0f;
747  if ( Sun_drew ) {
748  // check sunspots for all suns
749  n_lights = light_get_global_count();
750 
751  // check
752  for(idx=0; idx<n_lights; idx++) {
753  bool in_shadow = shipfx_eye_in_shadow(&Eye_position, Viewer_obj, idx);
754 
755  if ( (ls_on && !ls_force_off) || !in_shadow ) {
756  vec3d light_dir;
757  light_get_global_dir(&light_dir, idx);
758 
759  //only do sunglare stuff if this sun has one
760  if (stars_sun_has_glare(idx)) {
761  float dot = vm_vec_dot( &light_dir, &Eye_matrix.vec.fvec )*0.5f+0.5f;
762  Sun_spot_goal += (float)pow(dot,85.0f);
763  }
764  }
765  if ( !in_shadow ) {
766  // draw the glow for this sun
767  stars_draw_sun_glow(idx);
768  }
769  }
770 
771  Sun_drew = 0;
772  }
773  }
774 
775  float dec_amount = frametime*SUN_DIMINISH_RATE;
776 
777  if ( Sun_spot < Sun_spot_goal ) {
778  Sun_spot += dec_amount;
779  if ( Sun_spot > Sun_spot_goal ) {
780  Sun_spot = Sun_spot_goal;
781  }
782  } else if ( Sun_spot > Sun_spot_goal ) {
783  Sun_spot -= dec_amount;
784  if ( Sun_spot < Sun_spot_goal ) {
785  Sun_spot = Sun_spot_goal;
786  }
787  }
788 }
789 
790 
795 void game_flash_diminish(float frametime)
796 {
797  float dec_amount = frametime*DIMINISH_RATE;
798 
799  if ( Game_flash_red > 0.0f ) {
800  Game_flash_red -= dec_amount;
801  if ( Game_flash_red < 0.0f )
802  Game_flash_red = 0.0f;
803  } else {
804  Game_flash_red += dec_amount;
805  if ( Game_flash_red > 0.0f )
806  Game_flash_red = 0.0f;
807  }
808 
809  if ( Game_flash_green > 0.0f ) {
810  Game_flash_green -= dec_amount;
811  if ( Game_flash_green < 0.0f )
812  Game_flash_green = 0.0f;
813  } else {
814  Game_flash_green += dec_amount;
815  if ( Game_flash_green > 0.0f )
816  Game_flash_green = 0.0f;
817  }
818 
819  if ( Game_flash_blue > 0.0f ) {
820  Game_flash_blue -= dec_amount;
821  if ( Game_flash_blue < 0.0f )
822  Game_flash_blue = 0.0f;
823  } else {
824  Game_flash_blue += dec_amount;
825  if ( Game_flash_blue > 0.0f )
826  Game_flash_blue = 0.0f;
827  }
828 
829  // update big_explosion_cur_flash
830 #define TIME_UP 1500
831 #define TIME_DOWN 2500
832  int duration = TIME_UP + TIME_DOWN;
833  int time = timestamp_until(Big_expl_flash.flash_start);
834  if (time > -duration) {
835  time = -time;
836  if (time < TIME_UP) {
837  Big_expl_flash.cur_flash_intensity = Big_expl_flash.max_flash_intensity * time / (float) TIME_UP;
838  } else {
839  time -= TIME_UP;
840  Big_expl_flash.cur_flash_intensity = Big_expl_flash.max_flash_intensity * ((float) TIME_DOWN - time) / (float) TIME_DOWN;
841  }
842  }
843 
844  if ( Use_palette_flash ) {
845  int r,g,b;
846 
847  // Change the 200 to change the color range of colors.
848  r = fl2i( Game_flash_red*128.0f );
849  g = fl2i( Game_flash_green*128.0f );
850  b = fl2i( Game_flash_blue*128.0f );
851 
852  if ( Sun_spot > 0.0f && (!ls_on || ls_force_off)) {
853  r += fl2i(Sun_spot*128.0f);
854  g += fl2i(Sun_spot*128.0f);
855  b += fl2i(Sun_spot*128.0f);
856  }
857 
858  if ( Big_expl_flash.cur_flash_intensity > 0.0f ) {
859  r += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
860  g += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
861  b += fl2i(Big_expl_flash.cur_flash_intensity*128.0f);
862  }
863 
864  if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
865  if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
866  if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
867 
868  if ( (r!=0) || (g!=0) || (b!=0) ) {
869  gr_flash( r, g, b );
870  }
871  }
872 
873 }
874 
875 
877 {
878  //WMC - this is actually pretty damn dangerous, but I don't want a modder
879  //to accidentally use an override here without realizing it.
881  {
882  // save player-persistent variables
884 
885  // De-Initialize the game subsystems
886  sexp_music_close(); // Goober5000
889  snd_stop_all();
890  obj_snd_level_close(); // uninit object-linked persistant sounds
891  gamesnd_unload_gameplay_sounds(); // unload gameplay sounds from memory
892  anim_level_close(); // stop and clean up any anim instances
893  message_mission_shutdown(); // called after anim_level_close() to make sure instances are clear
895  fireball_close();
901  flak_level_close(); // unload flak stuff
902  neb2_level_close(); // shutdown gaseous nebula stuff
903  ct_level_close();
906  mission_brief_common_reset(); // close out parsed briefing/mission stuff
907  cam_close();
908  subtitles_close();
909  particle_close();
912  hud_level_close();
915 
916  // be sure to not only reset the time but the lock as well
917  set_time_compression(1.0f, 0.0f);
918  lock_time_compression(false);
919 
921  Game_paused = 0;
922 
923  if (gr_screen.envmap_render_target >= 0) {
926  }
927  }
928 
929  gr_set_ambient_light(120, 120, 120);
930 
932  }
933  else
934  {
935  Error(LOCATION, "Scripting Mission End override is not fully supported yet.");
936  }
937 
939 }
940 
944 
951 {
952  game_busy( NOX("** starting game_level_init() **") );
953  load_gl_init = (uint) time(NULL);
954 
955  // seed the random number generator in multiplayer
956  if ( Game_mode & GM_MULTIPLAYER ) {
957  // seed the generator from the netgame security flags -- ensures that all players in
958  // multiplayer will have the same random number sequence (with static rand functions)
959  srand( Netgame.security );
960 
961  // semirand function needs to get re-initted every time in multiplayer
962  init_semirand();
963  }
964 
965  Framecount = 0;
968 
970  Cheats_enabled = 0;
971 
972  Game_shudder_time = -1;
973 
974  Perspective_locked = false;
975 
976  // reset the geometry map and distortion map batcher, this should to be done pretty soon in this mission load process (though it's not required)
977  batch_reset();
978 
979  // Initialize the game subsystems
980  game_reset_time(); // resets time, and resets saved time too
981 
982  Multi_ping_timestamp = -1;
983 
984  obj_init(); // Must be inited before the other systems
985 
986  if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
987  model_page_in_start(); // mark any existing models as unused but don't unload them yet
988  mprintf(( "Beginning level bitmap paging...\n" ));
990  } else {
991  model_free_all(); // Free all existing models if standalone server
992  }
993 
994  mission_brief_common_init(); // Free all existing briefing/debriefing text
996 
997  NavSystem_Init(); // zero out the nav system
998 
999  ai_level_init(); // Call this before ship_init() because it reads ai.tbl.
1000  ship_level_init();
1002  shipfx_flash_init(); // Init the ship gun flash system.
1003  game_flash_reset(); // Reset the flash effect
1004  particle_init(); // Reset the particle system
1005  fireball_init();
1006  debris_init();
1007  shield_hit_init(); // Initialize system for showing shield hits
1008 
1010  mission_log_init();
1011  messages_init();
1012  obj_snd_level_init(); // init object-linked persistant sounds
1013  anim_level_init();
1017  key_level_init();
1021  Missiontime = 0;
1023  Pre_player_entry = 1; // Means the player has not yet entered.
1024  Entry_delay_time = 0; // Could get overwritten in mission read.
1025  observer_init();
1026  flak_level_init(); // initialize flak - bitmaps, etc
1027  ct_level_init(); // initialize ships contrails, etc
1028  awacs_level_init(); // initialize AWACS
1029  beam_level_init(); // initialize beam weapons
1031  ssm_level_init();
1033  cam_init();
1034  snd_aav_init();
1035 
1036  // multiplayer dogfight hack
1037  dogfight_blown = 0;
1038 
1040 
1042  neb2_level_init();
1043  nebl_level_init();
1044 
1045  Last_view_target = NULL;
1046  Game_paused = 0;
1047 
1048  Game_no_clear = 0;
1049 
1050  // campaign wasn't ended
1052 
1053  Env_cubemap_drawn = false;
1054 
1055  load_gl_init = (uint) (time(NULL) - load_gl_init);
1056 
1057  //WMC - Init multi players for level
1058  if (Game_mode & GM_MULTIPLAYER && Player != NULL) {
1060 
1061  // clear multiplayer stats
1063  }
1064 }
1065 
1070 {
1071  game_level_close();
1073 }
1074 
1079 {
1080  Assert( Net_player != NULL );
1081  if (!(Game_mode & GM_MULTIPLAYER)){
1082  return;
1083  }
1084 
1085  // see if this player should be reading/writing data. Bit is set when at join
1086  // screen onward until quits back to main menu.
1088  return;
1089  }
1090 
1092  multi_do_frame();
1093  } else {
1095  }
1096 }
1097 
1098 // An estimate as to how high the count passed to game_loading_callback will go.
1099 // This is just a guess, it seems to always be about the same. The count is
1100 // proportional to the code being executed, not the time, so this works good
1101 // for a bar, assuming the code does about the same thing each time you
1102 // load a level. You can find this value by looking at the return value
1103 // of game_busy_callback(NULL), which I conveniently print out to the
1104 // debug output window with the '=== ENDING LOAD ==' stuff.
1105 #define COUNT_ESTIMATE 425
1106 
1110 
1111 static int Game_loading_ani_coords[GR_NUM_RESOLUTIONS][2] = {
1112  {
1113  63, 316 // GR_640
1114  },
1115  {
1116  101, 505 // GR_1024
1117  }
1118 };
1119 
1120 #ifndef NDEBUG
1121 extern char Processing_filename[MAX_PATH_LEN];
1122 static int busy_shader_created = 0;
1124 #endif
1125 static int framenum;
1126 
1132 {
1133  int new_framenum;
1135 
1136  Assert( Game_loading_callback_inited==1 );
1137  Assertion( Game_loading_ani.num_frames > 0, "Load Screen animation %s not found, or corrupted. Needs to be an animation with at least 1 frame.", Game_loading_ani.filename );
1138 
1139  int do_flip = 0;
1140 
1141  new_framenum = ((Game_loading_ani.num_frames*count) / COUNT_ESTIMATE)+1;
1142  if ( new_framenum > Game_loading_ani.num_frames-1 ) {
1143  new_framenum = Game_loading_ani.num_frames-1;
1144  } else if ( new_framenum < 0 ) {
1145  new_framenum = 0;
1146  }
1147  //make sure we always run forwards - graphical hack
1148  if(new_framenum > framenum)
1149  framenum = new_framenum;
1150 
1151  if ( Game_loading_ani.num_frames > 0 ) {
1152  GR_MAYBE_CLEAR_RES(Game_loading_background);
1153  if ( Game_loading_background > -1 ) {
1154  gr_set_bitmap( Game_loading_background );
1156  }
1157 
1158  gr_set_bitmap( Game_loading_ani.first_frame + framenum );
1159  gr_bitmap(Game_loading_ani_coords[gr_screen.res][0],Game_loading_ani_coords[gr_screen.res][1], GR_RESIZE_MENU);
1160 
1161  do_flip = 1;
1162  }
1163 
1164 #ifndef NDEBUG
1165  // print the current filename being processed by game_busy(), the shader here is a quick hack
1166  // since the background isn't always drawn so we can't clear the text away from the previous
1167  // filename. the shader is completely opaque to hide the old text. must easier and faster than
1168  // redrawing the entire screen every flip - taylor
1169  if (!busy_shader_created) {
1170  gr_create_shader(&busy_shader, 5, 5, 5, 255);
1171  busy_shader_created = 1;
1172  }
1173 
1174  if (Processing_filename[0] != '\0') {
1175  gr_set_shader(&busy_shader);
1176  gr_shade(0, 0, gr_screen.max_w_unscaled, 17, GR_RESIZE_MENU); // make sure it goes across the entire width
1177 
1179  gr_string(5, 5, Processing_filename, GR_RESIZE_MENU);
1180 
1181  do_flip = 1;
1182  memset( Processing_filename, 0, MAX_PATH_LEN );
1183  }
1184 #endif
1185 
1186 #ifndef NDEBUG
1188  {
1189 #ifdef _WIN32
1190  void memblockinfo_sort();
1191  void memblockinfo_sort_get_entry(int index, char *filename, int *size);
1192 
1193  char mem_buffer[1000];
1194  char filename[35];
1195  int size;
1196  int i;
1197  int line_height = gr_get_font_height() + 1;
1198 
1199  memblockinfo_sort();
1200  for(i = 0; i < 30; i++)
1201  {
1202  memblockinfo_sort_get_entry(i, filename, &size);
1203 
1204  size /= 1024;
1205 
1206  if(size == 0)
1207  break;
1208 
1209  char *short_name = strrchr(filename, '\\');
1210  if(short_name == NULL)
1211  short_name = filename;
1212  else
1213  short_name++;
1214 
1215  sprintf(mem_buffer,"%s:\t%d K", short_name, size);
1216  gr_string( 20, 220 + (i*line_height), mem_buffer, GR_RESIZE_MENU);
1217  }
1218  sprintf(mem_buffer,"Total RAM:\t%d K", TotalRam / 1024);
1219  gr_string( 20, 230 + (i*line_height), mem_buffer, GR_RESIZE_MENU);
1220 #endif // _WIN32
1221  }
1222 #endif // !NDEBUG
1223 
1224  if (do_flip)
1225  gr_flip();
1226 }
1227 
1229 {
1230  Assert( Game_loading_callback_inited==0 );
1231 
1232  Game_loading_background = bm_load(The_mission.loading_screen[gr_screen.res]);
1233 
1234  if (Game_loading_background < 0)
1235  Game_loading_background = bm_load(Game_loading_bground_fname[gr_screen.res]);
1236 
1237  generic_anim_init(&Game_loading_ani, Game_loading_ani_fname[gr_screen.res]);
1238  generic_anim_load(&Game_loading_ani);
1239  Assertion( Game_loading_ani.num_frames > 0, "Load Screen animation %s not found, or corrupted. Needs to be an animation with at least 1 frame.", Game_loading_ani.filename );
1240 
1241  Game_loading_callback_inited = 1;
1242  Mouse_hidden = 1;
1243  framenum = 0;
1245 
1246 
1247 }
1248 
1250 {
1251  Assert( Game_loading_callback_inited==1 );
1252 
1253  // Make sure bar shows all the way over.
1255 
1256  int real_count __UNUSED = game_busy_callback( NULL );
1257  Mouse_hidden = 0;
1258 
1259  Game_loading_callback_inited = 0;
1260 
1261 #ifndef NDEBUG
1262  mprintf(( "=================== ENDING LOAD ================\n" ));
1263  mprintf(( "Real count = %d, Estimated count = %d\n", real_count, COUNT_ESTIMATE ));
1264  mprintf(( "================================================\n" ));
1265 #else
1266  // to remove warnings in release build
1267  real_count = 0;
1268 #endif
1269 
1270  generic_anim_unload(&Game_loading_ani);
1271 
1272  bm_release( Game_loading_background );
1273  common_free_interface_palette(); // restore game palette
1274  Game_loading_background = -1;
1275 
1276  gr_set_font( FONT1 );
1277 }
1278 
1283 {
1284  // do nothing for now
1285 }
1286 
1291 {
1292  if (The_mission.sound_environment.id >= 0) {
1293  Game_sound_env = The_mission.sound_environment;
1294  } else if (SND_ENV_DEFAULT > 0) {
1295  sound_env_get(&Game_sound_env, SND_ENV_DEFAULT);
1296  } else {
1297  Game_sound_env = Game_default_sound_env;
1298  }
1299 
1300  Game_sound_env_update_timestamp = timestamp(1);
1301 }
1302 
1307 {
1308  // called if we're not on a freespace dedicated (non rendering, no pilot) server
1309  // IE : we _don't_ want to load any sounds or bitmap/texture info on this machine.
1310  if(!(Game_mode & GM_STANDALONE_SERVER)){
1311 
1312  mprintf(( "=================== STARTING LEVEL DATA LOAD ==================\n" ));
1313 
1314  game_busy( NOX("** setting up event music **") );
1315  event_music_level_init(-1); // preloads the first 2 seconds for each event music track
1316 
1317  game_busy( NOX("** unloading interface sounds **") );
1318  gamesnd_unload_interface_sounds(); // unload interface sounds from memory
1319 
1320  game_busy( NOX("** preloading common game sounds **") );
1321  gamesnd_preload_common_sounds(); // load in sounds that are expected to play
1322 
1323  if (Cmdline_snd_preload) {
1324  game_busy( NOX("** preloading gameplay sounds **") );
1325  gamesnd_load_gameplay_sounds(); // preload in gameplay sounds if wanted
1326  }
1327 
1328  game_busy( NOX("** assigning sound environment for mission **") );
1329  ship_assign_sound_all(); // assign engine sounds to ships
1330  game_assign_sound_environment(); // assign the sound environment for this mission
1331 
1333 
1334  if (!(Game_mode & GM_MULTIPLAYER)) {
1335  // call function in missionparse.cpp to fixup player/ai stuff.
1336  game_busy( NOX("** fixing up player/ai stuff **") );
1338  }
1339 
1340  // Load in all the bitmaps for this level
1341  level_page_in();
1342 
1343  game_busy( NOX("** finished with level_page_in() **") );
1344 
1345  if(Game_loading_callback_inited) {
1347  }
1348  }
1349  // the only thing we need to call on the standalone for now.
1350  else {
1352 
1353  // Load in all the bitmaps for this level
1354  level_page_in();
1355  }
1356 }
1357 
1364 {
1365  extern void game_environment_map_gen();
1367 
1368  HUD_init();
1370  mission_hotkey_set_defaults(); // set up the default hotkeys (from mission file)
1371 
1373 
1374  // While trying to track down the nebula bug I encountered a cool effect -
1375  // comment this out to fly a mission in a void. Maybe we should develop this
1376  // into a full effect or something, because it is seriously cool.
1378 
1379 #ifndef NDEBUG
1381 #endif
1382 
1385 
1386  // set ambient light for level
1388  (The_mission.ambient_light_level >> 8) & 0xff,
1389  (The_mission.ambient_light_level >> 16) & 0xff);
1390 
1392 
1393  // If this is a red alert mission in campaign mode, bash wingman status
1394  if ( (Game_mode & GM_CAMPAIGN_MODE) && red_alert_mission() ) {
1396  }
1397 
1399 
1400  // m!m Make hv.Player available in "On Mission Start" hook
1401  if(Player_obj)
1403 
1404  // HACK: That scripting hook should be in mission so GM_IN_MISSION has to be set
1408 
1409  if (Player_obj)
1410  Script_system.RemHookVar("Player");
1411 }
1412 
1417 {
1418  mprintf(( "=================== STARTING LEVEL LOAD ==================\n" ));
1419 
1420  int s1 __UNUSED = timer_get_milliseconds();
1421 
1422  // clear post processing settings
1424 
1425  get_mission_info(Game_current_mission_filename, &The_mission, false);
1426 
1427  if ( !(Game_mode & GM_STANDALONE_SERVER) )
1429 
1430  game_level_init();
1431 
1432  if (Game_mode & GM_MULTIPLAYER) {
1434 
1435  // clear multiplayer stats
1437  }
1438 
1439  game_busy( NOX("** starting mission_load() **") );
1440  load_mission_load = (uint) time(NULL);
1441  if (mission_load(Game_current_mission_filename)) {
1442  if ( !(Game_mode & GM_MULTIPLAYER) ) {
1443  popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "Attempt to load the mission failed", 169));
1445  } else {
1447  }
1448 
1449  if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
1451  }
1452 
1453  game_level_close();
1454 
1455  return 0;
1456  }
1457  load_mission_load = (uint) (time(NULL) - load_mission_load);
1458 
1459  // free up memory from parsing the mission
1460  extern void stop_parse();
1461  stop_parse();
1462 
1463  game_busy( NOX("** starting game_post_level_init() **") );
1464  load_post_level_init = (uint) time(NULL);
1466  load_post_level_init = (uint) (time(NULL) - load_post_level_init);
1467 
1468 #ifndef NDEBUG
1469  {
1470  void Do_model_timings_test();
1472  }
1473 #endif
1474 
1475  bm_print_bitmaps();
1476 
1477  int e1 __UNUSED = timer_get_milliseconds();
1478 
1479  mprintf(("Level load took %f seconds.\n", (e1 - s1) / 1000.0f ));
1480 
1481  return 1;
1482 }
1483 
1485 #ifndef NDEBUG
1486 
1487 DCF_BOOL( mouse_control, Use_mouse_to_fly )
1488 DCF_BOOL( show_framerate, Show_framerate )
1489 DCF_BOOL( show_target_debug_info, Show_target_debug_info )
1490 DCF_BOOL( show_target_weapons, Show_target_weapons )
1491 DCF_BOOL( lead_target_cheat, Players[Player_num].lead_target_cheat )
1493 DCF_BOOL( zbuffer, game_zbuffer )
1494 DCF_BOOL( show_shield_mesh, Show_shield_mesh)
1495 DCF_BOOL( player_attacking, Player_attacking_enabled )
1496 DCF_BOOL( show_waypoints, Show_waypoints )
1497 DCF_BOOL( show_area_effect, Show_area_effect )
1498 DCF_BOOL( show_net_stats, Show_net_stats )
1500 extern int Training_message_method;
1501 DCF_BOOL( training_msg_method, Training_message_method )
1502 DCF_BOOL( show_player_pos, Show_player_pos )
1503 DCF_BOOL(i_framerate, Interface_framerate )
1504 
1505 DCF(warp, "Tests warpin effect")
1506 {
1507  if (dc_optional_string_either("help", "--help")) {
1508  dc_printf( "Params: bool warpin, string Target = ""\n Warps in if true, out if false. Player is target unless specific ship is specified\n" );
1509  return;
1510  } // Else, process command
1511 
1512  // TODO: Provide status flag
1513 
1514  bool warpin;
1515  char target[MAX_NAME_LEN];
1516  int idx = -1;
1517 
1518  dc_stuff_boolean(&warpin);
1520  idx = ship_name_lookup(target);
1521  } // Else, default target to player
1522 
1523  if (idx < 0) {
1524  // Player is target
1525  if (Player_ai->target_objnum > -1) {
1526  if(warpin) {
1528  } else {
1530  }
1531  }
1532  } else {
1533  // Non-player is targer
1534  if (warpin) {
1535  shipfx_warpin_start(&Objects[Ships[idx].objnum]);
1536  } else {
1537  shipfx_warpout_start(&Objects[Ships[idx].objnum]);
1538  }
1539  }
1540 
1541 }
1542 
1543 DCF(show_mem,"Toggles showing mem usage")
1544 {
1545  bool process = true;
1546 
1547  if (dc_optional_string_either("help", "--help")) {
1548  dc_printf( "Usage: (optional) bool Show_mem\n If true, Show_mem is set and Show_cpu is cleared. If false, then Show_mem is cleared. If nothing passed, then toggle.\n" );
1549  process = false;
1550  }
1551 
1552  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1553  dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
1554  dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
1555  process = false;
1556  }
1557 
1558  if (!process) {
1559  // Help and/or status was given, so don't process the command
1560  return;
1561  } // Else, process the command
1562 
1563  if (!dc_maybe_stuff_boolean(&Show_mem)) {
1564  // Nothing passed, so toggle
1565  Show_mem = !Show_mem;
1566  } // Else, value was set/cleared by user
1567 
1568  // Can't show mem and cpu at same time
1569  if (Show_mem) {
1570  Show_cpu = false;
1571  }
1572 }
1573 
1574 DCF(show_cpu,"Toggles showing cpu usage")
1575 {
1576  bool process = true;
1577 
1578  if (dc_optional_string_either("help", "--help")) {
1579  dc_printf( "Usage: (optional) bool Show_cpu\n If true, Show_cpu is set and Show_mem is cleared. If false, then Show_cpu is cleared. If nothing passed, then toggle.\n" );
1580  process = false;
1581  }
1582 
1583  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1584  dc_printf("Show_cpu is %s\n", (Show_cpu ? "TRUE" : "FALSE"));
1585  dc_printf("Show_mem is %s\n", (Show_mem ? "TRUE" : "FALSE"));
1586  process = false;
1587  }
1588 
1589  if (!process) {
1590  // Help and/or status was given, so don't process the command
1591  return;
1592  } // Else, process the command
1593 
1594  if (!dc_maybe_stuff_boolean(&Show_cpu)) {
1595  // Nothing passed, so toggle
1596  Show_cpu = !Show_cpu;
1597  } // Else, value was set/cleared by user
1598 
1599  // Can't show mem and cpu at same time
1600  if (Show_cpu) {
1601  Show_mem = false;
1602  }
1603 }
1604 
1605 #endif
1606 
1607 DCF(use_joy_mouse,"Makes joystick move mouse cursor")
1608 {
1609  bool process = true;
1610 
1611  if (dc_optional_string_either("help", "--help")) {
1612  dc_printf("Usage: use_joy_mouse [bool]\nSets use_joy_mouse to true or false. If nothing passed, then toggles it.\n");
1613  process = false;
1614  }
1615 
1616  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1617  dc_printf("use_joy_mouse is %s\n", (Use_joy_mouse ? "TRUE" : "FALSE"));
1618  process = false;
1619  }
1620 
1621  if (!process) {
1622  return;
1623  }
1624 
1625  if(!dc_maybe_stuff_boolean(&Use_joy_mouse)) {
1626  // Nothing passed, so toggle
1627  Use_joy_mouse = !Use_joy_mouse;
1628  } // Else, value was set/cleared by user
1629 
1630  os_config_write_uint( NULL, NOX("JoystickMovesCursor"), Use_joy_mouse );
1631 }
1632 
1633 DCF_BOOL(palette_flash, Use_palette_flash);
1634 
1635 int Use_low_mem = 0;
1636 
1637 DCF(low_mem,"Uses low memory settings regardless of RAM")
1638 {
1639  bool process = true;
1640 
1641  if (dc_optional_string_either("help", "--help")) {
1642  dc_printf("Usage: low_mem [bool]\nSets low_mem to true or false. If nothing passed, then toggles it.\n");
1643  process = false;
1644  }
1645 
1646  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1647  dc_printf("low_mem is %s\n", (Use_low_mem ? "TRUE" : "FALSE"));
1648  process = false;
1649  }
1650 
1651  if (!process) {
1652  return;
1653  }
1654 
1655  if (!dc_maybe_stuff_boolean(&Use_low_mem)) {
1656  // Nothing passed, so toggle
1657  Use_low_mem = !Use_low_mem;
1658  } // Else, value was set/cleared by user
1659 
1660  os_config_write_uint( NULL, NOX("LowMem"), Use_low_mem );
1661 }
1662 
1663 
1664 #ifndef NDEBUG
1665 
1666 DCF(force_fullscreen, "Forces game to startup in fullscreen mode")
1667 {
1668  bool process = true;
1669  if (dc_optional_string_either("help", "--help")) {
1670  dc_printf("Usage: low_mem [bool]\nSets low_mem to true or false. If nothing passed, then toggles it.\n");
1671  process = false;
1672  }
1673 
1674  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1675  dc_printf("low_mem is %s\n", (Use_fullscreen_at_startup ? "TRUE" : "FALSE"));
1676  process = false;
1677  }
1678 
1679  if (!process) {
1680  return;
1681  }
1682 
1683  if (dc_maybe_stuff_boolean(&Use_fullscreen_at_startup)) {
1684  // Nothing passed, so toggle
1685  Use_fullscreen_at_startup = !Use_fullscreen_at_startup;
1686  } // Else, value was set/cleared by user
1687 
1688  os_config_write_uint( NULL, NOX("ForceFullscreen"), Use_fullscreen_at_startup );
1689 }
1690 #endif
1691 
1693 
1694 float FreeSpace_gamma = 1.0f;
1695 
1696 DCF(gamma,"Sets and saves Gamma Factor")
1697 {
1698  if (dc_optional_string_either("help", "--help")) {
1699  dc_printf( "Usage: gamma <float>\n" );
1700  dc_printf( "Sets gamma in range 1-3, no argument resets to default 1.2\n" );
1701  return;
1702  }
1703 
1704  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
1705  dc_printf( "Gamma = %.2f\n", FreeSpace_gamma );
1706  return;
1707  }
1708 
1709  if (!dc_maybe_stuff_float(&FreeSpace_gamma)) {
1710  dc_printf( "Gamma reset to 1.0f\n" );
1711  FreeSpace_gamma = 1.0f;
1712  }
1713  if ( FreeSpace_gamma < 0.1f ) {
1714  FreeSpace_gamma = 0.1f;
1715  } else if ( FreeSpace_gamma > 5.0f ) {
1716  FreeSpace_gamma = 5.0f;
1717  }
1718  gr_set_gamma(FreeSpace_gamma);
1719 
1720  char tmp_gamma_string[32];
1721  sprintf( tmp_gamma_string, NOX("%.2f"), FreeSpace_gamma );
1722  os_config_write_string( NULL, NOX("Gamma"), tmp_gamma_string );
1723 }
1724 
1725 #ifdef APPLE_APP
1726 char full_path[1024];
1727 #endif
1728 
1733 {
1734  int s1 __UNUSED, e1 __UNUSED;
1735  const char *ptr;
1736  char whee[MAX_PATH_LEN];
1737 
1738  Game_current_mission_filename[0] = 0;
1739 
1740  // Moved from rand32, if we're gonna break, break immediately.
1741  Assert(RAND_MAX == 0x7fff || RAND_MAX >= 0x7ffffffd);
1742  // seed the random number generator
1743  int game_init_seed = (int) time(NULL);
1744  srand( game_init_seed );
1745 
1746  Framerate_delay = 0;
1747 
1748 #ifndef NDEBUG
1749  load_filter_info();
1750 #endif
1751 
1752  // encrypt stuff
1753  encrypt_init();
1754 
1755  // Initialize the timer before the os
1756  timer_init();
1757 
1758 #ifndef NDEBUG
1759  outwnd_init(1);
1760 #endif
1761 
1762  // init os stuff next
1763  if ( !Is_standalone ) {
1765  }
1766  else {
1767  std_init_os();
1768  }
1769 
1770 #ifndef NDEBUG
1771  #if FS_VERSION_REVIS == 0
1772  mprintf(("FreeSpace 2 Open version: %i.%i.%i\n", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD));
1773  #else
1774  mprintf(("FreeSpace 2 Open version: %i.%i.%i.%i\n", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD, FS_VERSION_REVIS));
1775  #endif
1776 
1777  extern void cmdline_debug_print_cmdline();
1779 #endif
1780 
1781  memset(whee, 0, sizeof(whee));
1782 
1784 
1785  strcat_s(whee, DIR_SEPARATOR_STR);
1786  strcat_s(whee, EXE_FNAME);
1787 
1788  profile_init();
1789  //Initialize the libraries
1790  s1 = timer_get_milliseconds();
1791 
1792  if ( cfile_init(whee, strlen(Game_CDROM_dir) ? Game_CDROM_dir : NULL) ) { // initialize before calling any cfopen stuff!!!
1793  exit(1);
1794  }
1795 
1796  e1 = timer_get_milliseconds();
1797 
1798  // initialize localization module. Make sure this is done AFTER initialzing OS.
1799  lcl_init( detect_lang() );
1800  lcl_xstr_init();
1801 
1802  mod_table_init(); // load in all the mod dependent settings
1803 
1804  if (Is_standalone) {
1805  // force off some cmdlines if they are on
1806  Cmdline_spec = 0;
1807  Cmdline_glow = 0;
1808  Cmdline_env = 0;
1809  Cmdline_3dwarp = 0;
1810  Cmdline_normal = 0;
1811 
1812  // now init the standalone server code
1814  }
1815 
1816  // verify that he has a valid ships.tbl (will Game_ships_tbl_valid if so)
1817  verify_ships_tbl();
1818 
1819  // verify that he has a valid weapons.tbl
1821 
1822 
1823  Use_joy_mouse = 0;
1824  Use_low_mem = os_config_read_uint( NULL, NOX("LowMem"), 0 );
1825 
1826 #ifndef NDEBUG
1827  Use_fullscreen_at_startup = os_config_read_uint( NULL, NOX("ForceFullscreen"), 1 );
1828 #endif
1829 
1830  // change FPS cap if told to do so (for those who can't use vsync or where vsync isn't enough)
1831  uint max_fps = 0;
1832  if ( (max_fps = os_config_read_uint(NULL, NOX("MaxFPS"), 0)) != 0 ) {
1833  if ( (max_fps > 15) && (max_fps < 120) ) {
1834  Framerate_cap = (int)max_fps;
1835  }
1836  }
1837 
1838  Asteroids_enabled = 1;
1839 
1841 // SOUND INIT START
1843 
1844  if ( !Is_standalone ) {
1845  snd_init();
1846  }
1847 
1848  if(fsspeech_init() == false) {
1849  mprintf(("Failed to init speech\n"));
1850 
1852  {
1853  if(!fsspeech_was_compiled())
1854  MessageBox((HWND)os_get_window(), "Speech is not compiled in this build in code.lib", "FS2_Open Warning", MB_ICONWARNING);
1855  else
1856  MessageBox((HWND)os_get_window(), "Speech is compiled, but failed to init", "FS2_Open Warning", MB_ICONWARNING);
1857  }
1858  } else if(Cmdline_query_speech) {
1859  // Its bad practice to use a negative type, this is an exceptional case
1860  fsspeech_play(-1,"Welcome to FS2 open");
1861  MessageBox((HWND)os_get_window(), "Speech is compiled and initialised and should be working", "FS2_Open Info", MB_OK);
1862  }
1863 
1865 // SOUND INIT END
1867 
1868  if ( gr_init() == false ) {
1869 #ifdef _WIN32
1870  ClipCursor(NULL);
1871  ShowCursor(TRUE);
1872  ShowWindow((HWND)os_get_window(),SW_MINIMIZE);
1873  MessageBox( NULL, "Error intializing graphics!", "Error", MB_OK|MB_TASKMODAL|MB_SETFOREGROUND );
1874 #elif defined(SCP_UNIX)
1875  fprintf(stderr, "Error initializing graphics!");
1876 
1877  // the default entry should have been created already if it didn't exist, so if we're here then
1878  // the current value is invalid and we need to replace it
1879  os_config_write_string(NULL, NOX("VideocardFs2open"), NOX("OGL -(1024x768)x16 bit"));
1880 
1881  // courtesy
1882  fprintf(stderr, "The default video entry is now in place. Please try running the game again...\n");
1883  fprintf(stderr, "(edit ~/.fs2_open/fs2_open.ini to change from default resolution)\n");
1884 #endif
1885  exit(1);
1886  return;
1887  }
1888 
1889 // Karajorma - Moved here from the sound init code cause otherwise windows complains
1890 #ifdef FS2_VOICER
1892  {
1894 
1895  if(voiceRectOn == false)
1896  {
1897  MessageBox((HWND)os_get_window(), "Failed to init voice rec", "Error", MB_OK);
1898  }
1899  }
1900 
1901 #endif
1902 
1903  // D3D's gamma system now works differently. 1.0 is the default value
1904  ptr = os_config_read_string(NULL, NOX("GammaD3D"), NOX("1.0"));
1905  FreeSpace_gamma = (float)atof(ptr);
1906 
1907  script_init(); //WMC
1908 
1909  gr_font_init(); // loads up all fonts
1910 
1911  // add title screen
1912  if(!Is_standalone){
1913  // #Kazan# - moved this down - WATCH THESE calls - anything that shares code between standalone and normal
1914  // cannot make gr_* calls in standalone mode because all gr_ calls are NULL pointers
1915  gr_set_gamma(FreeSpace_gamma);
1917  }
1918 
1919  // attempt to load up master tracker registry info (login and password)
1920  Multi_tracker_id = -1;
1921 
1922  // should we be using this or not?
1923  Om_tracker_flag = os_config_read_uint( "PXO", "FS2OpenPXO" , 0 );
1924  // pxo login and password
1925  ptr = os_config_read_string(NOX("PXO"),NOX("Login"),NULL);
1926  if(ptr == NULL){
1927  nprintf(("Network","Error reading in PXO login data\n"));
1929  } else {
1931  }
1932  ptr = os_config_read_string(NOX("PXO"),NOX("Password"),NULL);
1933  if(ptr == NULL){
1934  nprintf(("Network","Error reading PXO password\n"));
1936  } else {
1938  }
1939 
1940  // pxo squad name and password
1941  ptr = os_config_read_string(NOX("PXO"),NOX("SquadName"),NULL);
1942  if(ptr == NULL){
1943  nprintf(("Network","Error reading in PXO squad name\n"));
1945  } else {
1947  }
1948 
1949  // If less than 48MB of RAM, use low memory model.
1950  if (
1951 #ifdef _WIN32
1952  (FreeSpace_total_ram < 48*1024*1024) ||
1953 #endif
1954  Use_low_mem ) {
1955  mprintf(( "Using normal memory settings...\n" ));
1956  bm_set_low_mem(1); // Use every other frame of bitmaps
1957  } else {
1958  mprintf(( "Using high memory settings...\n" ));
1959  bm_set_low_mem(0); // Use all frames of bitmaps
1960  }
1961 
1962  //WMC - Initialize my new GUI system
1963  //This may seem scary, but it should take up 0 processing time and very little memory
1964  //as long as it's not being used.
1965  //Otherwise, it just keeps the parsed interface.tbl in memory.
1966  GUI_system.ParseClassInfo("interface.tbl");
1967 
1968  // load non-darkening pixel defs
1970 
1971  iff_init(); // Goober5000 - this must be done even before species_defs :p
1972  species_init(); // Load up the species defs - this needs to be done FIRST -- Kazan
1973 
1975 
1976  hud_init_comm_orders(); // Goober5000
1977 
1978  control_config_common_init(); // sets up localization stuff in the control config
1979 
1980  parse_rank_tbl();
1981  parse_medal_tbl();
1982 
1983  cutscene_init();
1984  key_init();
1985  mouse_init();
1987 
1988  gameseq_init();
1989 
1990  multi_init();
1991 
1992  // start up the mission logfile
1994  log_string(LOGFILE_EVENT_LOG,"FS2_Open Mission Log - Opened \n\n", 1);
1995 
1996  // standalone's don't use the joystick and it seems to sometimes cause them to not get shutdown properly
1997  if(!Is_standalone){
1998  joy_init();
1999  }
2000 
2002  model_init();
2003 
2004  event_music_init();
2005 
2006  // initialize alpha colors
2007  // CommanderDJ: try with colors.tbl first, then use the old way if that doesn't work
2009 
2010  obj_init();
2011  mflash_game_init();
2012  armor_init();
2013  ai_init();
2014  ai_profiles_init(); // Goober5000
2015  weapon_init();
2016  glowpoint_init();
2017  ship_init(); // read in ships.tbl
2018 
2019  player_init();
2020  mission_campaign_init(); // load in the default campaign
2021  anim_init();
2022  context_help_init();
2023  techroom_intel_init(); // parse species.tbl, load intel info
2024  hud_positions_init(); //Setup hud positions
2025 
2026  // initialize psnet
2027  psnet_init( Multi_options_g.protocol, Multi_options_g.port ); // initialize the networking code
2028 
2030  asteroid_init();
2031  mission_brief_common_init(); // Mark all the briefing structures as empty.
2032 
2033  neb2_init(); // fullneb stuff
2034  nebl_init();
2035  stars_init();
2036  ssm_init();
2037  player_tips_init(); // helpful tips
2038  beam_init();
2039 
2040  // load the list of pilot pic filenames (for barracks and pilot select popup quick reference)
2043 
2044  load_animating_pointer(NOX("cursor"));
2045 
2047  {
2049  }
2050 
2051  if (Cmdline_env) {
2052  ENVMAP = Default_env_map = bm_load("cubemap");
2053  }
2054 
2055  Viewer_mode = 0;
2056  Game_paused = 0;
2057 
2060 
2062 
2063  // convert old pilot files (if they need it)
2065 
2066 #ifdef _WIN32
2067  timeBeginPeriod(1);
2068 #endif
2069 
2070  nprintf(("General", "Ships.tbl is : %s\n", Game_ships_tbl_valid ? "VALID" : "INVALID!!!!"));
2071  nprintf(("General", "Weapons.tbl is : %s\n", Game_weapons_tbl_valid ? "VALID" : "INVALID!!!!"));
2072 
2073  mprintf(("cfile_init() took %d\n", e1 - s1));
2075 }
2076 
2077 char transfer_text[128];
2078 
2079 float Start_time = 0.0f;
2080 
2081 float Framerate = 0.0f;
2082 
2083 #ifndef NDEBUG
2084 float Timing_total = 0.0f;
2085 float Timing_render2 = 0.0f;
2086 float Timing_render3 = 0.0f;
2087 float Timing_flip = 0.0f;
2088 float Timing_clear = 0.0f;
2089 #endif
2090 
2091 MONITOR(NumPolysDrawn)
2092 MONITOR(NumPolys)
2093 MONITOR(NumVerts)
2094 MONITOR(BmpUsed)
2095 MONITOR(BmpNew)
2096 
2097 
2101 
2103 {
2104  if (frame_int == -1) {
2105  for (int i = 0; i < FRAME_FILTER; i++)
2106  frametimes[i] = 0.0f;
2107 
2108  frametotal = 0.0f;
2109  frame_int = 0;
2110  }
2111 
2112  frametotal -= frametimes[frame_int];
2113  frametotal += flRealframetime;
2114  frametimes[frame_int] = flRealframetime;
2115  frame_int = (frame_int + 1 ) % FRAME_FILTER;
2116 
2117  if (frametotal != 0.0f) {
2118  if (Framecount >= FRAME_FILTER)
2119  Framerate = FRAME_FILTER / frametotal;
2120  else
2121  Framerate = Framecount / frametotal;
2122  }
2123 
2124  Framecount++;
2125 }
2126 
2131 {
2132  float cur_time;
2133  int line_height = gr_get_font_height() + 1;
2134 
2135  cur_time = f2fl(timer_get_approx_seconds());
2136  if (cur_time - Start_time > 30.0f) {
2137  mprintf(("%i frames executed in %7.3f seconds, %7.3f frames per second.\n", Framecount, cur_time - Start_time, Framecount/(cur_time - Start_time)));
2138  Start_time += 1000.0f;
2139  }
2140 
2141 #ifdef WMC
2142  //WMC - this code spits out the target of all turrets
2143  if ( (Player_ai->target_objnum != -1) && (Objects[Player_ai->target_objnum].type == OBJ_SHIP) ) {
2144  //Debug crap
2145  int t = 0;
2146  ship_subsys *pss;
2147 
2149 
2150  object *objp = &Objects[Player_ai->target_objnum];
2151  for ( pss = GET_FIRST(&shipp->subsys_list); pss !=END_OF_LIST(&shipp->subsys_list); pss = GET_NEXT(pss) ) {
2152  if (pss->system_info->type == SUBSYSTEM_TURRET) {
2153  if(pss->turret_enemy_objnum == -1)
2154  gr_printf_no_resize(gr_screen.center_offset_x + 10, gr_screen.center_offset_y + (t*line_height), "Turret %d: <None>", t);
2155  else if (Objects[pss->turret_enemy_objnum].type == OBJ_SHIP)
2157  else
2158  gr_printf_no_resize(gr_screen.center_offset_x + 10, gr_screen.center_offset_y + (t*line_height), "Turret %d: <Object %d>", t, pss->turret_enemy_objnum);
2159 
2160  t++;
2161  }
2162  }
2163  }
2164 #endif
2165 
2166 
2167  if (Show_framerate || Cmdline_frame_profile) {
2169 
2170  if (Cmdline_frame_profile) {
2172  }
2173 
2174  if (Show_framerate) {
2175  if (frametotal != 0.0f)
2176  gr_printf_no_resize( gr_screen.center_offset_x + 20, gr_screen.center_offset_y + 100, "FPS: %0.1f", Framerate );
2177  else
2179  }
2180  }
2181 
2182 #ifndef NDEBUG
2183  if ( Debug_dump_frames )
2184  return;
2185 #endif
2186 
2187  // possibly show control checking info
2189 
2190 #ifdef _WIN32
2191  if (Cmdline_show_stats && HUD_draw) {
2192  int sx,sy;
2193  sx = gr_screen.center_offset_x + 20;
2194  sy = gr_screen.center_offset_y + 100 + (line_height * 2);
2195 
2196  char mem_buffer[50];
2197 
2198  MEMORYSTATUS mem_stats;
2199  GlobalMemoryStatus(&mem_stats);
2200 
2201  // on win2k+, it should be == -1 if >4gig (indicates wrap around)
2202  if ( ((int)Mem_starttime_phys == -1) || ((int)mem_stats.dwAvailPhys == -1) )
2203  sprintf(mem_buffer, "Using Physical: *** (>4G)");
2204  else
2205  sprintf(mem_buffer,"Using Physical: %d Meg",(Mem_starttime_phys - mem_stats.dwAvailPhys)/1024/1024);
2206 
2207  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2208  sy += line_height;
2209  sprintf(mem_buffer,"Using Pagefile: %d Meg",(Mem_starttime_pagefile - mem_stats.dwAvailPageFile)/1024/1024);
2210  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2211  sy += line_height;
2212  sprintf(mem_buffer,"Using Virtual: %d Meg",(Mem_starttime_virtual - mem_stats.dwAvailVirtual)/1024/1024);
2213  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2214  sy += line_height * 2;
2215 
2216  if ( ((int)mem_stats.dwAvailPhys == -1) || ((int)mem_stats.dwTotalPhys == -1) )
2217  sprintf(mem_buffer, "Physical Free: *** / *** (>4G)");
2218  else
2219  sprintf(mem_buffer,"Physical Free: %d / %d Meg",mem_stats.dwAvailPhys/1024/1024, mem_stats.dwTotalPhys/1024/1024);
2220 
2221  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2222  sy += line_height;
2223  sprintf(mem_buffer,"Pagefile Free: %d / %d Meg",mem_stats.dwAvailPageFile/1024/1024, mem_stats.dwTotalPageFile/1024/1024);
2224  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2225  sy += line_height;
2226  sprintf(mem_buffer,"Virtual Free: %d / %d Meg",mem_stats.dwAvailVirtual/1024/1024, mem_stats.dwTotalVirtual/1024/1024);
2227  gr_string( sx, sy, mem_buffer, GR_RESIZE_NONE);
2228  }
2229 #endif
2230 
2231 #ifndef NDEBUG
2232  if ( Show_cpu == 1 ) {
2233 
2234  int sx,sy;
2236  sy = gr_screen.center_offset_y + 15;
2237 
2239 
2240  gr_printf_no_resize( sx, sy, NOX("DMA: %s"), transfer_text );
2241  sy += line_height;
2242  gr_printf_no_resize( sx, sy, NOX("POLYP: %d"), modelstats_num_polys );
2243  sy += line_height;
2244  gr_printf_no_resize( sx, sy, NOX("POLYD: %d"), modelstats_num_polys_drawn );
2245  sy += line_height;
2246  gr_printf_no_resize( sx, sy, NOX("VERTS: %d"), modelstats_num_verts );
2247  sy += line_height;
2248 
2249  {
2250 
2251  extern int Num_pairs; // Number of object pairs that were checked.
2252  gr_printf_no_resize( sx, sy, NOX("PAIRS: %d"), Num_pairs );
2253  sy += line_height;
2254 
2255  extern int Num_pairs_checked; // What percent of object pairs were checked.
2256  gr_printf_no_resize( sx, sy, NOX("FVI: %d"), Num_pairs_checked );
2257  sy += line_height;
2258  Num_pairs_checked = 0;
2259 
2260  }
2261 
2262  gr_printf_no_resize( sx, sy, NOX("Snds: %d"), snd_num_playing() );
2263  sy += line_height;
2264 
2265  if ( Timing_total > 0.01f ) {
2266  gr_printf_no_resize( sx, sy, NOX("CLEAR: %.0f%%"), Timing_clear*100.0f/Timing_total );
2267  sy += line_height;
2268  gr_printf_no_resize( sx, sy, NOX("REND2D: %.0f%%"), Timing_render2*100.0f/Timing_total );
2269  sy += line_height;
2270  gr_printf_no_resize( sx, sy, NOX("REND3D: %.0f%%"), Timing_render3*100.0f/Timing_total );
2271  sy += line_height;
2272  gr_printf_no_resize( sx, sy, NOX("FLIP: %.0f%%"), Timing_flip*100.0f/Timing_total );
2273  sy += line_height;
2274  gr_printf_no_resize( sx, sy, NOX("GAME: %.0f%%"), (Timing_total-(Timing_render2+Timing_render3+Timing_flip+Timing_clear))*100.0f/Timing_total );
2275  sy += line_height;
2276  }
2277  }
2278 
2279  if ( Show_mem ) {
2280 
2281  int sx,sy;
2283  sy = gr_screen.center_offset_y + 15;
2284 
2286 
2287  {
2288  extern int TotalRam;
2289  gr_printf_no_resize( sx, sy, NOX("DYN: %d KB\n"), TotalRam/1024 );
2290  sy += line_height;
2291  }
2292 
2293  {
2294  extern int Model_ram;
2295  gr_printf_no_resize( sx, sy, NOX("POF: %d KB\n"), Model_ram/1024 );
2296  sy += line_height;
2297  }
2298 
2299  gr_printf_no_resize( sx, sy, NOX("%s: %d KB\n"), (Cmdline_cache_bitmaps) ? NOX("C-BMP") : NOX("BMP"), bm_texture_ram/1024 );
2300  sy += line_height;
2301 
2302  gr_printf_no_resize( sx, sy, NOX("S-SRAM: %d KB\n"), Snd_sram/1024 ); // mem used to store game sound
2303  sy += line_height;
2304 
2305  {
2306  extern int GL_textures_in;
2307  extern int GL_vertex_data_in;
2308  gr_printf_no_resize( sx, sy, NOX("VRAM: %d KB\n"), (GL_textures_in + GL_vertex_data_in)/1024 );
2309  sy += line_height;
2310  }
2311  }
2312 
2313 
2314  if ( Show_player_pos ) {
2315  int sx, sy;
2316  sx = gr_screen.center_offset_x + 320;
2317  sy = gr_screen.center_offset_y + 100;
2318  gr_printf_no_resize(sx, sy, NOX("Player Pos: (%d,%d,%d)"), fl2i(Player_obj->pos.xyz.x), fl2i(Player_obj->pos.xyz.y), fl2i(Player_obj->pos.xyz.z));
2319  }
2320 
2321 #ifdef _WIN32
2322  if (Cmdline_show_mem_usage) {
2323  void memblockinfo_sort();
2324  void memblockinfo_sort_get_entry(int index, char *filename, int *size);
2325 
2326  char mem_buffer[1000];
2327  char filename[MAX_PATH];
2328  int size;
2329 
2330  memblockinfo_sort();
2331 
2332  int mi = 0;
2333  for( ; mi < 30; mi++) {
2334  memblockinfo_sort_get_entry(mi, filename, &size);
2335 
2336  size /= 1024;
2337 
2338  if (size == 0)
2339  break;
2340 
2341  char *short_name = strrchr(filename, '\\');
2342 
2343  if (short_name == NULL)
2344  short_name = filename;
2345  else
2346  short_name++;
2347 
2348  sprintf(mem_buffer,"%s:\t%d K", short_name, size);
2349  gr_string( gr_screen.center_offset_x + 20, gr_screen.center_offset_y + 100 + (line_height * 12) + (mi*line_height), mem_buffer, GR_RESIZE_NONE);
2350  }
2351 
2352  sprintf(mem_buffer,"Total RAM:\t%d K", TotalRam / 1024);
2353  gr_string( gr_screen.center_offset_x + 20, gr_screen.center_offset_y + 100 + (line_height * 13) + (mi*line_height), mem_buffer, GR_RESIZE_NONE);
2354  }
2355 #endif
2356 
2357  MONITOR_INC(NumPolys, modelstats_num_polys);
2358  MONITOR_INC(NumPolysDrawn, modelstats_num_polys_drawn );
2359  MONITOR_INC(NumVerts, modelstats_num_verts );
2360 
2365 #endif
2366 }
2367 
2369 {
2370  if ( !Cmdline_show_pos )
2371  return;
2372 
2373  if(!cid.isValid())
2374  return;
2375 
2376  camera *cam = cid.getCamera();
2377  vec3d cam_pos = vmd_zero_vector;
2378  matrix cam_orient = vmd_identity_matrix;
2379  cam->get_info(&cam_pos, &cam_orient);
2380 
2381  //Do stuff
2382  int font_height = 2*gr_get_font_height();
2383  angles rot_angles;
2384 
2386 
2387  //Position
2388  gr_printf_no_resize(gr_screen.center_offset_x + 20, gr_screen.center_offset_y + 100 - font_height, "X:%f Y:%f Z:%f", cam_pos.xyz.x, cam_pos.xyz.y, cam_pos.xyz.z);
2389  font_height -= font_height/2;
2390 
2391  //Orientation
2392  vm_extract_angles_matrix(&rot_angles, &cam_orient);
2393  rot_angles.p *= (180/PI);
2394  rot_angles.b *= (180/PI);
2395  rot_angles.h *= (180/PI);
2396  gr_printf_no_resize(gr_screen.center_offset_x + 20, gr_screen.center_offset_y + 100 - font_height, "Xr:%f Yr:%f Zr:%f", rot_angles.p, rot_angles.b, rot_angles.h);
2397 }
2398 
2400 {
2401  float frame_rate=30.0f;
2402  if ( frame_int == -1 ) {
2403  int i;
2404  for (i=0; i<FRAME_FILTER; i++ ) {
2405  frametimes[i] = 0.0f;
2406  }
2407  frametotal = 0.0f;
2408  frame_int = 0;
2409  }
2410  frametotal -= frametimes[frame_int];
2411  frametotal += flRealframetime;
2412  frametimes[frame_int] = flRealframetime;
2413  frame_int = (frame_int + 1 ) % FRAME_FILTER;
2414 
2415  if ( frametotal != 0.0 ) {
2416  if ( Framecount >= FRAME_FILTER ){
2417  frame_rate = FRAME_FILTER / frametotal;
2418  } else {
2419  frame_rate = Framecount / frametotal;
2420  }
2421  }
2422  std_set_standalone_fps(frame_rate);
2423  Framecount++;
2424 }
2425 
2434 {
2435  int diff;
2436 
2437  if (Mission_end_time == -1)
2438  return;
2439 
2440  diff = f2i(Mission_end_time - Missiontime);
2441  // be sure to bash to 0. diff could be negative on frame that we quit mission
2442  if (diff < 0)
2443  diff = 0;
2444 
2446  gr_printf_no_resize( gr_screen.center_offset_x + 5, gr_screen.center_offset_y + 40, XSTR( "Mission time remaining: %d seconds", 179), diff );
2447 }
2448 
2449 //========================================================================================
2450 //=================== NEW DEBUG CONSOLE COMMANDS TO REPLACE OLD DEBUG PAUSE MENU =========
2451 //========================================================================================
2452 
2453 #ifndef NDEBUG
2454 
2455 DCF(ai_pause,"Pauses ai")
2456 {
2457  bool process = true;
2458 
2459  if (dc_optional_string_either("help", "--help")) {
2460  dc_printf( "Usage: ai_paused [bool]\nSets ai_paused to true or false. If nothing passed, then toggles it.\n" );
2461  process = false;
2462  }
2463 
2464  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
2465  dc_printf( "ai_paused is %s\n", (ai_paused?"TRUE":"FALSE") );
2466  process = false;
2467  }
2468 
2469  if (!process) {
2470  return;
2471  }
2472 
2474  ai_paused = !ai_paused;
2475  }
2476 
2477  if (ai_paused) {
2479  }
2480 }
2481 
2482 DCF(single_step,"Enables single step mode.")
2483 {
2484  bool process = true;
2485 
2486  if (dc_optional_string_either("help", "--help")) {
2487  dc_printf( "Usage: game_single_step [bool]\nEnables or disables single-step mode. If nothing passed, then toggles it.\nSingle-step mode will freeze the game, and will advance frame by frame with each key press\n");
2488  process = false;
2489  }
2490 
2491  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
2492  dc_printf( "ai_paused is %s\n", (game_single_step ? "TRUE" : "FALSE") );
2493  process = false;
2494  }
2495 
2496  if (!process) {
2497  return;
2498  }
2499 
2500  if (!dc_maybe_stuff_boolean(&game_single_step)) {
2501  game_single_step = !game_single_step;
2502  }
2503 
2504  last_single_step = 0; // Make so single step waits a frame before stepping
2505 }
2506 
2507 DCF_BOOL(physics_pause, physics_paused)
2508 DCF_BOOL(ai_rendering, Ai_render_debug_flag)
2509 DCF_BOOL(ai_firing, Ai_firing_enabled )
2510 
2511 // Create some simple aliases to these commands...
2512 debug_command dc_s("s","shortcut for single_step",dcf_single_step);
2513 debug_command dc_p("p","shortcut for physics_pause", dcf_physics_pause );
2514 debug_command dc_r("r","shortcut for ai_rendering", dcf_ai_rendering );
2515 debug_command dc_f("f","shortcut for ai_firing", dcf_ai_firing);
2516 debug_command dc_a("a","shortcut for ai_pause", dcf_ai_pause);
2517 #endif
2518 
2519 //========================================================================================
2520 //========================================================================================
2521 
2522 
2524 {
2525  int key;
2526 
2527  key = game_check_key();
2528  if (key > 0){
2530  }
2531 
2532  gr_flip();
2533 }
2534 
2535 
2537 {
2538  Game_skill_level++;
2539  if (Game_skill_level >= NUM_SKILL_LEVELS){
2540  Game_skill_level = 0;
2541  }
2542 }
2543 
2545 
2546 int View_percent = 100;
2547 
2548 
2549 DCF(view, "Sets the percent of the 3d view to render.")
2550 {
2551  bool process = true;
2552  int value;
2553 
2554  if (dc_optional_string_either("help", "--help")) {
2555  dc_printf("Usage: view [n]\nwhere n is percent of view to show (5-100).\n");
2556  process = false;
2557  }
2558 
2559  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
2560  dc_printf("View is set to %d%%\n", View_percent );
2561  process = false;
2562  }
2563 
2564  if (!process) {
2565  return;
2566  }
2567 
2568  dc_stuff_int(&value);
2569  if ( (value >= 5 ) && (value <= 100) ) {
2570  View_percent = value;
2571  } else {
2572  dc_printf("Error: Outside legal range [5 - 100]");
2573  }
2574 }
2575 
2576 
2581 {
2583  Cutscene_delta_time = 1.0f;
2584  Cutscene_bars_progress = 1.0f;
2585 }
2586 
2587 void game_set_view_clip(float frametime)
2588 {
2589  if ((Game_mode & GM_DEAD) || (supernova_active() >= 2))
2590  {
2591  // Set the clip region for the letterbox "dead view"
2592  int yborder = gr_screen.max_h/4;
2593 
2594  if (g3_in_frame() == 0) {
2595  // Ensure that the bars are black
2596  gr_set_color(0,0,0);
2597  gr_set_bitmap(0); // Valathil - Don't ask me why this has to be here but otherwise the black bars don't draw
2598  gr_rect(0, 0, gr_screen.max_w, yborder, GR_RESIZE_NONE);
2599  gr_rect(0, gr_screen.max_h-yborder, gr_screen.max_w, yborder, GR_RESIZE_NONE);
2600  } else {
2601  // Numeric constants encouraged by J "pig farmer" S, who shall remain semi-anonymous.
2602  // J.S. I've changed my ways!! See the new "no constants" code!!!
2603  gr_set_clip(0, yborder, gr_screen.max_w, gr_screen.max_h - yborder*2, GR_RESIZE_NONE );
2604  }
2605  }
2606  else {
2607  // Set the clip region for normal view
2608  if ( View_percent >= 100 ) {
2609  gr_reset_clip();
2610  } else {
2611  int xborder, yborder;
2612 
2613  if ( View_percent < 5 ) {
2614  View_percent = 5;
2615  }
2616 
2617  float fp = i2fl(View_percent)/100.0f;
2618  int fi = fl2i(fl_sqrt(fp)*100.0f);
2619  if ( fi > 100 ) fi=100;
2620 
2621  xborder = ( gr_screen.max_w*(100-fi) )/200;
2622  yborder = ( gr_screen.max_h*(100-fi) )/200;
2623 
2624  gr_set_clip(xborder, yborder, gr_screen.max_w-xborder*2,gr_screen.max_h-yborder*2, GR_RESIZE_NONE );
2625  }
2626  }
2627 }
2628 
2629 
2631 {
2632  int i;
2633  int laser_count = 0, missile_count = 0;
2634 
2635  for (i=0; i<MAX_OBJECTS; i++) {
2636  if (Objects[i].type == OBJ_WEAPON){
2637  if (Weapon_info[Weapons[Objects[i].instance].weapon_info_index].subtype == WP_LASER){
2638  laser_count++;
2639  } else if (Weapon_info[Weapons[Objects[i].instance].weapon_info_index].subtype == WP_MISSILE){
2640  missile_count++;
2641  }
2642  }
2643  }
2644 
2645  nprintf(("Mike", "Frame: %i Lasers: %4i, Missiles: %4i\n", Framecount, laser_count, missile_count));
2646 }
2647 
2648 extern int Tool_enabled;
2649 int tst = 0;
2650 int tst_time = 0;
2651 int tst_big = 0;
2653 int tst_bitmap = -1;
2654 float tst_x, tst_y;
2659 {
2660  // start tst
2661  if(tst == 3){
2662  tst = 0;
2663 
2664  // screen position
2665  vertex v;
2666  g3_rotate_vertex(&v, &tst_pos);
2667  g3_project_vertex(&v);
2668 
2669  // offscreen
2670  if(!(
2671  (v.screen.xyw.x >= 0)
2672  && (v.screen.xyw.x <= gr_screen.max_w)
2673  && (v.screen.xyw.y >= 0)
2674  && (v.screen.xyw.y <= gr_screen.max_h)
2675  ))
2676  {
2677  return;
2678  }
2679 
2680  // big ship? always tst
2681  if(tst_big){
2682  // within 3000 meters
2683  if( vm_vec_dist_quick(&tst_pos, &Eye_position) <= 3000.0f){
2684  tst = 2;
2685  }
2686  } else {
2687  // within 300 meters
2688  if( (vm_vec_dist_quick(&tst_pos, &Eye_position) <= 300.0f) && ((tst_time == 0) || ((time(NULL) - tst_time) >= 10)) ){
2689  tst = 2;
2690  }
2691  }
2692  }
2693 
2694 }
2696 {
2697  int left = 0;
2698 
2699  if(!Tool_enabled){
2700  return;
2701  }
2702 
2703  // setup tst
2704  if(tst == 2){
2705  tst_time = (int) time(NULL);
2706 
2707  // load the tst bitmap
2708  switch((int)frand_range(0.0f, 3.0)){
2709  case 0:
2710  tst_bitmap = bm_load("ig_jim");
2711  left = 1;
2712  mprintf(("TST 0\n"));
2713  break;
2714 
2715  case 1:
2716  tst_bitmap = bm_load("ig_kan");
2717  left = 0;
2718  mprintf(("TST 1\n"));
2719  break;
2720 
2721  case 2:
2722  tst_bitmap = bm_load("ig_jim");
2723  left = 1;
2724  mprintf(("TST 2\n"));
2725  break;
2726 
2727  default:
2728  tst_bitmap = bm_load("ig_kan");
2729  left = 0;
2730  mprintf(("TST 3\n"));
2731  break;
2732  }
2733 
2734  if(tst_bitmap < 0){
2735  tst = 0;
2736  return;
2737  }
2738 
2739  // get the tst bitmap dimensions
2740  int w, h;
2741  bm_get_info(tst_bitmap, &w, &h);
2742 
2743  // tst y
2744  tst_y = frand_range(0.0f, (float)gr_screen.max_h - h);
2745 
2747 
2748  // tst x and direction
2749  tst_mode = 0;
2750  if(left){
2751  tst_x = (float)-w;
2752  tst_offset_total = (float)w;
2753  tst_offset = (float)w;
2754  } else {
2755  tst_x = (float)gr_screen.max_w;
2756  tst_offset_total = (float)-w;
2757  tst_offset = (float)w;
2758  }
2759 
2760  tst = 1;
2761  }
2762 
2763  // run tst
2764  if(tst == 1){
2765  float diff = (tst_offset_total / 0.5f) * flFrametime;
2766 
2767  // move the bitmap
2768  if(tst_mode == 0){
2769  tst_x += diff;
2770 
2771  tst_offset -= fl_abs(diff);
2772  } else if(tst_mode == 2){
2773  tst_x -= diff;
2774 
2775  tst_offset -= fl_abs(diff);
2776  }
2777 
2778  // draw the bitmap
2779  gr_set_bitmap(tst_bitmap);
2780  gr_bitmap((int)tst_x, (int)tst_y, GR_RESIZE_NONE);
2781 
2782  if(tst_mode == 1){
2783  if(timestamp_elapsed_safe(tst_stamp, 1100)){
2784  tst_mode = 2;
2785  }
2786  } else {
2787  // if we passed the switch point
2788  if(tst_offset <= 0.0f){
2789  // switch modes
2790  switch(tst_mode){
2791  case 0:
2792  tst_mode = 1;
2793  tst_stamp = timestamp(1000);
2794  tst_offset = fl_abs(tst_offset_total);
2795  break;
2796 
2797  case 2:
2798  tst = 0;
2799  return;
2800  }
2801  }
2802  }
2803  }
2804 }
2805 void game_tst_mark(object *objp, ship *shipp)
2806 {
2807  ship_info *sip;
2808 
2809  if(!Tool_enabled){
2810  return;
2811  }
2812 
2813  // bogus
2814  if((objp == NULL) || (shipp == NULL) || (shipp->ship_info_index < 0) || (shipp->ship_info_index >= static_cast<int>(Ship_info.size()))){
2815  return;
2816  }
2817  sip = &Ship_info[shipp->ship_info_index];
2818 
2819  // already tst
2820  if(tst){
2821  return;
2822  }
2823 
2824  tst_pos = objp->pos;
2825  if(sip->flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP)){
2826  tst_big = 1;
2827  }
2828  tst = 3;
2829 }
2830 
2831 extern void render_shields();
2832 
2833 void player_repair_frame(float frametime)
2834 {
2835  if(MULTIPLAYER_MASTER){
2836  int idx;
2837  for(idx=0;idx<MAX_PLAYERS;idx++){
2838  net_player *np;
2839 
2840  np = &Net_players[idx];
2841 
2842  if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != NULL) && (Net_player->player_id != Net_players[idx].player_id) && (Net_players[idx].m_player != NULL) && (Net_players[idx].m_player->objnum >= 0) && (Net_players[idx].m_player->objnum < MAX_OBJECTS)){
2843 
2844  // don't rearm/repair if the player is dead or dying/departing
2846  ai_do_repair_frame(&Objects[Net_players[idx].m_player->objnum],&Ai_info[Ships[Objects[Net_players[idx].m_player->objnum].instance].ai_index],frametime);
2847  }
2848  }
2849  }
2850  }
2851 
2852  if ( (Player_obj != NULL) && (Player_obj->type == OBJ_SHIP) && !(Game_mode & GM_STANDALONE_SERVER) && (Player_ship != NULL) && !(Player_ship->flags & SF_DYING) ) {
2854  }
2855 }
2856 
2857 #define NUM_FRAMES_TEST 300
2858 #define NUM_MIXED_SOUNDS 16
2860 {
2861  static int framecount = 0;
2862  static int test_running = 0;
2863  static float test_time = 0.0f;
2864 
2865  static int snds[NUM_MIXED_SOUNDS];
2866  int i;
2867 
2868  if ( test_running ) {
2869  framecount++;
2870  test_time += frame_time;
2871  if ( framecount >= NUM_FRAMES_TEST ) {
2872  test_running = 0;
2873  nprintf(("General", "%d frames took %.3f seconds\n", NUM_FRAMES_TEST, test_time));
2874  for ( i = 0; i < NUM_MIXED_SOUNDS; i++ )
2875  snd_stop(snds[i]);
2876  }
2877  }
2878 
2879  if ( Test_begin == 1 ) {
2880  framecount = 0;
2881  test_running = 1;
2882  test_time = 0.0f;
2883  Test_begin = 0;
2884 
2885  for ( i = 0; i < NUM_MIXED_SOUNDS; i++ )
2886  snds[i] = -1;
2887 
2888  // start looping digital sounds
2889  for ( i = 0; i < NUM_MIXED_SOUNDS; i++ )
2890  snds[i] = snd_play_looping( &Snds[i], 0.0f, -1, -1);
2891  }
2892 
2893 
2894 }
2895 
2896 DCF(dcf_fov, "Change the field of view of the main camera")
2897 {
2898  camera *cam = Main_camera.getCamera();
2899  bool process = true;
2900  float value;
2901 
2902  if (dc_optional_string_either("help", "--help")) {
2903  dc_printf( "Usage: fov [factor]\nFactor is the zoom factor btwn .25 and 1.25\nNo parameter resets it to default.\n" );
2904  process = false;
2905  }
2906 
2907  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
2908  if(cam == NULL) {
2909  dc_printf("Camera unavailable.");
2910  } else {
2911  dc_printf("Zoom factor set to %6.3f (original = 0.5, John = 0.75)\n", cam->get_fov());
2912  }
2913 
2914  process = false;
2915  }
2916 
2917  if ((cam == NULL) || (!process)) {
2918  return;
2919  }
2920 
2921  if (!dc_maybe_stuff_float(&value)) {
2922  // No value passed, use default
2924  } else {
2925  // Value passed, Clamp it to valid values
2926  if (value < 0.25f) {
2927  value = 0.25f;
2928  dc_printf("Zoom factor clamped to 0.25\n");
2929  } else if (value > 1.25f) {
2930  value = 1.25f;
2931  dc_printf("Zoom factor clamped to 1.25\n");
2932  } else {
2933  dc_printf("Zoom factor set to %6.3f\n", value);
2934  }
2935 
2936  cam->set_fov(value);
2937  }
2938 }
2939 
2940 
2941 DCF(framerate_cap, "Sets the framerate cap")
2942 {
2943  bool process = true;
2944 
2945  if (dc_optional_string_either("help", "--help")) {
2946  dc_printf("Usage: framerate_cap [n]\nwhere n is the frames per second to cap framerate at.\n");
2947  dc_printf("If n is 0 or omitted, then the framerate cap is removed\n");
2948  dc_printf("[n] must be from 1 to 120.\n");
2949  process = false;
2950  }
2951 
2952  if (dc_optional_string_either("status", "--status") || dc_optional_string_either("?", "--?")) {
2953  if ( Framerate_cap ) {
2954  dc_printf("Framerate cap is set to %d fps\n", Framerate_cap );
2955  } else {
2956  dc_printf("There is no framerate cap currently active.\n");
2957  }
2958 
2959  process = false;
2960  }
2961 
2962  if (!process) {
2963  return;
2964  }
2965 
2966  if (!dc_maybe_stuff_int(&Framerate_cap)) {
2967  Framerate_cap = 0;
2968  }
2969 
2970  if ((Framerate_cap < 0) || (Framerate_cap > 120)) {
2971  dc_printf( "Illegal value for framerate cap. (Must be from 1-120) \n");
2972  Framerate_cap = 0;
2973  }
2974 
2975  if (Framerate_cap == 0) {
2976  dc_printf("Framerate cap disabled");
2977  } else {
2978  dc_printf("Framerate cap is set to %d fps\n", Framerate_cap );
2979  }
2980 }
2981 
2982 #define MIN_DIST_TO_DEAD_CAMERA 50.0f
2984 
2986 {
2987  object *view_target;
2988 
2989  if ((Viewer_mode & VM_OTHER_SHIP) && (Player_ai->target_objnum != -1))
2990  view_target = &Objects[Player_ai->target_objnum];
2991  else
2992  view_target = Player_obj;
2993 
2994  if (Game_mode & GM_DEAD) {
2995  if (Player_ai->target_objnum != -1)
2996  view_target = &Objects[Player_ai->target_objnum];
2997  }
2998 
2999  if (!(Game_mode & GM_DEAD_DIED) && ((Game_mode & (GM_DEAD_BLEW_UP)) || ((Last_view_target != NULL) && (Last_view_target != view_target)))) {
3000  if (view_target != Player_obj){
3001 
3002  char view_target_name[128] = "";
3003  switch(Objects[Player_ai->target_objnum].type) {
3004  case OBJ_SHIP:
3006  strcpy_s(view_target_name, "targeted ship");
3007  } else {
3009  }
3010  break;
3011  case OBJ_WEAPON:
3013  Viewer_mode &= ~VM_OTHER_SHIP;
3014  break;
3015  case OBJ_JUMP_NODE: {
3016  strcpy_s(view_target_name, XSTR( "jump node", 184));
3017  Viewer_mode &= ~VM_OTHER_SHIP;
3018  break;
3019  }
3020  case OBJ_DEBRIS: {
3021  strcpy_s(view_target_name, "Debris");
3022  Viewer_mode &= ~VM_OTHER_SHIP;
3023  break;
3024  }
3025 
3026  default:
3027  Int3();
3028  break;
3029  }
3030 
3031  end_string_at_first_hash_symbol(view_target_name);
3032  if ( strlen(view_target_name) ) {
3034  HUD_fixed_printf(0.0f, gr_screen.current_color, XSTR( "Viewing %s%s\n", 185), (Viewer_mode & VM_OTHER_SHIP) ? XSTR( "from ", 186) : "", view_target_name);
3035  Show_viewing_from_self = 1;
3036  }
3037  } else {
3038  color col;
3039  gr_init_color(&col, 0, 255, 0);
3041  HUD_fixed_printf(2.0f, col, XSTR( "Viewing from observer\n", 187));
3042  Show_viewing_from_self = 1;
3043  } else {
3044  if (Show_viewing_from_self)
3045  HUD_fixed_printf(2.0f, col, XSTR( "Viewing from self\n", 188));
3046  }
3047  }
3048  }
3049 
3050  Last_view_target = view_target;
3051 }
3052 
3053 
3054 float Game_hit_x = 0.0f;
3055 float Game_hit_y = 0.0f;
3056 
3057 // Reset at the beginning of each frame
3059 {
3060  Game_hit_x = 0.0f;
3061  Game_hit_y = 0.0f;
3062 }
3063 
3064 // Apply a 2d whack to the player
3065 void game_whack_apply( float x, float y )
3066 {
3067  // Do some force feedback
3068  joy_ff_play_dir_effect(x * 80.0f, y * 80.0f);
3069 
3070  // Move the eye
3071  Game_hit_x += x;
3072  Game_hit_y += y;
3073 
3074 // mprintf(( "WHACK = %.1f, %.1f\n", Game_hit_x, Game_hit_y ));
3075 }
3076 
3077 // call to apply a "shudder"
3078 void game_shudder_apply(int time, float intensity)
3079 {
3080  Game_shudder_time = timestamp(time);
3081  Game_shudder_total = time;
3082  Game_shudder_intensity = intensity;
3083 }
3084 
3085 float get_shake(float intensity, int decay_time, int max_decay_time)
3086 {
3087  int r = myrand();
3088 
3089  float shake = intensity * (float)(r-RAND_MAX_2) * RAND_MAX_1f;
3090 
3091  if (decay_time >= 0) {
3092  Assert(max_decay_time > 0);
3093  shake *= (0.5f - fl_abs(0.5f - (float) decay_time / (float) max_decay_time));
3094  }
3095 
3096  return shake;
3097 }
3098 
3099 #define FF_SCALE 10000
3100 extern int Wash_on;
3101 extern float sn_shudder;
3103 {
3104  angles tangles;
3105  tangles.p = 0.0f;
3106  tangles.h = 0.0f;
3107  tangles.b = 0.0f;
3108 
3109  // do shakes that only affect the HUD
3110  if (Viewer_obj == Player_obj) {
3112 
3113  // Make eye shake due to afterburner
3117  }
3118 
3119  // Make eye shake due to engine wash
3120  if (Player_obj->type == OBJ_SHIP && (Ships[Player_obj->instance].wash_intensity > 0) && Wash_on ) {
3121  float wash_intensity = Ships[Player_obj->instance].wash_intensity;
3122 
3123  tangles.p += get_shake(0.07f * wash_intensity, -1, 0);
3124  tangles.h += get_shake(0.07f * wash_intensity, -1, 0);
3125 
3126  // play the force feedback effect
3127  vec3d rand_vec;
3128  vm_vec_rand_vec_quick(&rand_vec);
3129  joy_ff_play_dir_effect(FF_SCALE * wash_intensity * rand_vec.xyz.x, FF_SCALE * wash_intensity * rand_vec.xyz.y);
3130  }
3131 
3132  // Make eye shake due to shuddering
3133  if (Game_shudder_time != -1) {
3134  if (timestamp_elapsed(Game_shudder_time)) {
3135  Game_shudder_time = -1;
3136  } else {
3137  tangles.p += get_shake(Game_shudder_intensity * 0.005f, timestamp_until(Game_shudder_time), Game_shudder_total);
3138  tangles.h += get_shake(Game_shudder_intensity * 0.005f, timestamp_until(Game_shudder_time), Game_shudder_total);
3139  }
3140  }
3141  }
3142  // do shakes that affect external cameras
3143  else {
3144  // Make eye shake due to supernova
3145  if (supernova_camera_cut()) {
3146  float cut_pct = 1.0f - (supernova_time_left() / SUPERNOVA_CUT_TIME);
3147  tangles.p += get_shake(0.07f * cut_pct * sn_shudder, -1, 0);
3148  tangles.h += get_shake(0.07f * cut_pct * sn_shudder, -1, 0);
3149  }
3150  }
3151 
3152  // maybe bail
3153  if (tangles.p == 0.0f && tangles.h == 0.0f && tangles.b == 0.0f)
3154  return;
3155 
3156  matrix tm, tm2;
3157  vm_angles_2_matrix(&tm, &tangles);
3158  Assert(vm_vec_mag(&tm.vec.fvec) > 0.0f);
3159  Assert(vm_vec_mag(&tm.vec.rvec) > 0.0f);
3160  Assert(vm_vec_mag(&tm.vec.uvec) > 0.0f);
3161  vm_matrix_x_matrix(&tm2, eye_orient, &tm);
3162  *eye_orient = tm2;
3163 }
3164 
3165 // Player's velocity just before he blew up. Used to keep camera target moving.
3166 vec3d Dead_player_last_vel = { { { 1.0f, 1.0f, 1.0f } } };
3167 
3168 extern float View_zoom;
3169 inline void render_environment(int i, vec3d *eye_pos, matrix *new_orient, float new_zoom)
3170 {
3172 
3173  gr_clear();
3174 
3175  g3_set_view_matrix( eye_pos, new_orient, new_zoom );
3176 
3179 
3180  if ( Game_subspace_effect ) {
3181  stars_draw(0, 0, 0, 1, 1);
3182  } else {
3183  stars_draw(0, 1, 1, 0, 1);
3184  }
3185 
3188 }
3189 
3191 {
3192  matrix new_orient = IDENTITY_MATRIX;
3193  float old_zoom = View_zoom, new_zoom = 1.0f;//0.925f;
3194  int i = 0;
3195 
3196 
3197  if (Cmdline_nohtl)
3198  return;
3199 
3200  if(!cid.isValid())
3201  return;
3202 
3203  vec3d cam_pos;
3204  matrix cam_orient;
3205  cid.getCamera()->get_info(&cam_pos, &cam_orient);
3206 
3207  // prefer the mission specified envmap over the static-generated envmap, but
3208  // the dynamic envmap should always get preference if in a subspace mission
3209  if ( !Dynamic_environment && strlen(The_mission.envmap_name) ) {
3211 
3212  if (ENVMAP >= 0)
3213  return;
3214  }
3215 
3216  if (gr_screen.envmap_render_target < 0) {
3217  if (ENVMAP >= 0)
3218  return;
3219 
3220  if (strlen(The_mission.envmap_name)) {
3222 
3223  if (ENVMAP < 0)
3225  } else {
3227  }
3228 
3229  return;
3230  }
3231 
3233 
3234 /*
3235  Envmap matrix setup -- left-handed
3236  -------------------------------------------------
3237  Face -- Forward Up Right
3238  px +X +Y -Z
3239  nx -X +Y +Z
3240  py +Y -Z +X
3241  ny -Y +Z +X
3242  pz +Z +Y +X
3243  nz -Z +Y -X
3244 */
3245 
3246  // NOTE: OpenGL needs up/down reversed
3247 
3248  // face 1 (px / right)
3249  memset( &new_orient, 0, sizeof(matrix) );
3250  new_orient.vec.fvec.xyz.x = 1.0f;
3251  new_orient.vec.uvec.xyz.y = 1.0f;
3252  new_orient.vec.rvec.xyz.z = -1.0f;
3253  render_environment(i, &cam_pos, &new_orient, new_zoom);
3254  i++; // bump!
3255 
3256  // face 2 (nx / left)
3257  memset( &new_orient, 0, sizeof(matrix) );
3258  new_orient.vec.fvec.xyz.x = -1.0f;
3259  new_orient.vec.uvec.xyz.y = 1.0f;
3260  new_orient.vec.rvec.xyz.z = 1.0f;
3261  render_environment(i, &cam_pos, &new_orient, new_zoom);
3262  i++; // bump!
3263 
3264  // face 3 (py / up)
3265  memset( &new_orient, 0, sizeof(matrix) );
3266  new_orient.vec.fvec.xyz.y = (gr_screen.mode == GR_OPENGL) ? 1.0f : -1.0f;
3267  new_orient.vec.uvec.xyz.z = (gr_screen.mode == GR_OPENGL) ? -1.0f : 1.0f;
3268  new_orient.vec.rvec.xyz.x = 1.0f;
3269  render_environment(i, &cam_pos, &new_orient, new_zoom);
3270  i++; // bump!
3271 
3272  // face 4 (ny / down)
3273  memset( &new_orient, 0, sizeof(matrix) );
3274  new_orient.vec.fvec.xyz.y = (gr_screen.mode == GR_OPENGL) ? -1.0f : 1.0f;
3275  new_orient.vec.uvec.xyz.z = (gr_screen.mode == GR_OPENGL) ? 1.0f : -1.0f;
3276  new_orient.vec.rvec.xyz.x = 1.0f;
3277  render_environment(i, &cam_pos, &new_orient, new_zoom);
3278  i++; // bump!
3279 
3280  // face 5 (pz / forward)
3281  memset( &new_orient, 0, sizeof(matrix) );
3282  new_orient.vec.fvec.xyz.z = 1.0f;
3283  new_orient.vec.uvec.xyz.y = 1.0f;
3284  new_orient.vec.rvec.xyz.x = 1.0f;
3285  render_environment(i, &cam_pos, &new_orient, new_zoom);
3286  i++; // bump!
3287 
3288  // face 6 (nz / back)
3289  memset( &new_orient, 0, sizeof(matrix) );
3290  new_orient.vec.fvec.xyz.z = -1.0f;
3291  new_orient.vec.uvec.xyz.y = 1.0f;
3292  new_orient.vec.rvec.xyz.x = -1.0f;
3293  render_environment(i, &cam_pos, &new_orient, new_zoom);
3294 
3295 
3296  // we're done, so now reset
3298  g3_set_view_matrix( &cam_pos, &cam_orient, old_zoom );
3299 }
3300 
3301 // setup the render target ready for this mission's environment map
3303 {
3304  const int size = 512;
3305  int gen_flags = (BMP_FLAG_RENDER_TARGET_STATIC | BMP_FLAG_CUBEMAP);
3306 
3307  if ( !Cmdline_env ) {
3308  return;
3309  }
3310 
3311  if (gr_screen.envmap_render_target >= 0) {
3313  Warning(LOCATION, "Unable to release environment map render target.");
3314  }
3315 
3317  }
3318 
3320  Dynamic_environment = true;
3321  gen_flags &= ~BMP_FLAG_RENDER_TARGET_STATIC;
3322  gen_flags |= BMP_FLAG_RENDER_TARGET_DYNAMIC;
3323  }
3324  // bail if we are going to be static, and have an envmap specified already
3325  else if ( strlen(The_mission.envmap_name) ) {
3326  return;
3327  }
3328 
3329  gr_screen.envmap_render_target = bm_make_render_target(size, size, gen_flags);
3330 }
3331 
3333 
3335 {
3336  static camid chase_camera;
3337  if(!chase_camera.isValid())
3338  {
3339  chase_camera = cam_create("Chase camera");
3340  }
3341 
3342  return chase_camera;
3343 }
3344 
3345 extern vec3d Dead_camera_pos;
3346 
3347 // Set eye_pos and eye_orient based on view mode.
3349 {
3350  bool fov_changed;
3351 
3352  if(!Main_camera.isValid())
3353  {
3354  Main_camera = cam_create("Main camera");
3355  }
3356  camera *main_cam = Main_camera.getCamera();
3357  if(main_cam == NULL)
3358  {
3359  Error(LOCATION, "Unable to generate main camera");
3360  return camid();
3361  }
3362 
3363  vec3d eye_pos;
3365  vec3d tmp_dir;
3366 
3367  static int last_Viewer_mode = 0;
3368  static int last_Game_mode = 0;
3369  static int last_Viewer_objnum = -1;
3370  static float last_FOV = Sexp_fov;
3371 
3372  fov_changed = ((last_FOV != Sexp_fov) && (Sexp_fov > 0.0f));
3373 
3374  //First, make sure we take into account 2D Missions.
3375  //These replace the normal player in-cockpit view with a topdown view.
3377  {
3378  if(!Viewer_mode)
3379  {
3381  }
3382  }
3383 
3384  // This code is supposed to detect camera "cuts"... like going between
3385  // different views.
3386 
3387  // determine if we need to regenerate the nebula
3388  if( (!(last_Viewer_mode & VM_EXTERNAL) && (Viewer_mode & VM_EXTERNAL)) || // internal to external
3389  ((last_Viewer_mode & VM_EXTERNAL) && !(Viewer_mode & VM_EXTERNAL)) || // external to internal
3390  (!(last_Viewer_mode & VM_DEAD_VIEW) && (Viewer_mode & VM_DEAD_VIEW)) || // non dead-view to dead-view
3391  ((last_Viewer_mode & VM_DEAD_VIEW) && !(Viewer_mode & VM_DEAD_VIEW)) || // dead-view to non dead-view
3392  (!(last_Viewer_mode & VM_WARP_CHASE) && (Viewer_mode & VM_WARP_CHASE)) || // non warp-chase to warp-chase
3393  ((last_Viewer_mode & VM_WARP_CHASE) && !(Viewer_mode & VM_WARP_CHASE)) || // warp-chase to non warp-chase
3394  (!(last_Viewer_mode & VM_OTHER_SHIP) && (Viewer_mode & VM_OTHER_SHIP)) || // non other-ship to other-ship
3395  ((last_Viewer_mode & VM_OTHER_SHIP) && !(Viewer_mode & VM_OTHER_SHIP)) || // other-ship to non-other ship
3396  (!(last_Viewer_mode & VM_FREECAMERA) && (Viewer_mode & VM_FREECAMERA)) ||
3397  ((last_Viewer_mode & VM_FREECAMERA) && !(Viewer_mode & VM_FREECAMERA)) ||
3398  (!(last_Viewer_mode & VM_TOPDOWN) && (Viewer_mode & VM_TOPDOWN)) ||
3399  ((last_Viewer_mode & VM_TOPDOWN) && !(Viewer_mode & VM_TOPDOWN)) ||
3400  (fov_changed) ||
3401  ((Viewer_mode & VM_OTHER_SHIP) && (last_Viewer_objnum != Player_ai->target_objnum)) // other ship mode, but targets changes
3402  ) {
3403 
3404  // regenerate the nebula
3405  neb2_eye_changed();
3406  }
3407 
3408  if ( (last_Viewer_mode != Viewer_mode)
3409  || (last_Game_mode != Game_mode)
3410  || (fov_changed)
3411  || (Viewer_mode & VM_FREECAMERA)) {
3412  //mprintf(( "************** Camera cut! ************\n" ));
3413  last_Viewer_mode = Viewer_mode;
3414  last_Game_mode = Game_mode;
3415  last_FOV = main_cam->get_fov();
3416 
3417  // Camera moved. Tell stars & debris to not do blurring.
3418  stars_camera_cut();
3419  }
3420 
3421  say_view_target();
3422 
3423  if ( Viewer_mode & VM_PADLOCK_ANY ) {
3425  }
3426 
3427  if (Game_mode & GM_DEAD) {
3428  vec3d vec_to_deader, view_pos;
3429  float dist;
3430 
3432 
3433  if (Player_ai->target_objnum != -1) {
3434  int view_from_player = 1;
3435 
3436  if (Viewer_mode & VM_OTHER_SHIP) {
3437  // View from target.
3439 
3440  last_Viewer_objnum = Player_ai->target_objnum;
3441 
3442  if ( Viewer_obj->type == OBJ_SHIP ) {
3443  ship_get_eye( &eye_pos, &eye_orient, Viewer_obj );
3444  view_from_player = 0;
3445  }
3446  } else {
3447  last_Viewer_objnum = -1;
3448  }
3449 
3450  if(Viewer_obj)
3452  else
3453  Script_system.RemHookVar("Viewer");
3454 
3455  if ( view_from_player ) {
3456  // View target from player ship.
3457  Viewer_obj = NULL;
3458  eye_pos = Player_obj->pos;
3459  vm_vec_normalized_dir(&tmp_dir, &Objects[Player_ai->target_objnum].pos, &eye_pos);
3460  vm_vector_2_matrix(&eye_orient, &tmp_dir, NULL, NULL);
3461  //rtn_cid = ship_get_followtarget_eye( Player_obj );
3462  }
3463  } else {
3464  dist = vm_vec_normalized_dir(&vec_to_deader, &Player_obj->pos, &Dead_camera_pos);
3465 
3466  if (dist < MIN_DIST_TO_DEAD_CAMERA)
3467  dist += flFrametime * 16.0f;
3468 
3469  vm_vec_scale(&vec_to_deader, -dist);
3470  vm_vec_add(&Dead_camera_pos, &Player_obj->pos, &vec_to_deader);
3471 
3472  view_pos = Player_obj->pos;
3473 
3474  if (!(Game_mode & GM_DEAD_BLEW_UP)) {
3475  Viewer_mode &= ~(VM_EXTERNAL | VM_CHASE);
3476  vm_vec_scale_add2(&Dead_camera_pos, &Original_vec_to_deader, 25.0f * flFrametime);
3477  Dead_player_last_vel = Player_obj->phys_info.vel;
3478  //nprintf(("AI", "Player death roll vel = %7.3f %7.3f %7.3f\n", Player_obj->phys_info.vel.x, Player_obj->phys_info.vel.y, Player_obj->phys_info.vel.z));
3479  } else if (Player_ai->target_objnum != -1) {
3480  view_pos = Objects[Player_ai->target_objnum].pos;
3481  } else {
3482  // Make camera follow explosion, but gradually slow down.
3483  vm_vec_scale_add2(&Player_obj->pos, &Dead_player_last_vel, flFrametime);
3484  view_pos = Player_obj->pos;
3485  vm_vec_scale(&Dead_player_last_vel, 0.99f);
3486  vm_vec_scale_add2(&Dead_camera_pos, &Original_vec_to_deader, MIN(25.0f, vm_vec_mag_quick(&Dead_player_last_vel)) * flFrametime);
3487  }
3488 
3489  eye_pos = Dead_camera_pos;
3490 
3491  vm_vec_normalized_dir(&tmp_dir, &Player_obj->pos, &eye_pos);
3492 
3493  vm_vector_2_matrix(&eye_orient, &tmp_dir, NULL, NULL);
3494  Viewer_obj = NULL;
3495  }
3496  }
3497 
3498  // if supernova shockwave
3499  if(supernova_camera_cut()){
3500  // no viewer obj
3501  Viewer_obj = NULL;
3502 
3503  // call it dead view
3505 
3506  // set eye pos and orient
3507  //rtn_cid = supernova_set_view();
3508  supernova_get_eye(&eye_pos, &eye_orient);
3509  } else {
3510  // If already blown up, these other modes can override.
3511  if (!(Game_mode & (GM_DEAD | GM_DEAD_BLEW_UP))) {
3512  Viewer_mode &= ~VM_DEAD_VIEW;
3513 
3514  if(!(Viewer_mode & VM_FREECAMERA))
3516 
3517  if (Viewer_mode & VM_OTHER_SHIP) {
3518  if (Player_ai->target_objnum != -1){
3520  last_Viewer_objnum = Player_ai->target_objnum;
3521  } else {
3522  Viewer_mode &= ~VM_OTHER_SHIP;
3523  last_Viewer_objnum = -1;
3524  }
3525  } else {
3526  last_Viewer_objnum = -1;
3527  }
3528 
3529  if(Viewer_mode & VM_FREECAMERA) {
3530  Viewer_obj = NULL;
3531  return cam_get_current();
3532  } else if (Viewer_mode & VM_EXTERNAL) {
3533  matrix tm, tm2;
3534 
3536  vm_matrix_x_matrix(&tm, &Viewer_obj->orient, &tm2);
3537 
3539 
3540  vm_vec_sub(&tmp_dir, &Viewer_obj->pos, &eye_pos);
3541  vm_vec_normalize(&tmp_dir);
3542  vm_vector_2_matrix(&eye_orient, &tmp_dir, &Viewer_obj->orient.vec.uvec, NULL);
3543  Viewer_obj = NULL;
3544 
3545  // Modify the orientation based on head orientation.
3546  compute_slew_matrix(&eye_orient, &Viewer_slew_angles);
3547 
3548  } else if ( Viewer_mode & VM_CHASE ) {
3549  vec3d move_dir;
3550  vec3d aim_pt;
3551 
3552  if ( Viewer_obj->phys_info.speed < 62.5f )
3553  move_dir = Viewer_obj->phys_info.vel;
3554  else {
3555  move_dir = Viewer_obj->phys_info.vel;
3556  vm_vec_scale(&move_dir, (62.5f/Viewer_obj->phys_info.speed));
3557  }
3558 
3559  vec3d tmp_up;
3560  matrix eyemat;
3561  ship_get_eye(&tmp_up, &eyemat, Viewer_obj, false, false);
3562 
3563  //create a better 3rd person view if this is the player ship
3564  if (Viewer_obj==Player_obj)
3565  {
3566  //get a point 1000m forward of ship
3567  vm_vec_copy_scale(&aim_pt,&Viewer_obj->orient.vec.fvec,1000.0f);
3568  vm_vec_add2(&aim_pt,&Viewer_obj->pos);
3569 
3570  vm_vec_scale_add(&eye_pos, &Viewer_obj->pos, &move_dir, -0.02f * Viewer_obj->radius);
3571  vm_vec_scale_add2(&eye_pos, &eyemat.vec.fvec, -2.125f * Viewer_obj->radius - Viewer_chase_info.distance);
3572  vm_vec_scale_add2(&eye_pos, &eyemat.vec.uvec, 0.625f * Viewer_obj->radius + 0.35f * Viewer_chase_info.distance);
3573  vm_vec_sub(&tmp_dir, &aim_pt, &eye_pos);
3574  vm_vec_normalize(&tmp_dir);
3575  }
3576  else
3577  {
3578  vm_vec_scale_add(&eye_pos, &Viewer_obj->pos, &move_dir, -0.02f * Viewer_obj->radius);
3579  vm_vec_scale_add2(&eye_pos, &eyemat.vec.fvec, -2.5f * Viewer_obj->radius - Viewer_chase_info.distance);
3580  vm_vec_scale_add2(&eye_pos, &eyemat.vec.uvec, 0.75f * Viewer_obj->radius + 0.35f * Viewer_chase_info.distance);
3581  vm_vec_sub(&tmp_dir, &Viewer_obj->pos, &eye_pos);
3582  vm_vec_normalize(&tmp_dir);
3583  }
3584 
3585  // JAS: I added the following code because if you slew up using
3586  // Descent-style physics, tmp_dir and Viewer_obj->orient.vec.uvec are
3587  // equal, which causes a zero-length vector in the vm_vector_2_matrix
3588  // call because the up and the forward vector are the same. I fixed
3589  // it by adding in a fraction of the right vector all the time to the
3590  // up vector.
3591  tmp_up = eyemat.vec.uvec;
3592  vm_vec_scale_add2( &tmp_up, &eyemat.vec.rvec, 0.00001f );
3593 
3594  vm_vector_2_matrix(&eye_orient, &tmp_dir, &tmp_up, NULL);
3595  Viewer_obj = NULL;
3596 
3597  // Modify the orientation based on head orientation.
3598  compute_slew_matrix(&eye_orient, &Viewer_slew_angles);
3599  } else if ( Viewer_mode & VM_WARP_CHASE ) {
3600  Warp_camera.get_info(&eye_pos, NULL);
3601 
3603 
3604  vec3d warp_pos = Player_obj->pos;
3605  shipp->warpout_effect->getWarpPosition(&warp_pos);
3606  vm_vec_sub(&tmp_dir, &warp_pos, &eye_pos);
3607  vm_vec_normalize(&tmp_dir);
3608  vm_vector_2_matrix(&eye_orient, &tmp_dir, &Player_obj->orient.vec.uvec, NULL);
3609  Viewer_obj = NULL;
3610  } else if (Viewer_mode & VM_TOPDOWN) {
3611  angles rot_angles = { PI_2, 0.0f, 0.0f };
3612  bool position_override = false;
3613  if(Viewer_obj->type == OBJ_SHIP) {
3615  if(sip->topdown_offset_def) {
3616  eye_pos.xyz.x = Viewer_obj->pos.xyz.x + sip->topdown_offset.xyz.x;
3617  eye_pos.xyz.y = Viewer_obj->pos.xyz.y + sip->topdown_offset.xyz.y;
3618  eye_pos.xyz.z = Viewer_obj->pos.xyz.z + sip->topdown_offset.xyz.z;
3619  position_override = true;
3620  }
3621  }
3622  if(!position_override) {
3623  eye_pos.xyz.x = Viewer_obj->pos.xyz.x;
3624  eye_pos.xyz.y = Viewer_obj->pos.xyz.y + Viewer_obj->radius * 25.0f;
3625  eye_pos.xyz.z = Viewer_obj->pos.xyz.z;
3626  }
3627  vm_angles_2_matrix(&eye_orient, &rot_angles);
3628  Viewer_obj = NULL;
3629  } else {
3630  // get an eye position based upon the correct type of object
3631  switch(Viewer_obj->type){
3632  case OBJ_SHIP:
3633  // make a call to get the eye point for the player object
3634  ship_get_eye( &eye_pos, &eye_orient, Viewer_obj );
3635  break;
3636  case OBJ_OBSERVER:
3637  // make a call to get the eye point for the player object
3638  observer_get_eye( &eye_pos, &eye_orient, Viewer_obj );
3639  break;
3640  default :
3641  mprintf(("Invalid Value for Viewer_obj->type. Expected values are OBJ_SHIP (1) and OBJ_OBSERVER (12), we encountered %d. Please tell a coder.\n", Viewer_obj->type));
3642  Int3();
3643  }
3644 
3645  #ifdef JOHNS_DEBUG_CODE
3646  john_debug_stuff(&eye_pos, &eye_orient);
3647  #endif
3648  }
3649  }
3650  }
3651 
3652  main_cam->set_position(&eye_pos);
3653  main_cam->set_rotation(&eye_orient);
3654 
3655  // setup neb2 rendering
3657 
3658  return Main_camera;
3659 }
3660 
3661 #ifndef NDEBUG
3662 extern void ai_debug_render_stuff();
3663 #endif
3664 
3666 DCF_BOOL( subspace, Game_subspace_effect )
3667 
3669 
3670 // Does everything needed to render a frame
3671 extern SCP_vector<object*> effect_ships;
3672 extern SCP_vector<object*> transparent_objects;
3674 {
3675 
3676  g3_start_frame(game_zbuffer);
3677 
3678  camera *cam = cid.getCamera();
3679  matrix eye_no_jitter = vmd_identity_matrix;
3680  if(cam != NULL)
3681  {
3682  vec3d eye_pos;
3684 
3685  //Get current camera info
3686  cam->get_info(&eye_pos, &eye_orient);
3687 
3688  //Handle jitter if not cutscene camera
3689  eye_no_jitter = eye_orient;
3690  if( !(Viewer_mode & VM_FREECAMERA) ) {
3691  apply_view_shake(&eye_orient);
3692  cam->set_rotation(&eye_orient);
3693  }
3694 
3695  //Maybe override FOV from SEXP
3696  if(Sexp_fov <= 0.0f)
3697  g3_set_view_matrix(&eye_pos, &eye_orient, cam->get_fov());
3698  else
3699  g3_set_view_matrix(&eye_pos, &eye_orient, Sexp_fov);
3700  }
3701  else
3702  {
3704  }
3705 
3706  // maybe offset the HUD (jitter stuff) and measure the 2D displacement between the player's view and ship vector
3707  int dont_offset = ((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_OBSERVER));
3708  HUD_set_offsets(Viewer_obj, !dont_offset, &eye_no_jitter);
3709 
3710  // for multiplayer clients, call code in Shield.cpp to set up the Shield_hit array. Have to
3711  // do this becaues of the disjointed nature of this system (in terms of setup and execution).
3712  // must be done before ships are rendered
3713  if ( MULTIPLAYER_CLIENT ) {
3715  }
3716 
3717  // this needs to happen after g3_start_frame() and before the primary projection and view matrix is setup
3718  // Note: environment mapping gets disabled when rendering to texture; if you change
3719  // this, make sure that the current render target gets restored right afterwards!
3720  if ( Cmdline_env && !Env_cubemap_drawn && gr_screen.rendering_to_texture == -1 ) {
3721  PROFILE("Environment Mapping", setup_environment_mapping(cid));
3722 
3723  if ( !Dynamic_environment ) {
3724  Env_cubemap_drawn = true;
3725  }
3726  }
3728 
3730 
3731  neb2_render_setup(cid);
3732 
3733 #ifndef DYN_CLIP_DIST
3734  if (!Cmdline_nohtl) {
3737  }
3738 #endif
3739 
3740  if ( Game_subspace_effect ) {
3741  stars_draw(0,0,0,1,0);
3742  } else {
3743  stars_draw(1,1,1,0,0);
3744  }
3745 
3746  PROFILE("Build Shadow Map", shadows_render_all(Proj_fov, &Eye_matrix, &Eye_position));
3747  PROFILE("Render Scene", obj_render_queue_all());
3748 
3749  render_shields();
3750 
3751  PROFILE("Trails", trail_render_all()); // render missilie trails after everything else.
3752  PROFILE("Particles", particle_render_all()); // render particles after everything else.
3753 
3754 #ifdef DYN_CLIP_DIST
3755  if(!Cmdline_nohtl)
3756  {
3761  }
3762 #endif
3763 
3764  beam_render_all(); // render all beam weapons
3765 
3766  // render nebula lightning
3767  nebl_render_all();
3768 
3769  // render local player nebula
3771 
3773 
3774  // render all ships with shader effects on them
3775  SCP_vector<object*>::iterator obji = effect_ships.begin();
3776  for(;obji != effect_ships.end();++obji)
3777  {
3778  obj_render(*obji);
3779  }
3780  effect_ships.clear();
3781 
3783 
3784  Shadow_override = true;
3785  //Draw the viewer 'cause we didn't before.
3786  //This is so we can change the minimum clipping distance without messing everything up.
3787  if ( Viewer_obj
3788  && (Viewer_obj->type == OBJ_SHIP)
3791  {
3794  }
3795 
3796 
3797 #ifndef NDEBUG
3799  extern void snd_spew_debug_info();
3801 #endif
3802 
3803  if(!Cmdline_nohtl)
3804  {
3807  }
3808 
3809  //Draw viewer cockpit
3810  if(Viewer_obj != NULL && Viewer_mode != VM_TOPDOWN && Ship_info[Ships[Viewer_obj->instance].ship_info_index].cockpit_model_num > 0)
3811  {
3814  }
3815 
3816  if (!Cmdline_nohtl) {
3819 
3820  // Do the sunspot
3821  game_sunspot_process(flFrametime);
3822 
3825  }
3826  Shadow_override = false;
3827  //================ END OF 3D RENDERING STUFF ====================
3828 
3829  PROFILE("Post Process", gr_scene_texture_end());
3830 
3831  extern int Multi_display_netinfo;
3832  if(Multi_display_netinfo){
3833  extern void multi_display_netinfo();
3835  }
3836 
3838 
3839 #ifndef NDEBUG
3840  do_timing_test(flFrametime);
3841 
3842  extern int OO_update_index;
3844 
3845  // test
3846  extern void oo_display();
3847  oo_display();
3848 #endif
3849 
3850  g3_end_frame();
3851 }
3852 
3853 //#define JOHNS_DEBUG_CODE 1
3854 
3855 #ifdef JOHNS_DEBUG_CODE
3856 void john_debug_stuff(vec3d *eye_pos, matrix *eye_orient)
3857 {
3858  //if ( keyd_pressed[KEY_LSHIFT] )
3859  {
3860  ship_subsys *tsys = Players[Player_num].targeted_subobject;
3861  if ( tsys ) {
3862  model_subsystem *turret = tsys->system_info;
3863 
3864  if (turret->type == SUBSYSTEM_TURRET ) {
3865  vec3d fvec, uvec;
3866  object * tobj = &Objects[Players[Player_num].targeted_subobject_parent];
3867 
3868  ship_model_start(tobj);
3869 
3870  model_find_world_point(eye_pos, &turret->turret_firing_point[0], turret->model_num, turret->turret_gun_sobj, &tobj->orient, &tobj->pos );
3871  model_find_world_dir(&fvec, &turret->turret_matrix.vec.fvec, turret->model_num, turret->turret_gun_sobj, &tobj->orient, NULL );
3872  model_find_world_dir(&uvec, &turret->turret_matrix.vec.uvec, turret->model_num, turret->turret_gun_sobj, &tobj->orient, NULL );
3873 
3874  vm_vector_2_matrix( eye_orient, &fvec, &uvec, NULL );
3875 
3876  ship_model_stop(tobj);
3877 
3878  Viewer_obj = NULL;
3879  }
3880  }
3881 
3882  }
3883 }
3884 #endif
3885 
3886 extern int Player_dead_state;
3887 
3888 // Flip the page and time how long it took.
3890 {
3891  fix t1, t2,d;
3892  int t;
3893  t1 = timer_get_fixed_seconds();
3894  gr_flip();
3895  t2 = timer_get_fixed_seconds();
3896  d = t2 - t1;
3898  sprintf( transfer_text, NOX("%d MB/s"), (int)fixmuldiv(t,65,d) );
3899 }
3900 
3902 {
3903  //Do camera stuff
3904  //This is for the warpout cam
3905  if ( Player->control_mode != PCM_NORMAL )
3906  Warp_camera.do_frame(flFrametime);
3907 
3908  //Do ingame cutscenes stuff
3909  if(!Time_compression_locked)
3910  {
3911  cam_do_frame(flFrametime);
3912  }
3913  else
3914  {
3915  cam_do_frame(flRealframetime);
3916  }
3917 
3918  // blow ships up in multiplayer dogfight
3919  if( MULTIPLAYER_MASTER && (Net_player != NULL) && (Netgame.type_flags & NG_TYPE_DOGFIGHT) && (f2fl(Missiontime) >= 2.0f) && !dogfight_blown){
3920  // blow up all non-player ships
3921  ship_obj *moveup = GET_FIRST(&Ship_obj_list);
3922  ship *shipp;
3923  ship_info *sip;
3924  while((moveup != END_OF_LIST(&Ship_obj_list)) && (moveup != NULL)){
3925  // bogus
3926  if((moveup->objnum < 0) || (moveup->objnum >= MAX_OBJECTS) || (Objects[moveup->objnum].type != OBJ_SHIP) || (Objects[moveup->objnum].instance < 0) || (Objects[moveup->objnum].instance >= MAX_SHIPS) || (Ships[Objects[moveup->objnum].instance].ship_info_index < 0) || (Ships[Objects[moveup->objnum].instance].ship_info_index >= static_cast<int>(Ship_info.size()))){
3927  moveup = GET_NEXT(moveup);
3928  continue;
3929  }
3930  shipp = &Ships[Objects[moveup->objnum].instance];
3931  sip = &Ship_info[shipp->ship_info_index];
3932 
3933  // only blow up small ships
3934  if((sip->flags & SIF_SMALL_SHIP) && (multi_find_player_by_object(&Objects[moveup->objnum]) < 0) && (shipp->team == Iff_traitor) ){
3935  // function to simply explode a ship where it is currently at
3936  ship_self_destruct( &Objects[moveup->objnum] );
3937  }
3938 
3939  moveup = GET_NEXT(moveup);
3940  }
3941 
3942  dogfight_blown = 1;
3943  }
3944 
3945  // process AWACS stuff - do this first thing
3946  awacs_process();
3947 
3948  //Do autopilot stuff
3949  NavSystem_Do();
3950 
3951  // single player, set Player hits_this_frame to 0
3952  if ( !(Game_mode & GM_MULTIPLAYER) && Player ) {
3953  Player->damage_this_burst -= (flFrametime * MAX_BURST_DAMAGE / (0.001f * BURST_DURATION));
3955  }
3956 
3957  // supernova
3959  if(supernova_active() >= 5){
3960  return;
3961  }
3962 
3963  // fire targeting lasers now so that
3964  // 1 - created this frame
3965  // 2 - collide this frame
3966  // 3 - render this frame
3967  // 4 - ignored and deleted next frame
3968  // the basic idea being that because it con be confusing to deal with them on a multi-frame basis, they are only valid for
3969  // frame
3971 
3972  // do this here so that it works for multiplayer
3973  if ( Viewer_obj ) {
3974  // get viewer direction
3975  int viewer_direction = PHYSICS_VIEWER_REAR;
3976 
3977  if(Viewer_mode == 0){
3978  viewer_direction = PHYSICS_VIEWER_FRONT;
3979  }
3980  if(Viewer_mode & VM_PADLOCK_UP){
3981  viewer_direction = PHYSICS_VIEWER_UP;
3982  }
3983  else if(Viewer_mode & VM_PADLOCK_REAR){
3984  viewer_direction = PHYSICS_VIEWER_REAR;
3985  }
3986  else if(Viewer_mode & VM_PADLOCK_LEFT){
3987  viewer_direction = PHYSICS_VIEWER_LEFT;
3988  }
3989  else if(Viewer_mode & VM_PADLOCK_RIGHT){
3990  viewer_direction = PHYSICS_VIEWER_RIGHT;
3991  }
3992 
3993  physics_set_viewer( &Viewer_obj->phys_info, viewer_direction );
3994  } else {
3996  }
3997 
3998  // evaluate mission departures and arrivals before we process all objects.
3999  if ( !(Game_mode & GM_MULTIPLAYER) || (MULTIPLAYER_MASTER && !multi_endgame_ending()) ) {
4000 
4001  // we don't want to evaluate mission stuff when any ingame joiner in multiplayer is receiving
4002  // ships/wing packets.
4003  if ( !((Game_mode & GM_MULTIPLAYER) && (Netgame.flags & NG_FLAG_INGAME_JOINING_CRITICAL))) {
4005  }
4006 
4007  // if we're an observer, move ourselves seperately from the standard physics
4008  if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_OBSERVER)){
4009  obj_observer_move(flFrametime);
4010  }
4011 
4012  // move all the objects now
4013  PROFILE("Move Objects - Master", obj_move_all(flFrametime));
4014 
4016  }
4017 
4018  // always check training objectives, even in multiplayer missions. we need to do this so that the directives gauge works properly on clients
4020 
4021  // do all interpolation now
4023  // client side processing of warping in effect stages
4024  multi_do_client_warp(flFrametime);
4025 
4026  // client side movement of an observer
4028  obj_observer_move(flFrametime);
4029  }
4030 
4031  // move all objects - does interpolation now as well
4032  PROFILE("Move Objects - Client", obj_move_all(flFrametime));
4033 
4034 
4035  }
4036 
4037  // only process the message queue when the player is "in" the game
4038  if ( !Pre_player_entry ){
4039  message_queue_process(); // process any messages send to the player
4040  }
4041 
4042  message_maybe_distort(); // maybe distort incoming message if comms damaged
4043  player_repair_frame(flFrametime); // AI objects get repaired in ai_process, called from move code...deal with player.
4044  player_process_pending_praise(); // maybe send off a delayed praise message to the player
4045  player_maybe_play_all_alone_msg(); // maybe tell the player he is all alone
4046 
4047  if(!(Game_mode & GM_STANDALONE_SERVER)){
4048  // process some stuff every frame (before frame is rendered)
4050 
4051  hud_update_frame(flFrametime); // update hud systems
4052 
4053  if (!physics_paused) {
4054  // Move particle system
4055  PROFILE("Move Particles", particle_move_all(flFrametime));
4056 
4057  // Move missile trails
4058  PROFILE("Move Trails", trail_move_all(flFrametime));
4059 
4060  // Flash the gun flashes
4061  shipfx_flash_do_frame(flFrametime);
4062 
4063  shockwave_move_all(flFrametime); // update all the shockwaves
4064  }
4065 
4066  // subspace missile strikes
4067  ssm_process();
4068 
4069  obj_snd_do_frame(); // update the object-linked persistant sounds
4070 
4073 
4074 // AL: debug code used for testing ambient subspace sound (ie when enabling subspace through debug console)
4075 #ifndef NDEBUG
4076  if ( Game_subspace_effect ) {
4078  }
4079 #endif
4080  }
4081 
4083 }
4084 
4085 // Maybe render and process the dead-popup
4086 void game_maybe_do_dead_popup(float frametime)
4087 {
4088  if ( popupdead_is_active() ) {
4089  int leave_popup=1;
4090  int choice = popupdead_do_frame(frametime);
4091 
4092  if ( Game_mode & GM_NORMAL ) {
4093  switch(choice) {
4094  case 0:
4096  break;
4097 
4098  case 1:
4100  break;
4101 
4102  case 2:
4104  break;
4105 
4106  // this should only happen during a red alert mission
4107  case 3:
4109  {
4110  // choose the previous mission
4112  }
4113  else
4114  {
4115  // bogus?
4116  Int3();
4117  }
4118 
4120  break;
4121 
4122  default:
4123  leave_popup=0;
4124  break;
4125  }
4126  } else {
4127  switch( choice ) {
4128 
4131  break;
4132 
4133  case POPUPDEAD_DO_RESPAWN:
4136  break;
4137 
4138  case POPUPDEAD_DO_OBSERVER:
4141  break;
4142 
4143  default:
4144  leave_popup = 0;
4145  break;
4146  }
4147  }
4148 
4149  if ( leave_popup ) {
4150  popupdead_close();
4151  }
4152  }
4153 }
4154 
4155 // returns true if player is actually in a game_play stats
4157 {
4158  int state;
4159 
4160  state = gameseq_get_state();
4161  if ( (state != GS_STATE_GAME_PLAY) && (state != GS_STATE_DEATH_DIED) && (state != GS_STATE_DEATH_BLEW_UP) )
4162  return 0;
4163  else
4164  return 1;
4165 }
4166 
4168 {
4169  gr_reset_clip();
4170 
4171  if(cid.isValid()) {
4172  g3_start_frame(0); // 0 = turn zbuffering off
4173  g3_set_view( cid.getCamera() );
4174 
4175  hud_render_preprocess(flFrametime);
4176 
4177  g3_end_frame();
4178  }
4179 
4180  // main HUD rendering function
4181  hud_render_all();
4182 
4183  // Diminish the palette effect
4184  game_flash_diminish(flFrametime);
4185 }
4186 
4187 //100% blackness
4189 {
4190  Fade_type = FI_NONE;
4191  gr_create_shader(&Viewer_shader, 0, 0, 0, 0);
4192 }
4193 
4194 void game_shade_frame(float frametime)
4195 {
4196  // only do frame shade if we are actually in a game play state
4197  if ( !game_actually_playing() ) {
4198  return;
4199  }
4200 
4201  if (Fade_type != FI_NONE) {
4205 
4206  if( timestamp() >= Fade_start_timestamp ) {
4207  int startAlpha = 0;
4208  int endAlpha = 0;
4209 
4210  if (Fade_type == FI_FADEOUT) {
4211  endAlpha = 255;
4212  } else if (Fade_type == FI_FADEIN) {
4213  startAlpha = 255;
4214  }
4215 
4216  int alpha = 0;
4217 
4218  if( timestamp() < Fade_end_timestamp ) {
4219  int duration = (Fade_end_timestamp - Fade_start_timestamp);
4220  int elapsed = (timestamp() - Fade_start_timestamp);
4221 
4222  alpha = fl2i( (float)startAlpha + (((float)endAlpha - (float)startAlpha) / (float)duration) * (float)elapsed );
4223  } else {
4224  //Fade finished
4225  Fade_type = FI_NONE;
4227  Fade_end_timestamp = 0;
4228 
4229  alpha = endAlpha;
4230  }
4231 
4232  Viewer_shader.c = (ubyte)alpha;
4233  }
4234  }
4235 
4237 }
4238 
4239 const static int CUTSCENE_BAR_DIVISOR = 8;
4240 void bars_do_frame(float frametime)
4241 {
4243  {
4244  //Determine how far along we are
4245  Assert(Cutscene_delta_time > 0.0f);
4246 
4248  if(Cutscene_bars_progress >= 1.0f)
4249  {
4250  //Reset this stuff
4251  Cutscene_delta_time = 1.0f;
4252  Cutscene_bars_progress = 1.0f;
4253  }
4254 
4255  //Figure out where the bars should be
4256  int yborder;
4258  yborder = fl2i(Cutscene_bars_progress*(gr_screen.max_h/CUTSCENE_BAR_DIVISOR));
4259  else
4260  yborder = gr_screen.max_h/CUTSCENE_BAR_DIVISOR - fl2i(Cutscene_bars_progress*(gr_screen.max_h/CUTSCENE_BAR_DIVISOR));
4261 
4262  if (g3_in_frame() == 0) {
4263  //Set rectangles
4264  gr_set_color(0,0,0);
4265  gr_set_bitmap(0); // Valathil - Don't ask me why this has to be here but otherwise the black bars don't draw
4266  gr_rect(0, 0, gr_screen.max_w, yborder, GR_RESIZE_NONE);
4267  gr_rect(0, gr_screen.max_h-yborder, gr_screen.max_w, yborder, GR_RESIZE_NONE);
4268  } else {
4269  //Set clipping
4270  gr_reset_clip();
4271  gr_set_clip(0, yborder, gr_screen.max_w, gr_screen.max_h - yborder*2, GR_RESIZE_NONE );
4272  }
4273  }
4274  else if(Cutscene_bar_flags & CUB_CUTSCENE)
4275  {
4276  int yborder = gr_screen.max_h/CUTSCENE_BAR_DIVISOR;
4277 
4278  if (g3_in_frame() == 0) {
4279  gr_set_color(0,0,0);
4280  gr_set_bitmap(0); // Valathil - Don't ask me why this has to be here but otherwise the black bars don't draw
4281  gr_rect(0, 0, gr_screen.max_w, yborder, GR_RESIZE_NONE);
4282  gr_rect(0, gr_screen.max_h-yborder, gr_screen.max_w, yborder, GR_RESIZE_NONE);
4283  } else {
4284  gr_reset_clip();
4285  gr_set_clip(0, yborder, gr_screen.max_w, gr_screen.max_h - (yborder*2), GR_RESIZE_NONE );
4286  }
4287  }
4288 }
4289 
4291  if(!Time_compression_locked) {
4292  // Player is dead
4293  game_set_view_clip(flFrametime);
4294 
4295  // Cutscene bars
4296  bars_do_frame(flRealframetime);
4297  } else {
4298  // Player is dead
4299  game_set_view_clip(flRealframetime);
4300 
4301  // Cutscene bars
4302  bars_do_frame(flRealframetime);
4303  }
4304 }
4305 
4306 //WMC - This does stuff like fading in and out and subtitles. Special FX?
4307 //Basically stuff you need rendered after everything else (including HUD)
4309 {
4310  float frametime = flFrametime;
4311  if(Time_compression_locked)
4312  {
4313  frametime = flRealframetime;
4314  }
4315 
4316  subtitles_do_frame(frametime);
4317  game_shade_frame(frametime);
4318  subtitles_do_frame_post_shaded(frametime);
4319 }
4320 
4321 #ifndef NDEBUG
4322 #define DEBUG_GET_TIME(x) { x = timer_get_fixed_seconds(); }
4323 #else
4324 #define DEBUG_GET_TIME(x)
4325 #endif
4326 
4327 void game_frame(bool paused)
4328 {
4329 #ifndef NDEBUG
4330  fix total_time1, total_time2;
4331  fix render2_time1=0, render2_time2=0;
4332  fix render3_time1=0, render3_time2=0;
4333  fix flip_time1=0, flip_time2=0;
4334  fix clear_time1=0, clear_time2=0;
4335 #endif
4336  int actually_playing;
4337 
4338 #ifndef NDEBUG
4339  if (Framerate_delay) {
4340  int start_time = timer_get_milliseconds();
4341  while (timer_get_milliseconds() < start_time + Framerate_delay)
4342  ;
4343  }
4344 #endif
4345  // start timing frame
4346  profile_begin("Main Frame");
4347 
4348  DEBUG_GET_TIME( total_time1 )
4349 
4350  if(paused)
4351  {
4352  // Reset the lights here or they just keep on increasing
4353  light_reset();
4354  }
4355  else
4356  {
4357  // var to hold which state we are in
4358  actually_playing = game_actually_playing();
4359 
4360  if ((!(Game_mode & GM_MULTIPLAYER)) || ((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_OBSERVER))) {
4361  if (!(Game_mode & GM_STANDALONE_SERVER)){
4362  Assert( OBJ_INDEX(Player_obj) >= 0 );
4363  }
4364  }
4365 
4367  Pre_player_entry = 0;
4368  } else {
4369  ; //nprintf(("AI", "Framecount = %i, time = %7.3f\n", Framecount, f2fl(Missiontime)));
4370  }
4371 
4372  // Note: These are done even before the player enters, else buffers can overflow.
4373  if (! (Game_mode & GM_STANDALONE_SERVER)){
4374  radar_frame_init();
4375  }
4376 
4378 
4379  if ( !Pre_player_entry && actually_playing ) {
4380  if (! (Game_mode & GM_STANDALONE_SERVER) ) {
4381 
4382  if( (!popup_running_state()) && (!popupdead_is_active()) ){
4384  read_player_controls( Player_obj, flFrametime);
4385  }
4386 
4387  // if we're not the master, we may have to send the server-critical ship status button_info bits
4390  }
4391  }
4392  }
4393 
4394  // Reset the whack stuff
4395  game_whack_reset();
4396 
4397  // These two lines must be outside of Pre_player_entry code,
4398  // otherwise too many lights are added.
4399  light_reset();
4400 
4401  if ((Game_mode & GM_MULTIPLAYER) && (Netgame.game_state == NETGAME_STATE_SERVER_TRANSFER)){
4402  return;
4403  }
4404 
4405  PROFILE("Simulation", game_simulation_frame());
4406 
4407  // if not actually in a game play state, then return. This condition could only be true in
4408  // a multiplayer game.
4409  if (!actually_playing ) {
4410  Assert( Game_mode & GM_MULTIPLAYER );
4411  return;
4412  }
4413 
4414  }
4415 
4416  if (!Pre_player_entry) {
4417  if (! (Game_mode & GM_STANDALONE_SERVER)) {
4418  DEBUG_GET_TIME( clear_time1 )
4419  // clear the screen to black
4420  gr_reset_clip();
4422  gr_clear();
4423  }
4424 
4425  if(Player_obj)
4427  else
4428  Script_system.RemHookVar("Player");
4429 
4430  DEBUG_GET_TIME( clear_time2 )
4431  DEBUG_GET_TIME( render3_time1 )
4432 
4434 
4435  PROFILE("Render", game_render_frame( cid ));
4436 
4437  //Cutscene bars
4438  clip_frame_view();
4439 
4440  // save the eye position and orientation
4441  if ( Game_mode & GM_MULTIPLAYER ) {
4443  }
4444 
4445  Scripting_didnt_draw_hud = 1;
4448  Scripting_didnt_draw_hud = 0;
4449  Script_system.RemHookVar("Self");
4450 
4451  if(Scripting_didnt_draw_hud) {
4452  game_render_hud(cid);
4453  }
4454  HUD_reset_clip();
4455 
4456  if( (Game_detail_flags & DETAIL_FLAG_HUD) && (!(Game_mode & GM_MULTIPLAYER) || ((Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_OBSERVER))) ) {
4457  anim_render_all(0, flFrametime);
4458  }
4459 
4462  {
4465  }
4466  Script_system.RemHookVar("Self");
4467 
4468  // check to see if we should display the death died popup
4469  if(Game_mode & GM_DEAD_BLEW_UP){
4470  if(Game_mode & GM_MULTIPLAYER){
4471  // catch the situation where we're supposed to be warping out on this transition
4475  } else if((Player_died_popup_wait != -1) && (timestamp_elapsed(Player_died_popup_wait))){
4476  Player_died_popup_wait = -1;
4477  popupdead_start();
4478  }
4479  } else {
4480  if((Player_died_popup_wait != -1) && (timestamp_elapsed(Player_died_popup_wait))){
4481  Player_died_popup_wait = -1;
4482  popupdead_start();
4483  }
4484  }
4485  }
4486 
4487  // Goober5000 - check if we should red-alert
4488  // (this is approximately where the red_alert_check_status() function tree began in the pre-HUD-overhaul code)
4490 
4491  DEBUG_GET_TIME( render3_time2 )
4492  DEBUG_GET_TIME( render2_time1 )
4493 
4494  gr_reset_clip();
4497  game_show_eye_pos(cid);
4498 
4500 
4501  gr_reset_clip();
4503 
4504  game_tst_frame();
4505 
4506  DEBUG_GET_TIME( render2_time2 )
4507 
4508  // maybe render and process the dead popup
4509  game_maybe_do_dead_popup(flFrametime);
4510 
4511  // If a regular popup is active, don't flip (popup code flips)
4512  if( !popup_running_state() ){
4513  DEBUG_GET_TIME( flip_time1 )
4514  PROFILE("Page Flip", game_flip_page_and_time_it());
4515  DEBUG_GET_TIME( flip_time2 )
4516  }
4517 
4518  } else {
4520  }
4521  }
4522 
4524  asteroid_frame();
4525 
4526  // process lightning (nebula only)
4527  nebl_process();
4528 
4529  profile_end("Main Frame");
4531 
4532  DEBUG_GET_TIME( total_time2 )
4533 
4534 #ifndef NDEBUG
4535  // Got some timing numbers
4536  Timing_total = f2fl( total_time2 - total_time1 ) * 1000.0f;
4537  Timing_clear = f2fl( clear_time2 - clear_time1 ) * 1000.0f;
4538  Timing_render2 = f2fl( render2_time2- render2_time1 ) * 1000.0f;
4539  Timing_render3 = f2fl( render3_time2- render3_time1 ) * 1000.0f;
4540  Timing_flip = f2fl( flip_time2 - flip_time1 ) * 1000.0f;
4541 #endif
4542 
4543 }
4544 
4545 #define MAX_FRAMETIME (F1_0/4) // Frametime gets saturated at this. Changed by MK on 11/1/97.
4546  // Some bug was causing Frametime to always get saturated at 2.0 seconds after the player
4547  // died. This resulted in screwed up death sequences.
4548 
4549 fix Last_time = 0; // The absolute time of game at end of last frame (beginning of this frame)
4550 fix Last_delta_time = 0; // While game is paused, this keeps track of how much elapsed in the frame before paused.
4551 static int timer_paused=0;
4552 #if defined(TIMER_TEST) && !defined(NDEBUG)
4553 static int stop_count,start_count;
4554 static int time_stopped,time_started;
4555 #endif
4557 
4559 {
4561  return ;
4562  }
4563 
4564  // Last_time = timer_get_fixed_seconds();
4565  game_start_time();
4566  timestamp_reset();
4567  game_stop_time();
4568 }
4569 
4571 {
4572  if (timer_paused==0) {
4573  fix time;
4574  time = timer_get_fixed_seconds();
4575  // Save how much time progressed so far in the frame so we can
4576  // use it when we unpause.
4577  Last_delta_time = time - Last_time;
4578 
4579  //mprintf(("Last_time in game_stop_time = %7.3f\n", f2fl(Last_delta_time)));
4580  if (Last_delta_time < 0) {
4581  #if defined(TIMER_TEST) && !defined(NDEBUG)
4582  Int3(); //get Matt!!!!
4583  #endif
4584  Last_delta_time = 0;
4585  }
4586  #if defined(TIMER_TEST) && !defined(NDEBUG)
4587  time_stopped = time;
4588  #endif
4589 
4590  // Stop the timer_tick stuff...
4591  // Normally, you should never access 'timestamp_ticker', consider this a low-level routine
4592  saved_timestamp_ticker = timestamp_ticker;
4593  }
4594  timer_paused++;
4595 
4596  #if defined(TIMER_TEST) && !defined(NDEBUG)
4597  stop_count++;
4598  #endif
4599 }
4600 
4602 {
4603  timer_paused--;
4604  Assert(timer_paused >= 0);
4605  if (timer_paused==0) {
4606  fix time;
4607  time = timer_get_fixed_seconds();
4608  #if defined(TIMER_TEST) && !defined(NDEBUG)
4609  if (Last_time < 0)
4610  Int3(); //get Matt!!!!
4611  }
4612  #endif
4613  // Take current time, and set it backwards to account for time
4614  // that the frame already executed, so that timer_get_fixed_seconds() - Last_time
4615  // will be correct when it goes to calculate the frametime next
4616  // frame.
4617  Last_time = time - Last_delta_time;
4618  #if defined(TIMER_TEST) && !defined(NDEBUG)
4619  time_started = time;
4620  #endif
4621 
4622  // Restore the timer_tick stuff...
4623  // Normally, you should never access 'timestamp_ticker', consider this a low-level routine
4624  Assert( saved_timestamp_ticker > -1 ); // Called out of order, get JAS
4626  saved_timestamp_ticker = -1;
4627  }
4628 
4629  #if defined(TIMER_TEST) && !defined(NDEBUG)
4630  start_count++;
4631  #endif
4632 }
4633 
4634 void lock_time_compression(bool is_locked)
4635 {
4636  Time_compression_locked = is_locked;
4637 }
4638 
4639 void change_time_compression(float multiplier)
4640 {
4641  fix modified = fl2f( f2fl(Game_time_compression) * multiplier );
4642 
4643  Desired_time_compression = Game_time_compression = modified;
4644  Time_compression_change_rate = 0;
4645 }
4646 
4647 void set_time_compression(float multiplier, float change_time)
4648 {
4649  if(change_time <= 0.0f)
4650  {
4651  Game_time_compression = Desired_time_compression = fl2f(multiplier);
4652  Time_compression_change_rate = 0;
4653  return;
4654  }
4655 
4656  Desired_time_compression = fl2f(multiplier);
4657  Time_compression_change_rate = fl2f( f2fl(Desired_time_compression - Game_time_compression) / change_time );
4658 }
4659 
4660 void game_set_frametime(int state)
4661 {
4662  fix thistime;
4663  float frame_cap_diff;
4664 
4665  thistime = timer_get_fixed_seconds();
4666 
4667  if ( Last_time == 0 )
4668  Frametime = F1_0 / 30;
4669  else
4670  Frametime = thistime - Last_time;
4671 
4672 // Frametime = F1_0 / 30;
4673 
4674 #ifndef NDEBUG
4675  fix debug_frametime = Frametime; // Just used to display frametime.
4676 #endif
4677 
4678  // If player hasn't entered mission yet, make frame take 1/4 second.
4679  if ((Pre_player_entry) && (state == GS_STATE_GAME_PLAY))
4680  Frametime = F1_0/4;
4681 #ifndef NDEBUG
4682  else if ((Debug_dump_frames) && (state == GS_STATE_GAME_PLAY)) { // note link to above if!!!!!
4683 
4684  fix frame_speed = F1_0 / Debug_dump_frames;
4685 
4686  if (Frametime > frame_speed ){
4687  nprintf(("warning","slow frame: %x\n",(int)Frametime));
4688  } else {
4689  do {
4690  thistime = timer_get_fixed_seconds();
4691  Frametime = thistime - Last_time;
4692  } while (Frametime < frame_speed );
4693  }
4694  Frametime = frame_speed;
4695  }
4696 #endif
4697 
4698  Assertion( Framerate_cap > 0, "Framerate cap %d is too low. Needs to be a positive, non-zero number", Framerate_cap );
4699 
4700  // Cap the framerate so it doesn't get too high.
4701  if (!Cmdline_NoFPSCap)
4702  {
4703  fix cap;
4704 
4705  cap = F1_0/Framerate_cap;
4706  if (Frametime < cap) {
4707  thistime = cap - Frametime;
4708 // mprintf(("Sleeping for %6.3f seconds.\n", f2fl(thistime)));
4709  Sleep( DWORD(f2fl(thistime) * 1000.0f) );
4710  Frametime = cap;
4711  thistime = timer_get_fixed_seconds();
4712  }
4713  }
4714 
4715  if((Game_mode & GM_STANDALONE_SERVER) &&
4716  (f2fl(Frametime) < ((float)1.0/(float)Multi_options_g.std_framecap))){
4717 
4718  frame_cap_diff = ((float)1.0/(float)Multi_options_g.std_framecap) - f2fl(Frametime);
4719  Sleep((DWORD)(frame_cap_diff*1000));
4720 
4721  thistime += fl2f((frame_cap_diff));
4722 
4723  Frametime = thistime - Last_time;
4724  }
4725 
4726  // If framerate is too low, cap it.
4727  if (Frametime > MAX_FRAMETIME) {
4728 #ifndef NDEBUG
4729  mprintf(("Frame %2i too long!!: frametime = %.3f (%.3f)\n", Framecount, f2fl(Frametime), f2fl(debug_frametime)));
4730 #endif
4732  }
4733 
4734  flRealframetime = f2fl(Frametime);
4735 
4736  //Handle changes in time compression
4737  if(Game_time_compression != Desired_time_compression)
4738  {
4739  bool ascending = Desired_time_compression > Game_time_compression;
4740  if(Time_compression_change_rate)
4741  Game_time_compression += fixmul(Time_compression_change_rate, Frametime);
4742  if((ascending && Game_time_compression > Desired_time_compression)
4743  || (!ascending && Game_time_compression < Desired_time_compression))
4744  Game_time_compression = Desired_time_compression;
4745  }
4746 
4747  Frametime = fixmul(Frametime, Game_time_compression);
4748 
4749  if (Frametime <= 0)
4750  {
4751  // If the Frametime is zero or below due to Game_time_compression, set
4752  // the Frametime to 1 (1/65536 of a second).
4753  Frametime = 1;
4754  }
4755 
4756  Last_time = thistime;
4757  //mprintf(("Frame %i, Last_time = %7.3f\n", Framecount, f2fl(Last_time)));
4759 
4760  flFrametime = f2fl(Frametime);
4761 
4762  auto frametime_ms = f2i(fixmul(Frametime, F1_0 * TIMESTAMP_FREQUENCY));
4763  timestamp_inc(frametime_ms);
4764 
4765  // wrap overall frametime if needed
4766  if ( FrametimeOverall > (INT_MAX - F1_0) )
4767  FrametimeOverall = 0;
4768 
4769  FrametimeOverall += Frametime;
4770 
4771 /* if ((Framecount > 0) && (Framecount < 10)) {
4772  mprintf(("Frame %2i: frametime = %.3f (%.3f)\n", Framecount, f2fl(Frametime), f2fl(debug_frametime)));
4773  }
4774 */
4775 }
4776 
4778 {
4779  return FrametimeOverall;
4780 }
4781 
4782 // This is called from game_do_frame(), and from navmap_do_frame()
4784 {
4785  // TODO JAS: Put in if and move this into game_set_frametime,
4786  // fix navmap to call game_stop/start_time
4787  //if ( !timer_paused )
4789 }
4790 
4792 {
4795 
4796 // if (Player_ship->flags & SF_DYING)
4797 // flFrametime /= 15.0;
4798 
4801  }
4802 
4803  if ( game_single_step && (last_single_step == game_single_step) ) {
4804  os_set_title( NOX("SINGLE STEP MODE (Pause exits, any other key steps)") );
4805  while( key_checkch() == 0 )
4806  os_sleep(10);
4807  os_set_title( XSTR( "FreeSpace", 171) );
4809  }
4810 
4811  last_single_step = game_single_step;
4812 
4814  Keep_mouse_centered = 1; // force mouse to center of our window (so we don't hit movement limits)
4815  }
4816  game_frame();
4817 
4818  Keep_mouse_centered = 0;
4819  monitor_update(); // Update monitor variables
4820 }
4821 
4823 {
4825  game_do_frame();
4826  }
4827 }
4828 
4830 
4831 // Flush all input devices
4833 {
4834  key_flush();
4835  mouse_flush();
4836  joy_flush();
4837  snazzy_flush();
4838 
4839  Joymouse_button_status = 0;
4840 
4841  //mprintf(("Game flush!\n" ));
4842 }
4843 
4844 // function for multiplayer only which calls game_do_state_common() when running the
4845 // debug console
4847 {
4849 
4851 }
4852 
4853 // Call this whenever in a loop, or when you need to check for a keystroke.
4855 {
4856  int k;
4857 
4858  k = game_poll();
4859 
4860  // convert keypad enter to normal enter
4861  if ((k & KEY_MASK) == KEY_PADENTER)
4862  k = (k & ~KEY_MASK) | KEY_ENTER;
4863 
4864  return k;
4865 }
4866 
4867 // same as game_check_key(), except this is used while actually in the game. Since there
4868 // generally are differences between game control keys and general UI keys, makes sense to
4869 // have seperate functions for each case. If you are not checking a game control while in a
4870 // mission, you should probably be using game_check_key() instead.
4872 {
4873  int k, state;
4874 
4876  {
4877  if (!os_foreground()) {
4878  game_stop_time();
4879  os_sleep(1);
4880  game_start_time();
4881 
4882  // If we're in a single player game, pause it.
4883  if (!(Game_mode & GM_MULTIPLAYER)){
4886  }
4887  }
4888  }
4889  }
4890 
4891  k = key_inkey();
4892 
4893  // Move the mouse cursor with the joystick.
4894  if (os_foreground() && (!Mouse_hidden) && (Use_joy_mouse) ) {
4895  // Move the mouse cursor with the joystick
4896  int mx, my, dx, dy;
4897  int jx, jy, jz, jr;
4898 
4899  joy_get_pos( &jx, &jy, &jz, &jr );
4900 
4901  dx = fl2i(f2fl(jx)*flFrametime*500.0f);
4902  dy = fl2i(f2fl(jy)*flFrametime*500.0f);
4903 
4904  if ( dx || dy ) {
4905  mouse_get_real_pos( &mx, &my );
4906  mouse_set_pos( mx+dx, my+dy );
4907  }
4908 
4909  int j, m;
4910  j = joy_down(0);
4912 
4913  if ( j != Joymouse_button_status ) {
4914  //mprintf(( "Joy went from %d to %d, mouse is %d\n", Joymouse_button_status, j, m ));
4915  Joymouse_button_status = j;
4916  if ( j && (!m) ) {
4918  } else if ( (!j) && (m) ) {
4920  }
4921  }
4922  }
4923 
4924  // if we should be ignoring keys because of some multiplayer situations
4926  return 0;
4927  }
4928 
4929  state = gameseq_get_state();
4930 
4931  // If a popup is running, don't process all the Fn keys
4932  if( popup_active()) {
4933  if (state != GS_STATE_DEATH_BLEW_UP) {
4934  return k;
4935  }
4936  }
4937 
4938 // if ( k ) nprintf(( "General", "Key = %x\n", k ));
4939 
4940  switch (k) {
4941  case KEY_DEBUGGED + KEY_BACKSP:
4942  if(!(Game_mode & GM_MULTIPLAYER))
4943  {
4945  k = 0;
4946  }
4947  break;
4948 
4949  case KEY_F1:
4951  k = 0;
4952  break;
4953 
4954  case KEY_F2:
4955 // if (state != GS_STATE_INITIAL_PLAYER_SELECT) {
4956 
4957  // don't allow f2 while warping out in multiplayer
4958  if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_WARPING_OUT)){
4959  break;
4960  }
4961 
4962  switch (state) {
4964  case GS_STATE_OPTIONS_MENU:
4965  case GS_STATE_HUD_CONFIG:
4967  case GS_STATE_DEATH_DIED:
4968 // case GS_STATE_DEATH_BLEW_UP: // DEATH_BLEW_UP might be okay but do not comment out DEATH_DIED as otherwise no clean up is performed on the dead ship
4969  case GS_STATE_VIEW_MEDALS:
4970  break;
4971 
4972  default:
4974  k = 0;
4975  break;
4976  }
4977 
4978  break;
4979 
4980  // hotkey selection screen -- only valid from briefing and beyond.
4981  case KEY_F3:
4982  if ( (state == GS_STATE_TEAM_SELECT) || (state == GS_STATE_BRIEFING) || (state == GS_STATE_SHIP_SELECT) || (state == GS_STATE_WEAPON_SELECT) || (state == GS_STATE_GAME_PLAY) || (state == GS_STATE_GAME_PAUSED) ) {
4984  k = 0;
4985  }
4986  break;
4987 
4988  case KEY_DEBUGGED + KEY_F3:
4990  break;
4991 
4992  case KEY_F4:
4993  if(Game_mode & GM_MULTIPLAYER){
4994  if((state == GS_STATE_GAME_PLAY) || (state == GS_STATE_MULTI_PAUSED)){
4996  k = 0;
4997  }
4998  } else {
4999  if ((state == GS_STATE_GAME_PLAY) || (state == GS_STATE_DEATH_DIED) || (state == GS_STATE_DEATH_BLEW_UP) || (state == GS_STATE_GAME_PAUSED) ) {
5001  k = 0;
5002  }
5003  }
5004  break;
5005 
5006  case KEY_ESC | KEY_SHIFTED:
5007  // make sure to quit properly out of multiplayer
5008  if(Game_mode & GM_MULTIPLAYER){
5010  }
5011 
5013  k = 0;
5014 
5015  break;
5016 
5017  case KEY_DEBUGGED + KEY_P:
5018  break;
5019 
5020  case KEY_PRINT_SCRN:
5021  {
5022  static int counter = os_config_read_uint(NULL, "ScreenshotNum", 0);
5023  char tmp_name[MAX_FILENAME_LEN];
5024 
5025  game_stop_time();
5026 
5027  // we could probably go with .3 here for 1,000 shots but people really need to clean out
5028  // their directories better than that so it's 100 for now.
5029  sprintf( tmp_name, NOX("screen%.4i"), counter );
5030  counter++;
5031 
5032  // we've got two character precision so we can only have 100 shots at a time, reset if needed
5033  //Now we have four digit precision :) -WMC
5034  if (counter > 9999)
5035  {
5036  //This should pop up a dialogue or something ingame.
5037  Warning(LOCATION, "Screenshot count has reached max of 9999. Resetting to 0.");
5038  counter = 0;
5039  }
5040 
5041  mprintf(( "Dumping screen to '%s'\n", tmp_name ));
5042  gr_print_screen(tmp_name);
5043 
5044  game_start_time();
5045  os_config_write_uint(NULL, "ScreenshotNum", counter);
5046  }
5047 
5048  k = 0;
5049  break;
5050 
5051  case KEY_SHIFTED | KEY_ENTER: {
5052 
5053 #if !defined(NDEBUG)
5054 
5055  if ( Game_mode & GM_NORMAL ){
5056  game_stop_time();
5057  }
5058 
5059  // if we're in multiplayer mode, do some special networking
5060  if(Game_mode & GM_MULTIPLAYER){
5062  } else {
5063  debug_console();
5064  }
5065 
5066  game_flush();
5067 
5068  if ( Game_mode & GM_NORMAL )
5069  game_start_time();
5070 
5071 #endif
5072 
5073  break;
5074  }
5075  }
5076 
5077  return k;
5078 }
5079 
5080 void os_close()
5081 {
5083 }
5084 
5085 // All code to process events. This is the only place
5086 // that you should change the state of the game.
5087 void game_process_event( int current_state, int event )
5088 {
5089  mprintf(("Got event %s (%d) in state %s (%d)\n", GS_event_text[event], event, GS_state_text[current_state], current_state));
5090 
5091  switch (event) {
5094  break;
5095 
5096  case GS_EVENT_MAIN_MENU:
5098  break;
5099 
5100  case GS_EVENT_OPTIONS_MENU:
5102  break;
5103 
5106  break;
5107 
5108  case GS_EVENT_TECH_MENU:
5110  break;
5111  case GS_EVENT_LAB:
5113  break;
5116  break;
5117 
5118  case GS_EVENT_START_GAME:
5119  Select_default_ship = 0;
5121  break;
5122 
5124  Select_default_ship = 1;
5126  break;
5127 
5128  case GS_EVENT_CMD_BRIEF:
5130  break;
5131 
5132  case GS_EVENT_RED_ALERT:
5134  break;
5135 
5138  break;
5139 
5140  case GS_EVENT_DEBRIEF:
5141  // did we end the campaign in the main freespace 2 single player campaign?
5142  // (specifically, did we successfully jump out when the supernova was in progress
5143  // and the campaign was ending?)
5144  if (Campaign_ending_via_supernova && (Game_mode & GM_CAMPAIGN_MODE)/* && !stricmp(Campaign.filename, "freespace2")*/) {
5146  } else {
5148  }
5149  break;
5150 
5153  break;
5154 
5157  break;
5158 
5159  case GS_EVENT_ENTER_GAME:
5160  if (Game_mode & GM_MULTIPLAYER) {
5161  // if we're respawning, make sure we change the view mode so that the hud shows up
5162  if (current_state == GS_STATE_DEATH_BLEW_UP) {
5163  Viewer_mode = 0;
5164  }
5165 
5167  } else {
5169  }
5170 
5171  // clear multiplayer button info
5173  memset(&Multi_ship_status_bi, 0, sizeof(button_info));
5174 
5175  // Make hv.Player available in "On Gameplay Start" hook -zookeeper
5176  if(Player_obj)
5178 
5180 
5181  if (Player_obj)
5182  Script_system.RemHookVar("Player");
5183 
5184  Start_time = f2fl(timer_get_approx_seconds());
5185  //Framecount = 0;
5186  mprintf(("Entering game at time = %7.3f\n", Start_time));
5187  break;
5188 
5189  case GS_EVENT_END_GAME:
5190  if ( (current_state == GS_STATE_GAME_PLAY) || (current_state == GS_STATE_DEATH_DIED) ||
5191  (current_state == GS_STATE_DEATH_BLEW_UP) || (current_state == GS_STATE_DEBRIEF) || (current_state == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)) {
5193 
5194  } else
5195  Int3();
5196 
5197  break;
5198 
5199  case GS_EVENT_QUIT_GAME:
5200  main_hall_stop_music(true);
5203  break;
5204 
5207  break;
5208 
5209  case GS_EVENT_PAUSE_GAME:
5211  break;
5212 
5215  break;
5216 
5219  break;
5220 
5223  break;
5224 
5227  break;
5228 
5231  break;
5232 
5233  case GS_EVENT_HUD_CONFIG:
5235  break;
5236 
5239  break;
5240 
5241  case GS_EVENT_DEATH_DIED:
5243  break;
5244 
5246  if ( current_state == GS_STATE_DEATH_DIED ) {
5249  } else {
5250  mprintf(( "Ignoring GS_EVENT_DEATH_BLEW_UP because we're in state %d\n", current_state ));
5251  }
5252  break;
5253 
5254  case GS_EVENT_NEW_CAMPAIGN:
5255  if (!mission_load_up_campaign()){
5257  }
5258  break;
5259 
5261  if (!mission_load_up_campaign()){
5263  }
5264  break;
5265 
5268  break;
5269 
5270  case GS_EVENT_CREDITS:
5272  break;
5273 
5274  case GS_EVENT_VIEW_MEDALS:
5276  break;
5277 
5278  case GS_EVENT_SHOW_GOALS:
5279  gameseq_push_state( GS_STATE_SHOW_GOALS ); // use push_state() since we might get to this screen through a variety of states
5280  break;
5281 
5283  gameseq_push_state( GS_STATE_HOTKEY_SCREEN ); // use push_state() since we might get to this screen through a variety of states
5284  break;
5285 
5286  // multiplayer stuff follow these comments
5287  case GS_EVENT_PXO:
5289  break;
5290 
5291  case GS_EVENT_PXO_HELP:
5293  break;
5294 
5297  break;
5298 
5301  break;
5302 
5305  break;
5306 
5309  break;
5310 
5313  break;
5314 
5317  break;
5318 
5319  case GS_EVENT_MULTI_PAUSE:
5321  break;
5322 
5325  break;
5326 
5327  case GS_EVENT_EVENT_DEBUG:
5329  break;
5330 
5331  // Start a warpout where player automatically goes 70 no matter what
5332  // and can't cancel out of it.
5334  Warpout_forced = 1; // If non-zero, bash the player to speed and go through effect
5335 
5336  // Same code as in GS_EVENT_PLAYER_WARPOUT_START only ignores current mode
5339  Warpout_sound = snd_play(&Snds[SND_PLAYER_WARP_OUT]);
5340  Warpout_time = 0.0f; // Start timer!
5341  break;
5342 
5344  if ( Player->control_mode != PCM_NORMAL ) {
5345  mprintf(( "Player isn't in normal mode; cannot warp out.\n" ));
5346  } else {
5349  Warpout_sound = snd_play(&Snds[SND_PLAYER_WARP_OUT]);
5350  Warpout_time = 0.0f; // Start timer!
5351  Warpout_forced = 0; // If non-zero, bash the player to speed and go through effect
5352  }
5353  break;
5354 
5356  if ( Player->control_mode != PCM_NORMAL ) {
5357  if ( !Warpout_forced ) { // cannot cancel forced warpout
5361  mprintf(( "Player put back to normal mode.\n" ));
5362  if ( Warpout_sound > -1 ) {
5363  snd_stop( Warpout_sound );
5364  Warpout_sound = -1;
5365  }
5366  }
5367  }
5368  break;
5369 
5370  case GS_EVENT_PLAYER_WARPOUT_DONE_STAGE1: // player ship got up to speed
5373  mprintf(( "Player put back to normal mode, because of invalid sequence in stage1.\n" ));
5374  } else {
5375  mprintf(( "Hit target speed. Starting warp effect and moving to stage 2!\n" ));
5378 
5383  }
5384  }
5385  break;
5386 
5387  case GS_EVENT_PLAYER_WARPOUT_DONE_STAGE2: // player ship got into the warp effect
5390  mprintf(( "Player put back to normal mode, because of invalid sequence in stage2.\n" ));
5391  } else {
5392  mprintf(( "Hit warp effect. Moving to stage 3!\n" ));
5394  }
5395  break;
5396 
5397  case GS_EVENT_PLAYER_WARPOUT_DONE: // player ship got through the warp effect
5398  mprintf(( "Player warped out. Going to debriefing!\n" ));
5401  Warpout_sound = -1;
5402 
5404  break;
5405 
5408  break;
5409 
5412  break;
5413 
5414  case GS_EVENT_GAME_INIT:
5415  // see if the command line option has been set to use the last pilot, and act acoordingly
5416  if( player_select_get_last_pilot() ) {
5417  // always enter the main menu -- do the automatic network startup stuff elsewhere
5418  // so that we still have valid checks for networking modes, etc.
5420  } else {
5422  }
5423  break;
5424 
5427  break;
5428 
5431  break;
5432 
5435  break;
5436 
5439  break;
5440 
5441  case GS_EVENT_TEAM_SELECT:
5443  break;
5444 
5445  case GS_EVENT_END_CAMPAIGN:
5447  break;
5448 
5449  case GS_EVENT_LOOP_BRIEF:
5451  break;
5452 
5455  break;
5456 
5457  case GS_EVENT_SCRIPTING:
5459  break;
5460 
5461  default:
5462  Int3();
5463  break;
5464  }
5465 }
5466 
5467 // Called when a state is being left.
5468 // The current state is still at old_state, but as soon as
5469 // this function leaves, then the current state will become
5470 // new state. You should never try to change the state
5471 // in here... if you think you need to, you probably really
5472 // need to post an event, not change the state.
5473 void game_leave_state( int old_state, int new_state )
5474 {
5475  int end_mission = 1;
5476 
5477  switch (new_state) {
5478  case GS_STATE_GAME_PAUSED:
5479  case GS_STATE_DEBUG_PAUSED:
5480  case GS_STATE_OPTIONS_MENU:
5483  case GS_STATE_DEATH_DIED:
5484  case GS_STATE_SHOW_GOALS:
5485  case GS_STATE_HOTKEY_SCREEN:
5486  case GS_STATE_MULTI_PAUSED:
5488  case GS_STATE_EVENT_DEBUG:
5490  case GS_STATE_LAB:
5491  end_mission = 0; // these events shouldn't end a mission
5492  break;
5493  }
5494 
5495  //WMC - Scripting override
5496  /*
5497  if(script_hook_valid(&GS_state_hooks[old_state]) && Script_system.IsOverride(GS_state_hooks[old_state])) {
5498  return;
5499  }
5500  */
5501 
5504  return;
5505  }
5506 
5507  //WMC - Clear scripting bitmaps
5509 
5510  switch (old_state) {
5511  case GS_STATE_BRIEFING:
5513  if ( (new_state != GS_STATE_OPTIONS_MENU) && (new_state != GS_STATE_WEAPON_SELECT)
5514  && (new_state != GS_STATE_SHIP_SELECT) && (new_state != GS_STATE_HOTKEY_SCREEN)
5515  && (new_state != GS_STATE_TEAM_SELECT) && (new_state != GS_STATE_MULTI_MISSION_SYNC)){
5517  if ( new_state == GS_STATE_MAIN_MENU ) {
5519  }
5520  }
5521 
5522  // COMMAND LINE OPTION
5524  cfwrite_string(NOX("-------------------------------------------\n"),Multi_chat_stream);
5526  }
5527  break;
5528 
5529  case GS_STATE_DEBRIEF:
5530  if ( (new_state != GS_STATE_VIEW_MEDALS) && (new_state != GS_STATE_OPTIONS_MENU) ) {
5531  debrief_close();
5532  fsspeech_stop();
5533  }
5534  break;
5535 
5538  break;
5539 
5542  break;
5543 
5545  sim_room_close();
5546  break;
5547 
5550  break;
5551 
5552  case GS_STATE_CMD_BRIEF:
5553  if (new_state == GS_STATE_OPTIONS_MENU) {
5554  cmd_brief_hold();
5555 
5556  } else {
5557  cmd_brief_close();
5559  if (new_state == GS_STATE_MAIN_MENU) {
5561  }
5562  }
5563  break;
5564 
5565  case GS_STATE_RED_ALERT:
5566  red_alert_close();
5568  if (new_state == GS_STATE_MAIN_MENU) {
5570  }
5571  break;
5572 
5573  case GS_STATE_SHIP_SELECT:
5574  if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_WEAPON_SELECT &&
5575  new_state != GS_STATE_HOTKEY_SCREEN &&
5576  new_state != GS_STATE_BRIEFING && new_state != GS_STATE_TEAM_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5578  if ( new_state == GS_STATE_MAIN_MENU ) {
5580  }
5581  }
5582  break;
5583 
5585  if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_SHIP_SELECT &&
5586  new_state != GS_STATE_HOTKEY_SCREEN &&
5587  new_state != GS_STATE_BRIEFING && new_state != GS_STATE_TEAM_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5589  if ( new_state == GS_STATE_MAIN_MENU ) {
5591  }
5592  }
5593  break;
5594 
5595  case GS_STATE_TEAM_SELECT:
5596  if ( new_state != GS_STATE_OPTIONS_MENU && new_state != GS_STATE_SHIP_SELECT &&
5597  new_state != GS_STATE_HOTKEY_SCREEN &&
5598  new_state != GS_STATE_BRIEFING && new_state != GS_STATE_WEAPON_SELECT && (new_state != GS_STATE_MULTI_MISSION_SYNC)) {
5600  if ( new_state == GS_STATE_MAIN_MENU ) {
5602  }
5603  }
5604  break;
5605 
5606  case GS_STATE_MAIN_MENU:
5607  main_hall_close();
5608  break;
5609 
5610  case GS_STATE_OPTIONS_MENU:
5611  //game_start_time();
5612  if(new_state == GS_STATE_MULTI_JOIN_GAME){
5614  }
5616  break;
5617 
5619  if(new_state != GS_STATE_VIEW_MEDALS){
5620  barracks_close();
5621  }
5622  break;
5623 
5626  break;
5627 
5630  break;
5631 
5632  case GS_STATE_GAME_PLAY:
5633  if ( !(Game_mode & GM_STANDALONE_SERVER) ) {
5636  }
5637 
5640 
5641  // stop game time under certain conditions
5642  if ( end_mission || (Game_mode & GM_NORMAL) || ((Game_mode & GM_MULTIPLAYER) && (new_state == GS_STATE_MULTI_PAUSED)) ){
5643  game_stop_time();
5644  }
5645 
5646  if (end_mission) {
5647  // when in multiplayer and going back to the main menu, send a leave game packet
5648  // right away (before calling stop mission). stop_mission was taking to long to
5649  // close mission down and I want people to get notified ASAP.
5650  if ( (Game_mode & GM_MULTIPLAYER) && (new_state == GS_STATE_MAIN_MENU) ){
5652  }
5653  snd_aav_init();
5654 
5656 
5657  if (Cmdline_benchmark_mode) {
5659  }
5660  }
5661  break;
5662 
5663  case GS_STATE_TECH_MENU:
5664  techroom_close();
5665  break;
5666 
5668  Training_num_lines = 0;
5669  // fall through to GS_STATE_GAME_PAUSED
5670 
5671  case GS_STATE_GAME_PAUSED:
5672  game_start_time();
5673  if ( end_mission ) {
5674  pause_close();
5675  }
5676  break;
5677 
5678  case GS_STATE_DEBUG_PAUSED:
5679  #ifndef NDEBUG
5680  game_start_time();
5682  #endif
5683  break;
5684 
5685  case GS_STATE_HUD_CONFIG:
5686  hud_config_close();
5687  break;
5688 
5689  case GS_STATE_PXO:
5690  if (new_state != GS_STATE_PXO_HELP) {
5691  multi_pxo_close();
5692  }
5693  break;
5694 
5695  case GS_STATE_PXO_HELP:
5697  break;
5698 
5699  // join/start a game
5701  if(new_state != GS_STATE_OPTIONS_MENU){
5703  }
5704  break;
5705 
5708  // if this is just the host going into the options screen, don't do anything
5709  if((new_state == GS_STATE_MULTI_HOST_OPTIONS) || (new_state == GS_STATE_OPTIONS_MENU)){
5710  break;
5711  }
5712 
5713  // close down the proper state
5714  if(old_state == GS_STATE_MULTI_HOST_SETUP){
5716  } else {
5718  }
5719 
5720  // COMMAND LINE OPTION
5722  if( (new_state != GS_STATE_TEAM_SELECT) && (Multi_chat_stream!=NULL) ) {
5723  cfwrite_string(NOX("-------------------------------------------\n"),Multi_chat_stream);
5725  }
5726  }
5727  break;
5728 
5731  break;
5732 
5733  case GS_STATE_DEATH_DIED:
5734  Game_mode &= ~GM_DEAD_DIED;
5735 
5736  if ( !(Game_mode & GM_MULTIPLAYER) ) {
5737  if ( end_mission && (new_state == GS_STATE_DEBRIEF) ) {
5739  }
5740  } else {
5741  // early end while respawning or blowing up in a multiplayer game
5742  if ( (new_state == GS_STATE_DEBRIEF) || (new_state == GS_STATE_MULTI_DOGFIGHT_DEBRIEF) ) {
5743  game_stop_time();
5745  }
5746  }
5747  break;
5748 
5751 
5752  // for single player, we might reload mission, etc. For multiplayer, look at my new state
5753  // to determine if I should do anything.
5754  if ( !(Game_mode & GM_MULTIPLAYER) ) {
5755  if ( end_mission ){
5757  }
5758  } else {
5759  // if we are not respawing as an observer or as a player, our new state will not
5760  // be gameplay state.
5761  if ( (new_state != GS_STATE_GAME_PLAY) && (new_state != GS_STATE_MULTI_PAUSED) ) {
5762  game_stop_time(); // hasn't been called yet!!
5764  }
5765  }
5766  break;
5767 
5768 
5769  case GS_STATE_CREDITS:
5770  credits_close();
5772  break;
5773 
5774  case GS_STATE_VIEW_MEDALS:
5775  medal_main_close();
5776  break;
5777 
5778  case GS_STATE_SHOW_GOALS:
5780  break;
5781 
5783  if ( new_state != GS_STATE_OPTIONS_MENU ) {
5785  }
5786  break;
5787 
5790 
5791  // if we're moving into the options menu we don't need to do anything else
5792  if(new_state == GS_STATE_OPTIONS_MENU){
5793  break;
5794  }
5795 
5796  Assert( Game_mode & GM_MULTIPLAYER );
5797  multi_sync_close();
5798  if ( new_state == GS_STATE_GAME_PLAY ){
5799  // palette_restore_palette();
5800 
5801  // change a couple of flags to indicate our state!!!
5804 
5805  // set the game mode
5807  }
5808 
5809  main_hall_stop_music(true);
5811  break;
5812 
5815  break;
5816 
5819  break;
5820 
5823  if(new_state == GS_STATE_MULTI_STD_WAIT){
5825  }
5826  break;
5827 
5830  break;
5831 
5832  case GS_STATE_MULTI_PAUSED:
5833  multi_pause_close(end_mission);
5834  break;
5835 
5838  break;
5839 
5842  break;
5843 
5846  break;
5847 
5850  break;
5851 
5854  break;
5855 
5856  case GS_STATE_LOOP_BRIEF:
5857  loop_brief_close();
5858  break;
5859 
5863  if (new_state == GS_STATE_MAIN_MENU) {
5865  }
5866  break;
5867 
5868  case GS_STATE_LAB:
5869  lab_close();
5870  break;
5871 
5872  case GS_STATE_SCRIPTING:
5874  break;
5875  }
5876 
5877  //WMC - Now run scripting stuff
5879 }
5880 
5881 // variable used for automatic netgame starting/joining
5883 
5884 // Called when a state is being entered.
5885 // The current state is set to the state we're entering at
5886 // this point, and old_state is set to the state we're coming
5887 // from. You should never try to change the state
5888 // in here... if you think you need to, you probably really
5889 // need to post an event, not change the state.
5890 
5891 void game_enter_state( int old_state, int new_state )
5892 {
5893  //WMC - Scripting override
5894  /*
5895  if(script_hook_valid(&GS_state_hooks[new_state]) && Script_system.IsOverride(GS_state_hooks[new_state])) {
5896  return;
5897  }
5898  */
5901  return;
5902  }
5903 
5904  switch (new_state) {
5905  case GS_STATE_MAIN_MENU:
5906  // in multiplayer mode, be sure that we are not doing networking anymore.
5907  if ( Game_mode & GM_MULTIPLAYER ) {
5908  Assert( Net_player != NULL );
5910  }
5911 
5912  // remove any multiplayer flags from the game mode
5913  Game_mode &= ~(GM_MULTIPLAYER);
5914 
5915  // set the game_mode based on the type of player
5916  Assert( Player != NULL );
5917 
5920  } else {
5921  Game_mode = GM_NORMAL;
5922  }
5923 
5924  // determine which ship this guy is currently based on
5926 
5927  // if we're coming from the end of a campaign, we want to load the first mainhall of the campaign
5928  // otherwise load the mainhall for the mission the player's up to
5929  if (Campaign.next_mission == -1) {
5931  } else {
5933  }
5934 
5935  //if ( (Cmdline_start_netgame || (Cmdline_connect_addr != NULL)) && !Main_hall_netgame_started ) {
5936  // Main_hall_netgame_started = 1;
5937  // main_hall_do_multi_ready();
5938  //} DTP commented out to keep original source
5939  if ( (Cmdline_start_netgame || (Cmdline_connect_addr != NULL)) && (!Main_hall_netgame_started) /*&& (Game_mode == GM_MULTIPLAYER)*/) { // DTP added "&& (game_mode == GM_multiplayer)" so that ppl don't get thrown into Multiplayer with a Singleplayer Pilot.
5940  Main_hall_netgame_started = 1;
5942  }
5943 
5944  if(Cmdline_start_mission) {
5945  strcpy_s(Game_current_mission_filename, Cmdline_start_mission);
5946  mprintf(( "Straight to mission '%s'\n", Game_current_mission_filename ));
5948  // This stops the mission from loading again when you go back to the hall
5949  Cmdline_start_mission = NULL;
5950  }
5951  break;
5952 
5953  case GS_STATE_START_GAME:
5954  main_hall_stop_music(true);
5956 
5957  if (Game_mode & GM_NORMAL) {
5958  // this should put us into a new state on failure!
5959  if (!game_start_mission())
5960  break;
5961  }
5962 
5963  // maybe play a movie before the mission
5965 
5966  // determine where to go next
5967  if (mission_has_fiction()) {
5969  } else if (mission_has_cmd_brief()) {
5971  } else if (red_alert_mission()) {
5973  } else {
5975  }
5976  break;
5977 
5981  break;
5982 
5983  case GS_STATE_CMD_BRIEF: {
5984  if (old_state == GS_STATE_OPTIONS_MENU) {
5985  cmd_brief_unhold();
5986  } else {
5988  int team_num = 0; // team number used as index for which cmd brief to use.
5989  cmd_brief_init(team_num);
5990  }
5991  break;
5992  }
5993 
5994  case GS_STATE_RED_ALERT:
5996  red_alert_init();
5997  break;
5998 
5999  case GS_STATE_BRIEFING:
6001  brief_init();
6002  break;
6003 
6004  case GS_STATE_DEBRIEF:
6006  mission_goal_fail_incomplete(); // fail all incomplete goals before entering debriefing
6007  if ( (old_state != GS_STATE_VIEW_MEDALS) && (old_state != GS_STATE_OPTIONS_MENU) ){
6009  debrief_init();
6010  }
6011  break;
6012 
6015  break;
6016 
6019  break;
6020 
6022  sim_room_init();
6023  break;
6024 
6027  break;
6028 
6029  case GS_STATE_SHIP_SELECT:
6030  ship_select_init();
6031  break;
6032 
6035  break;
6036 
6037  case GS_STATE_TEAM_SELECT:
6038  multi_ts_init();
6039  break;
6040 
6041  case GS_STATE_GAME_PAUSED:
6042  game_stop_time();
6043  pause_init();
6044  break;
6045 
6046  case GS_STATE_DEBUG_PAUSED:
6047  // game_stop_time();
6048  // os_set_title("FreeSpace - PAUSED");
6049  // break;
6050  //
6052  #ifndef NDEBUG
6053  game_stop_time();
6054  pause_debug_init();
6055  #endif
6056  break;
6057 
6058  case GS_STATE_OPTIONS_MENU:
6059  //game_stop_time();
6061  break;
6062 
6063  case GS_STATE_GAME_PLAY:
6064 
6065  // maybe play a cutscene
6066  if((old_state == GS_STATE_BRIEFING) || (old_state == GS_STATE_SHIP_SELECT) ||
6067  (old_state == GS_STATE_WEAPON_SELECT) || (old_state == GS_STATE_RED_ALERT) ) {
6069  }
6070  // reset time compression to default level so it's right at the beginning of a mission - taylor
6071  if(old_state != GS_STATE_GAME_PAUSED)
6072  {
6073  //Game_time_compression = F1_0;
6074  }
6075 
6076  /* game could be comming from a restart (rather than first start)
6077  so make sure that we zero the hud gauge overrides (Sexp_hud_*)
6078  \sa sexp_hud_display_gauge*/
6079  if ( (old_state == GS_STATE_GAME_PLAY)
6080  || (old_state == GS_STATE_BRIEFING)
6081  || (old_state == GS_STATE_DEBRIEF)
6082  || (old_state == GS_STATE_SHIP_SELECT)
6083  || (old_state == GS_STATE_WEAPON_SELECT)
6084  || (old_state == GS_STATE_RED_ALERT) )
6085  {
6087  }
6088 
6089  // Goober5000 - people may not have realized that pausing causes this state to be re-entered
6090  if ((old_state != GS_STATE_GAME_PAUSED) && (old_state != GS_STATE_MULTI_PAUSED) && (old_state != GS_STATE_MAIN_MENU))
6091  {
6092  if ( !Is_standalone )
6094 
6095  //Set the current hud
6096  set_current_hud();
6097 
6098  if ( !Is_standalone ) {
6100  }
6101  }
6102 
6103  // coming from the gameplay state or the main menu, we might need to load the mission
6104  if ( (Game_mode & GM_NORMAL) && ((old_state == GS_STATE_MAIN_MENU) || (old_state == GS_STATE_GAME_PLAY) || (old_state == GS_STATE_DEATH_BLEW_UP)) ) {
6105  if ( !game_start_mission() ) // this should put us into a new state.
6106  // Failed!!!
6107  break;
6108  }
6109 
6110  // if we are coming from the briefing, ship select, weapons loadout, or main menu (in the
6111  // case of quick start), then do bitmap loads, etc Don't do any of the loading stuff
6112  // if we are in multiplayer -- this stuff is all handled in the multi-wait section
6113  if ( !(Game_mode & GM_MULTIPLAYER) && ((old_state == GS_STATE_BRIEFING) || (old_state == GS_STATE_SHIP_SELECT) ||
6114  (old_state == GS_STATE_WEAPON_SELECT) || (old_state == GS_STATE_MAIN_MENU) || (old_state == GS_STATE_MULTI_STD_WAIT) || (old_state == GS_STATE_SIMULATOR_ROOM)) ) {
6115  // JAS: Used to do all paging here.
6116 
6117  #ifndef NDEBUG
6118  //XSTR:OFF
6119  HUD_printf("Skill level is set to ** %s **", Skill_level_names(Game_skill_level));
6120  //XSTR:ON
6121  #endif
6122 
6123  main_hall_stop_music(true);
6125  event_music_first_pattern(); // start the first pattern
6126  }
6127 
6128  // special code that restores player ship selection and weapons loadout when doing a quick start
6129  if ( !(Game_mode & GM_MULTIPLAYER) && ((old_state == GS_STATE_MAIN_MENU) || (old_state == GS_STATE_DEATH_BLEW_UP) || (old_state == GS_STATE_GAME_PLAY)) ) {
6130  if ( !stricmp(Player_loadout.filename, Game_current_mission_filename) ) {
6132  }
6133  }
6134 
6135  // single-player, quick-start after just died... we need to set weapon linking and kick off the event music
6136  if (!(Game_mode & GM_MULTIPLAYER) && (old_state == GS_STATE_DEATH_BLEW_UP) ) {
6137  event_music_first_pattern(); // start the first pattern
6138  }
6139 
6140  if ( !(Game_mode & GM_STANDALONE_SERVER) && ((old_state != GS_STATE_GAME_PAUSED) && (old_state != GS_STATE_MULTI_PAUSED)) ) {
6141  event_music_first_pattern(); // start the first pattern
6142  }
6144 
6146 
6147 #ifndef NDEBUG
6148  // required to truely make mouse deltas zeroed in debug mouse code
6149 void mouse_force_pos(int x, int y);
6151 #endif
6152 
6153  game_flush();
6154 
6155  // only start time if in single player, or coming from multi wait state
6156  if (
6157  (
6158  (Game_mode & GM_NORMAL) &&
6159  (old_state != GS_STATE_VIEW_CUTSCENES)
6160  ) || (
6161  (Game_mode & GM_MULTIPLAYER) && (
6162  (old_state == GS_STATE_MULTI_PAUSED) ||
6163  (old_state == GS_STATE_MULTI_MISSION_SYNC)
6164  )
6165  )
6166  )
6167  game_start_time();
6168 
6169  // when coming from the multi paused state, reset the timestamps
6170  if ( (Game_mode & GM_MULTIPLAYER) && (old_state == GS_STATE_MULTI_PAUSED) ){
6172  }
6173 
6174  if ((Game_mode & GM_MULTIPLAYER) && (old_state != GS_STATE_DEATH_BLEW_UP) ) {
6175  // initialize all object update details
6177  }
6178 
6179  // under certain circumstances, the server should reset the object update rate limiting stuff
6180  if( MULTIPLAYER_MASTER && ((old_state == GS_STATE_MULTI_PAUSED) || (old_state == GS_STATE_MULTI_MISSION_SYNC)) ){
6181 
6182  // reinitialize the rate limiting system for all clients
6184  }
6185 
6186  // multiplayer clients should always re-initialize their control info rate limiting system
6187  if(MULTIPLAYER_CLIENT){
6189  }
6190 
6191  // reset ping times
6192  if(Game_mode & GM_MULTIPLAYER){
6194  }
6195 
6196  Game_subspace_effect = 0;
6198  Game_subspace_effect = 1;
6199  if( !(Game_mode & GM_STANDALONE_SERVER) ){
6201  }
6202  }
6203 
6204  sound_env_set(&Game_sound_env);
6206 
6207  // clear multiplayer button info i
6209  memset(&Multi_ship_status_bi, 0, sizeof(button_info));
6210  break;
6211 
6212  case GS_STATE_HUD_CONFIG:
6213  hud_config_init();
6214  break;
6215 
6216  case GS_STATE_PXO:
6217  if (old_state != GS_STATE_PXO_HELP) {
6218  multi_pxo_init( 0 );
6219  }
6220  break;
6221 
6222  case GS_STATE_PXO_HELP:
6224  break;
6225 
6228 
6229  if (old_state != GS_STATE_OPTIONS_MENU) {
6231  }
6232 
6233  break;
6234 
6236  // don't reinitialize if we're coming back from the host options screen
6237  if ((old_state != GS_STATE_MULTI_HOST_OPTIONS) && (old_state != GS_STATE_OPTIONS_MENU)) {
6239  }
6240 
6241  break;
6242 
6244  if (old_state != GS_STATE_OPTIONS_MENU) {
6246  }
6247 
6248  break;
6249 
6252  break;
6253 
6254  case GS_STATE_TECH_MENU:
6255  techroom_init();
6256  break;
6257 
6259  if(old_state != GS_STATE_VIEW_MEDALS){
6260  barracks_init();
6261  }
6262  break;
6263 
6266  break;
6267 
6268  case GS_STATE_DEATH_DIED:
6269  Player_died_time = timestamp(10);
6270 
6271  if(!(Game_mode & GM_MULTIPLAYER)){
6273  }
6275  break;
6276 
6278  if ( !popupdead_is_active() ) {
6279  Player_ai->target_objnum = -1;
6280  }
6281 
6282  // stop any local EMP effect
6283  emp_stop_local();
6284 
6285  Players[Player_num].flags &= ~PLAYER_FLAGS_AUTO_TARGETING; // Prevent immediate switch to a hostile ship.
6287  Show_viewing_from_self = 0;
6288 
6289  // timestamp how long we should wait before displaying the died popup
6290  if ( !popupdead_is_active() ) {
6291  Player_died_popup_wait = timestamp(PLAYER_DIED_POPUP_WAIT);
6292  }
6293  break;
6294 
6297  break;
6298 
6299  case GS_STATE_CREDITS:
6300  main_hall_stop_music(true);
6302  credits_init();
6303  break;
6304 
6305  case GS_STATE_VIEW_MEDALS:
6307  break;
6308 
6309  case GS_STATE_SHOW_GOALS:
6311  break;
6312 
6315  break;
6316 
6318  // if we're coming from the options screen, don't do any
6319  if(old_state == GS_STATE_OPTIONS_MENU){
6320  break;
6321  }
6322 
6323  switch(Multi_sync_mode){
6325  // if moving from game forming to the team select state
6326  multi_sync_init();
6327  break;
6329  // if moving from briefing into the mission itself
6330  multi_sync_init();
6331 
6332  // tell everyone that we're now loading data
6335 
6336  // JAS: Used to do all paging here!!!!
6337 
6340  break;
6341  case MULTI_SYNC_INGAME:
6342  multi_sync_init();
6343  break;
6344  }
6345  break;
6346 
6349  break;
6350 
6353  break;
6354 
6356  // don't initialize if we're coming from one of these 2 states unless there are no
6357  // players left (reset situation)
6358  if((old_state != GS_STATE_STANDALONE_POSTGAME) || multi_endgame_ending()){
6360  }
6361  break;
6362 
6365  break;
6366 
6367  case GS_STATE_MULTI_PAUSED:
6368  multi_pause_init();
6369  break;
6370 
6373  break;
6374 
6377  break;
6378 
6381  break;
6382 
6385  break;
6386 
6389  break;
6390 
6391  case GS_STATE_LOOP_BRIEF:
6392  loop_brief_init();
6393  break;
6394 
6395  case GS_STATE_LAB:
6396  lab_init();
6397  break;
6398 
6399  case GS_STATE_SCRIPTING:
6401  break;
6402  } // end switch
6403 
6404  //WMC - now do user scripting stuff
6406 }
6407 
6408 // do stuff that may need to be done regardless of state
6409 void game_do_state_common(int state,int no_networking)
6410 {
6411  game_maybe_draw_mouse(flFrametime); // determine if to draw the mouse this frame
6412  snd_do_frame(); // update sound system
6413  event_music_do_frame(); // music needs to play across many states
6414 
6415  multi_log_process();
6416 
6417  if (no_networking) {
6418  return;
6419  }
6420 
6421  // maybe do a multiplayer frame based on game mode and state type
6422  if (Game_mode & GM_MULTIPLAYER) {
6423  switch (state) {
6424  case GS_STATE_OPTIONS_MENU:
6427  case GS_STATE_HUD_CONFIG:
6430  case GS_STATE_SHOW_GOALS:
6432  case GS_STATE_EVENT_DEBUG:
6434  break;
6435  }
6436 
6438  }
6439 }
6440 
6441 // Called once a frame.
6442 // You should never try to change the state
6443 // in here... if you think you need to, you probably really
6444 // need to post an event, not change the state.
6446 void game_do_state(int state)
6447 {
6448  // always lets the do_state_common() function determine if the state should be skipped
6449  Game_do_state_should_skip = 0;
6450 
6451  // legal to set the should skip state anywhere in this function
6452  game_do_state_common(state); // do stuff that may need to be done regardless of state
6453 
6454  if(Game_do_state_should_skip){
6455  return;
6456  }
6457 
6459  game_set_frametime(state);
6460  gr_clear();
6461  gr_flip(); //Does state hook automagically
6462  return;
6463  }
6464  /*
6465  if(Script_system.IsOverride(GS_state_hooks[state]))
6466  {
6467  game_set_frametime(state);
6468  gr_clear();
6469  Script_system.RunBytecode(GS_state_hooks[state]);
6470  gr_flip();
6471  return;
6472  }
6473  */
6474 
6475  switch (state) {
6476  case GS_STATE_MAIN_MENU:
6478  main_hall_do(flFrametime);
6479  break;
6480 
6481  case GS_STATE_OPTIONS_MENU:
6483  options_menu_do_frame(flFrametime);
6484  break;
6485 
6488  barracks_do_frame(flFrametime);
6489  break;
6490 
6493  training_menu_do_frame(flFrametime);
6494  break;
6495 
6496  case GS_STATE_TECH_MENU:
6498  techroom_do_frame(flFrametime);
6499  break;
6500 
6503  gameplay_help_do_frame(flFrametime);
6504  break;
6505 
6506  case GS_STATE_GAME_PLAY: // do stuff that should be done during gameplay
6507  game_do_frame();
6508  break;
6509 
6510  case GS_STATE_GAME_PAUSED:
6511 
6513 
6514  read_player_controls( Player_obj, flFrametime);
6515  // game_process_keys();
6516  game_frame(true);
6517  }
6518 
6519  pause_do();
6520  break;
6521 
6522  case GS_STATE_DEBUG_PAUSED:
6523  #ifndef NDEBUG
6525  pause_debug_do();
6526  #endif
6527  break;
6528 
6531  break;
6532 
6536  break;
6537 
6538  case GS_STATE_BRIEFING:
6540  brief_do_frame(flFrametime);
6541  break;
6542 
6543  case GS_STATE_DEBRIEF:
6545  debrief_do_frame(flFrametime);
6546  break;
6547 
6551  break;
6552 
6553  case GS_STATE_SHIP_SELECT:
6555  ship_select_do(flFrametime);
6556  break;
6557 
6560  weapon_select_do(flFrametime);
6561  break;
6562 
6565  hud_scrollback_do_frame(flFrametime);
6566  break;
6567 
6568  case GS_STATE_HUD_CONFIG:
6570  hud_config_do_frame(flFrametime);
6571  break;
6572 
6573  case GS_STATE_PXO:
6575  multi_pxo_do();
6576  break;
6577 
6578  case GS_STATE_PXO_HELP:
6581  break;
6582 
6586  break;
6587 
6591  break;
6592 
6596  break;
6597 
6600  control_config_do_frame(flFrametime);
6601  break;
6602 
6603  case GS_STATE_DEATH_DIED:
6604  game_do_frame();
6605  break;
6606 
6608  game_do_frame();
6609  break;
6610 
6613  sim_room_do_frame(flFrametime);
6614  break;
6615 
6618  campaign_room_do_frame(flFrametime);
6619  break;
6620 
6621  case GS_STATE_RED_ALERT:
6623  red_alert_do_frame(flFrametime);
6624  break;
6625 
6626  case GS_STATE_CMD_BRIEF:
6628  cmd_brief_do_frame(flFrametime);
6629  break;
6630 
6631  case GS_STATE_CREDITS:
6633  credits_do_frame(flFrametime);
6634  break;
6635 
6636  case GS_STATE_VIEW_MEDALS:
6638  medal_main_do();
6639  break;
6640 
6641  case GS_STATE_SHOW_GOALS:
6643  mission_show_goals_do_frame(flFrametime);
6644  break;
6645 
6648  mission_hotkey_do_frame(flFrametime);
6649  break;
6650 
6654  break;
6655 
6659  break;
6660 
6664  break;
6665 
6666  case GS_STATE_MULTI_PAUSED:
6668  multi_pause_do();
6669  break;
6670 
6671  case GS_STATE_TEAM_SELECT:
6673  multi_ts_do();
6674  break;
6675 
6679  break;
6680 
6681  case GS_STATE_EVENT_DEBUG:
6682  #ifndef NDEBUG
6684  game_show_event_debug(flFrametime);
6685  #endif
6686  break;
6687 
6691  break;
6692 
6695  player_select_do();
6696  break;
6697 
6700  multi_sync_do();
6701  break;
6702 
6706  break;
6707 
6711  break;
6712 
6715  break;
6716 
6717  case GS_STATE_LOOP_BRIEF:
6719  loop_brief_do(flFrametime);
6720  break;
6721 
6724  fiction_viewer_do_frame(flFrametime);
6725  break;
6726 
6727  case GS_STATE_LAB:
6729  lab_do_frame(flFrametime);
6730  break;
6731 
6732  case GS_STATE_SCRIPTING:
6734  scripting_state_do_frame(flFrametime);
6735  break;
6736 
6737  } // end switch(gs_current_state)
6738 }
6739 
6740 
6741 #ifdef _WIN32
6742 // return 0 if there is enough RAM to run FreeSpace, otherwise return -1
6743 int game_do_ram_check(uint ram_in_bytes)
6744 {
6745  if ( ram_in_bytes < 30*1024*1024 ) {
6746  int allowed_to_run = 1;
6747  if ( ram_in_bytes < 25*1024*1024 ) {
6748  allowed_to_run = 0;
6749  }
6750 
6751  char tmp[1024];
6752  uint FreeSpace_total_ram_MB;
6753  FreeSpace_total_ram_MB = (uint)(ram_in_bytes/(1024*1024));
6754 
6755  if ( allowed_to_run ) {
6756 
6757  sprintf( tmp, XSTR( "FreeSpace has detected that you only have %dMB of free memory.\n\nFreeSpace requires at least 32MB of memory to run. If you think you have more than %dMB of physical memory, ensure that you aren't running SmartDrive (SMARTDRV.EXE). Any memory allocated to SmartDrive is not usable by applications\n\nPress 'OK' to continue running with less than the minimum required memory\n", 193), FreeSpace_total_ram_MB, FreeSpace_total_ram_MB);
6758 
6759  int msgbox_rval;
6760  msgbox_rval = MessageBox( NULL, tmp, XSTR( "Not Enough RAM", 194), MB_OKCANCEL );
6761  if ( msgbox_rval == IDCANCEL ) {
6762  return -1;
6763  }
6764 
6765  } else {
6766  sprintf( tmp, XSTR( "FreeSpace has detected that you only have %dMB of free memory.\n\nFreeSpace requires at least 32MB of memory to run. If you think you have more than %dMB of physical memory, ensure that you aren't running SmartDrive (SMARTDRV.EXE). Any memory allocated to SmartDrive is not usable by applications\n", 195), FreeSpace_total_ram_MB, FreeSpace_total_ram_MB);
6767  MessageBox( NULL, tmp, XSTR( "Not Enough RAM", 194), MB_OK );
6768  return -1;
6769  }
6770  }
6771 
6772  return 0;
6773 }
6774 
6775 
6776 #if 0 // no updater for fs2
6777 // Check if there is a freespace.exe in the /update directory (relative to where fs.exe is installed).
6778 // If so, copy it over and remove the update directory.
6779 void game_maybe_update_launcher(char *exe_dir)
6780 {
6781  char src_filename[MAX_PATH];
6782  char dest_filename[MAX_PATH];
6783 
6784  strcpy_s(src_filename, exe_dir);
6785  strcat_s(src_filename, NOX("\\update\\freespace.exe"));
6786 
6787  strcpy_s(dest_filename, exe_dir);
6788  strcat_s(dest_filename, NOX("\\freespace.exe"));
6789 
6790  // see if src_filename exists
6791  FILE *fp;
6792  fp = fopen(src_filename, "rb");
6793  if ( !fp ) {
6794  return;
6795  }
6796  fclose(fp);
6797 
6798  SetFileAttributes(dest_filename, FILE_ATTRIBUTE_NORMAL);
6799 
6800  // copy updated freespace.exe to freespace exe dir
6801  if ( CopyFile(src_filename, dest_filename, 0) == 0 ) {
6802  MessageBox( NULL, XSTR("Unable to copy freespace.exe from update directory to installed directory. You should copy freespace.exe from the update directory (located in your FreeSpace install directory) to your install directory", 988), NULL, MB_OK|MB_TASKMODAL|MB_SETFOREGROUND );
6803  return;
6804  }
6805 
6806  // delete the file in the update directory
6807  DeleteFile(src_filename);
6808 
6809  // safe to assume directory is empty, since freespace.exe should only be the file ever in the update dir
6810  char update_dir[MAX_PATH];
6811  strcpy_s(update_dir, exe_dir);
6812  strcat_s(update_dir, NOX("\\update"));
6813  RemoveDirectory(update_dir);
6814 }
6815 #endif // no launcher
6816 
6817 #endif // ifdef WIN32
6818 
6819 void game_spew_pof_info_sub(int model_num, polymodel *pm, int sm, CFILE *out, int *out_total, int *out_destroyed_total)
6820 {
6821  int i;
6822  int sub_total = 0;
6823  int sub_total_destroyed = 0;
6824  int total = 0;
6825  char str[255] = "";
6826 
6827  // get the total for all his children
6828  for (i=pm->submodel[sm].first_child; i >= 0; i = pm->submodel[i].next_sibling ) {
6829  game_spew_pof_info_sub(model_num, pm, i, out, &sub_total, &sub_total_destroyed);
6830  }
6831 
6832  // find the # of faces for this _individual_ object
6833  total = submodel_get_num_polys(model_num, sm);
6834  if(strstr(pm->submodel[sm].name, "-destroyed")){
6835  sub_total_destroyed = total;
6836  }
6837 
6838  // write out total
6839  sprintf(str, "Submodel %s total : %d faces\n", pm->submodel[sm].name, total);
6840  cfputs(str, out);
6841 
6842  *out_total += total + sub_total;
6843  *out_destroyed_total += sub_total_destroyed;
6844 }
6845 
6846 #define BAIL() do { int _idx; for(_idx=0; _idx<num_files; _idx++){ if(pof_list[_idx] != NULL){vm_free(pof_list[_idx]); pof_list[_idx] = NULL;}} return;} while(0);
6848 {
6849  char *pof_list[1000];
6850  int num_files;
6851  CFILE *out;
6852  int idx, model_num, i, j;
6853  polymodel *pm;
6854  int total, root_total, model_total, destroyed_total, counted;
6855  char str[255] = "";
6856 
6857  // get file list
6858  num_files = cf_get_file_list(1000, pof_list, CF_TYPE_MODELS, "*.pof");
6859 
6860  // spew info on all the pofs
6861  if(!num_files){
6862  return;
6863  }
6864 
6865  // go
6866  out = cfopen("pofspew.txt", "wt", CFILE_NORMAL, CF_TYPE_DATA);
6867  if(out == NULL){
6868  BAIL();
6869  }
6870  counted = 0;
6871  for(idx=0; idx<num_files; idx++, counted++){
6872  sprintf(str, "%s.pof", pof_list[idx]);
6873  model_num = model_load(str, 0, NULL);
6874  if(model_num >= 0){
6875  pm = model_get(model_num);
6876 
6877  // if we have a real model
6878  if(pm != NULL){
6879  cfputs(str, out);
6880  cfputs("\n", out);
6881 
6882  // go through and print all raw submodels
6883  cfputs("RAW\n", out);
6884  total = 0;
6885  model_total = 0;
6886  for (i=0; i<pm->n_models; i++) {
6887  total = submodel_get_num_polys(model_num, i);
6888 
6889  model_total += total;
6890  sprintf(str, "Submodel %s total : %d faces\n", pm->submodel[i].name, total);
6891  cfputs(str, out);
6892  }
6893  sprintf(str, "Model total %d\n", model_total);
6894  cfputs(str, out);
6895 
6896  // now go through and do it by LOD
6897  cfputs("BY LOD\n\n", out);
6898  for(i=0; i<pm->n_detail_levels; i++){
6899  sprintf(str, "LOD %d\n", i);
6900  cfputs(str, out);
6901 
6902  // submodels
6903  root_total = submodel_get_num_polys(model_num, pm->detail[i] );
6904  total = 0;
6905  destroyed_total = 0;
6906  for (j=pm->submodel[pm->detail[i]].first_child; j >= 0; j = pm->submodel[j].next_sibling ) {
6907  game_spew_pof_info_sub(model_num, pm, j, out, &total, &destroyed_total);
6908  }
6909 
6910  sprintf(str, "Submodel %s total : %d faces\n", pm->submodel[pm->detail[i]].name, root_total);
6911  cfputs(str, out);
6912 
6913  sprintf(str, "TOTAL: %d\n", total + root_total);
6914  cfputs(str, out);
6915  sprintf(str, "TOTAL not counting destroyed faces %d\n", (total + root_total) - destroyed_total);
6916  cfputs(str, out);
6917  sprintf(str, "TOTAL destroyed faces %d\n\n", destroyed_total);
6918  cfputs(str, out);
6919  }
6920  cfputs("------------------------------------------------------------------------\n\n", out);
6921  }
6922  }
6923 
6924  if(counted >= MAX_POLYGON_MODELS - 5){
6925  model_free_all();
6926  counted = 0;
6927  }
6928  }
6929 
6930  cfclose(out);
6931  model_free_all();
6932  BAIL();
6933 }
6934 
6935 DCF(pofspew, "Spews POF info without shutting down the game")
6936 {
6938 }
6939 
6940 // returns:
6941 // 0 on an error
6942 // 1 on a clean exit
6943 int game_main(char *cmdline)
6944 {
6945  int state;
6946 
6947  // check if networking should be disabled, this could probably be done later but the sooner the better
6948  // TODO: remove this when multi is fixed to handle more than MAX_SHIP_CLASSES_MULTI
6949  if ( Ship_info.size() > MAX_SHIP_CLASSES_MULTI ) {
6950  Networking_disabled = 1;
6951  }
6952 
6953 #ifndef NDEBUG
6954  extern void windebug_memwatch_init();
6956 #endif
6957 
6958 #ifdef _WIN32
6959  // Find out how much RAM is on this machine
6960  MEMORYSTATUS ms;
6961  ms.dwLength = sizeof(MEMORYSTATUS);
6962  GlobalMemoryStatus(&ms);
6963  FreeSpace_total_ram = ms.dwTotalPhys;
6964 
6965  Mem_starttime_phys = ms.dwAvailPhys;
6966  Mem_starttime_pagefile = ms.dwAvailPageFile;
6967  Mem_starttime_virtual = ms.dwAvailVirtual;
6968 
6969  if ( game_do_ram_check(FreeSpace_total_ram) == -1 ) {
6970  return 1;
6971  }
6972 
6973  if ( ms.dwTotalVirtual < 1024 ) {
6974  MessageBox( NULL, XSTR( "FreeSpace requires virtual memory to run.\r\n", 196), XSTR( "No Virtual Memory", 197), MB_OK );
6975  return 1;
6976  }
6977 
6978  if (!vm_init(24*1024*1024)) {
6979  MessageBox( NULL, XSTR( "Not enough memory to run FreeSpace.\r\nTry closing down some other applications.\r\n", 198), XSTR( "Not Enough Memory", 199), MB_OK );
6980  return 1;
6981  }
6982 
6983  char *tmp_mem = (char *) vm_malloc(16 * 1024 * 1024);
6984  if (!tmp_mem) {
6985  MessageBox(NULL, XSTR( "Not enough memory to run FreeSpace.\r\nTry closing down some other applications.\r\n", 198), XSTR( "Not Enough Memory", 199), MB_OK);
6986  return 1;
6987  }
6988 
6989  vm_free(tmp_mem);
6990  tmp_mem = NULL;
6991 
6992 #else
6993 
6994  vm_init(0);
6995 
6996 #endif // _WIN32
6997 
6998 
6999  if ( !parse_cmdline(cmdline) ) {
7000  return 1;
7001  }
7002 
7003 
7004  if (Is_standalone){
7005  nprintf(("Network", "Standalone running\n"));
7006  }
7007 
7008 
7009 #ifdef _WIN32
7010  if ( !Is_standalone )
7011  disableWindowsKey( );
7012 #endif
7013 
7014 
7015  init_cdrom();
7016 
7017  game_init();
7018  // calling the function that will init all the function pointers for TrackIR stuff (Swifty)
7019  int trackIrInitResult = gTirDll_TrackIR.Init( (HWND)os_get_window( ) );
7020  if ( trackIrInitResult != SCP_INITRESULT_SUCCESS )
7021  {
7022  mprintf( ("TrackIR Init Failed - %d\n", trackIrInitResult) );
7023  }
7024  game_stop_time();
7025 
7027  multi_spew_pxo_checksums(1024, "mission_crcs.csv");
7028 
7030  fs2netd_spew_table_checksums("table_crcs.csv");
7031  }
7032 
7033  game_shutdown();
7034  return 0;
7035  }
7036 
7037 
7039  fs2netd_spew_table_checksums("table_crcs.csv");
7040  game_shutdown();
7041  return 0;
7042  }
7043 
7044  // maybe spew pof stuff
7047  game_shutdown();
7048  return 0;
7049  }
7050 
7051 
7052  // maybe spew VP CRCs, and exit
7053  if (Cmdline_verify_vps) {
7054  extern void cfile_spew_pack_file_crcs();
7056  game_shutdown();
7057  return 0;
7058  }
7059 
7060  if (!Is_standalone) {
7061  movie_play( NOX("intro.mve") );
7062  }
7063 
7064  if (Is_standalone){
7066  } else {
7067  gameseq_post_event(GS_EVENT_GAME_INIT); // start the game rolling -- check for default pilot, or go to the pilot select screen
7068  }
7069 
7070  while (1) {
7071  // only important for non THREADED mode
7072  os_poll();
7073 
7074  state = gameseq_process_events();
7075  if ( state == GS_STATE_QUIT_GAME ){
7076  break;
7077  }
7078  }
7079 
7080  game_shutdown();
7081 
7082 #ifdef _WIN32
7083  if ( !Is_standalone )
7084  enableWindowsKey( );
7085 #endif
7086 
7087  return 0;
7088 }
7089 
7090 
7091 // ------------------------------------------------------------------------------
7092 // Platform specific main() functions, nothing directly related to game function
7093 // should go here. Direct game related info should go in the game_main() function
7094 // TODO: this should end up in a separate file in the not too distant future.
7095 //
7096 
7097 #ifdef _WIN32
7098 // Windows Specific
7099 int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
7100 {
7101  int result = -1;
7102 
7103  // Don't let more than one instance of FreeSpace run.
7104  HWND hwnd = FindWindow( NOX( "FreeSpaceClass" ), NULL );
7105  if ( hwnd ) {
7106  SetForegroundWindow(hwnd);
7107  return 0;
7108  }
7109 
7110  ::CoInitialize(NULL);
7111 
7112 #ifdef _DEBUG
7113  void memblockinfo_output_memleak();
7114  atexit(memblockinfo_output_memleak);
7115 #endif
7116 
7117  //=====================================================
7118  // Make sure we're running in the right directory.
7119  char exe_dir[1024];
7120 
7121  if ( GetModuleFileName( hInst, exe_dir, 1023 ) > 0 ) {
7122  char *p = exe_dir + strlen(exe_dir);
7123 
7124  // chop off the filename
7125  while( (p>exe_dir) && (*p!='\\') && (*p!='/') && (*p!=':') ) {
7126  p--;
7127  }
7128  *p = 0;
7129 
7130  // Set directory
7131  if ( strlen(exe_dir) > 0 ) { //-V805
7132  SetCurrentDirectory(exe_dir);
7133  }
7134  }
7135 
7137 
7138 #ifdef GAME_ERRORLOG_TXT
7139 #ifdef _MSC_VER
7140  __try {
7141 #endif
7142 #endif
7143  result = !game_main(szCmdLine);
7144 #ifdef GAME_ERRORLOG_TXT
7145 #ifdef _MSC_VER
7146  } __except( RecordExceptionInfo(GetExceptionInformation(), "FreeSpace 2 Main Thread") ) {
7147  // Do nothing here - RecordExceptionInfo() has already done
7148  // everything that is needed. Actually this code won't even
7149  // get called unless you return EXCEPTION_EXECUTE_HANDLER from
7150  // the __except clause.
7151  }
7152 #endif // _MSC_VER
7153 #endif
7154 
7156 
7157  ::CoUninitialize();
7158 
7159 #ifndef _MINGW
7160  _CrtDumpMemoryLeaks();
7161 #endif
7162 
7163  return result;
7164 }
7165 
7166 #else
7167 
7168 // *NIX specific
7169 int main(int argc, char *argv[])
7170 {
7171  int result = EXIT_FAILURE;
7172  char *argptr = NULL;
7173  int i, len = 0;
7174  char userdir[MAX_PATH];
7175 
7176 #ifdef APPLE_APP
7177  // Finder sets the working directory to the root of the drive so we have to get a little creative
7178  // to find out where on the disk we should be running from for CFILE's sake.
7179  strncpy(full_path, *argv, 1024);
7180 #endif
7181 
7182  // create user's directory
7183  memset(userdir, 0, sizeof(userdir));
7184  snprintf(userdir, MAX_PATH - 1, "%s/%s/", detect_home(), Osreg_user_dir);
7185  _mkdir(userdir);
7186 
7187 
7188  // clean up the cmdline to just send arguments through
7189  for (i = 1; i < argc; i++) {
7190  len += strlen(argv[i]) + 1;
7191  }
7192 
7193  argptr = (char*) calloc(len + 1, sizeof(char));
7194 
7195  if (argptr == NULL) {
7196  fprintf(stderr, "ERROR: Out of memory in main()!\n");
7197  exit(EXIT_FAILURE);
7198  }
7199 
7200  memset( argptr, 0, len+1 );
7201 
7202  for (i = 1; i < argc; i++) {
7203  strcat(argptr, argv[i]);
7204  strcat(argptr, " ");
7205  }
7206 
7207  // switch to game_main()
7208  try {
7209  result = game_main(argptr);
7210 
7211  if (argptr != NULL) {
7212  free(argptr);
7213  argptr = NULL;
7214  }
7215  } catch (std::exception &ex) {
7216  fprintf(stderr, "Caught std::exception in main(): '%s'!\n", ex.what());
7217  result = EXIT_FAILURE;
7218  } catch ( ... ) {
7219  fprintf(stderr, "Caught exception in main()!\n");
7220  result = EXIT_FAILURE;
7221  }
7222 
7223  return result;
7224 }
7225 
7226 #endif // _WIN32
7227 
7228 //
7229 // End of platform specific main() section
7230 // ------------------------------------------------------------------------------
7231 
7232 
7233 #if 0 // don't have an updater for fs2_open
7234 // launch the fslauncher program on exit
7235 void game_launch_launcher_on_exit()
7236 {
7237  STARTUPINFO si;
7238  PROCESS_INFORMATION pi;
7239  char cmd_line[2048];
7240  char original_path[1024] = "";
7241 
7242  memset( &si, 0, sizeof(STARTUPINFO) );
7243  si.cb = sizeof(si);
7244 
7245  // directory
7246  _getcwd(original_path, 1023);
7247 
7248  // set up command line
7249  strcpy_s(cmd_line, original_path);
7250  strcat_s(cmd_line, DIR_SEPARATOR_STR);
7251  strcat_s(cmd_line, LAUNCHER_FNAME);
7252  strcat_s(cmd_line, " -straight_to_update");
7253 
7254  BOOL ret = CreateProcess( NULL, // pointer to name of executable module
7255  cmd_line, // pointer to command line string
7256  NULL, // pointer to process security attributes
7257  NULL, // pointer to thread security attributes
7258  FALSE, // handle inheritance flag
7259  CREATE_DEFAULT_ERROR_MODE, // creation flags
7260  NULL, // pointer to new environment block
7261  NULL, // pointer to current directory name
7262  &si, // pointer to STARTUPINFO
7263  &pi // pointer to PROCESS_INFORMATION
7264  );
7265  // to eliminate build warnings
7266  ret;
7267 }
7268 #endif
7269 
7270 
7271 // game_shutdown()
7272 //
7273 // This function is called when FreeSpace terminates normally.
7274 //
7275 void game_shutdown(void)
7276 {
7278  profile_deinit();
7279 
7280  fsspeech_deinit();
7281 #ifdef FS2_VOICER
7283  {
7284  VOICEREC_deinit();
7285  }
7286 #endif
7287 
7288  // don't ever flip a page on the standalone!
7290  gr_reset_clip();
7291  gr_clear();
7292  gr_flip();
7293  }
7294 
7295  // if the player has left the "player select" screen and quit the game without actually choosing
7296  // a player, Player will be NULL, in which case we shouldn't write the player file out!
7297  if (!(Game_mode & GM_STANDALONE_SERVER) && (Player!=NULL) && !Is_standalone){
7298  Pilot.save_player();
7299  Pilot.save_savefile();
7300  }
7301 
7302  // load up common multiplayer icons
7304  hud_close();
7305  fireball_close(); // free fireball system
7306  particle_close(); // close out the particle system
7307  weapon_close(); // free any memory that was allocated for the weapons
7308  ship_close(); // free any memory that was allocated for the ships
7309  hud_free_scrollback_list();// free space allocated to store hud messages in hud scrollback
7310  unload_animating_pointer();// frees the frames used for the animating mouse pointer
7311  mission_campaign_clear(); // clear out the campaign stuff
7312  message_mission_close(); // clear loaded table data from message.tbl
7313  mission_parse_close(); // clear out any extra memory that may be in use by mission parsing
7314  multi_voice_close(); // close down multiplayer voice (including freeing buffers, etc)
7315  multi_log_close();
7316  logfile_close(LOGFILE_EVENT_LOG); // close down the mission log
7317 #ifdef MULTI_USE_LAG
7318  multi_lag_close();
7319 #endif
7320  fs2netd_close();
7321 
7322  if ( Cmdline_old_collision_sys ) {
7323  obj_pairs_close(); // free memory from object collision pairs
7324  } else {
7326  }
7327  stars_close(); // clean out anything used by stars code
7328 
7329  // the menu close functions will unload the bitmaps if they were displayed during the game
7330  main_hall_close();
7332  gr_close();
7333 
7334  // free left over memory from table parsing
7336 
7338  joy_close();
7339 
7341  snd_close();
7343  gamesnd_close(); // close out gamesnd, needs to happen *after* other sounds are closed
7344  psnet_close();
7345 
7346  model_free_all();
7347  bm_unload_all(); // unload/free bitmaps, has to be called *after* model_free_all()!
7348 
7349  os_cleanup();
7350 
7351  // although the comment in cmdline.cpp said this isn't needed,
7352  // Valgrind disagrees (quite possibly incorrectly), but this is just cleaner
7353  if (Cmdline_mod != NULL) {
7354  delete[] Cmdline_mod;
7355  Cmdline_mod = NULL;
7356  }
7357 
7358 #if 0 // don't have an updater for fs2_open
7359  // HACKITY HACK HACK
7360  // if this flag is set, we should be firing up the launcher when exiting freespace
7362  if(Multi_update_fireup_launcher_on_exit){
7363  game_launch_launcher_on_exit();
7364  }
7365 #endif
7366 }
7367 
7368 // game_stop_looped_sounds()
7369 //
7370 // This function will call the appropriate stop looped sound functions for those
7371 // modules which use looping sounds. It is not enough just to stop a looping sound
7372 // at the DirectSound level, the game is keeping track of looping sounds, and this
7373 // function is used to inform the game that looping sounds are being halted.
7374 //
7376 {
7381  obj_snd_stop_all(); // stop all object-linked persistant sounds
7384  Radar_static_looping = -1;
7387  Target_static_looping = -1;
7388 }
7389 
7391 //
7392 // Code for supporting an animating mouse pointer
7393 //
7394 //
7396 
7397 typedef struct animating_obj
7398 {
7402  float time;
7404 } animating_obj;
7405 
7406 static animating_obj Animating_mouse;
7407 
7408 // ----------------------------------------------------------------------------
7409 // init_animating_pointer()
7410 //
7411 // Called by load_animating_pointer() to ensure the Animating_mouse struct
7412 // gets properly initialized
7413 //
7415 {
7416  Animating_mouse.first_frame = -1;
7417  Animating_mouse.num_frames = 0;
7418  Animating_mouse.current_frame = -1;
7419  Animating_mouse.time = 0.0f;
7420  Animating_mouse.elapsed_time = 0.0f;
7421 }
7422 
7423 // ----------------------------------------------------------------------------
7424 // load_animating_pointer()
7425 //
7426 // Called at game init to load in the frames for the animating mouse pointer
7427 //
7428 // input: filename => filename of animation file that holds the animation
7429 //
7430 void load_animating_pointer(char *filename)
7431 {
7432  int fps;
7433  animating_obj *am;
7434 
7436 
7437  mprintf(("loading animated cursor \"%s\"\n", filename));
7438 
7439  am = &Animating_mouse;
7440  am->first_frame = bm_load_animation(filename, &am->num_frames, &fps);
7441  if ( am->first_frame == -1 )
7442  Error(LOCATION, "Could not load animation %s for the mouse pointer\n", filename);
7443  am->current_frame = 0;
7444  am->time = am->num_frames / i2fl(fps);
7445 }
7446 
7447 // ----------------------------------------------------------------------------
7448 // unload_animating_pointer()
7449 //
7450 // Called at game shutdown to free the memory used to store the animation frames
7451 //
7453 {
7454  int i;
7455  animating_obj *am;
7456 
7457  am = &Animating_mouse;
7458  for ( i = 0; i < am->num_frames; i++ ) {
7459  Assert( (am->first_frame+i) >= 0 );
7460 
7461  // if we are the current cursor then reset to avoid gr_close() issues - taylor
7463  }
7464 
7465  // this will release all of the frames at once
7466  if (am->first_frame >= 0)
7467  bm_release(am->first_frame);
7468 
7469  am->first_frame = -1;
7470  am->num_frames = 0;
7471  am->current_frame = -1;
7472 }
7473 
7474 // draw the correct frame of the game mouse... called from game_maybe_draw_mouse()
7475 void game_render_mouse(float frametime)
7476 {
7477  int mx, my;
7478  animating_obj *am;
7479 
7480  // if animating cursor exists, play the next frame
7481  am = &Animating_mouse;
7482  if ( am->first_frame != -1 ) {
7483  mouse_get_pos(&mx, &my);
7484  am->elapsed_time += frametime;
7485  am->current_frame = fl2i( ( am->elapsed_time / am->time ) * (am->num_frames-1) );
7486  if ( am->current_frame >= am->num_frames ) {
7487  am->current_frame = 0;
7488  am->elapsed_time = 0.0f;
7489  }
7491  }
7492 }
7493 
7494 // ----------------------------------------------------------------------------
7495 // game_maybe_draw_mouse()
7496 //
7497 // determines whether to draw the mouse pointer at all, and what frame of
7498 // animation to use if the mouse is animating
7499 //
7500 // Sets mouse.cpp globals Mouse_hidden and Mouse_moved based on the state of the game.
7501 //
7502 // input: frametime => elapsed frame time in seconds since last call
7503 //
7504 void game_maybe_draw_mouse(float frametime)
7505 {
7506  int game_state;
7507 
7508  game_state = gameseq_get_state();
7509 
7510  switch ( game_state ) {
7511  case GS_STATE_GAME_PAUSED:
7512  // case GS_STATE_MULTI_PAUSED:
7513  case GS_STATE_GAME_PLAY:
7514  case GS_STATE_DEATH_DIED:
7516  if ( popup_active() || popupdead_is_active() ) {
7517  Mouse_hidden = 0;
7518  } else {
7519  Mouse_hidden = 1;
7520  }
7521  break;
7522 
7523  default:
7524  Mouse_hidden = 0;
7525  break;
7526  } // end switch
7527 
7528  if ( !Mouse_hidden )
7529  game_render_mouse(frametime);
7530 
7531 }
7532 
7534 {
7535  int i, s;
7536  float d;
7537  waypoint_list *wplp;
7538 
7540  s = (int) Player_obj->phys_info.fspeed;
7545  }
7546 
7547  } else
7549  }
7550 
7552  wplp = Training_context_path;
7553  if (wplp->get_waypoints().size() > (uint) Training_context_goal_waypoint) {
7555  do {
7556  waypoint *wpt = find_waypoint_at_index(wplp, i);
7557  Assert(wpt != NULL);
7558  d = vm_vec_dist(wpt->get_pos(), &Player_obj->pos);
7559  if (d <= Training_context_distance) {
7561  if (Training_context_goal_waypoint == i) {
7563  snd_play(&Snds[SND_CARGO_REVEAL], 0.0f);
7564  }
7565 
7566  break;
7567  }
7568 
7569  i++;
7570  if ((uint) i == wplp->get_waypoints().size())
7571  i = 0;
7572 
7573  } while (i != Training_context_goal_waypoint);
7574  }
7575  }
7576 
7581  }
7582  // following added by Sesquipedalian for is_missile_locked
7586  }
7587 
7588 }
7589 
7591 
7592 #ifndef NDEBUG
7593 
7594 #define EVENT_DEBUG_MAX 5000
7595 #define EVENT_DEBUG_EVENT 0x8000
7596 
7599 
7600 void game_add_event_debug_index(int n, int indent)
7601 {
7602  if (ED_count < EVENT_DEBUG_MAX)
7603  Event_debug_index[ED_count++] = n | (indent << 16);
7604 }
7605 
7606 void game_add_event_debug_sexp(int n, int indent)
7607 {
7608  if (n < 0)
7609  return;
7610 
7611  if (Sexp_nodes[n].first >= 0) {
7613  game_add_event_debug_sexp(Sexp_nodes[n].rest, indent);
7614  return;
7615  }
7616 
7617  game_add_event_debug_index(n, indent);
7619  game_add_event_debug_sexp(Sexp_nodes[n].rest, indent + 1);
7620  else
7621  game_add_event_debug_sexp(Sexp_nodes[n].rest, indent);
7622 }
7623 
7625 {
7626  int e;
7627 
7628  ED_count = 0;
7629  for (e=0; e<Num_mission_events; e++) {
7632  }
7633 }
7634 
7635 void game_show_event_debug(float frametime)
7636 {
7637  char buf[256];
7638  int i, k, z;
7639  int font_height, font_width;
7640  int y_index, y_max;
7641  static int scroll_offset = 0;
7642 
7643  k = game_check_key();
7644  if (k)
7645  switch (k) {
7646  case KEY_UP:
7647  case KEY_PAD8:
7648  scroll_offset--;
7649  if (scroll_offset < 0)
7650  scroll_offset = 0;
7651  break;
7652 
7653  case KEY_DOWN:
7654  case KEY_PAD2:
7655  scroll_offset++;
7656  break;
7657 
7658  case KEY_PAGEUP:
7659  scroll_offset -= 20;
7660  if (scroll_offset < 0)
7661  scroll_offset = 0;
7662  break;
7663 
7664  case KEY_PAGEDOWN:
7665  scroll_offset += 20; // not font-independent, hard-coded since I counted the lines!
7666  break;
7667 
7668  default:
7670  key_flush();
7671  break;
7672  } // end switch
7673 
7674  gr_clear();
7676  gr_set_font(FONT1);
7677  gr_printf_no_resize(0x8000, gr_screen.center_offset_y + 15, NOX("EVENT DEBUG VIEW"));
7678 
7680  gr_set_font(FONT1);
7681  gr_get_string_size(&font_width, &font_height, NOX("test"));
7682  y_max = gr_screen.center_offset_y + gr_screen.center_h - font_height - 5;
7683  y_index = gr_screen.center_offset_y + 45;
7684 
7685  k = scroll_offset;
7686  while (k < ED_count) {
7687  if (y_index > y_max)
7688  break;
7689 
7690  z = Event_debug_index[k];
7691  if (z & EVENT_DEBUG_EVENT) {
7692  z &= 0x7fff;
7693  sprintf(buf, NOX("%s%s (%s) %s%d %d"), (Mission_events[z].flags & MEF_CURRENT) ? NOX("* ") : "",
7694  Mission_events[z].name, Mission_events[z].result ? NOX("True") : NOX("False"),
7695  (Mission_events[z].chain_delay < 0) ? "" : NOX("x "),
7696  Mission_events[z].repeat_count, Mission_events[z].interval);
7697 
7698  } else {
7699  i = (z >> 16) * 3;
7700  buf[i] = 0;
7701  while (i--)
7702  buf[i] = ' ';
7703 
7704  strcat_s(buf, Sexp_nodes[z & 0x7fff].text);
7705  switch (Sexp_nodes[z & 0x7fff].value) {
7706  case SEXP_TRUE:
7707  strcat_s(buf, NOX(" (True)"));
7708  break;
7709 
7710  case SEXP_FALSE:
7711  strcat_s(buf, NOX(" (False)"));
7712  break;
7713 
7714  case SEXP_KNOWN_TRUE:
7715  strcat_s(buf, NOX(" (Always true)"));
7716  break;
7717 
7718  case SEXP_KNOWN_FALSE:
7719  strcat_s(buf, NOX(" (Always false)"));
7720  break;
7721 
7722  case SEXP_CANT_EVAL:
7723  strcat_s(buf, NOX(" (Can't eval)"));
7724  break;
7725 
7726  case SEXP_NAN:
7727  case SEXP_NAN_FOREVER:
7728  strcat_s(buf, NOX(" (Not a number)"));
7729  break;
7730  }
7731  }
7732 
7733  gr_printf_no_resize(gr_screen.center_offset_x + 10, y_index, buf);
7734  y_index += font_height;
7735  k++;
7736  }
7737 
7738  gr_flip();
7739 }
7740 
7741 #endif // NDEBUG
7742 
7743 #ifndef NDEBUG
7744 FILE * Time_fp;
7745 FILE * Texture_fp;
7746 
7750 
7751 void Time_model( int modelnum )
7752 {
7753 // mprintf(( "Timing ship '%s'\n", si->name ));
7754 
7755  vec3d eye_pos, model_pos;
7756  matrix eye_orient, model_orient;
7757 
7758  polymodel *pm = model_get( modelnum );
7759 
7760  int l = strlen(pm->filename);
7761  while( (l>0) ) {
7762  if ( (l == '/') || (l=='\\') || (l==':')) {
7763  l++;
7764  break;
7765  }
7766  l--;
7767  }
7768  char *pof_file = &pm->filename[l];
7769 
7770  int model_needs_splitting = 0;
7771 
7772  //fprintf( Texture_fp, "Model: %s\n", pof_file );
7773  int i;
7774  for (i=0; i<pm->n_textures; i++ ) {
7775  char filename[1024];
7776  ubyte pal[768];
7777  texture_map *tmap = &pm->maps[i];
7778 
7779  for(int j = 0; j < TM_NUM_TYPES; j++)
7780  {
7781  int bmp_num = tmap->textures[j].GetOriginalTexture();
7782  if ( bmp_num > -1 ) {
7783  bm_get_palette(bmp_num, pal, filename );
7784  int w,h;
7785  bm_get_info( bmp_num,&w, &h );
7786 
7787 
7788  if ( (w > 512) || (h > 512) ) {
7789  fprintf( Texture_fp, "%s\t%s\t%d\t%d\n", pof_file, filename, w, h );
7790  Tmap_num_too_big++;
7791  model_needs_splitting++;
7792  }
7793  } else {
7794  //fprintf( Texture_fp, "\tTexture %d is bogus\n", i );
7795  }
7796  }
7797  }
7798 
7799  if ( model_needs_splitting ) {
7800  Num_models_needing_splitting++;
7801  }
7802  eye_orient = model_orient = vmd_identity_matrix;
7803  eye_pos = model_pos = vmd_zero_vector;
7804 
7805  eye_pos.xyz.z = -pm->rad*2.0f;
7806 
7807  vec3d eye_to_model;
7808 
7809  vm_vec_sub( &eye_to_model, &model_pos, &eye_pos );
7810  vm_vector_2_matrix( &eye_orient, &eye_to_model, NULL, NULL );
7811 
7813 
7814  angles ta;
7815  ta.p = ta.b = ta.h = 0.0f;
7816  int framecount = 0;
7817 
7818  Tmap_npixels = 0;
7819 
7820  int bitmaps_used_this_frame, bitmaps_new_this_frame;
7821 
7822  bm_get_frame_usage(&bitmaps_used_this_frame,&bitmaps_new_this_frame);
7823 
7825 
7826  while( ta.h < PI2 ) {
7827 
7828  matrix m1;
7829  vm_angles_2_matrix(&m1, &ta );
7830  vm_matrix_x_matrix( &model_orient, &vmd_identity_matrix, &m1 );
7831 
7832  gr_reset_clip();
7833 // gr_clear();
7834 
7835  g3_start_frame(1);
7836 
7837  //WMC - I think I can set this to VIEWER_ZOOM_DEFAULT.
7838  //If it's not appropriate, use cam_get_current()
7839  g3_set_view_matrix( &eye_pos, &eye_orient, VIEWER_ZOOM_DEFAULT );
7840 
7841  model_clear_instance( modelnum );
7842 
7843  model_render_params render_info;
7844  render_info.set_detail_level_lock(0);
7845  model_set_detail_level(0); // use highest detail level
7846  model_render_immediate( &render_info, modelnum, &model_orient, &model_pos ); //|MR_NO_POLYS );
7847 
7848  g3_end_frame();
7849 // gr_flip();
7850 
7851  framecount++;
7852  ta.h += 0.1f;
7853 
7854  int k = key_inkey();
7855  if ( k == KEY_ESC ) {
7856  exit(1);
7857  }
7858  }
7859 
7861 
7862  bm_get_frame_usage(&bitmaps_used_this_frame,&bitmaps_new_this_frame);
7863 
7864  modelstats_num_polys /= framecount;
7865  modelstats_num_verts /= framecount;
7866 
7867  Tmap_npixels /=framecount;
7868 
7869 
7870  mprintf(( "'%s' is %.2f FPS\n", pof_file, i2fl(framecount)/f2fl(t2-t1) ));
7871  fprintf( Time_fp, "\"%s\"\t%.0f\t%d\t%d\t%d\t%d\n", pof_file, i2fl(framecount)/f2fl(t2-t1), bitmaps_used_this_frame, modelstats_num_polys, modelstats_num_verts, Tmap_npixels );
7872 }
7873 
7874 int Time_models = 0;
7875 DCF_BOOL( time_models, Time_models )
7876 
7878 {
7879 
7880 
7881  if ( !Time_models ) return;
7882 
7883  mprintf(( "Timing models!\n" ));
7884 
7885  int i;
7886 
7887  ubyte model_used[MAX_POLYGON_MODELS];
7888  int model_id[MAX_POLYGON_MODELS];
7889  for (i=0; i<MAX_POLYGON_MODELS; i++ ) {
7890  model_used[i] = 0;
7891  }
7892 
7893  // Load them all
7894  for (auto sip = Ship_info.begin(); sip != Ship_info.end(); ++sip ) {
7895  sip->model_num = model_load(sip->pof_file, 0, NULL);
7896 
7897  model_used[sip->model_num % MAX_POLYGON_MODELS]++;
7898  model_id[sip->model_num % MAX_POLYGON_MODELS] = sip->model_num;
7899  }
7900 
7901  Texture_fp = fopen( NOX("ShipTextures.txt"), "wt" );
7902  if ( !Texture_fp ) return;
7903 
7904  Time_fp = fopen( NOX("ShipTimings.txt"), "wt" );
7905  if ( !Time_fp ) return;
7906 
7907  fprintf( Time_fp, "Name\tFPS\tTRAM\tPolys\tVerts\tPixels\n" );
7908 // fprintf( Time_fp, "FPS\tTRAM\tPolys\tVerts\tPixels\n" );
7909 
7910  for (i=0; i<MAX_POLYGON_MODELS; i++ ) {
7911  if ( model_used[i] ) {
7912  Time_model( model_id[i] );
7913  }
7914  }
7915 
7916  fprintf( Texture_fp, "Number too big: %d\n", Tmap_num_too_big );
7917  fprintf( Texture_fp, "Number of models needing splitting: %d\n", Num_models_needing_splitting );
7918 
7919  fclose(Time_fp);
7920  fclose(Texture_fp);
7921 
7922  exit(1);
7923 }
7924 #endif
7925 
7926 // Call this function when you want to inform the player that a feature is disabled in this build
7928 {
7929  popup(PF_USE_AFFIRMATIVE_ICON|PF_BODY_BIG, 1, POPUP_OK, XSTR( "Sorry, the requested feature is currently disabled in this build", 1621));
7930 }
7931 
7932 // format the specified time (fixed point) into a nice string
7933 void game_format_time(fix m_time,char *time_str)
7934 {
7935  float mtime;
7936  int hours,minutes,seconds;
7937  char tmp[10];
7938 
7939  mtime = f2fl(m_time);
7940 
7941  // get the hours, minutes and seconds
7942  hours = (int)(mtime / 3600.0f);
7943  if(hours > 0){
7944  mtime -= (3600.0f * (float)hours);
7945  }
7946  seconds = (int)mtime%60;
7947  minutes = (int)mtime/60;
7948 
7949  // print the hour if necessary
7950  if(hours > 0){
7951  sprintf(time_str,XSTR( "%d:", 201),hours);
7952  // if there are less than 10 minutes, print a leading 0
7953  if(minutes < 10){
7954  strcpy_s(tmp,NOX("0"));
7955  strcat(time_str,tmp);
7956  }
7957  }
7958 
7959  // print the minutes
7960  if(hours){
7961  sprintf(tmp,XSTR( "%d:", 201),minutes);
7962  strcat(time_str,tmp);
7963  } else {
7964  sprintf(time_str,XSTR( "%d:", 201),minutes);
7965  }
7966 
7967  // print the seconds
7968  if(seconds < 10){
7969  strcpy_s(tmp,NOX("0"));
7970  strcat(time_str,tmp);
7971  }
7972  sprintf(tmp,"%d",seconds);
7973  strcat(time_str,tmp);
7974 }
7975 
7976 // Stuff version string in *str.
7977 void get_version_string(char *str, int max_size)
7978 {
7979 //XSTR:OFF
7980  Assert( max_size > 6 );
7981 
7982  #if FS_VERSION_REVIS == 0
7983  sprintf(str, "FreeSpace 2 Open v%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD);
7984  #else
7985  sprintf(str, "FreeSpace 2 Open v%i.%i.%i.%i", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD, FS_VERSION_REVIS);
7986  #endif
7987 
7988 #ifndef NDEBUG
7989  strcat_s( str, max_size, " Debug" );
7990 #endif
7991 
7992  // Lets get some more info in here
7993  switch(gr_screen.mode)
7994  {
7995  case GR_OPENGL:
7996  strcat_s( str, max_size, " OpenGL" );
7997  break;
7998  }
7999 
8000  if (Cmdline_nohtl)
8001  strcat_s( str, max_size, " non-HT&L" );
8002 
8003  // if a custom identifier exists, put it at the very end
8004  #ifdef FS_VERSION_IDENT
8005  strcat_s( str, max_size, " (" );
8006  strcat_s( str, max_size, FS_VERSION_IDENT );
8007  strcat_s( str, max_size, ")" );
8008  #endif
8009 }
8010 
8012 {
8013  sprintf(str,"v%d.%d", FS_VERSION_MAJOR, FS_VERSION_MINOR);
8014 }
8015 
8016 // ----------------------------------------------------------------
8017 //
8018 // Subspace Ambient Sound START
8019 //
8020 // ----------------------------------------------------------------
8021 
8022 static int Subspace_ambient_left_channel = -1;
8023 static int Subspace_ambient_right_channel = -1;
8024 
8025 //
8027 {
8028  if ( Subspace_ambient_left_channel < 0 ) {
8029  Subspace_ambient_left_channel = snd_play_looping(&Snds[SND_SUBSPACE_LEFT_CHANNEL], -1.0f);
8030  }
8031 
8032  if ( Subspace_ambient_right_channel < 0 ) {
8033  Subspace_ambient_right_channel = snd_play_looping(&Snds[SND_SUBSPACE_RIGHT_CHANNEL], 1.0f);
8034  }
8035 }
8036 
8038 {
8039  if ( Subspace_ambient_left_channel >= 0 ) {
8040  snd_stop(Subspace_ambient_left_channel);
8041  Subspace_ambient_left_channel = -1;
8042  }
8043 
8044  if ( Subspace_ambient_right_channel >= 0 ) {
8045  snd_stop(Subspace_ambient_right_channel);
8046  Subspace_ambient_right_channel = -1;
8047  }
8048 }
8049 
8050 // ----------------------------------------------------------------
8051 //
8052 // Subspace Ambient Sound END
8053 //
8054 // ----------------------------------------------------------------
8055 
8056 
8057 // ----------------------------------------------------------------
8058 //
8059 // CDROM detection code START
8060 //
8061 // ----------------------------------------------------------------
8062 
8063 #define CD_SIZE_72_MINUTE_MAX (697000000)
8064 
8066 {
8067 #ifdef _WIN32
8068  uint total = 0;
8069  char use_path[512] = "";
8070  char sub_path[512] = "";
8071  WIN32_FIND_DATA find;
8072  HANDLE find_handle;
8073 
8074  // recurse through all files and directories
8075  strcpy_s(use_path, path);
8076  strcat_s(use_path, "*.*");
8077  find_handle = FindFirstFile(use_path, &find);
8078 
8079  // bogus
8080  if(find_handle == INVALID_HANDLE_VALUE){
8081  return 0;
8082  }
8083 
8084  // whee
8085  do {
8086  // subdirectory. make sure to ignore . and ..
8087  if((find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && stricmp(find.cFileName, ".") && stricmp(find.cFileName, "..")){
8088  // subsearch
8089  strcpy_s(sub_path, path);
8090  strcat_s(sub_path, find.cFileName);
8091  strcat_s(sub_path, DIR_SEPARATOR_STR);
8092  total += game_get_cd_used_space(sub_path);
8093  } else {
8094  total += (uint)find.nFileSizeLow;
8095  }
8096  } while(FindNextFile(find_handle, &find));
8097 
8098  // close
8099  FindClose(find_handle);
8100 
8101  // total
8102  return total;
8103 #else
8104  if (path == NULL) {
8105  // bail
8106  mprintf(("NULL path passed to game_get_cd_used_space.\n"));
8107  return 0;
8108  }
8109 
8110  STUB_FUNCTION;
8111 
8112  return 0;
8113 #endif // _WIN32
8114 }
8115 
8116 
8117 // if volume_name is non-null, the CD name must match that
8118 int find_freespace_cd(char *volume_name)
8119 {
8120 #ifdef _WIN32
8121  char oldpath[MAX_PATH];
8122  char volume[256];
8123  int i;
8124  int cdrom_drive=-1;
8125  int volume_match = 0;
8126  _finddata_t find;
8127  int find_handle;
8128 
8129  GetCurrentDirectory(MAX_PATH-1, oldpath);
8130 
8131  for (i = 0; i < 26; i++)
8132  {
8133 //XSTR:OFF
8134  char path[]="d:\\";
8135 //XSTR:ON
8136 
8137  path[0] = (char)('A'+i);
8138  if (GetDriveType(path) == DRIVE_CDROM) {
8139  cdrom_drive = -3;
8140  if ( GetVolumeInformation(path, volume, 256, NULL, NULL, NULL, NULL, 0) == TRUE ) {
8141  nprintf(("CD", "CD volume: %s\n", volume));
8142 
8143  // check for any CD volume
8144  int volume1_present = 0;
8145  int volume2_present = 0;
8146  int volume3_present = 0;
8147 
8148  char full_check[512] = "";
8149 
8150  // look for setup.exe
8151  strcpy_s(full_check, path);
8152  strcat_s(full_check, "setup.exe");
8153  find_handle = _findfirst(full_check, &find);
8154  if(find_handle != -1){
8155  volume1_present = 1;
8156  _findclose(find_handle);
8157  }
8158 
8159  // look for intro.mve
8160  strcpy_s(full_check, path);
8161  strcat_s(full_check, "intro.mve");
8162  find_handle = _findfirst(full_check, &find);
8163  if(find_handle != -1){
8164  volume2_present = 1;
8165  _findclose(find_handle);
8166  }
8167 
8168  // look for endpart1.mve
8169  strcpy_s(full_check, path);
8170  strcat_s(full_check, "endpart1.mve");
8171  find_handle = _findfirst(full_check, &find);
8172  if(find_handle != -1){
8173  volume3_present = 1;
8174  _findclose(find_handle);
8175  }
8176 
8177  // see if we have the specific CD we're looking for
8178  if ( volume_name ) {
8179  // volume 1
8180  if ( !stricmp(volume_name, FS_CDROM_VOLUME_1) && volume1_present) {
8181  volume_match = 1;
8182  }
8183  // volume 2
8184  if ( !stricmp(volume_name, FS_CDROM_VOLUME_2) && volume2_present) {
8185  volume_match = 1;
8186  }
8187  // volume 3
8188  if ( !stricmp(volume_name, FS_CDROM_VOLUME_3) && volume3_present) {
8189  volume_match = 1;
8190  }
8191  } else {
8192  if ( volume1_present || volume2_present || volume3_present ) {
8193  volume_match = 1;
8194  }
8195  }
8196 
8197  // here's where we make sure that CD's 2 and 3 are not just ripped - check to make sure its capacity is > 697,000,000 bytes
8198  if ( volume_match ){
8199  // we don't care about CD1 though. let it be whatever size it wants, since the game will demand CD's 2 and 3 at the proper time
8200  if(volume2_present || volume3_present) {
8201  // first step - check to make sure its a cdrom
8202  if(GetDriveType(path) != DRIVE_CDROM){
8203  break;
8204  }
8205  // oem not on 80 min cds, so don't check tha size
8206  // check its size
8207  uint used_space = game_get_cd_used_space(path);
8208  if(used_space < CD_SIZE_72_MINUTE_MAX){
8209  break;
8210  }
8211  }
8212 
8213  cdrom_drive = i;
8214  break;
8215  }
8216  }
8217  }
8218  }
8219 
8220  SetCurrentDirectory(oldpath);
8221  return cdrom_drive;
8222 #else
8223 // STUB_FUNCTION;
8224 
8225  if (volume_name != NULL) {
8226  // volume specific checks
8227  STUB_FUNCTION;
8228  }
8229 
8230  return -1;
8231 #endif // _WIN32
8232 }
8233 
8234 int set_cdrom_path(int drive_num)
8235 {
8236  int rval;
8237 
8238  if (drive_num < 0) { //no CD
8239 // #ifndef NDEBUG
8240 // strcpy_s(CDROM_dir,"j:\\FreeSpaceCD\\"); //set directory
8241 // rval = 1;
8242 // #else
8243  memset(Game_CDROM_dir, 0, sizeof(Game_CDROM_dir));
8244  rval = 0;
8245 // #endif
8246  } else {
8247  sprintf(Game_CDROM_dir,NOX("%c:\\"), 'a' + drive_num ); //set directory
8248  rval = 1;
8249  }
8250 
8251  return rval;
8252 }
8253 
8255 {
8256  int i, rval;
8257 
8258  //scan for CD, etc.
8259  i = find_freespace_cd();
8260 
8261  rval = set_cdrom_path(i);
8262 
8263  return rval;
8264 }
8265 
8267 char Last_cd_label[256];
8268 
8270 {
8271 #ifdef _WIN32
8272  char label[256];
8273  int found;
8274  int changed = 0;
8275 
8276  if ( strlen(Game_CDROM_dir) == 0 ) { //-V805
8277  init_cdrom();
8278  }
8279 
8280  if ( strlen(Game_CDROM_dir) == 0 ) { //-V805
8281  return 0;
8282  }
8283 
8284  found = GetVolumeInformation(Game_CDROM_dir, label, 256, NULL, NULL, NULL, NULL, 0);
8285 
8286  if ( found != Last_cd_label_found ) {
8287  Last_cd_label_found = found;
8288  if ( found ) {
8289  mprintf(( "CD '%s' was inserted\n", label ));
8290  } else {
8291  mprintf(( "CD '%s' was removed\n", Last_cd_label ));
8292  }
8293  changed = 1;
8294  } else {
8295  if ( Last_cd_label_found ) {
8296  if ( !stricmp( Last_cd_label, label )) {
8297  //mprintf(( "CD didn't change\n" ));
8298  } else {
8299  mprintf(( "CD was changed from '%s' to '%s'\n", Last_cd_label, label ));
8300  changed = 1;
8301  }
8302  } else {
8303  // none found before, none found now.
8304  //mprintf(( "still no CD...\n" ));
8305  }
8306  }
8307 
8308  Last_cd_label_found = found;
8309  if ( found ) {
8310  strcpy_s( Last_cd_label, label );
8311  } else {
8312  strcpy_s( Last_cd_label, "" );
8313  }
8314 
8315  return changed;
8316 #else
8317  STUB_FUNCTION;
8318 
8319  return 0;
8320 #endif // _WIN32
8321 }
8322 
8323 // check if _any_ FreeSpace2 CDs are in the drive
8324 // return: 1 => CD now in drive
8325 // 0 => Could not find CD, they refuse to put it in the drive
8326 int game_do_cd_check(char *volume_name)
8327 {
8328 #if !defined(GAME_CD_CHECK)
8329  return 1;
8330 #else
8331  int cd_present = 0;
8332  int cd_drive_num;
8333 
8334  int num_attempts = 0;
8335  int refresh_files = 0;
8336  while(1) {
8337  int path_set_ok, popup_rval;
8338 
8339  cd_drive_num = find_freespace_cd(volume_name);
8340  path_set_ok = set_cdrom_path(cd_drive_num);
8341  if ( path_set_ok ) {
8342  cd_present = 1;
8343  if ( refresh_files ) {
8344  cfile_refresh();
8345  refresh_files = 0;
8346  }
8347  break;
8348  }
8349 
8350  // standalone mode
8351  if(Is_standalone){
8352  cd_present = 0;
8353  break;
8354  } else {
8355  // no CD found, so prompt user
8356  popup_rval = popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "FreeSpace 2 CD not found\n\nInsert a FreeSpace 2 CD to continue", 202));
8357  refresh_files = 1;
8358  if ( popup_rval != 1 ) {
8359  cd_present = 0;
8360  break;
8361  }
8362 
8363  if ( num_attempts++ > 5 ) {
8364  cd_present = 0;
8365  break;
8366  }
8367  }
8368  }
8369 
8370  return cd_present;
8371 #endif
8372 }
8373 
8374 // check if _any_ FreeSpace2 CDs are in the drive
8375 // return: 1 => CD now in drive
8376 // 0 => Could not find CD, they refuse to put it in the drive
8377 int game_do_cd_check_specific(char *volume_name, int cdnum)
8378 {
8379  int cd_present = 0;
8380  int cd_drive_num;
8381 
8382  int num_attempts = 0;
8383  int refresh_files = 0;
8384  while(1) {
8385  int path_set_ok, popup_rval;
8386 
8387  cd_drive_num = find_freespace_cd(volume_name);
8388  path_set_ok = set_cdrom_path(cd_drive_num);
8389  if ( path_set_ok ) {
8390  cd_present = 1;
8391  if ( refresh_files ) {
8392  cfile_refresh();
8393  refresh_files = 0;
8394  }
8395  break;
8396  }
8397 
8398  if(Is_standalone){
8399  cd_present = 0;
8400  break;
8401  } else {
8402  // no CD found, so prompt user
8403  popup_rval = popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR("Please insert CD %d", 1468), cdnum);
8404  refresh_files = 1;
8405  if ( popup_rval != 1 ) {
8406  cd_present = 0;
8407  break;
8408  }
8409 
8410  if ( num_attempts++ > 5 ) {
8411  cd_present = 0;
8412  break;
8413  }
8414  }
8415  }
8416 
8417  return cd_present;
8418 }
8419 
8420 // ----------------------------------------------------------------
8421 //
8422 // CDROM detection code END
8423 //
8424 // ----------------------------------------------------------------
8425 
8426 
8427 // ----------------------------------------------------------------
8428 // Language autodetection stuff
8429 //
8430 
8431 // default setting is "-1" to use registry setting with English as fall back
8432 // DO NOT change that default setting here or something uncouth might happen
8433 // in the localization code
8435 {
8436  uint file_checksum;
8437  int idx;
8438  char first_font[MAX_FILENAME_LEN];
8439 
8440  // if the reg is set then let lcl_init() figure out what to do
8441  if (os_config_read_string( NULL, NOX("Language"), NULL ) != NULL)
8442  return -1;
8443 
8444  // try and open the file to verify
8445  gr_stuff_first_font(first_font, sizeof(first_font));
8446  CFILE *detect = cfopen(first_font, "rb");
8447 
8448  // will use default setting if something went wrong
8449  if (!detect)
8450  return -1;
8451 
8452  // get the long checksum of the file
8453  file_checksum = 0;
8454  cfseek(detect, 0, SEEK_SET);
8455  cf_chksum_long(detect, &file_checksum);
8456  cfclose(detect);
8457  detect = NULL;
8458 
8459  // now compare the checksum/filesize against known #'s
8460  for (idx=0; idx < NUM_BUILTIN_LANGUAGES; idx++) {
8461  if (Lcl_builtin_languages[idx].checksum == (int)file_checksum) {
8462  mprintf(( "AutoLang: Language auto-detection successful...\n" ));
8463  return idx;
8464  }
8465  }
8466 
8467  // notify if a match was not found, include detected checksum
8468  mprintf(( "ERROR: Unknown Language Checksum: %i\n", (int)file_checksum ));
8469  mprintf(( "Using default language settings...\n" ));
8470 
8471  return -1;
8472 }
8473 
8474 //
8475 // Eng Auto Lang stuff
8476 // ----------------------------------------------------------------
8477 
8478 
8479 // ----------------------------------------------------------------
8480 // SHIPS TBL VERIFICATION STUFF
8481 //
8482 
8483 // checksums, just keep a list of all valid ones, if it matches any of them, keep it
8484 #define NUM_SHIPS_TBL_CHECKSUMS 1
8485 
8487 // -1022810006, // 1.0 FULL
8488  -1254285366 // 1.2 FULL (German)
8489 };
8490 
8492 {
8493  /*
8494 #ifdef NDEBUG
8495  Game_ships_tbl_valid = 1;
8496 #else
8497  */
8498  uint file_checksum;
8499  int idx;
8500 
8501  // detect if the packfile exists
8502  CFILE *detect = cfopen("ships.tbl", "rb");
8503  Game_ships_tbl_valid = 0;
8504 
8505  // not mission-disk
8506  if(!detect){
8507  Game_ships_tbl_valid = 0;
8508  return;
8509  }
8510 
8511  // get the long checksum of the file
8512  file_checksum = 0;
8513  cfseek(detect, 0, SEEK_SET);
8514  cf_chksum_long(detect, &file_checksum);
8515  cfclose(detect);
8516  detect = NULL;
8517 
8518  // now compare the checksum/filesize against known #'s
8519  for(idx=0; idx<NUM_SHIPS_TBL_CHECKSUMS; idx++){
8520  if(Game_ships_tbl_checksums[idx] == (int)file_checksum){
8521  Game_ships_tbl_valid = 1;
8522  return;
8523  }
8524  }
8525 // #endif
8526 }
8527 
8528 DCF(shipspew, "display the checksum for the current ships.tbl")
8529 {
8530  uint file_checksum;
8531  CFILE *detect = cfopen("ships.tbl", "rb");
8532  // get the long checksum of the file
8533  file_checksum = 0;
8534  cfseek(detect, 0, SEEK_SET);
8535  cf_chksum_long(detect, &file_checksum);
8536  cfclose(detect);
8537 
8538  dc_printf("%d", file_checksum);
8539 }
8540 
8541 // ----------------------------------------------------------------
8542 // WEAPONS TBL VERIFICATION STUFF
8543 //
8544 
8545 // checksums, just keep a list of all valid ones, if it matches any of them, keep it
8546 #define NUM_WEAPONS_TBL_CHECKSUMS 1
8547 
8549 // 399297860, // 1.0 FULL
8550  -553984927 // 1.2 FULL (german)
8551 };
8552 
8554 {
8555  /*
8556 #ifdef NDEBUG
8557  Game_weapons_tbl_valid = 1;
8558 #else
8559  */
8560  uint file_checksum;
8561  int idx;
8562 
8563  // detect if the packfile exists
8564  CFILE *detect = cfopen("weapons.tbl", "rb");
8565  Game_weapons_tbl_valid = 0;
8566 
8567  // not mission-disk
8568  if(!detect){
8569  Game_weapons_tbl_valid = 0;
8570  return;
8571  }
8572 
8573  // get the long checksum of the file
8574  file_checksum = 0;
8575  cfseek(detect, 0, SEEK_SET);
8576  cf_chksum_long(detect, &file_checksum);
8577  cfclose(detect);
8578  detect = NULL;
8579 
8580  // now compare the checksum/filesize against known #'s
8581  for(idx=0; idx<NUM_WEAPONS_TBL_CHECKSUMS; idx++){
8582  if(Game_weapons_tbl_checksums[idx] == (int)file_checksum){
8583  Game_weapons_tbl_valid = 1;
8584  return;
8585  }
8586  }
8587 // #endif
8588 }
8589 
8590 DCF(wepspew, "display the checksum for the current weapons.tbl")
8591 {
8592  uint file_checksum;
8593  CFILE *detect = cfopen("weapons.tbl", "rb");
8594  // get the long checksum of the file
8595  file_checksum = 0;
8596  cfseek(detect, 0, SEEK_SET);
8597  cf_chksum_long(detect, &file_checksum);
8598  cfclose(detect);
8599 
8600  dc_printf("%d", file_checksum);
8601 }
8602 
8603 // if the game is running using hacked data
8604 static bool Hacked_data_check_ready = false;
8605 static bool Hacked_data = false;
8606 
8608 {
8609  int rc = 0;
8610 
8611  if (Hacked_data) {
8612  return 1;
8613  }
8614 
8615 
8616  if ( Om_tracker_flag && !(Hacked_data_check_ready) ) {
8617  // this may fail the first time or two
8618  if ( (rc = fs2netd_update_valid_tables()) != -1 ) {
8619  Hacked_data = (rc != 0);
8620  Hacked_data_check_ready = true;
8621  }
8622  }
8623 
8624  // LAN game, only check if weapon and ship are valid since we can't or don't
8625  // want to validate against PXO server
8626  if ( !Om_tracker_flag && !(Game_weapons_tbl_valid && Game_ships_tbl_valid) ) {
8627  Hacked_data = true;
8628  }
8629 
8630 
8631  return (int)Hacked_data;
8632 }
8633 
8634 
8635 //#define MAX_SPLASHSCREENS 64
8636 //char Splash_screens[MAX_SPLASHSCREENS][MAX_FILENAME_LEN];
8637 
8638 
8640 {
8641 /* _finddata_t find;
8642  long find_handle;
8643  char current_dir[256];
8644 
8645  //Get the find string
8646  _getcwd(current_dir, 256);
8647  strcat_s(current_dir, DIR_SEPARATOR_STR);
8648  strcat_s(current_dir, "*.pcx");
8649 
8650  //Let the search begin!
8651  find_handle = _findfirst(current_dir, &find);
8652  int i = 0;
8653  if(find_handle != -1)
8654  {
8655  char *p;
8656 
8657  do {
8658  if(!(find.attrib & _A_SUBDIR) && (strlen(find.name) < MAX_FILENAME_LEN)) {
8659  p = strchr( find.name, '.' );
8660  if(p) {
8661  *p = '\0';
8662  }
8663 
8664  if(stricmp(find.name, Game_logo_screen_fname[gr_screen.res])
8665  && stricmp(find.name, Game_title_screen_fname[gr_screen.res]))
8666  {
8667  strcpy_s(Splash_screens[i], find.name);
8668  i++;
8669  }
8670 
8671  if(i == MAX_SPLASHSCREENS) {
8672  break;
8673  }
8674  }
8675  } while(!_findnext(find_handle, &find));
8676  }
8677 
8678  if(i) {
8679  srand(time(NULL));
8680  title_bitmap = bm_load(Splash_screens[rand() % i]);
8681 
8682  } else {
8683  title_bitmap = bm_load(Game_title_screen_fname[gr_screen.res]);
8684  }
8685 
8686  if (title_bitmap == -1 && title_logo == -1) {
8687 // return;
8688  }
8689  */
8690 
8691  bool globalhook_override = Script_system.IsOverride(Script_splashhook);
8692  bool condhook_override = Script_system.IsConditionOverride(CHA_SPLASHSCREEN);
8693  mprintf(("SCRIPTING: Splash screen overrides checked\n"));
8694  if(!globalhook_override && !condhook_override)
8695  {
8696  Game_title_logo = bm_load(Game_logo_screen_fname[gr_screen.res]);
8697  Game_title_bitmap = bm_load(Game_title_screen_fname[gr_screen.res]);
8698 
8699  if (Game_title_bitmap != -1)
8700  {
8701  // set
8702  gr_set_bitmap(Game_title_bitmap);
8703 
8704  // get bitmap's width and height
8705  int width, height;
8706  bm_get_info(Game_title_bitmap, &width, &height);
8707 
8708  // set the screen scale to the bitmap's dimensions
8709  gr_set_screen_scale(width, height);
8710 
8711  // draw it in the center of the screen
8713 
8714  if (Game_title_logo != -1)
8715  {
8716  gr_set_bitmap(Game_title_logo);
8717 
8718  gr_bitmap(0, 0, GR_RESIZE_MENU);
8719 
8720  }
8721 
8723  }
8724  }
8725 
8726  if(!condhook_override)
8728 
8729  mprintf(("SCRIPTING: Splash hook has been run\n"));
8730 
8731  if(!globalhook_override || condhook_override)
8733 
8734  mprintf(("SCRIPTING: Splash screen conditional hook has been run\n"));
8735 
8736  // flip
8737  gr_flip();
8738 }
8739 
8741 {
8742  if (Game_title_bitmap != -1) {
8743  bm_release(Game_title_bitmap);
8744  Game_title_bitmap = -1;
8745  }
8746 
8747  if (Game_title_logo != -1) {
8748  bm_release(Game_title_logo);
8749  Game_title_bitmap = -1;
8750  }
8751 }
8752 
8753 // return true if the game is running with "low memory", which is less than 48MB
8755 {
8756  if (Use_low_mem == 0) {
8757  return false;
8758  } else {
8759  return true;
8760  }
8761 }
8762 
8763 // place calls here that need to take effect immediately when the game is
8764 // minimized. Called from osapi.cpp
8766 {
8767  // Protection against flipping out -- Kazan
8768  if (!GameState_Stack_Valid())
8769  return;
8770 
8771  if (!(Game_mode & GM_MULTIPLAYER)){
8772  switch ( gameseq_get_state() )
8773  {
8774  case GS_STATE_MAIN_MENU:
8775  main_hall_pause(); // not an instant shutoff of misc anims and sounds
8776  break;
8777 
8778  case GS_STATE_BRIEFING:
8779  brief_pause();
8780  break;
8781 
8782  case GS_STATE_DEBRIEF:
8783  debrief_pause();
8784  break;
8785 
8786  case GS_STATE_CMD_BRIEF:
8787  cmd_brief_pause();
8788  break;
8789 
8790  case GS_STATE_RED_ALERT:
8792  break;
8793 
8794  // anything that would leave the ambient mainhall sound going
8795  case GS_STATE_TECH_MENU:
8798  main_hall_stop_music(true); // not an instant shutoff
8799  break;
8800 
8801  // things that would get music except if they are called while in-mission
8802  case GS_STATE_OPTIONS_MENU:
8803  case GS_STATE_HUD_CONFIG:
8804  if ( !(Game_mode & GM_IN_MISSION) ) {
8806  main_hall_stop_music(true); // not an instant shutoff
8807  }
8808  break;
8809 
8810  // only has the ambient sound, no music
8813  break;
8814 
8815  // pause_init is a special case and we don't unpause it ourselves
8816  case GS_STATE_GAME_PLAY:
8817  if ( (!popup_active()) && (!popupdead_is_active()) )
8818  pause_init();
8819  break;
8820 
8823  break;
8824 
8825  default:
8827  }
8828  }
8829 }
8830 
8831 // calls to be executed when the game is restored from minimized or inactive state
8833 {
8834  if (!GameState_Stack_Valid())
8835  return;
8836 
8837  // automatically recover from everything but an in-mission pause
8838  if (!(Game_mode & GM_MULTIPLAYER)) {
8839  switch ( gameseq_get_state() )
8840  {
8841  case GS_STATE_MAIN_MENU:
8843  break;
8844 
8845  case GS_STATE_BRIEFING:
8846  brief_unpause();
8847  break;
8848 
8849  case GS_STATE_DEBRIEF:
8850  debrief_unpause();
8851  break;
8852 
8853  case GS_STATE_CMD_BRIEF:
8855  break;
8856 
8857  case GS_STATE_RED_ALERT:
8859  break;
8860 
8861  // anything that would leave the ambient mainhall sound going
8862  case GS_STATE_TECH_MENU:
8865  main_hall_start_music(); // not an instant shutoff
8866  break;
8867 
8868  // things that would get music except if they are called while in-mission
8869  case GS_STATE_OPTIONS_MENU:
8870  case GS_STATE_HUD_CONFIG:
8871  if ( !(Game_mode & GM_IN_MISSION) ) {
8873  main_hall_start_music(); // not an instant shutoff
8874  }
8875  break;
8876 
8877  // only has the ambient sound, no music
8880  break;
8881 
8882  // if in a game then do nothing, pause_init() should have been called
8883  // and will get cleaned up elsewhere
8884  case GS_STATE_GAME_PLAY:
8885  break;
8886 
8887  // ditto for if we explicitly paused the game and then minimized it
8888  case GS_STATE_GAME_PAUSED:
8889  break;
8890 
8893  break;
8894 
8895  default:
8897  }
8898  }
8899 }
int fs2netd_update_valid_tables()
#define __UNUSED
Definition: clang.h:23
void player_maybe_play_all_alone_msg()
#define NETINFO_FLAG_WARPING_OUT
Definition: multi.h:618
int game_actually_playing()
Definition: freespace.cpp:4156
#define BMP_FLAG_RENDER_TARGET_DYNAMIC
Texture is a dynamic type (animation)
Definition: bmpman.h:67
#define GM_DEAD_DIED
Definition: systemvars.h:20
void gr_rect(int x, int y, int w, int h, int resize_mode)
Definition: 2d.cpp:2068
void shockwave_level_close()
Definition: shockwave.cpp:672
void red_alert_voice_pause()
Definition: redalert.cpp:201
Definition: sound.cpp:39
void mod_table_init()
Definition: mod_table.cpp:345
char * Cmdline_connect_addr
Definition: cmdline.cpp:263
void obj_snd_level_close()
Definition: objectsnd.cpp:864
GLuint64EXT * result
Definition: Glext.h:10775
void player_tips_close()
int game_cd_changed()
Definition: freespace.cpp:8269
void player_init()
void game_do_state(int state)
Definition: freespace.cpp:6446
void unload_animating_pointer()
Definition: freespace.cpp:7452
#define gr_scene_texture_end
Definition: 2d.h:911
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
#define MB_OKCANCEL
Definition: config.h:180
int Keep_mouse_centered
Definition: mouse.cpp:53
float frametimes[FRAME_FILTER]
Definition: freespace.cpp:245
pilotfile Pilot
Definition: pilotfile.cpp:7
int Tmap_num_too_big
Definition: freespace.cpp:7748
#define MOVIE_PRE_GAME
Definition: missionparse.h:119
void observer_get_eye(vec3d *eye_pos, matrix *eye_orient, object *obj)
Definition: observer.cpp:99
void game_tst_frame()
Definition: freespace.cpp:2695
#define MAX_POLYGON_MODELS
Definition: globals.h:80
uint FreeSpace_total_ram
Definition: freespace.cpp:508
bsp_info * submodel
Definition: model.h:764
void red_alert_do_frame(float frametime)
Definition: redalert.cpp:381
int timestamp(int delta_ms)
Definition: timer.cpp:226
void game_format_time(fix m_time, char *time_str)
Definition: freespace.cpp:7933
void medal_main_close()
Definition: medals.cpp:736
void gr_close()
Definition: 2d.cpp:637
#define KEY_F4
Definition: key.h:146
void radar_mission_init()
Definition: radarsetup.cpp:338
struct screen3d::@234::@236 xyw
fix Frametime
Definition: systemvars.cpp:21
#define MULTIPLAYER_CLIENT
Definition: multi.h:132
script_hook Script_hudhook
Definition: scripting.cpp:26
#define CFILE_NORMAL
Definition: cfile.h:89
void snd_stop_all()
Definition: sound.cpp:905
void * HWND
Definition: config.h:104
bool GameState_Stack_Valid()
#define KEY_PADENTER
Definition: key.h:171
vci Viewer_chase_info
Definition: systemvars.cpp:56
int Game_ships_tbl_checksums[NUM_SHIPS_TBL_CHECKSUMS]
Definition: freespace.cpp:8486
int i
Definition: multi_pxo.cpp:466
int Framecount
Definition: systemvars.cpp:22
#define COUNT_ESTIMATE
Definition: freespace.cpp:1105
fix Missiontime
Definition: systemvars.cpp:19
void game_flash_diminish(float frametime)
Definition: freespace.cpp:795
void shield_hit_init()
Definition: shield.cpp:131
#define vm_free(ptr)
Definition: pstypes.h:548
int tst_mode
Definition: freespace.cpp:2656
#define ABURN_DECAY_TIME
Definition: afterburner.h:16
void mouse_set_pos(int xpos, int ypos)
Definition: mouse.cpp:604
void ship_select_init()
int n_textures
Definition: model.h:761
camid cam_create(char *n_name, vec3d *n_pos, vec3d *n_norm, object *n_object, int n_object_host_submodel)
Definition: camera.cpp:888
void message_mission_close()
uint os_config_read_uint(const char *section, const char *name, uint default_value)
Definition: osregistry.cpp:372
float p
Definition: pstypes.h:111
void game_get_framerate()
Definition: freespace.cpp:2102
void player_display_padlock_view()
void mission_parse_close()
subspace ambient sound (right channel) (looped)
Definition: gamesnd.h:141
float Start_time
Definition: freespace.cpp:2079
void obj_snd_do_frame()
Definition: objectsnd.cpp:457
model_subsystem * system_info
Definition: ship.h:314
#define SEXP_TRUE
Definition: sexp.h:918
#define gr_clear
Definition: 2d.h:749
void snd_update_listener(vec3d *pos, vec3d *vel, matrix *orient)
Definition: sound.cpp:1113
void species_init()
weapon Weapons[MAX_WEAPONS]
Definition: weapons.cpp:78
char Multi_tracker_squad_name[MULTI_TRACKER_STRING_LEN+1]
Definition: multi.cpp:145
#define timestamp_elapsed_safe(_a, _b)
Definition: timer.h:114
char Processing_filename[MAX_PATH_LEN]
Definition: systemvars.cpp:66
float Training_context_distance
Definition: sexp.cpp:840
#define NETPLAYER_STATE_IN_MISSION
Definition: multi.h:686
bool gr_init(int d_mode, int d_width, int d_height, int d_depth)
Definition: 2d.cpp:909
#define SIF2_SHOW_SHIP_MODEL
Definition: ship.h:921
void multi_standalone_wait_init()
Definition: multi.cpp:1644
void campaign_room_init()
Definition: readyroom.cpp:1635
#define MIN(a, b)
Definition: pstypes.h:296
void bm_print_bitmaps()
(DEBUG) Prints all loaded bitmaps to an outwindow
Definition: bmpman.cpp:2586
void game_loading_callback_close()
Definition: freespace.cpp:1249
float Proj_fov
Definition: 3dsetup.cpp:31
void radar_frame_init()
Definition: radarsetup.cpp:365
void hud_stop_looped_engine_sounds()
Called when the game decides to stop all looping sounds.
Definition: hud.cpp:1816
void fsspeech_stop()
Definition: fsspeech.h:45
void cfile_spew_pack_file_crcs()
void mission_eval_goals()
void fiction_viewer_init()
void batch_reset()
Definition: grbatch.cpp:1159
void init_semirand()
Initialize Semirand array. Doesn't have to be called.
Definition: staticrand.cpp:22
void barracks_init()
Definition: barracks.cpp:1332
ai_info * Player_ai
Definition: ai.cpp:24
int Test_begin
Definition: freespace.cpp:295
int gameseq_process_events()
int team
Definition: ship.h:606
void mflash_level_close()
int Cmdline_old_collision_sys
Definition: cmdline.cpp:489
#define MAX_FRAMETIME
Definition: freespace.cpp:4545
float cur_flash_intensity
Definition: freespace.cpp:216
void ship_assign_sound_all()
Definition: ship.cpp:14263
void model_find_world_point(vec3d *outpnt, vec3d *mpnt, int model_num, int submodel_num, const matrix *objorient, const vec3d *objpos)
Definition: modelread.cpp:4099
sound_env Game_sound_env
Definition: freespace.cpp:523
int key_inkey()
Definition: key.cpp:424
void verify_weapons_tbl()
Definition: freespace.cpp:8553
#define SUPERNOVA_CUT_TIME
Definition: supernova.h:24
int Num_mission_events
float max_flash_intensity
Definition: freespace.cpp:215
#define KEY_DOWN
Definition: key.h:180
int Players_target_timestamp
Definition: sexp.cpp:856
#define SEXP_ATOM_OPERATOR
Definition: sexp.h:911
#define CAMPAIGN_MOVIE_PRE_MISSION
float vm_vec_mag_quick(const vec3d *v)
Definition: vecmat.cpp:371
matrix * vm_matrix_x_matrix(matrix *dest, const matrix *src0, const matrix *src1)
Definition: vecmat.cpp:1006
int flags
Definition: player.h:104
#define PCM_WARPOUT_STAGE1
Definition: player.h:59
#define CHA_ONSTATEEND
Definition: scripting.h:63
char name[NAME_LENGTH]
Definition: weapon.h:322
void joy_ff_stop_effects()
Definition: joy-unix.cpp:640
int joy_down(int btn)
Definition: joy-unix.cpp:93
float Cutscene_bars_progress
Definition: systemvars.cpp:36
int Log_debug_output_to_file
Definition: outwnd.cpp:97
int Show_viewing_from_self
Definition: freespace.cpp:2983
int os_foreground()
Definition: osapi.cpp:202
int Time_models
Definition: freespace.cpp:7874
#define PHYSICS_VIEWER_RIGHT
Definition: physics.h:155
int Game_mode
Definition: systemvars.cpp:24
SCP_string profile_output
Definition: profiling.cpp:42
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
#define F1_0
Definition: fix.h:15
void ship_model_stop(object *objp)
Definition: ship.cpp:13059
#define LOGFILE_EVENT_LOG
Definition: generic_log.h:19
void vm_vec_scale_add(vec3d *dest, const vec3d *src1, const vec3d *src2, float k)
Definition: vecmat.cpp:266
void multi_join_game_do_frame()
Definition: multiui.cpp:994
int ai_paused
Definition: object.cpp:677
void gameseq_init()
void gr_flip()
Definition: 2d.cpp:2113
int Cmdline_3dwarp
Definition: cmdline.cpp:377
#define MISSION_FLAG_FULLNEB
Definition: missionparse.h:70
#define PLAYER_DIED_POPUP_WAIT
Definition: freespace.cpp:336
int saved_viewer_mode
Definition: player.h:135
void scoring_level_init(scoring_struct *scp)
Definition: scoring.cpp:223
void game_whack_apply(float x, float y)
Definition: freespace.cpp:3065
void shipfx_flash_do_frame(float frametime)
Definition: shipfx.cpp:1331
void flak_level_close()
Definition: flak.cpp:30
void multi_join_game_init()
Definition: multiui.cpp:817
camid Main_camera
Definition: camera.cpp:25
int find_freespace_cd(char *volume_name)
Definition: freespace.cpp:8118
float frand_range(float min, float max)
Return a floating point number in the range min..max.
Definition: floating.cpp:50
void multi_ingame_select_do()
void outwnd_init(int display_under_freespace_window)
Definition: outwnd.cpp:1165
void gamesnd_parse_soundstbl()
Definition: gamesnd.cpp:1116
#define BAIL()
Definition: freespace.cpp:6846
polymodel * model_get(int model_num)
Definition: modelread.cpp:3134
void particle_close()
Definition: particle.cpp:83
weapon_info Weapon_info[MAX_WEAPON_TYPES]
Definition: weapons.cpp:79
#define KEY_PAGEDOWN
Definition: key.h:178
void mflash_game_init()
void fs2netd_close()
void ship_render_show_ship_cockpit(object *objp)
Definition: ship.cpp:7322
int Scripting_didnt_draw_hud
Definition: freespace.cpp:3332
void debrief_pause()
void obj_render(object *obj)
Definition: object.cpp:1604
int sound_env_set(sound_env *se)
Definition: sound.cpp:1357
GLuint counter
Definition: Glext.h:10587
void RemHookVar(char *name)
Definition: scripting.cpp:749
#define GR_RESIZE_MENU
Definition: 2d.h:684
net_player * Net_player
Definition: multi.cpp:94
#define MOUSE_LEFT_BUTTON
Definition: mouse.h:43
bool Cmdline_no_unfocus_pause
Definition: cmdline.cpp:513
SCP_vector< game_snd > Snds
Definition: gamesnd.cpp:19
void popupdead_start()
Definition: popupdead.cpp:129
void campaign_room_do_frame(float frametime)
Definition: readyroom.cpp:1724
void game_show_standalone_framerate()
Definition: freespace.cpp:2399
void afterburner_stop_sounds()
int Multi_pause_status
Definition: multi_pause.cpp:38
void message_maybe_distort()
void render_shields()
Definition: shield.cpp:486
float vm_vec_mag(const vec3d *v)
Definition: vecmat.cpp:325
#define gr_end_view_matrix
Definition: 2d.h:896
#define TIMESTAMP_FREQUENCY
Definition: timer.h:63
void joy_close()
Definition: joy-unix.cpp:53
void gamesnd_unload_gameplay_sounds()
Definition: gamesnd.cpp:548
int TotalRam
Definition: windebug.cpp:1580
int turret_gun_sobj
Definition: model.h:193
#define POPUPDEAD_DO_RESPAWN
Definition: popupdead.h:16
float get_shake(float intensity, int decay_time, int max_decay_time)
Definition: freespace.cpp:3085
void lock_time_compression(bool is_locked)
Definition: freespace.cpp:4634
#define KEY_PAD8
Definition: key.h:164
void batch_render_close()
Definition: grbatch.cpp:1165
void mission_campaign_clear()
int ambient_light_level
Definition: missionparse.h:152
void game_reset_view_clip()
Definition: freespace.cpp:2580
void game_reset_time()
Definition: freespace.cpp:4558
bool Env_cubemap_drawn
Definition: freespace.cpp:202
void clip_frame_view()
Definition: freespace.cpp:4290
uint Mem_starttime_pagefile
Definition: freespace.cpp:2099
GLsizei const GLfloat * value
Definition: Glext.h:5646
void lab_do_frame(float frametime)
Definition: lab.cpp:2456
float Game_flash_blue
Definition: freespace.cpp:513
int mode
Definition: 2d.h:371
#define NETINFO_FLAG_DO_NETWORKING
Definition: multi.h:610
GLuint index
Definition: Glext.h:5608
bool save_savefile()
Definition: csg.cpp:1524
void standalone_main_init()
Definition: multi.cpp:1428
#define MAX_PATH
CFILE * Multi_chat_stream
Definition: multi.cpp:111
#define VM_WARP_CHASE
Definition: systemvars.h:37
int multi_ignore_controls(int key)
Definition: multiutil.cpp:2845
void physics_set_viewer(physics_info *p, int dir)
Definition: physics.cpp:135
physics_info phys_info
Definition: object.h:157
player * m_player
Definition: multi.h:459
void multi_pxo_help_init()
Definition: multi_pxo.cpp:4807
int frame_int
Definition: freespace.cpp:244
matrix * vm_angles_2_matrix(matrix *m, const angles *a)
Definition: vecmat.cpp:752
float Timing_flip
Definition: freespace.cpp:2087
int Show_net_stats
Definition: freespace.cpp:297
int security
Definition: multi.h:499
int pause_get_type()
void game_show_framerate()
Definition: freespace.cpp:2130
#define MAX_SHIPS
Definition: globals.h:37
bool frame_rate_display
void gr_unset_cursor_bitmap(int n)
Definition: 2d.cpp:1281
void hud_stop_looped_locking_sounds()
Definition: hudlock.cpp:978
int Cmdline_query_speech
Definition: cmdline.cpp:389
void player_stop_looped_sounds()
void multi_standalone_postgame_do()
Definition: multi.cpp:1721
#define TRAINING_CONTEXT_FLY_PATH
Definition: sexp.h:999
int Game_shudder_time
Definition: freespace.cpp:518
void multi_reset_timestamps()
Definition: multi.cpp:1741
void lcl_xstr_init()
Definition: localize.cpp:408
void fiction_viewer_unpause()
void hud_subspace_notify_abort()
Definition: hud.cpp:3489
script_hook Script_simulationhook
Definition: scripting.cpp:25
#define CHA_ONSTATESTART
Definition: scripting.h:62
void game_flash(float r, float g, float b)
Definition: freespace.cpp:625
int game_check_key()
Definition: freespace.cpp:4854
void main_hall_pause()
void obj_init_all_ships_physics()
Definition: object.cpp:1689
void joy_ff_mission_init(vec3d v)
Definition: joy-unix.cpp:610
void emp_stop_local()
Definition: emp.cpp:420
#define NETGAME_STATE_SERVER_TRANSFER
Definition: multi.h:667
#define NG_FLAG_INGAME_JOINING_CRITICAL
Definition: multi.h:641
void fiction_viewer_pause()
void send_netplayer_update_packet(net_player *pl)
Definition: multimsgs.cpp:2308
script_hook Script_gameinithook
Definition: scripting.cpp:28
void training_menu_do_frame(float frametime)
void g3_set_view(camera *cam)
Definition: 3dsetup.cpp:137
object * Last_view_target
Definition: freespace.cpp:240
#define PCM_NORMAL
Definition: player.h:58
int mission_load(char *filename_ext)
Definition: missionload.cpp:83
void anim_level_close()
Called after the end of a mission to clean up any mission dependent anim data.
Definition: animplay.cpp:887
void load_animating_pointer(char *filename)
Definition: freespace.cpp:7430
#define MULTI_SYNC_PRE_BRIEFING
Definition: multiui.h:138
void obj_init()
Definition: object.cpp:327
int gameseq_get_state(void)
Definition: fredstubs.cpp:60
int tst
Definition: freespace.cpp:2649
int joy_init()
Definition: joy-unix.cpp:466
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
int generic_anim_load(generic_anim *ga)
Definition: generic.cpp:138
Assert(pm!=NULL)
void game_pause()
Definition: freespace.cpp:8765
int target_objnum
Definition: ai.h:339
void * HINSTANCE
Definition: config.h:105
vec3d Dead_camera_pos
Definition: shiphit.cpp:67
void multi_pause_do()
void game_flush()
Definition: freespace.cpp:4832
int key_checkch()
Definition: key.cpp:401
int GL_vertex_data_in
Definition: gropengltnl.cpp:72
int detail[MAX_MODEL_DETAIL_LEVELS]
Definition: model.h:738
bool dc_maybe_stuff_int(int *i)
Tries to stuff an int from the Command_string.
void VOICEREC_deinit()
Definition: pstypes.h:88
char filename[MAX_FILENAME_LEN]
#define GR_NUM_RESOLUTIONS
Definition: 2d.h:651
#define mprintf(args)
Definition: pstypes.h:238
int ai_index
Definition: ship.h:538
void standalone_main_close()
Definition: multi.cpp:1605
#define NETINFO_FLAG_OBSERVER
Definition: multi.h:605
fix Mission_end_time
void set_position(vec3d *in_position=NULL, float in_translation_time=0.0f, float in_translation_acceleration_time=0.0f, float in_translation_deceleration_time=0.0f, float in_end_velocity=0.0f)
Definition: camera.cpp:162
void scripting_state_close()
Definition: scripting.cpp:1436
void multi_log_close()
Definition: multi_log.cpp:93
__inline void gr_string(int x, int y, const char *string, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:769
float Game_hit_x
Definition: freespace.cpp:3054
void sexp_music_close()
Definition: sexp.cpp:10183
void obj_reset_colliders()
int HUD_draw
Definition: hud.cpp:78
void game_spew_pof_info()
Definition: freespace.cpp:6847
fix game_get_overall_frametime()
Definition: freespace.cpp:4777
#define NUM_SKILL_LEVELS
Definition: systemvars.h:150
void multi_unload_common_icons()
Definition: multiui.cpp:351
void model_find_world_dir(vec3d *out_dir, vec3d *in_dir, int model_num, int submodel_num, const matrix *objorient)
Definition: modelread.cpp:4551
int modelstats_num_polys
Definition: modelinterp.cpp:45
void multi_ingame_select_close()
#define NUM_MIXED_SOUNDS
Definition: freespace.cpp:2858
#define SEXP_NAN
Definition: sexp.h:924
void multi_log_process()
Definition: multi_log.cpp:100
#define VM_EXTERNAL
Definition: systemvars.h:31
Definition: 2d.h:95
void neb2_render_player()
Definition: neb.cpp:925
void multi_create_game_init()
Definition: multiui.cpp:3534
int medal_main_do()
Definition: medals.cpp:670
void Time_model(int modelnum)
Definition: freespace.cpp:7751
matrix Eye_matrix
Definition: 3dsetup.cpp:26
int Cmdline_spec
Definition: cmdline.cpp:329
int Cmdline_start_netgame
Definition: cmdline.cpp:280
int res
Definition: 2d.h:370
void multi_do_frame()
Definition: multi.cpp:1122
void game_frame(bool paused=false)
Definition: freespace.cpp:4327
int max_h_unscaled
Definition: 2d.h:361
void stars_pre_level_init(bool clear_backgrounds)
Definition: starfield.cpp:714
int Game_ships_tbl_valid
Definition: freespace.cpp:290
int Multi_display_netinfo
Definition: multi.cpp:85
int Cmdline_show_stats
Definition: cmdline.cpp:499
void ct_level_close()
int bm_get_info(int handle, int *w, int *h, ubyte *flags, int *nframes, int *fps)
Gets info on the bitmap indexed by handle.
Definition: bmpman.cpp:769
void multi_respawn_normal()
void obj_render_queue_all()
Definition: objectsort.cpp:347
float Game_flash_green
Definition: freespace.cpp:512
int bm_texture_ram
how many bytes of textures are used.
Definition: bmpman.cpp:64
struct animating_obj animating_obj
int joy_get_pos(int *x, int *y, int *z, int *rx)
Definition: joy-unix.cpp:267
#define FSB_CAMPAIGN_FILE
Definition: freespace.h:80
#define VM_TRACK
Definition: systemvars.h:32
int light_get_global_dir(vec3d *pos, int n)
Definition: lighting.cpp:621
ubyte r
Definition: 2d.h:84
void main_hall_start_ambient()
struct vec3d::@225::@227 xyz
void NavSystem_Init()
Definition: autopilot.cpp:1252
float tst_offset_total
Definition: freespace.cpp:2655
int center_h
Definition: 2d.h:363
ship_subsys * Players_targeted_subsys
Definition: sexp.cpp:855
bool fsspeech_init()
Definition: fsspeech.h:42
void model_render_immediate(model_render_params *render_info, int model_num, matrix *orient, vec3d *pos, int render, bool sort)
int timestamp_ticker
Definition: timer.cpp:199
int physics_paused
Definition: object.cpp:677
#define FS_VERSION_MAJOR
Definition: version.h:37
debug_command dc_r("r","shortcut for ai_rendering", dcf_ai_rendering)
int Pre_player_entry
Definition: freespace.cpp:299
void mission_hotkey_do_frame(float frametime)
GLclampf f
Definition: Glext.h:7097
int Tmap_npixels
Definition: freespace.cpp:7747
int snd_init()
Definition: sound.cpp:131
#define MAX_OBJECTS
Definition: globals.h:83
const char * Osreg_user_dir
void game_reset_shade_frame()
Definition: freespace.cpp:4188
void change_time_compression(float multiplier)
Definition: freespace.cpp:4639
void shockwave_level_init()
Definition: shockwave.cpp:595
int Debug_dump_frames
Definition: freespace.cpp:328
#define TRUE
Definition: pstypes.h:399
sound_env Game_default_sound_env
Definition: freespace.cpp:524
int Mouse_hidden
Definition: mouse.cpp:52
void mission_parse_eval_stuff()
Definition: cfile.h:28
void control_check_indicate()
void fireball_init()
Definition: fireballs.cpp:342
ai_info Ai_info[MAX_AI_INFO]
Definition: ai.cpp:23
void lcl_init(int lang_init)
Definition: localize.cpp:107
int center_offset_y
Definition: 2d.h:364
void multi_spew_pxo_checksums(int max_files, const char *outfile)
void mission_load_menu_close()
#define Assertion(expr, msg,...)
Definition: clang.h:41
float flRealframetime
Definition: freespace.cpp:247
Definition: 2d.h:82
void ai_do_repair_frame(object *objp, ai_info *aip, float frametime)
Definition: aicode.cpp:11996
void timestamp_reset()
Definition: timer.cpp:201
void debrief_close()
FILE * Time_fp
Definition: freespace.cpp:7744
#define f2fl(fx)
Definition: floating.h:37
void bm_page_in_start()
Tells bmpman to start keeping track of what bitmaps are used where.
Definition: bmpman.cpp:2372
void weapon_select_do(float frametime)
#define GR_MAYBE_CLEAR_RES(bmap)
Definition: 2d.h:639
void brief_init()
fix t2
Definition: animplay.cpp:37
void set_detail_level_lock(int detail_level_lock)
void cfile_refresh()
Definition: cfile.cpp:248
int Player_attacking_enabled
Definition: aicode.cpp:1638
ship_subsys * targeted_subsys
Definition: ai.h:472
int Multi_update_fireup_launcher_on_exit
void ship_init()
Definition: ship.cpp:5086
char Game_current_mission_filename[MAX_FILENAME_LEN]
Definition: freespace.cpp:307
angles Viewer_slew_angles
Definition: systemvars.cpp:54
const int RAND_MAX_2
Definition: pstypes.h:308
void snazzy_flush()
Definition: snazzyui.cpp:29
int detect_lang()
Definition: freespace.cpp:8434
void emp_process_local()
Definition: emp.cpp:434
void shipfx_engine_wash_level_init()
Definition: shipfx.cpp:3106
fix FrametimeOverall
Definition: freespace.cpp:249
void supernova_level_init()
Definition: supernova.cpp:51
int center_w
Definition: 2d.h:363
int Sexp_hud_display_warpout
Definition: sexp.cpp:9964
void control_config_common_init()
initialize common control config stuff - call at game startup after localization has been initialized...
void gr_set_screen_scale(int w, int h, int zoom_w, int zoom_h, int max_w, int max_h, int center_w, int center_h, bool force_stretch)
Definition: 2d.cpp:104
void game_process_event(int current_state, int event)
Definition: freespace.cpp:5087
void vm_vec_scale_add2(vec3d *dest, const vec3d *src, float k)
Definition: vecmat.cpp:284
float Timing_total
Definition: freespace.cpp:2084
#define PLAYER_FLAGS_AUTO_TARGETING
Definition: player.h:38
void key_flush()
Definition: key.cpp:356
int Init(HWND hwnd)
Definition: trackirpublic.h:86
bool Shadow_override
Definition: systemvars.cpp:80
void mission_campaign_end_do()
ubyte b
Definition: 2d.h:84
void cam_do_frame(float frametime)
Definition: camera.cpp:934
void multi_pxo_init(int use_last_channel)
Definition: multi_pxo.cpp:1083
void control_config_common_close()
close common control config stuff - call at game shutdown
int mouse_get_pos(int *xpos, int *ypos)
Definition: mouse.cpp:512
const char * os_config_read_string(const char *section, const char *name, const char *default_value)
Definition: osregistry.cpp:322
void model_page_in_start()
Definition: modelread.cpp:373
void gr_set_color_fast(color *dst)
Definition: 2d.cpp:1197
void training_check_objectives()
uint flags
Definition: ship.h:644
debug_command dc_s("s","shortcut for single_step", dcf_single_step)
#define KEY_PAGEUP
Definition: key.h:175
void game_increase_skill_level()
Definition: freespace.cpp:2536
void game_simulation_frame()
Definition: freespace.cpp:3901
void event_music_do_frame()
Definition: eventmusic.cpp:419
int Training_context_at_waypoint
Definition: sexp.cpp:839
int Framerate_cap
Definition: freespace.cpp:259
int Fred_running
Definition: freespace.cpp:301
int Radar_static_looping
Definition: radarsetup.cpp:34
int flags
Definition: multi.h:463
void obj_merge_created_list(void)
Definition: object.cpp:651
int key
void set_fov(float in_fov, float in_fov_time=0.0f, float in_fov_acceleration_time=0.0f, float in_deceleration_time=0.0f)
Definition: camera.cpp:87
void hud_scrollback_close()
Definition: hudmessage.cpp:979
object * objp
Definition: lua.cpp:3105
void encrypt_init()
Definition: encrypt.cpp:453
void game_leave_state(int old_state, int new_state)
Definition: freespace.cpp:5473
void multi_lag_close()
Definition: multilag.cpp:147
void multi_start_game_init()
Definition: multiui.cpp:2286
int red_alert_mission(void)
Definition: redalert.cpp:1031
#define gr_scene_texture_begin
Definition: 2d.h:910
void profile_begin(const char *name)
Definition: profiling.cpp:80
const char * detect_home(void)
Definition: osapi.cpp:101
#define OBJ_OBSERVER
Definition: object.h:43
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
GLsizeiptr size
Definition: Glext.h:5496
int max_w_unscaled
Definition: 2d.h:361
void game_add_event_debug_sexp(int n, int indent)
Definition: freespace.cpp:7606
void alpha_colors_init()
#define Int3()
Definition: pstypes.h:292
void gr_font_init()
Definition: font.cpp:699
void multi_handle_sudden_mission_end()
Definition: multiutil.cpp:2135
char * GS_event_text[]
uint Mem_starttime_phys
Definition: freespace.cpp:2098
#define CHA_MISSIONEND
Definition: scripting.h:56
DCF(warp,"Tests warpin effect")
Definition: freespace.cpp:1505
void multi_game_client_setup_do_frame()
Definition: multiui.cpp:6736
void snd_close(void)
Definition: sound.cpp:459
uint load_post_level_init
Definition: freespace.cpp:943
void hud_close()
Delete all HUD gauge objects, for all ships.
Definition: hud.cpp:1247
float FreeSpace_gamma
Definition: freespace.cpp:1694
bool Cmdline_frame_profile
Definition: cmdline.cpp:511
char * Cmdline_spew_mission_crcs
Definition: cmdline.cpp:410
void cmd_brief_close()
void techroom_intel_init()
Definition: techmenu.cpp:1050
int set_cdrom_path(int drive_num)
Definition: freespace.cpp:8234
#define NETPLAYER_STATE_DATA_LOAD
Definition: multi.h:683
ship * shipp
Definition: lua.cpp:9162
fs_builtin_mission Game_builtin_mission_list[MAX_BUILTIN_MISSIONS]
Definition: freespace.cpp:345
void beam_init()
Definition: beam.cpp:247
void SCP_mspdbcs_Initialise()
void os_config_write_uint(const char *section, const char *name, uint value)
Definition: osregistry.cpp:269
float tst_x
Definition: freespace.cpp:2654
vec3d pos
Definition: object.h:152
#define VM_TOPDOWN
Definition: systemvars.h:43
void level_page_in()
Definition: levelpaging.cpp:35
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: Glext.h:7308
void standalone_main_do()
Definition: multi.cpp:1590
#define GR_RESIZE_NONE
Definition: 2d.h:681
void get_info(vec3d *position, matrix *orientation)
Definition: camera.cpp:531
void asteroid_init()
Definition: asteroid.cpp:2140
#define PASCAL
Definition: config.h:74
vec3d view_pos
Definition: fredrender.cpp:103
void hud_set_default_color()
Set the current color to the default HUD color (with default alpha)
Definition: hud.cpp:2918
int bm_release(int handle, int clear_render_targets)
Frees both a bitmap's data and it's associated slot.
Definition: bmpman.cpp:2603
void cmd_brief_hold()
int Training_context_speed_min
Definition: sexp.cpp:834
vec3d turret_firing_point[MAX_TFP]
Definition: model.h:192
void nebl_init()
#define GR_OPENGL
Definition: 2d.h:648
void beam_render_all()
Definition: beam.cpp:1558
void brief_stop_voices()
void debug_console(void(*_func)(void))
Opens and processes the debug console. (Blocking call)
Definition: console.cpp:495
#define BMP_FLAG_RENDER_TARGET_STATIC
Texture is a static type.
Definition: bmpman.h:66
void game_title_screen_display()
Definition: freespace.cpp:8639
void multi_do_client_warp(float frame_time)
Definition: multiutil.cpp:1140
void mission_init_goals()
script_state Script_system("FS2_Open Scripting")
#define gr_end_proj_matrix
Definition: 2d.h:894
GUISystem GUI_system
Definition: wmcgui.cpp:21
int game_state
Definition: multi.h:498
#define TM_NUM_TYPES
Definition: model.h:663
int Show_area_effect
Definition: freespace.cpp:239
void parse_medal_tbl()
Definition: medals.cpp:246
#define AIPF2_NO_WARP_CAMERA
Definition: ai_profiles.h:64
#define PROFILE(name, function)
Definition: systemvars.h:251
void ship_get_eye(vec3d *eye_pos, matrix *eye_orient, object *obj, bool do_slew, bool from_origin)
Definition: ship.cpp:13227
uint game_get_cd_used_space(char *path)
Definition: freespace.cpp:8065
int Game_loading_background
Definition: freespace.cpp:1108
ubyte g
Definition: 2d.h:84
int Training_context_speed_timestamp
Definition: sexp.cpp:836
void hud_config_do_frame(float frametime)
Definition: hudconfig.cpp:1467
void cam_init()
Definition: camera.cpp:866
void multi_pxo_help_close()
Definition: multi_pxo.cpp:4893
void mission_event_shutdown()
void player_select_init()
Definition: playermenu.cpp:243
void get_info(vec3d *position, matrix *orientation)
Definition: camera.cpp:295
GLenum type
Definition: Gl.h:1492
void observer_init()
Definition: observer.cpp:22
void weapon_select_init()
void generic_anim_unload(generic_anim *ga)
Definition: generic.cpp:291
void std_init_os()
#define gr_set_ambient_light
Definition: 2d.h:908
void profile_init()
Called once at engine initialization to set the timer.
Definition: profiling.cpp:48
fix timer_get_approx_seconds()
Definition: timer.cpp:135
void supernova_get_eye(vec3d *eye_pos, matrix *eye_orient)
Definition: supernova.cpp:320
uint Ships_tbl_checksum
Definition: freespace.cpp:287
const char * Osreg_app_name
Definition: osregistry.cpp:35
void log_string(int logfile_type, const char *string, int add_time)
#define NUM_BUILTIN_LANGUAGES
Definition: localize.h:44
void os_set_title(const char *title)
Definition: osapi.cpp:172
int Joymouse_button_status
Definition: freespace.cpp:4829
int game_busy_callback(void(*callback)(int count), int delta_step=-1)
Definition: systemvars.cpp:144
int bm_load_animation(const char *real_filename, int *nframes, int *fps, int *keyframe, int can_drop_frames, int dir_type)
Loads a bitmap sequance so we can draw with it.
Definition: bmpman.cpp:1420
void shipfx_stop_engine_wash_sound()
Definition: shipfx.cpp:3114
#define CLAMP(x, min, max)
Definition: pstypes.h:488
debug_command dc_f("f","shortcut for ai_firing", dcf_ai_firing)
void ai_init(void)
Definition: aicode.cpp:828
#define MAX_BUILTIN_MISSIONS
Definition: freespace.h:75
int Multi_sync_mode
Definition: multiui.cpp:7348
GLint GLsizei width
Definition: Gl.h:1505
void asteroid_level_init()
Definition: asteroid.cpp:628
void debrief_unpause()
int Cmdline_show_mem_usage
Definition: cmdline.cpp:497
int weapon_info_index
Definition: weapon.h:164
void model_init()
Definition: modelread.cpp:409
vec3d topdown_offset
Definition: ship.h:1416
void game_busy(const char *filename=NULL)
Definition: systemvars.cpp:173
script_hook Script_splashhook
Definition: scripting.cpp:24
void gr_set_color(int r, int g, int b)
Definition: 2d.cpp:1188
bool isValid()
Definition: camera.cpp:851
void player_level_init()
fix Entry_delay_time
SCP_vector< waypoint > & get_waypoints()
Definition: waypoint.cpp:89
#define MIN_DIST_TO_DEAD_CAMERA
Definition: freespace.cpp:2982
matrix turret_matrix
Definition: model.h:187
char Last_cd_label[256]
Definition: freespace.cpp:8267
void obj_observer_move(float frame_time)
Definition: object.cpp:1772
int _getcwd(char *buffer, unsigned int len)
int objnum
Definition: ship.h:1483
void ship_render_cockpit(object *objp)
Definition: ship.cpp:7272
void ssm_init()
ship_subsys subsys_list
Definition: ship.h:630
__inline void gr_set_clip(int x, int y, int w, int h, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:741
int Game_subspace_effect
Definition: freespace.cpp:3665
int tst_time
Definition: freespace.cpp:2650
int multi_endgame_ending()
void SCP_mspdbcs_Cleanup()
void big_explosion_flash(float flash)
Definition: freespace.cpp:655
void game_maybe_update_sound_environment()
Definition: freespace.cpp:1282
int Cmdline_env
Definition: cmdline.cpp:323
int mouse_down(int btn)
Definition: mouse.cpp:315
bup bup bup-bup bup bup
Definition: gamesnd.h:348
void game_stop_time()
Definition: freespace.cpp:4570
player Players[MAX_PLAYERS]
sound_env sound_environment
Definition: missionparse.h:155
int Training_context_goal_waypoint
Definition: sexp.cpp:838
#define VM_PADLOCK_REAR
Definition: systemvars.h:39
void multi_voice_close()
float Sexp_fov
Definition: camera.cpp:16
uint os_get_window()
Definition: osapi.cpp:208
void os_config_write_string(const char *section, const char *name, const char *value)
Definition: osregistry.cpp:221
void ssm_process()
#define gr_set_view_matrix
Definition: 2d.h:895
void flak_level_init()
Definition: flak.cpp:23
#define EVENT_DEBUG_EVENT
Definition: freespace.cpp:7595
int OO_update_index
Definition: multi_obj.cpp:153
void read_player_controls(object *obj, float frametime)
char * LPSTR
Definition: config.h:107
void red_alert_voice_unpause()
Definition: redalert.cpp:213
float Game_shudder_intensity
Definition: freespace.cpp:520
vec3d Dead_player_last_vel
Definition: freespace.cpp:3166
#define VM_FREECAMERA
Definition: systemvars.h:44
int bytes_per_pixel
Definition: 2d.h:375
void loop_brief_init()
void multi_ping_reset_players()
Definition: multi_ping.cpp:30
int mission_campaign_previous_mission()
char * GS_state_text[]
int num_frames
Definition: generic.h:20
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
float supernova_time_left()
Definition: supernova.cpp:279
void model_instance_free_all()
Definition: modelread.cpp:355
void asteroid_level_close()
Definition: asteroid.cpp:1423
#define gr_reset_clip
Definition: 2d.h:745
int parse_cmdline(char *cmdline)
Definition: cmdline.cpp:1844
int instance
Definition: object.h:150
int afterburner_decay
Definition: physics.h:85
int Game_weapons_tbl_valid
Definition: freespace.cpp:293
void std_init_standalone()
void brief_do_frame(float frametime)
void game_stop_looped_sounds()
Definition: freespace.cpp:7375
void hud_positions_init()
Definition: hudparse.cpp:488
matrix * vm_vector_2_matrix(matrix *m, const vec3d *fvec, const vec3d *uvec, const vec3d *rvec)
Definition: vecmat.cpp:850
#define POPUPDEAD_DO_OBSERVER
Definition: popupdead.h:17
#define VM_PADLOCK_RIGHT
Definition: systemvars.h:41
void vm_vec_add2(vec3d *dest, const vec3d *src)
Definition: vecmat.cpp:178
int Cmdline_nohtl
Definition: cmdline.cpp:438
const float PI2
Definition: pstypes.h:305
#define VM_DEAD_VIEW
Definition: systemvars.h:33
int supernova_camera_cut()
Definition: supernova.cpp:296
void scripting_state_init()
Definition: scripting.cpp:1425
void multi_pause_close(int end_mission)
WarpEffect * warpout_effect
Definition: ship.h:576
void mission_campaign_maybe_play_movie(int type)
void medal_main_init(player *pl, int mode)
Definition: medals.cpp:525
void gamesnd_unload_interface_sounds()
Definition: gamesnd.cpp:578
#define gr_set_proj_matrix
Definition: 2d.h:893
void common_free_interface_palette()
float View_zoom
Definition: 3dsetup.cpp:30
#define PHYSICS_VIEWER_LEFT
Definition: physics.h:154
void game_do_frame()
Definition: freespace.cpp:4791
int type_flags
Definition: multi.h:493
void mission_parse_fixup_players()
void supernova_process()
Definition: supernova.cpp:184
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
void shockwave_move_all(float frametime)
Definition: shockwave.cpp:709
shader Viewer_shader
Definition: systemvars.cpp:39
int Last_frame_timestamp
char Multi_tracker_passwd[MULTI_TRACKER_STRING_LEN+1]
Definition: multi.cpp:144
void campaign_room_close()
Definition: readyroom.cpp:1711
#define SIF_BIG_SHIP
Definition: ship.h:944
void hud_level_close()
Do post mission cleanup of HUD.
Definition: hud.cpp:1229
#define CHA_ONFRAME
Definition: scripting.h:46
void multi_maybe_do_frame()
Definition: freespace.cpp:4822
struct matrix::@228::@230 vec
int game_do_cd_check(char *volume_name)
Definition: freespace.cpp:8326
void main_hall_table_init()
color Color_bright
Definition: alphacolors.cpp:28
void common_maybe_play_cutscene(int movie_type, bool restart_music, int music)
unsigned int uint
Definition: pstypes.h:64
void send_debrief_event()
Definition: multiutil.cpp:4159
virtual int getWarpPosition(vec3d *output)
Definition: shipfx.cpp:3525
#define EVENT_DEBUG_MAX
Definition: freespace.cpp:7594
void lab_close()
Definition: lab.cpp:2624
void multi_start_game_do()
Definition: multiui.cpp:2407
bsp_info * sm
Definition: lua.cpp:7079
float Timing_clear
Definition: freespace.cpp:2088
screen3d screen
Definition: pstypes.h:173
vec3d * get_pos()
Definition: waypoint.cpp:46
int subtype
Definition: lua.cpp:9763
int Show_shield_mesh
Definition: shield.cpp:27
void mouse_force_pos(int x, int y)
Definition: mouse.cpp:369
GLboolean GLboolean g
Definition: Glext.h:5781
#define cfopen(...)
Definition: cfile.h:134
color Color_bright_green
Definition: alphacolors.cpp:31
void game_start_time()
Definition: freespace.cpp:4601
void vm_vec_scale(vec3d *dest, float s)
Definition: vecmat.cpp:248
void mflash_level_init()
void nebl_process()
float Framerate
Definition: freespace.cpp:2081
int timestamp_until(int stamp)
Definition: timer.cpp:242
int state
Definition: multi.h:464
void game_spew_pof_info_sub(int model_num, polymodel *pm, int sm, CFILE *out, int *out_total, int *out_destroyed_total)
Definition: freespace.cpp:6819
#define nprintf(args)
Definition: pstypes.h:239
void do_timing_test(float frame_time)
Definition: freespace.cpp:2859
#define GM_MULTIPLAYER
Definition: systemvars.h:18
void game_render_frame(camid cid)
Definition: freespace.cpp:3673
int first_frame
Definition: generic.h:19
#define POPUPDEAD_DO_MAIN_HALL
Definition: popupdead.h:18
int snd_num_playing()
Definition: sound.cpp:1207
int mission_has_cmd_brief()
void joy_ff_play_dir_effect(float x, float y)
Definition: joy-unix.cpp:615
#define SEXP_FALSE
Definition: sexp.h:919
#define f2i(a)
Definition: fix.h:22
void messages_init()
void neb2_level_init()
Definition: neb.cpp:326
int Use_low_mem
Definition: freespace.cpp:1635
int dogfight_blown
Definition: freespace.cpp:242
int _mkdir(const char *path)
int game_hacked_data()
Definition: freespace.cpp:8607
void stars_post_level_init()
Definition: starfield.cpp:782
#define BMP_FLAG_CUBEMAP
Texture is a cubemap.
Definition: bmpman.h:68
int Cmdline_spew_pof_info
Definition: cmdline.cpp:279
float clip_aspect
Definition: 2d.h:372
float sn_glare_scale
Definition: freespace.cpp:670
void shield_hit_close()
Definition: shield.cpp:168
void mission_campaign_end_close()
void monitor_update()
Definition: systemvars.cpp:328
#define FSB_CAMPAIGN
Definition: freespace.h:79
#define gr_flash
Definition: 2d.h:813
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
void neb2_eye_changed()
Definition: neb.cpp:1111
float Gf_critical_time
Definition: freespace.cpp:561
int Num_pairs_checked
Definition: objcollide.cpp:34
int vm_init(int min_heap_size)
Definition: windebug.cpp:1657
int Cheats_enabled
Definition: key.cpp:100
#define DIR_SEPARATOR_STR
Definition: pstypes.h:44
vec3d tst_pos
Definition: freespace.cpp:2652
bool topdown_offset_def
Definition: ship.h:1415
int flags
Definition: ship.h:1227
void trail_render_all()
Definition: trails.cpp:556
void g3_set_view_matrix(const vec3d *view_pos, const matrix *view_matrix, float zoom)
Definition: 3dsetup.cpp:152
ai_profile_t * ai_profile
Definition: missionparse.h:168
#define MISSION_FLAG_RED_ALERT
Definition: missionparse.h:84
void model_clear_instance(int model_num)
Definition: modelread.cpp:4624
int Cmdline_normal
Definition: cmdline.cpp:331
void multi_maybe_send_ship_status()
Definition: multiutil.cpp:1242
#define SIF_SMALL_SHIP
Definition: ship.h:943
char * filename
#define NUM_FRAMES_TEST
Definition: freespace.cpp:2857
void mission_campaign_end_init()
#define CHA_SPLASHSCREEN
Definition: scripting.h:53
netgame_info Netgame
Definition: multi.cpp:97
void game_framerate_check_init()
Definition: freespace.cpp:563
void shield_frame_init()
Definition: shield.cpp:173
float speed
Definition: physics.h:79
#define CHA_GAMEINIT
Definition: scripting.h:54
int Training_num_lines
#define OBJ_WEAPON
Definition: object.h:33
void joy_flush()
Definition: joy-unix.cpp:152
mission_event Mission_events[MAX_MISSION_EVENTS]
void gameseq_pop_state()
texture_map maps[MAX_MODEL_TEXTURES]
Definition: model.h:762
void ssm_level_init()
angles_t angles
Definition: systemvars.h:73
#define KEY_SHIFTED
Definition: key.h:62
int Wash_on
Definition: shipfx.cpp:2864
void main_hall_do_multi_ready()
#define SF2_HIDE_SHIP_NAME
Definition: ship.h:498
void cmdline_debug_print_cmdline()
Definition: cmdline.cpp:538
#define BURST_DURATION
Definition: ai.h:573
void stars_draw_sun_glow(int sun_n)
Definition: starfield.cpp:1154
int Game_loading_callback_inited
Definition: freespace.cpp:1107
#define WP_LASER
Definition: weapon.h:27
bool stars_sun_has_glare(int index)
Definition: starfield.cpp:2448
void game_show_time_left()
Definition: freespace.cpp:2433
void stars_close()
Definition: starfield.cpp:706
int cfwrite_string(const char *buf, CFILE *file)
Definition: cfile.cpp:1366
float Max_draw_distance
Definition: 2d.cpp:85
#define MB_TASKMODAL
Definition: config.h:198
void game_set_frametime(int state)
Definition: freespace.cpp:4660
void barracks_close()
Definition: barracks.cpp:1639
void anim_level_init()
Called at the beginning of a mission to initialize any mission dependent anim data.
Definition: animplay.cpp:880
#define SCP_INITRESULT_SUCCESS
Definition: trackirpublic.h:9
#define OBJ_DEBRIS
Definition: object.h:37
#define w(p)
Definition: modelsinc.h:68
int Use_joy_mouse
Definition: freespace.cpp:234
int Cmdline_glow
Definition: cmdline.cpp:326
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void control_config_init()
void credits_do_frame(float frametime)
Definition: credits.cpp:666
struct big_expl_flash big_expl_flash
int Cmdline_cache_bitmaps
Definition: cmdline.cpp:352
bool fsspeech_was_compiled()
Definition: fsspeech.h:54
void obj_snd_stop_all()
Definition: objectsnd.cpp:299
#define CHA_GAMEPLAYSTART
Definition: scripting.h:69
const float RAND_MAX_1f
Definition: pstypes.h:309
void gr_shade(int x, int y, int w, int h, int resize_mode)
Definition: 2d.cpp:2085
void game_environment_map_gen()
Definition: freespace.cpp:3302
warp_camera Warp_camera
Definition: camera.cpp:17
GLdouble GLdouble z
Definition: Glext.h:5451
#define KEY_ENTER
Definition: key.h:125
void game_do_state_common(int state, int no_networking)
Definition: freespace.cpp:6409
void game_start_subspace_ambient_sound()
Definition: freespace.cpp:8026
void shadows_render_all(float fov, matrix *eye_orient, vec3d *eye_pos)
Definition: shadows.cpp:391
void game_tst_frame_pre()
Definition: freespace.cpp:2658
void player_select_close()
Definition: playermenu.cpp:448
void cutscenes_screen_close()
Definition: cutscenes.cpp:495
#define SEXP_NAN_FOREVER
Definition: sexp.h:925
void context_help_init()
void afterburner_level_init()
Definition: afterburner.cpp:53
#define SUBSYSTEM_TURRET
Definition: model.h:54
void main_hall_stop_ambient()
int Player_died_popup_wait
Definition: freespace.cpp:337
int model_num
Definition: model.h:176
object * Viewer_obj
Definition: object.cpp:57
fix Skybox_timestamp
Definition: systemvars.cpp:20
ubyte g3_rotate_vertex(vertex *dest, const vec3d *src)
Definition: 3dmath.cpp:97
void armor_init()
Definition: ship.cpp:18394
void game_update_missiontime()
Definition: freespace.cpp:4783
float distance
Definition: systemvars.h:74
void audiostream_close()
Definition: audiostr.cpp:1661
int Game_shudder_total
Definition: freespace.cpp:519
int Networking_disabled
Definition: freespace.cpp:262
void player_show_death_message()
int snd_play(game_snd *gs, float pan, float vol_scale, int priority, bool is_voice_msg)
Definition: sound.cpp:517
void game_process_keys()
#define fl_abs(fl)
Definition: floating.h:31
#define MB_OK
Definition: config.h:179
#define FS_VERSION_MINOR
Definition: version.h:38
void options_menu_close()
void message_mission_shutdown()
void sim_room_do_frame(float frametime)
Definition: readyroom.cpp:1172
float Supernova_last_glare
Definition: freespace.cpp:676
fs_builtin_mission * game_find_builtin_mission(char *filename)
Definition: freespace.cpp:528
int Use_mouse_to_fly
Definition: mouse.cpp:51
int event_music_player_death()
GLdouble s
Definition: Glext.h:5321
void logfile_close(int logfile_type)
Definition: generic_log.cpp:72
net_player_server_info s_info
Definition: multi.h:472
bool dc_maybe_stuff_boolean(bool *b)
Tries to stuff a bool from the Command_string.
#define SEXP_CANT_EVAL
Definition: sexp.h:926
int tst_bitmap
Definition: freespace.cpp:2653
int Training_context_speed_max
Definition: sexp.cpp:835
float vm_vec_normalized_dir(vec3d *dest, const vec3d *end, const vec3d *start)
Definition: vecmat.cpp:591
#define CUB_NONE
Definition: systemvars.h:50
float vm_vec_dist(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:355
#define EXE_FNAME
Definition: freespace.cpp:225
#define MAX_PLAYERS
Definition: pstypes.h:32
short player_id
Definition: multi.h:460
void multi_standalone_wait_close()
Definition: multi.cpp:1671
matrix eye_orient
Definition: fredrender.cpp:112
void options_menu_init()
void multi_sync_do()
Definition: multiui.cpp:7453
#define PCM_WARPOUT_STAGE2
Definition: player.h:60
int Interface_framerate
Definition: freespace.cpp:1484
void game_do_networking()
Definition: freespace.cpp:1078
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
#define MONITOR(function_name)
Definition: pstypes.h:454
void parse_rank_tbl()
Definition: scoring.cpp:58
char Fred_callsigns[MAX_SHIPS][NAME_LENGTH+1]
Definition: freespace.cpp:305
void event_music_init()
Definition: eventmusic.cpp:261
#define WM_RECOEVENT
Definition: voicerec.h:5
void set_time_compression(float multiplier, float change_time)
Definition: freespace.cpp:4647
angles * vm_extract_angles_matrix(angles *a, const matrix *m)
Definition: vecmat.cpp:1027
fix Game_time_compression
Definition: freespace.cpp:277
bool Perspective_locked
Definition: keycontrol.cpp:213
int Num_models_needing_splitting
Definition: freespace.cpp:7749
void hud_config_init()
Definition: hudconfig.cpp:924
void debrief_do_frame(float frametime)
void red_alert_init()
Definition: redalert.cpp:297
#define NUM_WEAPONS_TBL_CHECKSUMS
Definition: freespace.cpp:8546
FILE * Texture_fp
Definition: freespace.cpp:7745
#define DETAIL_FLAG_HUD
Definition: systemvars.h:114
Definition: ship.h:534
void sim_room_init()
Definition: readyroom.cpp:992
int model_load(char *filename, int n_subsystems, model_subsystem *subsystems, int ferror=1, int duplicate=0)
Definition: modelread.cpp:2573
int tst_big
Definition: freespace.cpp:2651
#define gr_post_process_set_defaults
Definition: 2d.h:915
void bm_get_frame_usage(int *ntotal, int *nnew)
(DEBUG) Gets memory size, in bytes, of the locked bitmaps
Definition: bmpman.cpp:749
vec3d eye_pos
Definition: fredrender.cpp:103
#define DETAIL_FLAG_CLEAR
Definition: systemvars.h:113
void multi_create_game_close()
Definition: multiui.cpp:3911
void SetHookObject(char *name, object *objp)
Definition: scripting.cpp:551
Class to aggregate a debug command with its name (as shown in the console) and short help...
Definition: console.h:221
unsigned long DWORD
Definition: config.h:90
void training_menu_close()
void pause_debug_init()
float wash_intensity
Definition: ship.h:664
void red_alert_maybe_move_to_next_mission()
Definition: redalert.cpp:1070
bool bm_set_render_target(int handle, int face)
(GR function) Calls gr_bm_set_render target for the given bitmap indexed by handle ...
Definition: bmpman.cpp:2810
#define KEY_BACKSP
Definition: key.h:126
void multi_pause_do_frame()
Definition: multi.cpp:1329
void fsspeech_play(int type, const char *text)
Definition: fsspeech.h:44
#define NETPLAYER_IS_DEAD(player)
Definition: multi.h:627
#define MULTI_END_ERROR_LOAD_FAIL
Definition: multi_endgame.h:46
void anim_init()
Initialise animation.
Definition: animplay.cpp:45
int player_select_get_last_pilot()
Definition: playermenu.cpp:841
color HUD_color_debug
Definition: hud.cpp:85
int Asteroids_enabled
Definition: asteroid.cpp:57
bool save_player(player *_p=NULL)
Definition: plr.cpp:935
void anim_render_all(int screen_id, float frametime)
Display the frames for the currently playing anims.
Definition: animplay.cpp:67
int Model_ram
Definition: modelread.cpp:69
void multi_standalone_postgame_init()
Definition: multi.cpp:1690
int g3_project_vertex(vertex *point)
Definition: 3dmath.cpp:202
int idx
Definition: multiui.cpp:761
debug_command dc_p("p","shortcut for physics_pause", dcf_physics_pause)
void gamesnd_load_gameplay_sounds()
Definition: gamesnd.cpp:529
void brief_pause()
cfbp fp
Definition: cfile.cpp:1065
#define KEY_P
Definition: key.h:97
sexp_node * Sexp_nodes
Definition: sexp.cpp:844
float sn_shudder
Definition: supernova.cpp:181
void neb2_init()
Definition: neb.cpp:250
GLdouble GLdouble t
Definition: Glext.h:5329
fix Time_compression_change_rate
Definition: freespace.cpp:279
void multi_host_options_do()
Definition: multiui.cpp:5944
void os_init(const char *wclass, const char *title, const char *app_name, const char *version_string)
Definition: osapi.cpp:134
#define FRAME_FILTER
Definition: freespace.cpp:220
void hud_render_all()
Undertakes main HUD render.
Definition: hud.cpp:1716
ubyte c
Definition: 2d.h:84
void debrief_init()
int Sound_enabled
Definition: sound.cpp:51
#define MB_ICONWARNING
Definition: config.h:185
void init_animating_pointer()
Definition: freespace.cpp:7414
void multi_game_client_setup_init()
Definition: multiui.cpp:6655
void bm_get_palette(int handle, ubyte *pal, char *name)
Gets the palette for a given bitmap indexed by handle, and optionally the filename.
Definition: bmpman.cpp:850
void multi_join_clear_game_list()
Definition: multiui.cpp:978
char loading_screen[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN]
Definition: missionparse.h:146
generic_anim Game_loading_ani
Definition: freespace.cpp:1109
fix fixmuldiv(fix a, fix b, fix c)
Definition: fix.cpp:34
void game_render_mouse(float frametime)
Definition: freespace.cpp:7475
void gr_stuff_first_font(char *first_font, size_t first_font_size)
Definition: font.cpp:694
void mission_hotkey_init()
void Do_model_timings_test()
Definition: freespace.cpp:7877
int Training_context
Definition: sexp.cpp:832
camid cam_get_current()
Definition: camera.cpp:952
button_info Multi_ship_status_bi
Definition: multiutil.cpp:1240
void nebl_level_init()
int event_music_player_respawn_as_observer()
void scripting_state_do_frame(float frametime)
Definition: scripting.cpp:1446
DCF_BOOL(palette_flash, Use_palette_flash)
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
for(int idx=0;idx< i;idx++)
Definition: multi_pxo.cpp:472
void ship_select_do(float frametime)
void shipfx_warpin_start(object *objp)
Definition: shipfx.cpp:565
void game_do_training_checks()
Definition: freespace.cpp:7533
void hud_config_close()
Definition: hudconfig.cpp:1541
long fix
Definition: pstypes.h:54
void profile_dump_output()
Definition: profiling.cpp:196
GLclampd n
Definition: Glext.h:7286
vei Viewer_external_info
Definition: systemvars.cpp:55
unsigned char ubyte
Definition: pstypes.h:62
#define MONITOR_INC(function_name, inc)
Definition: pstypes.h:457
int get_mission_info(const char *filename, mission *mission_p, bool basic)
void bm_set_low_mem(int mode)
Sets BMPMAN's memory mode.
Definition: bmpman.cpp:2803
uint Mem_starttime_virtual
Definition: freespace.cpp:2100
void key_level_init()
Definition: key.cpp:909
void hud_free_scrollback_list()
Definition: hudmessage.cpp:724
int game_poll()
Definition: freespace.cpp:4871
void ai_level_init(void)
Definition: aicode.cpp:853
int Training_message_method
void os_poll()
Definition: osapi.cpp:748
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
int game_do_cd_check_specific(char *volume_name, int cdnum)
Definition: freespace.cpp:8377
void mission_show_goals_do_frame(float frametime)
void control_config_do_frame(float frametime)
void stars_camera_cut()
Definition: starfield.cpp:1005
int Debug_octant
Definition: freespace.cpp:275
#define GM_DEAD
Definition: systemvars.h:25
int objnum
Definition: player.h:124
#define DIMINISH_RATE
Definition: freespace.cpp:665
#define OBJ_INDEX(objp)
Definition: object.h:235
void set_current_hud()
Definition: hudparse.cpp:669
#define FSB_MULTI
Definition: freespace.h:77
int mission_load_up_campaign(player *pl)
bool mission_has_fiction()
void game_assign_sound_environment()
Definition: freespace.cpp:1290
void weapon_init()
Definition: weapons.cpp:3516
ship * Player_ship
Definition: ship.cpp:124
bool shipfx_eye_in_shadow(vec3d *eye_pos, object *src_obj, int sun_n)
Definition: shipfx.cpp:977
#define GM_IN_MISSION
Definition: systemvars.h:23
GLenum cap
Definition: Glext.h:9110
color Color_bright_red
Definition: alphacolors.cpp:34
int Multi_tracker_id
Definition: multi.cpp:146
void multi_df_debrief_do()
#define KEY_PRINT_SCRN
Definition: key.h:184
void game_framerate_check()
Definition: freespace.cpp:577
#define PHYSICS_VIEWER_UP
Definition: physics.h:157
matrix orient
Definition: object.h:153
waypoint_list * Training_context_path
Definition: sexp.cpp:837
void mission_brief_common_init()
void cmd_brief_unpause()
int max_w
Definition: 2d.h:360
vec3d Original_vec_to_deader
Definition: shiphit.cpp:68
float Cutscene_delta_time
Definition: systemvars.cpp:34
void hud_init_comm_orders()
void hud_update_frame(float frametime)
Updates HUD systems each frame.
Definition: hud.cpp:1336
#define NOX(s)
Definition: pstypes.h:473
fix Desired_time_compression
Definition: freespace.cpp:278
void beam_level_init()
Definition: beam.cpp:253
int game_start_mission()
Definition: freespace.cpp:1416
void get_version_string(char *str, int max_size)
Definition: freespace.cpp:7977
void game_event_debug_init()
Definition: freespace.cpp:7624
bool end_string_at_first_hash_symbol(char *src)
Definition: parselo.cpp:3833
bool VOICEREC_init(HWND hWnd, int event_id, int grammar_id, int command_resource)
void vm_vec_copy_scale(vec3d *dest, const vec3d *src, float s)
Definition: vecmat.cpp:257
int game_single_step
Definition: freespace.cpp:308
#define OBJ_SHIP
Definition: object.h:32
#define KEY_F1
Definition: key.h:143
void game_enter_state(int old_state, int new_state)
Definition: freespace.cpp:5891
void game_title_screen_close()
Definition: freespace.cpp:8740
#define PHYSICS_VIEWER_FRONT
Definition: physics.h:153
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
void bars_do_frame(float frametime)
Definition: freespace.cpp:4240
#define GM_STANDALONE_SERVER
Definition: systemvars.h:27
void loop_brief_do(float frametime)
int Cmdline_voice_recognition
Definition: cmdline.cpp:391
int cf_chksum_long(const char *filename, uint *chksum, int max_size, int cf_type)
Definition: cfile.cpp:1841
void gamesnd_preload_common_sounds()
Definition: gamesnd.cpp:510
void shield_point_multi_setup()
Definition: shield.cpp:817
#define MULTI_END_NOTIFY_NONE
Definition: multi_endgame.h:32
void lab_init()
Definition: lab.cpp:2381
int Game_weapons_tbl_checksums[NUM_WEAPONS_TBL_CHECKSUMS]
Definition: freespace.cpp:8548
void game_render_post_frame()
Definition: freespace.cpp:4308
void dc_stuff_float(float *f)
Stuffs a float to the given variable.
GLbitfield flags
Definition: Glext.h:6722
void vm_vec_rand_vec_quick(vec3d *rvec)
Definition: vecmat.cpp:1379
void jumpnode_level_close()
Definition: jumpnode.cpp:485
void neb2_render_setup(camid cid)
Definition: neb.cpp:464
uint Weapon_tbl_checksum
Definition: freespace.cpp:286
#define vm_malloc(size)
Definition: pstypes.h:547
void set_rotation(matrix *in_orientation=NULL, float in_rotation_time=0.0f, float in_rotation_acceleration_time=0.0f, float in_rotation_deceleration_time=0.0f)
Definition: camera.cpp:195
int sound_env_get(sound_env *se, int preset)
Definition: sound.cpp:1372
#define SIF_HUGE_SHIP
Definition: ship.h:945
void psnet_init(int protocol, int port_num)
Definition: psnet2.cpp:458
int Multi_ping_timestamp
Definition: freespace.cpp:339
typedef void(APIENTRY *PFNGLARRAYELEMENTEXTPROC)(GLint i)
int game_zbuffer
Definition: freespace.cpp:311
unsigned int SND_ENV_DEFAULT
Definition: sound.cpp:56
int readyroom_continue_campaign()
Definition: readyroom.cpp:845
int envmap_render_target
Definition: 2d.h:406
int control_mode
Definition: player.h:134
void multi_host_options_init()
Definition: multiui.cpp:5817
void dc_stuff_int(int *i)
Stuffs an int to the given variable. Supports binary (0b), hexadecimal (0x), and octal (0o) formats...
GLuint const GLchar * name
Definition: Glext.h:5608
int saved_timestamp_ticker
Definition: freespace.cpp:4556
int light_get_global_count()
Definition: lighting.cpp:608
void snd_aav_init()
Definition: sound.cpp:1535
int RunCondition(int condition, char format='\0', void *data=NULL, class object *objp=NULL, int more_data=0)
Definition: scripting.cpp:924
#define PROMPT_NONE
Definition: multi_endgame.h:26
#define IDR_CMD_CFG
#define IDENTITY_MATRIX
Definition: vecmat.h:64
int GetOriginalTexture()
void cmd_brief_init(int team)
void mission_goal_fail_incomplete()
int Training_context_speed_set
Definition: sexp.cpp:833
int Debug_dump_frame_num
Definition: freespace.cpp:331
int Framerate_delay
Definition: freespace.cpp:1692
void ai_debug_render_stuff()
Definition: aicode.cpp:11081
int RunBytecode(script_hook &hd, char format='\0', void *data=NULL)
Definition: scripting.cpp:918
void techroom_close()
Definition: techmenu.cpp:1250
void vm_vec_sub(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:168
void game_tst_mark(object *objp, ship *shipp)
Definition: freespace.cpp:2805
#define MAX_PATH_LEN
Definition: pstypes.h:325
int Players_mlocked_timestamp
Definition: sexp.cpp:857
vec3d vel
Definition: physics.h:77
void collide_ship_ship_sounds_init()
float fspeed
Definition: physics.h:80
fix t1
Definition: animplay.cpp:37
void game_process_pause_key()
int Cutscene_bar_flags
Definition: systemvars.cpp:32
void particle_move_all(float frametime)
Definition: particle.cpp:239
int BOOL
Definition: config.h:80
void hud_scrollback_init()
Definition: hudmessage.cpp:931
#define VM_PADLOCK_UP
Definition: systemvars.h:38
float Gf_critical
Definition: freespace.cpp:560
int Use_palette_flash
Definition: freespace.cpp:235
TrackIRDLL gTirDll_TrackIR
void game_loading_callback(int count)
Definition: freespace.cpp:1131
#define TRAINING_CONTEXT_SPEED
Definition: sexp.h:998
vec3d Eye_position
Definition: 3dsetup.cpp:27
void multi_ingame_select_init()
SCP_vector< object * > effect_ships
Definition: objectsort.cpp:107
subspace ambient sound (left channel) (looped)
Definition: gamesnd.h:140
int event_music_player_respawn()
int bm_load(const char *real_filename)
Loads a bitmap so we can draw with it later.
Definition: bmpman.cpp:1119
int multi_quit_game(int prompt, int notify_code, int err_code, int wsa_error)
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
#define CF_TYPE_DATA
Definition: cfile.h:46
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
int Player_died_time
Definition: freespace.cpp:2544
void std_multi_set_standalone_missiontime(float mission_time)
void dc_stuff_boolean(bool *b)
stuffs a boolean evaluated integer or string into the given variable.
#define NETPLAYER_STATE_WAITING
Definition: multi.h:684
float flFrametime
Definition: freespace.cpp:248
void wss_direct_restore_loadout()
int Cmdline_snd_preload
Definition: cmdline.cpp:390
uint Game_detail_flags
Definition: systemvars.cpp:52
int submodel_get_num_polys(int model_num, int submodel_num)
void game_sunspot_process(float frametime)
Definition: freespace.cpp:680
#define SF_DEPARTING
Definition: ship.h:475
void game_feature_disabled_popup()
Definition: freespace.cpp:7927
#define FS_CDROM_VOLUME_2
Definition: freespace.h:30
void multi_pxo_do()
Definition: multi_pxo.cpp:1242
void NavSystem_Do()
Definition: autopilot.cpp:1065
void trail_move_all(float frametime)
Definition: trails.cpp:508
void profile_end(const char *name)
Definition: profiling.cpp:130
void popupdead_close()
Definition: popupdead.cpp:522
int player_process_pending_praise()
See if there is a praise message to deliver to the player. We want to delay the praise messages a bit...
#define GetCurrentDirectory(i, s)
Definition: config.h:224
void profile_deinit()
Definition: profiling.cpp:63
int modelstats_num_polys_drawn
Definition: modelinterp.cpp:46
void fireball_close()
Definition: fireballs.cpp:937
void options_menu_do_frame(float frametime)
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581
void gr_set_cursor_bitmap(int n, int lock)
Definition: 2d.cpp:1242
void palman_load_pixels()
Definition: palman.cpp:65
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
float damage_this_burst
Definition: player.h:146
void asteroid_create_all()
Definition: asteroid.cpp:529
void fsspeech_deinit()
Definition: fsspeech.h:43
void pilot_load_squad_pic_list()
void cmd_brief_do_frame(float frametime)
void main_hall_do(float frametime)
void psnet_close()
Definition: psnet2.cpp:563
void mouse_init()
Definition: mouse.cpp:103
SCP_string main_hall
#define FONT1
Definition: font.h:65
const char * Osreg_class_name
Definition: osregistry.cpp:29
void model_free_all()
Definition: modelread.cpp:337
color Color_white
Definition: alphacolors.cpp:32
void pause_debug_do()
void game_maybe_do_dead_popup(float frametime)
Definition: freespace.cpp:4086
float frame_time
Definition: multi.cpp:1426
void ship_model_start(object *objp)
Definition: ship.cpp:13012
void nebl_render_all()
int Tool_enabled
Definition: keycontrol.cpp:212
campaign Campaign
int Fade_end_timestamp
Definition: systemvars.cpp:42
int cfputs(const char *str, CFILE *cfile)
Definition: cfile.cpp:1504
GLint GLsizei GLsizei height
Definition: Gl.h:1505
float vm_vec_dist_quick(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:417
Definition: pstypes.h:606
void common_select_close()
int Show_target_debug_info
Definition: freespace.cpp:268
#define strcat_s(...)
Definition: safe_strings.h:68
#define FS_VERSION_REVIS
Definition: version.h:40
#define KEY_ESC
Definition: key.h:124
void weapon_close()
Definition: weapons.cpp:3545
#define NAME_LENGTH
Definition: globals.h:15
const char * label
void player_restore_target_and_weapon_link_prefs()
#define WP_MISSILE
Definition: weapon.h:28
int Players_mlocked
Definition: sexp.cpp:854
int Num_pairs
Definition: objcollide.cpp:32
void red_alert_close()
Definition: redalert.cpp:356
void neb2_post_level_init()
Definition: neb.cpp:332
int last_single_step
Definition: freespace.cpp:309
int Game_skill_level
Definition: freespace.cpp:223
float rad
Definition: model.h:757
void particle_render_all()
Definition: particle.cpp:346
void main_hall_unpause()
int n_models
Definition: model.h:744
void fiction_viewer_do_frame(float frametime)
void gameplay_help_init()
void obj_pairs_close()
Definition: objcollide.cpp:70
void stop_parse()
Definition: parselo.cpp:2071
void game_shade_frame(float frametime)
Definition: freespace.cpp:4194
#define VM_PADLOCK_LEFT
Definition: systemvars.h:40
bool Time_compression_locked
Definition: freespace.cpp:280
void HUD_init()
Called each level to initialize HUD systems.
Definition: hud.cpp:1164
void multi_sync_init()
Definition: multiui.cpp:7426
void ship_init_cockpit_displays(ship *shipp)
Definition: ship.cpp:7349
void show_debug_stuff()
Definition: freespace.cpp:2630
int g3_in_frame()
Definition: 3dsetup.cpp:66
#define NUM_SHIPS_TBL_CHECKSUMS
Definition: freespace.cpp:8484
void waypoint_level_close()
Definition: waypoint.cpp:106
int Cmdline_NoFPSCap
Definition: cmdline.cpp:353
void fiction_viewer_close()
#define fl2i(fl)
Definition: floating.h:33
char * Cmdline_start_mission
Definition: cmdline.cpp:488
#define MULTI_CONNECTED(np)
Definition: multi.h:136
void pause_init()
#define CUB_CUTSCENE
Definition: systemvars.h:52
void game_maybe_draw_mouse(float frametime)
Definition: freespace.cpp:7504
int Default_env_map
Definition: freespace.cpp:341
int Player_dead_state
camid game_render_frame_setup()
Definition: freespace.cpp:3348
loadout_data Player_loadout
fix timer_get_fixed_seconds()
Definition: timer.cpp:116
#define TIME_UP
int init_cdrom()
Definition: freespace.cpp:8254
player * Player
void audiostream_unpause_all(bool via_sexp_or_script=false)
Definition: audiostr.cpp:1990
void hud_scrollback_do_frame(float frametime)
Definition: hudmessage.cpp:998
void os_cleanup()
Definition: osapi.cpp:181
void pause_close()
#define KEY_MASK
Definition: key.h:67
void subtitles_do_frame(float frametime)
Definition: camera.cpp:1018
void multi_pxo_help_do()
Definition: multi_pxo.cpp:4851
GLenum target
Definition: Glext.h:6872
#define g3_end_frame()
Definition: 3d.h:49
void mission_log_init()
Definition: missionlog.cpp:72
void game_init()
Definition: freespace.cpp:1732
#define MULTI_SYNC_INGAME
Definition: multiui.h:140
int Campaign_ending_via_supernova
void ai_profiles_init()
cargo revealed
Definition: gamesnd.h:73
void cutscenes_screen_do_frame()
Definition: cutscenes.cpp:503
class camera * getCamera()
Definition: camera.cpp:833
screen gr_screen
Definition: 2d.cpp:46
#define MULTI_SYNC_POST_BRIEFING
Definition: multiui.h:139
char Game_CDROM_dir[MAX_PATH_LEN]
Definition: freespace.cpp:504
float Min_draw_distance
Definition: 2d.cpp:84
void gr_get_string_size(int *w, int *h, const char *text, int len=9999)
Definition: font.cpp:196
void generic_anim_init(generic_anim *ga)
Definition: generic.cpp:80
void game_whack_reset()
Definition: freespace.cpp:3058
bool Dynamic_environment
Definition: starfield.cpp:175
int snd_play_looping(game_snd *gs, float pan, int start_loop, int stop_loop, float vol_scale, int scriptingUpdateVolume)
Definition: sound.cpp:822
int tst_stamp
Definition: freespace.cpp:2657
#define SEXP_KNOWN_TRUE
Definition: sexp.h:922
GLint first
Definition: Gl.h:1491
void game_add_event_debug_index(int n, int indent)
Definition: freespace.cpp:7600
void multi_join_game_close()
Definition: multiui.cpp:1147
void weapon_level_init()
Definition: weapons.cpp:3582
void mission_hotkey_close()
#define MB_SETFOREGROUND
Definition: config.h:202
void game_post_level_init()
Definition: freespace.cpp:1363
#define CHA_HUDDRAW
Definition: scripting.h:51
#define FSB_FROM_VOLITION
Definition: freespace.h:76
int next_sibling
Definition: model.h:362
#define MOVIE_PRE_FICTION
Definition: missionparse.h:116
int ED_count
Definition: freespace.cpp:7598
void event_music_level_init(int force_soundtrack)
Definition: eventmusic.cpp:543
#define GRAMMARID1
Definition: voicerec.h:4
void hud_setup_escort_list(int level)
Definition: hudescort.cpp:651
#define KEY_F2
Definition: key.h:144
void game_shudder_apply(int time, float intensity)
Definition: freespace.cpp:3078
void get_version_string_short(char *str)
Definition: freespace.cpp:8011
#define GM_DEAD_BLEW_UP
Definition: systemvars.h:21
GLsizei const GLchar ** path
Definition: Glext.h:6795
void game_flip_page_and_time_it()
Definition: freespace.cpp:3889
void mission_load_menu_init()
ship_obj Ship_obj_list
Definition: ship.cpp:162
int gr_get_font_height()
Definition: font.cpp:187
void event_music_close()
Definition: eventmusic.cpp:320
void debris_init()
Definition: debris.cpp:87
char name[MAX_NAME_LEN]
Definition: model.h:325
bool logfile_init(int logfile_type)
Definition: generic_log.cpp:53
uint load_mission_load
Definition: freespace.cpp:942
float elapsed_time
Definition: freespace.cpp:7403
#define fl_sqrt(fl)
Definition: floating.h:29
void game_render_hud(camid cid)
Definition: freespace.cpp:4167
void timestamp_inc(int frametime_ms)
Definition: timer.cpp:212
int ship_info_index
Definition: ship.h:539
void light_reset()
Definition: lighting.cpp:150
int center_offset_x
Definition: 2d.h:364
#define KEY_DEBUGGED
Definition: key.h:65
char transfer_text[128]
Definition: freespace.cpp:2077
void stars_draw(int show_stars, int show_suns, int show_nebulas, int show_subspace, int env)
Definition: starfield.cpp:1813
GLfloat GLfloat p
Definition: Glext.h:8373
#define NG_FLAG_SERVER_LOST
Definition: multi.h:639
void mission_campaign_init()
#define DEFAULT_SKILL_LEVEL
Definition: freespace.cpp:222
void Sleep(int mili)
#define MULTIPLAYER_MASTER
Definition: multi.h:130
void HUD_reset_clip()
Like gr_reset_clip() only it accounts for HUD jittering.
Definition: hud.cpp:3633
float Game_flash_red
Definition: freespace.cpp:511
An overhauled/updated debug console to allow monitoring, testing, and general debugging of new featur...
struct _cl_event * event
Definition: Glext.h:7296
void player_select_do()
Definition: playermenu.cpp:347
void trail_level_close()
Definition: trails.cpp:36
texture_info textures[TM_NUM_TYPES]
Definition: model.h:671
#define TIME_DOWN
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
#define LOCATION
Definition: pstypes.h:245
void ship_clear_cockpit_displays()
Definition: ship.cpp:7385
int max_h
Definition: 2d.h:360
void gameseq_push_state(int new_state)
bool game_using_low_mem()
Definition: freespace.cpp:8754
#define VM_PADLOCK_ANY
Definition: systemvars.h:46
void ct_level_init()
void gr_reset_screen_scale()
Definition: 2d.cpp:176
int MessageBox(HWND h, const char *s1, const char *s2, int i)
void main_hall_start_music()
const char * Skill_level_names(int skill_level, int translate=1)
Definition: aicode.cpp:208
int Show_framerate
Definition: freespace.cpp:252
void brief_unpause()
void cutscene_init()
Definition: cutscenes.cpp:51
int Viewer_mode
Definition: systemvars.cpp:28
void asteroid_frame()
Definition: asteroid.cpp:2122
void cam_close()
Definition: camera.cpp:872
#define timestamp_elapsed(stamp)
Definition: timer.h:102
void multi_init()
Definition: multi.cpp:160
void barracks_do_frame(float frametime)
Definition: barracks.cpp:1444
char * Cmdline_spew_table_crcs
Definition: cmdline.cpp:411
int Last_cd_label_found
Definition: freespace.cpp:8266
int Target_static_looping
#define MEF_CURRENT
Definition: missiongoals.h:82
color current_color
Definition: 2d.h:396
shader busy_shader
Definition: freespace.cpp:1123
#define gr_post_process_save_zbuffer
Definition: 2d.h:918
#define FS_CDROM_VOLUME_3
Definition: freespace.h:31
void multi_sync_close()
Definition: multiui.cpp:7491
lang_info Lcl_builtin_languages[NUM_BUILTIN_LANGUAGES]
Definition: localize.cpp:36
#define PI
Definition: pstypes.h:303
void convert_pilot_files()
void control_config_close()
void shipfx_warpout_start(object *objp)
Definition: shipfx.cpp:794
void verify_ships_tbl()
Definition: freespace.cpp:8491
#define gr_copy_effect_texture
Definition: 2d.h:912
#define MISSION_FLAG_2D_MISSION
Definition: missionparse.h:82
#define MOVIE_PRE_DEBRIEF
Definition: missionparse.h:120
void say_view_target()
Definition: freespace.cpp:2985
float Timing_render3
Definition: freespace.cpp:2086
void gameplay_help_do_frame(float frametime)
const GLfloat * m
Definition: Glext.h:10319
void multi_ts_init()
int game_main(char *cmdline)
Definition: freespace.cpp:6943
void awacs_process()
Definition: awacs.cpp:74
float get_fov()
Definition: camera.cpp:284
FadeType Fade_type
Definition: systemvars.cpp:40
bool movie_play(char *name)
Definition: movie.cpp:72
void mission_campaign_save_player_persistent_variables()
float tst_offset
Definition: freespace.cpp:2655
int Iff_traitor
Definition: iff_defs.cpp:22
color Color_normal
Definition: alphacolors.cpp:28
void freespace_mission_load_stuff()
Definition: freespace.cpp:1306
int ENVMAP
References a map that is for environment mapping -Bobboau.
Definition: bmpman.cpp:59
void player_controls_init()
void ship_process_targeting_lasers()
Definition: ship.cpp:11611
void multi_df_debrief_init()
#define PHYSICS_VIEWER_REAR
Definition: physics.h:156
float vm_vec_dot(const vec3d *v0, const vec3d *v1)
Definition: vecmat.cpp:312
void multi_respawn_observer()
void event_music_level_close()
Definition: eventmusic.cpp:691
void multi_oo_gameplay_init()
Definition: multi_obj.cpp:1386
void main_hall_close()
#define i2fl(i)
Definition: floating.h:32
void fs2netd_spew_table_checksums(char *outfile)
#define STUB_FUNCTION
Definition: config.h:67
void cutscenes_screen_init()
Definition: cutscenes.cpp:447
GLint GLsizei count
Definition: Gl.h:1491
int View_percent
Definition: freespace.cpp:2546
int Cmdline_verify_vps
Definition: cmdline.cpp:506
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
int Players_target
Definition: sexp.cpp:853
#define KEY_UP
Definition: key.h:179
void oo_display()
Definition: multi_obj.cpp:2031
void game_stop_subspace_ambient_sound()
Definition: freespace.cpp:8037
const float PI_2
Definition: pstypes.h:307
int Cmdline_show_pos
Definition: cmdline.cpp:498
float frametotal
Definition: freespace.cpp:246
int Show_mem
Definition: freespace.cpp:253
int modelstats_num_verts
Definition: modelinterp.cpp:47
fix Last_delta_time
Definition: freespace.cpp:4550
void multi_standalone_postgame_close()
Definition: multi.cpp:1736
int Key_normal_game
Definition: key.cpp:101
void HUD_fixed_printf(float duration, color col, const char *format,...)
Definition: hudmessage.cpp:470
#define CHA_MISSIONSTART
Definition: scripting.h:55
void multi_standalone_wait_do()
Definition: multi.cpp:1663
int game_get_default_skill_level()
Definition: freespace.cpp:543
GLenum GLsizei len
Definition: Glext.h:6283
void ship_self_destruct(object *objp)
Definition: shiphit.cpp:1697
void timer_init()
Definition: timer.cpp:55
object * Player_obj
Definition: object.cpp:56
void message_queue_process()
void player_save_target_and_weapon_link_prefs()
void mouse_get_real_pos(int *mx, int *my)
Definition: mouse.cpp:589
void loop_brief_close()
#define FS_VERSION_BUILD
Definition: version.h:39
void particle_init()
Definition: particle.cpp:47
int GL_textures_in
int Game_font
Definition: freespace.cpp:270
uint flags2
Definition: ship.h:645
void iff_init()
Definition: iff_defs.cpp:117
uint load_gl_init
Definition: freespace.cpp:941
#define SF_DYING
Definition: ship.h:447
void game_shutdown(void)
Definition: freespace.cpp:7275
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
Definition: console.cpp:358
int Ai_firing_enabled
Definition: aicode.cpp:194
void freespace_stop_mission()
Definition: freespace.cpp:1069
polymodel * pm
Definition: lua.cpp:1598
void game_do_dc_networking()
Definition: freespace.cpp:4846
#define PCM_WARPOUT_STAGE3
Definition: player.h:61
void gr_create_shader(shader *shade, ubyte r, ubyte g, ubyte b, ubyte c)
Definition: 2d.cpp:1211
bool ls_force_off
void windebug_memwatch_init()
Definition: windebug.cpp:1645
void multi_oo_rate_init_all()
Definition: multi_obj.cpp:1668
void multi_pause_init()
#define MAX(a, b)
Definition: pstypes.h:299
Definition: camera.h:18
void HUD_printf(const char *format,...)
Definition: hudmessage.cpp:527
SCP_vector< object * > transparent_objects
Definition: objectsort.cpp:108
void game_loading_callback_init()
Definition: freespace.cpp:1228
#define VM_OTHER_SHIP
Definition: systemvars.h:35
camid chase_get_camera()
Definition: freespace.cpp:3334
big_expl_flash Big_expl_flash
Definition: freespace.cpp:515
#define PLAYER_FLAGS_IS_MULTI
Definition: player.h:42
float Timing_render2
Definition: freespace.cpp:2085
void UnloadImages()
Definition: scripting.cpp:838
void subtitles_do_frame_post_shaded(float frametime)
Definition: camera.cpp:1028
char filename[MAX_FILENAME_LEN]
Definition: generic.h:18
void os_close()
Definition: freespace.cpp:5080
void batch_render_distortion_map_bitmaps(int buffer_handle)
Definition: grbatch.cpp:1245
void game_level_close()
Definition: freespace.cpp:876
int ship_name_lookup(const char *name, int inc_players)
Definition: ship.cpp:12900
void cmd_brief_pause()
void credits_close()
Definition: credits.cpp:643
waypoint * find_waypoint_at_index(waypoint_list *list, int index)
Definition: waypoint.cpp:307
int Warpout_sound
Definition: freespace.cpp:233
char envmap_name[MAX_FILENAME_LEN]
Definition: missionparse.h:149
void multi_pxo_close()
Definition: multi_pxo.cpp:1325
void ParseClassInfo(char *section)
Definition: wmcgui.cpp:142
#define GM_NORMAL
Definition: systemvars.h:19
void pause_debug_close()
void snd_spew_debug_info()
Definition: sound.cpp:212
fix Last_time
Definition: freespace.cpp:4549
int Snd_sram
Definition: sound.cpp:52
void mission_load_menu_do()
void pilot_load_pic_list()
float radius
Definition: object.h:154
#define SEXP_KNOWN_FALSE
Definition: sexp.h:921
void snd_do_frame()
Definition: sound.cpp:1411
void brief_parse_icon_tbl()
void launch_context_help()
void snd_stop(int sig)
Definition: sound.cpp:875
void _cdecl gr_printf_no_resize(int x, int y, const char *format,...)
Definition: font.cpp:342
mission The_mission
char * Cmdline_mod
Definition: cmdline.cpp:397
int supernova_active()
Definition: supernova.cpp:240
void audiostream_pause_all(bool via_sexp_or_script=false)
Definition: audiostr.cpp:1978
#define CUB_GRADUAL
Definition: systemvars.h:54
void shipfx_flash_init()
Definition: shipfx.cpp:1216
int Om_tracker_flag
int cfclose(CFILE *cfile)
Definition: cfile.cpp:895
#define VM_CHASE
Definition: systemvars.h:34
void * HANDLE
Definition: config.h:106
#define KEY_PAD2
Definition: key.h:158
void game_training_pause_do()
Definition: freespace.cpp:2523
#define gr_flash_alpha
Definition: 2d.h:814
void ship_close()
Definition: ship.cpp:14146
void multi_df_debrief_close()
void neb2_level_close()
Definition: neb.cpp:432
void do_frame(float in_frametime)
Definition: camera.cpp:492
float h
Definition: pstypes.h:111
void gr_set_font(int fontnum)
Definition: font.cpp:566
int turret_enemy_objnum
Definition: ship.h:337
int model_num
Definition: lua.cpp:4996
GLclampf GLclampf GLclampf alpha
Definition: Glext.h:5177
void game_show_eye_pos(camid cid)
Definition: freespace.cpp:2368
int bm_make_render_target(int width, int height, int flags)
Creates a render target as close to the desired resolution as possible.
Definition: bmpman.cpp:2267
void stars_init()
Definition: starfield.cpp:693
void bm_unload_all()
Unloads all used bitmaps, should only ever be called by game_shutdown()
Definition: bmpman.cpp:2952
int Ai_render_debug_flag
Definition: ship.cpp:113
int Show_waypoints
Definition: object.cpp:73
void obj_snd_level_init()
Definition: objectsnd.cpp:191
int rendering_to_texture
Definition: 2d.h:403
char type
Definition: object.h:146
void hud_render_preprocess(float frametime)
Render gauges that need to be between a g3_start_frame() and a g3_end_frame()
Definition: hud.cpp:1580
void compute_slew_matrix(matrix *orient, angles *a)
Definition: ship.cpp:6546
#define FF_SCALE
Definition: freespace.cpp:3099
void multi_game_client_setup_close()
Definition: multiui.cpp:6851
void red_alert_bash_wingman_status()
Definition: redalert.cpp:817
vec3d vmd_zero_vector
Definition: vecmat.cpp:24
void main_hall_stop_music(bool fade)
void apply_view_shake(matrix *eye_orient)
Definition: freespace.cpp:3102
void sim_room_close()
Definition: readyroom.cpp:1116
#define MOVIE_PRE_CMD_BRIEF
Definition: missionparse.h:117
int Game_no_clear
Definition: freespace.cpp:212
#define FS_CDROM_VOLUME_1
Definition: freespace.h:29
void gr_set_shader(shader *shade)
Definition: 2d.cpp:1220
#define FALSE
Definition: pstypes.h:400
void multi_create_game_do()
Definition: multiui.cpp:3652
int Game_builtin_mission_count
Definition: freespace.cpp:344
void mission_brief_common_reset()
int sound_env_disable()
Definition: sound.cpp:1389
float tst_y
Definition: freespace.cpp:2654
int multi_find_player_by_object(object *objp)
Definition: multiutil.cpp:500
#define gr_set_gamma
Definition: 2d.h:829
char filename[FILESPEC_LENGTH]
Definition: model.h:734
int cf_get_file_list(SCP_vector< SCP_string > &list, int pathtype, const char *filter, int sort=CF_SORT_NONE, SCP_vector< file_list_info > *info=NULL)
void player_tips_init()
void control_config_clear_used_status()
void multi_rate_display(int np_index, int x, int y)
char Fred_alt_names[MAX_SHIPS][NAME_LENGTH+1]
Definition: freespace.cpp:304
bool dc_maybe_stuff_float(float *f)
Tries to stuff a float from the Command_string.
#define MAX_NAME_LEN
Definition: model.h:29
int Debug_dump_trigger
Definition: freespace.cpp:329
void game_show_event_debug(float frametime)
Definition: freespace.cpp:7635
bool IsConditionOverride(int action, object *objp=NULL)
Definition: scripting.cpp:938
net_player Net_players[MAX_PLAYERS]
Definition: multi.cpp:93
void game_set_view_clip(float frametime)
Definition: freespace.cpp:2587
int Cmdline_reparse_mainhall
Definition: cmdline.cpp:510
#define SetCurrentDirectory(s)
Definition: config.h:223
debug_command dc_a("a","shortcut for ai_pause", dcf_ai_pause)
int timer_get_milliseconds()
Definition: timer.cpp:150
int Use_fullscreen_at_startup
Definition: freespace.cpp:237
void gameseq_post_event(int event)
void multi_ts_do()
void main_hall_init(const SCP_string &main_hall_name)
int Cmdline_multi_stream_chat_to_file
Definition: cmdline.cpp:276
void gamesnd_close()
Definition: gamesnd.cpp:1141
int Sun_drew
Definition: freespace.cpp:668
void hud_set_iff_color(object *objp, int is_bright)
Will set the color to the IFF color based on the team.
Definition: hud.cpp:2950
void training_mission_init()
float distance
Definition: systemvars.h:79
#define SUN_DIMINISH_RATE
Definition: freespace.cpp:666
#define GM_CAMPAIGN_MODE
Definition: systemvars.h:29
void game_unpause()
Definition: freespace.cpp:8832
void game_level_init()
Definition: freespace.cpp:950
#define stricmp(s1, s2)
Definition: config.h:271
#define OBJ_JUMP_NODE
Definition: object.h:45
void vm_vec_add(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:159
#define MOVIE_PRE_BRIEF
Definition: missionparse.h:118
const GLdouble * v
Definition: Glext.h:5322
void gr_init_color(color *c, int r, int g, int b)
Definition: 2d.cpp:1155
void obj_move_all(float frametime)
Definition: object.cpp:1383
int Select_default_ship
char Multi_tracker_login[MULTI_TRACKER_STRING_LEN+1]
Definition: multi.cpp:143
float Warpout_time
Definition: freespace.cpp:231
ship is warping out in 3rd person
Definition: gamesnd.h:118
matrix vmd_identity_matrix
Definition: vecmat.cpp:28
void pause_do()
void awacs_level_init()
Definition: awacs.cpp:67
multi_global_options Multi_options_g
#define CF_TYPE_MODELS
Definition: cfile.h:49
int popupdead_do_frame(float frametime)
Definition: popupdead.cpp:410
void cmd_brief_unhold()
#define CD_SIZE_72_MINUTE_MAX
Definition: freespace.cpp:8063
int popupdead_is_active()
Definition: popupdead.cpp:538
int flags
Definition: multi.h:495
void mouse_mark_button(uint flags, int set)
Definition: mouse.cpp:156
char ship_name[NAME_LENGTH]
Definition: ship.h:604
void multi_display_netinfo()
Definition: multi.cpp:1787
int id
Definition: sound.h:92
fix fixmul(fix a, fix b)
Definition: fix.cpp:22
void techroom_init()
Definition: techmenu.cpp:1102
void techroom_do_frame(float frametime)
Definition: techmenu.cpp:1269
void script_init()
Definition: scripting.cpp:188
void key_init()
Definition: key.cpp:864
int modelstats_num_sortnorms
Definition: modelinterp.cpp:48
#define DEBUG_GET_TIME(x)
Definition: freespace.cpp:4322
float VIEWER_ZOOM_DEFAULT
Definition: camera.cpp:15
#define MAX_SHIP_CLASSES_MULTI
Definition: globals.h:46
int myrand()
Definition: systemvars.cpp:102
#define KEY_F3
Definition: key.h:145
void mouse_flush()
Definition: mouse.cpp:221
void model_set_detail_level(int n)
float Sun_spot
Definition: freespace.cpp:514
void event_music_first_pattern()
Definition: eventmusic.cpp:648
cmission missions[MAX_CAMPAIGN_MISSIONS]
void mission_hotkey_set_defaults()
void load_filter_info(void)
Definition: outwnd.cpp:167
int first_child
Definition: model.h:361
void beam_level_close()
Definition: beam.cpp:273
#define fl2f(fl)
Definition: floating.h:38
int n_detail_levels
Definition: model.h:737
#define MISSION_FLAG_SUBSPACE
Definition: missionparse.h:68
int Debug_dump_frame_count
Definition: freespace.cpp:330
#define MAX_BURST_DAMAGE
Definition: ai.h:572
int Main_hall_netgame_started
Definition: freespace.cpp:5882
void glowpoint_init()
Definition: modelread.cpp:5779
int Show_cpu
Definition: freespace.cpp:267
float b
Definition: pstypes.h:111
void std_set_standalone_fps(float fps)
GLint y
Definition: Gl.h:1505
void mission_show_goals_init()
void gameseq_set_state(int new_state, int override)
int Game_do_state_should_skip
Definition: freespace.cpp:6445
void credits_init()
Definition: credits.cpp:420
int cfile_init(const char *exe_dir, const char *cdrom_dir)
Initialize the cfile system. Called once at application start.
Definition: cfile.cpp:183
int current_target_is_locked
Definition: ai.h:490
int jx
int Show_target_weapons
Definition: freespace.cpp:269
bool Cmdline_benchmark_mode
Definition: cmdline.cpp:514
#define NG_TYPE_DOGFIGHT
Definition: multi.h:651
void multi_start_game_close()
Definition: multiui.cpp:2476
void game_flash_reset()
Definition: freespace.cpp:549
#define g3_start_frame(zbuffer_flag)
Definition: 3d.h:39
scoring_struct stats
Definition: player.h:127
void subtitles_close()
Definition: camera.cpp:1013
int Event_debug_index[EVENT_DEBUG_MAX]
Definition: freespace.cpp:7597
void setup_environment_mapping(camid cid)
Definition: freespace.cpp:3190
bool dc_maybe_stuff_string_white(char *str, size_t len)
Tries to stuff a whitespace delimited string to out_str from the command line, stopping at the end of...
bool IsOverride(script_hook &hd)
Definition: scripting.cpp:1414
#define gr_zbuffer_clear
Definition: 2d.h:818
float vm_vec_normalize(vec3d *v)
Definition: vecmat.cpp:460
int Player_num
#define strcpy_s(...)
Definition: safe_strings.h:67
void init_multiplayer_stats()
Definition: stats.cpp:308
#define gr_print_screen
Definition: 2d.h:735
void player_repair_frame(float frametime)
Definition: freespace.cpp:2833
int Is_standalone
Definition: systemvars.cpp:59
void os_sleep(int ms)
Definition: osapi.cpp:232
int main(int argc, char *argv[])
Definition: freespace.cpp:7169
int Warpout_forced
Definition: freespace.cpp:232
int Fade_start_timestamp
Definition: systemvars.cpp:41
int Game_sound_env_update_timestamp
Definition: freespace.cpp:525
float Game_hit_y
Definition: freespace.cpp:3055
void ship_level_init()
Definition: ship.cpp:5226
void multi_host_options_close()
Definition: multiui.cpp:6015
#define UNINITIALIZED
Definition: pstypes.h:30
void render_environment(int i, vec3d *eye_pos, matrix *new_orient, float new_zoom)
Definition: freespace.cpp:3169
#define LAUNCHER_FNAME
Definition: freespace.cpp:227
void HUD_set_offsets(object *viewer_obj, int wiggedy_wack, matrix *eye_orient)
Set the offset values for this render frame.
Definition: hud.cpp:3536
int cfseek(CFILE *fp, int offset, int where)
GLint left
Definition: Glext.h:7283
void mission_show_goals_close()