]> git.jsancho.org Git - lugaru.git/blob - Source/MacCompatibility.h
Added GPL license and headers.
[lugaru.git] / Source / MacCompatibility.h
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #ifndef _MACCOMPATIBLITY_H_
23 #define _MACCOMPATIBLITY_H_
24
25 #if !PLATFORM_MACOSX
26
27 #include <stdio.h>
28 #include <float.h>
29 #include <math.h>
30
31 // stuff to make Mac code compatable with Windows/Linux/etc
32
33 #ifdef _MSC_VER
34 // disable warnings about double to float conversions
35 #pragma warning(disable:4305)
36 #pragma warning(disable:4244)
37
38 // disable warnings about boolean to int conversions
39 #pragma warning(disable:4800)
40
41 // disable warning about unreferenced local variables
42 #pragma warning(disable:4101)
43 #endif
44
45 #ifndef __forceinline
46 #  ifdef __GNUC__
47 #    define __forceinline inline __attribute__((always_inline))
48 #  endif
49 #endif
50
51 typedef bool Boolean;
52
53
54 struct Point
55 {
56         short v;
57         short h;
58 };
59
60 typedef signed char SInt8;
61 typedef unsigned int UInt32;
62
63
64 #include "Random.h"
65
66
67 void CopyCStringToPascal( const char* src, unsigned char dst[256]);
68 void CopyPascalStringToC( const unsigned char* src, char* dst);
69
70
71 typedef struct AbsoluteTime
72 {
73         unsigned long   hi;
74         unsigned long   lo;
75 } AbsoluteTime; 
76
77 AbsoluteTime UpTime();          // NOTE: returns time since app started, not system start
78
79 typedef long Duration; 
80
81 enum
82 {
83         durationMicrosecond             = -1,
84         durationMillisecond             = 1,
85         durationSecond                  = 1000,
86         durationMinute                  = 1000 * 60,
87         durationHour                    = 1000 * 60 * 60,
88         durationDay                     = 1000 * 60 * 60 * 24,
89         durationForever                 = 0x7FFFFFFF,
90         durationImmediate               = 0,
91 }; 
92
93 Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b);
94
95 #ifdef _MSC_VER
96 inline bool isnormal( double x)
97 {
98         int ret = _fpclass( x);
99         return (ret == _FPCLASS_NN || ret == _FPCLASS_PN);
100 }
101 #else
102 #include <stdint.h>
103 #endif
104
105
106 // fix file names to use '/' instead of ':'
107 char* ConvertFileName( const char* orgfilename, const char *mode = "rb" );
108
109 #define fopen( a, b) fopen(ConvertFileName(a, b), b)
110 /*
111 inline float abs( float f)
112 {
113 if (f < 0)
114 return -f;
115 return f;
116 }
117
118 inline double abs( double f)
119 {
120 if (f < 0)
121 return -f;
122 return f;
123 }
124 */
125 __forceinline long long longlongabs( long long f)
126 {
127         if (f < 0)
128                 return -f;
129         return f;
130 }
131 #endif
132 #endif
133
134