Skip to content

Commit

Permalink
xrEngine: some Linux fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Jul 6, 2018
1 parent 0805db3 commit dbc99d4
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ os:
- linux
before_script:
- g++ --version
- sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev libpugixml-dev libopenal-dev libtbb-dev libcrypto++-dev
- sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev libpugixml-dev libopenal-dev libtbb-dev libcrypto++-dev liblockfile-dev
- sudo apt-get install cmake lua5.1-dev libssl-dev libogg-dev libtheora-dev libvorbis-dev libsdl2-dev liblzo2-dev libjpeg-dev libncurses5-dev
- mkdir bin
- cd bin
Expand Down
35 changes: 32 additions & 3 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@
#define __pragma(...) _Pragma(#__VA_ARGS__)
#define __declspec(x)
#define CALLBACK
#define TEXT(x) strdup(x)

inline char *_strlwr_l(char *str, locale_t loc)
{
//TODO
}

inline char *_strupr_l(char *str, locale_t loc)
{
//TODO
}

#define VOID void
#define HKL void *
#define ActivateKeyboardLayout(x, y) {}
#define GetCursorPos(point) {}
#define ScreenToClient(hwnd, p) {}

#define __except(X) catch(X)

Expand Down Expand Up @@ -94,7 +111,7 @@ inline int GetExceptionCode()

#define xr_unlink unlink

typedef char BOOL;
typedef bool BOOL;
typedef char* LPSTR;
typedef char* PSTR;
typedef char* LPTSTR;
Expand Down Expand Up @@ -194,10 +211,15 @@ typedef struct tagPOINT {
long y;
} POINT, *PPOINT, *LPPOINT;

#define DWORD_PTR UINT_PTR
#define WM_USER 0x0400
#define WA_INACTIVE 0
#define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16))
#define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xFFFF))

#define TRUE 1
#define FALSE 0

#define TRUE true
#define FALSE false
#define NONE 0
#define CONST const

Expand All @@ -218,6 +240,7 @@ typedef dirent DirEntryType;
#define strcmpi stricmp
#define lstrcpy strcpy
#define stricmp strcasecmp
#define strupr SDL_strupr
#define strncpy_s(dest, size, source, num) (NULL == strncpy(dest, source, num))
#define strcpy_s(dest, num, source) (NULL == strcpy(dest, source))
#define strcat_s(dest, num, source) (dest == strcat(dest, source))
Expand Down Expand Up @@ -267,6 +290,9 @@ inline int _filelength(int fd)

#define itoa SDL_itoa
#define _itoa_s(value, buffer, radix) SDL_itoa(value, buffer, radix)
#define _locale_t locale_t
#define _isalpha_l isalpha_l
#define _create_locale(category, arg) newlocale(category, arg, (locale_t) 0)

#define ZeroMemory(p, sz) memset((p), 0, (sz))
#define CopyMemory(d, s, n) memcpy(d, s, n)
Expand All @@ -282,3 +308,6 @@ inline int _filelength(int fd)
#define _MAX_DIR 256
#define _MAX_FNAME 256
#define _MAX_EXT 256

#define SEM_FAILCRITICALERRORS 1
#define SetErrorMode(x) {x=x}
5 changes: 5 additions & 0 deletions src/xrCore/_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ extern XRCORE_API void _initialize_cpu_thread();
using thread_t = void(void*);
extern XRCORE_API void thread_name(const char* name);
extern XRCORE_API void thread_spawn(thread_t* entry, const char* name, unsigned stack, void* arglist);

#if defined(LINUX)
void QueryPerformanceCounter(PLARGE_INTEGER result);
DWORD timeGetTime();
#endif
7 changes: 5 additions & 2 deletions src/xrEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/OpenAutomate/inc
${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/FreeImage/Dist/x64
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include
${CMAKE_CURRENT_SOURCE_DIR}/../../Externals/luabind
/usr/include/SDL2
)

list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/./tntQAVI.cpp")
list(REMOVE_ITEM ${PROJECT_NAME}__SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/./editor_environment_manager_properties.cpp")
#list(REMOVE_ITEM ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/./xr_cda.h")

list(REMOVE_ITEM ${PROJECT_NAME}__INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/./tntQAVI.h")

add_definitions(-DENGINE_BUILD)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}__SOURCES} ${${PROJECT_NAME}__INCLUDES})

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
target_link_libraries(${PROJECT_NAME} xrCore luabind xrAPI xrSound xrScriptEngine luajit theora ${OGG_LIBRARIES} xrNetServer xrCDB xrPhysics openal)
target_link_libraries(${PROJECT_NAME} xrCore luabind xrAPI xrSound xrScriptEngine luajit theora ${OGG_LIBRARIES} xrNetServer xrCDB xrPhysics openal lockfile)
7 changes: 4 additions & 3 deletions src/xrEngine/Device_Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "PerformanceAlert.hpp"
#include "xrCore/ModuleLookup.hpp"

