common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #ifndef _COMMON_H
  23. #define _COMMON_H
  24. #ifndef ENABLE_REVISIED_BATTLE
  25. # define PAL_CLASSIC 1
  26. #endif
  27. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  28. #define _CRT_SECURE_NO_WARNINGS
  29. #endif
  30. #include <wchar.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <time.h>
  35. #include <limits.h>
  36. #include <stdarg.h>
  37. #include <assert.h>
  38. #include <stdint.h>
  39. #include "SDL.h"
  40. #include "SDL_endian.h"
  41. #define __WIDETEXT(quote) L##quote
  42. #define WIDETEXT(quote) __WIDETEXT(quote)
  43. #if !defined(fmax) || !defined(fmin)
  44. # include <math.h>
  45. #endif
  46. #include <float.h>
  47. #ifndef max
  48. # define max fmax
  49. #endif
  50. #ifndef min
  51. # define min fmin
  52. #endif
  53. // For SDL 1.2 compatibility
  54. #ifndef SDL_TICKS_PASSED
  55. #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
  56. #endif
  57. #ifndef SDL_INIT_CDROM
  58. # define SDL_INIT_CDROM 0 /* Compatibility with SDL 1.2 */
  59. #endif
  60. #ifndef SDL_AUDIO_BITSIZE
  61. # define SDL_AUDIO_BITSIZE(x) (x & 0xFF)
  62. #endif
  63. /* This is need when compiled with SDL 1.2 */
  64. #ifndef SDL_FORCE_INLINE
  65. #if defined(_MSC_VER)
  66. #define SDL_FORCE_INLINE __forceinline
  67. #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
  68. #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
  69. #else
  70. #define SDL_FORCE_INLINE static SDL_INLINE
  71. #endif
  72. #endif /* SDL_FORCE_INLINE not defined */
  73. #if defined(_MSC_VER)
  74. # define PAL_FORCE_INLINE static SDL_FORCE_INLINE
  75. #else
  76. # define PAL_FORCE_INLINE SDL_FORCE_INLINE
  77. #endif
  78. #ifdef _WIN32
  79. # include <windows.h>
  80. # include <io.h>
  81. # if defined(_MSC_VER)
  82. # if _MSC_VER < 1900
  83. # define vsnprintf _vsnprintf
  84. # define snprintf _snprintf
  85. # endif
  86. # define strdup _strdup
  87. # define access _access
  88. # pragma warning (disable:4244)
  89. # endif
  90. # ifndef _LPCBYTE_DEFINED
  91. # define _LPCBYTE_DEFINED
  92. typedef const BYTE *LPCBYTE;
  93. # endif
  94. # define PAL_MAX_PATH MAX_PATH
  95. #else
  96. # include <unistd.h>
  97. # include <dirent.h>
  98. # ifdef __APPLE__
  99. # include <objc/objc.h>
  100. # endif
  101. # ifndef FALSE
  102. # define FALSE 0
  103. # endif
  104. # ifndef TRUE
  105. # define TRUE 1
  106. # endif
  107. # define VOID void
  108. typedef char CHAR;
  109. typedef wchar_t WCHAR;
  110. typedef short SHORT;
  111. typedef long LONG;
  112. typedef unsigned long ULONG, *PULONG;
  113. typedef unsigned short USHORT, *PUSHORT;
  114. typedef unsigned char UCHAR, *PUCHAR;
  115. typedef unsigned short WORD, *LPWORD;
  116. typedef unsigned int DWORD, *LPDWORD;
  117. typedef int INT, *LPINT;
  118. # if !defined( __APPLE__ ) && !defined( GEKKO )
  119. typedef int BOOL, *LPBOOL;
  120. # endif
  121. typedef unsigned int UINT, *PUINT, UINT32, *PUINT32;
  122. typedef unsigned char BYTE, *LPBYTE;
  123. typedef const BYTE *LPCBYTE;
  124. typedef float FLOAT, *LPFLOAT;
  125. typedef void *LPVOID;
  126. typedef const void *LPCVOID;
  127. typedef CHAR *LPSTR;
  128. typedef const CHAR *LPCSTR;
  129. typedef WCHAR *LPWSTR;
  130. typedef const WCHAR *LPCWSTR;
  131. # define PAL_MAX_PATH PATH_MAX
  132. #endif
  133. #ifdef __cplusplus
  134. # define PAL_C_LINKAGE extern "C"
  135. # define PAL_C_LINKAGE_BEGIN PAL_C_LINKAGE {
  136. # define PAL_C_LINKAGE_END }
  137. #else
  138. # define PAL_C_LINKAGE
  139. # define PAL_C_LINKAGE_BEGIN
  140. # define PAL_C_LINKAGE_END
  141. #endif
  142. /* When porting SDLPAL to a new platform, please make a separate directory and put a file
  143. named 'pal_config.h' that contains marco definitions & header includes into the directory.
  144. The example of this file can be found in directories of existing portings.
  145. */
  146. #include "pal_config.h"
  147. #if defined(PAL_HAS_GIT_REVISION)
  148. # undef PAL_GIT_REVISION
  149. # include "generated.h"
  150. #endif
  151. #ifndef PAL_DEFAULT_FULLSCREEN_HEIGHT
  152. # define PAL_DEFAULT_FULLSCREEN_HEIGHT PAL_DEFAULT_WINDOW_HEIGHT
  153. #endif
  154. /* Default for 1024 samples */
  155. #ifndef PAL_AUDIO_DEFAULT_BUFFER_SIZE
  156. # define PAL_AUDIO_DEFAULT_BUFFER_SIZE 1024
  157. #endif
  158. #ifndef PAL_HAS_SDLCD
  159. # define PAL_HAS_SDLCD 0
  160. #endif
  161. #ifndef PAL_HAS_MP3
  162. # define PAL_HAS_MP3 1 /* Try always enable MP3. If compilation/run failed, please change this value to 0. */
  163. #endif
  164. #ifndef PAL_HAS_OGG
  165. # define PAL_HAS_OGG 1 /* Try always enable OGG. If compilation/run failed, please change this value to 0. */
  166. #endif
  167. #ifndef PAL_CONFIG_PREFIX
  168. # define PAL_CONFIG_PREFIX PAL_PREFIX
  169. #endif
  170. #ifndef PAL_HAS_NATIVEMIDI
  171. # define PAL_HAS_NATIVEMIDI 0
  172. #endif
  173. #ifndef PAL_LARGE
  174. # define PAL_LARGE
  175. #endif
  176. #ifndef PAL_SCALE_SCREEN
  177. # define PAL_SCALE_SCREEN TRUE
  178. #endif
  179. #ifndef PAL_IS_VALID_JOYSTICK
  180. # define PAL_IS_VALID_JOYSTICK(s) TRUE
  181. #endif
  182. #ifndef PAL_FATAL_OUTPUT
  183. # define PAL_FATAL_OUTPUT(s)
  184. #endif
  185. #define PAL_fread(buf, elem, num, fp) if (fread((buf), (elem), (num), (fp)) < (num)) return -1
  186. typedef enum tagLOGLEVEL
  187. {
  188. LOGLEVEL_MIN,
  189. LOGLEVEL_VERBOSE = LOGLEVEL_MIN,
  190. LOGLEVEL_DEBUG,
  191. LOGLEVEL_INFO,
  192. LOGLEVEL_WARNING,
  193. LOGLEVEL_ERROR,
  194. LOGLEVEL_FATAL,
  195. LOGLEVEL_MAX = LOGLEVEL_FATAL,
  196. } LOGLEVEL;
  197. #define PAL_LOG_MAX_OUTPUTS (LOGLEVEL_MAX + 1)
  198. #if defined(DEBUG) || defined(_DEBUG)
  199. # define PAL_DEFAULT_LOGLEVEL LOGLEVEL_MIN
  200. #else
  201. # define PAL_DEFAULT_LOGLEVEL LOGLEVEL_MAX
  202. #endif
  203. #ifndef PAL_HAS_CONFIG_PAGE
  204. # define PAL_HAS_CONFIG_PAGE FALSE
  205. #endif
  206. #define PAL_MAX_GLOBAL_BUFFERS 4
  207. #define PAL_GLOBAL_BUFFER_SIZE 1024
  208. //
  209. // PAL_PATH_SEPARATORS contains all vaild path separators under a specific OS
  210. // If you define this constant, please put the default separator at first.
  211. //
  212. #ifndef PAL_PATH_SEPARATORS
  213. # define PAL_PATH_SEPARATORS "/"
  214. #endif
  215. #ifndef PAL_IS_PATH_SEPARATOR
  216. # define PAL_IS_PATH_SEPARATOR(x) ((x) == '/')
  217. #endif
  218. #endif