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