extern LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

void CRenderDevice::initialize_weather_editor()
{
m_editor_module = XRay::LoadModule("xrWeatherEditor");
Expand Down Expand Up @@ -48,7 +46,10 @@ void CRenderDevice::Initialize()

if (!m_sdlWnd)
{
Uint32 flags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALWAYS_ON_TOP;
Uint32 flags = SDL_WINDOW_BORDERLESS;
#if SDL_VERSION_ATLEAST(2, 0, 5)
flags |= SDL_WINDOW_ALWAYS_ON_TOP;
#endif

if (strstr(Core.Params, "-gl"))
flags |= SDL_WINDOW_OPENGL;
Expand Down
3 changes: 3 additions & 0 deletions src/xrEngine/Device_wndproc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"

#if defined(WINDOWS)
bool CRenderDevice::on_message(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result)
{
switch (uMsg)
Expand Down Expand Up @@ -53,6 +54,7 @@ bool CRenderDevice::on_message(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara

return (false);
}

//-----------------------------------------------------------------------------
// Name: WndProc()
// Desc: Static msg handler which passes messages to the application class.
Expand All @@ -65,3 +67,4 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
#endif
4 changes: 4 additions & 0 deletions src/xrEngine/EngineAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ CEngineAPI::~CEngineAPI()

bool is_enough_address_space_available()
{
#if defined(WINDOWS)
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return (*(u32*)&system_info.lpMaximumApplicationAddress) > 0x90000000;
#else
return TRUE; // In linux allocated memory limited only by pointer size
#endif
}

void CEngineAPI::SetupCurrentRenderer()
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/Feel_Sound.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "xrSound/sound.h"
#include "xrSound/Sound.h"

// fwd. decl.
class IGameObject;
Expand Down
2 changes: 2 additions & 0 deletions src/xrEngine/IObjectPhysicsCollision.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class IPhysicsShell;
class IPhysicsElement;
#if defined(WINDOWS)
xr_pure_interface IObjectPhysicsCollision
{
public:
virtual const IPhysicsShell* physics_shell() const = 0;
virtual const IPhysicsElement* physics_character() const = 0; // depricated
};
#endif
2 changes: 2 additions & 0 deletions src/xrEngine/IPHdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "xrCore/_types.h"

#if defined(WINDOWS)
xr_pure_interface IPhDebugRender
{
virtual void open_cashed_draw() = 0;
Expand All @@ -10,3 +11,4 @@ xr_pure_interface IPhDebugRender
};

extern ENGINE_API IPhDebugRender* ph_debug_render;
#endif
2 changes: 2 additions & 0 deletions src/xrEngine/Text_Console_WndProc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "Text_Console.h"

#if defined(WINDOWS)
LRESULT CALLBACK TextConsole_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
Expand Down Expand Up @@ -51,3 +52,4 @@ LRESULT CALLBACK TextConsole_LogWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
#endif
12 changes: 6 additions & 6 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#define MMNOAUX
#define MMNOMIXER
#define MMNOJOY
#if defined(WINDOWS)
#include <mmsystem.h>
#endif
#include <SDL.h>
#pragma warning(pop)

Expand Down Expand Up @@ -329,9 +331,8 @@ void CRenderDevice::message_loop()
return;
}


SDL_PumpEvents();

SDL_Event event;

SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_SYSWMEVENT);
Expand All @@ -356,7 +357,7 @@ void CRenderDevice::message_loop()
#if SDL_VERSION_ATLEAST(2, 0, 5)
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_EXPOSED:
//case SDL_WINDOWEVENT_TAKE_FOCUS:
// case SDL_WINDOWEVENT_TAKE_FOCUS:
if (editor())
{
Device.b_is_Active = TRUE;
Expand All @@ -375,12 +376,11 @@ void CRenderDevice::message_loop()

on_idle();
}

/*
while (true)
on_idle();
*/

}

void CRenderDevice::Run()
Expand Down Expand Up @@ -531,7 +531,7 @@ void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)
u16 fActive = LOWORD(wParam);
const BOOL fMinimized = (BOOL)HIWORD(wParam);

const BOOL isWndActive = (fActive != WA_INACTIVE && !fMinimized) ? TRUE : FALSE;
const BOOL isWndActive = (fActive != WA_INACTIVE && (!fMinimized)) ? TRUE : FALSE;
if (!editor() && !GEnv.isDedicatedServer && isWndActive)
pInput->ClipCursor(true);
else
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/edit_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define EDIT_ACTIONS_H_INCLUDED

