Skip to content

Commit

Permalink
Common: update Linux defines
Browse files Browse the repository at this point in the history
xrCore: some fixes for linix build && file read
  • Loading branch information
eagleivg committed May 23, 2018
1 parent 3291f1a commit 319423a
Show file tree
Hide file tree
Showing 28 changed files with 672 additions and 26 deletions.
46 changes: 46 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.5)

project(XRAY)

include(${CMAKE_SOURCE_DIR}/utils.cmake)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include_directories (
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/src"
)

add_definitions(
-D_MT
-D_CPPUNWIND
-DPURE_DYNAMIC_CAST
-DDECLARE_SPECIALIZATION
-DM_NOSTDCONTAINERS_EXT
-DUSE_OGL
)

add_compile_options(-std=c++14 -fpermissive)

#find_package(Lua51 REQUIRED)
#find_package(OpenSSL REQUIRED)
#find_package(Theora REQUIRED)
#find_package(OGG REQUIRED)
#find_package(SDL2 REQUIRED)
#find_package(LZO REQUIRED)

add_library(tbb SHARED IMPORTED GLOBAL)
add_library(lzo SHARED IMPORTED GLOBAL)
add_library(pugixml SHARED IMPORTED GLOBAL)
add_library(SDL2 SHARED IMPORTED GLOBAL)


add_subdirectory(
xrCore
)
# xrEngine
# xrGame
# xrParticles
# xrPhysics
# xrScriptEngine
# xrSound
257 changes: 257 additions & 0 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
#include <stdio.h>
#include <cstring>
#include <stdlib.h> // for malloc
#include <unistd.h> // for rmdir
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
#include <limits.h> // for PAGESIZE...
#include <math.h>
#include <algorithm> // for min max

#include <string>
#include <alloca.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/mman.h> // for mmap / munmap
#include <dirent.h>
#include <utime.h>

#include <SDL2/SDL.h>
#define CONFIG_USE_SDL

#define _LINUX // for GameSpy

#if !defined(__INTEL_COMPILER)
#define _alloca alloca
#endif

#define _MAX_PATH PATH_MAX + 1
#define MAX_PATH PATH_MAX + 1

#define WINAPI

#define _copysign copysign

#define _cdecl //__attribute__((cdecl))
#define _stdcall //__attribute__((stdcall))
#define _fastcall //__attribute__((fastcall))

#define __cdecl
#define __stdcall
#define __fastcall

//#define __declspec
#define __forceinline FORCE_INLINE
#define __pragma(...) _Pragma(#__VA_ARGS__)
#define __declspec(x)
#define CALLBACK

#define __except(X) catch(X)

/*
static inline long InterlockedExchange(volatile long *val, long new_val)
{
long old_val;
do {
old_val = *val;
} while (__sync_val_compare_and_swap (val, old_val, new_val) != old_val);
return old_val;
}
*/

inline pthread_t GetCurrentThreadId()
{
return pthread_self();
}

inline void Sleep(int ms)
{
SDL_Delay(ms);
}

inline void _splitpath (
const char *path, // Path Input
char *drive, // Drive : Output
char *dir, // Directory : Output
char *fname, // Filename : Output
char *ext // Extension : Output
){}

inline unsigned long GetLastError()
{
return 0;
}

inline int GetExceptionCode()
{
return 0;
}

#define xr_unlink unlink

typedef char BOOL;
typedef char* LPSTR;
typedef char* PSTR;
typedef char* LPTSTR;
typedef const char* LPCSTR;
typedef const char* LPCTSTR;
typedef unsigned char BYTE;
typedef unsigned char* LPBYTE;
typedef unsigned int UINT;
typedef int INT;
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long& ULONG_PTR;
typedef long long int LARGE_INTEGER;
typedef unsigned long long int ULARGE_INTEGER;

typedef unsigned short WORD;
typedef unsigned short* LPWORD;
typedef unsigned long DWORD;
typedef unsigned long* LPDWORD;
typedef const void *LPCVOID;
typedef long long int *PLARGE_INTEGER;

typedef wchar_t WCHAR;

#define WAVE_FORMAT_PCM 0x0001

