2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/GlobalIncs/PsTypes.h $
15 * Header file containg global typedefs, constants and macros
18 * Revision 1.12 2005/10/01 21:38:32 taylor
19 * some reorg of includes to not requires the same headers in many different files
20 * handle FS1 specific language changes
21 * some OS X changes for paths and to handle socklen_t better
23 * Revision 1.11 2004/12/15 04:10:45 taylor
24 * outwnd_unix.cpp from fs2_open for logging to file in debug mode
25 * fixes for default function values
26 * always use vm_* functions for sanity sake
27 * make cfilearchiver 64-bit compatible
28 * fix crash on exit from double free()
29 * fix crash on startup from extra long GL extension string in debug
31 * Revision 1.10 2004/07/04 11:31:43 taylor
32 * amd64 support, compiler warning fixes, don't use software rendering
34 * Revision 1.9 2004/06/11 21:39:44 taylor
35 * x86 compile fixes for OSX patch
37 * Revision 1.8 2004/06/11 00:15:06 tigital
38 * byte-swapping changes for bigendian systems
40 * Revision 1.7 2002/07/13 19:47:02 theoddone33
41 * Fix some more warnings
43 * Change demo building, edit Makefile if you want the demo.
45 * Revision 1.6 2002/06/19 04:52:45 relnev
46 * MacOS X updates (Ryan)
48 * Revision 1.5 2002/06/17 06:33:08 relnev
49 * ryan's struct patch for gcc 2.95
51 * Revision 1.4 2002/06/09 04:41:14 relnev
52 * added copyright header
54 * Revision 1.3 2002/06/01 07:12:32 relnev
55 * a few NDEBUG updates.
57 * removed a few warnings.
59 * Revision 1.2 2002/05/28 06:28:20 theoddone33
60 * Filesystem mods, actually reads some data files now
62 * Revision 1.1.1.1 2002/05/03 03:28:12 root
66 * 34 6/16/00 3:16p Jefff
67 * sim of the year dvd version changes, a few german soty localization
70 * 33 10/05/99 2:29p Danw
72 * 32 10/01/99 9:10a Daveb
75 * 31 9/13/99 12:22a Dave
78 * 30 8/28/99 4:54p Dave
79 * Fixed directives display for multiplayer clients for wings with
80 * multiple waves. Fixed hud threat indicator rendering color.
82 * 29 8/09/99 4:18p Andsager
83 * Make french and german defines, needed specifically to enable language
84 * under launcher misc. tab
86 * 28 7/20/99 1:49p Dave
87 * Peter Drake build. Fixed some release build warnings.
89 * 27 7/18/99 5:19p Dave
90 * Jump node icon. Fixed debris fogging. Framerate warning stuff.
92 * 26 7/15/99 9:21a Andsager
95 * 25 7/09/99 9:51a Dave
96 * Added thick polyline code.
98 * 24 6/29/99 10:35a Dave
99 * Interface polygon bitmaps! Whee!
101 * 23 6/14/99 10:45a Dave
102 * Made beam weapons specify accuracy by skill level in the weapons.tbl
104 * 22 6/03/99 10:15p Dave
105 * Put in temporary main hall screen.
107 * 21 5/09/99 8:57p Dave
108 * Final E3 build preparations.
110 * 20 4/25/99 7:43p Dave
111 * Misc small bug fixes. Made sun draw properly.
113 * 19 4/25/99 3:03p Dave
114 * Removed E3_BUILD from pstypes
116 * 18 4/25/99 3:02p Dave
117 * Build defines for the E3 build.
119 * 17 4/15/99 1:29p Dave
120 * Remove multiplayer beta build define.
122 * 16 4/15/99 1:24p Dave
123 * Final Beta 1 checkin.
125 * 15 4/14/99 5:28p Dave
128 * 14 4/12/99 2:22p Dave
129 * More checks for dogfight stats.
131 * 13 4/09/99 2:21p Dave
132 * Multiplayer beta stuff. CD checking.
134 * 12 2/25/99 4:19p Dave
135 * Added multiplayer_beta defines. Added cd_check define. Fixed a few
136 * release build warnings. Added more data to the squad war request and
139 * 11 2/23/99 2:29p Dave
140 * First run of oldschool dogfight mode.
142 * 10 2/07/99 8:51p Andsager
143 * Add inner bound to asteroid field. Inner bound tries to stay astroid
144 * free. Wrap when within and don't throw at ships inside.
146 * 9 1/15/99 11:29a Neilk
147 * Fixed D3D screen/texture pixel formatting problem.
149 * 8 1/08/99 2:08p Dave
150 * Fixed software rendering for pofview. Super early support for AWACS and
153 * 7 1/06/99 2:24p Dave
154 * Stubs and release build fixes.
156 * 6 11/30/98 1:07p Dave
157 * 16 bit conversion, first run.
159 * 5 11/05/98 4:18p Dave
160 * First run nebula support. Beefed up localization a bit. Removed all
161 * conditional compiles for foreign versions. Modified mission file
164 * 4 10/13/98 9:28a Dave
165 * Started neatening up freespace.h. Many variables renamed and
166 * reorganized. Added AlphaColors.[h,cpp]
168 * 3 10/07/98 11:28a Dave
170 * 2 10/07/98 10:52a Dave
173 * 1 10/07/98 10:48a Dave
175 * 75 8/20/98 5:30p Dave
176 * Put in handy multiplayer logfile system. Now need to put in useful
177 * applications of it all over the code.
179 * 74 6/17/98 11:01a Lawrance
180 * set correct offset for English special font chars
182 * 73 6/12/98 4:52p Hoffoss
183 * Added support for special characters in in forgeign languages.
185 * 72 6/09/98 6:49p Lawrance
186 * Comment out UK_BUILD
188 * 71 6/09/98 5:15p Lawrance
189 * French/German localization
191 * 70 6/09/98 12:12p Hoffoss
192 * Added XSTR localization code.
194 * 69 6/05/98 9:49a Lawrance
197 * 68 5/22/98 3:13p Allender
198 * no Int3()'s and Asserts
200 * 67 5/20/98 12:59p John
201 * Turned optimizations on for debug builds. Also turning on automatic
202 * function inlining. Turned off the unreachable code warning.
204 * 66 5/04/98 1:49p Allender
205 * make Int3's do nothing when InterplayQA is defined
207 * 65 4/25/98 11:55p Lawrance
208 * compile out Int3() and SDL_assert() for release demo build
219 // Build defines. Comment in/out for whatever build is necessary:
220 // #define OEM_BUILD // enable for OEM builds
221 // #define MULTIPLAYER_BETA_BUILD // enable for multiplayer beta build
222 // #define E3_BUILD // enable for 3dfx E3 build
223 // #define PRESS_TOUR_BUILD // enable for press tour build
224 //#define FS2_DEMO // enable demo build for FS2
225 // #define PD_BUILD // fred documentation/evaluation build
226 // #define FRENCH_BUILD // build for French (obsolete)
227 // #define GERMAN_BUILD // build for German (this is now used)
228 //#define RELEASE_REAL // this means that it is an actual release candidate, not just an optimized/release build
230 // uncomment this #define for DVD version (makes popups say DVD instead of CD 2 or whatever): JCF 5/10/2000
231 // #define DVD_MESSAGE_HACK
234 #if defined(MULTIPLAYER_BETA_BUILD) || defined(E3_BUILD) || defined(RELEASE_REAL)
235 #define GAME_CD_CHECK
238 // 4127 is constant conditional (assert)
239 // 4100 is unreferenced formal parameters,
240 // 4514 is unreferenced inline function removed,
241 // 4201 is nameless struct extension used. (used by windows header files)
242 // 4410 illegal size for operand... ie... fxch st(1)
243 // 4611 is _setjmp warning. Since we use setjmp alot, and we don't really use constructors or destructors, this warning doesn't really apply to us.
244 // 4725 is the pentium division bug warning, and I can't seem to get rid of it, even with this pragma.
245 // JS: I figured out the disabling 4725 works, but not on the first function in the module.
246 // So to disable this, I add in a stub function at the top of each module that does nothing.
247 // 4710 is inline function not expanded (who cares?)
248 // 4711 tells us an inline function was expanded (who cares?)
249 // 4702 unreachable code. I care, but too many to deal with
250 // 4201 nonstandard extension used : nameless struct/union (happens a lot in Windows include headers)
251 // 4390 emptry control statement (triggered by nprintf and mprintf's inside of one-line if's, etc)
253 #pragma warning(disable: 4127 4100 4514 4201 4410 4611 4725 4710 4711 4702 4201 4390)
258 #include <stdio.h> // For NULL, etc
272 // value to represent an uninitialized state in any int or uint
273 #define UNINITIALIZED 0x7f8e6d9c
275 #if defined(DEMO) || defined(OEM_BUILD) // no change for FS2_DEMO
276 #define MAX_PLAYERS 1
278 #define MAX_PLAYERS 12
283 #define USE_INLINE_ASM 1 // Define this to use inline assembly
284 #define STRUCT_CMP(a, b) memcmp((void *) &a, (void *) &b, sizeof(a))
286 #define LOCAL static // make module local varilable static.
290 typedef Uint16 ushort;
292 typedef Sint32 fs_time_t; // forced 32-bit version of time_t - **don't use this unless required**
294 // ptr_? is a value matching the size of a pointer on this specific platform
295 #if ( defined(__x86_64__) || defined(_WIN64) )
296 typedef Sint64 ptr_s;
297 typedef Uint64 ptr_u;
299 typedef Sint32 ptr_s;
300 typedef Uint32 ptr_u;
303 #define HARDWARE_ONLY
305 //Stucture to store clipping codes in a word
306 typedef struct ccodes {
307 ubyte vor,vand; //or is low byte, and is high byte
310 typedef struct vector {
319 // A vector referenced as an array
320 typedef struct vectora {
324 typedef struct vec2d {
328 // Used for some 2d primitives, like gr_poly
329 typedef struct vert2df {
333 typedef struct angles {
337 typedef struct matrix {
340 vector rvec, uvec, fvec;
347 typedef struct uv_pair {
351 // Used to store rotated points for mines.
352 // Has flag to indicate if projected.
353 typedef struct vertex {
354 float x, y, z; // world space position
355 float sx, sy, sw; // screen space position (sw == 1/z)
356 float u, v; // texture position
357 ubyte r, g, b, a; // color. Use b for darkening;
358 ubyte codes; // what sides of view pyramid this point is on/off. 0 = Inside view pyramid.
359 ubyte flags; // Projection flags. Indicates whether it is projected or not or if projection overflowed.
360 ubyte pad[2]; // pad structure to be 4 byte aligned.
363 #define BMP_AABITMAP (1<<0) // antialiased bitmap
364 #define BMP_TEX_XPARENT (1<<1) // transparent texture
365 #define BMP_TEX_NONDARK (1<<2) // nondarkening texture
366 #define BMP_TEX_OTHER (1<<3) // so we can identify all "normal" textures
369 #define BMP_TEX_ANY ( BMP_TEX_XPARENT | BMP_TEX_NONDARK | BMP_TEX_OTHER )
371 // max res == 1024x768. max texture size == 256
372 #define MAX_BMAP_SECTIONS_X 4
373 #define MAX_BMAP_SECTIONS_Y 3
374 #define MAX_BMAP_SECTION_SIZE 256
375 typedef struct bitmap_section_info {
376 ushort sx[MAX_BMAP_SECTIONS_X]; // x offset of each section
377 ushort sy[MAX_BMAP_SECTIONS_Y]; // y offset of each section
379 ubyte num_x, num_y; // number of x and y sections
380 } bitmap_section_info;
382 typedef struct bitmap {
383 short w, h; // Width and height
384 short rowsize; // What you need to add to go to next row
385 ubyte bpp; // How many bits per pixel it is. (7,8,15,16,24,32)
386 ubyte flags; // See the BMP_???? defines for values
387 ptr_u data; // Pointer to data, or maybe offset into VRAM.
388 ubyte *palette; // If bpp==8, this is pointer to palette. If the BMP_NO_PALETTE_MAP flag
389 // is not set, this palette just points to the screen palette. (gr_palette)
391 bitmap_section_info sections;
394 //This are defined in MainWin.c
395 extern void __cdecl Error( const char * filename, int line, const char * format, ... );
396 extern void __cdecl Warning( const char * filename, int line, const char * format, ... );
400 // To debug printf do this:
401 // mprintf(( "Error opening %s\n", filename ));
403 #define mprintf(args) outwnd_printf2 args
404 #define nprintf(args) outwnd_printf args
406 #define mprintf(args)
407 #define nprintf(args)
410 #define LOCATION __FILE__,__LINE__
412 // To flag an error, you can do this:
413 // Error( __FILE__, __LINE__, "Error opening %s", filename );
415 // Error( LOCATION, "Error opening %s", filename );
418 #define STUB_FUNCTION
420 void gr_activate(int);
421 #define STUB_FUNCTION mprintf(("STUB: %s at %s, line %d, thread %d\n", __FUNCTION__, LOCATION, getpid()))
424 //#define Int3() _asm { int 3 }
427 // Interplay QA version of Int3
428 #define Int3() do { } while (0)
430 // define to call from Warning function above since it calls Int3, so without this, we
431 // get put into infinite dialog boxes
432 #define AsmInt3() _asm { int 3 }
436 // No debug version of Int3
437 #define Int3() do { } while (0)
441 // Debug version of Int3
442 #define Int3() debug_int3()
443 #endif // NDEBUG && DEMO
444 #endif // INTERPLAYQA
446 #define min(a,b) (((a) < (b)) ? (a) : (b))
447 #define max(a,b) (((a) > (b)) ? (a) : (b))
449 #define PI 3.141592654f
450 #define PI2 (3.141592654f*2.0f) // PI*2
451 #define ANG_TO_RAD(x) ((x)*PI/180)
454 extern int Fred_running; // Is Fred running, or FreeSpace?
455 extern int Pofview_running;
456 extern int Nebedit_running;
459 //======================================================================================
460 //====== D E B U G C O N S O L E S T U F F ========================
461 //======================================================================================
463 // Here is a a sample command to toggle something that would
464 // be called by doing "toggle it" from the debug console command window/
467 DCF(toggle_it,"description")
470 This_var = !This_var;
474 dc_printf( "Usage: sample\nToggles This_var on/off.\n" );
478 dc_printf( "The status is %d.\n", This_var );
482 class debug_command {
487 debug_command(const char *name, const char *help, void (*func)()); // constructor
490 #define DCF(function_name,help_text) \
491 void dcf_##function_name(); \
492 debug_command dc_##function_name(#function_name,help_text,dcf_##function_name); \
493 void dcf_##function_name()
495 // Starts the debug console
496 extern void debug_console( void (*func)() = NULL );
498 // The next three variables tell your function what to do. It should
499 // only change something if the dc_command is set. A minimal function
500 // needs to process the dc_command. Usually, these will be called in
501 // these combinations:
502 // dc_command=true, dc_status=true means process it and show status
503 // dc_help=true means show help only
504 // dc_status=true means show status only
505 // I would recommend doing this in each function:
506 // if (dc_command) { process command }
507 // if (dc_help) { print out help }
508 // if (dc_status) { print out status }
509 // with the last two being optional
511 extern int Dc_command; // If this is set, then process the command
512 extern int Dc_help; // If this is set, then print out the help text in the form, "usage: ... \nLong description\n" );
513 extern int Dc_status; // If this is set, then print out the current status of the command.
515 void dc_get_arg(uint flags); // Gets the next argument. If it doesn't match the flags, this function will print an error and not return.
516 extern char *Dc_arg; // The (lowercased) string value of the argument retrieved from dc_arg
517 extern char *Dc_arg_org; // Dc_arg before it got converted to lowercase
518 extern uint Dc_arg_type; // The type of dc_arg.
519 extern const char *Dc_command_line; // The rest of the command line, from the end of the last processed arg on.
520 extern int Dc_arg_int; // If Dc_arg_type & ARG_INT or ARG_HEX is set, then this is the value
521 extern float Dc_arg_float; // If Dc_arg_type & ARG_FLOAT is set, then this is the value
523 // Outputs text to the console
524 void dc_printf( const char *format, ... );
526 // Each dc_arg_type can have one or more of these flags set.
527 // This is because some things can fit into two catagories.
528 // Like 1 can be an integer, a float, a string, or a true boolean
530 #define ARG_NONE (1<<0) // no argument
531 #define ARG_ANY 0xFFFFFFFF // Anything.
532 #define ARG_STRING (1<<1) // any valid string
533 #define ARG_QUOTE (1<<2) // a quoted string
534 #define ARG_INT (1<<3) // a valid integer
535 #define ARG_FLOAT (1<<4) // a valid floating point number
537 // some specific commonly used predefined types. Can add up to (1<<31)
538 #define ARG_HEX (1<<5) // a valid hexadecimal integer. Note that ARG_INT will always be set also in this case.
539 #define ARG_TRUE (1<<6) // on, true, non-zero number
540 #define ARG_FALSE (1<<7) // off, false, zero
541 #define ARG_PLUS (1<<8) // Plus sign
542 #define ARG_MINUS (1<<9) // Minus sign
543 #define ARG_COMMA (1<<10) // a comma
545 // A shortcut for boolean only variables.
547 // DCF_BOOL( lighting, Show_lighting )
549 #define DCF_BOOL( function_name, bool_variable ) \
550 void dcf_##function_name(); \
551 debug_command dc_##function_name(#function_name,"Toggles "#bool_variable,dcf_##function_name ); \
552 void dcf_##function_name() { \
553 if ( Dc_command ) { \
554 dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE); \
555 if ( Dc_arg_type & ARG_TRUE ) bool_variable = 1; \
556 else if ( Dc_arg_type & ARG_FALSE ) bool_variable = 0; \
557 else if ( Dc_arg_type & ARG_NONE ) bool_variable ^= 1; \
559 if ( Dc_help ) dc_printf( "Usage: %s [bool]\nSets %s to true or false. If nothing passed, then toggles it.\n", #function_name, #bool_variable ); \
560 if ( Dc_status ) dc_printf( "%s is %s\n", #function_name, (bool_variable?"TRUE":"FALSE") ); \
564 //======================================================================================
565 //======================================================================================
566 //======================================================================================
568 inline int mul_div(int n, int num, int dem)
577 #include "floating.h"
579 // Some constants for stuff
580 #define MAX_FILENAME_LEN 32 // Length for filenames, ie "title.pcx"
581 #define MAX_PATH_LEN 128 // Length for pathnames, ie "c:\bitmaps\title.pcx"
583 // contants and defined for byteswapping routines (useful for mac)
585 #define INTEL_INT(x) SDL_SwapLE32(x)
586 #define INTEL_SHORT(x) SDL_SwapLE16(x)
587 #define INTEL_FLOAT(x) SDL_SwapFloatLE(x)
592 #define MY_RAND_MAX 0x7fff
597 // Callback Loading function.
598 // If you pass a function to this, that function will get called
599 // around 10x per second, so you can update the screen.
600 // Pass NULL to turn it off.
601 // Call this with the name of a function. That function will
602 // then get called around 10x per second. The callback function
603 // gets passed a 'count' which is how many times game_busy has
604 // been called since the callback was set. It gets called
605 // one last time with count=-1 when you turn off the callback
606 // by calling game_busy_callback(NULL). Game_busy_callback
607 // returns the current count, so you can tell how many times
608 // game_busy got called.
609 // If delta_step is above 0, then it will also make sure it
610 // calls the callback each time count steps 'delta_step' even
611 // if 1/10th of a second hasn't elapsed.
612 extern int game_busy_callback( void (*callback)(int count), int delta_step = -1 );
614 // Call whenever loading to display cursor
615 extern void game_busy();
618 //=========================================================
619 // Functions to monitor performance
625 int value; // Value that gets cleared to 0 each frame.
626 int min, max, sum, cnt; // Min & Max of value. Sum is used to calculate average
627 monitor(const char *name); // constructor
630 // Creates a monitor variable
631 #define MONITOR(function_name) monitor mon_##function_name(#function_name)
633 // Increments a monitor variable
634 #define MONITOR_INC(function_name,inc) do { mon_##function_name.value+=(inc); } while(0)
636 // Call this once per frame to update monitor file
637 void monitor_update();
641 #define MONITOR(function_name)
643 #define MONITOR_INC(function_name,inc) do { } while(0)
645 // Call this once per frame to update monitor file
646 #define monitor_update() do { } while(0)
652 const char *XSTR(const char *str, int index);
654 // Caps V between MN and MX.
655 template <class T> void CAP( T& v, T mn, T mx )
659 } else if ( v > mx ) {
664 // ========================================================
665 // stamp checksum stuff
666 // ========================================================
668 // here is the define for the stamp for this set of code
669 #define STAMP_STRING "\001\001\001\001\002\002\002\002Read the Foundation Novels from Asimov. I liked them."
670 #define STAMP_STRING_LENGTH 80
671 #define DEFAULT_CHECKSUM_STRING "\001\001\001\001"
672 #define DEFAULT_TIME_STRING "\002\002\002\002"
674 // macro to calculate the checksum for the stamp. Put here so that we can use different methods
675 // for different applications. Requires the local variable 'checksum' to be defined!!!
676 #define CALCULATE_STAMP_CHECKSUM() do { \
680 for ( i = 0; i < (int)strlen(ptr); i++ ) { \
682 checksum += ptr[i]; \
683 if ( checksum & 0x01 ) \
685 checksum = checksum >> 1; \
687 checksum |= 0x80000000; \
689 checksum |= 0x80000000; \
692 //=========================================================
693 // Memory management functions
694 //=========================================================
699 // Returns 0 if not enough RAM.
700 int vm_init(int min_heap_size);
702 // Allocates some RAM.
703 void *vm_malloc( int size, const char *filename=NULL, int line=-1 );
706 char *vm_strdup( const char *ptr, const char *filename, int line );
709 void vm_free( void *ptr, const char *filename=NULL, int line=-1 );
714 // Easy to use macros
715 #define VM_MALLOC(size) vm_malloc((size),__FILE__,__LINE__)
716 #define VM_FREE(ptr) vm_free((ptr),__FILE__,__LINE__)
718 #define malloc(size) vm_malloc((size),__FILE__,__LINE__)
719 #define free(ptr) vm_free((ptr),__FILE__,__LINE__)
720 #define strdup(ptr) vm_strdup((ptr),__FILE__,__LINE__)
725 // Returns 0 if not enough RAM.
726 int vm_init(int min_heap_size);
728 // Allocates some RAM.
729 void *vm_malloc( int size );
732 char *vm_strdup( const char *ptr );
735 void vm_free( void *ptr );
740 // Easy to use macros
741 #define VM_MALLOC(size) vm_malloc(size)
742 #define VM_FREE(ptr) vm_free(ptr)
744 #define malloc(size) vm_malloc(size)
745 #define free(ptr) vm_free(ptr)
746 #define strdup(ptr) vm_strdup(ptr)