#include "Common/Noncopyable.hpp"
#include "line_edit_control.h"

namespace text_editor
{
Expand Down
15 changes: 14 additions & 1 deletion src/xrEngine/editor_environment_detail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include "stdafx.h"

#include "editor_environment_detail.hpp"
#ifdef _WIN32
#include <shlwapi.h>

#pragma comment(lib, "shlwapi.lib")

#endif
using editor::environment::detail::logical_string_predicate;

static HRESULT AnsiToUnicode(pcstr pszA, LPVOID buffer, u32 const& buffer_size)
{
#if defined(WINDOWS)
VERIFY(pszA);
VERIFY(buffer);
VERIFY(buffer_size);
Expand All @@ -28,10 +30,14 @@ static HRESULT AnsiToUnicode(pcstr pszA, LPVOID buffer, u32 const& buffer_size)
return (NOERROR);

return (HRESULT_FROM_WIN32(GetLastError()));
#else
return 0;
#endif
}

bool logical_string_predicate::operator()(pcstr const& first, pcstr const& second) const
{
#if defined(WINDOWS)
u32 buffer_size0 = (xr_strlen(first) + 1) * 2;
LPCWSTR buffer0 = (LPCWSTR)_alloca(buffer_size0);
AnsiToUnicode(first, (LPVOID)buffer0, buffer_size0);
Expand All @@ -41,10 +47,14 @@ bool logical_string_predicate::operator()(pcstr const& first, pcstr const& secon
AnsiToUnicode(second, (LPVOID)buffer1, buffer_size1);

return (StrCmpLogicalW(buffer0, buffer1) < 0);
#else
return false;
#endif
}

bool logical_string_predicate::operator()(shared_str const& first, shared_str const& second) const
{
#if defined(WINDOWS)
u32 buffer_size0 = (first.size() + 1) * 2;
LPCWSTR buffer0 = (LPCWSTR)_alloca(buffer_size0);
AnsiToUnicode(first.c_str(), (LPVOID)buffer0, buffer_size0);
Expand All @@ -54,6 +64,9 @@ bool logical_string_predicate::operator()(shared_str const& first, shared_str co
AnsiToUnicode(second.c_str(), (LPVOID)buffer1, buffer_size1);

return (StrCmpLogicalW(buffer0, buffer1) < 0);
#else
return false;
#endif
}

shared_str editor::environment::detail::real_path(pcstr folder, pcstr path)
Expand Down
15 changes: 15 additions & 0 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#include "stdafx.h"
#include "main.h"

#if defined(WINDOWS)
#include <process.h>
#elif defined(LINUX)
#include <lockfile.h>
#endif
#include <locale.h>

#include "IGame_Persistent.h"
Expand Down Expand Up @@ -128,6 +132,9 @@ ENGINE_API void destroyEngine()
{
Device.Destroy();
Engine.Destroy();
#if defined(LINUX)
lockfile_remove("/var/lock/stalker-cop.lock");
#endif
}

void execUserScript()
Expand Down Expand Up @@ -209,9 +216,15 @@ ENGINE_API int RunApplication()
#ifdef NO_MULTI_INSTANCES
if (!GEnv.isDedicatedServer)
{
#if defined(WINDOWS)
CreateMutex(nullptr, TRUE, "Local\\STALKER-COP");
if (GetLastError() == ERROR_ALREADY_EXISTS)
return 2;
#elif defined(LINUX)
int lock_res = lockfile_create("/var/lock/stalker-cop.lock", 0, L_PID);
if(L_ERROR == lock_res)
return 2;
#endif
}
#endif
*g_sLaunchOnExit_app = 0;
Expand Down Expand Up @@ -264,13 +277,15 @@ ENGINE_API int RunApplication()
// check for need to execute something external
if (/*xr_strlen(g_sLaunchOnExit_params) && */ xr_strlen(g_sLaunchOnExit_app))
{
#if defined(WINDOWS)
// CreateProcess need to return results to next two structures
STARTUPINFO si = {};
si.cb = sizeof(si);
PROCESS_INFORMATION pi = {};
// We use CreateProcess to setup working folder
pcstr tempDir = xr_strlen(g_sLaunchWorkingFolder) ? g_sLaunchWorkingFolder : nullptr;
CreateProcess(g_sLaunchOnExit_app, g_sLaunchOnExit_params, nullptr, nullptr, FALSE, 0, nullptr, tempDir, &si, &pi);
#endif
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/xrEngine/phdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

#include "IPHdebug.h"

#if defined(WINDOWS)
IPhDebugRender* ph_debug_render = 0;
#endif
Loading

0 comments on commit dbc99d4

Please sign in to comment.