typedef struct {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX, *LPWAVEFORMATEX;

typedef struct _EXCEPTION_POINTERS {
} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;

#ifdef XR_X64
typedef int64_t INT_PTR;
typedef uint16_t UINT_PTR;
typedef int64_t LONG_PTR;
#else
typedef int INT_PTR;
typedef unsigned int UINT_PTR;
typedef long LONG_PTR;
#endif // XR_X64

typedef int HANDLE;
typedef void *HMODULE;
typedef void *LPVOID;
typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef long HRESULT;
typedef long LRESULT;
typedef long _W64;
//typedef void *HWND;
typedef SDL_Window *HWND;
typedef void *HDC;
//typedef void *HGLRC;
typedef SDL_GLContext HGLRC;
typedef float FLOAT;
typedef unsigned char UINT8;

typedef struct _RECT {
long left;
long top;
long right;
long bottom;
} RECT, *PRECT;

typedef struct tagPOINT {
long x;
long y;
} POINT, *PPOINT, *LPPOINT;

#define WM_USER 0x0400

#define TRUE 1
#define FALSE 0
#define NONE 0
#define CONST const

typedef dirent DirEntryType;

#define _O_WRONLY O_WRONLY
#define _O_RDONLY O_RDONLY
#define _O_TRUNC O_TRUNC
#define _O_CREAT O_CREAT
#define _S_IWRITE S_IWRITE
#define _S_IREAD S_IREAD
#define _O_BINARY 0
#define O_BINARY 0
#define O_SEQUENTIAL 0
#define SH_DENYWR 0

#define _stricmp stricmp
#define strcmpi stricmp
#define lstrcpy strcpy
#define stricmp strcasecmp
#define strncpy_s(dest, size, source, num) strncpy(dest, source, num)
#define strcpy_s(dest, num, source) strcpy(dest, source)
#define _vsnprintf vsnprintf
#define _alloca alloca
#define _snprintf snprintf
#define sprintf_s(buffer, buffer_size, stringbuffer, ...) sprintf(buffer, stringbuffer, ##__VA_ARGS__)
#define GetProcAddress(handle, name) dlsym(handle, name)
#define _chdir chdir
#define _strnicmp strnicmp
#define strnicmp strncasecmp
#define _getcwd getcwd
#define _snwprintf swprintf
#define swprintf_s swprintf
#define wcsicmp _wcsicmp
#define _wcsicmp wcscmp
#define _tempnam tempnam
#define _unlink unlink
#define _access access
#define _open open
#define _close close
#define _sopen open
#define _sopen_s(handle, filename, ...) open(filename, O_RDONLY)
inline int _filelength(int fd)
{
struct stat file_info;
::fstat(fd, &file_info);
return file_info.st_size;
}
#define _fdopen fdopen
#define _rmdir rmdir
#define _write write
#define _strupr strupr
#define _read read
#define _set_new_handler std::set_new_handler
#define _finite isfinite
#define _mkdir(dir) mkdir(dir, S_IRWXU)
#define _wtoi(arg) wcstol(arg, NULL, 10)
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
#undef min
#undef max
#define __max(a, b) std::max(a, b)
#define __min(a, b) std::min(a, b)

#define xr_itoa SDL_itoa

#define ZeroMemory(p, sz) memset((p), 0, (sz))
#define CopyMemory(d, s, n) memcpy(d, s, n)

#define RGB(r,g,b) ( ((DWORD)(BYTE)r)|((DWORD)((BYTE)g)<<8)|((DWORD)((BYTE)b)<<16) )
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#define FAILED(hr) (((HRESULT)(hr)) < 0)
#define S_OK 0x00000000
#define S_FALSE 0x10000000
#define E_FAIL 0x80004005

#define _MAX_DRIVE 3
#define _MAX_DIR 256
#define _MAX_FNAME 256
#define _MAX_EXT 256
11 changes: 11 additions & 0 deletions src/utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro(add_dir DIRS)
foreach(dir ${DIRS})
message( "adding " ${dir} )
include_directories (${dir} )
file( GLOB ${dir}__INCLUDES_H ${dir} *.h)
file( GLOB ${dir}__INCLUDES_HPP ${dir} *.hpp)
list( APPEND XRCORE__INCLUDES ${${dir}__INCLUDES_H} ${${dir}__INCLUDES_HPP} )
file( GLOB ${dir}__SOURCES ${dir} *.cpp)
list( APPEND XRCORE__SOURCES ${${dir}__SOURCES} )
endforeach()
endmacro()
21 changes: 21 additions & 0 deletions src/xrCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)

add_dir (
"."
"Animation"
"Compression"
"Containers"
"Crypto"
"Math"
"Media"
"PostProcess"
"Text"
"Threading"
"XML"
)

message( "path " ${CMAKE_CURRENT_SOURCE_DIR} )

add_library(xrCore SHARED ${XRCORE__SOURCES} ${XRCORE__INCLUDES})

#target_link_libraries(xrCore ${SDL2_LIBRARY} ${OPENSSL_LIBRARIES} ${LZO_LIBRARIES})
Loading

0 comments on commit 319423a

Please sign in to comment.