Skip to content

Commit 319423a

Browse files
committed
Common: update Linux defines
xrCore: some fixes for linix build && file read
1 parent 3291f1a commit 319423a

28 files changed

+672
-26
lines changed

src/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(XRAY)
4+
5+
include(${CMAKE_SOURCE_DIR}/utils.cmake)
6+
7+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
8+
9+
include_directories (
10+
"${PROJECT_SOURCE_DIR}"
11+
"${PROJECT_SOURCE_DIR}/src"
12+
)
13+
14+
add_definitions(
15+
-D_MT
16+
-D_CPPUNWIND
17+
-DPURE_DYNAMIC_CAST
18+
-DDECLARE_SPECIALIZATION
19+
-DM_NOSTDCONTAINERS_EXT
20+
-DUSE_OGL
21+
)
22+
23+
add_compile_options(-std=c++14 -fpermissive)
24+
25+
#find_package(Lua51 REQUIRED)
26+
#find_package(OpenSSL REQUIRED)
27+
#find_package(Theora REQUIRED)
28+
#find_package(OGG REQUIRED)
29+
#find_package(SDL2 REQUIRED)
30+
#find_package(LZO REQUIRED)
31+
32+
add_library(tbb SHARED IMPORTED GLOBAL)
33+
add_library(lzo SHARED IMPORTED GLOBAL)
34+
add_library(pugixml SHARED IMPORTED GLOBAL)
35+
add_library(SDL2 SHARED IMPORTED GLOBAL)
36+
37+
38+
add_subdirectory(
39+
xrCore
40+
)
41+
# xrEngine
42+
# xrGame
43+
# xrParticles
44+
# xrPhysics
45+
# xrScriptEngine
46+
# xrSound

