]> git.jsancho.org Git - lugaru.git/blob - Source/MacCompatibility.h
More work.
[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 #ifdef __GNUC__
25 #define __forceinline inline __attribute__((always_inline))
26 #endif
27
28
29 typedef bool Boolean;
30
31
32 struct Point
33 {
34         short v;
35         short h;
36 };
37
38 typedef signed char SInt8;
39 typedef unsigned int UInt32;
40
41
42 #include "Random.h"
43
44
45 void CopyCStringToPascal( const char* src, unsigned char dst[256]);
46 void CopyPascalStringToC( const unsigned char* src, char* dst);
47
48
49 typedef struct AbsoluteTime
50 {
51         unsigned long   hi;
52         unsigned long   lo;
53 } AbsoluteTime; 
54
55 AbsoluteTime UpTime();          // NOTE: returns time since app started, not system start
56
57 typedef long Duration; 
58
59 enum
60 {
61         durationMicrosecond             = -1,
62         durationMillisecond             = 1,
63         durationSecond                  = 1000,
64         durationMinute                  = 1000 * 60,
65         durationHour                    = 1000 * 60 * 60,
66         durationDay                     = 1000 * 60 * 60 * 24,
67         durationForever                 = 0x7FFFFFFF,
68         durationImmediate               = 0,
69 }; 
70
71 Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b);
72
73 #ifdef _MSC_VER
74 inline bool isnormal( double x)
75 {
76         int ret = _fpclass( x);
77         return (ret == _FPCLASS_NN || ret == _FPCLASS_PN);
78 }
79 #endif
80
81 typedef unsigned int uintptr_t;
82
83
84 // fix file names to use '/' instead of ':'
85 char* ConvertFileName( const char* orgfilename);
86
87 #define fopen( a, b) fopen( ConvertFileName( a), b);
88 /*
89 inline float abs( float f)
90 {
91 if (f < 0)
92 return -f;
93 return f;
94 }
95
96 inline double abs( double f)
97 {
98 if (f < 0)
99 return -f;
100 return f;
101 }
102 */
103 __forceinline long long longlongabs( long long f)
104 {
105         if (f < 0)
106                 return -f;
107         return f;
108 }
109 #endif
110 #endif
111