AppleSpecific.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : Apple specific declarations common amongst its products
  9. #ifndef CRYINCLUDE_CRYCOMMON_APPLESPECIFIC_H
  10. #define CRYINCLUDE_CRYCOMMON_APPLESPECIFIC_H
  11. #pragma once
  12. //////////////////////////////////////////////////////////////////////////
  13. // Standard includes.
  14. //////////////////////////////////////////////////////////////////////////
  15. #include <stdlib.h>
  16. #include <stdint.h>
  17. #include <math.h>
  18. #include <fcntl.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <time.h>
  22. #include <ctype.h>
  23. #include <limits.h>
  24. #include <signal.h>
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <malloc/malloc.h>
  28. #include <Availability.h>
  29. // Atomic operations , guaranteed to work across all apple platforms
  30. #include <libkern/OSAtomic.h>
  31. #include <sys/socket.h>
  32. #include <netinet/in.h>
  33. #include <string>
  34. //////////////////////////////////////////////////////////////////////////
  35. #define FP16_MESH
  36. #define BOOST_DISABLE_WIN32
  37. #ifndef __COUNTER__
  38. #define __COUNTER__ __LINE__
  39. #endif
  40. typedef void* LPVOID;
  41. #define VOID void
  42. #define PVOID void*
  43. typedef unsigned int UINT;
  44. typedef char CHAR;
  45. typedef float FLOAT;
  46. #define PHYSICS_EXPORTS
  47. // MSVC compiler-specific keywords
  48. #define __forceinline inline
  49. #define _inline inline
  50. #define __cdecl
  51. #define _cdecl
  52. #define __stdcall
  53. #define _stdcall
  54. #define __fastcall
  55. #define _fastcall
  56. #define IN
  57. #define OUT
  58. #define MAP_ANONYMOUS MAP_ANON
  59. //////////////////////////////////////////////////////////////////////////
  60. // Define platform independent types.
  61. //////////////////////////////////////////////////////////////////////////
  62. #include "BaseTypes.h"
  63. typedef double real;
  64. typedef uint32 DWORD;
  65. typedef DWORD* LPDWORD;
  66. typedef uint64 DWORD_PTR;
  67. typedef intptr_t INT_PTR, * PINT_PTR;
  68. typedef uintptr_t UINT_PTR, * PUINT_PTR;
  69. typedef char* LPSTR, * PSTR;
  70. typedef char TCHAR;
  71. typedef uint64 __uint64;
  72. #if !defined(__clang__)
  73. typedef int64 __int64;
  74. #endif
  75. typedef int64 INT64;
  76. typedef uint64 UINT64;
  77. typedef long LONG_PTR, * PLONG_PTR, * PLONG;
  78. typedef unsigned long ULONG_PTR, * PULONG_PTR;
  79. typedef uint8 BYTE;
  80. typedef uint16 WORD;
  81. typedef void* HWND;
  82. typedef UINT_PTR WPARAM;
  83. typedef LONG_PTR LPARAM;
  84. typedef LONG_PTR LRESULT;
  85. #define PLARGE_INTEGER LARGE_INTEGER *
  86. typedef const char* LPCSTR, * PCSTR;
  87. typedef long long LONGLONG;
  88. typedef ULONG_PTR SIZE_T;
  89. typedef uint8 byte;
  90. #define ILINE __forceinline
  91. #ifndef MAXUINT
  92. #define MAXUINT ((uint) ~((uint)0))
  93. #endif
  94. #ifndef MAXINT
  95. #define MAXINT ((int)(MAXUINT >> 1))
  96. #endif
  97. #ifndef _CVTBUFSIZE
  98. #define _CVTBUFSIZE (309+40) /* # of digits in max. dp value + slop */
  99. #endif
  100. #ifndef STDMETHODCALLTYPE_DEFINED
  101. #define STDMETHODCALLTYPE_DEFINED
  102. #define STDMETHODCALLTYPE
  103. #endif
  104. #define _PACK __attribute__ ((packed))
  105. // Safe memory freeing
  106. #ifndef SAFE_DELETE
  107. #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } \
  108. }
  109. #endif
  110. #ifndef SAFE_DELETE_ARRAY
  111. #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } \
  112. }
  113. #endif
  114. #ifndef SAFE_RELEASE
  115. #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } \
  116. }
  117. #endif
  118. #define MAKEWORD(a, b) ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
  119. #define MAKELONG(a, b) ((LONG)(((WORD)((DWORD_PTR)(a) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)(b) & 0xffff))) << 16))
  120. #define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff))
  121. #define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16))
  122. #define LOBYTE(w) ((BYTE)((DWORD_PTR)(w) & 0xff))
  123. #define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8))
  124. #define CALLBACK
  125. #define WINAPI
  126. #ifndef __cplusplus
  127. #ifndef _WCHAR_T_DEFINED
  128. typedef unsigned short wchar_t;
  129. #define TCHAR wchar_t;
  130. #define _WCHAR_T_DEFINED
  131. #endif
  132. #endif
  133. typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
  134. typedef WCHAR* PWCHAR;
  135. typedef WCHAR* LPWCH, * PWCH;
  136. typedef const WCHAR* LPCWCH, * PCWCH;
  137. typedef WCHAR* NWPSTR;
  138. typedef WCHAR* LPWSTR, * PWSTR;
  139. typedef WCHAR* LPUWSTR, * PUWSTR;
  140. typedef const WCHAR* LPCWSTR, * PCWSTR;
  141. typedef const WCHAR* LPCUWSTR, * PCUWSTR;
  142. typedef LPCWSTR LPCTSTR;
  143. typedef LPWSTR LPTSTR;
  144. typedef DWORD COLORREF;
  145. #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
  146. #define GetRValue(rgb) (LOBYTE(rgb))
  147. #define GetGValue(rgb) (LOBYTE(((WORD)(rgb)) >> 8))
  148. #define GetBValue(rgb) (LOBYTE((rgb)>>16))
  149. #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
  150. ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
  151. ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
  152. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  153. // Conflit with OBJC defined bool type.
  154. #if defined(IOS)
  155. typedef bool BOOL;
  156. #else
  157. typedef signed char BOOL;
  158. #endif
  159. typedef int32_t LONG;
  160. typedef unsigned int ULONG;
  161. typedef int HRESULT;
  162. //typedef int32 __int32;
  163. typedef uint32 __uint32;
  164. typedef int64 __int64;
  165. typedef uint64 __uint64;
  166. #define TRUE 1
  167. #define FALSE 0
  168. #ifndef MAX_PATH
  169. #define MAX_PATH PATH_MAX
  170. #endif
  171. #ifndef _MAX_PATH
  172. #define _MAX_PATH MAX_PATH
  173. #endif
  174. #define _PTRDIFF_T_DEFINED 1
  175. typedef union _LARGE_INTEGER
  176. {
  177. struct
  178. {
  179. DWORD LowPart;
  180. LONG HighPart;
  181. };
  182. struct
  183. {
  184. DWORD LowPart;
  185. LONG HighPart;
  186. } u;
  187. long long QuadPart;
  188. } LARGE_INTEGER;
  189. #define _A_RDONLY (0x01) /* Read only file */
  190. #define _A_HIDDEN (0x02) /* Hidden file */
  191. #define _A_SUBDIR (0x10) /* Subdirectory */
  192. //////////////////////////////////////////////////////////////////////////
  193. // Win32 FileAttributes.
  194. //////////////////////////////////////////////////////////////////////////
  195. #define FILE_ATTRIBUTE_READONLY 0x00000001
  196. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  197. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  198. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  199. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  200. #define FILE_ATTRIBUTE_DEVICE 0x00000040
  201. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  202. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  203. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  204. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  205. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  206. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  207. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  208. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  209. #define INVALID_FILE_ATTRIBUTES (-1)
  210. #define BST_UNCHECKED 0x0000
  211. #ifndef HRESULT_VALUES_DEFINED
  212. #define HRESULT_VALUES_DEFINED
  213. enum
  214. {
  215. E_OUTOFMEMORY = 0x8007000E,
  216. E_FAIL = 0x80004005,
  217. E_ABORT = 0x80004004,
  218. E_INVALIDARG = 0x80070057,
  219. E_NOINTERFACE = 0x80004002,
  220. E_NOTIMPL = 0x80004001,
  221. E_UNEXPECTED = 0x8000FFFF
  222. };
  223. #endif
  224. #define ERROR_SUCCESS 0L
  225. enum
  226. {
  227. IDOK = 1,
  228. IDCANCEL = 2,
  229. IDABORT = 3,
  230. IDRETRY = 4,
  231. IDIGNORE = 5,
  232. IDYES = 6,
  233. IDNO = 7,
  234. IDTRYAGAIN = 10,
  235. IDCONTINUE = 11
  236. };
  237. #define MB_OK 0x00000000L
  238. #define MB_OKCANCEL 0x00000001L
  239. #define MB_ABORTRETRYIGNORE 0x00000002L
  240. #define MB_YESNOCANCEL 0x00000003L
  241. #define MB_YESNO 0x00000004L
  242. #define MB_RETRYCANCEL 0x00000005L
  243. #define MB_CANCELTRYCONTINUE 0x00000006L
  244. #define MB_ICONQUESTION 0x00000020L
  245. #define MB_ICONEXCLAMATION 0x00000030L
  246. #define MB_ICONERROR 0x00000010L
  247. #define MB_ICONWARNING 0x00000030L
  248. #define MB_ICONINFORMATION 0x00000040L
  249. #define MB_SETFOREGROUND 0x00010000L
  250. #define MB_APPLMODAL 0x00000000L
  251. #define MK_LBUTTON 0x0001
  252. #define MK_RBUTTON 0x0002
  253. #define MK_SHIFT 0x0004
  254. #define MK_CONTROL 0x0008
  255. #define MK_MBUTTON 0x0010
  256. #define SM_MOUSEPRESENT 0x00000000L
  257. #define SM_CMOUSEBUTTONS 43
  258. #define VK_TAB 0x09
  259. #define VK_SHIFT 0x10
  260. #define VK_MENU 0x12
  261. #define VK_ESCAPE 0x1B
  262. #define VK_SPACE 0x20
  263. #define VK_DELETE 0x2E
  264. #define VK_OEM_COMMA 0xBC // ',' any country
  265. #define VK_OEM_PERIOD 0xBE // '.' any country
  266. #define VK_OEM_3 0xC0 // '`~' for US
  267. #define VK_OEM_4 0xDB // '[{' for US
  268. #define VK_OEM_6 0xDD // ']}' for US
  269. #define WAIT_TIMEOUT 258L // dderror
  270. #define WM_MOVE 0x0003
  271. #define WM_USER 0x0400
  272. #define WHEEL_DELTA 120
  273. #define WS_CHILD 0x40000000L
  274. #define WS_VISIBLE 0x10000000L
  275. #define CB_ERR (-1)
  276. // function renaming
  277. #define _finite std::isfinite
  278. #define _snprintf snprintf
  279. //#define _isnan isnan
  280. #define stricmp strcasecmp
  281. #define _stricmp strcasecmp
  282. #define strnicmp strncasecmp
  283. #define _strnicmp strncasecmp
  284. #define wcsicmp wcscasecmp
  285. #define wcsnicmp wcsncasecmp
  286. //#define memcpy_s(dest,bytes,src,n) memcpy(dest,src,n)
  287. #define _isnan ISNAN
  288. #define TARGET_DEFAULT_ALIGN (0x8U)
  289. #define _msize malloc_size
  290. struct _OVERLAPPED;
  291. typedef void (* LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, struct _OVERLAPPED* lpOverlapped);
  292. typedef struct _OVERLAPPED
  293. {
  294. void* pCaller;//this is orginally reserved for internal purpose, we store the Caller pointer here
  295. LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine; ////this is orginally ULONG_PTR InternalHigh and reserved for internal purpose
  296. union
  297. {
  298. struct
  299. {
  300. DWORD Offset;
  301. DWORD OffsetHigh;
  302. };
  303. PVOID Pointer;
  304. };
  305. DWORD dwNumberOfBytesTransfered; //additional member temporary speciying the number of bytes to be read
  306. /*HANDLE*/ void* hEvent;
  307. } OVERLAPPED, * LPOVERLAPPED;
  308. typedef struct _SECURITY_ATTRIBUTES
  309. {
  310. DWORD nLength;
  311. LPVOID lpSecurityDescriptor;
  312. BOOL bInheritHandle;
  313. } SECURITY_ATTRIBUTES, * PSECURITY_ATTRIBUTES, * LPSECURITY_ATTRIBUTES;
  314. #ifdef __cplusplus
  315. #define __min(_S, _T) min(_S, _T)
  316. #define __max(_S, _T) max(_S, _T)
  317. typedef enum
  318. {
  319. INVALID_HANDLE_VALUE = -1l
  320. }INVALID_HANDLE_VALUE_ENUM;
  321. //for compatibility reason we got to create a class which actually contains an int rather than a void* and make sure it does not get mistreated
  322. template <class T, T U>
  323. //U is default type for invalid handle value, T the encapsulated handle type to be used instead of void* (as under windows and never linux)
  324. class CHandle
  325. {
  326. public:
  327. typedef T HandleType;
  328. typedef void* PointerType; //for compatibility reason to encapsulate a void* as an int
  329. static const HandleType sciInvalidHandleValue = U;
  330. CHandle(const CHandle<T, U>& cHandle)
  331. : m_Value(cHandle.m_Value){}
  332. CHandle(const HandleType cHandle = U)
  333. : m_Value(cHandle){}
  334. CHandle(const PointerType cpHandle)
  335. : m_Value(reinterpret_cast<HandleType>(cpHandle)){}
  336. CHandle(INVALID_HANDLE_VALUE_ENUM)
  337. : m_Value(U){} //to be able to use a common value for all InvalidHandle - types
  338. #if defined(PLATFORM_64BIT)
  339. //treat __null tyope also as invalid handle type
  340. CHandle(long)
  341. : m_Value(U){} //to be able to use a common value for all InvalidHandle - types
  342. #endif
  343. operator HandleType(){
  344. return m_Value;
  345. }
  346. bool operator!() const{return m_Value == sciInvalidHandleValue; }
  347. const CHandle& operator =(const CHandle& crHandle){m_Value = crHandle.m_Value; return *this; }
  348. const CHandle& operator =(const PointerType cpHandle){m_Value = (HandleType) reinterpret_cast<UINT_PTR>(cpHandle); return *this; }
  349. const bool operator ==(const CHandle& crHandle) const{return m_Value == crHandle.m_Value; }
  350. const bool operator ==(const HandleType cHandle) const{return m_Value == cHandle; }
  351. const bool operator ==(const PointerType cpHandle) const{return m_Value == reinterpret_cast<HandleType>(cpHandle); }
  352. const bool operator !=(const HandleType cHandle) const{return m_Value != cHandle; }
  353. const bool operator !=(const CHandle& crHandle) const{return m_Value != crHandle.m_Value; }
  354. const bool operator !=(const PointerType cpHandle) const{return m_Value != reinterpret_cast<HandleType>(cpHandle); }
  355. const bool operator < (const CHandle& crHandle) const{return m_Value < crHandle.m_Value; }
  356. HandleType Handle() const{return m_Value; }
  357. private:
  358. HandleType m_Value; //the actual value, remember that file descriptors are ints under linux
  359. typedef void ReferenceType;//for compatibility reason to encapsulate a void* as an int
  360. //forbid these function which would actually not work on an int
  361. PointerType operator->();
  362. PointerType operator->() const;
  363. ReferenceType operator*();
  364. ReferenceType operator*() const;
  365. operator PointerType();
  366. };
  367. typedef CHandle<int, (int) - 1l> HANDLE;
  368. typedef HANDLE EVENT_HANDLE;
  369. typedef HANDLE THREAD_HANDLE;
  370. typedef HANDLE HKEY;
  371. typedef HANDLE HDC;
  372. typedef HANDLE HBITMAP;
  373. typedef HANDLE HMENU;
  374. #endif //__cplusplus
  375. extern bool QueryPerformanceCounter(LARGE_INTEGER*);
  376. extern bool QueryPerformanceFrequency(LARGE_INTEGER* frequency);
  377. inline int64 CryGetTicks()
  378. {
  379. LARGE_INTEGER counter;
  380. QueryPerformanceCounter(&counter);
  381. return counter.QuadPart;
  382. }
  383. #ifdef _RELEASE
  384. #define __debugbreak()
  385. #else
  386. #define __debugbreak() ::raise(SIGTRAP)
  387. #endif
  388. #define __assume(x)
  389. #define _flushall sync
  390. inline int closesocket(int s)
  391. {
  392. return ::close(s);
  393. }
  394. template <typename T, size_t N>
  395. char (*RtlpNumberOf( T (&)[N] ))[N];
  396. #define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
  397. #define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
  398. #undef SUCCEEDED
  399. #define SUCCEEDED(x) ((x) >= 0)
  400. #undef FAILED
  401. #define FAILED(x) (!(SUCCEEDED(x)))
  402. #endif // CRYINCLUDE_CRYCOMMON_APPLESPECIFIC_H