src/stdafx.h
changeset 5934 46e88dcb71ff
parent 5933 c09d80249412
child 5935 4583abb7d050
equal deleted inserted replaced
5933:c09d80249412 5934:46e88dcb71ff
    18 #include <cstddef>
    18 #include <cstddef>
    19 #include <cstring>
    19 #include <cstring>
    20 #include <cstdlib>
    20 #include <cstdlib>
    21 #include <climits>
    21 #include <climits>
    22 
    22 
    23 // MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal
    23 /* MacOS X will use an NSAlert to display failed assertaions since they're lost unless running from a terminal
    24 // strgen always runs from terminal and don't need a window for asserts
    24  * strgen always runs from terminal and don't need a window for asserts */
    25 #if !defined(__APPLE__) || defined(STRGEN)
    25 #if !defined(__APPLE__) || defined(STRGEN)
    26 # include <cassert>
    26 # include <cassert>
    27 #else
    27 #else
    28 # include "os/macosx/macos.h"
    28 # include "os/macosx/macos.h"
    29 #endif
    29 #endif
    44 #ifdef SUNOS
    44 #ifdef SUNOS
    45 # include <alloca.h>
    45 # include <alloca.h>
    46 #endif
    46 #endif
    47 
    47 
    48 #ifdef __MORPHOS__
    48 #ifdef __MORPHOS__
    49 // morphos defines certain amiga defines per default, we undefine them
    49 /* MorphOS defines certain Amiga defines per default, we undefine them
    50 // here to make the rest of source less messy and more clear what is
    50  * here to make the rest of source less messy and more clear what is
    51 // required for morphos and what for amigaos
    51  * required for morphos and what for AmigaOS */
    52 # ifdef amigaos
    52 # ifdef amigaos
    53 #  undef amigaos
    53 #  undef amigaos
    54 # endif
    54 # endif
    55 # ifdef __amigaos__
    55 # ifdef __amigaos__
    56 #  undef __amigaos__
    56 #  undef __amigaos__
    66 # endif
    66 # endif
    67 #endif /* __MORPHOS__ */
    67 #endif /* __MORPHOS__ */
    68 
    68 
    69 #ifdef __APPLE__
    69 #ifdef __APPLE__
    70 # include "os/macosx/osx_stdafx.h"
    70 # include "os/macosx/osx_stdafx.h"
    71 /* make endian swapping use Apple's macros to increase speed (since it will use hardware swapping if available)
    71 /* Make endian swapping use Apple's macros to increase speed (since it will use hardware swapping if available)
    72  * Even though they should return uint16 and uint32, we get warnings if we don't cast those (why?) */
    72  * Even though they should return uint16 and uint32, we get warnings if we don't cast those (why?) */
    73 # define BSWAP32(x) ((uint32)Endian32_Swap(x))
    73 # define BSWAP32(x) ((uint32)Endian32_Swap(x))
    74 # define BSWAP16(x) ((uint16)Endian16_Swap(x))
    74 # define BSWAP16(x) ((uint16)Endian16_Swap(x))
    75 #else
    75 #else
    76 # define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000))
    76 # define BSWAP32(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | (((x) << 24) & 0xFF000000))
    77 # define BSWAP16(x) ((x) >> 8 | (x) << 8)
    77 # define BSWAP16(x) ((x) >> 8 | (x) << 8)
    78 #endif /* __APPLE__ */
    78 #endif /* __APPLE__ */
    79 
    79 
    80 // by default we use [] var arrays
    80 /* by default we use [] var arrays */
    81 #define VARARRAY_SIZE
    81 #define VARARRAY_SIZE
    82 
    82 
    83 
    83 
    84 // Stuff for GCC
    84 /* Stuff for GCC */
    85 #if defined(__GNUC__)
    85 #if defined(__GNUC__)
    86 # define NORETURN __attribute__ ((noreturn))
    86 # define NORETURN __attribute__ ((noreturn))
    87 # define FORCEINLINE inline
    87 # define FORCEINLINE inline
    88 # define CDECL
    88 # define CDECL
    89 # define __int64 long long
    89 # define __int64 long long
   107 
   107 
   108 #if defined(__MINGW32__) || defined(__CYGWIN__)
   108 #if defined(__MINGW32__) || defined(__CYGWIN__)
   109 # include <malloc.h> // alloca()
   109 # include <malloc.h> // alloca()
   110 #endif
   110 #endif
   111 
   111 
   112 // Stuff for MSVC
   112 /* Stuff for MSVC */
   113 #if defined(_MSC_VER)
   113 #if defined(_MSC_VER)
   114 # pragma once
   114 # pragma once
   115 # define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
   115 # define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
   116 # pragma warning(disable: 4244)  // 'conversion' conversion from 'type1' to 'type2', possible loss of data
   116 # pragma warning(disable: 4244)  // 'conversion' conversion from 'type1' to 'type2', possible loss of data
   117 # pragma warning(disable: 4761)  // integral size mismatch in argument : conversion supplied
   117 # pragma warning(disable: 4761)  // integral size mismatch in argument : conversion supplied
   145    typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
   145    typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
   146 # endif /* WIN32 && !_WIN64 && !WIN64 */
   146 # endif /* WIN32 && !_WIN64 && !WIN64 */
   147 
   147 
   148 # define GCC_PACK
   148 # define GCC_PACK
   149 
   149 
   150 // This is needed to zlib uses the stdcall calling convention on visual studio, also used with libpng (VS6 warning)
   150 /* This is needed to zlib uses the stdcall calling convention on visual studio */
   151 # if defined(WITH_ZLIB) || defined(WITH_PNG)
   151 # if defined(WITH_ZLIB) || defined(WITH_PNG)
   152 #  ifndef ZLIB_WINAPI
   152 #  ifndef ZLIB_WINAPI
   153 #   define ZLIB_WINAPI
   153 #   define ZLIB_WINAPI
   154 #  endif
   154 #  endif
   155 # endif
   155 # endif
   156 
   156 
   157 # define strcasecmp stricmp
   157 # define strcasecmp stricmp
   158 # define strncasecmp strnicmp
   158 # define strncasecmp strnicmp
   159 // suppress: warning C4005: 'offsetof' : macro redefinition (VC8)
   159 /* suppress: warning C4005: 'offsetof' : macro redefinition (VC8) */
   160 #endif /* defined(_MSC_VER) */
   160 #endif /* defined(_MSC_VER) */
   161 
   161 
   162 #if defined(WINCE)
   162 #if defined(WINCE)
   163 # define strdup _strdup
   163 # define strdup _strdup
   164 #endif /* WINCE */
   164 #endif /* WINCE */
   179    const char *FS2OTTD(const char *name);
   179    const char *FS2OTTD(const char *name);
   180    const char *OTTD2FS(const char *name);
   180    const char *OTTD2FS(const char *name);
   181 # endif /* WIN32 */
   181 # endif /* WIN32 */
   182 #endif /* STRGEN */
   182 #endif /* STRGEN */
   183 
   183 
   184 // Windows has always LITTLE_ENDIAN
   184 /* Windows has always LITTLE_ENDIAN */
   185 #if defined(WIN32) || defined(__OS2__) || defined(WIN64)
   185 #if defined(WIN32) || defined(__OS2__) || defined(WIN64)
   186 # define TTD_LITTLE_ENDIAN
   186 # define TTD_LITTLE_ENDIAN
   187 #else
   187 #else
   188 // Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile
   188 /* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */
   189 # if defined(STRGEN)
   189 # if defined(STRGEN)
   190 #  include "endian_host.h"
   190 #  include "endian_host.h"
   191 # else
   191 # else
   192 #  include "endian_target.h"
   192 #  include "endian_target.h"
   193 # endif
   193 # endif
   200 # define PATHSEP "/"
   200 # define PATHSEP "/"
   201 # define PATHSEPCHAR '/'
   201 # define PATHSEPCHAR '/'
   202 #endif
   202 #endif
   203 
   203 
   204 typedef unsigned char byte;
   204 typedef unsigned char byte;
   205 #ifndef __BEOS__ // already defined
   205 #ifndef __BEOS__ /* already defined */
   206   typedef unsigned char uint8;
   206   typedef unsigned char uint8;
   207   typedef unsigned short uint16;
   207   typedef unsigned short uint16;
   208   typedef unsigned int uint32;
   208   typedef unsigned int uint32;
   209 #endif
   209 #endif
   210 
   210 
   211 // This is already defined in unix
   211 /* This is already defined in unix */
   212 #if !defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)
   212 #if !defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)
   213   typedef unsigned int uint;
   213   typedef unsigned int uint;
   214 #endif
   214 #endif
   215 // Not defined in QNX Neutrino (6.x)
   215 /* Not defined in QNX Neutrino (6.x) */
   216 #if defined(__QNXNTO__)
   216 #if defined(__QNXNTO__)
   217   typedef unsigned int uint;
   217   typedef unsigned int uint;
   218 #endif
   218 #endif
   219 
   219 
   220 #ifndef __BEOS__
   220 #ifndef __BEOS__
   221 
   221 
   222 // some platforms use 4 bytes bool in C++
   222 /* some platforms use 4 bytes bool in C++
   223 // C bool has to be the same
   223  * C bool has to be the same */
   224 #	ifndef __cplusplus
   224 #	ifndef __cplusplus
   225 #		ifdef FOUR_BYTE_BOOL
   225 #		ifdef FOUR_BYTE_BOOL
   226 			typedef unsigned long bool;
   226 			typedef unsigned long bool;
   227 #		else /* FOUR_BYTE_BOOL */
   227 #		else /* FOUR_BYTE_BOOL */
   228 			typedef unsigned char bool;
   228 			typedef unsigned char bool;
   238 
   238 
   239 #if defined(ARM) || defined(__arm__) || defined(__alpha__)
   239 #if defined(ARM) || defined(__arm__) || defined(__alpha__)
   240 # define OTTD_ALIGNMENT
   240 # define OTTD_ALIGNMENT
   241 #endif
   241 #endif
   242 
   242 
   243 // Setup alignment and conversion macros
   243 /* Setup alignment and conversion macros */
   244 #if defined(TTD_BIG_ENDIAN)
   244 #if defined(TTD_BIG_ENDIAN)
   245   static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); }
   245   static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); }
   246   static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); }
   246   static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); }
   247   static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
   247   static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
   248   static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
   248   static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
   280     true = 1,
   280     true = 1,
   281    };
   281    };
   282 # endif
   282 # endif
   283 #endif /* __cplusplus */
   283 #endif /* __cplusplus */
   284 
   284 
   285 // Compile time assertions
   285 /* Compile time assertions */
   286 #ifdef __OS2__
   286 #ifdef __OS2__
   287 # define assert_compile(expr)
   287 # define assert_compile(expr)
   288 #else
   288 #else
   289 # ifdef __cplusplus
   289 # ifdef __cplusplus
   290 #  define assert_compile(expr) extern "C" void __ct_assert__(int a[1 - 2 * !(expr)])
   290 #  define assert_compile(expr) extern "C" void __ct_assert__(int a[1 - 2 * !(expr)])
   313 #  define offsetof(s,m)       cpp_offsetof(s, m)
   313 #  define offsetof(s,m)       cpp_offsetof(s, m)
   314 # endif /* !__MORPHOS__ */
   314 # endif /* !__MORPHOS__ */
   315 #endif /* __cplusplus */
   315 #endif /* __cplusplus */
   316 
   316 
   317 
   317 
   318 // take care of some name clashes on macos
   318 /* take care of some name clashes on MacOS */
   319 #if defined(__APPLE__)
   319 #if defined(__APPLE__)
   320 # define GetString OTTD_GetString
   320 # define GetString OTTD_GetString
   321 # define DrawString OTTD_DrawString
   321 # define DrawString OTTD_DrawString
   322 # define Random OTTD_Random
   322 # define Random OTTD_Random
   323 # define CloseConnection OTTD_CloseConnection
   323 # define CloseConnection OTTD_CloseConnection
   324 #endif /* __APPLE */
   324 #endif /* __APPLE */
   325 
   325 
   326 #ifdef __AMIGA__
   326 #ifdef __AMIGA__
   327 // it seems AmigaOS already have a Point declared
   327 /* it seems AmigaOS already have a Point declared */
   328 # define Point OTTD_AMIGA_POINT
   328 # define Point OTTD_AMIGA_POINT
   329 #endif
   329 #endif
   330 
   330 
   331 #endif /* STDAFX_H */
   331 #endif /* STDAFX_H */