]> git.jsancho.org Git - lugaru.git/blob - Source/MacCompatibility.h
d49a42b50a309154ed2fd95a041ee7debbb76ad3
[lugaru.git] / Source / MacCompatibility.h
1 #ifndef _MACCOMPATIBLITY_H_
2 #define _MACCOMPATIBLITY_H_
3
4 #if !PLATFORM_MACOSX
5
6 #include <stdio.h>
7 #include <float.h>
8 #include <math.h>
9
10 // stuff to make Mac code compatable with Windows/Linux/etc
11
12 #ifdef _MSC_VER
13 // disable warnings about double to float conversions
14 #pragma warning(disable:4305)
15 #pragma warning(disable:4244)
16
17 // disable warnings about boolean to int conversions
18 #pragma warning(disable:4800)
19
20 // disable warning about unreferenced local variables
21 #pragma warning(disable:4101)
22 #endif
23
24 #ifndef __forceinline
25 #  ifdef __GNUC__
26 #    define __forceinline inline __attribute__((always_inline))
27 #  endif
28 #endif
29
30 typedef bool Boolean;
31
32
33 struct Point
34 {
35         short v;
36         short h;
37 };
38
39 typedef signed char SInt8;
40 typedef unsigned int UInt32;
41
42
43 #include "Random.h"
44
45
46 void CopyCStringToPascal( const char* src, unsigned char dst[256]);
47 void CopyPascalStringToC( const unsigned char* src, char* dst);
48
49
50 typedef struct AbsoluteTime
51 {
52         unsigned long   hi;
53         unsigned long   lo;
54 } AbsoluteTime; 
55
56 AbsoluteTime UpTime();          // NOTE: returns time since app started, not system start
57
58 typedef long Duration; 
59
60 enum
61 {
62         durationMicrosecond             = -1,
63         durationMillisecond             = 1,
64         durationSecond                  = 1000,
65         durationMinute                  = 1000 * 60,
66         durationHour                    = 1000 * 60 * 60,
67         durationDay                     = 1000 * 60 * 60 * 24,
68         durationForever                 = 0x7FFFFFFF,
69         durationImmediate               = 0,
70 }; 
71
72 Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b);
73
74 #ifdef _MSC_VER
75 inline bool isnormal( double x)
76 {
77         int ret = _fpclass( x);
78         return (ret == _FPCLASS_NN || ret == _FPCLASS_PN);
79 }
80 #else
81 #include <stdint.h>
82 #endif
83
84
85 // fix file names to use '/' instead of ':'
86 char* ConvertFileName( const char* orgfilename, const char *mode = "rb" );
87
88 #define fopen( a, b) fopen(ConvertFileName(a, b), b)
89 /*
90 inline float abs( float f)
91 {
92 if (f < 0)
93 return -f;
94 return f;
95 }
96
97 inline double abs( double f)
98 {
99 if (f < 0)
100 return -f;
101 return f;
102 }
103 */
104 __forceinline long long longlongabs( long long f)
105 {
106         if (f < 0)
107                 return -f;
108         return f;
109 }
110 #endif
111 #endif
112
113