2 * $Logfile: /Freespace2/code/GlobalIncs/SystemVars.cpp $
7 * Variables and constants common to FreeSpace and Fred.
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 12 9/09/99 8:53p Dave
15 * Fixed multiplayer degenerate orientation case problem. Make sure warp
16 * effect never goes lower than LOD 1.
18 * 11 9/06/99 11:25a Mikek
19 * Decrease some settings for High detail level.
21 * 10 8/05/99 2:05a Dave
24 * 9 7/29/99 10:47p Dave
25 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
27 * 8 7/29/99 12:05a Dave
28 * Nebula speed optimizations.
30 * 7 6/22/99 7:03p Dave
31 * New detail options screen.
33 * 6 6/16/99 4:06p Dave
34 * New pilot info popup. Added new draw-bitmap-as-poly function.
36 * 5 5/24/99 5:45p Dave
37 * Added detail levels to the nebula, with a decent speedup. Split nebula
38 * lightning into its own section.
40 * 4 11/30/98 1:07p Dave
41 * 16 bit conversion, first run.
43 * 3 10/07/98 6:27p Dave
44 * Globalized mission and campaign file extensions. Removed Silent Threat
45 * special code. Moved \cache \players and \multidata into the \data
48 * 2 10/07/98 10:52a Dave
51 * 1 10/07/98 10:48a Dave
53 * 38 9/21/98 8:46p Dave
54 * Put in special check in fred for identifying unknown ships.
56 * 37 8/17/98 5:07p Dave
57 * First rev of corkscrewing missiles.
59 * 36 5/13/98 11:34p Mike
60 * Model caching system.
62 * 35 4/25/98 4:06p John
63 * Made defaults make a little more sense
65 * 34 4/20/98 8:41p John
66 * Made debris culling actually reduce Glide texture resolution.
68 * 33 4/12/98 9:56a John
69 * Made lighting detail flags work. Made explosions cast light on
72 * 32 4/08/98 8:34p Lawrance
73 * Fix up how custom button works on the detail tab.
75 * 31 4/01/98 5:34p John
76 * Made only the used POFs page in for a level. Reduced some interp
77 * arrays. Made custom detail level work differently.
79 * 30 3/31/98 5:18p John
80 * Removed demo/save/restore. Made NDEBUG defined compile. Removed a
81 * bunch of debug stuff out of player file. Made model code be able to
82 * unload models and malloc out only however many models are needed.
85 * 29 3/30/98 2:38p Mike
86 * Add asteroid_density to detail level support.
87 * No force explosion damage in training missions.
88 * Make cargo deathrolls shorter.
90 * 28 3/24/98 8:16a John
91 * made highest detail different than next one down
93 * 27 3/23/98 5:19p John
94 * Upped number of default detail levels to 4
96 * 26 3/22/98 4:11p Andsager
97 * Remove global Freespace_running
99 * 25 3/22/98 3:28p John
100 * Added in stippled alpha for lower details. Made medium detail use
103 * 24 3/22/98 2:41p John
104 * Added lighting into the detail structure.
106 * 23 3/22/98 11:06a John
107 * Changed default detail levels
109 * 22 3/22/98 11:02a John
110 * Made a bunch of the detail levels actually do something
112 * 21 3/22/98 9:53a John
113 * Added in first stage of new detail level stuff
115 * 20 3/09/98 12:13a Andsager
116 * Add code to help find jumps in position.
118 * 19 2/28/98 7:03p Lawrance
119 * get slew working in any view
121 * 18 2/16/98 4:16p John
122 * Added loading animation
124 * 17 2/10/98 9:06a John
125 * Added variables for restoring
127 * 16 2/05/98 9:27p John
128 * took out ending min/max etc on monitor
130 * 15 2/05/98 9:21p John
131 * Some new Direct3D code. Added code to monitor a ton of stuff in the
134 * 14 2/03/98 9:25p John
135 * Upgraded Direct3D code to new version 5.0 code. Separated the D3D code
136 * more. Added a global variable D3D_enabled flag.
138 * 13 1/17/98 12:17p John
139 * fixed erroneous print
141 * 12 1/17/98 12:14p John
142 * Added loading... bar to freespace.
144 * 11 1/11/98 2:15p John
145 * Changed a lot of stuff that had to do with bitmap loading. Made cfile
146 * not do callbacks, I put that in global code. Made only bitmaps that
147 * need to load for a level load.
149 * 10 12/16/97 6:20p Hoffoss
150 * Added more debugging code for demos, and fixed a bug in demo
151 * recording/playback.
153 * 9 12/05/97 3:46p John
154 * made ship thruster glow scale instead of being an animation.
156 * 8 8/05/97 10:18a Lawrance
157 * my_rand() being used temporarily instead of rand()
159 * 7 8/04/97 10:21a Dave
160 * Added Is_standalone global var
162 * 6 6/24/97 6:21p John
163 * added detail flags.
164 * sped up motion debris system a bit.
166 * 5 4/15/97 11:28p Mike
167 * External view system
169 * 4 4/15/97 4:00p Mike
170 * Intermediate checkin caused by getting other files. Working on camera
173 * 3 4/08/97 8:47a John
174 * Added a global varible for detail level
176 * 2 4/01/97 11:07p Mike
177 * Clean up game sequencing functions. Get rid of Multiplayer and add
178 * Game_mode. Add SystemVars.cpp
180 * 1 4/01/97 10:59p Mike
186 #include "systemvars.h"
196 int Game_restoring = 0; // If set, this means we are restoring data from disk
198 int Viewer_mode; // Viewer's mode, see VM_xxxx flags.
200 // The detail level. Anything below zero draws simple models earlier than it
201 // should. Anything above zero draws higher detail models longer than it should.
207 int Game_detail_level = 0;
208 uint Game_detail_flags = DETAIL_DEFAULT; // see systemvars.h for explanation
210 angles Viewer_slew_angles; // Angles of viewer relative to forward.
211 vei Viewer_external_info; // Viewer angles to ship in external view.
212 vci Viewer_chase_info; // View chase camera information
217 int Interface_last_tick = -1; // last timer tick on flip
219 // for notifying players of unknown ship types
220 int Fred_found_unknown_ship_during_parsing = 0;
222 // If true, then we are using Direct3D hardware. This is used for game type stuff
223 // that changes when you're using hardware.
226 // Values used for noise for thruster animations
227 float Noise[NOISE_NUM_FRAMES] = {
251 // nprintf(("Alan","RAND: %d\n", rval));
256 // Variables for the loading callback hooks
257 static int cf_timestamp = -1;
258 static void (*cf_callback)(int count) = NULL;
259 static int cf_in_callback = 0;
260 static int cb_counter = 0;
261 static int cb_last_counter = 0;
262 static int cb_delta_step = -1;
264 // Call this with the name of a function. That function will
265 // then get called around 10x per second. The callback function
266 // gets passed a 'count' which is how many times game_busy has
267 // been called since the callback was set. It gets called
268 // one last time with count=-1 when you turn off the callback
269 // by calling game_busy_callback(NULL). Game_busy_callback
270 // returns the current count, so you can tell how many times
271 // game_busy got called.
272 int game_busy_callback( void (*callback)(int count), int delta_step )
276 // Call it once more to finalize things
286 cb_delta_step = delta_step;
287 cf_timestamp = timer_get_milliseconds()+(1000/10);
288 cf_callback = callback;
292 (*cf_callback)(0); // pass 0 first time!
300 // Call whenever loading to display cursor
303 if ( cf_in_callback != 0 ) return; // don't call callback if we're already in it.
304 if ( cf_timestamp < 0 ) return;
305 if ( !cf_callback ) return;
309 // mprintf(( "CB_COUNTER=%d\n", cb_counter ));
311 int t1 = timer_get_milliseconds();
313 if ( (t1 > cf_timestamp) || ((cb_counter>cb_last_counter+155)&&(cb_delta_step>0)) ) {
314 cb_last_counter = cb_counter;
316 (*cf_callback)(cb_counter);
318 cf_timestamp = t1 + +(1000/10);
322 //======================== CODE TO MONITOR EVENTS ======================
326 #define MAX_MONITORS 64
328 static int Num_monitors = 0;
329 static monitor *Monitor[MAX_MONITORS];
331 monitor::monitor( char *_name )
335 if ( Num_monitors >= MAX_MONITORS ) {
336 Int3(); // Too many monitor variables!! Increase MAX_MONITORS!!
340 for (i=0; i<Num_monitors; i++ ) {
341 int ret = stricmp( Monitor[i]->name, _name );
344 Int3(); // This monitor variable already exists!!!!
346 } else if ( ret > 0 ) {
347 break; // Insert it here
349 } else if ( ret < 0 ) {
354 if ( i < Num_monitors ) {
355 // Insert it at element i
357 for (j=Num_monitors; j>i; j-- ) {
358 Monitor[j] = Monitor[j-1];
363 Monitor[Num_monitors] = this;
372 int Monitor_inited = 0;
373 char Monitor_filename[128];
374 fix monitor_last_time = -1;
376 DCF(monitor,"Monitors game performace")
379 dc_get_arg(ARG_STRING|ARG_NONE);
380 if ( Dc_arg_type == ARG_NONE ) {
381 if ( Monitor_inited ) {
385 FILE *fp = fopen( Monitor_filename, "at" );
387 fprintf( fp, "\n\n" );
388 fprintf( fp, "Name\tMin\tMax\tAvg\n" );
389 for (int i=0; i<Num_monitors; i++ ) {
390 if ( Monitor[i]->cnt > 0 ) {
391 fprintf( fp, "%s\t%d\t%d\t%d\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max, Monitor[i]->sum / Monitor[i]->cnt );
393 fprintf( fp, "%s\t%d\t%d\t?\n", Monitor[i]->name, Monitor[i]->min, Monitor[i]->max );
400 dc_printf( "Monitor to file '%s' turned off\n", Monitor_filename );
402 dc_printf( "Monitor isn't on\n" );
405 if ( Monitor_inited ) {
406 dc_printf( "Monitor already on\n" );
410 strcpy( Monitor_filename, Dc_arg );
414 for (i=0; i<Num_monitors; i++ ) {
415 Monitor[i]->value = 0;
422 FILE *fp = fopen( Monitor_filename, "wt" );
424 for (i=0; i<Num_monitors; i++ ) {
428 fprintf( fp, "%s", Monitor[i]->name );
434 dc_printf( "Monitor outputting to file '%s'\n", Monitor_filename );
435 monitor_last_time = -1;
440 dc_printf( "Usage: monitor filename\nOutputs monitoring info to filename. No filename turns it off\n" );
446 MONITOR(FrameRateX100);
448 void monitor_update()
453 fix this_time = timer_get_fixed_seconds();
456 if ( monitor_last_time != -1 ) {
457 frametime = this_time - monitor_last_time;
462 if ( frametime > 0 ) {
463 MONITOR_INC(FrameRateX100, (F1_0*100) / frametime );
465 MONITOR_INC(FrameRateX100, 0 );
469 if ( !Monitor_inited ) {
473 if ( frametime != 0 ) {
474 fp = fopen( Monitor_filename, "at" );
477 for (i=0; i<Num_monitors; i++ ) {
478 if (i>0) fprintf( fp, "\t" );
479 fprintf( fp, "%d", Monitor[i]->value );
485 for (i=0; i<Num_monitors; i++ ) {
488 Monitor[i]->sum += Monitor[i]->value;
490 if ( (Monitor[i]->cnt < 1) || (Monitor[i]->value < Monitor[i]->min )) {
491 Monitor[i]->min = Monitor[i]->value;
494 if ( (Monitor[i]->cnt < 1) || (Monitor[i]->value > Monitor[i]->max )) {
495 Monitor[i]->max = Monitor[i]->value;
501 Monitor[i]->value = 0;
504 for (i=0; i<Num_monitors; i++ ) {
506 Monitor[i]->value = 0;
510 monitor_last_time = timer_get_fixed_seconds();
516 #if MAX_DETAIL_LEVEL != 4
517 #error MAX_DETAIL_LEVEL is assumed to be 4 in SystemVars.cpp
520 #if NUM_DEFAULT_DETAIL_LEVELS != 4
521 #error NUM_DEFAULT_DETAIL_LEVELS is assumed to be 4 in SystemVars.cpp
524 // Detail level stuff
525 detail_levels Detail_defaults[NUM_DEFAULT_DETAIL_LEVELS] = {
528 // ===== Analogs (0-MAX_DETAIL_LEVEL) ====
529 0, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
530 0, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
531 0, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
532 0, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
533 0, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
534 0, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
535 0, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
536 2, // lighting; // 0=min, MAX_DETAIL_LEVEL=max
538 // ==== Booleans ====
539 0, // targetview_model; // 0=off, 1=on
540 0, // planets_suns; // 0=off, 1=on
545 // ===== Analogs (0-MAX_DETAIL_LEVEL) ====
546 1, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
547 1, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
548 1, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
549 2, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
550 2, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
551 2, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
552 1, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
553 3, // lighting; // 0=min, MAX_DETAIL_LEVEL=max
555 // ==== Booleans ====
556 1, // targetview_model; // 0=off, 1=on
557 1, // planets_suns; // 0=off, 1=on
562 // ===== Analogs (0-MAX_DETAIL_LEVEL) ====
563 2, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
564 3, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
565 3, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
566 3, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
567 3, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
568 4, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
569 3, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
570 4, // lighting; // 0=min, MAX_DETAIL_LEVEL=max
572 // ==== Booleans ====
573 1, // targetview_model; // 0=off, 1=on
574 1, // planets_suns; // 0=off, 1=on
579 // ===== Analogs (0-MAX_DETAIL_LEVEL) ====
580 3, // nebula_detail; // 0=lowest detail, MAX_DETAIL_LEVEL=highest detail
581 3, // detail_distance; // 0=lowest MAX_DETAIL_LEVEL=highest
582 4, // hardware_textures; // 0=max culling, MAX_DETAIL_LEVEL=no culling
583 4, // num_small_debris; // 0=min number, MAX_DETAIL_LEVEL=max number
584 3, // num_particles; // 0=min number, MAX_DETAIL_LEVEL=max number
585 4, // num_stars; // 0=min number, MAX_DETAIL_LEVEL=max number
586 4, // shield_effects; // 0=min, MAX_DETAIL_LEVEL=max
587 4, // lighting; // 0=min, MAX_DETAIL_LEVEL=max
589 // ==== Booleans ====
590 1, // targetview_model; // 0=off, 1=on
591 1, // planets_suns; // 0=off, 1=on
597 // Global used to access detail levels in game and libs
598 detail_levels Detail = Detail_defaults[NUM_DEFAULT_DETAIL_LEVELS-1];
602 // NUM_DETAIL_LEVELS - highest
603 // To set the parameters in Detail to some set of defaults
604 void detail_level_set(int level)
610 Assert( level >= 0 );
611 Assert( level < NUM_DEFAULT_DETAIL_LEVELS );
613 Detail = Detail_defaults[level];
615 // reset nebula stuff
616 neb2_set_detail_level(level);
619 // Returns the current detail level or -1 if custom.
620 int current_detail_level()
622 // return Detail.setting;
625 for (i=0; i<NUM_DEFAULT_DETAIL_LEVELS; i++ ) {
626 if ( memcmp( &Detail, &Detail_defaults[i], sizeof(detail_levels) )==0 ) {
634 DCF(detail_level,"Change the detail level")
637 dc_get_arg(ARG_INT|ARG_NONE);
638 if ( Dc_arg_type & ARG_NONE ) {
639 Game_detail_level = 0;
640 dc_printf( "Detail level reset\n" );
642 if ( Dc_arg_type & ARG_INT ) {
643 Game_detail_level = Dc_arg_int;
648 dc_printf( "Usage: detail_level [n]\nn is detail level. 0 normal, - lower, + higher, -2 to 2 usually\nNo parameter resets it to default.\n" );
651 dc_printf("Detail level set to %d\n", Game_detail_level);
654 DCF(detail, "Turns on/off parts of the game for speed testing" )
657 dc_get_arg(ARG_INT|ARG_NONE);
658 if ( Dc_arg_type & ARG_NONE ) {
659 if ( Game_detail_flags == DETAIL_DEFAULT ) {
660 Game_detail_flags = DETAIL_FLAG_CLEAR;
661 dc_printf( "Detail flags set lowest (except has screen clear)\n" );
663 Game_detail_flags = DETAIL_DEFAULT;
664 dc_printf( "Detail flags set highest\n" );
667 if ( Dc_arg_type & ARG_INT ) {
668 Game_detail_flags ^= Dc_arg_int;
673 dc_printf( "Usage: detail [n]\nn is detail bit to toggle.\n" );
674 dc_printf( " 1: draw the stars\n" );
675 dc_printf( " 2: draw the nebulas\n" );
676 dc_printf( " 4: draw the motion debris\n" );
677 dc_printf( " 8: draw planets\n" );
678 dc_printf( " 16: draw models not as blobs\n" );
679 dc_printf( " 32: draw lasers not as pixels\n" );
680 dc_printf( " 64: clear screen background after each frame\n" );
681 dc_printf( " 128: draw hud stuff\n" );
682 dc_printf( " 256: draw fireballs\n" );
683 dc_printf( " 512: do collision detection\n" );
687 dc_printf("Detail flags set to 0x%08x\n", Game_detail_flags);
688 dc_printf( " 1: draw the stars: %s\n", (Game_detail_flags&1?"on":"off") );
689 dc_printf( " 2: draw the nebulas: %s\n", (Game_detail_flags&2?"on":"off") );
690 dc_printf( " 4: draw the motion debris: %s\n", (Game_detail_flags&4?"on":"off") );
691 dc_printf( " 8: draw planets: %s\n", (Game_detail_flags&8?"on":"off") );
692 dc_printf( " 16: draw models not as blobs: %s\n", (Game_detail_flags&16?"on":"off") );
693 dc_printf( " 32: draw lasers not as pixels: %s\n", (Game_detail_flags&32?"on":"off") );
694 dc_printf( " 64: clear screen background after each frame: %s\n", (Game_detail_flags&64?"on":"off") );
695 dc_printf( " 128: draw hud stuff: %s\n", (Game_detail_flags&128?"on":"off") );
696 dc_printf( " 256: draw fireballs: %s\n", (Game_detail_flags&256?"on":"off") );
697 dc_printf( " 512: do collision detection: %s\n", (Game_detail_flags&512?"on":"off") );