From d8208f0884ede854f0fe092f21d6525846e5837a Mon Sep 17 00:00:00 2001 From: s1lent Date: Thu, 6 Feb 2020 04:31:59 +0700 Subject: [PATCH] Added support building using cmake Added support clang compiler Fixed some compiler warnings Update README.md --- README.md | 30 ++++- regamedll/CMakeLists.txt | 148 ++++++++++++++++++++++ regamedll/build.gradle | 34 +++-- regamedll/compile.sh | 7 + regamedll/dlls/func_break.cpp | 2 +- regamedll/dlls/hostage/hostage_improv.cpp | 1 + regamedll/dlls/player.cpp | 12 +- regamedll/dlls/saverestore.cpp | 4 +- regamedll/dlls/sound.cpp | 2 +- regamedll/dlls/sound.h | 4 +- regamedll/dlls/soundent.cpp | 3 +- regamedll/engine/unicode_strtools.cpp | 2 +- regamedll/game_shared/bot/nav_file.cpp | 16 +-- regamedll/public/utlrbtree.h | 7 +- regamedll/version/appversion.sh | 141 +++++++++++++++++++++ shared.gradle | 5 + shared_clang.gradle | 55 ++++++++ version_script.lds | 18 +++ 18 files changed, 451 insertions(+), 40 deletions(-) create mode 100644 regamedll/CMakeLists.txt create mode 100644 regamedll/compile.sh create mode 100755 regamedll/version/appversion.sh create mode 100644 shared_clang.gradle create mode 100644 version_script.lds diff --git a/README.md b/README.md index 71ea2be2..821bf2a1 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ There are several software requirements for building Regamedll_CS:
  1. Java Development Kit (JDK) 7+ (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
  2. For Windows: Visual Studio 2015 and later
  3. -
  4. For Linux: Intel C++ Compiler 15 and later
  5. +
  6. For Linux: GCC/Clang/Intel C++ Compiler 15 and later
### Checking requirements @@ -122,19 +122,25 @@ Help -> About icc (ICC) 15.0.1 20141023 -### Building -On Windows: +### Building and run unit tests using gradle +#### On Windows:
gradlew --max-workers=1 clean buildRelease
* For faster building without unit tests use this:exclamation:
gradlew --max-workers=1 clean buildFixes
-On Linux (ICC): +#### On Linux (ICC):
./gradlew --max-workers=1 clean buildRelease
* For faster building without unit tests use this:exclamation:
./gradlew --max-workers=1 clean buildFixes
-On Linux (GCC): +#### On Linux (Clang): +
./gradlew --max-workers=1 clean -PuseClang buildRelease
+ +* For faster building without unit tests use this:exclamation: +
./gradlew --max-workers=1 clean -PuseClang buildFixes
+ +#### On Linux (GCC):
./gradlew --max-workers=1 clean -PuseGcc buildRelease
* For faster building without unit tests use this:exclamation: @@ -142,6 +148,20 @@ On Linux (GCC): Compiled binaries will be placed in the build/binaries/ directory +### Simplified building using CMake 3.1 and later +#### On Windows: +
Open solution msvc\ReGameDLL.sln and build it
+ +#### On Linux: +* Run script `regamedll/compile.sh` +* Options using `regamedll/compile.sh -D[option]=[ON or OFF]` (without square brackets) +
+DEBUG              - Enables debugging mode
+USE_INTEL_COMPILER - Switch main compiler to ICC
+USE_CLANG_COMPILER - Switch main compiler to Clang
+USE_STATIC_LIBSTDC - Enables static linking library libstdc++
+
+ ### Credits Thanks to the project [ReHLDS](https://github.com/dreamstalker/rehlds) ( ReGameDLL_CS was created on the basis of ReHLDS ) diff --git a/regamedll/CMakeLists.txt b/regamedll/CMakeLists.txt new file mode 100644 index 00000000..ff6431d5 --- /dev/null +++ b/regamedll/CMakeLists.txt @@ -0,0 +1,148 @@ +cmake_minimum_required(VERSION 3.1) +project(regamedll CXX) + +option(DEBUG "Build debug application." OFF) +option(USE_INTEL_COMPILER "Use the Intel compiler." OFF) +option(USE_CLANG_COMPILER "Use the Clang compiler." OFF) +option(USE_STATIC_LIBSTDC "Enables static linking libstdc++." OFF) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if (USE_INTEL_COMPILER) + set(CMAKE_C_COMPILER "/opt/intel/bin/icc") + set(CMAKE_CXX_COMPILER "/opt/intel/bin/icpc") +elseif (USE_CLANG_COMPILER) + set(CMAKE_C_COMPILER "/usr/bin/clang") + set(CMAKE_CXX_COMPILER "/usr/bin/clang++") +endif() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") + +if (USE_INTEL_COMPILER OR USE_CLANG_COMPILER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fasm-blocks") +endif() + +if (DEBUG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -ggdb -O3 -Wall -ffunction-sections -fdata-sections") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O3 -fno-rtti -ffunction-sections -fdata-sections") +endif() + +if (USE_INTEL_COMPILER) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel -no-intel-extensions") +else() + ## Produce code optimized for the most common IA32/AMD64/EM64T processors. + ## As new processors are deployed in the marketplace, the behavior of this option will change. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ + -mtune=generic -msse3\ + -Wno-write-strings -Wno-invalid-offsetof\ + -Wno-unused-variable -Wno-unused-function\ + -Wno-unused-result -Wno-invalid-offsetof\ + -fpermissive -Wno-switch -Wno-enum-compare\ + -Wno-unknown-pragmas -Wno-unused-value") + + if (USE_CLANG_COMPILER) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ + -Wno-unused-local-typedef\ + -Wno-unused-private-field\ + -fno-strict-vtable-pointers\ + -Wno-overloaded-virtual") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ + -Wno-unused-local-typedefs\ + -Wno-sign-compare\ + -Wno-strict-aliasing\ + -Wno-unused-but-set-variable\ + -fno-devirtualize") + endif() +endif() + +if (NOT DEBUG AND USE_STATIC_LIBSTDC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-gc-sections -Wl,--version-script=${PROJECT_SOURCE_DIR}/../version_script.lds") +endif() + +if (USE_STATIC_LIBSTDC) + add_definitions(-DBUILD_STATIC_LIBSTDC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") +endif() + +set(PROJECT_SRC_DIR + "${PROJECT_SOURCE_DIR}" + "${PROJECT_SOURCE_DIR}/engine" + "${PROJECT_SOURCE_DIR}/common" + "${PROJECT_SOURCE_DIR}/dlls" + "${PROJECT_SOURCE_DIR}/game_shared" + "${PROJECT_SOURCE_DIR}/pm_shared" + "${PROJECT_SOURCE_DIR}/regamedll" +) + +set(PROJECT_PUBLIC_DIR + "${PROJECT_SOURCE_DIR}/public" + "${PROJECT_SOURCE_DIR}/public/regamedll" +) + +set(ENGINE_SRCS + "engine/unicode_strtools.cpp" +) + +file(GLOB SHARED_SRCS + "game_shared/bot/*.cpp" + "game_shared/*.cpp" + "pm_shared/*.cpp" + "regamedll/*.cpp" + "public/FileSystem.cpp" + "public/interface.cpp" + "public/MemPool.cpp" + "version/version.cpp" +) + +list(REMOVE_ITEM SHARED_SRCS EXCLUDE "${PROJECT_SOURCE_DIR}/regamedll/classes_dummy.cpp") + +file(GLOB GAMEDLL_SRCS + "dlls/*.cpp" + "dlls/API/*.cpp" + "dlls/addons/*.cpp" + "dlls/wpn_shared/*.cpp" + "dlls/bot/*.cpp" + "dlls/bot/states/*.cpp" + "dlls/hostage/*.cpp" + "dlls/hostage/states/*.cpp" +) + +include_directories( + ${PROJECT_SRC_DIR} + ${PROJECT_PUBLIC_DIR} +) + +link_directories(${PROJECT_SOURCE_DIR}/lib/linux32) + +add_definitions( + -DREGAMEDLL_FIXES + -DBUILD_LATEST + -DREGAMEDLL_ADD + -DREGAMEDLL_API + -DUNICODE_FIXES + -DCLIENT_WEAPONS + -DUSE_QSTRING + -DGNUC + -DPOSIX + -D_LINUX + -DLINUX + -D_stricmp=strcasecmp + -D_strnicmp=strncasecmp + -D_strdup=strdup + -D_unlink=unlink + -D_vsnprintf=vsnprintf + -D_write=write + -D_close=close + -D_access=access + -D_vsnwprintf=vswprintf +) + +add_library(regamedll SHARED ${appversion.sh} ${GAMEDLL_SRCS} ${ENGINE_SRCS} ${SHARED_SRCS}) +set_property(TARGET regamedll PROPERTY LIBRARY_OUTPUT_NAME cs) +add_custom_target(appversion COMMAND ${PROJECT_SOURCE_DIR}/version/appversion.sh ${PROJECT_SOURCE_DIR} regamedll) +set_target_properties(regamedll PROPERTIES PREFIX "" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32" POSITION_INDEPENDENT_CODE ON) +target_link_libraries(regamedll dl aelf32) +add_dependencies(regamedll appversion) diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 0f6ec68e..6964226f 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -92,6 +92,7 @@ void postEvaluate(NativeBinarySpec b) { void setupToolchain(NativeBinarySpec b) { boolean useGcc = project.hasProperty("useGcc") + boolean useClang = project.hasProperty("useClang") boolean unitTestExecutable = b.component.name.endsWith('_tests') boolean regamedllFixes = b.flavor.name.contains('regamedllFixes') @@ -121,7 +122,7 @@ void setupToolchain(NativeBinarySpec b) cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED } else { - cfg.compilerOptions.args '/Oi', '/GF', '/GS-', '/GR-' + cfg.compilerOptions.args '/Oi', '/GF', '/GS', '/GR' } cfg.projectLibpath(project, '/lib') @@ -129,7 +130,7 @@ void setupToolchain(NativeBinarySpec b) } else if (cfg instanceof GccToolchainConfig) { - if (!useGcc) + if (!useGcc && !useClang) { cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions( enabled: true, @@ -150,10 +151,17 @@ void setupToolchain(NativeBinarySpec b) '_access' : 'access' ]) - if (useGcc) { + if (useGcc || useClang) { // Produce code optimized for the most common IA32/AMD64/EM64T processors. // As new processors are deployed in the marketplace, the behavior of this option will change. - cfg.compilerOptions.args '-mtune=generic', '-msse3', '-Wno-write-strings', '-Wno-invalid-offsetof', '-fpermissive', '-fno-devirtualize' + cfg.compilerOptions.args '-mtune=generic', '-msse3', '-Wno-write-strings', '-Wno-invalid-offsetof', '-fpermissive', '-Wno-switch', '-Wno-unused-value', '-Wno-enum-compare' + + if (useGcc) { + cfg.compilerOptions.args '-fno-devirtualize' + else { + cfg.compilerOptions.args '-fno-strict-vtable-pointers', '-Wno-overloaded-virtual' + } + } else { cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp' @@ -169,7 +177,7 @@ void setupToolchain(NativeBinarySpec b) cfg.singleDefines 'BUILD_STATIC_LIBSTDC' } - cfg.compilerOptions.args '-g0', '-fno-rtti', '-fno-exceptions' + cfg.compilerOptions.args '-g0', '-fno-exceptions' cfg.projectLibpath(project, '/lib/linux32') cfg.extraLibs 'dl', 'm', 'aelf32' } @@ -276,7 +284,10 @@ model { toolChains { visualCpp(VisualCpp) { } - if (project.hasProperty("useGcc")) { + if (project.hasProperty("useClang")) { + clang(Clang) + } + else if (project.hasProperty("useGcc")) { gcc(Gcc) } else { icc(Icc) @@ -343,11 +354,18 @@ task buildFixes { } } +task buildDebug { + dependsOn binaries.withType(SharedLibraryBinarySpec).matching { + SharedLibraryBinarySpec blib -> blib.buildable && blib.buildType.name == 'debug' && blib.flavor.name == 'regamedllFixes' && blib.component.name == 'regamedll_mp_gamedll' + } +} + buildFixes.finalizedBy(buildFinalize); +buildDebug.finalizedBy(buildFinalize); buildRelease.finalizedBy(buildFinalize); gradle.taskGraph.whenReady { graph -> - if (!graph.hasTask(buildFixes)) { + if (!graph.hasTask(buildFixes) && !graph.hasTask(buildDebug)) { return; } @@ -396,7 +414,7 @@ tasks.clean.doLast { task generateAppVersion { - RegamedllVersionInfo verInfo = (RegamedllVersionInfo) rootProject.regamedllVersionInfo + RegamedllVersionInfo verInfo = (RegamedllVersionInfo)rootProject.regamedllVersionInfo def tplFile = project.file('version/appversion.vm') def renderedFile = project.file('version/appversion.h') diff --git a/regamedll/compile.sh b/regamedll/compile.sh new file mode 100644 index 00000000..c75a2eed --- /dev/null +++ b/regamedll/compile.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +rm -rf build +mkdir build +cd build +cmake ../ $* +make diff --git a/regamedll/dlls/func_break.cpp b/regamedll/dlls/func_break.cpp index 238febf9..fa819f83 100644 --- a/regamedll/dlls/func_break.cpp +++ b/regamedll/dlls/func_break.cpp @@ -397,7 +397,7 @@ void CBreakable::DamageSound() int pitch; float fvol; char *rgpsz[6]; - int i; + int i = 0; int material = m_Material; if (RANDOM_LONG(0, 2)) diff --git a/regamedll/dlls/hostage/hostage_improv.cpp b/regamedll/dlls/hostage/hostage_improv.cpp index 9045a891..a70d2c76 100644 --- a/regamedll/dlls/hostage/hostage_improv.cpp +++ b/regamedll/dlls/hostage/hostage_improv.cpp @@ -201,6 +201,7 @@ void CHostageImprov::MoveTowards(const Vector &pos, float deltaT) switch (m_moveType) { case Stopped: + default: accelRate = 0; break; case Walking: diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 4af41c6f..1d75039b 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -2098,7 +2098,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) case 1: { UTIL_ScreenFade(this, Vector(0, 0, 0), 3, 3, 255, (FFADE_OUT | FFADE_STAYOUT)); - break; } case 2: @@ -2116,7 +2115,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib) { CBasePlayer* pObserver = UTIL_PlayerByIndex(i); - if (pObserver == this || pObserver && pObserver->IsObservingPlayer(this)) + if (pObserver == this || (pObserver && pObserver->IsObservingPlayer(this))) { UTIL_ScreenFade(pObserver, Vector(0, 0, 0), 1, 4, 255, (FFADE_OUT)); } @@ -2677,9 +2676,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) animDesired = LookupActivity(ACT_DIE_BACKSHOT); m_iThrowDirection = THROW_HITVEL; break; - case 3: - animDesired = LookupActivity(ACT_DIESIMPLE); - break; case 4: animDesired = LookupActivity(ACT_DIEBACKWARD); m_iThrowDirection = THROW_HITVEL; @@ -2698,6 +2694,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) animDesired = LookupActivity(ACT_DIE_HEADSHOT); break; default: + animDesired = LookupActivity(ACT_DIESIMPLE); break; } break; @@ -2750,11 +2747,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(SetAnimation)(PLAYER_ANIM playerAnim) break; } default: - { animDesired = LookupActivity(ACT_DIESIMPLE); break; - } } + if (pev->flags & FL_DUCKING) { animDesired = LookupSequence("crouch_die"); @@ -4349,7 +4345,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() #ifdef REGAMEDLL_FIXES IsAlive() && #endif - m_flIdleCheckTime <= (double)gpGlobals->time || m_flIdleCheckTime == 0.0f) + (m_flIdleCheckTime <= (double)gpGlobals->time || m_flIdleCheckTime == 0.0f)) { // check every 5 seconds m_flIdleCheckTime = gpGlobals->time + 5.0; diff --git a/regamedll/dlls/saverestore.cpp b/regamedll/dlls/saverestore.cpp index 0522ce8f..a8e63d12 100644 --- a/regamedll/dlls/saverestore.cpp +++ b/regamedll/dlls/saverestore.cpp @@ -282,8 +282,8 @@ extern "C" { inline unsigned _rotr(unsigned val, int shift) { - register unsigned lobit; - register unsigned num = val; + unsigned lobit; + unsigned num = val; shift &= 0x1f; diff --git a/regamedll/dlls/sound.cpp b/regamedll/dlls/sound.cpp index 31099871..57605f7f 100644 --- a/regamedll/dlls/sound.cpp +++ b/regamedll/dlls/sound.cpp @@ -772,7 +772,7 @@ void CAmbientGeneric::KeyValue(KeyValueData *pkvd) // lfotype else if (FStrEq(pkvd->szKeyName, "lfotype")) { - m_dpv.lfotype = (LowFreqOsc)Q_atoi(pkvd->szValue); + m_dpv.lfotype = Q_atoi(pkvd->szValue); if (m_dpv.lfotype > 4) m_dpv.lfotype = LFO_TRIANGLE; diff --git a/regamedll/dlls/sound.h b/regamedll/dlls/sound.h index 7c876f53..d2f0b41a 100644 --- a/regamedll/dlls/sound.h +++ b/regamedll/dlls/sound.h @@ -38,7 +38,7 @@ const int MAX_SENTENCE_DPV_RESET = 27; // Max number of dynamic pitch volumes const float MAX_ANNOUNCE_MINS = 2.25f; const float MIN_ANNOUNCE_MINS = 0.25f; -enum LowFreqOsc : int +enum { LFO_OFF = 0, LFO_SQUARE, // Square @@ -75,7 +75,7 @@ typedef struct dynpitchvol int fadeout; // Volume fade out time 0 - 100 // Low Frequency Oscillator - LowFreqOsc lfotype; // 0) off 1) square 2) triangle 3) random + int lfotype; // 0) off 1) square 2) triangle 3) random int lforate; // 0 - 1000, how fast lfo osciallates int lfomodpitch; // 0-100 mod of current pitch. 0 is off. diff --git a/regamedll/dlls/soundent.cpp b/regamedll/dlls/soundent.cpp index 4825e6d3..de8980b8 100644 --- a/regamedll/dlls/soundent.cpp +++ b/regamedll/dlls/soundent.cpp @@ -238,7 +238,7 @@ void CSoundEnt::Initialize() int CSoundEnt::ISoundsInList(int iListType) { int i; - int iThisSound; + int iThisSound = SOUNDLIST_EMPTY; if (iListType == SOUNDLISTTYPE_FREE) { @@ -251,6 +251,7 @@ int CSoundEnt::ISoundsInList(int iListType) else { ALERT(at_console, "Unknown Sound List Type!\n"); + iThisSound = iListType; } if (iThisSound == SOUNDLIST_EMPTY) diff --git a/regamedll/engine/unicode_strtools.cpp b/regamedll/engine/unicode_strtools.cpp index d20118c3..d19c92f0 100644 --- a/regamedll/engine/unicode_strtools.cpp +++ b/regamedll/engine/unicode_strtools.cpp @@ -563,7 +563,7 @@ int Q_UChar32ToUTF8(uchar32 uVal, char *pUTF8Out) if (uVal <= 0xFFFF) { pUTF8Out[0] = (unsigned char)(uVal >> 12) | 0xE0; - pUTF8Out[1] = (unsigned char)(uVal >> 6) & 0x3F | 0x80; + pUTF8Out[1] = (unsigned char)((uVal >> 6) & 0x3F) | 0x80; pUTF8Out[2] = (unsigned char)(uVal & 0x3F) | 0x80; return 3; } diff --git a/regamedll/game_shared/bot/nav_file.cpp b/regamedll/game_shared/bot/nav_file.cpp index 9c486026..1e8bf717 100644 --- a/regamedll/game_shared/bot/nav_file.cpp +++ b/regamedll/game_shared/bot/nav_file.cpp @@ -331,7 +331,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) // Load hiding spots // load number of hiding spots - unsigned char hidingSpotCount; + unsigned char hidingSpotCount = 0; file->Read(&hidingSpotCount, sizeof(unsigned char)); if (version == 1) @@ -366,13 +366,13 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&m_approachCount, sizeof(unsigned char)); // load approach area info (IDs) - unsigned char type; + unsigned char type = 0; for (int a = 0; a < m_approachCount; a++) { file->Read(&m_approach[a].here.id, sizeof(unsigned int)); file->Read(&m_approach[a].prev.id, sizeof(unsigned int)); - file->Read(&type, sizeof(unsigned char) ); + file->Read(&type, sizeof(unsigned char)); m_approach[a].prevToHereHow = (NavTraverseType)type; file->Read(&m_approach[a].next.id, sizeof(unsigned int)); @@ -398,7 +398,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&encounter.path.to.x, 3 * sizeof(float)); // read list of spots along this path - unsigned char spotCount; + unsigned char spotCount = 0; file->Read(&spotCount, sizeof(unsigned char)); for (int s = 0; s < spotCount; s++) @@ -418,7 +418,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) file->Read(&encounter.from.id, sizeof(unsigned int)); - unsigned char dir; + unsigned char dir = 0; file->Read(&dir, sizeof(unsigned char)); encounter.fromDir = static_cast(dir); @@ -428,7 +428,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) encounter.toDir = static_cast(dir); // read list of spots along this path - unsigned char spotCount; + unsigned char spotCount = 0; file->Read(&spotCount, sizeof(unsigned char)); SpotOrder order; @@ -436,7 +436,7 @@ void CNavArea::Load(SteamFile *file, unsigned int version) { file->Read(&order.id, sizeof(unsigned int)); - unsigned char t; + unsigned char t = 0; file->Read(&t, sizeof(unsigned char)); order.t = float(t) / 255.0f; @@ -733,7 +733,7 @@ void SanityCheckNavigationMap(const char *mapName) navFile.Read(&saveBspSize, sizeof(unsigned int)); // verify size - if (!bspFilename) + if (saveBspSize == 0) { CONSOLE_ECHO("ERROR: No map corresponds to navigation file %s.\n", navFilename); return; diff --git a/regamedll/public/utlrbtree.h b/regamedll/public/utlrbtree.h index bc333c8e..100ccbc9 100644 --- a/regamedll/public/utlrbtree.h +++ b/regamedll/public/utlrbtree.h @@ -235,11 +235,12 @@ protected: // Constructor, Destructor template CUtlRBTree::CUtlRBTree(int growSize, int initSize, LessFunc_t lessfunc) : - m_Elements(growSize, initSize), m_LessFunc(lessfunc), + m_Elements(growSize, initSize), m_Root(InvalidIndex()), - m_NumElements(0), m_TotalElements(0), - m_FirstFree(InvalidIndex()) + m_NumElements(0), + m_FirstFree(InvalidIndex()), + m_TotalElements(0) { } diff --git a/regamedll/version/appversion.sh b/regamedll/version/appversion.sh new file mode 100755 index 00000000..35a94cb5 --- /dev/null +++ b/regamedll/version/appversion.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +init() +{ + SOURCE_DIR=$1 + VERSION_FILE=$SOURCE_DIR/../gradle.properties + APPVERSION_FILE=$SOURCE_DIR/version/appversion.h + + if test -z "`git --version`"; then + echo "Please install git client" + echo "sudo apt-get install git" + exit 0 + fi + + # Read old version + if [ -e $APPVERSION_FILE ]; then + OLD_VERSION=$(cat $APPVERSION_FILE | grep -wi '#define APP_VERSION' | sed -e 's/#define APP_VERSION[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') + if [ $? -ne 0 ]; then + OLD_VERSION="" + else + # Remove quotes + OLD_VERSION=$(echo $OLD_VERSION | xargs) + fi + fi + + + # Get major, minor and maintenance information from version.h + MAJOR=$(sed -nr -e '/majorVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + if [ $? -ne 0 -o "$MAJOR" = "" ]; then + MAJOR=0 + fi + + MINOR=$(sed -nr -e '/minorVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + if [ $? -ne 0 -o "$MINOR" = "" ]; then + MINOR=0 + fi + + MAINTENANCE=$(sed -nr -e '/maintenanceVersion/ s/.*\= *//p' $VERSION_FILE | tr -d '\n\r') + if [ $? -ne 0 -o "$MAINTENANCE" = "" ]; then + MAINTENANCE=0 + fi + + BRANCH_NAME=$(git -C $SOURCE_DIR/../ rev-parse --abbrev-ref HEAD) + if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then + BRANCH_NAME=master + fi + + COMMIT_COUNT=$(git -C $SOURCE_DIR/../ rev-list --count $BRANCH_NAME) + if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then + COMMIT_COUNT=0 + fi + + # + # Configure remote url repository + # + # Get remote name by current branch + BRANCH_REMOTE=$(git -C $SOURCE_DIR/../ config branch.$BRANCH_NAME.remote) + if [ $? -ne 0 -o "$BRANCH_REMOTE" = "" ]; then + BRANCH_REMOTE=origin + fi + + # Get commit id + COMMIT_SHA=$(git -C $SOURCE_DIR/../ rev-parse --verify HEAD) + COMMIT_SHA=${COMMIT_SHA:0:7} + + # Get remote url + COMMIT_URL=$(git -C $SOURCE_DIR/../ config remote.$BRANCH_REMOTE.url) + + # Strip prefix 'git@' + COMMIT_URL=${COMMIT_URL#git@} + + # Strip postfix '.git' + COMMIT_URL=${COMMIT_URL%.git} + + # Replace ':' to '/' + COMMIT_URL=${COMMIT_URL/:/\/} + + # Append extra string + if [ $? -ne 0 -o "$COMMIT_URL" = "${COMMIT_URL/bitbucket.org}" ]; then + COMMIT_URL=$(echo https://$COMMIT_URL/commits/) + else + COMMIT_URL=$(echo https://$COMMIT_URL/commit/) + fi + + # + # Detect local modifications + # + if [ `git -C $SOURCE_DIR/../ ls-files -m | wc -l` = 0 ]; then + MODIFIED= + else + MODIFIED=+m + fi + + NEW_VERSION="$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT-dev$MODIFIED" + + # Update appversion.h if version has changed or modifications/mixed revisions detected + if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then + update_appversion + fi +} + +update_appversion() +{ + day=$(date +%m) + year=$(date +%Y) + hours=$(date +%H:%M:%S) + month=$(LANG=en_us_88591; date +"%b") + + # Write appversion.h + echo Updating appversion.h, new version is '"'$NEW_VERSION'"', the old one was $OLD_VERSION + + echo -e "#ifndef __APPVERSION_H__\r">$APPVERSION_FILE + echo -e "#define __APPVERSION_H__\r">>$APPVERSION_FILE + echo -e "\r">>$APPVERSION_FILE + echo -e "//\r">>$APPVERSION_FILE + echo -e "// This file is generated automatically.\r">>$APPVERSION_FILE + echo -e "// Don't edit it.\r">>$APPVERSION_FILE + echo -e "//\r">>$APPVERSION_FILE + echo -e "\r">>$APPVERSION_FILE + echo -e "// Version defines\r">>$APPVERSION_FILE + echo -e '#define APP_VERSION "'$NEW_VERSION'"\r'>>$APPVERSION_FILE + + echo -e "#define APP_VERSION_C $MAJOR,$MINOR,$MAINTENANCE,$COMMIT_COUNT\r">>$APPVERSION_FILE + echo -e '#define APP_VERSION_STRD "'$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT'"\r'>>$APPVERSION_FILE + echo -e "#define APP_VERSION_FLAGS 0x0L\r">>$APPVERSION_FILE + echo -e "\r">>$APPVERSION_FILE + echo -e '#define APP_COMMIT_DATE "'$month $day $year'"\r'>>$APPVERSION_FILE + echo -e '#define APP_COMMIT_TIME "'$hours'"\r'>>$APPVERSION_FILE + echo -e "\r">>$APPVERSION_FILE + + echo -e '#define APP_COMMIT_SHA "'$COMMIT_SHA'"\r'>>$APPVERSION_FILE + echo -e '#define APP_COMMIT_URL "'$COMMIT_URL'"\r'>>$APPVERSION_FILE + echo -e "\r">>$APPVERSION_FILE + echo -e "#endif //__APPVERSION_H__\r">>$APPVERSION_FILE +} + +# Initialise +init $* + +# Exit normally +exit 0 diff --git a/shared.gradle b/shared.gradle index 1c46bc49..47ed31b1 100644 --- a/shared.gradle +++ b/shared.gradle @@ -8,6 +8,7 @@ import org.gradle.nativeplatform.toolchain.VisualCpp apply from: 'shared_msvc.gradle' apply from: 'shared_icc.gradle' +apply from: 'shared_clang.gradle' apply from: 'shared_gcc.gradle' rootProject.ext.createToolchainConfig = { NativeBinarySpec bin -> @@ -38,6 +39,10 @@ rootProject.ext.createToolchainConfig = { NativeBinarySpec bin -> { return rootProject.createIccConfig(releaseBuild, binaryKind) } + else if (bin.toolChain instanceof Clang) + { + return rootProject.createClangConfig(releaseBuild, binaryKind) + } else if (bin.toolChain instanceof Gcc) { return rootProject.createGccConfig(releaseBuild, binaryKind) diff --git a/shared_clang.gradle b/shared_clang.gradle new file mode 100644 index 00000000..9891ea24 --- /dev/null +++ b/shared_clang.gradle @@ -0,0 +1,55 @@ +import org.doomedsociety.gradlecpp.cfg.BinaryKind +import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig +import org.doomedsociety.gradlecpp.gcc.OptimizationLevel + +rootProject.ext.createClangConfig = { boolean release, BinaryKind binKind -> + GccToolchainConfig cfg + if (release) { + cfg = new GccToolchainConfig( + compilerOptions: new GccToolchainConfig.CompilerOptions( + optimizationLevel: OptimizationLevel.LEVEL_3, + stackProtector: false, + noBuiltIn: true, + positionIndependentCode: false, + extraDefines: [ + '_GLIBCXX_USE_CXX11_ABI': 0, + ] + ), + + linkerOptions: new GccToolchainConfig.LinkerOptions( + stripSymbolTable: false, + staticLibGcc: false, + staticLibStdCpp: false, + ), + + librarianOptions: new GccToolchainConfig.LibrarianOptions( + + ) + ) + } else { + // debug + cfg = new GccToolchainConfig( + compilerOptions: new GccToolchainConfig.CompilerOptions( + optimizationLevel: OptimizationLevel.DISABLE, + stackProtector: true, + noBuiltIn: true, + extraDefines: [ + '_GLIBCXX_USE_CXX11_ABI': 0, + ] + ), + + linkerOptions: new GccToolchainConfig.LinkerOptions( + stripSymbolTable: false, + staticLibGcc: false, + staticLibStdCpp: false, + ), + + librarianOptions: new GccToolchainConfig.LibrarianOptions( + + ) + ) + } + + cfg.singleDefines('LINUX', '_LINUX') + return cfg +} diff --git a/version_script.lds b/version_script.lds new file mode 100644 index 00000000..96fbab0a --- /dev/null +++ b/version_script.lds @@ -0,0 +1,18 @@ +REGAMEDLL_ABI_1.0 { + global: + *; + local: + _Zn*; + _Zd*; + + extern "C++" { + *std::*; + *__cxxabi*::*; + *__gnu_cxx::*; + __cxa_*; + _txnal_*; + __dynamic_cast; + __gxx_personality_*; + __gcclibcxx_demangle_callback; + }; +};