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