]> icculus.org git repositories - taylor/freespace2.git/blob - include/pstypes.h
x86 compile fixes for OSX patch
[taylor/freespace2.git] / include / pstypes.h
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/GlobalIncs/PsTypes.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file containg global typedefs, constants and macros
16  *
17  * $Log$
18  * Revision 1.9  2004/06/11 21:39:44  taylor
19  * x86 compile fixes for OSX patch
20  *
21  * Revision 1.8  2004/06/11 00:15:06  tigital
22  * byte-swapping changes for bigendian systems
23  *
24  * Revision 1.7  2002/07/13 19:47:02  theoddone33
25  * Fix some more warnings
26  *
27  * Change demo building, edit Makefile if you want the demo.
28  *
29  * Revision 1.6  2002/06/19 04:52:45  relnev
30  * MacOS X updates (Ryan)
31  *
32  * Revision 1.5  2002/06/17 06:33:08  relnev
33  * ryan's struct patch for gcc 2.95
34  *
35  * Revision 1.4  2002/06/09 04:41:14  relnev
36  * added copyright header
37  *
38  * Revision 1.3  2002/06/01 07:12:32  relnev
39  * a few NDEBUG updates.
40  *
41  * removed a few warnings.
42  *
43  * Revision 1.2  2002/05/28 06:28:20  theoddone33
44  * Filesystem mods, actually reads some data files now
45  *
46  * Revision 1.1.1.1  2002/05/03 03:28:12  root
47  * Initial import.
48  *
49  * 
50  * 34    6/16/00 3:16p Jefff
51  * sim of the year dvd version changes, a few german soty localization
52  * fixes
53  * 
54  * 33    10/05/99 2:29p Danw
55  * 
56  * 32    10/01/99 9:10a Daveb
57  * V 1.1 PATCH
58  * 
59  * 31    9/13/99 12:22a Dave
60  * Minor build update.
61  * 
62  * 30    8/28/99 4:54p Dave
63  * Fixed directives display for multiplayer clients for wings with
64  * multiple waves. Fixed hud threat indicator rendering color.
65  * 
66  * 29    8/09/99 4:18p Andsager
67  * Make french and german defines, needed specifically to enable language
68  * under launcher misc. tab
69  * 
70  * 28    7/20/99 1:49p Dave
71  * Peter Drake build. Fixed some release build warnings.
72  * 
73  * 27    7/18/99 5:19p Dave
74  * Jump node icon. Fixed debris fogging. Framerate warning stuff.
75  * 
76  * 26    7/15/99 9:21a Andsager
77  * FS2_DEMO check in
78  * 
79  * 25    7/09/99 9:51a Dave
80  * Added thick polyline code.
81  * 
82  * 24    6/29/99 10:35a Dave
83  * Interface polygon bitmaps! Whee!
84  * 
85  * 23    6/14/99 10:45a Dave
86  * Made beam weapons specify accuracy by skill level in the weapons.tbl
87  * 
88  * 22    6/03/99 10:15p Dave
89  * Put in temporary main hall screen.
90  * 
91  * 21    5/09/99 8:57p Dave
92  * Final E3 build preparations.
93  * 
94  * 20    4/25/99 7:43p Dave
95  * Misc small bug fixes. Made sun draw properly.
96  * 
97  * 19    4/25/99 3:03p Dave
98  * Removed E3_BUILD from pstypes
99  * 
100  * 18    4/25/99 3:02p Dave
101  * Build defines for the E3 build.
102  * 
103  * 17    4/15/99 1:29p Dave
104  * Remove multiplayer beta build define.
105  * 
106  * 16    4/15/99 1:24p Dave
107  * Final Beta 1 checkin.
108  * 
109  * 15    4/14/99 5:28p Dave
110  * Minor bug fixes.
111  * 
112  * 14    4/12/99 2:22p Dave
113  * More checks for dogfight stats.
114  * 
115  * 13    4/09/99 2:21p Dave
116  * Multiplayer beta stuff. CD checking.
117  * 
118  * 12    2/25/99 4:19p Dave
119  * Added multiplayer_beta defines. Added cd_check define. Fixed a few
120  * release build warnings. Added more data to the squad war request and
121  * response packets.
122  * 
123  * 11    2/23/99 2:29p Dave
124  * First run of oldschool dogfight mode. 
125  * 
126  * 10    2/07/99 8:51p Andsager
127  * Add inner bound to asteroid field.  Inner bound tries to stay astroid
128  * free.  Wrap when within and don't throw at ships inside.
129  * 
130  * 9     1/15/99 11:29a Neilk
131  * Fixed D3D screen/texture pixel formatting problem. 
132  * 
133  * 8     1/08/99 2:08p Dave
134  * Fixed software rendering for pofview. Super early support for AWACS and
135  * beam weapons.
136  * 
137  * 7     1/06/99 2:24p Dave
138  * Stubs and release build fixes.
139  * 
140  * 6     11/30/98 1:07p Dave
141  * 16 bit conversion, first run.
142  * 
143  * 5     11/05/98 4:18p Dave
144  * First run nebula support. Beefed up localization a bit. Removed all
145  * conditional compiles for foreign versions. Modified mission file
146  * format.
147  * 
148  * 4     10/13/98 9:28a Dave
149  * Started neatening up freespace.h. Many variables renamed and
150  * reorganized. Added AlphaColors.[h,cpp]
151  * 
152  * 3     10/07/98 11:28a Dave
153  * 
154  * 2     10/07/98 10:52a Dave
155  * Initial checkin.
156  * 
157  * 1     10/07/98 10:48a Dave
158  * 
159  * 75    8/20/98 5:30p Dave
160  * Put in handy multiplayer logfile system. Now need to put in useful
161  * applications of it all over the code.
162  * 
163  * 74    6/17/98 11:01a Lawrance
164  * set correct offset for English special font chars
165  * 
166  * 73    6/12/98 4:52p Hoffoss
167  * Added support for special characters in in forgeign languages.
168  * 
169  * 72    6/09/98 6:49p Lawrance
170  * Comment out UK_BUILD
171  * 
172  * 71    6/09/98 5:15p Lawrance
173  * French/German localization
174  * 
175  * 70    6/09/98 12:12p Hoffoss
176  * Added XSTR localization code.
177  * 
178  * 69    6/05/98 9:49a Lawrance
179  * OEM changes
180  * 
181  * 68    5/22/98 3:13p Allender
182  * no Int3()'s and Asserts
183  * 
184  * 67    5/20/98 12:59p John
185  * Turned optimizations on for debug builds.   Also turning on automatic
186  * function inlining.  Turned off the unreachable code warning.
187  * 
188  * 66    5/04/98 1:49p Allender
189  * make Int3's do nothing when InterplayQA is defined
190  * 
191  * 65    4/25/98 11:55p Lawrance
192  * compile out Int3() and Assert() for release demo build
193  * 
194  *
195  * $NoKeywords: $
196  *
197  */
198
199 #ifndef _PSTYPES_H
200 #define _PSTYPES_H
201
202
203 // Build defines.  Comment in/out for whatever build is necessary:
204 // #define OEM_BUILD                                            // enable for OEM builds
205 // #define MULTIPLAYER_BETA_BUILD                               // enable for multiplayer beta build
206 // #define E3_BUILD                                                     // enable for 3dfx E3 build                                             
207 // #define PRESS_TOUR_BUILD                     // enable for press tour build
208 //#define FS2_DEMO                                      // enable demo build for FS2
209 // #define PD_BUILD                                             // fred documentation/evaluation build
210 //      #define FRENCH_BUILD                            // build for French (obsolete)
211 // #define GERMAN_BUILD                         // build for German (this is now used)
212 //#define RELEASE_REAL                                  // this means that it is an actual release candidate, not just an optimized/release build
213
214 // uncomment this #define for DVD version (makes popups say DVD instead of CD 2 or whatever): JCF 5/10/2000
215 // #define DVD_MESSAGE_HACK
216
217
218 #if defined(MULTIPLAYER_BETA_BUILD) || defined(E3_BUILD) || defined(RELEASE_REAL)
219         #define GAME_CD_CHECK
220 #endif
221
222 // 4127 is constant conditional (assert)
223 // 4100 is unreferenced formal parameters,
224 // 4514 is unreferenced inline function removed, 
225 // 4201 is nameless struct extension used. (used by windows header files)
226 // 4410 illegal size for operand... ie...       fxch st(1)
227 // 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.
228 // 4725 is the pentium division bug warning, and I can't seem to get rid of it, even with this pragma.
229 //      JS: I figured out the disabling 4725 works, but not on the first function in the module.
230 //      So to disable this, I add in a stub function at the top of each module that does nothing.
231 // 4710 is inline function not expanded (who cares?)
232 // 4711 tells us an inline function was expanded (who cares?)
233 // 4702 unreachable code.  I care, but too many to deal with
234 // 4201 nonstandard extension used : nameless struct/union (happens a lot in Windows include headers)
235 // 4390 emptry control statement (triggered by nprintf and mprintf's inside of one-line if's, etc)
236 #ifndef PLAT_UNIX
237 #pragma warning(disable: 4127 4100 4514 4201 4410 4611 4725 4710 4711 4702 4201 4390)
238 #endif
239
240 #include <stdio.h>      // For NULL, etc
241 #include <stdlib.h>
242 #include <memory.h>
243
244 #ifndef __APPLE__
245 #include <malloc.h>
246 #endif
247
248 #include <string.h>
249
250 #ifdef PLAT_UNIX
251 #include "unix.h"
252 #endif
253 // value to represent an uninitialized state in any int or uint
254 #define UNINITIALIZED 0x7f8e6d9c
255
256 #if defined(DEMO) || defined(OEM_BUILD) // no change for FS2_DEMO
257         #define MAX_PLAYERS     1
258 #else
259         #define MAX_PLAYERS     12
260 #endif
261
262 #define MAX_TEAMS               3
263
264 #define USE_INLINE_ASM 1                // Define this to use inline assembly
265 #define STRUCT_CMP(a, b) memcmp((void *) &a, (void *) &b, sizeof(a))
266
267 #define LOCAL static                    // make module local varilable static.
268
269 #ifdef __APPLE__
270 typedef int socklen_t;
271 #endif
272
273 typedef __int64 longlong;
274 typedef long fix;
275 typedef unsigned char ubyte;
276 typedef unsigned short ushort;
277 typedef unsigned int uint;
278 typedef unsigned long ulong;
279
280 #define HARDWARE_ONLY
281
282 //Stucture to store clipping codes in a word
283 typedef struct ccodes {
284         ubyte vor,vand; //or is low byte, and is high byte
285 } ccodes;
286
287 typedef struct vector {
288         union {
289                 struct {
290                         float x,y,z;
291                 } xyz;
292                 float a1d[3];
293         };
294 } vector;
295
296 // A vector referenced as an array
297 typedef struct vectora {
298         float   xyz[3];
299 } vectora;
300
301 typedef struct vec2d {
302         float i,j;
303 } vec2d;
304
305 // Used for some 2d primitives, like gr_poly
306 typedef struct vert2df {
307         float x, y;
308 } vert2df;
309
310 typedef struct angles {
311         float   p, b, h;
312 } angles_t;
313
314 typedef struct matrix {
315         union {
316                 struct {
317                         vector  rvec, uvec, fvec;
318                 } v;
319                 float a2d[3][3];
320                 float a1d[9];
321         };
322 } matrix;
323
324 typedef struct uv_pair {
325         float u,v;
326 } uv_pair;
327
328 // Used to store rotated points for mines.
329 // Has flag to indicate if projected.
330 typedef struct vertex {
331         float           x, y, z;                                // world space position
332         float           sx, sy, sw;                     // screen space position (sw == 1/z)
333         float           u, v;                                   // texture position
334         ubyte           r, g, b, a;                     // color.  Use b for darkening;
335         ubyte           codes;                          // what sides of view pyramid this point is on/off.  0 = Inside view pyramid.
336         ubyte           flags;                          // Projection flags.  Indicates whether it is projected or not or if projection overflowed.
337         ubyte           pad[2];                         // pad structure to be 4 byte aligned.
338 } vertex;
339
340 #define BMP_AABITMAP            (1<<0)                          // antialiased bitmap
341 #define BMP_TEX_XPARENT         (1<<1)                          // transparent texture
342 #define BMP_TEX_NONDARK         (1<<2)                          // nondarkening texture
343 #define BMP_TEX_OTHER           (1<<3)                          // so we can identify all "normal" textures
344
345 // any texture type
346 #define BMP_TEX_ANY                             ( BMP_TEX_XPARENT | BMP_TEX_NONDARK | BMP_TEX_OTHER )
347
348 // max res == 1024x768. max texture size == 256
349 #define MAX_BMAP_SECTIONS_X                             4
350 #define MAX_BMAP_SECTIONS_Y                             3
351 #define MAX_BMAP_SECTION_SIZE                           256
352 typedef struct bitmap_section_info {
353         ushort sx[MAX_BMAP_SECTIONS_X];         // x offset of each section
354         ushort sy[MAX_BMAP_SECTIONS_Y];         // y offset of each section
355
356         ubyte num_x, num_y;                                             // number of x and y sections
357 } bitmap_section_info;
358
359 typedef struct bitmap {
360         short   w, h;           // Width and height
361         short   rowsize;        // What you need to add to go to next row
362         ubyte   bpp;            // How many bits per pixel it is. (7,8,15,16,24,32)
363         ubyte   flags;  // See the BMP_???? defines for values
364         uint    data;           // Pointer to data, or maybe offset into VRAM.
365         ubyte *palette; // If bpp==8, this is pointer to palette.   If the BMP_NO_PALETTE_MAP flag
366                                                         // is not set, this palette just points to the screen palette. (gr_palette)
367
368         bitmap_section_info sections;
369 } bitmap;
370
371 //This are defined in MainWin.c
372 extern void _cdecl WinAssert(char * text,char *filename, int line);
373 extern void _cdecl Error( char * filename, int line, char * format, ... );
374 extern void _cdecl Warning( char * filename, int line, char * format, ... );
375
376 #include "outwnd.h"
377
378 // To debug printf do this:
379 // mprintf(( "Error opening %s\n", filename ));
380 #ifndef NDEBUG
381 #define mprintf(args) outwnd_printf2 args
382 #define nprintf(args) outwnd_printf args
383 #else
384 #define mprintf(args) 
385 #define nprintf(args) 
386 #endif
387
388 #define LOCATION __FILE__,__LINE__
389
390 // To flag an error, you can do this:
391 // Error( __FILE__, __LINE__, "Error opening %s", filename );
392 // or, 
393 // Error( LOCATION, "Error opening %s", filename );
394
395 #if defined(NDEBUG)
396 #define Assert(x) do {} while (0)
397 #else
398 void gr_activate(int);
399 #define Assert(x) do { if (!(x)){ gr_activate(0); WinAssert(#x,__FILE__,__LINE__); gr_activate(1); } } while (0)
400 #endif
401
402 //#define Int3() _asm { int 3 }
403
404 #ifdef INTERPLAYQA
405         // Interplay QA version of Int3
406         #define Int3() do { } while (0) 
407
408         // define to call from Warning function above since it calls Int3, so without this, we
409         // get put into infinite dialog boxes
410         #define AsmInt3() _asm { int 3 }
411
412 #else
413         #if defined(NDEBUG)
414                 // No debug version of Int3
415                 #define Int3() do { } while (0) 
416         #else
417                 void debug_int3();
418
419                 // Debug version of Int3
420                 #define Int3() debug_int3()
421         #endif  // NDEBUG && DEMO
422 #endif  // INTERPLAYQA
423
424 #define min(a,b) (((a) < (b)) ? (a) : (b))
425 #define max(a,b) (((a) > (b)) ? (a) : (b))
426
427 #define PI                                      3.141592654f
428 #define PI2                                     (3.141592654f*2.0f)     // PI*2
429 #define ANG_TO_RAD(x)   ((x)*PI/180)
430
431
432 extern int      Fred_running;  // Is Fred running, or FreeSpace?
433 extern int Pofview_running;
434 extern int Nebedit_running;
435
436
437 //======================================================================================
438 //======          D E B U G    C O N S O L E   S T U F F        ========================
439 //======================================================================================
440
441 // Here is a a sample command to toggle something that would
442 // be called by doing "toggle it" from the debug console command window/
443
444 /*
445 DCF(toggle_it,"description")
446 {
447         if (Dc_command) {
448                 This_var = !This_var;
449         }
450
451         if (Dc_help)    {
452                 dc_printf( "Usage: sample\nToggles This_var on/off.\n" );
453         }
454
455         if (Dc_status)  {
456                 dc_printf( "The status is %d.\n", This_var );
457         }
458 */
459
460 class debug_command {
461         public:
462         char *name;
463         char *help;
464         void (*func)();
465         debug_command(char *name,char *help,void (*func)());    // constructor
466 };
467
468 #define DCF(function_name,help_text)                    \
469                 void dcf_##function_name();     \
470                 debug_command dc_##function_name(#function_name,help_text,dcf_##function_name); \
471                 void dcf_##function_name()              
472
473 // Starts the debug console
474 extern void debug_console( void (*func)() = NULL );
475
476 // The next three variables tell your function what to do.  It should
477 // only change something if the dc_command is set.   A minimal function
478 // needs to process the dc_command.   Usually, these will be called in
479 // these combinations:
480 // dc_command=true, dc_status=true  means process it and show status
481 // dc_help=true means show help only
482 // dc_status=true means show status only
483 // I would recommend doing this in each function:
484 // if (dc_command) { process command }
485 // if (dc_help) { print out help }
486 // if (dc_status) { print out status }
487 // with the last two being optional
488
489 extern int Dc_command;  // If this is set, then process the command
490 extern int Dc_help;             // If this is set, then print out the help text in the form, "usage: ... \nLong description\n" );
491 extern int Dc_status;           // If this is set, then print out the current status of the command.
492
493 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.
494 extern char *Dc_arg;            // The (lowercased) string value of the argument retrieved from dc_arg
495 extern char *Dc_arg_org;        // Dc_arg before it got converted to lowercase
496 extern uint Dc_arg_type;        // The type of dc_arg.
497 extern char *Dc_command_line;           // The rest of the command line, from the end of the last processed arg on.
498 extern int Dc_arg_int;          // If Dc_arg_type & ARG_INT or ARG_HEX is set, then this is the value
499 extern float Dc_arg_float;      // If Dc_arg_type & ARG_FLOAT is set, then this is the value
500
501 // Outputs text to the console
502 void dc_printf( char *format, ... );
503
504 // Each dc_arg_type can have one or more of these flags set.
505 // This is because some things can fit into two catagories.
506 // Like 1 can be an integer, a float, a string, or a true boolean
507 // value.
508 #define ARG_NONE                (1<<0)  // no argument
509 #define ARG_ANY         0xFFFFFFFF      // Anything.
510 #define ARG_STRING      (1<<1)  // any valid string
511 #define ARG_QUOTE               (1<<2)  // a quoted string
512 #define ARG_INT         (1<<3)  // a valid integer
513 #define ARG_FLOAT               (1<<4)  // a valid floating point number
514
515 // some specific commonly used predefined types. Can add up to (1<<31)
516 #define ARG_HEX         (1<<5)  // a valid hexadecimal integer. Note that ARG_INT will always be set also in this case.
517 #define ARG_TRUE                (1<<6)  // on, true, non-zero number
518 #define ARG_FALSE               (1<<7)  // off, false, zero
519 #define ARG_PLUS                (1<<8)  // Plus sign
520 #define ARG_MINUS               (1<<9)  // Minus sign
521 #define ARG_COMMA               (1<<10) // a comma
522
523 // A shortcut for boolean only variables.
524 // Example:  
525 // DCF_BOOL( lighting, Show_lighting )
526 //
527 #define DCF_BOOL( function_name, bool_variable )        \
528         void dcf_##function_name();     \
529         debug_command dc_##function_name(#function_name,"Toggles "#bool_variable,dcf_##function_name ); \
530         void dcf_##function_name()      {       \
531         if ( Dc_command )       {       \
532                 dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);                \
533                 if ( Dc_arg_type & ARG_TRUE )   bool_variable = 1;      \
534                 else if ( Dc_arg_type & ARG_FALSE ) bool_variable = 0;  \
535                 else if ( Dc_arg_type & ARG_NONE ) bool_variable ^= 1;  \
536         }       \
537         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 );      \
538         if ( Dc_status )        dc_printf( "%s is %s\n", #function_name, (bool_variable?"TRUE":"FALSE") );      \
539 }
540
541
542 //======================================================================================
543 //======================================================================================
544 //======================================================================================
545
546
547
548 #include "fix.h"
549 #include "floating.h"
550
551 // Some constants for stuff
552 #define MAX_FILENAME_LEN        32                      // Length for filenames, ie "title.pcx"
553 #define MAX_PATH_LEN                    128             // Length for pathnames, ie "c:\bitmaps\title.pcx"
554
555 // contants and defined for byteswapping routines (useful for mac)
556
557 #define SWAPSHORT(x)    (                                                       \
558                                                 ((ubyte)x << 8) |                                       \
559                                                 (((ushort)x) >> 8)                      \
560                                                 )
561                                                 
562 #define SWAPINT(x)              (                                                       \
563                                                 (x << 24) |                                     \
564                                                 (((ulong)x) >> 24) |            \
565                                                 ((x & 0x0000ff00) << 8) |       \
566                                                 ((x & 0x00ff0000) >> 8)         \
567                                                 )
568 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
569 inline 
570 float SWAPFLOAT( float *x )
571 {
572     #if ! defined( __MWERKS__ )
573                 //Usage:  void __stwbrx( unsigned int, unsigned int *address, int byteOffsetFromAddress );
574                 #define __stwbrx( value, base, index ) \
575                          __asm__ ( "stwbrx %0, %1, %2" :  : "r" (value), "b%" (index), "r" (base) : "memory" )
576         #endif
577
578         union
579         {
580                 int             i;
581                 float           f;
582         }buf;
583         
584         //load the float into the integer unit
585         //unsigned int  a = ((long*) x)[0];
586         register int a = ((int*) x )[0];
587
588         //store it to the transfer union, with byteswapping
589         __stwbrx( a, 0, &buf.i );       
590
591         //load it into the FPU and return it
592         return buf.f;
593 }
594 #endif
595
596 #if SDL_BYTEORDER != SDL_BIG_ENDIAN
597 #define INTEL_INT(x)    x
598 #define INTEL_SHORT(x)  x
599 #define INTEL_FLOAT(x)  (*x)
600 #else
601 #define INTEL_INT(x)    SWAPINT(x)
602 #define INTEL_SHORT(x)  SWAPSHORT(x)
603 #define INTEL_FLOAT(x)  SWAPFLOAT(x)
604 #endif
605
606 #define TRUE    1
607 #define FALSE   0
608
609 int myrand();
610
611
612
613 // Callback Loading function. 
614 // If you pass a function to this, that function will get called
615 // around 10x per second, so you can update the screen.
616 // Pass NULL to turn it off.
617 // Call this with the name of a function.  That function will
618 // then get called around 10x per second.  The callback function
619 // gets passed a 'count' which is how many times game_busy has
620 // been called since the callback was set.   It gets called
621 // one last time with count=-1 when you turn off the callback
622 // by calling game_busy_callback(NULL).   Game_busy_callback
623 // returns the current count, so you can tell how many times
624 // game_busy got called.
625 // If delta_step is above 0, then it will also make sure it 
626 // calls the callback each time count steps 'delta_step' even
627 // if 1/10th of a second hasn't elapsed.
628 extern int game_busy_callback( void (*callback)(int count), int delta_step = -1 );
629
630 // Call whenever loading to display cursor
631 extern void game_busy();
632
633
634 //=========================================================
635 // Functions to monitor performance
636 #ifndef NDEBUG
637
638 class monitor {
639         public:
640         char    *name;                  
641         int     value;                  // Value that gets cleared to 0 each frame.
642         int     min, max, sum, cnt;             // Min & Max of value.  Sum is used to calculate average 
643         monitor(char *name);    // constructor
644 };
645
646 // Creates a monitor variable
647 #define MONITOR(function_name)                          monitor mon_##function_name(#function_name)
648
649 // Increments a monitor variable
650 #define MONITOR_INC(function_name,inc)          do { mon_##function_name.value+=(inc); } while(0)
651
652 // Call this once per frame to update monitor file
653 void monitor_update();
654
655 #else
656
657 #define MONITOR(function_name)
658
659 #define MONITOR_INC(function_name,inc)          do { } while(0)
660
661 // Call this once per frame to update monitor file
662 #define monitor_update() do { } while(0)
663
664 #endif
665
666 #define NOX(s) s
667
668 char *XSTR(char *str, int index);
669
670 // Caps V between MN and MX.
671 template <class T> void CAP( T& v, T mn, T mx )
672 {
673         if ( v < mn )   {
674                 v = mn;
675         } else if ( v > mx )    {
676                 v = mx;
677         }
678 }
679
680 // ========================================================
681 // stamp checksum stuff
682 // ========================================================
683
684 // here is the define for the stamp for this set of code
685 #define STAMP_STRING "\001\001\001\001\002\002\002\002Read the Foundation Novels from Asimov.  I liked them." 
686 #define STAMP_STRING_LENGTH     80
687 #define DEFAULT_CHECKSUM_STRING         "\001\001\001\001"
688 #define DEFAULT_TIME_STRING                     "\002\002\002\002"
689
690 // macro to calculate the checksum for the stamp.  Put here so that we can use different methods
691 // for different applications.  Requires the local variable 'checksum' to be defined!!!
692 #define CALCULATE_STAMP_CHECKSUM() do { \
693                 int i, found;   \
694                                                         \
695                 checksum = 0;   \
696                 for ( i = 0; i < (int)strlen(ptr); i++ ) {      \
697                         found = 0;      \
698                         checksum += ptr[i];     \
699                         if ( checksum & 0x01 )  \
700                                 found = 1;      \
701                         checksum = checksum >> 1;       \
702                         if (found)      \
703                                 checksum |= 0x80000000; \
704                 }       \
705                 checksum |= 0x80000000; \
706         } while (0) ;
707
708 //=========================================================
709 // Memory management functions
710 //=========================================================
711
712 #ifndef NDEBUG
713         // Debug versions
714
715         // Returns 0 if not enough RAM.
716         int vm_init(int min_heap_size);
717
718         // Allocates some RAM.
719         void *vm_malloc( int size, char *filename=NULL, int line=-1 );
720
721         // 
722         char *vm_strdup( const char *ptr, char *filename, int line );
723
724         // Frees some RAM. 
725         void vm_free( void *ptr, char *filename=NULL, int line=-1 );
726
727         // Frees all RAM.
728         void vm_free_all();
729
730         // Easy to use macros
731         #define VM_MALLOC(size) vm_malloc((size),__FILE__,__LINE__)
732         #define VM_FREE(ptr) vm_free((ptr),__FILE__,__LINE__)
733
734         #define malloc(size) vm_malloc((size),__FILE__,__LINE__)
735         #define free(ptr) vm_free((ptr),__FILE__,__LINE__)
736         #define strdup(ptr) vm_strdup((ptr),__FILE__,__LINE__)
737         
738 #else
739         // Release versions
740
741         // Returns 0 if not enough RAM.
742         int vm_init(int min_heap_size);
743
744         // Allocates some RAM.
745 //      void *vm_malloc( int size );
746
747         // 
748 //      char *vm_strdup( const char *ptr );
749
750         // Frees some RAM. 
751 //      void vm_free( void *ptr );
752
753         // Frees all RAM.
754         void vm_free_all();
755
756         // Easy to use macros
757         #define VM_MALLOC(size) vm_malloc(size)
758         #define VM_FREE(ptr) vm_free(ptr)
759
760 //      #define malloc(size) vm_malloc(size)
761 //      #define free(ptr) vm_free(ptr)
762 //      #define strdup(ptr) vm_strdup(ptr)
763         #define vm_malloc(size) malloc(size)
764         #define vm_free(ptr) free(ptr)
765         #define vm_strdup(ptr) strdup(ptr)
766 #endif
767
768
769 #endif          // PS_TYPES_H
770