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