src/Common/PlatformLinux.inl

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#include <stdio.h>
2+
#include <cstring>
3+
#include <stdlib.h> // for malloc
4+
#include <unistd.h> // for rmdir
5+
#include <sys/fcntl.h>
6+
#include <sys/stat.h>
7+
#include <sys/types.h>
8+
#include <sys/param.h>
9+
#include <errno.h>
10+
#include <stdarg.h>
11+
#include <ctype.h>
12+
#include <limits.h> // for PAGESIZE...
13+
#include <math.h>
14+
#include <algorithm> // for min max
15+
16+
#include <string>
17+
#include <alloca.h>
18+
#include <pthread.h>
19+
#include <fcntl.h>
20+
#include <sys/mman.h> // for mmap / munmap
21+
#include <dirent.h>
22+
#include <utime.h>
23+
24+
#include <SDL2/SDL.h>
25+
#define CONFIG_USE_SDL
26+
27+
#define _LINUX // for GameSpy
28+
29+
#if !defined(__INTEL_COMPILER)
30+
#define _alloca alloca
31+
#endif
32+
33+
#define _MAX_PATH PATH_MAX + 1
34+
#define MAX_PATH PATH_MAX + 1
35+
36+
#define WINAPI
37+
38+
#define _copysign copysign
39+
40+
#define _cdecl //__attribute__((cdecl))
41+
#define _stdcall //__attribute__((stdcall))
42+
#define _fastcall //__attribute__((fastcall))
43+
44+
#define __cdecl
45+
#define __stdcall
46+
#define __fastcall
47+
48+
//#define __declspec
49+
#define __forceinline FORCE_INLINE
50+
#define __pragma(...) _Pragma(#__VA_ARGS__)
51+
#define __declspec(x)
52+
#define CALLBACK
53+
54+
#define __except(X) catch(X)
55+
56+
/*
57+
static inline long InterlockedExchange(volatile long *val, long new_val)
58+
{
59+
long old_val;
60+
do {
61+
old_val = *val;
62+
} while (__sync_val_compare_and_swap (val, old_val, new_val) != old_val);
63+
return old_val;
64+
}
65+
*/
66+
67+
inline pthread_t GetCurrentThreadId()
68+
{
69+
return pthread_self();
70+
}
71+
72+
inline void Sleep(int ms)
73+
{
74+
SDL_Delay(ms);
75+
}
76+
77+
inline void _splitpath (
78+
const char *path, // Path Input
79+
char *drive, // Drive : Output
80+
char *dir, // Directory : Output
81+
char *fname, // Filename : Output
82+
char *ext // Extension : Output
83+
){}
84+
85+
inline unsigned long GetLastError()
86+
{
87+
return 0;
88+
}
89+
90+
inline int GetExceptionCode()
91+
{
92+
return 0;
93+
}
94+
95+
#define xr_unlink unlink
96+
97+
typedef char BOOL;
98+
typedef char* LPSTR;
99+
typedef char* PSTR;
100+
typedef char* LPTSTR;
101+
typedef const char* LPCSTR;
102+
typedef const char* LPCTSTR;
103+
typedef unsigned char BYTE;
104+
typedef unsigned char* LPBYTE;
105+
typedef unsigned int UINT;
106+
typedef int INT;
107+
typedef long LONG;
108+
typedef unsigned long ULONG;
109+
typedef unsigned long& ULONG_PTR;
110+
typedef long long int LARGE_INTEGER;
111+
typedef unsigned long long int ULARGE_INTEGER;
112+
113+
typedef unsigned short WORD;
114+
typedef unsigned short* LPWORD;
115+
typedef unsigned long DWORD;
116+
typedef unsigned long* LPDWORD;
117+
typedef const void *LPCVOID;
118+
typedef long long int *PLARGE_INTEGER;
119+
120+
typedef wchar_t WCHAR;
121+
122+
#define WAVE_FORMAT_PCM 0x0001
123+
124+
typedef struct {
125+
WORD wFormatTag;
126+
WORD nChannels;
127+
DWORD nSamplesPerSec;
128+
DWORD nAvgBytesPerSec;
129+
WORD nBlockAlign;
130+
WORD wBitsPerSample;
131+
WORD cbSize;
132+
} WAVEFORMATEX, *LPWAVEFORMATEX;
133+
134+
typedef struct _EXCEPTION_POINTERS {
135+
} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
136+
137+
#ifdef XR_X64
138+
typedef int64_t INT_PTR;
139+
typedef uint16_t UINT_PTR;
140+
typedef int64_t LONG_PTR;
141+
#else
142+
typedef int INT_PTR;
143+
typedef unsigned int UINT_PTR;
144+
typedef long LONG_PTR;
145+
#endif // XR_X64
146+
147+
typedef int HANDLE;
148+
typedef void *HMODULE;
149+
typedef void *LPVOID;
150+
typedef UINT_PTR WPARAM;
151+
typedef LONG_PTR LPARAM;
152+
typedef long HRESULT;
153+
typedef long LRESULT;
154+
typedef long _W64;
155+
//typedef void *HWND;
156+
typedef SDL_Window *HWND;
157+
typedef void *HDC;
158+
//typedef void *HGLRC;
159+
typedef SDL_GLContext HGLRC;
160+
typedef float FLOAT;
161+
typedef unsigned char UINT8;
162+
163+
typedef struct _RECT {
164+
long left;
165+
long top;
166+
long right;
167+
long bottom;
168+
} RECT, *PRECT;
169+
170+
typedef struct tagPOINT {
171+
long x;
172+
long y;
173+
} POINT, *PPOINT, *LPPOINT;
174+
175+
#define WM_USER 0x0400
176+
177+
#define TRUE 1
178+
#define FALSE 0
179+
#define NONE 0
180+
#define CONST const
181+
182+
typedef dirent DirEntryType;
183+
184+
#define _O_WRONLY O_WRONLY
185+
#define _O_RDONLY O_RDONLY
186+
#define _O_TRUNC O_TRUNC
187+
#define _O_CREAT O_CREAT
188+
#define _S_IWRITE S_IWRITE
189+
#define _S_IREAD S_IREAD
190+
#define _O_BINARY 0
191+
#define O_BINARY 0
192+
#define O_SEQUENTIAL 0
193+
#define SH_DENYWR 0
194+
195+
#define _stricmp stricmp
196+
#define strcmpi stricmp
197+
#define lstrcpy strcpy
198+
#define stricmp strcasecmp
199+
#define strncpy_s(dest, size, source, num) strncpy(dest, source, num)
200+
#define strcpy_s(dest, num, source) strcpy(dest, source)
201+
#define _vsnprintf vsnprintf
202+
#define _alloca alloca
203+
#define _snprintf snprintf
204+
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) sprintf(buffer, stringbuffer, ##__VA_ARGS__)
205+
#define GetProcAddress(handle, name) dlsym(handle, name)
206+
#define _chdir chdir
207+
#define _strnicmp strnicmp
208+
#define strnicmp strncasecmp
209+
#define _getcwd getcwd
210+
#define _snwprintf swprintf
211+
#define swprintf_s swprintf
212+
#define wcsicmp _wcsicmp
213+
#define _wcsicmp wcscmp
214+
#define _tempnam tempnam
215+
#define _unlink unlink
216+
#define _access access
217+
#define _open open
218+
#define _close close
219+
#define _sopen open
220+
#define _sopen_s(handle, filename, ...) open(filename, O_RDONLY)
221+
inline int _filelength(int fd)
222+
{
223+
struct stat file_info;
224+
::fstat(fd, &file_info);
225+
return file_info.st_size;
226+
}
227+
#define _fdopen fdopen
228+
#define _rmdir rmdir
229+
#define _write write
230+
#define _strupr strupr
231+
#define _read read
232+
#define _set_new_handler std::set_new_handler
233+
#define _finite isfinite
234+
#define _mkdir(dir) mkdir(dir, S_IRWXU)
235+
#define _wtoi(arg) wcstol(arg, NULL, 10)
236+
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
237+
#undef min
238+
#undef max
239+
#define __max(a, b) std::max(a, b)
240+
#define __min(a, b) std::min(a, b)
241+
242+
#define xr_itoa SDL_itoa
243+
244+
#define ZeroMemory(p, sz) memset((p), 0, (sz))
245+
#define CopyMemory(d, s, n) memcpy(d, s, n)
246+
247+
#define RGB(r,g,b) ( ((DWORD)(BYTE)r)|((DWORD)((BYTE)g)<<8)|((DWORD)((BYTE)b)<<16) )
248+
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
249+
#define FAILED(hr) (((HRESULT)(hr)) < 0)
250+
#define S_OK 0x00000000
251+
#define S_FALSE 0x10000000
252+
#define E_FAIL 0x80004005
253+
254+
#define _MAX_DRIVE 3
255+
#define _MAX_DIR 256
256+
#define _MAX_FNAME 256
257+
#define _MAX_EXT 256

src/utils.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
macro(add_dir DIRS)
2+
foreach(dir ${DIRS})
3+
message( "adding " ${dir} )
4+
include_directories (${dir} )
5+
file( GLOB ${dir}__INCLUDES_H ${dir} *.h)
6+
file( GLOB ${dir}__INCLUDES_HPP ${dir} *.hpp)
7+
list( APPEND XRCORE__INCLUDES ${${dir}__INCLUDES_H} ${${dir}__INCLUDES_HPP} )
8+
file( GLOB ${dir}__SOURCES ${dir} *.cpp)
9+
list( APPEND XRCORE__SOURCES ${${dir}__SOURCES} )
10+
endforeach()
11+
endmacro()

src/xrCore/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
add_dir (
4+
"."
5+
"Animation"
6+
"Compression"
7+
"Containers"
8+
"Crypto"
9+
"Math"
10+
"Media"
11+
"PostProcess"
12+
"Text"
13+
"Threading"
14+
"XML"
15+
)
16+
17+
message( "path " ${CMAKE_CURRENT_SOURCE_DIR} )
18+
19+
add_library(xrCore SHARED ${XRCORE__SOURCES} ${XRCORE__INCLUDES})
20+
21+
#target_link_libraries(xrCore ${SDL2_LIBRARY} ${OPENSSL_LIBRARIES} ${LZO_LIBRARIES})

0 commit comments

Comments
 (0)