Skip to content

Commit

Permalink
Merge pull request #6 from Zegeri/clang-support
Browse files Browse the repository at this point in the history
Fix clang compilation
  • Loading branch information
q4a authored Sep 24, 2018
2 parents b1aaba6 + 5badae3 commit b02dda3
Show file tree
Hide file tree
Showing 58 changed files with 271 additions and 140 deletions.
7 changes: 7 additions & 0 deletions cmake/FindTBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ if (UNIX)
# has itanium/*
set(_TBB_COMPILER ${TBB_COMPILER})
set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE})

# Fix for clang compiler
# https://www.threadingbuildingblocks.org/docs/help/reference/appendices/known_issues/linux_os.html
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
string(REPLACE "." "0" TBB_USE_GLIBCXX_VERSION ${CMAKE_CXX_COMPILER_VERSION})
add_definitions(-DTBB_USE_GLIBCXX_VERSION=${TBB_USE_GLIBCXX_VERSION})
endif()
endif (APPLE)
endif (UNIX)

Expand Down
4 changes: 2 additions & 2 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ inline void _splitpath (
}

#include <iostream>
inline void OutputDebugString(char *str) // for linux debugger
inline void OutputDebugString(const char *str) // for linux debugger
{
std::cerr << str;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ typedef struct _EXCEPTION_POINTERS {

#ifdef XR_X64
typedef int64_t INT_PTR;
typedef uint16_t UINT_PTR;
typedef uint64_t UINT_PTR;
typedef int64_t LONG_PTR;
#else
typedef int INT_PTR;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/xrMiscMath/vector3d_ext.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "pch.hpp"
#include "xrCore/_vector3d_ext.h"
#include "xrCommon/math_funcs_inline.h"
#include "xrCore/_vector3d_ext.h"

float dotproduct(const Fvector& v1, const Fvector& v2)
{
Expand Down
2 changes: 2 additions & 0 deletions src/utils/xrQSlim/src/MxDynBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MxDynBlock : public MxBlock<T>
{
private:
int fill;
using MxBlock<T>::resize;
using MxBlock<T>::begin;

public:
MxDynBlock(int n = 2) : MxBlock<T>(n) { fill = 0; }
Expand Down
2 changes: 1 addition & 1 deletion src/xrAICore/AISpaceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "AISpaceBase.hpp"
#include "Navigation/game_graph.h"
#include "Navigation/level_graph.h"
#include "Navigation/graph_engine.h"
#include "Navigation/PatrolPath/patrol_path_storage.h"
#include "Navigation/graph_engine.h"

AISpaceBase::AISpaceBase() { GEnv.AISpace = this; }
AISpaceBase::~AISpaceBase()
Expand Down
2 changes: 0 additions & 2 deletions src/xrAICore/Components/problem_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "xrCore/Containers/AssociativeVector.hpp"
#include "Common/object_broker.h"

class CGraphEngine;

template <typename _operator_condition, typename _condition_state, typename _operator, typename _condition_evaluator,
typename _operator_id_type, bool _reverse_search = false, typename _operator_ptr = _operator*,
typename _condition_evaluator_ptr = _condition_evaluator*>
Expand Down
4 changes: 4 additions & 0 deletions src/xrAICore/Components/problem_solver_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#pragma once

#ifndef AI_COMPILER
#include "xrAICore/Navigation/graph_engine.h"
#endif

#define TEMPLATE_SPECIALIZATION \
template <typename _operator_condition, typename _operator, typename _condition_state, \
typename _condition_evaluator, typename _operator_id_type, bool _reverse_search, typename _operator_ptr, \
Expand Down
13 changes: 0 additions & 13 deletions src/xrAICore/Navigation/ai_object_location_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
#include "xrAICore/Navigation/game_graph.h"
#include "xrAICore/Navigation/level_graph.h"

IC void CAI_ObjectLocation::init()
{
if (ai().get_level_graph())
ai().level_graph().set_invalid_vertex(m_level_vertex_id);
else
m_level_vertex_id = u32(-1);

if (ai().get_game_graph())
ai().game_graph().set_invalid_vertex(m_game_vertex_id);
else
m_game_vertex_id = GameGraph::_GRAPH_ID(-1);
}

IC void CAI_ObjectLocation::game_vertex(CVertex const* game_vertex)
{
VERIFY(ai().game_graph().valid_vertex_id(ai().game_graph().vertex_id(game_vertex)));
Expand Down
15 changes: 15 additions & 0 deletions src/xrAICore/Navigation/ai_object_location_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

#pragma once

#include "xrAICore/Navigation/level_graph.h"

IC void CAI_ObjectLocation::init()
{
if (ai().get_level_graph())
ai().level_graph().set_invalid_vertex(m_level_vertex_id);
else
m_level_vertex_id = u32(-1);

if (ai().get_game_graph())
ai().game_graph().set_invalid_vertex(m_game_vertex_id);
else
m_game_vertex_id = GameGraph::_GRAPH_ID(-1);
}

IC CAI_ObjectLocation::CAI_ObjectLocation() { init(); }
IC void CAI_ObjectLocation::reinit() { init(); }
IC const GameGraph::_GRAPH_ID CAI_ObjectLocation::game_vertex_id() const { return (m_game_vertex_id); }
Expand Down
4 changes: 4 additions & 0 deletions src/xrCore/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ class XRCORE_API IReader : public IReaderBase<IReader>
class XRCORE_API CVirtualFileRW : public IReader
{
private:
#if defined(WINDOWS)
void *hSrcFile, *hSrcMap;
#elif defined(LINUX)
int hSrcFile;
#endif

public:
CVirtualFileRW(const char* cFileName);
Expand Down
4 changes: 4 additions & 0 deletions src/xrCore/FS_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ class CCompressedReader : public IReader
class CVirtualFileReader : public IReader
{
private:
#if defined(WINDOWS)
void *hSrcFile, *hSrcMap;
#elif defined(LINUX)
int hSrcFile;
#endif

public:
CVirtualFileReader(const char* cFileName);
Expand Down
95 changes: 69 additions & 26 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,47 +256,33 @@ const CLocatorAPI::file* CLocatorAPI::Register(
return &*result;
}

#if defined(WINDOWS)
IReader* open_chunk(void* ptr, u32 ID)
{
u32 dwType, dwSize;
DWORD read_byte;
#ifdef WINDOWS
u32 pt = SetFilePointer(ptr, 0, nullptr, FILE_BEGIN);
VERIFY(pt != INVALID_SET_FILE_POINTER);
#else
::lseek(ptr, 0L, SEEK_SET);
#endif

while (true)
{
#ifdef WINDOWS
bool res = ReadFile(ptr, &dwType, 4, &read_byte, nullptr);
#elif defined(LINUX)
read_byte = ::read(ptr, &dwType, 4);
bool res = (read_byte != -1);
#endif

if (read_byte == 0)
return nullptr;
//. VERIFY(res&&(read_byte==4));

#ifdef WINDOWS
res = ReadFile(ptr, &dwSize, 4, &read_byte, nullptr);
#else
read_byte = ::read(ptr, &dwSize, 4);
res = (read_byte != -1);
#endif

if (read_byte == 0)
return nullptr;
//. VERIFY(res&&(read_byte==4));

if ((dwType & ~CFS_CompressMark) == ID)
{
u8* src_data = xr_alloc<u8>(dwSize);
#ifdef WINDOWS
res = ReadFile(ptr, src_data, dwSize, &read_byte, nullptr);
#else
read_byte = ::read(ptr, src_data, dwSize);
res = (read_byte != -1);
#endif

VERIFY(res && (read_byte == dwSize));
if (dwType & CFS_CompressMark)
{
Expand All @@ -308,17 +294,62 @@ IReader* open_chunk(void* ptr, u32 ID)
}
return new CTempReader(src_data, dwSize, 0);
}
#ifdef WINDOWS

pt = SetFilePointer(ptr, dwSize, nullptr, FILE_CURRENT);
if (pt == INVALID_SET_FILE_POINTER)
return nullptr;
#else
if(-1 == ::lseek(ptr, dwSize, SEEK_CUR))
return nullptr;
}
return nullptr;
};
#endif

#if defined(LINUX)
IReader* open_chunk(int fd, u32 ID)
{
u32 dwType, dwSize;
DWORD read_byte;
::lseek(fd, 0L, SEEK_SET);

while (true)
{
read_byte = ::read(fd, &dwType, 4);
bool res = (read_byte != -1);

if (read_byte == 0)
return nullptr;
//. VERIFY(res&&(read_byte==4));

read_byte = ::read(fd, &dwSize, 4);
res = (read_byte != -1);

if (read_byte == 0)
return nullptr;
//. VERIFY(res&&(read_byte==4));

if ((dwType & ~CFS_CompressMark) == ID)
{
u8* src_data = xr_alloc<u8>(dwSize);
read_byte = ::read(fd, src_data, dwSize);
res = (read_byte != -1);

VERIFY(res && (read_byte == dwSize));
if (dwType & CFS_CompressMark)
{
BYTE* dest;
unsigned dest_sz;
_decompressLZ(&dest, &dest_sz, src_data, dwSize);
xr_free(src_data);
return new CTempReader(dest, dest_sz, 0);
}
return new CTempReader(src_data, dwSize, 0);
}

if(-1 == ::lseek(fd, dwSize, SEEK_CUR))
return nullptr;
}
return nullptr;
};
#endif

void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint)
{
Expand Down Expand Up @@ -416,17 +447,21 @@ void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint)

void CLocatorAPI::archive::open()
{
#if defined(WINDOWS)
// Open the file
if (hSrcFile && hSrcMap)
return;

#if defined(WINDOWS)
hSrcFile = CreateFile(*path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
R_ASSERT(hSrcFile != INVALID_HANDLE_VALUE);
hSrcMap = CreateFileMapping(hSrcFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
R_ASSERT(hSrcMap != INVALID_HANDLE_VALUE);
size = GetFileSize(hSrcFile, nullptr);
#elif defined(LINUX)
// Open the file
if (hSrcFile)
return;

hSrcFile = ::open(*path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
R_ASSERT(hSrcFile != -1);
struct stat file_info;
Expand Down Expand Up @@ -505,7 +540,11 @@ bool CLocatorAPI::load_all_unloaded_archives()
bool res = false;
for (auto& archive : m_archives)
{
#if defined(WINDOWS)
if (archive.hSrcFile == nullptr)
#elif defined(LINUX)
if (archive.hSrcFile == 0)
#endif
{
LoadArchive(archive);
res = true;
Expand Down Expand Up @@ -593,7 +632,7 @@ bool ignore_path(const char* _path)
else
return true;
#elif defined(LINUX)
HANDLE h = ::open(_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
int h = ::open(_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (h != -1)
{
::close(h);
Expand Down Expand Up @@ -1294,7 +1333,11 @@ void CLocatorAPI::file_from_archive(CStreamReader*& R, pcstr fname, const file&
make_string("cannot use stream reading for compressed data %s, do not compress data to be streamed", fname));

R = new CStreamReader();
#if defined(WINDOWS)
R->construct(A.hSrcMap, desc.ptr, desc.size_compressed, A.size, BIG_FILE_READER_WINDOW_SIZE);
#elif defined(LINUX)
R->construct(A.hSrcFile, desc.ptr, desc.size_compressed, A.size, BIG_FILE_READER_WINDOW_SIZE);
#endif
}

void CLocatorAPI::copy_file_to_build(IWriter* W, IReader* r) { W->w(r->pointer(), r->length()); }
Expand Down Expand Up @@ -1506,7 +1549,7 @@ void CLocatorAPI::w_close(IWriter*& S)
Register(fname, 0xffffffff, 0, 0, st.st_size, st.st_size, (u32)st.st_mtime);
#elif defined(LINUX)
struct stat st;
::fstat(fname, &st);
::stat(fname, &st);
Register(fname, 0xffffffff, 0, 0, st.st_size, st.st_size, (u32)st.st_mtime);
#endif
}
Expand Down
15 changes: 10 additions & 5 deletions src/xrCore/LocatorAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ class XRCORE_API CLocatorAPI : Noncopyable

struct archive
{
u32 size;
u32 vfs_idx;
u32 size = 0;
u32 vfs_idx = u32(-1);
shared_str path;
void *hSrcFile, *hSrcMap;
CInifile* header;
#if defined(WINDOWS)
void *hSrcFile = nullptr;
void *hSrcMap = nullptr
#elif defined(LINUX)
int hSrcFile = 0;
#endif
CInifile* header = nullptr;

archive() : size(0), vfs_idx(u32(-1)), hSrcFile(nullptr), hSrcMap(nullptr), header(nullptr) {}
archive() = default;
void open();
void close();
};
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/XML/XMLDocument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class XML_NODE
return node;
}

bool operator==(nullptr_t) = delete;
bool operator==(std::nullptr_t) = delete;

XML_NODE firstChild() const
{
Expand Down
6 changes: 4 additions & 2 deletions src/xrCore/file_stream_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ void CFileStreamReader::construct(LPCSTR file_name, const u32& window_size)
struct stat file_info;
::fstat(m_file_handle, &file_info);
u32 file_size = (u32)file_info.st_size;
inherited::construct(&m_file_handle, 0, file_size, file_size, window_size);
inherited::construct(m_file_handle, 0, file_size, file_size, window_size);
#endif
}

void CFileStreamReader::destroy()
{
#if defined(WINDOWS)
HANDLE file_mapping_handle = this->file_mapping_handle();
inherited::destroy();
#if defined(WINDOWS)
CloseHandle(file_mapping_handle);
CloseHandle(m_file_handle);
#elif defined(LINUX)
int file_mapping_handle = this->file_mapping_handle();
inherited::destroy();
::close(m_file_handle);
m_file_handle = -1;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/xrCore/file_stream_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class CFileStreamReader : public CStreamReader
typedef CStreamReader inherited;

private:
#if defined(WINDOWS)
HANDLE m_file_handle;
#elif defined(LINUX)
int m_file_handle;
#endif

public:
virtual void construct(LPCSTR file_name, const u32& window_size);
Expand Down
Loading

0 comments on commit b02dda3

Please sign in to comment.