diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..e7bc1fc35de --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 2.8.0) +project(OpenXRay) + +include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++17") + +add_definitions(-D_MT -D_CPPUNWIND -DPURE_DYNAMIC_CAST -DDECLARE_SPECIALIZATION -DM_NOSTDCONTAINERS_EXT -DUSE_OGL) + +set(LUA_INCLUDE_DIR Externals/luajit/src) +set(LUA_LIBRARIES luajit) +set(LUA_FOUND 1) +if (NOT WIN32) +find_package(OpenSSL REQUIRED) +find_package(Theora REQUIRED) +find_package(OGG REQUIRED) +find_package(SDL2 REQUIRED) +find_package(LZO REQUIRED) +find_package(JPEG REQUIRED) +endif() + +include_directories(${LUA_INCLUDE_DIR}) +include_directories(${CMAKE_SOURCE_DIR} {CMAKE_SOURCE_DIR}/Common ${CMAKE_SOURCE_DIR}/Externals ${CMAKE_SOURCE_DIR}/Externals/gli/external/glm ${CMAKE_SOURCE_DIR}/../sdk/include/loki) + +add_subdirectory(Externals) +add_subdirectory(src) diff --git a/Externals/CMakeLists.txt b/Externals/CMakeLists.txt new file mode 100644 index 00000000000..617b7f2864a --- /dev/null +++ b/Externals/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(luajit) +add_subdirectory(luabind) +add_subdirectory(lzo) +add_subdirectory(cximage) +add_subdirectory(NVTT) +#add_subdirectory(gli) +#add_subdirectory(glew) diff --git a/Externals/NVTT/CMakeLists.txt b/Externals/NVTT/CMakeLists.txt new file mode 100644 index 00000000000..2c63a27232e --- /dev/null +++ b/Externals/NVTT/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.0) +project(nvtt) +add_definitions(-DHAVE_SIGNAL_H -DHAVE_EXECINFO_H) +add_subdirectory(src/nvcore) +add_subdirectory(src/nvimage) +add_subdirectory(src/nvmath) +add_subdirectory(src/nvtt) diff --git a/Externals/NVTT/src/nvcore/CMakeLists.txt b/Externals/NVTT/src/nvcore/CMakeLists.txt index 385e2012fca..2e3aba3158e 100644 --- a/Externals/NVTT/src/nvcore/CMakeLists.txt +++ b/Externals/NVTT/src/nvcore/CMakeLists.txt @@ -23,7 +23,7 @@ SET(CORE_SRCS Library.h Library.cpp) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../include) # targets ADD_DEFINITIONS(-DNVCORE_EXPORTS) diff --git a/Externals/NVTT/src/nvcore/Debug.cpp b/Externals/NVTT/src/nvcore/Debug.cpp index 0babc0fd220..48d16d34bda 100644 --- a/Externals/NVTT/src/nvcore/Debug.cpp +++ b/Externals/NVTT/src/nvcore/Debug.cpp @@ -28,6 +28,8 @@ #endif #if NV_OS_LINUX && defined(HAVE_EXECINFO_H) +# include +# include // getpid # include // backtrace # if NV_CC_GNUC // defined(HAVE_CXXABI_H) # include diff --git a/Externals/NVTT/src/nvcore/Debug.h b/Externals/NVTT/src/nvcore/Debug.h index c1f0ca5d9d9..5cafb1c22f1 100644 --- a/Externals/NVTT/src/nvcore/Debug.h +++ b/Externals/NVTT/src/nvcore/Debug.h @@ -30,6 +30,19 @@ #else // NV_NO_ASSERT +# if NV_CC_MSVC + // @@ Does this work in msvc-6 and earlier? +# define nvDebugBreak() __debugbreak() +//# define nvDebugBreak() __asm { int 3 } +# elif NV_OS_ORBIS +# define nvDebugBreak() __debugbreak() +# elif NV_CC_GNUC +# define nvDebugBreak() __builtin_trap() +# else +# error "No nvDebugBreak()!" +# endif + +/* # if NV_CC_MSVC // @@ Does this work in msvc-6 and earlier? // @@ Do I have to include ? @@ -39,13 +52,14 @@ # define nvDebugBreak() __asm__ volatile ("trap"); # elif NV_CC_GNUC && NV_CPU_X86 && NV_OS_DARWIN # define nvDebugBreak() __asm__ volatile ("int3"); -# elif NV_CC_GNUC && NV_CPU_X86 +# elif NV_CC_GNUC && NV_CPU_X86 # define nvDebugBreak() __asm__ ( "int %0" : :"I"(3) ) # else # include # define nvDebugBreak() raise(SIGTRAP); // define nvDebugBreak() *((int *)(0)) = 0 # endif +*/ # define nvAssertMacro(exp) \ do { \ diff --git a/Externals/NVTT/src/nvimage/CMakeLists.txt b/Externals/NVTT/src/nvimage/CMakeLists.txt index 7b2f197ba63..ae762366bd1 100644 --- a/Externals/NVTT/src/nvimage/CMakeLists.txt +++ b/Externals/NVTT/src/nvimage/CMakeLists.txt @@ -1,6 +1,6 @@ PROJECT(nvimage) -SET(IMAGE_SRCS +SET(IMAGE_SRCS nvimage.h FloatImage.h FloatImage.cpp @@ -27,7 +27,7 @@ SET(IMAGE_SRCS PsdFile.h TgaFile.h) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../include) IF(PNG_FOUND) SET(LIBS ${LIBS} ${PNG_LIBRARIES}) diff --git a/Externals/NVTT/src/nvimage/ImageIO.cpp b/Externals/NVTT/src/nvimage/ImageIO.cpp index 1d09c0e2b1a..cd17f07bb51 100644 --- a/Externals/NVTT/src/nvimage/ImageIO.cpp +++ b/Externals/NVTT/src/nvimage/ImageIO.cpp @@ -135,7 +135,7 @@ FloatImage * nv::ImageIO::loadFloat(const char * fileName) StdInputStream stream(fileName); if (stream.isError()) { - return false; + return NULL; } return loadFloat(fileName, stream); @@ -233,7 +233,7 @@ Image * nv::ImageIO::loadTGA(Stream & s) case TGA_TYPE_INDEXED: if( tga.colormap_type!=1 || tga.colormap_size!=24 || tga.colormap_length>256 ) { nvDebug( "*** ImageIO::loadTGA: Error, only 24bit paletted images are supported.\n" ); - return false; + return NULL; } pal = true; break; @@ -254,7 +254,7 @@ Image * nv::ImageIO::loadTGA(Stream & s) default: nvDebug( "*** ImageIO::loadTGA: Error, unsupported image type.\n" ); - return false; + return NULL; } const uint pixel_size = (tga.pixel_size/8); diff --git a/Externals/NVTT/src/nvmath/CMakeLists.txt b/Externals/NVTT/src/nvmath/CMakeLists.txt index 96aec78dc3f..7c6a765ab1e 100644 --- a/Externals/NVTT/src/nvmath/CMakeLists.txt +++ b/Externals/NVTT/src/nvmath/CMakeLists.txt @@ -13,7 +13,7 @@ SET(MATH_SRCS Basis.h Basis.cpp Triangle.h Triangle.cpp TriBox.cpp) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../include) # targets ADD_DEFINITIONS(-DNVMATH_EXPORTS) diff --git a/Externals/NVTT/src/nvmath/TriBox.cpp b/Externals/NVTT/src/nvmath/TriBox.cpp index 61d69bb68d5..216f42df236 100644 --- a/Externals/NVTT/src/nvmath/TriBox.cpp +++ b/Externals/NVTT/src/nvmath/TriBox.cpp @@ -1,6 +1,6 @@ /********************************************************/ /* AABB-triangle overlap test code */ -/* by Tomas Akenine-Möller */ +/* by Tomas Akenine-Möller */ /* Function: int triBoxOverlap(float boxcenter[3], */ /* float boxhalfsize[3],float triverts[3][3]); */ /* History: */ diff --git a/Externals/NVTT/src/nvmath/Triangle.cpp b/Externals/NVTT/src/nvmath/Triangle.cpp index f0052979881..54902b9bc1f 100644 --- a/Externals/NVTT/src/nvmath/Triangle.cpp +++ b/Externals/NVTT/src/nvmath/Triangle.cpp @@ -1,11 +1,11 @@ -// This code is in the public domain -- Ignacio Castaño +// This code is in the public domain -- Ignacio Castaño #include using namespace nv; -/// Tomas Möller, barycentric ray-triangle test. +/// Tomas Möller, barycentric ray-triangle test. bool rayTest_Moller(const Triangle & t, Vector3::Arg orig, Vector3::Arg dir, float * out_t, float * out_u, float * out_v) { // find vectors for two edges sharing vert0 diff --git a/Externals/NVTT/src/nvmath/Triangle.h b/Externals/NVTT/src/nvmath/Triangle.h index 7cd8db5e7c3..b3eb5a15c65 100644 --- a/Externals/NVTT/src/nvmath/Triangle.h +++ b/Externals/NVTT/src/nvmath/Triangle.h @@ -1,4 +1,4 @@ -// This code is in the public domain -- Ignacio Castaño +// This code is in the public domain -- Ignacio Castaño #ifndef NV_MATH_TRIANGLE_H #define NV_MATH_TRIANGLE_H @@ -44,7 +44,7 @@ namespace nv }; - // Tomas Akenine-Möller box-triangle test. + // Tomas Akenine-Möller box-triangle test. NVMATH_API bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & triangle); NVMATH_API bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & triangle); diff --git a/Externals/NVTT/src/nvmath/nvmath.h b/Externals/NVTT/src/nvmath/nvmath.h index ec086b0d899..6699960e476 100644 --- a/Externals/NVTT/src/nvmath/nvmath.h +++ b/Externals/NVTT/src/nvmath/nvmath.h @@ -115,9 +115,9 @@ inline bool isZero(const float f, const float epsilon = NV_EPSILON) inline bool isFinite(const float f) { -#if NV_OS_WIN32 +#if NV_OS_WIN32 && !NV_CC_GNUC return _finite(f) != 0; -#elif NV_OS_DARWIN +#elif NV_OS_DARWIN || NV_CC_GNUC return isfinite(f); #elif NV_OS_LINUX return finitef(f); @@ -130,9 +130,9 @@ inline bool isFinite(const float f) inline bool isNan(const float f) { -#if NV_OS_WIN32 +#if NV_OS_WIN32 && !NV_CC_GNUC return _isnan(f) != 0; -#elif NV_OS_DARWIN +#elif NV_OS_DARWIN || NV_CC_GNUC return isnan(f); #elif NV_OS_LINUX return isnanf(f); diff --git a/Externals/NVTT/src/nvtt/CMakeLists.txt b/Externals/NVTT/src/nvtt/CMakeLists.txt index 9ce93d05c16..a3fd451510f 100644 --- a/Externals/NVTT/src/nvtt/CMakeLists.txt +++ b/Externals/NVTT/src/nvtt/CMakeLists.txt @@ -39,7 +39,7 @@ IF(CUDA_FOUND) INCLUDE_DIRECTORIES(${CUDA_INCLUDE_PATH}) ENDIF(CUDA_FOUND) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../include) ADD_DEFINITIONS(-DNVTT_EXPORTS) diff --git a/Externals/cximage/CMakeLists.txt b/Externals/cximage/CMakeLists.txt new file mode 100644 index 00000000000..869ce6b3179 --- /dev/null +++ b/Externals/cximage/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 2.8.0) +project(cximage) + +set(SOURCES + ximacfg.cpp + ximaenc.cpp + ximaexif.cpp + ximage.cpp + ximainfo.cpp + ximaint.cpp + ximajpg.cpp + ximalpha.cpp + ximalyr.cpp + ximapal.cpp + ximasel.cpp + ximath.cpp + xmemfile.cpp +) + +set(HEADERS + xfile.h + ximacfg.h + ximadef.h + ximage.h + ximaiter.h + ximajpg.h + ximath.h + xiofile.h + xmemfile.h +) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++14") +add_definitions(-DCXIMAGE_BUILD) + +include_directories("." ${CMAKE_SOURCE_DIR}) + +add_library(cximage STATIC ${SOURCES} ${HEADERS}) + +set_target_properties(cximage PROPERTIES PREFIX "") +target_link_libraries(cximage) diff --git a/Externals/cximage/ximacfg.h b/Externals/cximage/ximacfg.h index 0bdb2af8692..a08d80c8a44 100644 --- a/Externals/cximage/ximacfg.h +++ b/Externals/cximage/ximacfg.h @@ -1,5 +1,8 @@ #if !defined(__ximaCFG_h) #define __ximaCFG_h +#if !defined(WIN32) +#include +#endif extern "C" void* cxalloc(size_t size); extern "C" void cxfree(void* ptr); diff --git a/Externals/cximage/ximadef.h b/Externals/cximage/ximadef.h index b388b2b81f4..f00f59fff09 100644 --- a/Externals/cximage/ximadef.h +++ b/Externals/cximage/ximadef.h @@ -98,10 +98,16 @@ typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef unsigned int UINT; +typedef const char* LPCTSTR; typedef DWORD COLORREF; typedef unsigned int HANDLE; typedef void* HRGN; +typedef void* HDC; + +typedef int boolean; + +#define _tfopen fopen #ifndef BOOL #define BOOL bool diff --git a/Externals/cximage/ximainfo.cpp b/Externals/cximage/ximainfo.cpp index 28cbad40cc4..39b79f3c77f 100644 --- a/Externals/cximage/ximainfo.cpp +++ b/Externals/cximage/ximainfo.cpp @@ -5,6 +5,10 @@ #include "ximage.h" +#if !defined(WIN32) +#define _tcsnicmp(a,b,c) strcasecmp(a,b) +#endif + //////////////////////////////////////////////////////////////////////////////// /** * \return the color used for transparency, and/or for background color @@ -538,7 +542,7 @@ void CxImage::SetOffset(long x,long y) //////////////////////////////////////////////////////////////////////////////// /** * \sa SetJpegQuality, GetJpegQualityF - * \author [DP]; changes [Stefan Schürmans] + * \author [DP]; changes [Stefan Schürmans] */ BYTE CxImage::GetJpegQuality() const { @@ -547,7 +551,7 @@ BYTE CxImage::GetJpegQuality() const //////////////////////////////////////////////////////////////////////////////// /** * \sa SetJpegQuality, GetJpegQuality - * \author [Stefan Schürmans] + * \author [Stefan Schürmans] */ float CxImage::GetJpegQualityF() const { @@ -557,7 +561,7 @@ float CxImage::GetJpegQualityF() const /** * quality level for JPEG and JPEG2000 * \param q: can be from 0 to 100 - * \author [DP]; changes [Stefan Schürmans] + * \author [DP]; changes [Stefan Schürmans] */ void CxImage::SetJpegQuality(BYTE q){ info.fQuality = (float)q; @@ -567,7 +571,7 @@ void CxImage::SetJpegQuality(BYTE q){ * quality level for JPEG and JPEG2000 * necessary for JPEG2000 when quality is between 0.0 and 1.0 * \param q: can be from 0.0 to 100.0 - * \author [Stefan Schürmans] + * \author [Stefan Schürmans] */ void CxImage::SetJpegQualityF(float q){ if (q>0) info.fQuality = q; diff --git a/cmake/FindLZO.cmake b/cmake/FindLZO.cmake new file mode 100644 index 00000000000..8fdd814c689 --- /dev/null +++ b/cmake/FindLZO.cmake @@ -0,0 +1,68 @@ +#https://raw.githubusercontent.com/dfelinto/blender/master/build_files/cmake/Modules/FindLZO.cmake +# - Find LZO library +# Find the native LZO includes and library +# This module defines +# LZO_INCLUDE_DIRS, where to find lzo1x.h, Set when +# LZO_INCLUDE_DIR is found. +# LZO_LIBRARIES, libraries to link against to use LZO. +# LZO_ROOT_DIR, The base directory to search for LZO. +# This can also be an environment variable. +# LZO_FOUND, If false, do not try to use LZO. +# +# also defined, but not for general use are +# LZO_LIBRARY, where to find the LZO library. + +#============================================================================= +# Copyright 2015 Blender Foundation. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +# If LZO_ROOT_DIR was defined in the environment, use it. +IF(NOT LZO_ROOT_DIR AND NOT $ENV{LZO_ROOT_DIR} STREQUAL "") + SET(LZO_ROOT_DIR $ENV{LZO_ROOT_DIR}) +ENDIF() + +SET(_lzo_SEARCH_DIRS + ${LZO_ROOT_DIR} + /usr/local + /sw # Fink + /opt/local # DarwinPorts +) + +FIND_PATH(LZO_INCLUDE_DIR lzo/lzo1x.h + HINTS + ${_lzo_SEARCH_DIRS} + PATH_SUFFIXES + include +) + +FIND_LIBRARY(LZO_LIBRARY + NAMES + lzo2 + HINTS + ${_lzo_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib + ) + +# handle the QUIETLY and REQUIRED arguments and set LZO_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO DEFAULT_MSG + LZO_LIBRARY LZO_INCLUDE_DIR) + +IF(LZO_FOUND) + SET(LZO_LIBRARIES ${LZO_LIBRARY}) + SET(LZO_INCLUDE_DIRS ${LZO_INCLUDE_DIR}) +ENDIF(LZO_FOUND) + +MARK_AS_ADVANCED( + LZO_INCLUDE_DIR + LZO_LIBRARY +) \ No newline at end of file diff --git a/cmake/FindOGG.cmake b/cmake/FindOGG.cmake new file mode 100644 index 00000000000..3d657f8f6e7 --- /dev/null +++ b/cmake/FindOGG.cmake @@ -0,0 +1,106 @@ +#https://raw.githubusercontent.com/freeorion/freeorion/master/cmake/FindOgg.cmake +#.rst: +# FindOgg +# ------- +# +# Find the native Ogg includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``Ogg::Ogg``, if +# Ogg has been found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# OGG_INCLUDE_DIRS - where to find ogg.h, etc. +# OGG_LIBRARIES - List of libraries when using ogg. +# OGG_FOUND - True if ogg found. +# +# Hints +# ^^^^^ +# +# A user may set ``OGGDIR`` environment to a ogg installation root +# to tell this module where to look. + + +set(_OGG_SEARCHES) + +# Search OGGDIR first when is set. +if(ENV{OGGDIR}) + set(_OGG_SEARCH_ROOT PATHS $ENV{OGGDIR} NO_DEFAULT_PATH) + list(APPEND _OGG_SEARCHES _OGG_SEARCH_ROOT) +endif() + +# Normal search. +set(_OGG_SEARCH_NORMAL + PATH "" + ) +list(APPEND _OGG_SEARCHES _OGG_SEARCH_NORMAL) + +set(OGG_NAMES ogg libogg) +set(OGG_NAMES_DEBUG oggd ogg_D oggD ogg_D) + +foreach(search ${_OGG_SEARCHES}) + find_path(OGG_INCLUDE_DIR NAMES ogg.h ${${search}} PATH_SUFFIXES ogg) +endforeach() + +# Allow OGG_LIBRARY to be set manually, as the location of the +# ogg library +if(NOT OGG_LIBRARY) + foreach(search ${_OGG_SEARCHES}) + find_library(OGG_LIBRARY_RELEASE NAMES ${OGG_NAMES} ${${search}} PATH_SUFFIXES lib) + find_library(OGG_LIBRARY_DEBUG NAMES ${OGG_NAMES_DEBUG} ${${search}} PATH_SUFFIXES lib) + endforeach() + + include(SelectLibraryConfigurations) + select_library_configurations(OGG) +endif() + +unset(OGG_NAMES) +unset(OGG_NAMES_DEBUG) + +mark_as_advanced(OGG_LIBRARY OGG_INCLUDE_DIR) + +# handle the QUIETLY and REQUIRED argument and set OGG_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ogg REQUIRED_VARS OGG_LIBRARY OGG_INCLUDE_DIR) + +if(OGG_FOUND) + set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR}) + + if(NOT OGG_LIBRARIES) + set(OGG_LIBRARIES ${OGG_LIBRARY}) + endif() + + if(NOT TARGET Ogg::Ogg) + add_library(Ogg::Ogg UNKNOWN IMPORTED) + set_target_properties(Ogg::Ogg PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIRS}") + + if(OGG_LIBRARY_RELEASE) + set_property(TARGET Ogg::Ogg APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(Ogg::Ogg PROPERTIES + IMPORTED_LOCATION_RELEASE "${OGG_LIBRARY_RELEASE}") + endif() + + if(OGG_LIBRARY_DEBUG) + set_property(TARGET Ogg::Ogg APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(Ogg::Ogg PROPERTIES + IMPORTED_LOCATION_DEBUG "${OGG_LIBRARY_DEBUG}") + endif() + + if(NOT OGG_LIBRARY_RELEASE AND NOT OGG_LIBRARY_DEBUG) + set_property(TARGET Ogg::Ogg APPEND PROPERTY + IMPORTED_LOCATION "${OGG_LIBRARY}") + endif() + endif() +endif() \ No newline at end of file diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 00000000000..93252f4947c --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,160 @@ +#https://raw.githubusercontent.com/freeorion/freeorion/master/cmake/FindSDL.cmake +#.rst: +# FindSDL +# ------- +# +# Find the native SDL includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` targets +# +# :: +# +# ``SDL::SDL`` - The SDL library. +# ``SDL::main`` - The SDLmain library. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# SDL_INCLUDE_DIRS - where to find SDL.h, etc. +# SDL_LIBRARIES - List of librarie when using SDL +# SDL_VERSION - SDL version from SDL_version.hpp +# SDL_MAJOR_VERSION - SDL major version number (X in X.y.z) +# SDL_MINOR_VERSION - SDL minor version number (Y in x.Y.z) +# SDL_PATCH_VERSION - SDL patch version number (Z in x.y.Z) +# SDL_FOUND - True if SDL found. +# +# Controls +# ^^^^^^^^ +# +# :: +# +# SDL_NO_MAIN - If set to true the SDLmain library is skipped +# from the SDL_LIBRARIES to let the application +# handle the various entry point variants used +# by different operating systems. +# +# Hints +# ^^^^^ +# +# A user may set ``SDL_ROOT`` to a SDL installation root to tell this +# module where to look. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of SDL2_LIBRARY to +# override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +set(_SDL_SEARCHES) + +# Search SDL_ROOT first when is set. +if(SDL_ROOT) + set(_SDL_SEARCH_ROOT PATH ${SDL_ROOT} NO_DEFAULT_PATH) + list(APPEND _SDL_SEARCHES _OGG_SEARCH_ROOT) +endif() + +# Normal search. +set(_SDL_SEARCH_NORMAL + PATH "" + ) +list(APPEND _SDL_SEARCHES _SDL_SEARCH_NORMAL) + +foreach(search ${_SDL_SEARCHES}) + find_path(SDL_INCLUDE_DIR NAMES SDL.h ${${search}} PATH_SUFFIXES SDL2) +endforeach() + +if(SDL_INCLUDE_DIR) + file(STRINGS "${SDL_INCLUDE_DIR}/SDL_version.h" _SDL_VERSION_HPP_CONTENTS REGEX "#define SDL_((MAJOR|MINOR)_VERSION|PATCHLEVEL)") + foreach(v MAJOR_VERSION MINOR_VERSION PATCHLEVEL) + if("${_SDL_VERSION_HPP_CONTENTS}" MATCHES "#define SDL_${v} +([0-9]+)") + set(SDL_${v} "${CMAKE_MATCH_1}") + endif() + endforeach() + set(SDL_PATCH_VERSION ${SDL_PATCHLEVEL}) + unset(SDL_PATCHLEVEL) + set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_PATCH_VERSION}") +endif() + +# Allow SDL_LIBRARY to be set manually, as the location of the +# SDL library +if(NOT SDL_LIBRARY) + foreach(search ${_SDL_SEARCHES}) + find_library(SDL_LIBRARY NAMES SDL2 ${${search}} PATH_SUFFIXES lib64 lib) + endforeach() +endif() + +if(NOT SDL_NO_MAIN AND NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") + foreach(search ${_SDL_SEARCHES}) + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + find_library(SDL_MAIN_LIBRARY NAMES SDL2main ${${search}} PATH_SUFFIXES lib64 lib) + endforeach() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR + VERSION_VAR SDL_VERSION) + +if(SDL_FOUND) + set(SDL_INCLUDE_DIRS ${SDL_INCLUDE_DIRS}) + + if(NOT SDL_LIBRARIES) + set(SDL_LIBRARIES ${SDL_LIBRARY}) + + # For SDL2main + if(NOT SDL_NO_MAIN AND SDL_MAIN_LIBRARY) + set(SDL_LIBRARIES ${SDL_MAIN_LIBRARY} ${SDL_LIBRARIES}) + endif() + + if(APPLE) + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + set(SDL_LIBRARIES ${SDL_LIBRARIES} "-framework Cocoa") + endif() + endif() + + if(NOT TARGET SDL::SDL) + add_library(SDL::SDL UNKNOWN IMPORTED) + set_target_properties(SDL::SDL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIRS}") + + if(SDL_LIBRARY) + set_property(TARGET SDL::SDL APPEND PROPERTY + IMPORTED_LOCATION "${SDL_LIBRARY}") + endif() + endif() + + if(NOT TARGET SDL::main AND SDL_MAIN_LIBRARY) + add_library(SDL::main UNKNOWN IMPORTED) + + if(SDL_MAIN_LIBRARY) + set_property(TARGET SDL::main APPEND PROPERTY + IMPORTED_LOCATION "${SDL_MAIN_LIBRARY}") + endif() + + + add_dependencies(SDL::SDL SDL::main) + endif() +endif() \ No newline at end of file diff --git a/cmake/FindTheora.cmake b/cmake/FindTheora.cmake new file mode 100644 index 00000000000..841f090d62e --- /dev/null +++ b/cmake/FindTheora.cmake @@ -0,0 +1,39 @@ +#https://raw.githubusercontent.com/Andrettin/Wyrmgus/master/cmake/modules/FindTheora.cmake +# Option for build or not Theora + +# Copyright (c) 2006,2007 Laurent Montel, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if(THEORA_INCLUDE_DIR AND THEORA_LIB_LIBRARIES AND THEORA_VORBIS_LIBRARIES AND THEORA_OGG_LIBRARIES) + # Already in cache, be silent + set(Theora_FIND_QUIETLY TRUE) +endif(THEORA_INCLUDE_DIR AND THEORA_LIB_LIBRARIES AND THEORA_VORBIS_LIBRARIES AND THEORA_OGG_LIBRARIES) + +FIND_PATH(THEORA_INCLUDE_DIR theora/theora.h) + +FIND_LIBRARY(THEORA_OGG_LIBRARIES NAMES libogg libogg_static ogg ogg_static) + +FIND_LIBRARY(THEORA_VORBIS_LIBRARIES NAMES libvorbis libvorbis_static vorbis vorbis_static) + +FIND_LIBRARY(THEORA_LIB_LIBRARIES NAMES libtheora libtheora_static theora theora_static) + +if(THEORA_LIB_LIBRARIES AND THEORA_VORBIS_LIBRARIES AND THEORA_OGG_LIBRARIES AND THEORA_INCLUDE_DIR) + set(THEORA_LIBRARY ${THEORA_LIB_LIBRARIES} ${THEORA_OGG_LIBRARIES} ${THEORA_VORBIS_LIBRARIES}) + set(THEORA_FOUND TRUE) +endif(THEORA_LIB_LIBRARIES AND THEORA_VORBIS_LIBRARIES AND THEORA_OGG_LIBRARIES AND THEORA_INCLUDE_DIR) + +if (THEORA_FOUND) + if (NOT Theora_FIND_QUIETLY) + MESSAGE( STATUS "theora found: includes in ${THEORA_INCLUDE_DIR}, library in ${THEORA_LIBRARY}") + endif (NOT Theora_FIND_QUIETLY) +else (THEORA_FOUND) + if (Theora_FIND_REQUIRED) + MESSAGE( FATAL_ERROR "theora not found") + endif (Theora_FIND_REQUIRED) +endif (THEORA_FOUND) + + +MARK_AS_ADVANCED(THEORA_INCLUDE_DIR THEORA_LIBRARY) diff --git a/cmake/utils.cmake b/cmake/utils.cmake new file mode 100644 index 00000000000..743bf4f972c --- /dev/null +++ b/cmake/utils.cmake @@ -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() diff --git a/doc/howto/build-linux.txt b/doc/howto/build-linux.txt new file mode 100644 index 00000000000..289266f4b6f --- /dev/null +++ b/doc/howto/build-linux.txt @@ -0,0 +1,63 @@ +TITLE: X-Ray 1.6 build and setup on Linux + +Required packages: +------ +OpenSSL +Theora +OGG +SDL2 +LZO +JPEG + +Ubuntu 18.04 build dependencies: +sudo apt install git cmake libssl-dev libogg-dev libtheora-dev libvorbis-dev libsdl2-dev liblzo2-dev libjpeg-dev libncurses5-dev + +Build commands: +------ +cd xray-16 +git submodule update --init --recursive +mkdir bin && cd bin +cmake .. +(or export CC=clang && export CXX=clang++ && cmake ..) +make + + +Build: +------ +To build X-Ray Engine you'll need following libraries: +* OpenSSL: https://www.openssl.org/source + - Prebuilt binaries can be downloaded here: https://slproweb.com/products/Win32OpenSSL.html +* OpenAutomate: https://developer.nvidia.com/openautomate +* NVAPI: https://developer.nvidia.com/nvapi +* libjpeg: http://sourceforge.net/projects/libjpeg + - Use "jpeg" as project root directory name for compatibility with CxImage +* zlib: http://zlib.net +* BugTrap: https://github.com/nitrocaster/BugTrap +* FreeImage: http://freeimage.sourceforge.net +* FreeMagic +* libogg-1.1.4: http://xiph.org/downloads +* libtheora-1.1.1: http://xiph.org/downloads +* libvorbis-1.2.3: http://xiph.org/downloads +* Autodesk Maya 2008/2009 SDK +* Autodesk 3DS Max 6.0 SDK +* Windows SDK: http://www.microsoft.com/en-us/download/details.aspx?id=8279 +* DirectX SDK June 2010: http://www.microsoft.com/en-us/download/details.aspx?id=6812 + - replace dxguid.lib with the one from Windows SDK + (for DirectPlay GUIDs) +XXX nitrocaster: add LuaJIT & LuaBind instructions + +You can download all these libraries (except Windows/DirectX SDK) with compiled binaries here: +https://drive.google.com/file/d/0B2mH6ffKfXjCMjRfRTZsVlBtUVE + +Setup: +------ +- Install S.T.A.L.K.E.R Call of Pripyat +- Install patch 1.6.02 (only for russian locale, worldwide release should have it included): + http://cop.stalker-game.ru/?page=patches#2 +- Download and unpack archive with libraries +- Run xrbinprep.cmd to initialize new game binary directories and link default gamedata to OpenXRay's: + $ xrbinprep.cmd "C:\Program Files (x86)\GSC World Publishing\S.T.A.L.K.E.R. - Call of Pripyat" + Note that this script requires admin rights (in order to execute 'mklink'). Also make sure you pass a + game installation directory to this script. Once done, you can find .xrbinup_xxx scripts in the reporitory root: + use them later to install newly built binaries to the corresponding game binary directory. +- Now you can build the engine! diff --git a/doc/howto/build.txt b/doc/howto/build.txt index 42716083d2c..f3bdcd35769 100644 --- a/doc/howto/build.txt +++ b/doc/howto/build.txt @@ -2,12 +2,23 @@ TITLE: X-Ray 1.6 build and setup instructions Build: ------ -Currently, the only compiler supported is Visual C++ 2015. If you don't have Visual Studio yet, you can -download and install Visual Studio 2015 Community Edition - it's absolutely free for open source projects. +Currently, the only compiler supported is Visual C++ 2017. If you don't have Visual Studio yet, you can +download and install Visual Studio 2017 Community Edition - it's absolutely free for open source projects. -By default, all libraries mentioned below (except Windows/DirectX SDK) are assumed to be in -the src\Externals directory. +By default, all libraries mentioned below (except Windows SDK) are assumed to be in +the src\Externals directory. You can download all these libraries (except Windows SDK) with compiled binaries here: +https://drive.google.com/file/d/0B2mH6ffKfXjCMjRfRTZsVlBtUVE + +Windows SDK is available from Visual Studio 2017 installer. You will definitely need to install the following items: +* Windows 8.1 SDK (or newer) +* Visual C++ MFC for x86 and x64 +* NuGet package manager + +You will need following extension to save files in Visual Studio with encoding UTF-8 without BOM: +https://marketplace.visualstudio.com/items?itemName=hbuexinxin.ForceUTF8NoBOM +Libraries: +------ To build X-Ray Engine you'll need following libraries: * OpenSSL: https://www.openssl.org/source - Prebuilt binaries can be downloaded here: https://slproweb.com/products/Win32OpenSSL.html @@ -24,15 +35,12 @@ To build X-Ray Engine you'll need following libraries: * libvorbis-1.2.3: http://xiph.org/downloads * Autodesk Maya 2008/2009 SDK * Autodesk 3DS Max 6.0 SDK -* Windows SDK: http://www.microsoft.com/en-us/download/details.aspx?id=8279 -* DirectX SDK June 2010: http://www.microsoft.com/en-us/download/details.aspx?id=6812 +* Windows SDK +* DirectX SDK June 2010 (DOES NOT NEED ANYMORE ?): http://www.microsoft.com/en-us/download/details.aspx?id=6812 - replace dxguid.lib with the one from Windows SDK (for DirectPlay GUIDs) XXX nitrocaster: add LuaJIT & LuaBind instructions -You can download all these libraries (except Windows/DirectX SDK) with compiled binaries here: -https://drive.google.com/file/d/0B2mH6ffKfXjCMjRfRTZsVlBtUVE - Setup: ------ - Install S.T.A.L.K.E.R Call of Pripyat @@ -45,3 +53,11 @@ Setup: game installation directory to this script. Once done, you can find .xrbinup_xxx scripts in the reporitory root: use them later to install newly built binaries to the corresponding game binary directory. - Now you can build the engine! + +Debug/Run from Visual Studio: +------ +In solution "engine" properties in Visual Studio set: +- Startup Project: Single startup project = xr_3da + +In Project "xr_3da" properties set: +- Debugging: Working Directory = C:\PATH\TO\StalkerCallOfPripyat\ (which contains fsgame.ltx) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04ad4ceef1f..beb13345802 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,39 +1,13 @@ -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) - -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 +#add_subdirectory(utils) +#add_subdirectory(Layers) +#add_subdirectory(xrMisc) +#add_subdirectory(xrAICore) +#add_subdirectory(xrCDB) +add_subdirectory(xrCore) +#add_subdirectory(xrEngine) +#add_subdirectory(xrGame) +#add_subdirectory(xrNetServer) +#add_subdirectory(xrParticles) +#add_subdirectory(xrPhysics) +#add_subdirectory(xrScriptEngine) +#add_subdirectory(xrSound) diff --git a/src/Common/PlatformWindows.inl b/src/Common/PlatformWindows.inl index f63b400818d..54c1b0a0f01 100644 --- a/src/Common/PlatformWindows.inl +++ b/src/Common/PlatformWindows.inl @@ -23,7 +23,11 @@ #define NOHELP #define NOPROFILER #define NOMCX + +#ifndef NOMINMAX #define NOMINMAX +#endif + #define DOSWIN32 #define _WIN32_DCOM diff --git a/src/xrCore/CMakeLists.txt b/src/xrCore/CMakeLists.txt index 382a4280ea1..fe319f50a04 100644 --- a/src/xrCore/CMakeLists.txt +++ b/src/xrCore/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.5) - add_dir ( "." "Animation" @@ -16,10 +14,9 @@ add_dir ( message( "path " ${CMAKE_CURRENT_SOURCE_DIR} ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/include) + add_library(xrCore SHARED ${XRCORE__SOURCES} ${XRCORE__INCLUDES}) -find_library(SDL2_LIB SDL2) -find_library(LZO_LIBRARY lzo2) -find_library(CRYPTO_LIBRARY crypto++) -find_library(PUGIXML_LIBRARY pugixml) +set_target_properties(xrCore PROPERTIES PREFIX "") target_link_libraries(xrCore ${SDL2_LIB} ${OPENSSL_LIBRARIES} ${LZO_LIBRARY} ${CRYPTO_LIBRARY} ${PUGIXML_LIBRARY}) diff --git a/src/xrCore/LocatorAPI.h b/src/xrCore/LocatorAPI.h index 734a3f89cb6..bd90d14c238 100644 --- a/src/xrCore/LocatorAPI.h +++ b/src/xrCore/LocatorAPI.h @@ -18,13 +18,34 @@ #define _A_HIDDEN 0x02 #define _A_SUBDIR 0x00000010 +#ifdef XR_X64 +#define _finddata_t _finddata64i32_t +#elif XR_X86 +#define _finddata_t _finddata32_t +#endif // XR_X64 or XR_X86 + +typedef int64_t __int64; +typedef __int64 __time64_t; +typedef long __time32_t; +typedef unsigned long _fsize_t; + struct _finddata64i32_t { - unsigned int attrib; - int64_t time_create; - int64_t time_access; - int64_t time_write; - size_t size; - char name[260]; + unsigned attrib; + __time64_t time_create; + __time64_t time_access; + __time64_t time_write; + _fsize_t size; + char name[FILENAME_MAX]; +}; + +struct _finddata32_t +{ + unsigned attrib; + __time32_t time_create; + __time32_t time_access; + __time32_t time_write; + _fsize_t size; + char name[FILENAME_MAX]; }; #define _finddata_t _finddata64i32_t diff --git a/src/xrCore/Threading/Event.hpp b/src/xrCore/Threading/Event.hpp index 87fa7922907..b55f0b37c2e 100644 --- a/src/xrCore/Threading/Event.hpp +++ b/src/xrCore/Threading/Event.hpp @@ -3,16 +3,14 @@ class XRCORE_API Event { -#if defined(WINDOWS) void* handle; -#elif defined(LINUX) +#if defined(LINUX) struct EventHandle { pthread_mutex_t mutex; pthread_cond_t cond; bool signaled; }; - pthread_mutex_t handle; private: EventHandle m_id; diff --git a/src/xrCore/XML/XMLDocument.hpp b/src/xrCore/XML/XMLDocument.hpp index dc5bd1b3102..b4fd84bc480 100644 --- a/src/xrCore/XML/XMLDocument.hpp +++ b/src/xrCore/XML/XMLDocument.hpp @@ -8,7 +8,9 @@ #define PUGIXML_NO_XPATH #define PUGIXML_HAS_LONG_LONG #include "pugixml.hpp" +#ifdef DEBUG // debug & mixed #include "xrCommon/xr_vector.h" +#endif #include "xrCore/xrstring.h" static constexpr pcstr CONFIG_PATH = "$game_config$"; diff --git a/src/xrCore/_math.cpp b/src/xrCore/_math.cpp index 429305876a7..b665c9eb185 100644 --- a/src/xrCore/_math.cpp +++ b/src/xrCore/_math.cpp @@ -6,6 +6,7 @@ #include #include #elif defined(LINUX) +#include // __rdtsc #include #include #endif diff --git a/src/xrCore/_obb.h b/src/xrCore/_obb.h index a381634598f..8d427a14558 100644 --- a/src/xrCore/_obb.h +++ b/src/xrCore/_obb.h @@ -120,7 +120,7 @@ struct _obb Tvector kDirection; kDirection.set(dir.dotproduct(m_rotate.i), dir.dotproduct(m_rotate.j), dir.dotproduct(m_rotate.k)); - T fT0 = 0.0f, fT1 = type_max(T); + T fT0 = 0.0f, fT1 = type_max; if (intersect(kOrigin, kDirection, m_halfsize, fT0, fT1)) { bool bPick = false; diff --git a/src/xrCore/cpuid.cpp b/src/xrCore/cpuid.cpp index c371ea5c927..f4412b6f11a 100644 --- a/src/xrCore/cpuid.cpp +++ b/src/xrCore/cpuid.cpp @@ -203,7 +203,28 @@ unsigned int query_processor_info(processor_info* pinfo) #elif defined(LINUX) int logicalProcessorCount = std::thread::hardware_concurrency(); + //not sure about processorCoreCount - is it really cores or threads + //https://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine int processorCoreCount = sysconf(_SC_NPROCESSORS_ONLN); + + //2nd implementation + // + //#include + //// Allocate, initialize, and perform topology detection + //hwloc_topology_t topology; + //hwloc_topology_init(&topology); + //hwloc_topology_load(topology); + // + //// Try to get the number of CPU cores from topology + //int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_CORE); + //int processorCoreCount = hwloc_get_nbobjs_by_depth(topology, depth); + // + //// Destroy topology object and return + //hwloc_topology_destroy(topology); + + //3rd another implementation + //https://stackoverflow.com/questions/2901694/programmatically-detect-number-of-physical-processors-cores-or-if-hyper-threadin + #endif diff --git a/src/xrCore/xrCore.h b/src/xrCore/xrCore.h index f4f7f075179..8ce923d506f 100644 --- a/src/xrCore/xrCore.h +++ b/src/xrCore/xrCore.h @@ -50,7 +50,6 @@ #include "clsid.h" //#include "Threading/Lock.hpp" #include "xrMemory.h" -#include "xrDebug.h" //#include "_stl_extensions.h" #include "_std_extensions.h"