diff --git a/.github/workflows/mapbase_build-base-dispatch.yml b/.github/workflows/mapbase_build-base-dispatch.yml index 4e80325ce24..9822a06eeb2 100644 --- a/.github/workflows/mapbase_build-base-dispatch.yml +++ b/.github/workflows/mapbase_build-base-dispatch.yml @@ -20,14 +20,13 @@ on: - Debug game: description: 'Name of the game to build (if relevant)' - default: 'episodic' + default: 'tf /hl2mp' required: false type: choice options: - - episodic + - episodic /hl2 - hl2 - hl2mp - - hl2mp /episodic - tf - tf /hl2mp project-group: @@ -39,8 +38,21 @@ on: - game - shaders - maptools - build-on-linux: - description: 'Build on Ubuntu/Linux?' + arch: + description: 'Which architecture to build for' + default: '64' + required: false + type: choice + options: + - 64 + - 32 + build-windows: + description: 'Build on Windows?' + default: true + required: false + type: boolean + build-linux: + description: 'Build on Linux?' default: true required: false type: boolean @@ -52,4 +64,6 @@ jobs: configuration: '${{ github.event.inputs.configuration }}' game: '${{ github.event.inputs.game }}' project-group: '${{ github.event.inputs.project-group }}' - build-on-linux: "${{ github.event.inputs.build-on-linux == 'true' }}" + arch: '${{ github.event.inputs.arch }}' + build-windows: "${{ github.event.inputs.build-windows == 'true' }}" + build-linux: "${{ github.event.inputs.build-linux == 'true' }}" diff --git a/.github/workflows/mapbase_build-base.yml b/.github/workflows/mapbase_build-base.yml index e473b6d399c..4c3196300e9 100644 --- a/.github/workflows/mapbase_build-base.yml +++ b/.github/workflows/mapbase_build-base.yml @@ -30,31 +30,42 @@ on: description: 'Which group of projects to compile' required: true type: string - build-on-linux: - description: 'Build on Ubuntu/Linux?' + arch: + description: 'Which architecture to build for' + default: '64' + required: false + type: string + build-windows: + description: 'Build on Windows?' + default: true + required: false + type: boolean + build-linux: + description: 'Build on Linux?' default: true required: false type: boolean jobs: build_windows: - name: Windows (VS2022) + if: inputs.build-windows + name: Windows runs-on: windows-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 with: python-version: '3.13' - name: Add MSBuild to PATH - uses: compnerd/gha-setup-vsdevenv@v6 + uses: compnerd/gha-setup-vsdevenv@v7 # HACKHACK: MSBuild doesn't seem to recognize Python even when its directory is within PATH, # so we currently have to make it call Python directly. # This assumes %Python3_ROOT_DIR% will always be set by setup-python above. - name: Implement Python workaround - if: inputs.project-group == 'game' || inputs.project-group == 'everything' + if: contains(inputs.project-group, 'game') || contains(inputs.project-group, 'everything') working-directory: 'src/game/server' shell: bash run: | @@ -65,7 +76,7 @@ jobs: working-directory: 'src' shell: cmd run: | - devtools\bin\vpc.exe /${{inputs.game}} /define:SOURCESDK +${{inputs.project-group}} /mksln build.sln + devtools\bin\vpc.exe /${{inputs.game}} /win${{inputs.arch}} /define:SOURCESDK /define:CI_RUNNER +${{inputs.project-group}} /mksln build.sln # -------------------------------------------------------------------- @@ -75,14 +86,14 @@ jobs: shell: cmd run: | devenv build.sln /upgrade - msbuild -m -t:Rebuild -p:Configuration=${{inputs.configuration}};Platform=win64 build.sln + msbuild -m -t:Rebuild -p:Configuration=${{inputs.configuration}};Platform=win${{inputs.arch}} build.sln # -------------------------------------------------------------------- - name: Publish binaries - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: - name: '${{inputs.project-group}}_win64_${{ inputs.configuration }}' + name: '${{inputs.project-group}}_win${{inputs.arch}}_${{ inputs.configuration }}' path: | game/bin game/bin/x64 @@ -90,17 +101,19 @@ jobs: game/mod_*/x64/bin !game/bin/x64/steam_api64.dll !game/bin/linux64/libsteam_api.so + game/*.exe + game/*.exe if-no-files-found: error build_ubuntu: - if: inputs.build-on-linux == true && inputs.project-group != 'maptools' # No Linux map tools for now - name: Ubuntu (GCC/G++) + if: inputs.build-linux == true + name: Linux runs-on: ubuntu-latest env: config: ${{ inputs.configuration }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Install dependencies run: | @@ -108,12 +121,12 @@ jobs: sudo apt-get -y install podman python3 - name: Pick game - if: inputs.project-group == 'game' || inputs.project-group == 'shaders' working-directory: 'src' shell: bash run: | sed -i 's|/hl2mp /tf|/${{inputs.game}}|' buildgameprojects - sed -i 's|+game|+${{inputs.project-group}}|' buildgameprojects + sed -i 's|+game|/define:CI_RUNNER +${{inputs.project-group}}|' buildgameprojects + sed -i 's|/linux64|/linux${{inputs.arch}}|' buildgameprojects - name: Set configuration working-directory: 'src' @@ -143,9 +156,9 @@ jobs: # For now, don't publish the .dbg files even though we publish .pdb files on Windows # (they're too big) - name: Publish binaries - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: - name: '${{inputs.project-group}}_linux64_${{ inputs.configuration }}' + name: '${{inputs.project-group}}_linux${{inputs.arch}}_${{ inputs.configuration }}' path: | game/bin/linux64/*.so game/bin/*.so @@ -156,4 +169,6 @@ jobs: !game/mod_*/bin/linux64/*_srv.so !game/mod_*/bin/*_srv.so !game/bin/linux64/libsteam_api.so + game/* + game/* if-no-files-found: error diff --git a/.github/workflows/mapbase_build-games.yml b/.github/workflows/mapbase_build-games.yml deleted file mode 100644 index 9b1297d64d9..00000000000 --- a/.github/workflows/mapbase_build-games.yml +++ /dev/null @@ -1,37 +0,0 @@ -# -# MAPBASE SOURCE 2013 CI -# -# Builds game projects every time a pull request which modifies the game code is opened. -# If you're using a fork of Mapbase, feel free to configure this to meet your repository's needs. -# -# See mapbase_build-base.yml for more information on how this works. - -name: Build Game Projects #(SP Release) - -on: - pull_request: - branches: - - develop - - mapbase-mp-2025 - paths: - - '.github/workflows/mapbase_build-base.yml' - - '.github/workflows/mapbase_build-games.yml' - - 'src/vpc_scripts/**' - - 'src/game/**' - - 'src/mathlib/**' - - 'src/responserules/runtime/**' - - 'src/tier1/**' - - 'src/vgui2/vgui_controls/**' - - 'src/vscript/**' - -jobs: - games: - strategy: - matrix: - configuration: [Release, Debug] - uses: ./.github/workflows/mapbase_build-base.yml - with: - configuration: ${{ matrix.configuration }} - game: 'tf /hl2mp' # Change this if your mod is not using these game projects - project-group: 'game' - build-on-linux: true # Disable this if you don't want to compile for Linux diff --git a/.github/workflows/mapbase_build-generic.yml b/.github/workflows/mapbase_build-generic.yml new file mode 100644 index 00000000000..1868cd1dda0 --- /dev/null +++ b/.github/workflows/mapbase_build-generic.yml @@ -0,0 +1,96 @@ +# +# MAPBASE SOURCE 2013 CI +# +# Builds projects every time a pull request which modifies the code is opened. +# If you're using a fork of Mapbase, feel free to configure this to meet your repository's needs. +# +# See mapbase_build-base.yml for more information on how this works. + +name: Build Projects + +on: + pull_request: + branches: + - develop + - mapbase-mp-2025 + - feature/combined-sp-mp + paths: + - '.github/workflows/mapbase_build-generic.yml' + - 'src/**' + +jobs: + check-changes: + runs-on: ubuntu-latest + outputs: + project-groups: ${{ steps.combine-group.outputs.groups }} + steps: + - uses: actions/checkout@v7 + + - name: Identify file changes + uses: dorny/paths-filter@v4 + id: filter + with: + filters: | + games: + - 'src/game/**' + - 'src/responserules/runtime/**' + - 'src/vgui2/vgui_controls/**' + - 'src/vscript/**' + shaders: + - 'src/materialsystem/**' + maptools: + - 'src/utils/vbsp/**' + - 'src/utils/vvis/**' + - 'src/utils/vvis_launcher/**' + - 'src/utils/vrad/**' + - 'src/utils/vrad_launcher/**' + - 'src/vscript/**' + everything: + - 'src/vpc_scripts/**' + - 'src/mathlib/**' + - 'src/tier1/**' + - '.github/workflows/mapbase_build-generic.yml' + + - name: Combine project groups + id: combine-group + env: + in_games_group: ${{ steps.filter.outputs.games }} + in_shaders_group: ${{ steps.filter.outputs.shaders }} + in_maptools_group: ${{ steps.filter.outputs.maptools }} + in_everything_group: ${{ steps.filter.outputs.everything }} + run: | + all_groups="" + if [ "$in_everything_group" = "true" ]; then + # 'everything' encompasses all other groups + all_groups+=" +everything" + else + if [ "$in_games_group" = "true" ]; then + all_groups+=" +game" + fi + if [ "$in_shaders_group" = "true" ]; then + all_groups+=" +shaders" + fi + if [ "$in_maptools_group" = "true" ]; then + all_groups+=" +maptools" + fi + fi + echo "groups=${all_groups:2}" >> "$GITHUB_OUTPUT" + + build: + needs: check-changes + strategy: + matrix: + arch: [32, 64] + configuration: [Release, Debug] + include: + - game: 'tf /hl2mp' + arch: 64 + - game: 'hl2 /episodic' + arch: 32 + uses: ./.github/workflows/mapbase_build-base.yml + with: + configuration: ${{ matrix.configuration }} + game: ${{ matrix.game }} + project-group: ${{ needs.check-changes.outputs.project-groups }} + build-linux: true # Disable this if you don't want to compile for Linux + arch: ${{ matrix.arch }} diff --git a/.github/workflows/mapbase_build-maptools.yml b/.github/workflows/mapbase_build-maptools.yml deleted file mode 100644 index c0025ff66a2..00000000000 --- a/.github/workflows/mapbase_build-maptools.yml +++ /dev/null @@ -1,38 +0,0 @@ -# -# MAPBASE SOURCE 2013 CI -# -# Builds map tool projects every time a pull request which modifies the map tool code is opened. -# If you're using a fork of Mapbase, feel free to configure this to meet your repository's needs. -# -# See mapbase_build-base.yml for more information on how this works. - -name: Build Map Tool Projects #(SP Release) - -on: - pull_request: - branches: - - develop - - mapbase-mp-2025 - paths: - - '.github/workflows/mapbase_build-maptools.yml' - - 'src/vpc_scripts/**' - - 'src/utils/vbsp/**' - - 'src/utils/vvis/**' - - 'src/utils/vvis_launcher/**' - - 'src/utils/vrad/**' - - 'src/utils/vrad_launcher/**' - - 'src/mathlib/**' - - 'src/tier1/**' - - 'src/vgui2/vgui_controls/**' - - 'src/vscript/**' - -jobs: - maptools: - strategy: - matrix: - configuration: [Release, Debug] - uses: ./.github/workflows/mapbase_build-base.yml - with: - configuration: ${{ matrix.configuration }} - project-group: 'maptools' - solution-name: 'maptools' diff --git a/.github/workflows/mapbase_build-master.yml b/.github/workflows/mapbase_build-master.yml index ae7fe6498ef..c76ccbb9cc8 100644 --- a/.github/workflows/mapbase_build-master.yml +++ b/.github/workflows/mapbase_build-master.yml @@ -10,7 +10,7 @@ # # See mapbase_build-base.yml for more information on how this works. -name: Build All Projects #(SP Release) +name: Build All on: pull_request: @@ -22,8 +22,16 @@ jobs: strategy: matrix: configuration: [Release, Debug] + arch: [32, 64] + include: + - game: 'tf /hl2mp' + arch: 64 + - game: 'hl2 /episodic' + arch: 32 uses: ./.github/workflows/mapbase_build-base.yml with: configuration: ${{ matrix.configuration }} + game: ${{ matrix.game }} project-group: 'everything' - build-on-linux: true # Disable this if you don't want to compile for Linux + build-linux: true # Disable this if you don't want to compile for Linux + arch: ${{ matrix.arch }} diff --git a/.github/workflows/mapbase_build-shaders.yml b/.github/workflows/mapbase_build-shaders.yml deleted file mode 100644 index 3ccb6ddb1f6..00000000000 --- a/.github/workflows/mapbase_build-shaders.yml +++ /dev/null @@ -1,32 +0,0 @@ -# -# MAPBASE SOURCE 2013 CI -# -# Builds shader projects every time a pull request which modifies the shader code is opened. -# If you're using a fork of Mapbase, feel free to configure this to meet your repository's needs. -# -# See mapbase_build-base.yml for more information on how this works. - -name: Build Shader Projects #(SP Release) - -on: - pull_request: - branches: - - develop - - mapbase-mp-2025 - paths: - - '.github/workflows/mapbase_build-shaders.yml' - - 'src/vpc_scripts/**' - - 'src/materialsystem/**' - - 'src/mathlib/**' - -jobs: - shaders: - strategy: - matrix: - configuration: [Release, Debug] - uses: ./.github/workflows/mapbase_build-base.yml - with: - configuration: ${{ matrix.configuration }} - game: 'episodic' # Change this if your mod is not using HL2/Episodic game projects - project-group: 'shaders' - build-on-linux: true # Disable this if you don't want to compile for Linux diff --git a/src/buildallprojects b/src/buildallprojects index 20680ec9841..f480065b0a1 100755 --- a/src/buildallprojects +++ b/src/buildallprojects @@ -31,6 +31,7 @@ if [[ ! -e "$solution_out.ninja" ]]; then # Remove some unsupported clang commands. sed -i 's/-fpredictive-commoning//g; s/-fvar-tracking-assignments//g' compile_commands.json sed -i 's|/my_mod/src|.|g' compile_commands.json + sed -i 's|i386|i686|g' "$solution_out.ninja" # Need i686-linux-gnu-g++, not i386-linux-gnu-g++ fi ninja -f "$solution_out.ninja" -j$(nproc) diff --git a/src/buildgameprojects b/src/buildgameprojects index c335c41f547..cdbdcf6f36e 100755 --- a/src/buildgameprojects +++ b/src/buildgameprojects @@ -31,6 +31,7 @@ if [[ ! -e "$solution_out.ninja" ]]; then # Remove some unsupported clang commands. sed -i 's/-fpredictive-commoning//g; s/-fvar-tracking-assignments//g' compile_commands.json sed -i 's|/my_mod/src|.|g' compile_commands.json + sed -i 's|i386|i686|g' "$solution_out.ninja" # Need i686-linux-gnu-g++, not i386-linux-gnu-g++ fi ninja -f "$solution_out.ninja" -j$(nproc) diff --git a/src/buildshadersprojects b/src/buildshadersprojects index f7a730c3192..54ab9ac43c0 100755 --- a/src/buildshadersprojects +++ b/src/buildshadersprojects @@ -31,6 +31,7 @@ if [[ ! -e "$solution_out.ninja" ]]; then # Remove some unsupported clang commands. sed -i 's/-fpredictive-commoning//g; s/-fvar-tracking-assignments//g' compile_commands.json sed -i 's|/my_mod/src|.|g' compile_commands.json + sed -i 's|i386|i686|g' "$solution_out.ninja" # Need i686-linux-gnu-g++, not i386-linux-gnu-g++ fi ninja -f "$solution_out.ninja" -j$(nproc) diff --git a/src/common/steamid.cpp b/src/common/steamid.cpp index 0df52bc94c2..c54781e20be 100644 --- a/src/common/steamid.cpp +++ b/src/common/steamid.cpp @@ -524,8 +524,10 @@ bool SteamIDFromSteam2String( const char *pchSteam2ID, EUniverse eUniverse, CSte if ( cExtraCharCheck != 0 || cFieldConverted == EOF || cFieldConverted < 2 || ( cFieldConverted < 3 && steam2ID.m_SteamInstanceID != 1 ) ) return false; +#ifdef SDK_MP // Now convert to steam ID from the Steam2 ID structure *pSteamIDOut = SteamIDFromSteam2UserID( &steam2ID, eUniverse ); +#endif return true; } #endif diff --git a/src/creategameprojects_hl2.bat b/src/creategameprojects_hl2.bat deleted file mode 100644 index bf2c91be62b..00000000000 --- a/src/creategameprojects_hl2.bat +++ /dev/null @@ -1,2 +0,0 @@ -devtools\bin\vpc.exe /hl2 /define:SOURCESDK +game +shaders /mksln games.sln -pause diff --git a/src/createshadersprojects_hl2.bat b/src/createshadersprojects_hl2.bat deleted file mode 100644 index ed7f1e754d0..00000000000 --- a/src/createshadersprojects_hl2.bat +++ /dev/null @@ -1 +0,0 @@ -devtools\bin\vpc.exe /hl2 /episodic /define:SOURCESDK +shaders /mksln shaders.sln diff --git a/src/devtools/sp_gcc9+support.cpp b/src/devtools/sp_gcc9+support.cpp new file mode 100644 index 00000000000..c4f7ea94e4f --- /dev/null +++ b/src/devtools/sp_gcc9+support.cpp @@ -0,0 +1,59 @@ +// compatibility with old ABI (originally by z33ky) +#if __GNUC__ >= 9 +#include + +extern "C" double __pow_finite(double a, double b) +{ + return pow(a, b); +} + +extern "C" double __log_finite(double a) +{ + return log(a); +} + +extern "C" double __exp_finite(double a) +{ + return exp(a); +} + +extern "C" double __atan2_finite(double a, double b) +{ + return atan2(a, b); +} + +extern "C" double __atan2f_finite(double a, double b) +{ + return atan2f(a, b); +} + +extern "C" float __powf_finite(float a, float b) +{ + return powf(a, b); +} + +extern "C" float __logf_finite(float a) +{ + return logf(a); +} + +extern "C" float __expf_finite(float a) +{ + return expf(a); +} + +extern "C" float __acosf_finite(float a) +{ + return acosf(a); +} + +extern "C" double __asin_finite(double a) +{ + return asin(a); +} + +extern "C" double __acos_finite(double a) +{ + return acos(a); +} +#endif diff --git a/src/fgdlib/gdvar.cpp b/src/fgdlib/gdvar.cpp index 80c0d863a4e..09e84273d4c 100644 --- a/src/fgdlib/gdvar.cpp +++ b/src/fgdlib/gdvar.cpp @@ -51,8 +51,10 @@ static TypeMap_t TypeMap[] = { ivVecLine, "vecline", STRING }, { ivPointEntityClass, "pointentityclass", STRING }, { ivNodeDest, "node_dest", INTEGER }, +#ifdef SDK_MP { ivScript, "script", STRING }, { ivScriptList, "scriptlist", STRING }, +#endif { ivInstanceFile, "instance_file", STRING }, { ivAngleNegativePitch, "angle_negative_pitch", STRING }, { ivInstanceVariable, "instance_variable", STRING }, @@ -424,7 +426,8 @@ BOOL GDinputvariable::InitFromTokens(TokenReader& tr) GDError(tr, "no %s specified", m_eType == ivFlags ? "flags" : "choices"); return(FALSE); } - + +#ifdef SDK_MP // For boolean values, we construct it as if it were a choices dialog if ( m_eType == ivBoolean ) { @@ -459,6 +462,7 @@ BOOL GDinputvariable::InitFromTokens(TokenReader& tr) return(FALSE); } } +#endif return(TRUE); } diff --git a/src/fgdlib/inputoutput.cpp b/src/fgdlib/inputoutput.cpp index ea810c1345b..0273bbbcc7f 100644 --- a/src/fgdlib/inputoutput.cpp +++ b/src/fgdlib/inputoutput.cpp @@ -36,7 +36,9 @@ static TypeMap_t TypeMap[] = { iotEHandle, "target_destination" }, { iotColor, "color255" }, { iotEHandle, "ehandle" }, // for backwards compatibility +#ifdef SDK_MP { iotScript, "script" }, +#endif }; diff --git a/src/game/client/c_baseanimating.cpp b/src/game/client/c_baseanimating.cpp index c3f5ec70497..b35355aca66 100644 --- a/src/game/client/c_baseanimating.cpp +++ b/src/game/client/c_baseanimating.cpp @@ -1080,7 +1080,11 @@ void C_BaseAnimating::LockStudioHdr() if ( pNewWrapper->GetVirtualModel() ) { +#ifdef SDK_MP MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); +#else + MDLHandle_t hVirtualModel = (MDLHandle_t)(int)(pStudioHdr->virtualModel)&0xffff; +#endif mdlcache->LockStudioHdr( hVirtualModel ); } @@ -1112,7 +1116,11 @@ void C_BaseAnimating::UnlockStudioHdr() // Immediate-mode rendering, can unlock immediately if ( pStudioHdr->GetVirtualModel() ) { +#ifdef SDK_MP MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() ); +#else + MDLHandle_t hVirtualModel = (MDLHandle_t)(int)pStudioHdr->virtualModel&0xffff; +#endif mdlcache->UnlockStudioHdr( hVirtualModel ); } mdlcache->UnlockStudioHdr( m_hStudioHdr ); @@ -1815,7 +1823,11 @@ void C_BaseAnimating::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quater } // do jiggle physics +#ifdef SDK_MP m_pJiggleBones->BuildJiggleTransformations( i, gpGlobals->realtime, jiggleInfo, goalMX, GetBoneForWrite( i ), this->ShouldFlipViewModel() ); +#else + m_pJiggleBones->BuildJiggleTransformations( i, gpGlobals->realtime, jiggleInfo, goalMX, GetBoneForWrite( i ) ); +#endif } else if (hdr->boneParent(i) == -1) @@ -3547,10 +3559,12 @@ int C_BaseAnimating::DrawModel( int flags ) extraFlags |= STUDIO_GENERATE_STATS; } +#ifdef SDK_MP if ( flags & ( STUDIO_NO_OVERRIDE_FOR_ATTACH ) ) { extraFlags |= STUDIO_NO_OVERRIDE_FOR_ATTACH; } +#endif // Necessary for lighting blending CreateModelInstance(); @@ -6270,12 +6284,14 @@ int C_BaseAnimating::SelectWeightedSequence ( int activity ) } +#ifdef SDK_MP int C_BaseAnimating::SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount ) { Assert( activity != ACT_INVALID ); Assert( GetModelPtr() ); return GetModelPtr()->SelectWeightedSequenceFromModifiers( activity, pActivityModifiers, iModifierCount ); } +#endif //========================================================= //========================================================= diff --git a/src/game/client/c_baseanimating.h b/src/game/client/c_baseanimating.h index 927ebd5875d..6532a8f7d31 100644 --- a/src/game/client/c_baseanimating.h +++ b/src/game/client/c_baseanimating.h @@ -449,7 +449,9 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback // For prediction int SelectWeightedSequence ( int activity ); +#ifdef SDK_MP int SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount ); +#endif void ResetSequenceInfo( void ); float SequenceDuration( void ); float SequenceDuration( CStudioHdr *pStudioHdr, int iSequence ); diff --git a/src/game/client/cdll_client_int.cpp b/src/game/client/cdll_client_int.cpp index 2f836e9e68e..fcd80060c65 100644 --- a/src/game/client/cdll_client_int.cpp +++ b/src/game/client/cdll_client_int.cpp @@ -125,10 +125,14 @@ #include "sourcevr/isourcevirtualreality.h" #include "client_virtualreality.h" #include "mumble.h" +#ifdef SDK_MP #include "steamshare.h" +#endif #include "vgui_controls/BuildGroup.h" +#ifdef SDK_MP #include "secure_command_line.h" +#endif // NVNT includes #include "hud_macros.h" @@ -907,12 +911,14 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi ConnectTier2Libraries( &appSystemFactory, 1 ); ConnectTier3Libraries( &appSystemFactory, 1 ); +#ifdef SDK_MP // Client needs to protect from writing files into random locations to avoid becoming a remote-code // execution platform. if ( g_pFullFileSystem ) { g_pFullFileSystem->SetWriteProtectionEnable( true ); } +#endif #ifndef NO_STEAM ClientSteamContext().Activate(); @@ -1068,7 +1074,9 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi IGameSystem::Add( ClientSoundscapeSystem() ); IGameSystem::Add( PerfVisualBenchmark() ); IGameSystem::Add( MumbleSystem() ); +#ifdef SDK_MP IGameSystem::Add( SteamShareSystem() ); +#endif #if defined( TF_CLIENT_DLL ) IGameSystem::Add( CustomTextureToolCacheGameSystem() ); @@ -1156,6 +1164,7 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi CommandLine()->AppendParm( "+r_hunkalloclightmaps", "0" ); #endif +#ifdef SDK_MP FnUnsafeCmdLineProcessor *pfnUnsafeCmdLineProcessor = #ifndef TF_CLIENT_DLL &UnsafeCmdLineProcessor; @@ -1167,6 +1176,7 @@ int CHLClient::Init( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physi { RegisterSecureLaunchProcessFunc( pfnUnsafeCmdLineProcessor ); } +#endif return true; } diff --git a/src/game/client/cdll_util.cpp b/src/game/client/cdll_util.cpp index f5c24587587..8890d832214 100644 --- a/src/game/client/cdll_util.cpp +++ b/src/game/client/cdll_util.cpp @@ -919,6 +919,7 @@ void UTIL_ReplaceKeyBindings( const wchar_t *inbuf, int inbufsizebytes, OUT_Z_BY char binding[64]; g_pVGuiLocalize->ConvertUnicodeToANSI( token, binding, sizeof(binding) ); +#ifdef SDK_MP // Find a Steam Controller mapping, if an action set was specified and steam controller is active. const char* sc_origin = nullptr; if ( actionset != GAME_ACTION_SET_NONE && g_pInputSystem->IsSteamControllerActive() ) @@ -930,6 +931,7 @@ void UTIL_ReplaceKeyBindings( const wchar_t *inbuf, int inbufsizebytes, OUT_Z_BY sc_origin = pSteamController ? pSteamController->GetStringForActionOrigin( origin ) : ""; } } +#endif // Find also the keyboard mapping const char *key = engine->Key_LookupBinding( *binding == '+' ? binding + 1 : binding ); @@ -961,6 +963,7 @@ void UTIL_ReplaceKeyBindings( const wchar_t *inbuf, int inbufsizebytes, OUT_Z_BY const wchar_t* locName = nullptr; +#ifdef SDK_MP // If we got a Steam Controller key description, use that, otherwise use the (possibly localized) key name CStrAutoEncode sc_origin_encoded( sc_origin ); @@ -969,6 +972,7 @@ void UTIL_ReplaceKeyBindings( const wchar_t *inbuf, int inbufsizebytes, OUT_Z_BY locName = sc_origin_encoded.ToWString(); } else +#endif { locName = g_pVGuiLocalize->Find( friendlyName ); } diff --git a/src/game/client/cdll_util.h b/src/game/client/cdll_util.h index 1950cea9dd7..253671257b1 100644 --- a/src/game/client/cdll_util.h +++ b/src/game/client/cdll_util.h @@ -38,7 +38,11 @@ typedef CGameTrace trace_t; namespace vgui { +#ifdef SDK_MP typedef uint32 HFont; +#else + typedef unsigned long HFont; +#endif }; diff --git a/src/game/client/client_base.vpc b/src/game/client/client_base.vpc index 1ee0d6b8347..68934980d4a 100644 --- a/src/game/client/client_base.vpc +++ b/src/game/client/client_base.vpc @@ -383,7 +383,7 @@ $Project $File "in_camera.cpp" $File "in_joystick.cpp" $File "in_main.cpp" - $File "in_steamcontroller.cpp" + $File "in_steamcontroller.cpp" [$WIN64||$LINUX64] // SDK_MP $File "initializer.cpp" $File "interpolatedvar.cpp" $File "IsNPCProxy.cpp" @@ -456,7 +456,7 @@ $Project $File "spritemodel.cpp" $File "$SRCDIR\game\shared\SpriteTrail.cpp" $File "$SRCDIR\game\shared\studio_shared.cpp" - $File "steamshare.cpp" + $File "steamshare.cpp" [$WIN64||$LINUX64] // SDK_MP $File "studio_stats.cpp" $File "studio_stats.h" $File "$SRCDIR\game\shared\takedamageinfo.cpp" @@ -522,7 +522,7 @@ $Project $File "$SRCDIR\public\haptics\haptic_msgs.cpp" [!$X360] $File "$SRCDIR\public\haptics\haptic_utils.cpp" [$WINDOWS&&!$X360] - $File "$SRCDIR\game\shared\secure_command_line.cpp" + $File "$SRCDIR\game\shared\secure_command_line.cpp" [$WIN64||$LINUX64] // SDK_MP $Folder "Sixense" @@ -562,6 +562,7 @@ $Project "$SRCDIR\public\studio.cpp" \ "$SRCDIR\public\vallocator.cpp" \ "$SRCDIR\public\vgui_controls\vgui_controls.cpp" \ + "$SRCDIR\public\jigglebones.cpp" \ "hud_lcd.cpp" \ "in_mouse.cpp" \ "mumble.cpp" \ @@ -868,7 +869,7 @@ $Project $File "smoke_fog_overlay.h" $File "splinepatch.h" $File "$SRCDIR\public\steam\steam_api.h" - $File "steamshare.h" + $File "steamshare.h" [$WIN64||$LINUX64] // SDK_MP $File "TeamBitmapImage.h" $File "tempent.h" $File "text_message.h" @@ -895,7 +896,7 @@ $Project $File "weapons_resource.h" $File "vgui_video.h" $File "vgui_video_player.h" - $File "$SRCDIR\game\shared\secure_command_line.h" + $File "$SRCDIR\game\shared\secure_command_line.h" [$WIN64||$LINUX64] // SDK_MP } diff --git a/src/game/client/client_episodic.vpc b/src/game/client/client_episodic.vpc index 3c6f20dda54..a469b69674f 100644 --- a/src/game/client/client_episodic.vpc +++ b/src/game/client/client_episodic.vpc @@ -14,7 +14,8 @@ $Configuration { $Compiler { - $AdditionalIncludeDirectories ".\hl2;.\hl2\elements;$SRCDIR\game\shared\hl2;$SRCDIR\game\shared\episodic;..\..\public;$BASE" + $AdditionalIncludeDirectories ".\hl2;.\hl2\elements;$SRCDIR\game\shared\hl2;$SRCDIR\game\shared\episodic;..\..\public;$BASE" [$WIN64||$LINUX64] // SDK_MP + $AdditionalIncludeDirectories ".\hl2;.\hl2\elements;$SRCDIR\game\shared\hl2;$SRCDIR\game\shared\episodic;..\..\public_sp;$BASE" [$WIN32||$LINUX32] // SDK_SP $PreprocessorDefinitions "$BASE;HL2_CLIENT_DLL;HL2_EPISODIC" } } diff --git a/src/game/client/clientmode_shared.cpp b/src/game/client/clientmode_shared.cpp index f80cbc270c8..6567388eea6 100644 --- a/src/game/client/clientmode_shared.cpp +++ b/src/game/client/clientmode_shared.cpp @@ -331,11 +331,13 @@ ClientModeShared::~ClientModeShared() void ClientModeShared::ReloadScheme( bool flushLowLevel ) { +#ifdef SDK_MP // Invalidate the global cache first. if (flushLowLevel) { KeyValuesSystem()->InvalidateCache(); } +#endif BuildGroup::ClearResFileCache(); diff --git a/src/game/client/clientsteamcontext.cpp b/src/game/client/clientsteamcontext.cpp index 62376d18471..76db48baa7f 100644 --- a/src/game/client/clientsteamcontext.cpp +++ b/src/game/client/clientsteamcontext.cpp @@ -64,8 +64,10 @@ void CClientSteamContext::Activate() SteamAPI_SetTryCatchCallbacks( false ); // We don't use exceptions, so tell steam not to use try/catch in callback handlers Init(); // Steam API context init +#ifdef SDK_MP if ( SteamUtils() ) SteamUtils()->InitFilterText(); +#endif UpdateLoggedOnState(); Msg( "CClientSteamContext logged on = %d\n", m_bLoggedOn ); diff --git a/src/game/client/game_controls/SpectatorGUI.cpp b/src/game/client/game_controls/SpectatorGUI.cpp index a575c517cf4..d0f4d4570b3 100644 --- a/src/game/client/game_controls/SpectatorGUI.cpp +++ b/src/game/client/game_controls/SpectatorGUI.cpp @@ -592,6 +592,7 @@ void CSpectatorGUI::ShowPanel(bool bShow) { if ( bShow && !IsVisible() ) { +#ifdef SDK_MP // Josh: Someone made this InvalidateLayout with reloadScheme = true // every time when adding SteamController support, when it should only // have done this if the state changes, because otherwise whenever @@ -611,6 +612,7 @@ void CSpectatorGUI::ShowPanel(bool bShow) InvalidateLayout( true, true ); m_iWasSteamController = bWasSteamController ? 1 : 0; } +#endif m_bSpecScoreboard = false; } @@ -739,11 +741,13 @@ void CSpectatorGUI::Update() //----------------------------------------------------------------------------- const char * CSpectatorGUI::GetResFile( void ) { +#ifdef SDK_MP if ( ::input->IsSteamControllerActive() ) { return "Resource/UI/Spectator_SC.res"; } else +#endif { return "Resource/UI/Spectator.res"; } diff --git a/src/game/client/game_controls/basemodel_panel.cpp b/src/game/client/game_controls/basemodel_panel.cpp index 0fed0085787..79072cfb420 100644 --- a/src/game/client/game_controls/basemodel_panel.cpp +++ b/src/game/client/game_controls/basemodel_panel.cpp @@ -274,7 +274,11 @@ void CBaseModelPanel::SetModelAnim( int iAnim ) if ( iSequence != ACT_INVALID ) { +#ifdef SDK_MP SetSequence( iSequence, true ); +#else + SetSequence( iSequence ); +#endif } } @@ -401,6 +405,7 @@ void CBaseModelPanel::PerformLayout() //----------------------------------------------------------------------------- void CBaseModelPanel::OnTick() { +#ifdef SDK_MP // Cycle stuff gets handled in mdlpanel::OnTick, so we want to fix up // what our sequence is before it gets called. @@ -417,6 +422,7 @@ void CBaseModelPanel::OnTick() SetupModelDefaults(); } } +#endif BaseClass::OnTick(); } @@ -483,8 +489,10 @@ void CBaseModelPanel::OnMousePressed ( vgui::MouseCode code ) EnableMouseCapture( true, code ); +#ifdef SDK_MP // Save where they clicked input()->GetCursorPosition( m_nClickStartX, m_nClickStartY ); +#endif // Warp the mouse to the center of the screen int width, height; @@ -519,8 +527,10 @@ void CBaseModelPanel::OnMouseReleased( vgui::MouseCode code ) EnableMouseCapture( false ); m_bMousePressed = false; +#ifdef SDK_MP // Restore the cursor to where the clicked input()->SetCursorPos( m_nClickStartX, m_nClickStartY ); +#endif } //----------------------------------------------------------------------------- @@ -628,7 +638,11 @@ void CBaseModelPanel::PlaySequence( const char *pszSequenceName ) { m_nActiveSequence = iSeq; m_flActiveSequenceDuration = Studio_Duration( &studioHDR, iSeq, NULL ); +#ifdef SDK_MP SetSequence( m_nActiveSequence, true ); +#else + SetSequence( m_nActiveSequence ); +#endif } } diff --git a/src/game/client/game_controls/basemodel_panel.h b/src/game/client/game_controls/basemodel_panel.h index 438be08e71c..f56ba9a8c07 100644 --- a/src/game/client/game_controls/basemodel_panel.h +++ b/src/game/client/game_controls/basemodel_panel.h @@ -183,7 +183,9 @@ class CBaseModelPanel : public CMDLPanel bool BIsBeingManipulated() const { return m_bMousePressed; } studiohdr_t* GetStudioHdr( void ) { return m_RootMDL.m_MDL.GetStudioHdr(); } +#ifdef SDK_MP CStudioHdr* GetStudioHdrFull( void ) { return m_RootMDL.m_pStudioHdr; } +#endif void SetBody( unsigned int nBody ) { m_RootMDL.m_MDL.m_nBody = nBody; } void RotateYaw( float flDelta ); diff --git a/src/game/client/game_controls/commandmenu.cpp b/src/game/client/game_controls/commandmenu.cpp index 93d5b492154..86ba7092c77 100644 --- a/src/game/client/game_controls/commandmenu.cpp +++ b/src/game/client/game_controls/commandmenu.cpp @@ -62,7 +62,11 @@ void CommandMenu::OnMessage(const KeyValues *params, VPANEL fromPanel) if ( text[0] ) { +#ifdef SDK_MP UIConVarRef convar( g_pVGui->GetVGUIEngine(), text ); +#else + UIConVarRef convar( text ); +#endif if ( convar.IsValid() ) { // toggle cvar @@ -214,7 +218,11 @@ void CommandMenu::UpdateMenu() if ( text[0] ) { // set toggle state equal to cvar state +#ifdef SDK_MP UIConVarRef convar( g_pVGui->GetVGUIEngine(), text ); +#else + UIConVarRef convar( text ); +#endif if ( convar.IsValid() ) { diff --git a/src/game/client/hud_closecaption.cpp b/src/game/client/hud_closecaption.cpp index 5e0d581bfcd..677afcaef8a 100644 --- a/src/game/client/hud_closecaption.cpp +++ b/src/game/client/hud_closecaption.cpp @@ -1672,13 +1672,23 @@ void CHudCloseCaption::CreateFonts( void ) { vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() ); +#ifdef SDK_MP m_hFonts[CCFONT_NORMAL] = pScheme->GetFont( "CloseCaption", true ); +#else + m_hFonts[CCFONT_NORMAL] = pScheme->GetFont( "CloseCaption_Normal" ); +#endif if ( IsPC() ) { +#ifdef SDK_MP m_hFonts[CCFONT_BOLD] = pScheme->GetFont( "CloseCaption_Bold", true ); m_hFonts[CCFONT_ITALIC] = pScheme->GetFont( "CloseCaption_Italic", true ); m_hFonts[CCFONT_ITALICBOLD] = pScheme->GetFont( "CloseCaption_BoldItalic", true ); +#else + m_hFonts[CCFONT_BOLD] = pScheme->GetFont( "CloseCaption_Bold" ); + m_hFonts[CCFONT_ITALIC] = pScheme->GetFont( "CloseCaption_Italic" ); + m_hFonts[CCFONT_ITALICBOLD] = pScheme->GetFont( "CloseCaption_BoldItalic" ); +#endif } else { diff --git a/src/game/client/hud_locator_target.cpp b/src/game/client/hud_locator_target.cpp index f8a63304e7f..38d800dea59 100644 --- a/src/game/client/hud_locator_target.cpp +++ b/src/game/client/hud_locator_target.cpp @@ -2022,8 +2022,14 @@ void CLocatorPanel::DrawTargetCaption( CLocatorTarget *pTarget, int x, int y, bo if ( bDrawGlow ) { vgui::surface()->DrawSetTextFont( m_hCaptionGlowFont ); +#ifdef SDK_MP + color32 glowColor; + UTIL_StringToColor32( &glowColor, locator_text_glow_color.GetString() ); + vgui::surface()->DrawSetTextColor( glowColor.r, glowColor.g, glowColor.b, ( glowColor.a / 255.0f ) * pTarget->m_alpha ); +#else Color glowColor = locator_text_glow_color.GetColor(); vgui::surface()->DrawSetTextColor( glowColor.r(), glowColor.g(), glowColor.b(), ( glowColor.a() / 255.0f ) * pTarget->m_alpha ); +#endif vgui::surface()->DrawSetTextPos( x - 1, y - (fontTall >>1) - 1 ); vgui::surface()->DrawUnicodeString( pTarget->GetCaptionText() ); vgui::surface()->DrawSetTextFont( m_hCaptionFont ); @@ -2052,7 +2058,12 @@ void CLocatorPanel::DrawTargetCaption( CLocatorTarget *pTarget, int x, int y, bo const wchar_t *pString = pTarget->GetCaptionText(); int len = Q_wcslen( pString ); +#ifdef SDK_MP + color32 glowColor; + UTIL_StringToColor32( &glowColor, locator_text_glow_color.GetString() ); +#else Color glowColor = locator_text_glow_color.GetColor(); +#endif for ( int iChar = 0; iChar < len; ++ iChar ) { int charW = vgui::surface()->GetCharacterWidth( m_hCaptionFont, pString[ iChar ] ); @@ -2068,7 +2079,11 @@ void CLocatorPanel::DrawTargetCaption( CLocatorTarget *pTarget, int x, int y, bo if ( bDrawGlow ) { vgui::surface()->DrawSetTextFont( m_hCaptionGlowFont ); +#ifdef SDK_MP + vgui::surface()->DrawSetTextColor( glowColor.r, glowColor.g, glowColor.b, ( glowColor.a / 255.0f ) * pTarget->m_alpha ); +#else vgui::surface()->DrawSetTextColor( glowColor.r(), glowColor.g(), glowColor.b(), ( glowColor.a() / 255.0f ) * pTarget->m_alpha ); +#endif vgui::surface()->DrawSetTextPos( charX - 1, charY ); vgui::surface()->DrawUnicodeChar( pString[iChar] ); vgui::surface()->DrawSetTextFont( m_hCaptionFont ); diff --git a/src/game/client/iinput.h b/src/game/client/iinput.h index bb4751200b0..39123755e68 100644 --- a/src/game/client/iinput.h +++ b/src/game/client/iinput.h @@ -97,9 +97,11 @@ abstract_class IInput virtual bool CAM_IsOrthographic() const = 0; virtual void CAM_OrthographicSize( float& w, float& h ) const = 0; +#ifdef SDK_MP virtual void SetPreferredGameActionSet( GameActionSet_t action_set ) = 0; virtual GameActionSet_t GetPreferredGameActionSet() = 0; virtual void SetGameActionSetFlags( GameActionSetFlags_t action_set_flags ) = 0; +#endif #if defined( HL2_CLIENT_DLL ) // IK back channel info @@ -116,7 +118,11 @@ abstract_class IInput virtual bool EnableJoystickMode() = 0; +#ifdef SDK_MP virtual bool IsSteamControllerActive() = 0; +#else + FORCEINLINE bool IsSteamControllerActive() { return false; } +#endif }; extern ::IInput *input; diff --git a/src/game/client/imessagechars.h b/src/game/client/imessagechars.h index 43b73792bed..20135063523 100644 --- a/src/game/client/imessagechars.h +++ b/src/game/client/imessagechars.h @@ -21,7 +21,6 @@ namespace vgui { class Panel; -typedef uint32 HFont; } abstract_class IMessageChars diff --git a/src/game/client/in_main.cpp b/src/game/client/in_main.cpp index e94463c58ca..a392085ac61 100644 --- a/src/game/client/in_main.cpp +++ b/src/game/client/in_main.cpp @@ -314,8 +314,10 @@ CInput::CInput( void ) m_pCommands = NULL; m_pCameraThirdData = NULL; m_pVerifiedCommands = NULL; +#ifdef SDK_MP m_PreferredGameActionSet = GAME_ACTION_SET_MENUCONTROLS; m_bSteamControllerGameActionsInitialized = false; +#endif } //----------------------------------------------------------------------------- @@ -950,7 +952,9 @@ void CInput::ControllerMove( float frametime, CUserCmd *cmd ) } } +#ifdef SDK_MP SteamControllerMove( frametime, cmd ); +#endif JoyStickMove( frametime, cmd ); // NVNT if we have a haptic device.. @@ -1684,8 +1688,10 @@ void CInput::Init_All (void) // Initialize third person camera controls. Init_Camera(); +#ifdef SDK_MP // Initialize steam controller action sets m_bSteamControllerGameActionsInitialized = InitializeSteamControllerGameActionSets(); +#endif } /* diff --git a/src/game/client/input.h b/src/game/client/input.h index 28c7a704f4a..dadaa26b099 100644 --- a/src/game/client/input.h +++ b/src/game/client/input.h @@ -114,6 +114,7 @@ class CInput : public IInput virtual bool EnableJoystickMode(); +#ifdef SDK_MP // SteamController bool InitializeSteamControllerGameActionSets(); Vector2D ScaleSteamControllerLook( Vector2D vecPosition ); @@ -127,6 +128,7 @@ class CInput : public IInput virtual void SetGameActionSetFlags( GameActionSetFlags_t action_set_flags ); virtual bool IsSteamControllerActive(); +#endif // Private Implementation protected: @@ -158,7 +160,9 @@ class CInput : public IInput void JoyStickMove ( float frametime, CUserCmd *cmd ); float ScaleAxisValue( const float axisValue, const float axisThreshold ); virtual float JoyStickAdjustYaw( float flSpeed ) { return flSpeed; } +#ifdef SDK_MP virtual void SteamControllerMove( float frametime, CUserCmd *cmd ); +#endif // Call this to get the cursor position. The call will be logged in the VCR file if there is one. void GetMousePos(int &x, int &y); @@ -272,11 +276,13 @@ class CInput : public IInput // Steam controller stuff int m_nControllerType[MAX_JOYSTICKS + MAX_STEAM_CONTROLLERS]; +#ifdef SDK_MP GameActionSet_t m_PreferredGameActionSet; GameActionSetFlags_t m_GameActionSetFlags; bool m_bSteamControllerGameActionsInitialized; bool m_bSteamControllerSeenInput = false; +#endif class CVerifiedUserCmd { diff --git a/src/game/client/particlemgr.cpp b/src/game/client/particlemgr.cpp index 5376f4d8053..8efc96d1f07 100644 --- a/src/game/client/particlemgr.cpp +++ b/src/game/client/particlemgr.cpp @@ -1782,7 +1782,8 @@ void CParticleMgr::BuildParticleSimList( CUtlVector< ParticleSimListEntry_t > &l { g_nNumParticlesSimulated += pNewEffect->m_nActiveParticles; } - + +#ifdef SDK_MP // Particles that are attached to moving things will need to update their bboxes even if they // otherwise would like to skip the updates. Check that here. if (bSkip) @@ -1790,6 +1791,7 @@ void CParticleMgr::BuildParticleSimList( CUtlVector< ParticleSimListEntry_t > &l bNeedsBboxUpdate = pNewEffect->HasMoved(); bSkip = !bNeedsBboxUpdate; } +#endif if (!bSkip) { diff --git a/src/game/client/vgui_centerstringpanel.cpp b/src/game/client/vgui_centerstringpanel.cpp index 13057cc17db..f1a1c3a0bc5 100644 --- a/src/game/client/vgui_centerstringpanel.cpp +++ b/src/game/client/vgui_centerstringpanel.cpp @@ -123,7 +123,11 @@ void CCenterStringLabel::ApplySchemeSettings(vgui::IScheme *pScheme) BaseClass::ApplySchemeSettings(pScheme); // Use a large font +#ifdef SDK_MP m_hFont = pScheme->GetFont( "Trebuchet24", true ); +#else + m_hFont = pScheme->GetFont( "Trebuchet24" ); +#endif assert( m_hFont ); SetFont( m_hFont ); diff --git a/src/game/client/vgui_fpspanel.cpp b/src/game/client/vgui_fpspanel.cpp index f67b131be47..8254db0e9c2 100644 --- a/src/game/client/vgui_fpspanel.cpp +++ b/src/game/client/vgui_fpspanel.cpp @@ -299,6 +299,7 @@ void CFPSPanel::Paint() g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2, ucColor[0], ucColor[1], ucColor[2], 255, "%3i fps on %s", nFps, pszMapName ); } +#ifdef SDK_MP const CPUFrequencyResults frequency = GetCPUFrequencyResults(); double currentTime = Plat_FloatTime(); const double displayTime = 5.0f; // Display frequency results for this long. @@ -309,6 +310,7 @@ void CFPSPanel::Paint() GetCPUColor( frequency.m_percentage, ucColor ); g_pMatSystemSurface->DrawColoredText( m_hFont, x, lineHeight + 2, ucColor[0], ucColor[1], ucColor[2], 255, "CPU frequency percent: %3.1f%% Min percent: %3.1f%%", frequency.m_percentage, frequency.m_lowestPercentage ); } +#endif } } m_lastRealTime = gpGlobals->realtime; diff --git a/src/game/client/vgui_int.cpp b/src/game/client/vgui_int.cpp index 8fb97d5f2fc..7d79ac2d4d5 100644 --- a/src/game/client/vgui_int.cpp +++ b/src/game/client/vgui_int.cpp @@ -268,7 +268,11 @@ void VGui_PreRender() bool bShowPausedImage = !enginevgui->IsGameUIVisible() && cl_showpausedimage.GetBool() && engine->IsPaused() && !engine->IsTakingScreenshot() && !engine->IsPlayingDemo(); #if !defined( TF_CLIENT_DLL ) +#ifdef SDK_MP loadingdisc->SetPausedVisible( bShowPausedImage, engine->GetPausedExpireTime() ); +#else + loadingdisc->SetPausedVisible( bShowPausedImage ); +#endif #else bShowPausedImage &= ( TFGameRules() && !TFGameRules()->IsInTraining() ); loadingdisc->SetPausedVisible( bShowPausedImage, engine->GetPausedExpireTime() ); diff --git a/src/game/client/vgui_netgraphpanel.cpp b/src/game/client/vgui_netgraphpanel.cpp index 8723254e3c7..75ad8a6ef58 100644 --- a/src/game/client/vgui_netgraphpanel.cpp +++ b/src/game/client/vgui_netgraphpanel.cpp @@ -885,6 +885,7 @@ void CNetGraphPanel::DrawTextFields( int graphvalue, int x, int y, int w, netban g_pMatSystemSurface->DrawColoredText( m_hFontSmall, x, y, 0, 0, 128, 255, "voice" ); y -= textTall; } +#ifdef SDK_MP else { const CPUFrequencyResults frequency = GetCPUFrequencyResults(); @@ -914,6 +915,7 @@ void CNetGraphPanel::DrawTextFields( int graphvalue, int x, int y, int w, netban "CPU freq: %3.1f%% Min: %3.1f%%", frequency.m_percentage, frequency.m_lowestPercentage ); } } +#endif } //----------------------------------------------------------------------------- diff --git a/src/game/client/view.cpp b/src/game/client/view.cpp index e84101c83cc..c6fec2346db 100644 --- a/src/game/client/view.cpp +++ b/src/game/client/view.cpp @@ -108,7 +108,11 @@ static ConVar v_centerspeed( "v_centerspeed","500" ); #if defined(TF_CLIENT_DLL) || defined(MAPBASE) // 54 degrees approximates a 35mm camera - we determined that this makes the viewmodels // and motions look the most natural. +#ifdef SDK_MP ConVar v_viewmodel_fov( "viewmodel_fov", "54", FCVAR_ARCHIVE, "Sets the field-of-view for the viewmodel.", true, 0.1, true, 179.9, true, 54, true, 70, NULL ); +#else +ConVar v_viewmodel_fov( "viewmodel_fov", "54", FCVAR_ARCHIVE ); +#endif ConVar v_viewmodel_fov_script_override( "viewmodel_fov_script_override", "0", FCVAR_NONE, "If nonzero, overrides the viewmodel FOV of weapon scripts which override the viewmodel FOV." ); #else ConVar v_viewmodel_fov( "viewmodel_fov", "54", FCVAR_CHEAT, "Sets the field-of-view for the viewmodel.", true, 0.1, true, 179.9 ); diff --git a/src/game/client/worldlight.cpp b/src/game/client/worldlight.cpp index fa484a1a836..63e5f3ca143 100644 --- a/src/game/client/worldlight.cpp +++ b/src/game/client/worldlight.cpp @@ -179,11 +179,13 @@ void CWorldLights::LevelInitPreEntity() // then the BSP format changed and we're unaware int lumpsize = lightLump.filelen; +#ifdef SDK_MP // account for compressed BSPs if ( lightLump.uncompressedSize > 0 ) { lumpsize = lightLump.uncompressedSize; } +#endif if( lumpsize % sizeof(dworldlight_t) ) { @@ -200,6 +202,7 @@ void CWorldLights::LevelInitPreEntity() m_nWorldLights = lumpsize / sizeof(dworldlight_t); m_pWorldLights = new dworldlight_t[m_nWorldLights]; +#ifdef SDK_MP // Read worldlights then close if ( lightLump.uncompressedSize > 0 ) { @@ -210,6 +213,7 @@ void CWorldLights::LevelInitPreEntity() delete[] worldlights; } else +#endif { g_pFullFileSystem->Read( m_pWorldLights, lightLump.filelen, hFile ); } diff --git a/src/game/protobuf_include.vpc b/src/game/protobuf_include.vpc index 72d456a0789..284fd30ea70 100644 --- a/src/game/protobuf_include.vpc +++ b/src/game/protobuf_include.vpc @@ -13,6 +13,7 @@ $Project $Libexternal $SRCDIR\thirdparty\protobuf-2.6.1\bin\osx32\libc++\libprotobuf [$OSX32] $Libexternal $SRCDIR\thirdparty\protobuf-2.6.1\bin\linux32\libprotobuf [$LINUX32] $Libexternal $SRCDIR\thirdparty\protobuf-2.6.1\bin\linux64\libprotobuf [$LINUX64] + $Libexternal libprotobuf [$WIN32] } $Folder "Link Libraries" diff --git a/src/game/server/ai_baseactor.cpp b/src/game/server/ai_baseactor.cpp index df0a5aaa4b4..08578d047e0 100644 --- a/src/game/server/ai_baseactor.cpp +++ b/src/game/server/ai_baseactor.cpp @@ -254,7 +254,11 @@ bool CAI_BaseActor::StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, { case CChoreoEvent::FACE: { +#ifdef MAPBASE + return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget, pSceneEnt ); +#else return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget ); +#endif } break; @@ -432,14 +436,22 @@ bool CAI_BaseActor::StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, #endif else { +#ifdef MAPBASE + return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget, pSceneEnt ); +#else return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget ); +#endif } return true; } break; default: +#ifdef MAPBASE + return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget, pSceneEnt ); +#else return BaseClass::StartSceneEvent( info, scene, event, actor, pTarget ); +#endif } } diff --git a/src/game/server/baseanimating.cpp b/src/game/server/baseanimating.cpp index 317b0df2222..cdc340564ad 100644 --- a/src/game/server/baseanimating.cpp +++ b/src/game/server/baseanimating.cpp @@ -842,12 +842,14 @@ int CBaseAnimating::SelectWeightedSequence ( Activity activity, int curSequence return ::SelectWeightedSequence( GetModelPtr(), activity, curSequence ); } +#ifdef SDK_MP int CBaseAnimating::SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount ) { Assert( activity != ACT_INVALID ); AssertMsg( GetModelPtr(), "GetModelPtr NULL. %s", STRING(GetEntityName()) ? STRING(GetEntityName()) : "" ); return GetModelPtr()->SelectWeightedSequenceFromModifiers( activity, pActivityModifiers, iModifierCount ); } +#endif //========================================================= // ResetActivityIndexes @@ -2934,7 +2936,11 @@ void CBaseAnimating::LockStudioHdr() if ( pStudioHdrContainer && pStudioHdrContainer->GetVirtualModel() ) { +#ifdef SDK_MP MDLHandle_t hVirtualModel = VoidPtrToMDLHandle(pStudioHdrContainer->GetRenderHdr()->VirtualModel()); +#else + MDLHandle_t hVirtualModel = (MDLHandle_t)(int)(pStudioHdrContainer->GetRenderHdr()->virtualModel)&0xffff; +#endif mdlcache->LockStudioHdr( hVirtualModel ); } m_pStudioHdr = pStudioHdrContainer; // must be last to ensure virtual model correctly set up @@ -2952,7 +2958,11 @@ void CBaseAnimating::UnlockStudioHdr() mdlcache->UnlockStudioHdr( modelinfo->GetCacheHandle( mdl ) ); if ( m_pStudioHdr->GetVirtualModel() ) { +#ifdef SDK_MP MDLHandle_t hVirtualModel = VoidPtrToMDLHandle(m_pStudioHdr->GetRenderHdr()->VirtualModel()); +#else + MDLHandle_t hVirtualModel = (MDLHandle_t)(int)(m_pStudioHdr->GetRenderHdr()->virtualModel)&0xffff; +#endif mdlcache->UnlockStudioHdr( hVirtualModel ); } } diff --git a/src/game/server/baseanimating.h b/src/game/server/baseanimating.h index 0b74bd3f401..ff981048636 100644 --- a/src/game/server/baseanimating.h +++ b/src/game/server/baseanimating.h @@ -120,7 +120,9 @@ class CBaseAnimating : public CBaseEntity void ResetEventIndexes ( void ); int SelectWeightedSequence ( Activity activity ); int SelectWeightedSequence ( Activity activity, int curSequence ); +#ifdef SDK_MP int SelectWeightedSequenceFromModifiers( Activity activity, CUtlSymbol *pActivityModifiers, int iModifierCount ); +#endif int SelectHeaviestSequence ( Activity activity ); int LookupActivity( const char *label ); int LookupSequence ( const char *label ); diff --git a/src/game/server/baseentity.h b/src/game/server/baseentity.h index 8c039cd9b1d..00248ee29c7 100644 --- a/src/game/server/baseentity.h +++ b/src/game/server/baseentity.h @@ -1352,7 +1352,11 @@ class CBaseEntity : public IServerEntity #define ENTITYFUNCPTR_SIZE 8 #endif #else // PLATFORM_64BITS - #define ENTITYFUNCPTR_SIZE 4 + #if defined( COMPILER_GCC ) || defined( GNUC ) + #define ENTITYFUNCPTR_SIZE 8 + #else + #define ENTITYFUNCPTR_SIZE 4 + #endif #endif // !PLATFORM_64BITS void FunctionCheck( void *pFunction, const char *name ); diff --git a/src/game/server/entity_tools_server.cpp b/src/game/server/entity_tools_server.cpp index d3c599596af..a49e1251972 100644 --- a/src/game/server/entity_tools_server.cpp +++ b/src/game/server/entity_tools_server.cpp @@ -91,11 +91,17 @@ static CServerTools g_ServerTools; // VSERVERTOOLS_INTERFACE_VERSION_1 is compatible with the latest since we're only adding things to the end, so expose that as well. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CServerTools, IServerTools001, VSERVERTOOLS_INTERFACE_VERSION_1, g_ServerTools ); +#ifdef SDK_MP EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CServerTools, IServerTools002, VSERVERTOOLS_INTERFACE_VERSION_2, g_ServerTools ); +#endif EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CServerTools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION, g_ServerTools ); // When bumping the version to this interface, check that our assumption is still valid and expose the older version in the same way +#ifdef SDK_MP COMPILE_TIME_ASSERT( VSERVERTOOLS_INTERFACE_VERSION_INT == 3 ); +#else +COMPILE_TIME_ASSERT( VSERVERTOOLS_INTERFACE_VERSION_INT == 2 ); +#endif IServerEntity *CServerTools::GetIServerEntity( IClientEntity *pClientEntity ) diff --git a/src/game/server/gameinterface.cpp b/src/game/server/gameinterface.cpp index b5fc3eaf9ab..76c75b9fd30 100644 --- a/src/game/server/gameinterface.cpp +++ b/src/game/server/gameinterface.cpp @@ -574,7 +574,11 @@ CServerGameDLL g_ServerGameDLL; EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CServerGameDLL, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL, g_ServerGameDLL); // When bumping the version to this interface, check that our assumption is still valid and expose the older version in the same way +#ifdef SDK_MP COMPILE_TIME_ASSERT( INTERFACEVERSION_SERVERGAMEDLL_INT == 12 ); +#else +COMPILE_TIME_ASSERT( INTERFACEVERSION_SERVERGAMEDLL_INT == 9 ); +#endif bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn fileSystemFactory, @@ -1429,11 +1433,13 @@ void CServerGameDLL::LevelShutdown( void ) // In case we quit out during initial load CBaseEntity::SetAllowPrecache( false ); +#ifdef SDK_MP // Josh: Uncache all the particle systems on level shutdown // otherwise we leak them constantly on changelevel in the // particle precache stringtable list. g_pParticleSystemMgr->UncacheAllParticleSystems(); g_pParticleSystemMgr->RecreateDictionary(); +#endif g_nCurrentChapterIndex = -1; @@ -2047,6 +2053,7 @@ const char *CServerGameDLL::GetServerBrowserGameData() return rchResult; } +#ifdef SDK_MP //----------------------------------------------------------------------------- void CServerGameDLL::Status( void (*print) (const char *fmt, ...) ) { @@ -2110,6 +2117,7 @@ bool CServerGameDLL::GetWorkshopMap( uint32 uIndex, WorkshopMapDesc_t *pDesc ) #endif // TF_DLL return false; } +#endif //----------------------------------------------------------------------------- // Purpose: Called during a transition, to build a map adjacency list @@ -2835,7 +2843,9 @@ void CServerGameEnts::CheckTransmit( CCheckTransmitInfo *pInfo, const unsigned s CServerGameClients g_ServerGameClients; // INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_3 is compatible with the latest since we're only adding things to the end, so expose that as well. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CServerGameClients, IServerGameClients003, INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_3, g_ServerGameClients ); +#ifdef SDK_MP EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CServerGameClients, IServerGameClients004, INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_4, g_ServerGameClients ); +#endif EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CServerGameClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS, g_ServerGameClients ); @@ -3367,6 +3377,7 @@ void CServerGameClients::GetBugReportInfo( char *buf, int buflen ) } } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: A player sent a voice packet //----------------------------------------------------------------------------- @@ -3381,6 +3392,7 @@ void CServerGameClients::ClientVoice( edict_t *pEdict ) PlayerVoiceListener().AddPlayerSpeakTime( pPlayer ); } } +#endif //----------------------------------------------------------------------------- // Purpose: A user has had their network id setup and validated diff --git a/src/game/server/gameinterface.h b/src/game/server/gameinterface.h index c153bd07e29..5c94d38ab62 100644 --- a/src/game/server/gameinterface.h +++ b/src/game/server/gameinterface.h @@ -58,7 +58,9 @@ class CServerGameClients : public IServerGameClients // Notify that the player is spawned virtual void ClientSpawned( edict_t *pPlayer ) OVERRIDE; +#ifdef SDK_MP virtual void ClientVoice( edict_t* pEdict ) OVERRIDE; +#endif }; @@ -140,6 +142,7 @@ class CServerGameDLL : public IServerGameDLL virtual const char *GetServerBrowserMapOverride() OVERRIDE; virtual const char *GetServerBrowserGameData() OVERRIDE; +#ifdef SDK_MP // Called to add output to the status command virtual void Status( void (*print) (const char *fmt, ...) ) OVERRIDE; @@ -156,6 +159,7 @@ class CServerGameDLL : public IServerGameDLL virtual bool IsManualMapChangeOkay( const char **pszReason ) OVERRIDE; virtual bool GetWorkshopMap( uint32 uIndex, WorkshopMapDesc_t *pDesc ) OVERRIDE; +#endif private: diff --git a/src/game/server/hl2/npc_combinedropship.cpp b/src/game/server/hl2/npc_combinedropship.cpp index 2051143f609..bcbee14943b 100644 --- a/src/game/server/hl2/npc_combinedropship.cpp +++ b/src/game/server/hl2/npc_combinedropship.cpp @@ -921,6 +921,9 @@ CNPC_CombineDropship::~CNPC_CombineDropship(void) void CNPC_CombineDropship::Spawn( void ) { Precache( ); +#ifdef MAPBASE + SetModel( DefaultOrCustomModel( "models/combine_dropship.mdl" ) ); +#endif #ifdef _XBOX AddEffects( EF_NOSHADOW ); @@ -1108,9 +1111,11 @@ void CNPC_CombineDropship::Spawn( void ) break; } +#ifndef MAPBASE // We have our own fix for this (for now) // moving this after we've created m_hContainer so we can properly setup the // weapon_pitch and weapon_yaw pose parameter indexes in PopulatePoseParameters() SetModel( DefaultOrCustomModel( "models/combine_dropship.mdl" ) ); +#endif // Setup our bbox if ( m_hContainer ) diff --git a/src/game/server/hl2/weapon_physcannon.cpp b/src/game/server/hl2/weapon_physcannon.cpp index c2a3c4ca3d3..6aec0d088cf 100644 --- a/src/game/server/hl2/weapon_physcannon.cpp +++ b/src/game/server/hl2/weapon_physcannon.cpp @@ -4733,7 +4733,11 @@ CBaseEntity *PhysCannonGetHeldEntity( CBaseCombatWeapon *pActiveWeapon ) CBaseEntity *GetPlayerHeldEntity( CBasePlayer *pPlayer ) { CBaseEntity *pObject = NULL; +#ifdef MAPBASE + CPlayerPickupController *pPlayerPickupController = dynamic_cast(pPlayer->GetUseEntity()); +#else CPlayerPickupController *pPlayerPickupController = (CPlayerPickupController *)(pPlayer->GetUseEntity()); +#endif if ( pPlayerPickupController ) { diff --git a/src/game/server/logic_eventlistener.cpp b/src/game/server/logic_eventlistener.cpp index 59bbbcc5402..a9274a7aa1a 100644 --- a/src/game/server/logic_eventlistener.cpp +++ b/src/game/server/logic_eventlistener.cpp @@ -32,6 +32,7 @@ DEFINE_OUTPUT( m_OnEventFired, "OnEventFired" ), END_DATADESC() +#ifdef SDK_MP class CScriptEventTableWriter : public IGameEventVisitor2 { public: @@ -70,6 +71,7 @@ class CScriptEventTableWriter : public IGameEventVisitor2 IScriptVM* mVM; HSCRIPT mTable; }; +#endif //----------------------------------------------------------------------------- // Purpose: Spawn @@ -118,8 +120,12 @@ void CLogicEventListener::FireGameEvent( IGameEvent *event ) ScriptVariant_t table; vm->CreateTable( table ); { +#ifdef SDK_MP CScriptEventTableWriter tableWriter( vm, table ); event->ForEventData( &tableWriter ); +#else + Warning( "CLogicEventListener vscript not supported in SP branch at the moment\n" ); +#endif } vm->SetValue( entityTable, "event_data", table ); vm->ReleaseValue( table ); diff --git a/src/game/server/particle_system.cpp b/src/game/server/particle_system.cpp index 5680cc67c07..7f4c7d942de 100644 --- a/src/game/server/particle_system.cpp +++ b/src/game/server/particle_system.cpp @@ -275,6 +275,7 @@ void CParticleSystem::ReadControlPointEnts( void ) const char* pszVector = STRING(m_iszControlPointNames[i]); UTIL_StringToVector(vecCoords.Base(), pszVector); m_vControlPointVecs.Set(i, vecCoords); + m_bUsesCoordinates = true; } else { @@ -290,7 +291,6 @@ void CParticleSystem::ReadControlPointEnts( void ) } m_hControlPointEnts.Set( i, pPointEnt ); - m_bUsesCoordinates = true; } } } diff --git a/src/game/server/player_command.cpp b/src/game/server/player_command.cpp index 261d6b45481..e799e93bfff 100644 --- a/src/game/server/player_command.cpp +++ b/src/game/server/player_command.cpp @@ -346,7 +346,7 @@ void CPlayerMove::RunCommand ( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper } const float playerCurTime = player->m_nTickBase * TICK_INTERVAL; - const float playerFrameTime = TICK_INTERVAL; + const float playerFrameTime = player->m_bGamePaused ? 0 : TICK_INTERVAL; StartCommand( player, ucmd ); diff --git a/src/game/server/vote_controller.cpp b/src/game/server/vote_controller.cpp index 9d4b3acecd2..127fb73de56 100644 --- a/src/game/server/vote_controller.cpp +++ b/src/game/server/vote_controller.cpp @@ -150,11 +150,13 @@ class CVoteControllerSystem : public CAutoGameSystemPerFrame m_mapNameLockedList.RemoveAt( i ); break; } +#ifdef SDK_MP // See if they reconnected else if ( pPlayer && !engine->IsPlayerNameLocked( pPlayer->edict() ) ) { engine->ServerCommand( UTIL_VarArgs( "namelockid %d %d\n", pPlayer->GetUserID(), 1 ) ); } +#endif } m_flNextNameLockCheckTime = gpGlobals->curtime + 1.f; diff --git a/src/game/server/vscript_server.cpp b/src/game/server/vscript_server.cpp index 36e0c268d00..c1571129404 100644 --- a/src/game/server/vscript_server.cpp +++ b/src/game/server/vscript_server.cpp @@ -495,7 +495,9 @@ void CScrollingScreenOverlay::Draw() { if ( developer.GetBool() ) { +#ifdef SDK_MP int line = m_iFirstLine; +#endif int i; int alpha; float age; @@ -514,6 +516,7 @@ void CScrollingScreenOverlay::Draw() } } +#ifdef SDK_MP // TODO: Consider adapting CFmtStrN<1024> msg; float msgTime; for ( int i = m_Text.Head(); i != m_Text.InvalidIndex(); i = m_Text.Next( i ) ) @@ -532,6 +535,7 @@ void CScrollingScreenOverlay::Draw() msg.sprintf( "(%0.2f): %s", msgTime, m_Text[i].m_text.operator const char *() ); NDebugOverlay::ScreenTextLine( m_x, m_y, line++, msg, m_Text[i].m_r, m_Text[i].m_g, m_Text[i].m_b, alpha, NDEBUG_PERSIST_TILL_NEXT_SERVER ); } +#endif } } @@ -801,8 +805,10 @@ void CVScriptGameEventListener::Init() void CVScriptGameEventListener::FireGameEvent( IGameEvent *event ) { // Pass all keyvales as a table of parameters +#ifdef SDK_MP // TODO HSCRIPT paramsTable = ScriptTableFromKeyValues( g_pScriptVM, event->GetDataKeys() ); RunGameEventCallbacks( event->GetName(), paramsTable ); +#endif } void CVScriptGameEventListener::ListenForScriptHook( const char* szName ) @@ -1319,7 +1325,9 @@ bool ScriptSendGlobalGameEvent( const char *szName, HSCRIPT params ) case FIELD_FLOAT: event->SetFloat ( pszKeyName, (float)vValue ); break; case FIELD_INTEGER: event->SetInt ( pszKeyName, (int)vValue ); break; case FIELD_CSTRING: event->SetString( pszKeyName, (const char *)vValue ); break; +#ifdef SDK_MP case FIELD_UINT64: event->SetUint64( pszKeyName, (uint64)vValue ); break; +#endif default: { Log_Msg( LOG_VScript, "VSCRIPT: ScriptSendRealGameEvent: Don't understand FIELD_TYPE of value for key %s.", pszKeyName ); @@ -2768,7 +2776,9 @@ bool VScriptServerInit() ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetPlayerFromUserID, "GetPlayerFromUserID", "Given a user id, return the entity, or null"); ScriptRegisterFunctionNamed( g_pScriptVM, Script_IsPlayerABot, "IsPlayerABot", "Is this player/entity a bot"); +#ifdef SDK_MP ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::ScreenTextLine, "DebugDrawScreenTextLine", "Draw text with a line offset" ); +#endif ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Text, "DebugDrawText", "Draw text in 3d (origin, text, bViewCheck, duration)" ); ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Box, "DebugDrawBox", "Draw a debug overlay box" ); ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Line, "DebugDrawLine", "Draw a debug overlay line" ); diff --git a/src/game/shared/GameStats.cpp b/src/game/shared/GameStats.cpp index c40002119b0..1b2b06b30cb 100644 --- a/src/game/shared/GameStats.cpp +++ b/src/game/shared/GameStats.cpp @@ -1181,7 +1181,9 @@ bool CBaseGameStats_Driver::AddBaseDataForSend( KeyValues *pKV, StatSendType_t s int mapTime = gpGlobals->realtime - m_flLevelStartTime; pKV->SetInt( "MapTime", mapTime ); +#ifdef SDK_MP pKV->SetBool( "SteamControllerActive", g_pInputSystem->IsSteamControllerActive() ); +#endif AddLoadTimeMainMenu(pKV); AddLoadTimeMap(pKV); @@ -1227,7 +1229,8 @@ void CBaseGameStats_Driver::ResetData() pKV->SetUint64( "CPUFeatures1", cpu.m_nFeatures[ 1 ] ); pKV->SetUint64( "CPUFeatures2", cpu.m_nFeatures[ 2 ] ); pKV->SetInt( "NumCores", cpu.m_nPhysicalProcessors ); - + +#ifdef SDK_MP // Capture memory stats as well. MemoryInformation memInfo; if ( GetMemoryInformation( &memInfo ) ) @@ -1237,6 +1240,7 @@ void CBaseGameStats_Driver::ResetData() pKV->SetInt( "VirtualRamMbTotal", memInfo.m_nVirtualRamMbTotal ); pKV->SetInt( "VirtualRamMbAvailable", memInfo.m_nVirtualRamMbAvailable ); } +#endif MaterialAdapterInfo_t gpu; materials->GetDisplayAdapterInfo( materials->GetCurrentAdapter(), gpu ); diff --git a/src/game/shared/ModelSoundsCache.cpp b/src/game/shared/ModelSoundsCache.cpp index 86154fe8a1b..e0f72562f1a 100644 --- a/src/game/shared/ModelSoundsCache.cpp +++ b/src/game/shared/ModelSoundsCache.cpp @@ -68,7 +68,7 @@ void CModelSoundsCache::Restore( CUtlBuffer& buf ) { char soundname[ 512 ]; - buf.GetString( soundname ); + buf.GetString( soundname, sizeof( soundname ) ); int idx = soundemitterbase->GetSoundIndex( soundname ); if ( idx != -1 ) diff --git a/src/game/shared/SoundEmitterSystem.cpp b/src/game/shared/SoundEmitterSystem.cpp index 0dc0c7e044b..b36f836b2e0 100644 --- a/src/game/shared/SoundEmitterSystem.cpp +++ b/src/game/shared/SoundEmitterSystem.cpp @@ -362,6 +362,7 @@ class CSoundEmitterSystem : public CBaseGameSystem #endif } +#ifdef SDK_MP void Flush() { Assert( soundemitterbase ); @@ -370,6 +371,7 @@ class CSoundEmitterSystem : public CBaseGameSystem #endif soundemitterbase->Flush(); } +#endif void InternalPrecacheWaves( int soundIndex ) { @@ -1016,9 +1018,18 @@ void S_SoundEmitterSystemFlush( void ) return; #endif +#ifdef SDK_MP // save the current soundscape // kill the system g_SoundEmitterSystem.Flush(); +#else + // save the current soundscape + // kill the system + g_SoundEmitterSystem.Shutdown(); + + // restart the system + g_SoundEmitterSystem.Init(); +#endif #if !defined( CLIENT_DLL ) // Redo precache all wave files... (this should work now that we have dynamic string tables) diff --git a/src/game/shared/achievementmgr.cpp b/src/game/shared/achievementmgr.cpp index d36af88a0db..cdc5c6671a4 100644 --- a/src/game/shared/achievementmgr.cpp +++ b/src/game/shared/achievementmgr.cpp @@ -126,8 +126,13 @@ static void WriteAchievementGlobalState( KeyValues *pKV, bool bPersistToSteamClo if (pRemoteStorage) { +#ifdef SDK_MP uint64 availableBytes = 0; uint64 totalBytes = 0; +#else + int32 availableBytes = 0; + int32 totalBytes = 0; +#endif if ( pRemoteStorage->GetQuota( &totalBytes, &availableBytes ) ) { if ( totalBytes > 0 ) diff --git a/src/game/shared/animation.cpp b/src/game/shared/animation.cpp index 4f87205754f..726c9ae18bf 100644 --- a/src/game/shared/animation.cpp +++ b/src/game/shared/animation.cpp @@ -336,6 +336,7 @@ int CStudioHdr::CActivityToSequenceMapping::SelectWeightedSequence( CStudioHdr * } +#ifdef SDK_MP int CStudioHdr::CActivityToSequenceMapping::SelectWeightedSequenceFromModifiers( CStudioHdr *pstudiohdr, int activity, CUtlSymbol *pActivityModifiers, int iModifierCount ) { if ( !pstudiohdr->SequencesAvailable() ) @@ -406,6 +407,7 @@ int CStudioHdr::CActivityToSequenceMapping::SelectWeightedSequenceFromModifiers( return topScoring[ RandomInt( 0, topScoring.Count() - 1 ) ]; } +#endif #endif diff --git a/src/game/shared/choreoscene.h b/src/game/shared/choreoscene.h index b4a5679d73a..554fc39e887 100644 --- a/src/game/shared/choreoscene.h +++ b/src/game/shared/choreoscene.h @@ -329,7 +329,9 @@ class CChoreoScene : public ICurveDataAccessor // Current simulation time float m_flCurrentTime; +#ifdef SDK_MP float m_flStartLoopTime; +#endif float m_flStartTime; float m_flEndTime; diff --git a/src/game/shared/debugoverlay_shared.cpp b/src/game/shared/debugoverlay_shared.cpp index e6533a5fef0..af7c8e723e5 100644 --- a/src/game/shared/debugoverlay_shared.cpp +++ b/src/game/shared/debugoverlay_shared.cpp @@ -252,6 +252,7 @@ void NDebugOverlay::ScreenText( float flXpos, float flYpos, const char *text, in } } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: Add debug overlay text with screen position and line offset //----------------------------------------------------------------------------- @@ -262,6 +263,7 @@ void NDebugOverlay::ScreenTextLine( float flXpos, float flYpos, int iLine, const debugoverlay->AddScreenTextOverlay( flXpos, flYpos, iLine, duration, r, g, b, a, text ); } } +#endif //----------------------------------------------------------------------------- // Purpose: Draw a colored 3D cross of the given hull size at the given position diff --git a/src/game/shared/debugoverlay_shared.h b/src/game/shared/debugoverlay_shared.h index 3deecd5d079..06097731930 100644 --- a/src/game/shared/debugoverlay_shared.h +++ b/src/game/shared/debugoverlay_shared.h @@ -30,7 +30,9 @@ namespace NDebugOverlay void Grid( const Vector &vPosition ); void Text( const Vector &origin, const char *text, bool bViewCheck, float flDuration ); void ScreenText( float fXpos, float fYpos, const char *text, int r, int g, int b, int a, float flDuration); +#ifdef SDK_MP void ScreenTextLine( float flXpos, float flYpos, int iLine, const char *text, int r, int g, int b, int a, float duration ); +#endif void Cross3D(const Vector &position, const Vector &mins, const Vector &maxs, int r, int g, int b, bool noDepthTest, float flDuration ); void Cross3D(const Vector &position, float size, int r, int g, int b, bool noDepthTest, float flDuration ); void Cross3DOriented( const Vector &position, const QAngle &angles, float size, int r, int g, int b, bool noDepthTest, float flDuration ); diff --git a/src/game/shared/expressionsample.h b/src/game/shared/expressionsample.h index 006db6d03cc..2e0dc842d6e 100644 --- a/src/game/shared/expressionsample.h +++ b/src/game/shared/expressionsample.h @@ -69,7 +69,9 @@ struct CExpressionSample class ICurveDataAccessor { public: +#ifdef SDK_MP virtual ~ICurveDataAccessor(){} +#endif virtual float GetDuration() = 0; virtual bool CurveHasEndTime() = 0; // only matters for events virtual int GetDefaultCurveType() = 0; diff --git a/src/game/shared/util_shared.cpp b/src/game/shared/util_shared.cpp index b348ec66bd8..65fc584346f 100644 --- a/src/game/shared/util_shared.cpp +++ b/src/game/shared/util_shared.cpp @@ -1170,6 +1170,7 @@ CBasePlayer* UTIL_PlayerByCommandArg( const char *arg ) UTIL_PLAYERBYCMDARG_CHECKMATCH( bMatch ? UTIL_PlayerBySteamID( steamID ) : NULL ); } +#ifdef SDK_MP // Legacy SteamID? const char szPrefix[] = "STEAM_"; if ( nLength >= V_ARRAYSIZE( szPrefix ) && V_strncmp( szPrefix, arg, V_ARRAYSIZE( szPrefix ) - 1 ) == 0 ) @@ -1178,6 +1179,7 @@ CBasePlayer* UTIL_PlayerByCommandArg( const char *arg ) bool bMatch = SteamIDFromSteam2String( arg, GetUniverse(), &steamID ); UTIL_PLAYERBYCMDARG_CHECKMATCH( bMatch ? UTIL_PlayerBySteamID( steamID ) : NULL ); } +#endif // UserID preceded by a pound (#4) if ( nLength > 1 && arg[0] == '#' && bAllButFirstNumbers ) @@ -1302,10 +1304,12 @@ char *UTIL_GetFilteredPlayerName( const CSteamID &steamID, char *pszName ) pszName = ""; } +#ifdef SDK_MP if ( SteamUtils() ) { SteamUtils()->FilterText( k_ETextFilteringContextName, steamID, pszName, pszName, MAX_PLAYER_NAME_LENGTH ); } +#endif return pszName; } @@ -1329,6 +1333,7 @@ wchar_t *UTIL_GetFilteredPlayerNameAsWChar( const CSteamID &steamID, const char pszName = ""; } +#ifdef SDK_MP if ( SteamUtils() ) { char szName[ MAX_PLAYER_NAME_LENGTH ]; @@ -1336,6 +1341,7 @@ wchar_t *UTIL_GetFilteredPlayerNameAsWChar( const CSteamID &steamID, const char g_pVGuiLocalize->ConvertANSIToUnicode( szName, pwszName, MAX_PLAYER_NAME_LENGTH * sizeof( wchar_t ) ); } else +#endif { g_pVGuiLocalize->ConvertANSIToUnicode( pszName, pwszName, MAX_PLAYER_NAME_LENGTH * sizeof( wchar_t ) ); } @@ -1345,6 +1351,7 @@ wchar_t *UTIL_GetFilteredPlayerNameAsWChar( const CSteamID &steamID, const char char *UTIL_GetFilteredChatText( int iPlayerIndex, char *pszText, int nTextBufferSize ) { +#ifdef SDK_MP if ( SteamUtils() ) { CSteamID steamIDPlayer; @@ -1355,6 +1362,7 @@ char *UTIL_GetFilteredChatText( int iPlayerIndex, char *pszText, int nTextBuffer } SteamUtils()->FilterText( k_ETextFilteringContextChat, steamIDPlayer, pszText, pszText, nTextBufferSize ); } +#endif return pszText; } #endif // CLIENT_DLL @@ -1637,6 +1645,7 @@ CSteamID SteamIDFromDecimalString( const char *pszUint64InDecimal ) } } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: Try to parse an un-ambiguous steamID from a string // @@ -1741,6 +1750,7 @@ CSteamID UTIL_GuessSteamIDFromFuzzyInput( const char *pszInputRaw, bool bCurrent return CSteamID(); } +#endif #define WORKSHOP_PREFIX_1 "workshop/" #define MAP_WORKSHOP_PREFIX_1 "maps/" WORKSHOP_PREFIX_1 diff --git a/src/game/shared/util_shared.h b/src/game/shared/util_shared.h index eeb1811616c..54a51fed48f 100644 --- a/src/game/shared/util_shared.h +++ b/src/game/shared/util_shared.h @@ -696,6 +696,7 @@ EUniverse GetUniverse(); CSteamID SteamIDFromDecimalString( const char *pszUint64InDecimal ); +#ifdef SDK_MP //----------------------------------------------------------------------------- // Try to parse an un-ambiguous steamID from a string // @@ -713,6 +714,7 @@ CSteamID UTIL_SteamIDFromProperString( const char *pszInputRaw, bool bAllowSteam // or un-ambiugous result //----------------------------------------------------------------------------- CSteamID UTIL_GuessSteamIDFromFuzzyInput( const char *pszInputRaw, bool bCurrentUniverseOnly = true ); +#endif // This will return the first active operation string it can find. In the case of multiple // operations overlapping, the list order will act as priority. diff --git a/src/buildgameprojects_hl2 b/src/hl2_buildgameprojects old mode 100755 new mode 100644 similarity index 93% rename from src/buildgameprojects_hl2 rename to src/hl2_buildgameprojects index 651ee05f237..8fc0f2dc7f8 --- a/src/buildgameprojects_hl2 +++ b/src/hl2_buildgameprojects @@ -24,7 +24,7 @@ fi solution_out="_vpc_/ninja/sdk_everything_$VPC_NINJA_BUILD_MODE" if [[ ! -e "$solution_out.ninja" ]]; then - devtools/bin/vpc /hl2 /episodic /linux64 /ninja /define:SOURCESDK +game /mksln "$solution_out" + devtools/bin/vpc /hl2 /episodic /linux32 /ninja /define:SOURCESDK +game /mksln "$solution_out" # Generate compile commands. ninja -f "$solution_out.ninja" -t compdb > compile_commands.json diff --git a/src/buildshadersprojects_hl2 b/src/hl2_buildshadersprojects old mode 100755 new mode 100644 similarity index 93% rename from src/buildshadersprojects_hl2 rename to src/hl2_buildshadersprojects index e344a975a6c..f43c666b9c5 --- a/src/buildshadersprojects_hl2 +++ b/src/hl2_buildshadersprojects @@ -24,7 +24,7 @@ fi solution_out="_vpc_/ninja/sdk_everything_$VPC_NINJA_BUILD_MODE" if [[ ! -e "$solution_out.ninja" ]]; then - devtools/bin/vpc /hl2 /episodic /linux64 /ninja /define:SOURCESDK +shaders /mksln "$solution_out" + devtools/bin/vpc /hl2 /episodic /linux32 /ninja /define:SOURCESDK +shaders /mksln "$solution_out" # Generate compile commands. ninja -f "$solution_out.ninja" -t compdb > compile_commands.json diff --git a/src/hl2_createallprojects.bat b/src/hl2_createallprojects.bat new file mode 100644 index 00000000000..918f4d342c8 --- /dev/null +++ b/src/hl2_createallprojects.bat @@ -0,0 +1 @@ +devtools\bin\vpc.exe /win32 /episodic /hl2 /define:SOURCESDK +everything /mksln everything.sln diff --git a/src/hl2_creategameprojects.bat b/src/hl2_creategameprojects.bat new file mode 100644 index 00000000000..d57139e1585 --- /dev/null +++ b/src/hl2_creategameprojects.bat @@ -0,0 +1,2 @@ +devtools\bin\vpc.exe /hl2 /episodic /win32 /define:SOURCESDK +game +shaders /mksln games.sln +pause diff --git a/src/hl2_createmaptoolsprojects.bat b/src/hl2_createmaptoolsprojects.bat new file mode 100644 index 00000000000..d509d28b48c --- /dev/null +++ b/src/hl2_createmaptoolsprojects.bat @@ -0,0 +1 @@ +devtools\bin\vpc.exe /win32 /define:SOURCESDK +maptools /mksln maptools.sln diff --git a/src/hl2_createshadersprojects.bat b/src/hl2_createshadersprojects.bat new file mode 100644 index 00000000000..116a6702d66 --- /dev/null +++ b/src/hl2_createshadersprojects.bat @@ -0,0 +1 @@ +devtools\bin\vpc.exe /win32 /hl2 /episodic /define:SOURCESDK +shaders +game /mksln shaders.sln diff --git a/src/launcher_main/launcher_main.vpc b/src/launcher_main/launcher_main.vpc index f9e4f3386f9..29c0bf13ea1 100644 --- a/src/launcher_main/launcher_main.vpc +++ b/src/launcher_main/launcher_main.vpc @@ -55,7 +55,9 @@ $Project { $Folder "Source Files" { - -$File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + -$File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + -$File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] } $Folder "Link Libraries" diff --git a/src/launcher_main/main.cpp b/src/launcher_main/main.cpp index 19dbd35e2d1..fb571fe58bd 100644 --- a/src/launcher_main/main.cpp +++ b/src/launcher_main/main.cpp @@ -47,6 +47,10 @@ extern "C" { __declspec( dllexport ) int AmdPowerXpressRequestHighPerformance = #endif +#ifndef SDK_MP +#define Q_snprintf snprintf +#endif + #include #ifdef _WIN32 @@ -169,6 +173,7 @@ static bool LoadSteam( const char *pRootDir ) fclose( pFile ); } +#ifdef SDK_MP decltype(SteamAPI_Init) *pfnSAPIInit = (decltype( SteamAPI_Init ) *) GetProcAddress( s_SteamModule, "SteamAPI_Init" ); if ( !pfnSAPIInit ) { @@ -185,6 +190,7 @@ static bool LoadSteam( const char *pRootDir ) } s_bInittedSteam = true; +#endif return true; } @@ -195,6 +201,7 @@ static bool GetGameInstallDir( const char *pRootDir, char *pszBuf, int nBufSize return false; } +#ifdef SDK_MP decltype( SteamAPI_GetHSteamUser )* pfnSteamAPI_GetHSteamUser = ( decltype( SteamAPI_GetHSteamUser )* )GetProcAddress( s_SteamModule, "SteamAPI_GetHSteamUser" ); if ( !pfnSteamAPI_GetHSteamUser ) { @@ -229,6 +236,7 @@ static bool GetGameInstallDir( const char *pRootDir, char *pszBuf, int nBufSize MessageBox( 0, "Source SDK 2013 Multiplayer (243750) must be installed to launch this mod.", "Launcher Error", MB_OK ); return false; } +#endif return true; } diff --git a/src/lib/common/libcurl.lib b/src/lib/common/libcurl.lib new file mode 100644 index 00000000000..9b6fc8fb108 Binary files /dev/null and b/src/lib/common/libcurl.lib differ diff --git a/src/lib/common/linux32/libcrypto.a b/src/lib/common/linux32/libcrypto.a new file mode 100644 index 00000000000..274849e00c1 Binary files /dev/null and b/src/lib/common/linux32/libcrypto.a differ diff --git a/src/lib/common/linux32/libcurl.a b/src/lib/common/linux32/libcurl.a new file mode 100644 index 00000000000..be6615d962d Binary files /dev/null and b/src/lib/common/linux32/libcurl.a differ diff --git a/src/lib/common/linux32/libcurlssl.a b/src/lib/common/linux32/libcurlssl.a new file mode 100644 index 00000000000..ea01c02cc54 Binary files /dev/null and b/src/lib/common/linux32/libcurlssl.a differ diff --git a/src/lib/common/linux32/libssl.a b/src/lib/common/linux32/libssl.a new file mode 100644 index 00000000000..a96bdc0a275 Binary files /dev/null and b/src/lib/common/linux32/libssl.a differ diff --git a/src/lib/public/appframework.lib b/src/lib/public/appframework.lib new file mode 100644 index 00000000000..2700698193f Binary files /dev/null and b/src/lib/public/appframework.lib differ diff --git a/src/lib/public/bitmap.lib b/src/lib/public/bitmap.lib new file mode 100644 index 00000000000..944eb8643e3 Binary files /dev/null and b/src/lib/public/bitmap.lib differ diff --git a/src/lib/public/choreoobjects.lib b/src/lib/public/choreoobjects.lib new file mode 100644 index 00000000000..9d11c2af8c3 Binary files /dev/null and b/src/lib/public/choreoobjects.lib differ diff --git a/src/lib/public/dmxloader.lib b/src/lib/public/dmxloader.lib new file mode 100644 index 00000000000..5f61c3bf061 Binary files /dev/null and b/src/lib/public/dmxloader.lib differ diff --git a/src/lib/public/libprotobuf.lib b/src/lib/public/libprotobuf.lib new file mode 100644 index 00000000000..59ffc578866 Binary files /dev/null and b/src/lib/public/libprotobuf.lib differ diff --git a/src/lib/public/libz.lib b/src/lib/public/libz.lib new file mode 100644 index 00000000000..dd8f463aa27 Binary files /dev/null and b/src/lib/public/libz.lib differ diff --git a/src/lib/public/linux32/bitmap.a b/src/lib/public/linux32/bitmap.a new file mode 100644 index 00000000000..cc942c70ead Binary files /dev/null and b/src/lib/public/linux32/bitmap.a differ diff --git a/src/lib/public/linux32/choreoobjects.a b/src/lib/public/linux32/choreoobjects.a new file mode 100644 index 00000000000..6c27bc5c47f Binary files /dev/null and b/src/lib/public/linux32/choreoobjects.a differ diff --git a/src/lib/public/linux32/dmxloader.a b/src/lib/public/linux32/dmxloader.a new file mode 100644 index 00000000000..553ea325426 Binary files /dev/null and b/src/lib/public/linux32/dmxloader.a differ diff --git a/src/lib/public/linux32/libSDL2-2.0.so.0 b/src/lib/public/linux32/libSDL2-2.0.so.0 new file mode 100644 index 00000000000..4cb32b6a323 Binary files /dev/null and b/src/lib/public/linux32/libSDL2-2.0.so.0 differ diff --git a/src/lib/public/linux32/libSDL2.so b/src/lib/public/linux32/libSDL2.so new file mode 100644 index 00000000000..027f051ae41 --- /dev/null +++ b/src/lib/public/linux32/libSDL2.so @@ -0,0 +1 @@ +libSDL2-2.0.so.0 \ No newline at end of file diff --git a/src/lib/public/linux32/libprotobuf.a b/src/lib/public/linux32/libprotobuf.a new file mode 100644 index 00000000000..2fd92725a30 Binary files /dev/null and b/src/lib/public/linux32/libprotobuf.a differ diff --git a/src/lib/public/linux32/libsteam_api.so b/src/lib/public/linux32/libsteam_api.so new file mode 100644 index 00000000000..cb4ee649f0a Binary files /dev/null and b/src/lib/public/linux32/libsteam_api.so differ diff --git a/src/lib/public/linux32/libtier0.so b/src/lib/public/linux32/libtier0.so new file mode 100644 index 00000000000..6cfc83418bc Binary files /dev/null and b/src/lib/public/linux32/libtier0.so differ diff --git a/src/lib/public/linux32/libvstdlib.so b/src/lib/public/linux32/libvstdlib.so new file mode 100644 index 00000000000..4a4af170c16 Binary files /dev/null and b/src/lib/public/linux32/libvstdlib.so differ diff --git a/src/lib/public/linux32/libz.a b/src/lib/public/linux32/libz.a new file mode 100644 index 00000000000..0e5f958bb0d Binary files /dev/null and b/src/lib/public/linux32/libz.a differ diff --git a/src/lib/public/linux32/matsys_controls.a b/src/lib/public/linux32/matsys_controls.a new file mode 100644 index 00000000000..c389ddf7d2c Binary files /dev/null and b/src/lib/public/linux32/matsys_controls.a differ diff --git a/src/lib/public/linux32/particles.a b/src/lib/public/linux32/particles.a new file mode 100644 index 00000000000..9c20f02430c Binary files /dev/null and b/src/lib/public/linux32/particles.a differ diff --git a/src/lib/public/linux32/shaderlib.a b/src/lib/public/linux32/shaderlib.a new file mode 100644 index 00000000000..062e7b66ee6 Binary files /dev/null and b/src/lib/public/linux32/shaderlib.a differ diff --git a/src/lib/public/linux32/tier2.a b/src/lib/public/linux32/tier2.a new file mode 100644 index 00000000000..d54e86390a0 Binary files /dev/null and b/src/lib/public/linux32/tier2.a differ diff --git a/src/lib/public/linux32/tier3.a b/src/lib/public/linux32/tier3.a new file mode 100644 index 00000000000..637239e7022 Binary files /dev/null and b/src/lib/public/linux32/tier3.a differ diff --git a/src/lib/public/linux32/vtf.a b/src/lib/public/linux32/vtf.a new file mode 100644 index 00000000000..e0fed546e72 Binary files /dev/null and b/src/lib/public/linux32/vtf.a differ diff --git a/src/lib/public/matsys_controls.lib b/src/lib/public/matsys_controls.lib new file mode 100644 index 00000000000..e8c38ca05bb Binary files /dev/null and b/src/lib/public/matsys_controls.lib differ diff --git a/src/lib/public/nvtristrip.lib b/src/lib/public/nvtristrip.lib new file mode 100644 index 00000000000..9b1d8702bdf Binary files /dev/null and b/src/lib/public/nvtristrip.lib differ diff --git a/src/lib/public/particles.lib b/src/lib/public/particles.lib new file mode 100644 index 00000000000..bbc27c63c43 Binary files /dev/null and b/src/lib/public/particles.lib differ diff --git a/src/lib/public/shaderlib.lib b/src/lib/public/shaderlib.lib new file mode 100644 index 00000000000..e78628e1b7b Binary files /dev/null and b/src/lib/public/shaderlib.lib differ diff --git a/src/lib/public/steam_api.lib b/src/lib/public/steam_api.lib new file mode 100644 index 00000000000..3b9c60b6695 Binary files /dev/null and b/src/lib/public/steam_api.lib differ diff --git a/src/lib/public/tier0.lib b/src/lib/public/tier0.lib new file mode 100644 index 00000000000..9cfea1a96d9 Binary files /dev/null and b/src/lib/public/tier0.lib differ diff --git a/src/lib/public/tier2.lib b/src/lib/public/tier2.lib new file mode 100644 index 00000000000..e9bac91c692 Binary files /dev/null and b/src/lib/public/tier2.lib differ diff --git a/src/lib/public/tier3.lib b/src/lib/public/tier3.lib new file mode 100644 index 00000000000..3b99bb05901 Binary files /dev/null and b/src/lib/public/tier3.lib differ diff --git a/src/lib/public/vmpi.lib b/src/lib/public/vmpi.lib new file mode 100644 index 00000000000..4080914a6f0 Binary files /dev/null and b/src/lib/public/vmpi.lib differ diff --git a/src/lib/public/vstdlib.lib b/src/lib/public/vstdlib.lib new file mode 100644 index 00000000000..2e6ffe27e35 Binary files /dev/null and b/src/lib/public/vstdlib.lib differ diff --git a/src/lib/public/vtf.lib b/src/lib/public/vtf.lib new file mode 100644 index 00000000000..5d35a3e78dc Binary files /dev/null and b/src/lib/public/vtf.lib differ diff --git a/src/materialsystem/stdshaders/BaseVSShader.h b/src/materialsystem/stdshaders/BaseVSShader.h index 523c9ef2eff..6ebd2ea0b51 100644 --- a/src/materialsystem/stdshaders/BaseVSShader.h +++ b/src/materialsystem/stdshaders/BaseVSShader.h @@ -30,6 +30,12 @@ extern ConVar mat_specular_disable_on_missing; #endif +#ifdef SDK_SP +// Most shaders are replacements and need this by default in SP. +// Include "mapbase_sdk_macros_off.h" if you don't want this in your shader +#include "mapbase_sdk_macros_on.h" +#endif + //----------------------------------------------------------------------------- // Helper macro for vertex shaders //----------------------------------------------------------------------------- diff --git a/src/materialsystem/stdshaders/depthoffield_dx9.cpp b/src/materialsystem/stdshaders/depthoffield_dx9.cpp index 69650e748f3..bdd075d2d96 100644 --- a/src/materialsystem/stdshaders/depthoffield_dx9.cpp +++ b/src/materialsystem/stdshaders/depthoffield_dx9.cpp @@ -12,6 +12,11 @@ // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" +#ifdef SDK_SP +// Not a default shader +#include "mapbase_sdk_macros_off.h" +#endif + ConVar mat_dof_max_blur_radius( "mat_dof_max_blur_radius", "50" ); ConVar mat_dof_quality( "mat_dof_quality", "3" ); ConVar mat_dof_constant( "mat_dof_constant", "512" ); diff --git a/src/materialsystem/stdshaders/game_shader_generic_example_base.vpc b/src/materialsystem/stdshaders/game_shader_generic_example_base.vpc index bdf22554f43..301bdc941f0 100644 --- a/src/materialsystem/stdshaders/game_shader_generic_example_base.vpc +++ b/src/materialsystem/stdshaders/game_shader_generic_example_base.vpc @@ -8,6 +8,9 @@ $Macro OUTBINDIR "$SRCDIR\..\game\$GAMENAME\bin" $Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" +// SP Mapbase shader replacements +$Include "$SRCDIR\materialsystem\stdshaders\game_shader_sp_sdk_mapbase.vpc" [$MAPBASE && ($WIN32||$LINUX32)] // SDK_SP (see sdk_sp_branch.vpc) + $Configuration "Debug" { $General @@ -32,7 +35,8 @@ $Configuration $Compiler { $AdditionalIncludeDirectories "$BASE;include;" - $PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS;GAME_SHADER_DLL" + $PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS;GAME_SHADER_DLL" [$WIN64||$LINUX64] // SDK_MP + $PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" [$WIN32||$LINUX32] // SDK_SP $PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [$WINDOWS && !$GL] } @@ -54,7 +58,7 @@ $Project $File "sdk_bloom.cpp" $File "sdk_screenspace_general.cpp" - $File "mapbase_sdk_stubs.cpp" + $File "mapbase_sdk_stubs.cpp" [$WIN64||$LINUX64] // SDK_MP } $Folder "Header Files" diff --git a/src/materialsystem/stdshaders/game_shader_generic_example_episodic.vpc b/src/materialsystem/stdshaders/game_shader_generic_example_episodic.vpc index bb5f6e1455f..86caccdd55d 100644 --- a/src/materialsystem/stdshaders/game_shader_generic_example_episodic.vpc +++ b/src/materialsystem/stdshaders/game_shader_generic_example_episodic.vpc @@ -5,7 +5,8 @@ //----------------------------------------------------------------------------- $Macro SRCDIR "..\.." -$Macro OUTBINNAME "game_shader_generic_example" +$Macro OUTBINNAME "game_shader_generic_example" [$WIN64||$LINUX64] // SDK_MP +$Macro OUTBINNAME "game_shader_dx9" [$WIN32||$LINUX32] // SDK_SP $Macro GAMENAME "mod_episodic" $Include "$SRCDIR\materialsystem\stdshaders\game_shader_generic_example_base.vpc" diff --git a/src/materialsystem/stdshaders/game_shader_generic_example_hl2.vpc b/src/materialsystem/stdshaders/game_shader_generic_example_hl2.vpc index 9837c1f1bca..51cb7061341 100644 --- a/src/materialsystem/stdshaders/game_shader_generic_example_hl2.vpc +++ b/src/materialsystem/stdshaders/game_shader_generic_example_hl2.vpc @@ -5,7 +5,8 @@ //----------------------------------------------------------------------------- $Macro SRCDIR "..\.." -$Macro OUTBINNAME "game_shader_generic_example" +$Macro OUTBINNAME "game_shader_generic_example" [$WIN64||$LINUX64] // SDK_MP +$Macro OUTBINNAME "game_shader_dx9" [$WIN32||$LINUX32] // SDK_SP $Macro GAMENAME "mod_hl2" $Include "$SRCDIR\materialsystem\stdshaders\game_shader_generic_example_base.vpc" diff --git a/src/materialsystem/stdshaders/game_shader_sp_sdk_mapbase.vpc b/src/materialsystem/stdshaders/game_shader_sp_sdk_mapbase.vpc new file mode 100644 index 00000000000..ed12ba63d56 --- /dev/null +++ b/src/materialsystem/stdshaders/game_shader_sp_sdk_mapbase.vpc @@ -0,0 +1,76 @@ +//----------------------------------------------------------------------------- +// game_shader_dx9_mapbase.vpc +// +// Project Script for Mapbase shader changes +//----------------------------------------------------------------------------- + +$Configuration +{ + $Compiler + { + // https://developer.valvesoftware.com/wiki/Parallax_Corrected_Cubemaps + $PreprocessorDefinitions "$BASE;PARALLAX_CORRECTED_CUBEMAPS" + } +} + +$Project +{ + $Folder "Source Files" + { + $File "cloak_blended_pass_helper.cpp" + $File "emissive_scroll_blended_pass_helper.cpp" + $File "flesh_interior_blended_pass_helper.cpp" + $File "lightmappedgeneric_dx9.cpp" + $File "lightmappedgeneric_dx9_helper.cpp" + $File "lightmappedreflective.cpp" + $File "skin_dx9_helper.cpp" + $File "unlitgeneric_dx9.cpp" + $File "vertexlitgeneric_dx9.cpp" + $File "vertexlitgeneric_dx9_helper.cpp" + + $File "common_flashlight_fxc.h" + $File "lightmappedgeneric_dx9_helper.h" + $File "lightmappedgeneric_ps2_3_x.h" + + $File "worldtwotextureblend.cpp" + $File "worldvertextransition.cpp" + $File "worldvertextransition_dx8_helper.cpp" + $File "refract.cpp" + $File "refract_dx9_helper.cpp" + + $File "water.cpp" + $File "depthwrite.cpp" + //$File "cable_dx9.cpp" + $File "splinerope.cpp" + + //$File "eyes.cpp" + $File "eyes_dx9.cpp" + $File "eyes_dx8_dx9_helper.cpp" + $File "eyeball.cpp" + $File "eyeglint_dx9.cpp" + $File "eye_refract.cpp" + $File "eye_refract_helper.cpp" + $File "teeth.cpp" + + //$File "sprite.cpp" + $File "sprite_dx9.cpp" + + $File "DecalModulate_dx9.cpp" + + $File "unlittwotexture_dx9.cpp" + $File "MonitorScreen_dx9.cpp" + $File "shatteredglass.cpp" + $File "windowimposter_dx90.cpp" + + $File "Engine_Post_dx9.cpp" + $File "depthoffield_dx9.cpp" + + $File "core_dx9.cpp" + + // MP branch additions + $File "weapon_sheen_pass_helper.cpp" + } + + //$Shaders "mapbase_dx9_20b.txt" + //$Shaders "mapbase_dx9_30.txt" +} diff --git a/src/materialsystem/stdshaders/include/depth_of_field_ps20b.inc b/src/materialsystem/stdshaders/include/depth_of_field_ps20b.inc new file mode 100644 index 00000000000..99961231fa5 --- /dev/null +++ b/src/materialsystem/stdshaders/include/depth_of_field_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class depth_of_field_ps20b_Static_Index +{ +public: + depth_of_field_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depth_of_field_ps20b 0 +class depth_of_field_ps20b_Dynamic_Index +{ +private: + int m_nQUALITY; +#ifdef _DEBUG + bool m_bQUALITY; +#endif +public: + void SetQUALITY( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nQUALITY = i; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } + void SetQUALITY( bool i ) + { + m_nQUALITY = i ? 1 : 0; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } +public: + depth_of_field_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bQUALITY = false; +#endif // _DEBUG + m_nQUALITY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bQUALITY; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nQUALITY ) + 0; + } +}; +#define shaderDynamicTest_depth_of_field_ps20b psh_forgot_to_set_dynamic_QUALITY + 0 diff --git a/src/materialsystem/stdshaders/include/depth_of_field_vs20.inc b/src/materialsystem/stdshaders/include/depth_of_field_vs20.inc new file mode 100644 index 00000000000..a014d1b95a3 --- /dev/null +++ b/src/materialsystem/stdshaders/include/depth_of_field_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class depth_of_field_vs20_Static_Index +{ +public: + depth_of_field_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depth_of_field_vs20 0 +class depth_of_field_vs20_Dynamic_Index +{ +public: + depth_of_field_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_depth_of_field_vs20 0 diff --git a/src/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp b/src/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp index fd63fcd94be..7226241e84b 100644 --- a/src/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp +++ b/src/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp @@ -35,7 +35,9 @@ ConVar mat_force_lightmapped_phong( "mat_force_lightmapped_phong", "0", FCVAR_CH ConVar mat_force_lightmapped_phong_boost( "mat_force_lightmapped_phong_boost", "5.0", FCVAR_CHEAT ); ConVar mat_force_lightmapped_phong_exp( "mat_force_lightmapped_phong_exp", "50.0", FCVAR_CHEAT ); +#ifdef SDK_MP // SP lacks some changes required for this :( ConVar r_lightmap_bicubic( "r_lightmap_bicubic", "0", FCVAR_NONE, "Enable bi-cubic (high quality) lightmap sampling." ); +#endif extern ConVar r_flashlight_version2; @@ -1591,7 +1593,11 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); +#ifdef SDK_MP SET_DYNAMIC_PIXEL_SHADER_COMBO( BICUBIC_LIGHTMAP, r_lightmap_bicubic.GetBool() ? 1 : 0 ); +#else + SET_DYNAMIC_PIXEL_SHADER_COMBO( BICUBIC_LIGHTMAP, 0 ); +#endif SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_ps30 ); } @@ -1606,7 +1612,11 @@ void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); +#ifdef SDK_MP SET_DYNAMIC_PIXEL_SHADER_COMBO( BICUBIC_LIGHTMAP, r_lightmap_bicubic.GetBool() ? 1 : 0 ); +#else + SET_DYNAMIC_PIXEL_SHADER_COMBO( BICUBIC_LIGHTMAP, 0 ); +#endif SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_ps20b ); } diff --git a/src/materialsystem/stdshaders/mapbase_sdk_macros_off.h b/src/materialsystem/stdshaders/mapbase_sdk_macros_off.h new file mode 100644 index 00000000000..4b5fb50f3df --- /dev/null +++ b/src/materialsystem/stdshaders/mapbase_sdk_macros_off.h @@ -0,0 +1,8 @@ +//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============// +// +// Purpose: Disables automatic SP SDK_ shader concatenation (only necessary in SP) +// +//=============================================================================// + +#undef SHADER_PREFIX +#define SHADER_PREFIX diff --git a/src/materialsystem/stdshaders/mapbase_sdk_macros_on.h b/src/materialsystem/stdshaders/mapbase_sdk_macros_on.h new file mode 100644 index 00000000000..2daab32dbb6 --- /dev/null +++ b/src/materialsystem/stdshaders/mapbase_sdk_macros_on.h @@ -0,0 +1,8 @@ +//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============// +// +// Purpose: Enables automatic SDK_ shader concatenation (only necessary in SP) +// +//=============================================================================// + +#undef SHADER_PREFIX +#define SHADER_PREFIX "SDK_" diff --git a/src/materialsystem/stdshaders/sdk_screenspace_general.cpp b/src/materialsystem/stdshaders/sdk_screenspace_general.cpp index e593973cd89..5035b548882 100644 --- a/src/materialsystem/stdshaders/sdk_screenspace_general.cpp +++ b/src/materialsystem/stdshaders/sdk_screenspace_general.cpp @@ -9,6 +9,10 @@ #include "sdk_screenspaceeffect_vs20.inc" +#ifdef SDK_SP +#include "mapbase_sdk_macros_off.h" +#endif + DEFINE_FALLBACK_SHADER( SDK_screenspace_general, SDK_screenspace_general_dx9 ) BEGIN_VS_SHADER_FLAGS( SDK_screenspace_general_dx9, "Help for screenspace_general", SHADER_NOT_EDITABLE ) BEGIN_SHADER_PARAMS diff --git a/src/materialsystem/stdshaders/shaders/fxc/add_sdk_prefix.bat b/src/materialsystem/stdshaders/shaders/fxc/add_sdk_prefix.bat new file mode 100644 index 00000000000..dfed4f1787c --- /dev/null +++ b/src/materialsystem/stdshaders/shaders/fxc/add_sdk_prefix.bat @@ -0,0 +1 @@ +for %f in (*) do ren "%f" "sdk_%f" diff --git a/src/materialsystem/stdshaders/stdshader_dx9_inc.vpc b/src/materialsystem/stdshaders/stdshader_dx9_inc.vpc index 7d42ffde94f..d645d90f59d 100644 --- a/src/materialsystem/stdshaders/stdshader_dx9_inc.vpc +++ b/src/materialsystem/stdshaders/stdshader_dx9_inc.vpc @@ -16,8 +16,10 @@ $Configuration "Debug" { $General { - $OutputDirectory "Debug_dx9" [$WINDOWS] - $IntermediateDirectory "Debug_dx9" [$WINDOWS] + // Causes problems when building multiple shader projects in parallel. + // It'd be nice to automate dependency, but for now, just fall back to game-based naming + $OutputDirectory "Debug_dx9" [$WINDOWS&&!$MAPBASE] + $IntermediateDirectory "Debug_dx9" [$WINDOWS&&!$MAPBASE] } } @@ -25,8 +27,8 @@ $Configuration "Release" { $General { - $OutputDirectory "Release_dx9" [$WINDOWS] - $IntermediateDirectory "Release_dx9" [$WINDOWS] + $OutputDirectory "Release_dx9" [$WINDOWS&&!$MAPBASE] + $IntermediateDirectory "Release_dx9" [$WINDOWS&&!$MAPBASE] } } @@ -162,7 +164,7 @@ $Project $File "writestencil_dx9.cpp" $File "splinerope.cpp" [$MAPBASE] - $File "mapbase_sdk_stubs.cpp" [$MAPBASE] + $File "mapbase_sdk_stubs.cpp" [$MAPBASE && ($WIN64||$LINUX64)] // SDK_MP $Folder "Remove me when VAC2 is out" [$WINDOWS && !$SOURCESDK] { diff --git a/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp b/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp index 58077e16e3e..00ccc15398c 100644 --- a/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp +++ b/src/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp @@ -41,7 +41,9 @@ BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" ) SHADER_PARAM( SELFILLUMFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC4, "0", "Self illum fresnel min, max, exp" ) SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) SHADER_PARAM( FLASHLIGHTNOLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Flashlight pass sets N.L=1.0" ) +#ifdef SDK_MP SHADER_PARAM( LIGHTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "lightmap texture--will be bound by the engine") +#endif // Debugging term for visualizing ambient data on its own SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" ) @@ -194,7 +196,9 @@ BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" ) info.m_nEnvmapSaturation = ENVMAPSATURATION; info.m_nAlphaTestReference = ALPHATESTREFERENCE; info.m_nFlashlightNoLambert = FLASHLIGHTNOLAMBERT; +#ifdef SDK_MP info.m_nLightmap = LIGHTMAP; +#endif info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; diff --git a/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp b/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp index 888d587906b..8fee6891f6c 100644 --- a/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp +++ b/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp @@ -418,8 +418,10 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; bool bHasDiffuseWarp = (!bHasFlashlight || IsX360() ) && hasDiffuseLighting && (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsTexture(); +#ifdef SDK_MP bool bHasLightmapTexture = IsTextureSet( info.m_nLightmap, params ); bool bHasMatLuxel = bHasLightmapTexture && mat_luxels.GetBool(); +#endif //bool bNoCull = IS_FLAG_SET( MATERIAL_VAR_NOCULL ); bool bFlashlightNoLambert = false; @@ -1341,12 +1343,17 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial // Set up light combo state +#ifdef SDK_MP LightState_t lightState = { 0, false, false, false }; +#else + LightState_t lightState = { 0, false, false }; +#endif if ( bVertexLitGeneric && (!bHasFlashlight || IsX360() ) ) { pShaderAPI->GetDX9LightState( &lightState ); } +#ifdef SDK_MP // Override the lighting desired if we have a lightmap set! if ( bHasLightmapTexture ) { @@ -1366,6 +1373,7 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial DynamicCmdsOut.SetPixelShaderConstant( 11, dimensions, 1 ); } } +#endif MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; @@ -1473,7 +1481,11 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, lightState.m_bStaticLightVertex ? 1 : 0 ); +#ifdef SDK_MP SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0); +#else + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0); +#endif SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( @@ -1490,8 +1502,13 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo1( true ) ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); +#ifdef SDK_MP SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, bHasMatLuxel ? 1 : 0 ); +#else + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, 0 ); +#endif SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); @@ -1501,7 +1518,11 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial { DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); +#ifdef SDK_MP SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); +#else + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0 ); +#endif SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); @@ -1516,7 +1537,11 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, lightState.m_bStaticLightVertex ? 1 : 0 ); +#ifdef SDK_MP SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); +#else + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0 ); +#endif SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, @@ -1528,8 +1553,13 @@ static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterial DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps30 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo1( true ) ); SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); +#ifdef SDK_MP SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, bHasMatLuxel ? 1 : 0 ); +#else + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, 0 ); +#endif SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_ps30 ); diff --git a/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h b/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h index 207f72c21a0..f77c17d7792 100644 --- a/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h +++ b/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h @@ -54,7 +54,9 @@ struct VertexLitGeneric_DX9_Vars_t int m_nFlashlightNoLambert; int m_nFlashlightTexture; int m_nFlashlightTextureFrame; +#ifdef SDK_MP int m_nLightmap; +#endif int m_nSelfIllumTint; int m_nSelfIllumFresnel; diff --git a/src/mathlib/sseconst.cpp b/src/mathlib/sseconst.cpp index d68588fdde9..0fcbfdce0e4 100644 --- a/src/mathlib/sseconst.cpp +++ b/src/mathlib/sseconst.cpp @@ -38,19 +38,25 @@ const fltx4 g_QuatMultRowSign[4] = { -1.0f, -1.0f, -1.0f, 1.0f } }; -const uint32 ALIGN16 g_SIMD_clear_signmask[4] ALIGN16_POST = {0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff}; -const uint32 ALIGN16 g_SIMD_signmask[4] ALIGN16_POST = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; -const uint32 ALIGN16 g_SIMD_lsbmask[4] ALIGN16_POST = { 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe }; -const uint32 ALIGN16 g_SIMD_clear_wmask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; -const uint32 ALIGN16 g_SIMD_AllOnesMask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; // ~0,~0,~0,~0 -const uint32 ALIGN16 g_SIMD_Low16BitsMask[4] ALIGN16_POST = { 0xffff, 0xffff, 0xffff, 0xffff }; // 0xffff x 4 - -const uint32 ALIGN16 g_SIMD_ComponentMask[4][4] ALIGN16_POST = +#if defined(SDK_SP) && defined(LINUX) +// Don't care about narrowing these +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnarrowing" +#endif + +const SIMD_mask_int ALIGN16 g_SIMD_clear_signmask[4] ALIGN16_POST = {0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff}; +const SIMD_mask_int ALIGN16 g_SIMD_signmask[4] ALIGN16_POST = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; +const SIMD_mask_int ALIGN16 g_SIMD_lsbmask[4] ALIGN16_POST = { 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe }; +const SIMD_mask_int ALIGN16 g_SIMD_clear_wmask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; +const SIMD_mask_int ALIGN16 g_SIMD_AllOnesMask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; // ~0,~0,~0,~0 +const SIMD_mask_int ALIGN16 g_SIMD_Low16BitsMask[4] ALIGN16_POST = { 0xffff, 0xffff, 0xffff, 0xffff }; // 0xffff x 4 + +const SIMD_mask_int ALIGN16 g_SIMD_ComponentMask[4][4] ALIGN16_POST = { { 0xFFFFFFFF, 0, 0, 0 }, { 0, 0xFFFFFFFF, 0, 0 }, { 0, 0, 0xFFFFFFFF, 0 }, { 0, 0, 0, 0xFFFFFFFF } }; -const uint32 ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST = +const SIMD_mask_int ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST = { { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 }, @@ -58,6 +64,10 @@ const uint32 ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 }, }; +#if defined(SDK_SP) && defined(LINUX) +#pragma GCC diagnostic pop +#endif + // FUNCTIONS // NOTE: WHY YOU **DO NOT** WANT TO PUT FUNCTIONS HERE diff --git a/src/public/SoundEmitterSystem/isoundemittersystembase.h b/src/public/SoundEmitterSystem/isoundemittersystembase.h index 77fbf0daafe..3de99aac8ed 100644 --- a/src/public/SoundEmitterSystem/isoundemittersystembase.h +++ b/src/public/SoundEmitterSystem/isoundemittersystembase.h @@ -265,8 +265,10 @@ abstract_class ISoundEmitterSystemBase : public IAppSystem virtual void ReloadSoundEntriesInList( IFileList *pFilesToReload ) = 0; +#ifdef SDK_MP // Called by either client or server to force ModShutdown and ModInit virtual void Flush() = 0; +#endif }; #endif // ISOUNDEMITTERSYSTEMBASE_H diff --git a/src/public/UtlCachedFileData.h b/src/public/UtlCachedFileData.h index 0be5049f9b5..b7075ae35ea 100644 --- a/src/public/UtlCachedFileData.h +++ b/src/public/UtlCachedFileData.h @@ -462,7 +462,7 @@ void CUtlCachedFileData::InitSmallBuffer( FileHandle_t& fh, int fileSize, boo // Read the element name char elementFileName[ 512 ]; - buf.GetString( elementFileName ); + buf.GetString( elementFileName, sizeof( elementFileName ) ); // Now read the element int slot = GetIndex( elementFileName ); diff --git a/src/public/basehandle.h b/src/public/basehandle.h index 6cb9019f4d1..7f4dc117461 100644 --- a/src/public/basehandle.h +++ b/src/public/basehandle.h @@ -37,6 +37,9 @@ friend class CBaseEntityList; CBaseHandle( INVALID_EHANDLE_tag ); CBaseHandle( const CBaseHandle &other ); explicit CBaseHandle( IHandleEntity* pHandleObj ); +#ifndef SDK_MP + CBaseHandle( unsigned long value ); +#endif CBaseHandle( int iEntry, int iSerialNumber ); // NOTE: The following constructor is not type-safe, and can allow creating an @@ -99,6 +102,13 @@ inline CBaseHandle::CBaseHandle( const CBaseHandle &other ) m_Index = other.m_Index; } +#ifndef SDK_MP +inline CBaseHandle::CBaseHandle( unsigned long value ) +{ + m_Index = value; +} +#endif + inline CBaseHandle::CBaseHandle( IHandleEntity* pEntity ) { Set( pEntity ); diff --git a/src/public/bitmap/imageformat.h b/src/public/bitmap/imageformat.h index 394e8bc6555..23bae7400f2 100644 --- a/src/public/bitmap/imageformat.h +++ b/src/public/bitmap/imageformat.h @@ -15,7 +15,11 @@ enum NormalDecodeMode_t { - NORMAL_DECODE_NONE = 0 + NORMAL_DECODE_NONE = 0, +#ifndef SDK_MP + NORMAL_DECODE_ATI2N = 1, + NORMAL_DECODE_ATI2N_ALPHA = 2 +#endif }; // Forward declaration @@ -450,9 +454,11 @@ namespace ImageLoader int height, int depth, ImageFormat imageFormat, float srcGamma, float dstGamma, int numLevels = 0 ); +#ifdef SDK_MP // Low quality mipmap generation, but way faster. void GenerateMipmapLevelsLQ( unsigned char* pSrc, unsigned char* pDst, int width, int height, ImageFormat imageFormat, int numLevels ); +#endif //----------------------------------------------------------------------------- // operations on square images (src and dst can be the same) @@ -516,10 +522,12 @@ namespace ImageLoader return ( info.m_NumRedBits > 8 || info.m_NumGreeBits > 8 || info.m_NumBlueBits > 8 || info.m_NumAlphaBits > 8 ); } +#ifdef SDK_MP inline bool IsRuntimeCompressed( ImageFormat fmt ) { return ( fmt == IMAGE_FORMAT_DXT1_RUNTIME ) || ( fmt == IMAGE_FORMAT_DXT5_RUNTIME ); } +#endif } // end namespace ImageLoader diff --git a/src/public/bitvec.h b/src/public/bitvec.h index a1a984d0a66..5dd94af29a4 100644 --- a/src/public/bitvec.h +++ b/src/public/bitvec.h @@ -266,8 +266,13 @@ class CBitVecT : public BASE_OPS void SetDWord(int i, uint32 val); CBitVecT& operator=(const CBitVecT &other) { other.CopyTo( this ); return *this; } +#ifdef SDK_MP bool operator==(const CBitVecT &other) const { return Compare( other ); } bool operator!=(const CBitVecT &other) const { return !operator==( other ); } +#else + bool operator==(const CBitVecT &other) { return Compare( other ); } + bool operator!=(const CBitVecT &other) { return !operator==( other ); } +#endif static void GetOffsetMaskForBit( uint32 bitNum, uint32 *pOffset, uint32 *pMask ) { *pOffset = BitVec_Int( bitNum ); *pMask = BitVec_Bit( bitNum ); } }; @@ -1065,6 +1070,7 @@ inline int CFixedBitVecBase::FindNextSetBit( int startBit ) const const uint32 * RESTRICT pCurElem = Base() + wordIndex; unsigned int elem = *pCurElem; elem &= startMask; +#ifdef SDK_MP while ( wordIndex < NUM_INTS ) { if ( elem ) @@ -1077,6 +1083,16 @@ inline int CFixedBitVecBase::FindNextSetBit( int startBit ) const elem = *pCurElem; } } +#else + do + { + if ( elem ) + return FirstBitInWord(elem, wordIndex << 5); + ++pCurElem; + elem = *pCurElem; + ++wordIndex; + } while( wordIndex <= NUM_INTS-1); +#endif } } diff --git a/src/public/bspfile.h b/src/public/bspfile.h index c64c17c6ca4..c8e81587bb2 100644 --- a/src/public/bspfile.h +++ b/src/public/bspfile.h @@ -388,9 +388,13 @@ struct lump_t DECLARE_BYTESWAP_DATADESC(); int fileofs, filelen; int version; // default to zero +#ifdef SDK_MP // this field was char fourCC[4] previously, but was unused, favoring the LUMP IDs above instead. It has been // repurposed for compression. 0 implies the lump is not compressed. int uncompressedSize; // default to zero +#else + char fourCC[4]; // default to ( char )0, ( char )0, ( char )0, ( char )0 +#endif }; diff --git a/src/public/cdll_int.h b/src/public/cdll_int.h index b026aaf4366..15ed39de7cd 100644 --- a/src/public/cdll_int.h +++ b/src/public/cdll_int.h @@ -548,13 +548,15 @@ abstract_class IVEngineClient013 // returns the string name of the key to which this string is bound. Returns NULL if no such binding exists // Unlike Key_LookupBinding, leading '+' characters are not stripped from bindings. virtual const char *Key_LookupBindingExact( const char *pBinding ) = 0; - + +#ifdef SDK_MP virtual void AddPhonemeFile( const char *pszPhonemeFile ) = 0; virtual float GetPausedExpireTime( void ) = 0; virtual bool StartDemoRecording( const char *pszFilename, const char *pszFolder = NULL ) = 0; virtual void StopDemoRecording( void ) = 0; virtual void TakeScreenshot( const char *pszFilename, const char *pszFolder = NULL ) = 0; +#endif }; abstract_class IVEngineClient : public IVEngineClient013 @@ -576,7 +578,9 @@ abstract_class IVEngineClient : public IVEngineClient013 virtual int GetInstancesRunningCount( ) = 0; +#ifdef SDK_MP virtual void SetRichPresenceConnect( const char *pszOverride ) = 0; +#endif }; @@ -792,9 +796,11 @@ abstract_class IBaseClientDLL virtual bool IsConnectedUserInfoChangeAllowed( IConVar *pCvar ) = 0; +#ifdef SDK_MP virtual bool BHaveChatSuspensionInCurrentMatch() = 0; virtual void DisplayVoiceUnavailableMessage() = 0; +#endif }; #define CLIENT_DLL_INTERFACE_VERSION "VClient017" diff --git a/src/public/const.h b/src/public/const.h index 3b69a0573db..12fd3a0adba 100644 --- a/src/public/const.h +++ b/src/public/const.h @@ -121,7 +121,11 @@ #define FL_INWATER (1<<9) // In water // NOTE if you move things up, make sure to change this value +#ifdef SDK_MP #define PLAYER_FLAG_BITS 32 +#else +#define PLAYER_FLAG_BITS 10 +#endif #define FL_FLY (1<<10) // Changes the SV_Movestep() behavior to not need to be on ground #define FL_SWIM (1<<11) // Changes the SV_Movestep() behavior to not need to be on ground (but stay in water) @@ -163,7 +167,11 @@ #define FL_INWATER (1<<10) // In water // NOTE if you move things up, make sure to change this value +#ifdef SDK_MP #define PLAYER_FLAG_BITS 32 +#else +#define PLAYER_FLAG_BITS 11 +#endif #define FL_FLY (1<<11) // Changes the SV_Movestep() behavior to not need to be on ground #define FL_SWIM (1<<12) // Changes the SV_Movestep() behavior to not need to be on ground (but stay in water) diff --git a/src/public/datacache/imdlcache.h b/src/public/datacache/imdlcache.h index 4ef3c6dbd2b..343fbb07da6 100644 --- a/src/public/datacache/imdlcache.h +++ b/src/public/datacache/imdlcache.h @@ -203,7 +203,11 @@ abstract_class IMDLCache : public IAppSystem virtual vertexFileHeader_t *GetVertexData( MDLHandle_t handle ) = 0; // Brings all data associated with an MDL into memory +#ifdef SDK_MP virtual void TouchAllData_Old( MDLHandle_t handle ) = 0; +#else + virtual void TouchAllData( MDLHandle_t handle ) = 0; +#endif // Gets/sets user data associated with the MDL virtual void SetUserData( MDLHandle_t handle, void* pData ) = 0; @@ -266,7 +270,9 @@ abstract_class IMDLCache : public IAppSystem virtual void MarkFrame() = 0; +#ifdef SDK_MP virtual bool TouchAllData( MDLHandle_t handle ) = 0; +#endif }; diff --git a/src/public/eiface.h b/src/public/eiface.h index 160de2c3528..e877b4618c0 100644 --- a/src/public/eiface.h +++ b/src/public/eiface.h @@ -73,10 +73,14 @@ typedef struct player_info_s player_info_t; #define DLLEXPORT /* */ #endif +#ifdef SDK_MP #define INTERFACEVERSION_VENGINESERVER_VERSION_21 "VEngineServer021" #define INTERFACEVERSION_VENGINESERVER_VERSION_22 "VEngineServer022" #define INTERFACEVERSION_VENGINESERVER "VEngineServer023" #define INTERFACEVERSION_VENGINESERVER_INT 23 +#else +#define INTERFACEVERSION_VENGINESERVER "VEngineServer021" +#endif struct bbox_t { @@ -84,6 +88,7 @@ struct bbox_t Vector maxs; }; +#ifdef SDK_MP struct WorkshopMapDesc_t { char szMapName[MAX_PATH]; @@ -91,6 +96,7 @@ struct WorkshopMapDesc_t uint32 uTimestamp; bool bDownloaded; }; +#endif //----------------------------------------------------------------------------- // Purpose: Interface the engine exposes to the game DLL @@ -423,6 +429,7 @@ abstract_class IVEngineServer // Get sv.GetTime() virtual float GetServerTime() const = 0; +#ifdef SDK_MP // Exposed for server plugin authors virtual IServer *GetIServer() = 0; @@ -453,8 +460,10 @@ abstract_class IVEngineServer virtual eFindMapResult FindMap( /* in/out */ char *pMapName, int nMapNameMax ) = 0; virtual void SetPausedForced( bool bPaused, float flDuration = -1.f ) = 0; +#endif }; +#ifdef SDK_MP // These only differ in new items added to the end typedef IVEngineServer IVEngineServer021; typedef IVEngineServer IVEngineServer022; @@ -466,6 +475,11 @@ typedef IVEngineServer IVEngineServer022; #define INTERFACEVERSION_SERVERGAMEDLL_VERSION_11 "ServerGameDLL011" #define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL012" #define INTERFACEVERSION_SERVERGAMEDLL_INT 12 +#else +#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_8 "ServerGameDLL008" +#define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL009" +#define INTERFACEVERSION_SERVERGAMEDLL_INT 9 +#endif class IServerGCLobby; @@ -594,6 +608,7 @@ abstract_class IServerGameDLL // Get gamedata string to send to the master serer updater. virtual const char *GetServerBrowserGameData() = 0; +#ifdef SDK_MP // Called to add output to the status command virtual void Status( void (*print) (const char *fmt, ...) ) = 0; @@ -646,6 +661,7 @@ abstract_class IServerGameDLL // Used primarily for listmaps code. // Returns true if uIndex was valid, false if invalid. virtual bool GetWorkshopMap( uint32 uIndex, WorkshopMapDesc_t *pDesc ) = 0; +#endif }; typedef IServerGameDLL IServerGameDLL008; @@ -688,8 +704,12 @@ abstract_class IServerGameEnts }; #define INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_3 "ServerGameClients003" +#ifdef SDK_MP #define INTERFACEVERSION_SERVERGAMECLIENTS_VERSION_4 "ServerGameClients004" #define INTERFACEVERSION_SERVERGAMECLIENTS "ServerGameClients005" +#else +#define INTERFACEVERSION_SERVERGAMECLIENTS "ServerGameClients004" +#endif //----------------------------------------------------------------------------- // Purpose: Player / Client related functions @@ -755,12 +775,16 @@ abstract_class IServerGameClients // Hook for player spawning virtual void ClientSpawned( edict_t *pPlayer ) = 0; +#ifdef SDK_MP // Hook for player voice virtual void ClientVoice( edict_t *pPlayer ) = 0; +#endif }; typedef IServerGameClients IServerGameClients003; +#ifdef SDK_MP typedef IServerGameClients IServerGameClients004; +#endif #define INTERFACEVERSION_UPLOADGAMESTATS "ServerUploadGameStats001" @@ -842,8 +866,10 @@ abstract_class IServerGCLobby virtual void UpdateServerDetails(void) = 0; virtual bool ShouldHibernate() = 0; +#ifdef SDK_MP virtual bool MatchAllowsNameChanges() = 0; virtual bool GetPlayerGCMatchName( const CSteamID &steamId, char *pszOutGCMatchName, size_t nGCMatchNameLen ) = 0; +#endif }; #endif // EIFACE_H diff --git a/src/public/engine/IEngineSound.h b/src/public/engine/IEngineSound.h index 4145bcff8ea..c68c60bc2cb 100644 --- a/src/public/engine/IEngineSound.h +++ b/src/public/engine/IEngineSound.h @@ -46,6 +46,7 @@ class Vector; #define SNDLEVEL_IS_COMPATIBILITY_MODE( x ) ( (x) >= soundlevel_t(256) ) +#ifdef SDK_MP // IAudioOutputStream from source2 // a separate stream that connects to the main output class IAudioOutputStream @@ -71,6 +72,7 @@ class IAudioOutputStream virtual void Pause() = 0; virtual void Resume() = 0; }; +#endif @@ -147,6 +149,7 @@ abstract_class IEngineSound virtual void NotifyBeginMoviePlayback() = 0; virtual void NotifyEndMoviePlayback() = 0; +#ifdef SDK_MP // create/destroy an audio stream virtual IAudioOutputStream *CreateOutputStream( uint nSampleRate, uint nChannels, uint nBits ) = 0; virtual void DestroyOutputStream( IAudioOutputStream *pStream ) = 0; @@ -155,6 +158,7 @@ abstract_class IEngineSound virtual void ManualUpdate( const AudioState_t *pListenerState ) = 0; // Force an extra update. virtual void ExtraUpdate() = 0; +#endif }; diff --git a/src/public/engine/ishadowmgr.h b/src/public/engine/ishadowmgr.h index 5165a8ab2a4..babac919b0c 100644 --- a/src/public/engine/ishadowmgr.h +++ b/src/public/engine/ishadowmgr.h @@ -40,7 +40,6 @@ enum ShadowFlags_t { SHADOW_FLAGS_FLASHLIGHT = (1 << 0), SHADOW_FLAGS_SHADOW = (1 << 1), - // Update this if you add flags SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_SHADOW }; diff --git a/src/public/engine/ivdebugoverlay.h b/src/public/engine/ivdebugoverlay.h index f7e7ab3ab89..65c00d12053 100644 --- a/src/public/engine/ivdebugoverlay.h +++ b/src/public/engine/ivdebugoverlay.h @@ -55,6 +55,7 @@ abstract_class IVDebugOverlay virtual void AddLineOverlayAlpha(const Vector& origin, const Vector& dest, int r, int g, int b, int a, bool noDepthTest, float duration) = 0; virtual void AddBoxOverlay2( const Vector& origin, const Vector& mins, const Vector& max, QAngle const& orientation, const Color& faceColor, const Color& edgeColor, float duration ) = 0; +#ifdef SDK_MP virtual void AddScreenTextOverlay2(float flXPos, float flYPos, int iLine, float flDuration, int r, int g, int b, int a, const char *text) = 0; // misyl: compat. @@ -63,6 +64,7 @@ abstract_class IVDebugOverlay { this->AddScreenTextOverlay2( flXPos, flYPos, iLine, flDuration, r, g, b, a, text ); } +#endif private: inline void AddTextOverlay(const Vector& origin, int line_offset, float duration, int r, int g, int b, int a, PRINTF_FORMAT_STRING const char *format, ...) {} /* catch improper use of bad interface. Needed because '0' duration can be resolved by compiler to NULL format string (i.e., compiles but calls wrong function) */ diff --git a/src/public/engine/ivmodelrender.h b/src/public/engine/ivmodelrender.h index fc10350d2de..7b28227b73e 100644 --- a/src/public/engine/ivmodelrender.h +++ b/src/public/engine/ivmodelrender.h @@ -178,7 +178,9 @@ abstract_class IVModelRender virtual void AddColoredDecal( ModelInstanceHandle_t handle, Ray_t const& ray, Vector const& decalUp, int decalIndex, int body, Color cColor, bool noPokeThru = false, int maxLODToDecal = ADDDECAL_TO_ALL_LODS ) = 0; - virtual void GetMaterialOverride( IMaterial** ppOutForcedMaterial, OverrideType_t* pOutOverrideType ) = 0; +#ifdef SDK_MP + virtual void GetMaterialOverride( IMaterial** ppOutForcedMaterial, OverrideType_t* pOutOverrideType ) = 0; +#endif }; diff --git a/src/public/fgdlib/gdvar.h b/src/public/fgdlib/gdvar.h index 55374de687c..e7a987c8365 100644 --- a/src/public/fgdlib/gdvar.h +++ b/src/public/fgdlib/gdvar.h @@ -50,9 +50,11 @@ enum GDIV_TYPE ivAngleNegativePitch, // used for instance rotating when just a pitch value is present ivInstanceVariable, // used for instance variables for easy hammer editing ivInstanceParm, // used for instance parameter declaration +#ifdef SDK_MP ivScript, ivScriptList, ivBoolean, +#endif ivMax // count of types }; diff --git a/src/public/fgdlib/inputoutput.h b/src/public/fgdlib/inputoutput.h index e8efa79a7bc..f3179f431a2 100644 --- a/src/public/fgdlib/inputoutput.h +++ b/src/public/fgdlib/inputoutput.h @@ -24,7 +24,9 @@ enum InputOutputType_t iotVector, iotEHandle, iotColor, +#ifdef SDK_MP iotScript, +#endif }; diff --git a/src/public/filesystem.h b/src/public/filesystem.h index 560ea301747..46459a1eef5 100644 --- a/src/public/filesystem.h +++ b/src/public/filesystem.h @@ -919,6 +919,7 @@ abstract_class IFileSystem : public IAppSystem, public IBaseFileSystem // Called when we unload a file, to remove that file's info for pure server purposes. virtual void NotifyFileUnloaded( const char *pszFilename, const char *pPathId ) = 0; +#ifdef SDK_MP // Returns true on successfully retrieve case-sensitive full path, otherwise false // Prefer using the GetCaseCorrectFullPath template wrapper to calling this directly virtual bool GetCaseCorrectFullPath_Ptr( const char *pFullPath, OUT_Z_CAP( maxLenInChars ) char *pDest, int maxLenInChars ) = 0; @@ -932,6 +933,7 @@ abstract_class IFileSystem : public IAppSystem, public IBaseFileSystem // remote users can coerce us into writing things down via a clickable URL. virtual void SetWriteProtectionEnable( bool bEnable ) = 0; virtual bool GetWriteProtectionEnable() const = 0; +#endif }; //----------------------------------------------------------------------------- diff --git a/src/public/filesystem/IQueuedLoader.h b/src/public/filesystem/IQueuedLoader.h index c3df99b7cf6..acd445c5847 100644 --- a/src/public/filesystem/IQueuedLoader.h +++ b/src/public/filesystem/IQueuedLoader.h @@ -130,8 +130,10 @@ abstract_class IQueuedLoader : public IAppSystem virtual void DynamicLoadMapResource( const char *pFilename, DynamicResourceCallback_t pCallback, void *pContext, void *pContext2 ) = 0; virtual void QueueDynamicLoadFunctor( CFunctor* pFunctor ) = 0; virtual bool CompleteDynamicLoad() = 0; +#ifdef SDK_MP virtual void QueueCleanupDynamicLoadFunctor( CFunctor* pFunctor ) = 0; virtual bool CleanupDynamicLoad() = 0; +#endif // callback is asynchronous virtual bool ClaimAnonymousJob( const char *pFilename, QueuedLoaderCallback_t pCallback, void *pContext, void *pContext2 = NULL ) = 0; diff --git a/src/public/filesystem_init.cpp b/src/public/filesystem_init.cpp index 4fe72d40c44..77fd74c5dc7 100644 --- a/src/public/filesystem_init.cpp +++ b/src/public/filesystem_init.cpp @@ -33,7 +33,9 @@ #include "xbox\xbox_win32stubs.h" #endif +#ifdef SDK_MP #include "steam/steam_api.h" +#endif // memdbgon must be the last include file in a .cpp file!!! #include @@ -60,7 +62,9 @@ void FileSystem_UseVProjectBinDir( bool bEnable ) s_bUseVProjectBinDir = bEnable; } +#ifdef SDK_MP bool FileSystem_AllowedSearchPath( const char *pchPath ); +#endif // This class lets you modify environment variables, and it restores the original value // when it goes out of scope. @@ -289,6 +293,7 @@ KeyValues* ReadKeyValuesFile( const char *pFilename ) } +#ifdef SDK_MP static char szSDKExecDir[4096]; const char* GetSDKExecDir() { @@ -310,6 +315,7 @@ const char* GetSDKExecDir() return nullptr; } +#endif static bool Sys_GetExecutableName( char *out, int len ) { @@ -346,13 +352,14 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) } if ( pProject ) { - +#ifdef SDK_MP // Only used by external code, i.e. maya but needed so app system loads the correct game DLLs #ifdef WIN64 Q_snprintf( exedir, exeDirLen, "%s%c..%cbin%cx64", pProject, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR ); #else Q_snprintf( exedir, exeDirLen, "%s%c..%cbin", pProject, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR ); #endif // +#endif return true; } return false; @@ -372,6 +379,7 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) } } +#ifdef SDK_MP { const char* pszSDKExecDir = GetSDKExecDir(); if ( pszSDKExecDir ) @@ -379,6 +387,7 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) V_strncpy( exedir, pszSDKExecDir, exeDirLen ); } } +#endif Q_FixSlashes( exedir ); @@ -571,6 +580,7 @@ static int SortStricmp( char * const * sz1, char * const * sz2 ) return V_stricmp( *sz1, *sz2 ); } +#ifdef SDK_MP #ifdef _WIN32 static void Plat_OpenURL( const char *pchURL ) { @@ -639,6 +649,7 @@ const Source1AppidInfo_t *GetKnownAppidInfo( uint32 nAppid ) return nullptr; } +#endif FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) { @@ -684,9 +695,10 @@ FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) bool bLowViolence = initInfo.m_bLowViolence; for ( KeyValues *pCur=pSearchPaths->GetFirstValue(); pCur; pCur=pCur->GetNextValue() ) { - const char *pszPathID = pCur->GetName(); const char *pLocation = pCur->GetString(); const char *pszBaseDir = baseDir; +#ifdef SDK_MP + const char *pszPathID = pCur->GetName(); #ifdef ENGINE_DLL char szAppInstallDir[ 1024 ]; #endif @@ -749,7 +761,9 @@ FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) Error( "Appid based mounting is not supported on non-engine DLL projects." ); #endif } - else if ( Q_stristr( pLocation, GAMEINFOPATH_TOKEN ) == pLocation ) + else +#endif + if ( Q_stristr( pLocation, GAMEINFOPATH_TOKEN ) == pLocation ) { pLocation += strlen( GAMEINFOPATH_TOKEN ); pszBaseDir = initInfo.m_pDirectoryName; @@ -767,12 +781,14 @@ FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) pLocation += strlen( BASESOURCEPATHS_TOKEN ); } +#ifdef SDK_MP char szBinLocation[MAX_PATH]; if ( Q_stricmp( pszPathID, "GAMEBIN" ) == 0 ) { V_sprintf_safe( szBinLocation, "%s" PLATFORM_DIR, pLocation ); pLocation = szBinLocation; } +#endif CUtlStringList vecFullLocationPaths; char szAbsSearchPath[MAX_PATH]; @@ -1164,6 +1180,79 @@ bool DoesPathExistAlready( const char *pPathEnvVar, const char *pTestPath ) } } +#ifndef SDK_MP +FSReturnCode_t SetSteamInstallPath( char *steamInstallPath, int steamInstallPathLen, CSteamEnvVars &steamEnvVars, bool bErrorsAsWarnings ) +{ + if ( IsConsole() ) + { + // consoles don't use steam + return FS_MISSING_STEAM_DLL; + } + + if ( IsPosix() ) + return FS_OK; // under posix the content does not live with steam.dll up the path, rely on the environment already being set by steam + + // Start at our bin directory and move up until we find a directory with steam.dll in it. + char executablePath[MAX_PATH]; + if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) + { + if ( bErrorsAsWarnings ) + { + Warning( "SetSteamInstallPath: FileSystem_GetExecutableDir failed.\n" ); + return FS_INVALID_PARAMETERS; + } + else + { + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); + } + } + + Q_strncpy( steamInstallPath, executablePath, steamInstallPathLen ); +#ifdef WIN32 + const char *pchSteamDLL = "steam" DLL_EXT_STRING; +#elif defined(POSIX) + // under osx the bin lives in the bin/ folder, so step back one + Q_StripLastDir( steamInstallPath, steamInstallPathLen ); + const char *pchSteamDLL = "libsteam" DLL_EXT_STRING; +#else + #error +#endif + while ( 1 ) + { + // Ignore steamapp.cfg here in case they're debugging. We still need to know the real steam path so we can find their username. + // find + if ( DoesFileExistIn( steamInstallPath, pchSteamDLL ) && !DoesFileExistIn( steamInstallPath, "steamapp.cfg" ) ) + break; + + if ( !Q_StripLastDir( steamInstallPath, steamInstallPathLen ) ) + { + if ( bErrorsAsWarnings ) + { + Warning( "Can't find %s relative to executable path: %s.\n", pchSteamDLL, executablePath ); + return FS_MISSING_STEAM_DLL; + } + else + { + return SetupFileSystemError( false, FS_MISSING_STEAM_DLL, "Can't find %s relative to executable path: %s.", pchSteamDLL, executablePath ); + } + } + } + + // Also, add the install path to their PATH environment variable, so filesystem_steam.dll can get to steam.dll. + char szPath[ 8192 ]; + steamEnvVars.m_Path.GetValue( szPath, sizeof( szPath ) ); + if ( !DoesPathExistAlready( szPath, steamInstallPath ) ) + { +#ifdef WIN32 +#define PATH_SEP ";" +#else +#define PATH_SEP ":" +#endif + steamEnvVars.m_Path.SetValue( "%s%s%s", szPath, PATH_SEP, steamInstallPath ); + } + return FS_OK; +} +#endif FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ) { @@ -1243,6 +1332,31 @@ void SetSteamUserPassphrase( KeyValues *pSteamInfo, CSteamEnvVars &steamEnvVars } } +#ifndef SDK_MP +FSReturnCode_t SetupSteamStartupEnvironment( KeyValues *pFileSystemInfo, const char *pGameInfoDirectory, CSteamEnvVars &steamEnvVars ) +{ + // Ok, we're going to run Steam. See if they have SteamInfo.txt. If not, we'll try to deduce what we can. + char steamInfoFile[MAX_PATH]; + Q_strncpy( steamInfoFile, pGameInfoDirectory, sizeof( steamInfoFile ) ); + Q_AppendSlash( steamInfoFile, sizeof( steamInfoFile ) ); + Q_strncat( steamInfoFile, "steaminfo.txt", sizeof( steamInfoFile ), COPY_ALL_CHARACTERS ); + KeyValues *pSteamInfo = ReadKeyValuesFile( steamInfoFile ); + + char steamInstallPath[MAX_PATH]; + FSReturnCode_t ret = SetSteamInstallPath( steamInstallPath, sizeof( steamInstallPath ), steamEnvVars, false ); + if ( ret != FS_OK ) + return ret; + + SetSteamAppUser( pSteamInfo, steamInstallPath, steamEnvVars ); + SetSteamUserPassphrase( pSteamInfo, steamEnvVars ); + + if ( pSteamInfo ) + pSteamInfo->deleteThis(); + + return FS_OK; +} +#endif + FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) { pFileSystem->RemoveSearchPaths( "EXECUTABLE_PATH" ); @@ -1252,6 +1366,7 @@ FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); pFileSystem->AddSearchPath( executablePath, "EXECUTABLE_PATH" ); +#ifdef SDK_MP if ( *PLATFORM_DIR ) { char baseBinFolder[MAX_PATH]; @@ -1259,6 +1374,7 @@ FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) baseBinFolder[ V_strlen( baseBinFolder ) - V_strlen( PLATFORM_DIR ) ] = '\0'; pFileSystem->AddSearchPath( baseBinFolder, "EXECUTABLE_PATH" ); } +#endif if ( !FileSystem_GetBaseDir( executablePath, sizeof( executablePath ) ) ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); @@ -1305,6 +1421,20 @@ FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLe return FS_OK; } +#ifndef SDK_MP +//----------------------------------------------------------------------------- +// Sets up the steam.dll install path in our PATH env var (so you can then just +// LoadLibrary() on filesystem_steam.dll without having to copy steam.dll anywhere special ) +//----------------------------------------------------------------------------- +FSReturnCode_t FileSystem_SetupSteamInstallPath() +{ + CSteamEnvVars steamEnvVars; + char steamInstallPath[MAX_PATH]; + FSReturnCode_t ret = SetSteamInstallPath( steamInstallPath, sizeof( steamInstallPath ), steamEnvVars, true ); + steamEnvVars.m_Path.SetRestoreOriginalValue( false ); // We want to keep the change to the path going forward. + return ret; +} +#endif //----------------------------------------------------------------------------- // Sets up the steam environment + gets back the gameinfo.txt path @@ -1324,6 +1454,44 @@ FSReturnCode_t FileSystem_SetupSteamEnvironment( CFSSteamSetupInfo &fsInfo ) #else setenv( GAMEDIR_TOKEN, fsInfo.m_GameInfoPath, 1 ); #endif + +#ifndef SDK_MP + CSteamEnvVars steamEnvVars; + if ( fsInfo.m_bSteam ) + { + if ( fsInfo.m_bToolsMode ) + { + // Now, load gameinfo.txt (to make sure it's there) + KeyValues *pMainFile, *pFileSystemInfo, *pSearchPaths; + ret = LoadGameInfoFile( fsInfo.m_GameInfoPath, pMainFile, pFileSystemInfo, pSearchPaths ); + if ( ret != FS_OK ) + return ret; + + // If filesystem_stdio.dll is missing or -steam is specified, then load filesystem_steam.dll. + // There are two command line parameters for Steam: + // 1) -steam (runs Steam in remote filesystem mode; requires Steam backend) + // 2) -steamlocal (runs Steam in local filesystem mode (all content off HDD) + + // Setup all the environment variables related to Steam so filesystem_steam.dll knows how to initialize Steam. + ret = SetupSteamStartupEnvironment( pFileSystemInfo, fsInfo.m_GameInfoPath, steamEnvVars ); + if ( ret != FS_OK ) + return ret; + + steamEnvVars.m_SteamAppId.SetRestoreOriginalValue( false ); // We want to keep the change to the path going forward. + + // We're done with main file + pMainFile->deleteThis(); + } + else if ( fsInfo.m_bSetSteamDLLPath ) + { + // This is used by the engine to automatically set the path to their steam.dll when running the engine, + // so they can debug it without having to copy steam.dll up into their hl2.exe folder. + char steamInstallPath[MAX_PATH]; + ret = SetSteamInstallPath( steamInstallPath, sizeof( steamInstallPath ), steamEnvVars, true ); + steamEnvVars.m_Path.SetRestoreOriginalValue( false ); // We want to keep the change to the path going forward. + } + } +#endif return FS_OK; } @@ -1429,6 +1597,7 @@ void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *sz pFileSystem->AddSearchPath( platform, "PLATFORM" ); } +#ifdef SDK_MP bool FileSystem_AllowedSearchPath( const char *pchPath ) { if ( V_stristr( pchPath, "WebDavRedirector" ) ) @@ -1439,3 +1608,4 @@ bool FileSystem_AllowedSearchPath( const char *pchPath ) return true; } +#endif diff --git a/src/public/filesystem_init.h b/src/public/filesystem_init.h index 9274a5cb137..8161701cd73 100644 --- a/src/public/filesystem_init.h +++ b/src/public/filesystem_init.h @@ -209,6 +209,13 @@ void FileSystem_ClearSteamEnvVars(); // Find the steam.cfg above you for optional stuff FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ); +#ifndef SDK_MP +// Setup the Steam.dll path without needing all the extra gameinfo stuff first +// used by the CSteamApplication::Create() code to LoadModule() on the filesystem +// before the underlying apps know specific details about the environment to load +FSReturnCode_t FileSystem_SetupSteamInstallPath(); +#endif + // Returns the last error. const char *FileSystem_GetLastErrorString(); diff --git a/src/public/filesystem_passthru.h b/src/public/filesystem_passthru.h index 1bdcea7054f..a7294fe17af 100644 --- a/src/public/filesystem_passthru.h +++ b/src/public/filesystem_passthru.h @@ -120,9 +120,14 @@ class CFileSystemPassThru : public CInternalFileSystemPassThru virtual const char *FindNext( FileFindHandle_t handle ) { return m_pFileSystemPassThru->FindNext( handle ); } virtual bool FindIsDirectory( FileFindHandle_t handle ) { return m_pFileSystemPassThru->FindIsDirectory( handle ); } virtual void FindClose( FileFindHandle_t handle ) { m_pFileSystemPassThru->FindClose( handle ); } +#ifdef SDK_MP virtual const char *GetLocalPath( const char *pFileName, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars ) { return m_pFileSystemPassThru->GetLocalPath( pFileName, pDest, maxLenInChars ); } virtual bool FullPathToRelativePath( const char *pFullpath, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars ) { return m_pFileSystemPassThru->FullPathToRelativePath( pFullpath, pDest, maxLenInChars ); } virtual bool GetCaseCorrectFullPath_Ptr( const char *pFullPath, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars ) { return m_pFileSystemPassThru->GetCaseCorrectFullPath_Ptr( pFullPath, pDest, maxLenInChars ); } +#else + virtual const char *GetLocalPath( const char *pFileName, char *pLocalPath, int localPathBufferSize ) { return m_pFileSystemPassThru->GetLocalPath( pFileName, pLocalPath, localPathBufferSize ); } + virtual bool FullPathToRelativePath( const char *pFullpath, char *pRelative, int maxlen ) { return m_pFileSystemPassThru->FullPathToRelativePath( pFullpath, pRelative, maxlen ); } +#endif virtual bool GetCurrentDirectory( char* pDirectory, int maxlen ) { return m_pFileSystemPassThru->GetCurrentDirectory( pDirectory, maxlen ); } virtual void PrintOpenedFiles( void ) { m_pFileSystemPassThru->PrintOpenedFiles(); } virtual void PrintSearchPaths( void ) { m_pFileSystemPassThru->PrintSearchPaths(); } @@ -175,8 +180,13 @@ class CFileSystemPassThru : public CInternalFileSystemPassThru virtual FSAsyncStatus_t AsyncSetPriority(FSAsyncControl_t hControl, int newPriority) { return m_pFileSystemPassThru->AsyncSetPriority(hControl, newPriority); } virtual bool AsyncSuspend() { return m_pFileSystemPassThru->AsyncSuspend(); } virtual bool AsyncResume() { return m_pFileSystemPassThru->AsyncResume(); } +#ifdef SDK_MP virtual const char *RelativePathToFullPath( const char *pFileName, const char *pPathID, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t *pPathType = NULL ) { return m_pFileSystemPassThru->RelativePathToFullPath( pFileName, pPathID, pDest, maxLenInChars, pathFilter, pPathType ); } virtual int GetSearchPath( const char *pathID, bool bGetPackFiles, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars ) { return m_pFileSystemPassThru->GetSearchPath( pathID, bGetPackFiles, pDest, maxLenInChars ); } +#else + virtual const char *RelativePathToFullPath( const char *pFileName, const char *pPathID, char *pLocalPath, int localPathBufferSize, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t *pPathType = NULL ) { return m_pFileSystemPassThru->RelativePathToFullPath( pFileName, pPathID, pLocalPath, localPathBufferSize, pathFilter, pPathType ); } + virtual int GetSearchPath( const char *pathID, bool bGetPackFiles, char *pPath, int nMaxLen ) { return m_pFileSystemPassThru->GetSearchPath( pathID, bGetPackFiles, pPath, nMaxLen ); } +#endif virtual FileHandle_t OpenEx( const char *pFileName, const char *pOptions, unsigned flags = 0, const char *pathID = 0, char **ppszResolvedFilename = NULL ) { return m_pFileSystemPassThru->OpenEx( pFileName, pOptions, flags, pathID, ppszResolvedFilename );} virtual int ReadEx( void* pOutput, int destSize, int size, FileHandle_t file ) { return m_pFileSystemPassThru->ReadEx( pOutput, destSize, size, file ); } @@ -209,7 +219,11 @@ class CFileSystemPassThru : public CInternalFileSystemPassThru virtual void EndMapAccess() { m_pFileSystemPassThru->EndMapAccess(); } virtual bool ReadToBuffer( FileHandle_t hFile, CUtlBuffer &buf, int nMaxBytes = 0, FSAllocFunc_t pfnAlloc = NULL ) { return m_pFileSystemPassThru->ReadToBuffer( hFile, buf, nMaxBytes, pfnAlloc ); } +#ifdef SDK_MP virtual bool FullPathToRelativePathEx( const char *pFullPath, const char *pPathId, OUT_Z_CAP(maxLenInChars) char *pDest, int maxLenInChars ) { return m_pFileSystemPassThru->FullPathToRelativePathEx( pFullPath, pPathId, pDest, maxLenInChars ); } +#else + virtual bool FullPathToRelativePathEx( const char *pFullPath, const char *pPathId, char *pRelative, int nMaxLen ) { return m_pFileSystemPassThru->FullPathToRelativePathEx( pFullPath, pPathId, pRelative, nMaxLen ); } +#endif virtual int GetPathIndex( const FileNameHandle_t &handle ) { return m_pFileSystemPassThru->GetPathIndex( handle ); } virtual long GetPathTime( const char *pPath, const char *pPathID ) { return m_pFileSystemPassThru->GetPathTime( pPath, pPathID ); } @@ -247,10 +261,10 @@ class CFileSystemPassThru : public CInternalFileSystemPassThru { return m_pFileSystemPassThru->CheckVPKFileHash( PackFileID, nPackFileNumber, nFileFraction, md5Value ); } virtual void NotifyFileUnloaded( const char *pszFilename, const char *pPathId ) OVERRIDE { m_pFileSystemPassThru->NotifyFileUnloaded( pszFilename, pPathId ); } - +#ifdef SDK_MP virtual void SetWriteProtectionEnable( bool bEnable ) { m_pFileSystemPassThru->SetWriteProtectionEnable( bEnable ); } virtual bool GetWriteProtectionEnable() const { return m_pFileSystemPassThru->GetWriteProtectionEnable(); } - +#endif protected: IFileSystem *m_pFileSystemPassThru; diff --git a/src/public/game/client/IGameClientExports.h b/src/public/game/client/IGameClientExports.h index 764eb1c0f29..9622481d96a 100644 --- a/src/public/game/client/IGameClientExports.h +++ b/src/public/game/client/IGameClientExports.h @@ -45,7 +45,9 @@ abstract_class IGameClientExports : public IBaseInterface //============================================================================= virtual const char *GetHolidayString() = 0; +#ifdef SDK_MP virtual const char *GetOperationString() = 0; +#endif }; #define GAMECLIENTEXPORTS_INTERFACE_VERSION "GameClientExports001" diff --git a/src/public/game/client/iviewport.h b/src/public/game/client/iviewport.h index b09b1666e9c..e01ae7f10ac 100644 --- a/src/public/game/client/iviewport.h +++ b/src/public/game/client/iviewport.h @@ -20,7 +20,9 @@ #include "viewport_panel_names.h" +#ifdef SDK_MP #include "inputsystem/InputEnums.h" +#endif class KeyValues; @@ -39,7 +41,9 @@ abstract_class IViewPortPanel virtual void ShowPanel( bool state ) = 0; // activate VGUI Frame +#ifdef SDK_MP virtual GameActionSet_t GetPreferredActionSet() = 0; +#endif // VGUI functions: virtual vgui::VPANEL GetVPanel( void ) = 0; // returns VGUI panel handle diff --git a/src/public/gamebspfile.h b/src/public/gamebspfile.h index 4f9996f7747..be9e0450d07 100644 --- a/src/public/gamebspfile.h +++ b/src/public/gamebspfile.h @@ -21,6 +21,7 @@ //----------------------------------------------------------------------------- // This enumerations defines all the four-CC codes for the client lump names //----------------------------------------------------------------------------- +#ifdef SDK_MP enum { GAMELUMP_DETAIL_PROPS = 'dprp', @@ -28,13 +29,28 @@ enum GAMELUMP_STATIC_PROPS = 'sprp', GAMELUMP_DETAIL_PROP_LIGHTING_HDR = 'dplh', }; +#else +// TODO: We may have some endian considerations here! +#define GAMELUMP_MAKE_CODE(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d) << 0) +enum +{ + GAMELUMP_DETAIL_PROPS = GAMELUMP_MAKE_CODE('d', 'p', 'r', 'p'), + GAMELUMP_DETAIL_PROP_LIGHTING = GAMELUMP_MAKE_CODE('d', 'p', 'l', 't'), + GAMELUMP_STATIC_PROPS = GAMELUMP_MAKE_CODE('s', 'p', 'r', 'p'), + GAMELUMP_DETAIL_PROP_LIGHTING_HDR = GAMELUMP_MAKE_CODE('d', 'p', 'l', 'h'), +}; +#endif // Versions... enum { GAMELUMP_DETAIL_PROPS_VERSION = 4, GAMELUMP_DETAIL_PROP_LIGHTING_VERSION = 0, +#ifdef SDK_MP GAMELUMP_STATIC_PROPS_VERSION = 10, +#else + GAMELUMP_STATIC_PROPS_VERSION = 6, +#endif GAMELUMP_STATIC_PROP_LIGHTING_VERSION = 0, GAMELUMP_DETAIL_PROP_LIGHTING_HDR_VERSION = 0, }; @@ -137,9 +153,13 @@ enum STATIC_PROP_NO_SELF_SHADOWING = 0x80, // disable self shadowing in vrad +#ifdef SDK_MP STATIC_PROP_NO_PER_TEXEL_LIGHTING = 0x100, // whether we should do per-texel lightmaps in vrad. STATIC_PROP_WC_MASK = 0x1d8, // all flags settable in hammer (?) +#else + STATIC_PROP_WC_MASK = 0xd8, // all flags settable in hammer (?) +#endif }; struct StaticPropDictLump_t @@ -183,7 +203,11 @@ struct StaticPropLumpV5_t // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump }; +#ifdef SDK_MP struct StaticPropLumpV6_t +#else +struct StaticPropLump_t +#endif { DECLARE_BYTESWAP_DATADESC(); Vector m_Origin; @@ -203,6 +227,7 @@ struct StaticPropLumpV6_t // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump }; +#ifdef SDK_MP struct StaticPropLump_t { DECLARE_BYTESWAP_DATADESC(); @@ -269,6 +294,7 @@ struct StaticPropLump_t return *this; } }; +#endif diff --git a/src/public/haptics/haptic_utils.cpp b/src/public/haptics/haptic_utils.cpp index e6d3288a5ca..ed77c7bb09f 100644 --- a/src/public/haptics/haptic_utils.cpp +++ b/src/public/haptics/haptic_utils.cpp @@ -138,7 +138,7 @@ void ConnectHaptics(CreateInterfaceFn appFactory) HookHapticMessages(); } -#if _MSC_VER >= 1925 +#if _MSC_VER >= 1925 && !defined(SDK_MP) // deleting haptics results in a warning about deleting something with a non-virtual destructor // big yikes but we can't do anything about it as it's accessed via interface #pragma warning (disable: 5205) diff --git a/src/public/iachievementmgr.h b/src/public/iachievementmgr.h index f6cafd8e8fa..1637f5c245c 100644 --- a/src/public/iachievementmgr.h +++ b/src/public/iachievementmgr.h @@ -46,7 +46,9 @@ abstract_class IAchievementMgr virtual void SaveGlobalStateIfDirty( bool bAsync ) = 0; virtual bool HasAchieved( const char *pchName ) = 0; virtual bool WereCheatsEverOn() = 0; +#ifdef SDK_MP virtual void ResetAchievements() = 0; +#endif }; // flags for IAchievement::GetFlags diff --git a/src/public/ibsppack.h b/src/public/ibsppack.h index 3f115d788e2..e62a3767c7e 100644 --- a/src/public/ibsppack.h +++ b/src/public/ibsppack.h @@ -28,12 +28,14 @@ abstract_class IBSPPack virtual void SetHDRMode( bool bHDR ) = 0; virtual bool SwapBSPFile( IFileSystem *pFileSystem, const char *filename, const char *swapFilename, bool bSwapOnLoad, VTFConvertFunc_t pVTFConvertFunc, VHVFixupFunc_t pVHVFixupFunc, CompressFunc_t pCompressFunc ) = 0; +#ifdef SDK_MP enum eRepackBSPFlags { eRepackBSP_CompressLumps = 1 << 0, eRepackBSP_CompressPackfile = 1 << 1 }; virtual bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, eRepackBSPFlags repackFlags ) = 0; +#endif // used to get/set the pak file from a BSP virtual bool GetPakFileLump( IFileSystem *pFileSystem, const char *pBSPFilename, void **pPakData, int *pPakSize ) = 0; @@ -43,6 +45,10 @@ abstract_class IBSPPack virtual bool GetBSPDependants( IFileSystem *pFileSystem, const char *pBSPFilename, CUtlVector< CUtlString > *pList ) = 0; }; +#ifdef SDK_MP #define IBSPPACK_VERSION_STRING "IBSPPACK004" +#else +#define IBSPPACK_VERSION_STRING "IBSPPACK003" +#endif #endif // IBSPPACK_H diff --git a/src/public/iclientnetworkable.h b/src/public/iclientnetworkable.h index 6ecb362b3a6..2a4dcff6f8b 100644 --- a/src/public/iclientnetworkable.h +++ b/src/public/iclientnetworkable.h @@ -100,7 +100,9 @@ abstract_class IClientNetworkable // an uncompressed update that's caused it to destroy all entities & recreate them. virtual void SetDestroyedOnRecreateEntities( void ) = 0; +#ifdef SDK_MP virtual void OnDataUnchangedInPVS() = 0; +#endif }; diff --git a/src/public/icvar.h b/src/public/icvar.h index 50176805c0e..d4cf80954e4 100644 --- a/src/public/icvar.h +++ b/src/public/icvar.h @@ -87,9 +87,15 @@ abstract_class ICvar : public IAppSystem // Install a console printer virtual void InstallConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0; virtual void RemoveConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0; +#ifdef SDK_MP virtual void ConsoleColorPrintf( const Color& clr, PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 3, 4 ) = 0; virtual void ConsolePrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 0; virtual void ConsoleDPrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 0; +#else + virtual void ConsoleColorPrintf( const Color& clr, PRINTF_FORMAT_STRING const char *pFormat, ... ) const = 0; + virtual void ConsolePrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const = 0; + virtual void ConsoleDPrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const = 0; +#endif // Reverts cvars which contain a specific flag virtual void RevertFlaggedConVars( int nFlag ) = 0; diff --git a/src/public/ienginevgui.h b/src/public/ienginevgui.h index cf89648d4f3..44d517b825f 100644 --- a/src/public/ienginevgui.h +++ b/src/public/ienginevgui.h @@ -15,7 +15,9 @@ #include "interface.h" #include "vgui/VGUI.h" +#ifdef SDK_MP #include "eiface.h" +#endif // Forward declarations. namespace vgui @@ -32,7 +34,9 @@ enum VGuiPanel_t PANEL_INGAMESCREENS, PANEL_GAMEDLL, PANEL_CLIENTDLL_TOOLS, +#ifdef SDK_MP PANEL_SIZING, +#endif }; // In-game panels are cropped to the current engine viewport size @@ -52,11 +56,17 @@ abstract_class IEngineVGui virtual bool IsGameUIVisible() = 0; +#ifdef SDK_MP virtual bool GetWorkshopMap( uint32 uIndex, WorkshopMapDesc_t *pDesc ) = 0; +#endif }; +#ifdef SDK_MP #define VENGINE_VGUI_VERSION "VEngineVGui002" #define VENGINE_VGUI_VERSION_OLD "VEngineVGui001" +#else +#define VENGINE_VGUI_VERSION "VEngineVGui001" +#endif #if defined(_STATIC_LINKED) && defined(CLIENT_DLL) namespace Client diff --git a/src/public/igameevents.h b/src/public/igameevents.h index 43ce3417d43..a3ddd6fee29 100644 --- a/src/public/igameevents.h +++ b/src/public/igameevents.h @@ -62,6 +62,7 @@ data field should not be broadcasted to clients, use the type "local". class KeyValues; class CGameEvent; +#ifdef SDK_MP // Class for visiting every key of data on an event abstract_class IGameEventVisitor2 { @@ -75,6 +76,7 @@ abstract_class IGameEventVisitor2 virtual bool VisitWString( const char* name, const wchar_t* value ) { return true; } virtual bool VisitBool( const char* name, bool value ) { return true; } }; +#endif abstract_class IGameEvent { @@ -87,16 +89,24 @@ abstract_class IGameEvent virtual bool IsEmpty(const char *keyName = NULL) = 0; // check if data field exists // Data access +#ifdef SDK_MP virtual bool GetBool( const char *keyName = NULL, bool defaultValue = false ) const = 0; virtual int GetInt( const char *keyName = NULL, int defaultValue = 0 ) const = 0; virtual float GetFloat( const char *keyName = NULL, float defaultValue = 0.0f ) const = 0; virtual const char *GetString( const char *keyName = NULL, const char *defaultValue = "" ) const = 0; +#else + virtual bool GetBool( const char *keyName = NULL, bool defaultValue = false ) = 0; + virtual int GetInt( const char *keyName = NULL, int defaultValue = 0 ) = 0; + virtual float GetFloat( const char *keyName = NULL, float defaultValue = 0.0f ) = 0; + virtual const char *GetString( const char *keyName = NULL, const char *defaultValue = "" ) = 0; +#endif virtual void SetBool( const char *keyName, bool value ) = 0; virtual void SetInt( const char *keyName, int value ) = 0; virtual void SetFloat( const char *keyName, float value ) = 0; virtual void SetString( const char *keyName, const char *value ) = 0; +#ifdef SDK_MP // New stuff! virtual uint64 GetUint64( const char *keyName = NULL, uint64 defaultValue = 0 ) const = 0; virtual const wchar_t *GetWString( const char *keyName = NULL, const wchar_t *defaultValue = L"" ) const = 0; @@ -110,6 +120,7 @@ abstract_class IGameEvent // returns true if iteration aborted normally, false if it was aborted by the visitor callback virtual bool ForEventData( IGameEventVisitor2* event ) const = 0; +#endif }; diff --git a/src/public/inetchannel.h b/src/public/inetchannel.h index 9ba67e7396e..42acb98ee61 100644 --- a/src/public/inetchannel.h +++ b/src/public/inetchannel.h @@ -28,6 +28,10 @@ abstract_class INetChannel : public INetChannelInfo virtual void SetDataRate(float rate) = 0; virtual bool RegisterMessage(INetMessage *msg) = 0; +#ifndef SDK_MP + virtual bool StartStreaming( unsigned int challengeNr ) = 0; + virtual void ResetStreaming( void ) = 0; +#endif virtual void SetTimeout(float seconds) = 0; virtual void SetDemoRecorder(IDemoRecorder *recorder) = 0; virtual void SetChallengeNr(unsigned int chnr) = 0; @@ -37,6 +41,9 @@ abstract_class INetChannel : public INetChannelInfo virtual void Shutdown(const char *reason) = 0; virtual void ProcessPlayback( void ) = 0; +#ifndef SDK_MP + virtual bool ProcessStream( void ) = 0; +#endif virtual void ProcessPacket( struct netpacket_s* packet, bool bHasHeader ) = 0; virtual bool SendNetMsg(INetMessage &msg, bool bForceReliable = false, bool bVoice = false ) = 0; diff --git a/src/public/inetmessage.h b/src/public/inetmessage.h index 7a0da427ff7..cafdf9d63a7 100644 --- a/src/public/inetmessage.h +++ b/src/public/inetmessage.h @@ -41,9 +41,11 @@ class INetMessage virtual INetChannel *GetNetChannel( void ) const = 0; virtual const char *ToString( void ) const = 0; // returns a human readable string about message content +#ifdef SDK_MP virtual bool BIncomingMessageForProcessing( double dblNetTime, int numBytes ) = 0; virtual size_t GetSize() const = 0; +#endif }; diff --git a/src/public/inetmsghandler.h b/src/public/inetmsghandler.h index 79c299a2dbc..ebea9c2ebcb 100644 --- a/src/public/inetmsghandler.h +++ b/src/public/inetmsghandler.h @@ -181,7 +181,9 @@ class IServerMessageHandler : public INetMessageHandler PROCESS_SVC_MESSAGE( GameEventList ) = 0; PROCESS_SVC_MESSAGE( GetCvarValue ) = 0; PROCESS_SVC_MESSAGE( CmdKeyValues ) = 0; +#ifdef SDK_MP PROCESS_SVC_MESSAGE( SetPauseTimed ) = 0; +#endif }; class MM_Heartbeat; diff --git a/src/public/inputsystem/ButtonCode.h b/src/public/inputsystem/ButtonCode.h index ee6cb29762f..a82d5e16bba 100644 --- a/src/public/inputsystem/ButtonCode.h +++ b/src/public/inputsystem/ButtonCode.h @@ -210,12 +210,21 @@ enum ButtonCode_t STEAMCONTROLLER_FIRST = JOYSTICK_LAST + 1 #endif +#ifdef SDK_MP // Steam Controller STEAMCONTROLLER_FIRST_BUTTON = STEAMCONTROLLER_FIRST, STEAMCONTROLLER_LAST_BUTTON = STEAMCONTROLLER_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS - 1, STEAMCONTROLLER_MAX_BUTTON_COUNT - 1 ), STEAMCONTROLLER_FIRST_AXIS_BUTTON, STEAMCONTROLLER_LAST_AXIS_BUTTON = STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS - 1, STEAMCONTROLLER_AXIS_BUTTON_COUNT - 1 ), STEAMCONTROLLER_LAST = STEAMCONTROLLER_LAST_AXIS_BUTTON, +#else + // Steam Controller stubs + STEAMCONTROLLER_FIRST_BUTTON = STEAMCONTROLLER_FIRST, + STEAMCONTROLLER_LAST_BUTTON = STEAMCONTROLLER_BUTTON_INTERNAL( 7, STEAMCONTROLLER_MAX_BUTTON_COUNT - 1 ), + STEAMCONTROLLER_FIRST_AXIS_BUTTON, + STEAMCONTROLLER_LAST_AXIS_BUTTON = STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( 7, STEAMCONTROLLER_AXIS_BUTTON_COUNT - 1 ), + STEAMCONTROLLER_LAST = STEAMCONTROLLER_LAST_AXIS_BUTTON, +#endif BUTTON_CODE_LAST, BUTTON_CODE_COUNT = BUTTON_CODE_LAST - KEY_FIRST + 1, @@ -458,7 +467,11 @@ inline ButtonCode_t ButtonCodeToJoystickButtonCode( ButtonCode_t code, int nDesi if ( IsJoystickCode( code ) && !IsSteamControllerCode( code ) ) nDesiredJoystick = clamp( nDesiredJoystick, 0, MAX_JOYSTICKS - 1 ); else +#ifdef SDK_MP nDesiredJoystick = clamp( nDesiredJoystick, 0, MAX_STEAM_CONTROLLERS - 1 ); +#else + nDesiredJoystick = clamp( nDesiredJoystick, 0, 7 ); +#endif code = GetBaseButtonCode( code ); diff --git a/src/public/inputsystem/iinputsystem.h b/src/public/inputsystem/iinputsystem.h index d53496ea32d..cfb7489ff96 100644 --- a/src/public/inputsystem/iinputsystem.h +++ b/src/public/inputsystem/iinputsystem.h @@ -17,7 +17,9 @@ #include "inputsystem/ButtonCode.h" #include "inputsystem/AnalogCode.h" +#ifdef SDK_MP #include "steam/isteamcontroller.h" +#endif //----------------------------------------------------------------------------- // Main interface for input. This is a low-level interface @@ -127,6 +129,7 @@ abstract_class IInputSystem : public IAppSystem // being initialized. virtual void SetConsoleTextMode( bool bConsoleTextMode ) = 0; +#ifdef SDK_MP virtual ISteamController* SteamControllerInterface() = 0; virtual uint32 GetNumSteamControllersConnected() = 0; virtual bool IsSteamControllerActive() = 0; @@ -156,6 +159,7 @@ abstract_class IInputSystem : public IAppSystem void ActivateSteamControllerActionSet( GameActionSet_t eActionSet ) { ActivateSteamControllerActionSetForSlot( 0xffffffffffffffff, eActionSet ); } +#endif }; diff --git a/src/public/iserver.h b/src/public/iserver.h index 4c038925f70..d0a9445e316 100644 --- a/src/public/iserver.h +++ b/src/public/iserver.h @@ -13,7 +13,9 @@ #include #include #include +#ifdef SDK_MP #include +#endif class INetMessage; class IRecipientFilter; @@ -32,9 +34,13 @@ abstract_class IServer : public IConnectionlessPacketHandler virtual int GetMaxClients( void ) const = 0; // returns current client limit virtual IClient *GetClient( int index ) = 0; // returns interface to client virtual int GetClientCount() const = 0; // returns number of clients slots (used & unused) +#ifdef SDK_MP virtual netadr_t GetPublicAddress( void ) const = 0; // returns public IP:port that should be advertised in server browser, etc. (If any!) virtual bool IsUsingFakeIP() const = 0; // Returns true if we're using FakeIP. (If so, the value will be returned by GetPublicAddress(). note that it might be invalid if FakeIP allocation hasn't finished yet!" virtual int GetLocalUDPPort( void ) const = 0; // returns current UDP port we are actually listening on, if any +#else + virtual int GetUDPPort( void ) const = 0; // returns current used UDP port +#endif virtual float GetTime( void ) const = 0; // returns game world time virtual int GetTick( void ) const = 0; // returns game world tick virtual float GetTickInterval( void ) const = 0; // tick interval in seconds diff --git a/src/public/istudiorender.h b/src/public/istudiorender.h index ffdc253740e..580b9b1ad20 100644 --- a/src/public/istudiorender.h +++ b/src/public/istudiorender.h @@ -178,6 +178,7 @@ struct DrawModelResults_t CUtlVectorFixed m_Materials; }; +#ifdef SDK_MP struct ColorTexelsInfo_t { int m_nWidth; @@ -187,6 +188,7 @@ struct ColorTexelsInfo_t int m_nByteCount; byte* m_pTexelData; }; +#endif struct ColorMeshInfo_t { @@ -196,8 +198,10 @@ struct ColorMeshInfo_t IPooledVBAllocator * m_pPooledVBAllocator; int m_nVertOffsetInBytes; int m_nNumVerts; +#ifdef SDK_MP ITexture * m_pLightmap; ColorTexelsInfo_t * m_pLightmapData; +#endif }; struct DrawModelInfo_t @@ -377,7 +381,9 @@ abstract_class IStudioRender : public IAppSystem // draw an array of models with the same state virtual void DrawModelArray( const DrawModelInfo_t &drawInfo, int arrayCount, model_array_instance_t *pInstanceData, int instanceStride, int flags = STUDIORENDER_DRAW_ENTIRE_MODEL ) = 0; +#ifdef SDK_MP virtual void GetMaterialOverride( IMaterial** ppOutForcedMaterial, OverrideType_t* pOutOverrideType ) = 0; +#endif }; extern IStudioRender *g_pStudioRender; diff --git a/src/public/keyframe/keyframe.cpp b/src/public/keyframe/keyframe.cpp index 8f0575aae27..0045708108b 100644 --- a/src/public/keyframe/keyframe.cpp +++ b/src/public/keyframe/keyframe.cpp @@ -154,7 +154,7 @@ class CPositionInterpolator_Linear : public IPositionInterpolator { public: virtual void Release(); - virtual void GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ); + virtual void GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ); virtual void SetKeyPosition( int keyNum, Vector const &vPos ); virtual void InterpolatePosition( float time, Vector &vOut ); virtual bool ProcessKey( char const *pName, char const *pValue ) { return false; } @@ -171,7 +171,7 @@ void CPositionInterpolator_Linear::Release() { } -void CPositionInterpolator_Linear::GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ) +void CPositionInterpolator_Linear::GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ) { *outName = "Linear"; *outMinKeyReq = 0; @@ -201,7 +201,7 @@ class CPositionInterpolator_CatmullRom : public IPositionInterpolator { public: virtual void Release(); - virtual void GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ); + virtual void GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ); virtual void SetKeyPosition( int keyNum, Vector const &vPos ); virtual void InterpolatePosition( float time, Vector &vOut ); virtual bool ProcessKey( char const *pName, char const *pValue ) { return false; } @@ -218,7 +218,7 @@ void CPositionInterpolator_CatmullRom::Release() { } -void CPositionInterpolator_CatmullRom::GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ) +void CPositionInterpolator_CatmullRom::GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ) { *outName = "Catmull-Rom Spline"; *outMinKeyReq = -1; @@ -282,7 +282,7 @@ class CPositionInterpolator_Rope final : public IPositionInterpolator CPositionInterpolator_Rope(); virtual void Release(); - virtual void GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ); + virtual void GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ); virtual void SetKeyPosition( int keyNum, Vector const &vPos ); virtual void InterpolatePosition( float time, Vector &vOut ); virtual bool ProcessKey( char const *pName, char const *pValue ); @@ -319,7 +319,7 @@ void CPositionInterpolator_Rope::Release() delete this; } -void CPositionInterpolator_Rope::GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ) +void CPositionInterpolator_Rope::GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ) { *outName = "Rope"; *outMinKeyReq = 0; @@ -433,7 +433,7 @@ typedef void (*RotationInterpolatorFunc_t)(float time, Quaternion &outRot); typedef struct { - const char *szName; + POS_INTERP_CONST char *szName; RotationInterpolatorFunc_t pFunc; // defines the range of keys this interpolator needs to function @@ -458,7 +458,7 @@ int Motion_GetNumberOfRotationInterpolators( void ) return ARRAYSIZE(g_RotationInterpolators); } -bool Motion_GetRotationInterpolatorDetails( int rotInterpNum, const char **outName, int *outMinKeyReq, int *outMaxKeyReq ) +bool Motion_GetRotationInterpolatorDetails( int rotInterpNum, POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ) { if ( rotInterpNum < 0 || rotInterpNum >= Motion_GetNumberOfRotationInterpolators() ) { diff --git a/src/public/keyframe/keyframe.h b/src/public/keyframe/keyframe.h index 4ee04824391..42ea801e59a 100644 --- a/src/public/keyframe/keyframe.h +++ b/src/public/keyframe/keyframe.h @@ -8,13 +8,19 @@ #define KEYFRAME_H #pragma once +// Very ugly, but not as bad as putting ifdefs everywhere this is used +#ifdef SDK_MP +#define POS_INTERP_CONST const +#else +#define POS_INTERP_CONST +#endif class IPositionInterpolator { public: virtual void Release() = 0; - virtual void GetDetails( const char **outName, int *outMinKeyReq, int *outMaxKeyReq ) = 0; + virtual void GetDetails( POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ) = 0; virtual void SetKeyPosition( int keyNum, Vector const &vPos ) = 0; virtual void InterpolatePosition( float time, Vector &vOut ) = 0; @@ -34,7 +40,7 @@ IPositionInterpolator* Motion_GetPositionInterpolator( int interpNum ); // Rotation interpolators. int Motion_GetNumberOfRotationInterpolators( void ); -bool Motion_GetRotationInterpolatorDetails( int rotInterpNum, const char **outName, int *outMinKeyReq, int *outMaxKeyReq ); +bool Motion_GetRotationInterpolatorDetails( int rotInterpNum, POS_INTERP_CONST char **outName, int *outMinKeyReq, int *outMaxKeyReq ); bool Motion_InterpolateRotation( float time, int interpFuncNum, Quaternion &outQuatRotation ); bool Motion_SetKeyAngles( int keyNum, Quaternion &quatAngles ); diff --git a/src/public/materialsystem/IShader.h b/src/public/materialsystem/IShader.h index 7815e8aa100..b851b3e32b7 100644 --- a/src/public/materialsystem/IShader.h +++ b/src/public/materialsystem/IShader.h @@ -21,9 +21,13 @@ // it's not 256, because you can't use all 256 slots in 10.5.x. // use this constant everywhere you might normally use "256" in reference to a parameter array size. // The highest shader constant is c218, plus we allocate c219 and c220 for two clip planes +#ifdef SDK_MP #define DXABSTRACT_VS_PARAM_SLOTS 228 -#define DXABSTRACT_VS_FIRST_BONE_SLOT VERTEX_SHADER_MODEL #define DXABSTRACT_VS_LAST_BONE_SLOT (VERTEX_SHADER_SHADER_SPECIFIC_CONST_13-1) +#else +#define DXABSTRACT_VS_PARAM_SLOTS 219 +#endif +#define DXABSTRACT_VS_FIRST_BONE_SLOT VERTEX_SHADER_MODEL // user clip plane 0 goes in DXABSTRACT_VS_CLIP_PLANE_BASE... plane 1 goes in the slot after that // dxabstract uses these constants to check plane index limit and to deliver planes to shader for DP4 -> oCLP[n] diff --git a/src/public/materialsystem/MaterialSystemUtil.h b/src/public/materialsystem/MaterialSystemUtil.h index ddabcd220b8..ca6df06ac28 100644 --- a/src/public/materialsystem/MaterialSystemUtil.h +++ b/src/public/materialsystem/MaterialSystemUtil.h @@ -72,10 +72,12 @@ class CTextureReference void Init( char const* pTexture, const char *pTextureGroupName, bool bComplain = true ); void InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, ImageFormat fmt, int nFlags ); void InitRenderTarget( int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL ); +#ifndef SDK_MP void InitRenderTarget(int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, const char* pStrOptionalName = NULL) { InitRenderTarget(w, h, sizeMode, fmt, depth, bHDR, const_cast(pStrOptionalName)); } +#endif #if defined( _X360 ) // used when RT coupling is disparate (texture is DDR based, surface is EDRAM based) void InitRenderTargetTexture( int width, int height, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL ); diff --git a/src/public/materialsystem/imaterialsystem.h b/src/public/materialsystem/imaterialsystem.h index 6265547eef7..b59bb6470e8 100644 --- a/src/public/materialsystem/imaterialsystem.h +++ b/src/public/materialsystem/imaterialsystem.h @@ -30,6 +30,9 @@ #include "vtf/vtf.h" #include "materialsystem/deformations.h" #include "materialsystem/IColorCorrection.h" +#ifdef SDK_SP +#include "renderparm.h" +#endif //----------------------------------------------------------------------------- @@ -67,6 +70,7 @@ typedef uint64 VertexFormat_t; // NOTE NOTE NOTE!!!! If you up this, grep for "NEW_INTERFACE" to see if there is anything // waiting to be enabled during an interface revision. +#ifdef SDK_MP // V081 - 10/25/2016 - Added new Suspend/Resume texture streaming interfaces. Might also have added more calls here due // to the streaming work that didn't get bumped, but we're not guarding versions on the TF branch // very judiciously since we need to audit them when merging to SDK branch either way. @@ -74,6 +78,9 @@ typedef uint64 VertexFormat_t; // misyl: unfrogged this interface to be compatible, added MATERIAL_SYSTEM_INTERFACE_VERSION_OLD for sdk 2013 compat. #define MATERIAL_SYSTEM_INTERFACE_VERSION "VMaterialSystem082" #define MATERIAL_SYSTEM_INTERFACE_VERSION_OLD "VMaterialSystem080" +#else +#define MATERIAL_SYSTEM_INTERFACE_VERSION "VMaterialSystem080" +#endif #ifdef POSIX #define ABSOLUTE_MINIMUM_DXLEVEL 90 @@ -104,7 +111,9 @@ enum ShaderParamType_t SHADER_PARAM_TYPE_MATRIX, SHADER_PARAM_TYPE_MATERIAL, SHADER_PARAM_TYPE_STRING, +#ifdef SDK_MP SHADER_PARAM_TYPE_MATRIX4X2 +#endif }; enum MaterialMatrixMode_t @@ -532,6 +541,7 @@ struct FlashlightState_t int m_nBottom; }; +#ifdef SDK_MP // Passed as the callback object to Async functions in the material system // so that callers don't have to worry about memory going out of scope before the // results return. @@ -545,6 +555,7 @@ abstract_class IAsyncTextureOperationReceiver : public IRefCounted virtual int GetRefCount() const = 0; }; +#endif //----------------------------------------------------------------------------- @@ -594,9 +605,10 @@ enum RenderTargetSizeMode_t RT_SIZE_OFFSCREEN=5, // Target of specified size, don't mess with dimensions RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP=6, // Same size as the frame buffer, rounded up if necessary for systems that can't do non-power of two textures. RT_SIZE_REPLAY_SCREENSHOT = 7, // Rounded down to power of 2, essentially... +#ifdef SDK_MP RT_SIZE_LITERAL = 8, // Use the size passed in. Don't clamp it to the frame buffer size. Really. RT_SIZE_LITERAL_PICMIP = 9 // Use the size passed in, don't clamp to the frame buffer size, but do apply picmip restrictions. - +#endif }; typedef void (*MaterialBufferReleaseFunc_t)( ); @@ -616,6 +628,7 @@ class CShadowMgr; DECLARE_POINTER_HANDLE( MaterialLock_t ); +#ifdef SDK_MP enum RenderBackend_t { RENDER_BACKEND_UNKNOWN, @@ -677,6 +690,7 @@ FORCEINLINE RenderBackend_t DetermineRenderBackend() return RENDER_BACKEND_VULKAN; #endif } +#endif //----------------------------------------------------------------------------- // @@ -1173,6 +1187,7 @@ abstract_class IMaterialSystem : public IAppSystem // returns the display device name that matches the adapter index we were started with virtual char *GetDisplayDeviceName() const = 0; +#ifdef SDK_MP // creates a texture suitable for use with materials from a raw stream of bits. // The bits will be retained by the material system and can be freed upon return. virtual ITexture* CreateTextureFromBits(int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits) = 0; @@ -1206,11 +1221,13 @@ abstract_class IMaterialSystem : public IAppSystem // operations that shouldn't take usage of textures as a signal to stream them in at full rez. virtual void SuspendTextureStreaming() = 0; virtual void ResumeTextureStreaming() = 0; +#endif }; extern IMaterialSystem *materials; extern IMaterialSystem *g_pMaterialSystem; +#ifdef SDK_MP FORCEINLINE bool IsOpenGL( void ) { #ifndef DX_TO_GL_ABSTRACTION @@ -1223,6 +1240,7 @@ FORCEINLINE bool IsVulkan( void ) { return g_pMaterialSystem->GetRenderBackend() == RENDER_BACKEND_VULKAN; } +#endif //----------------------------------------------------------------------------- // @@ -1683,6 +1701,7 @@ abstract_class IMatRenderContext : public IRefCounted virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0; +#ifdef SDK_MP // Create a texture from the specified src render target, then call pRecipient->OnAsyncCreateComplete from the main thread. // The texture will be created using the destination format, and will optionally have mipmaps generated. // In case of error, the provided callback function will be called with the error texture. @@ -1690,6 +1709,10 @@ abstract_class IMatRenderContext : public IRefCounted virtual void FogRadial( bool bRadial ) = 0; virtual bool GetFogRadial() = 0; +#else + FORCEINLINE void FogRadial( bool bRadial ) { SetIntRenderingParameter( INT_RENDERPARM_FOG_TYPE, bRadial ? MATERIAL_FOG_RANGE_RADIAL-1 : MATERIAL_FOG_LINEAR-1 ); } + //FORCEINLINE bool GetFogRadial() { return GetIntRenderingParameter( INT_RENDERPARM_FOG_TYPE ) == MATERIAL_FOG_RANGE_RADIAL; } +#endif }; template< class E > inline E* IMatRenderContext::LockRenderDataTyped( int nCount, const E* pSrcData ) diff --git a/src/public/materialsystem/imaterialsystemhardwareconfig.h b/src/public/materialsystem/imaterialsystemhardwareconfig.h index c7b75b87199..0d74120621a 100644 --- a/src/public/materialsystem/imaterialsystemhardwareconfig.h +++ b/src/public/materialsystem/imaterialsystemhardwareconfig.h @@ -26,6 +26,13 @@ FORCEINLINE bool IsEmulatingGL() return bIsEmulatingGL; } +#ifndef SDK_MP +FORCEINLINE bool IsOpenGL( void ) +{ + return IsPlatformOpenGL() || IsEmulatingGL(); +} +#endif + //----------------------------------------------------------------------------- // Material system interface version //----------------------------------------------------------------------------- @@ -86,7 +93,11 @@ class IMaterialSystemHardwareConfig virtual bool HasSetDeviceGammaRamp() const = 0; DEFCONFIGMETHOD( bool, SupportsCompressedTextures(), true ); virtual VertexCompressionType_t SupportsCompressedVertices() const = 0; +#ifdef SDK_MP virtual bool SupportsNormalMapCompression() const { return false; } +#else + DEFCONFIGMETHOD( bool, SupportsNormalMapCompression(), true ); +#endif DEFCONFIGMETHOD( bool, SupportsVertexAndPixelShaders(), true ); DEFCONFIGMETHOD( bool, SupportsPixelShaders_1_4(), true ); DEFCONFIGMETHOD( bool, SupportsStaticControlFlow(), true ); @@ -192,7 +203,9 @@ class IMaterialSystemHardwareConfig virtual bool SupportsBorderColor( void ) const = 0; virtual bool SupportsFetch4( void ) const = 0; +#ifdef SDK_MP virtual bool CanStretchRectFromTextures( void ) const = 0; +#endif inline bool ShouldAlwaysUseShaderModel2bShaders() const { return IsOpenGL(); } inline bool PlatformRequiresNonNullPixelShaders() const { return IsOpenGL(); } diff --git a/src/public/materialsystem/imaterialvar.h b/src/public/materialsystem/imaterialvar.h index 3ae4db88832..211be63f832 100644 --- a/src/public/materialsystem/imaterialvar.h +++ b/src/public/materialsystem/imaterialvar.h @@ -239,7 +239,11 @@ class IMaterialVar m_nTempIndex = nIndex; } +#ifdef SDK_MP + friend void EnableThreadedMaterialVarAccess( bool bEnable, IMaterialVar **ppParams, int nVarCount ); +#else friend void EnableThreadedMaterialVarAccess( bool bEnable ); +#endif }; #endif // IMATERIALVAR_H diff --git a/src/public/materialsystem/imesh.h b/src/public/materialsystem/imesh.h index b43ef931bf3..5aa92e51bbf 100644 --- a/src/public/materialsystem/imesh.h +++ b/src/public/materialsystem/imesh.h @@ -19,7 +19,7 @@ #include "tier2/meshutils.h" #include "mathlib/mathlib.h" -#if defined( OSX ) +#if defined( OSX ) || (!defined(SDK_MP) && defined( DX_TO_GL_ABSTRACTION )) // Needed to support older versions of MacOS. // No longer needed on Linux as we have BGRA there. #define OPENGL_SWAP_COLORS @@ -216,6 +216,7 @@ inline void IncrementFloatPointer( float* &pBufferPointer, int vertexSize ) pBufferPointer = reinterpret_cast( reinterpret_cast( pBufferPointer ) + vertexSize ); } +#ifdef SDK_MP inline int PackRGBToPlatformColor( int r, int g, int b, int a ) { #if defined( OPENGL_SWAP_COLORS ) @@ -227,6 +228,7 @@ inline int PackRGBToPlatformColor( int r, int g, int b, int a ) #endif return col; } +#endif //----------------------------------------------------------------------------- // Used in lists of indexed primitives. diff --git a/src/public/materialsystem/ishadersystem_declarations.h b/src/public/materialsystem/ishadersystem_declarations.h index 905813cc335..82ffbed52bb 100644 --- a/src/public/materialsystem/ishadersystem_declarations.h +++ b/src/public/materialsystem/ishadersystem_declarations.h @@ -123,6 +123,9 @@ enum PrecompiledShaderType_t enum { // runtime flags +#ifndef SDK_MP + SHADER_DYNAMIC_COMPILE_IS_HLSL = 0x1, +#endif SHADER_IS_ASM = 0x1, SHADER_FAILED_LOAD = 0x2, }; diff --git a/src/public/materialsystem/itexture.h b/src/public/materialsystem/itexture.h index db6ddcb3377..9516a2c458a 100644 --- a/src/public/materialsystem/itexture.h +++ b/src/public/materialsystem/itexture.h @@ -125,6 +125,7 @@ abstract_class ITexture // Save texture to a file. virtual bool SaveToFile( const char *fileName ) = 0; +#ifdef SDK_MP // Copy this texture, which must be a render target or a renderable texture, to the destination texture, // which must have been created with the STAGING bit. virtual void CopyToStagingTexture( ITexture* pDstTex ) = 0; @@ -134,6 +135,7 @@ abstract_class ITexture // Download textures, except return true if we were successful and false if we were not. virtual bool BDownload( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) = 0; +#endif }; diff --git a/src/public/materialsystem/materialsystem_config.h b/src/public/materialsystem/materialsystem_config.h index 4b5e195e1dd..954b00e88f4 100644 --- a/src/public/materialsystem/materialsystem_config.h +++ b/src/public/materialsystem/materialsystem_config.h @@ -34,8 +34,10 @@ enum MaterialSystem_Config_Flags_t MATSYS_VIDCFG_FLAGS_USING_MULTIPLE_WINDOWS = ( 1 << 15 ), MATSYS_VIDCFG_FLAGS_DISABLE_PHONG = ( 1 << 16 ), MATSYS_VIDCFG_FLAGS_VR_MODE = ( 1 << 17 ), +#ifdef SDK_MP MATSYS_VIDCFG_FLAGS_NO_WINDOW_BORDER = ( 1 << 18 ), MATSYS_VIDCFG_FLAGS_LIGHTMAP_BICUBIC = ( 1 << 19 ), +#endif }; struct MaterialSystemHardwareIdentifier_t @@ -48,7 +50,9 @@ struct MaterialSystemHardwareIdentifier_t struct MaterialSystem_Config_t { bool Windowed() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_WINDOWED ) != 0; } +#ifdef SDK_MP bool NoWindowBorder() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_NO_WINDOW_BORDER ) != 0; } +#endif bool Resizing() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_RESIZING ) != 0; } #ifdef CSS_PERF_TEST bool WaitForVSync() const { return false; }//( m_Flags & MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC ) == 0; } @@ -63,7 +67,9 @@ struct MaterialSystem_Config_t bool UseParallaxMapping() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING ) != 0; } bool UseZPrefill() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_USE_Z_PREFILL ) != 0; } bool ReduceFillrate() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE ) != 0; } +#ifdef SDK_MP bool LightmapBicubic() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_LIGHTMAP_BICUBIC ) != 0; } +#endif bool HDREnabled() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_ENABLE_HDR ) != 0; } bool LimitWindowedSize() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_LIMIT_WINDOWED_SIZE ) != 0; } bool ScaleToOutputResolution() const { return ( m_Flags & MATSYS_VIDCFG_FLAGS_SCALE_TO_OUTPUT_RESOLUTION ) != 0; } @@ -154,7 +160,9 @@ struct MaterialSystem_Config_t // video config defaults SetFlag( MATSYS_VIDCFG_FLAGS_WINDOWED, false ); +#ifdef SDK_MP SetFlag( MATSYS_VIDCFG_FLAGS_NO_WINDOW_BORDER, false ); +#endif SetFlag( MATSYS_VIDCFG_FLAGS_RESIZING, false ); SetFlag( MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC, true ); SetFlag( MATSYS_VIDCFG_FLAGS_STENCIL, false ); @@ -165,7 +173,9 @@ struct MaterialSystem_Config_t SetFlag( MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING, true ); SetFlag( MATSYS_VIDCFG_FLAGS_USE_Z_PREFILL, false ); SetFlag( MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE, false ); +#ifdef SDK_MP SetFlag( MATSYS_VIDCFG_FLAGS_LIGHTMAP_BICUBIC, false ); +#endif SetFlag( MATSYS_VIDCFG_FLAGS_LIMIT_WINDOWED_SIZE, false ); SetFlag( MATSYS_VIDCFG_FLAGS_SCALE_TO_OUTPUT_RESOLUTION, false ); SetFlag( MATSYS_VIDCFG_FLAGS_USING_MULTIPLE_WINDOWS, false ); diff --git a/src/public/mathlib/ssemath.h b/src/public/mathlib/ssemath.h index afe35dd3758..8834e7ec20c 100644 --- a/src/public/mathlib/ssemath.h +++ b/src/public/mathlib/ssemath.h @@ -174,17 +174,23 @@ extern const fltx4 Four_Negative_FLT_MAX; // -FLT_MAX, -FLT_MAX, -FLT_MAX, extern const fltx4 g_SIMD_0123; // 0 1 2 3 as float // external aligned integer constants -extern const ALIGN16 uint32 g_SIMD_clear_signmask[] ALIGN16_POST; // 0x7fffffff x 4 -extern const ALIGN16 uint32 g_SIMD_signmask[] ALIGN16_POST; // 0x80000000 x 4 -extern const ALIGN16 uint32 g_SIMD_lsbmask[] ALIGN16_POST; // 0xfffffffe x 4 -extern const ALIGN16 uint32 g_SIMD_clear_wmask[] ALIGN16_POST; // -1 -1 -1 0 -extern const ALIGN16 uint32 g_SIMD_ComponentMask[4][4] ALIGN16_POST; // [0xFFFFFFFF 0 0 0], [0 0xFFFFFFFF 0 0], [0 0 0xFFFFFFFF 0], [0 0 0 0xFFFFFFFF] -extern const ALIGN16 uint32 g_SIMD_AllOnesMask[] ALIGN16_POST; // ~0,~0,~0,~0 -extern const ALIGN16 uint32 g_SIMD_Low16BitsMask[] ALIGN16_POST; // 0xffff x 4 +#ifdef SDK_MP +typedef uint32 SIMD_mask_int; +#else +typedef int32 SIMD_mask_int; +#endif + +extern const ALIGN16 SIMD_mask_int g_SIMD_clear_signmask[] ALIGN16_POST; // 0x7fffffff x 4 +extern const ALIGN16 SIMD_mask_int g_SIMD_signmask[] ALIGN16_POST; // 0x80000000 x 4 +extern const ALIGN16 SIMD_mask_int g_SIMD_lsbmask[] ALIGN16_POST; // 0xfffffffe x 4 +extern const ALIGN16 SIMD_mask_int g_SIMD_clear_wmask[] ALIGN16_POST; // -1 -1 -1 0 +extern const ALIGN16 SIMD_mask_int g_SIMD_ComponentMask[4][4] ALIGN16_POST; // [0xFFFFFFFF 0 0 0], [0 0xFFFFFFFF 0 0], [0 0 0xFFFFFFFF 0], [0 0 0 0xFFFFFFFF] +extern const ALIGN16 SIMD_mask_int g_SIMD_AllOnesMask[] ALIGN16_POST; // ~0,~0,~0,~0 +extern const ALIGN16 SIMD_mask_int g_SIMD_Low16BitsMask[] ALIGN16_POST; // 0xffff x 4 // this mask is used for skipping the tail of things. If you have N elements in an array, and wish // to mask out the tail, g_SIMD_SkipTailMask[N & 3] what you want to use for the last iteration. -extern const uint32 ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST; +extern const SIMD_mask_int ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST; // Define prefetch macros. // The characteristics of cache and prefetch are completely @@ -3013,7 +3019,13 @@ inline fltx4 fnegate( const fltx4 & x ) } +#if defined(SDK_SP) && defined(__GNUC__) +// The handling for __m128 in GCC has changed since SP's particles.a was compiled. +// This links the function directly to the symbol inside of that library. +fltx4 Pow_FixedPoint_Exponent_SIMD( const fltx4 & x, int exponent) asm("_Z28Pow_FixedPoint_Exponent_SIMDRKU8__vectorfi"); +#else fltx4 Pow_FixedPoint_Exponent_SIMD( const fltx4 & x, int exponent); +#endif // PowSIMD - raise a SIMD register to a power. This is analogous to the C pow() function, with some // restictions: fractional exponents are only handled with 2 bits of precision. Basically, diff --git a/src/public/matsys_controls/mdlpanel.h b/src/public/matsys_controls/mdlpanel.h index ab96a408265..b090db57240 100644 --- a/src/public/matsys_controls/mdlpanel.h +++ b/src/public/matsys_controls/mdlpanel.h @@ -64,7 +64,11 @@ class CMDLPanel : public CPotteryWheelPanel void SetLOD( int nLOD ); // Sets the current sequence +#ifdef SDK_MP void SetSequence( int nSequence, bool bResetSequence = false ); +#else + void SetSequence( int nSequence ); +#endif // Set the pose parameters void SetPoseParameters( const float *pPoseParameters, int nCount ); @@ -95,15 +99,21 @@ class CMDLPanel : public CPotteryWheelPanel int GetMergeMDLIndex( MDLHandle_t handle ); CMDL *GetMergeMDL(MDLHandle_t handle ); void ClearMergeMDLs( void ); +#ifdef SDK_MP void ValidateMDLs( void ); CStudioHdr *GetMergeMDLStudioHdr( MDLHandle_t handle ); +#endif virtual void SetupFlexWeights( void ) { return; } // Events void DoAnimationEvents(); void DoAnimationEvents( CStudioHdr *pStudioHdr, int nSeqNum, float flTime, bool bNoLoop, MDLAnimEventState_t *pEventState ); +#ifdef SDK_MP virtual void FireEvent( const char *pszEventName, const char *pszEventOptions ); +#else + virtual void FireEvent( const char *pszEventName, const char *pszEventOptions ) { } +#endif void ResetAnimationEventState( MDLAnimEventState_t *pEventState ); protected: @@ -115,9 +125,11 @@ class CMDLPanel : public CPotteryWheelPanel CMDL m_MDL; matrix3x4_t m_MDLToWorld; bool m_bDisabled; +#ifdef SDK_MP float m_flCycleStartTime; CStudioHdr *m_pStudioHdr; uint32 m_unMdlCacheSerial; +#endif }; MDLData_t m_RootMDL; @@ -137,7 +149,9 @@ class CMDLPanel : public CPotteryWheelPanel virtual void PostPaint3D( IMatRenderContext *pRenderContext ) { }; virtual void RenderingRootModel( IMatRenderContext *pRenderContext, CStudioHdr *pStudioHdr, MDLHandle_t mdlHandle, matrix3x4_t *pWorldMatrix ) { }; virtual void RenderingMergedModel( IMatRenderContext *pRenderContext, CStudioHdr *pStudioHdr, MDLHandle_t mdlHandle, matrix3x4_t *pWorldMatrix ) { }; +#ifdef SDK_MP virtual IMaterial* GetOverrideMaterial( MDLHandle_t mdlHandle ) { return NULL; } +#endif void OnMouseDoublePressed( vgui::MouseCode code ); diff --git a/src/public/matsys_controls/potterywheelpanel.h b/src/public/matsys_controls/potterywheelpanel.h index 5da55e485b1..4deda1a6ee4 100644 --- a/src/public/matsys_controls/potterywheelpanel.h +++ b/src/public/matsys_controls/potterywheelpanel.h @@ -45,7 +45,9 @@ class CPotteryWheelPanel : public vgui::EditablePanel virtual ~CPotteryWheelPanel(); // Overriden methods of vgui::Panel +#ifdef SDK_MP virtual void ApplySettings( KeyValues *inResourceData ); +#endif virtual void Init( int x, int y, int wide, int tall ); virtual void Paint(); @@ -118,7 +120,9 @@ class CPotteryWheelPanel : public vgui::EditablePanel bool WarpMouse( int &x, int &y ); IManipulator *m_pCurrentManip; int m_nManipStartX, m_nManipStartY; +#ifdef SDK_MP int m_nClickStartX, m_nClickStartY; +#endif // Re-apply the manipulators on a new model void ApplyManipulation(); @@ -138,7 +142,9 @@ class CPotteryWheelPanel : public vgui::EditablePanel private: void CreateDefaultLights(); void DestroyLights(); +#ifdef SDK_MP void ParseLightsFromKV( KeyValues *pLightsKV ); +#endif CMaterialReference m_LightProbeBackground; CMaterialReference m_LightProbeHDRBackground; diff --git a/src/public/model_types.h b/src/public/model_types.h index e285876250d..e0bb87b84b6 100644 --- a/src/public/model_types.h +++ b/src/public/model_types.h @@ -22,7 +22,9 @@ #define STUDIO_ITEM_BLINK 0x00000040 #define STUDIO_NOSHADOWS 0x00000080 #define STUDIO_WIREFRAME_VCOLLIDE 0x00000100 +#ifdef SDK_MP #define STUDIO_NO_OVERRIDE_FOR_ATTACH 0x00000200 +#endif // Not a studio flag, but used to flag when we want studio stats #define STUDIO_GENERATE_STATS 0x01000000 diff --git a/src/public/p4lib/ip4.h b/src/public/p4lib/ip4.h index d37ab396e10..4556616fdcf 100644 --- a/src/public/p4lib/ip4.h +++ b/src/public/p4lib/ip4.h @@ -39,7 +39,9 @@ struct P4File_t CUtlSymbol m_sDepotFile; // the name in the depot CUtlSymbol m_sClientFile; // the name on the client in Perforce syntax CUtlSymbol m_sLocalFile; // the name on the client in local syntax +#ifdef SDK_MP CUtlSymbol m_sFileType; // the type according to the server, see p4 help filetypes +#endif int m_iHeadRevision; // head revision number int m_iHaveRevision; // the revision the clientspec has synced locally bool m_bDir; // directory @@ -79,7 +81,13 @@ struct P4Client_t //----------------------------------------------------------------------------- // Purpose: Interface to accessing P4 commands //----------------------------------------------------------------------------- +#ifdef SDK_MP #define P4_INTERFACE_VERSION "VP4002" +#else +#define P4_INTERFACE_VERSION "VP4001" +// Vitaliy - 09-Feb-'07: if anybody ups the version of this interface, please +// move the method "SetOpenFileChangeList" into the appropriate section. +#endif abstract_class IP4 : public IAppSystem { @@ -115,8 +123,10 @@ abstract_class IP4 : public IAppSystem // changes the clientspec to remove the specified path (cloaking) virtual void RemovePathFromActiveClientspec( const char *path ) = 0; +#ifdef SDK_MP // sets the name of the changelist to open files under, NULL for "Default" changelist virtual void SetOpenFileChangeList(const char *pChangeListName) = 0; +#endif // file manipulation virtual bool OpenFileForAdd( const char *pFullPath ) = 0; @@ -175,10 +185,12 @@ abstract_class IP4 : public IAppSystem // Returns file information for a single file virtual bool GetFileInfo( const char *pFullPath, P4File_t *pFileInfo ) = 0; +#ifdef SDK_MP // Reopens a file for edit or add with the specified filetype. To see the valid strings for // filetypes, see p4 help fileinfo. Perforce has to know about files before the filetype can // be changed (so for new files, they must be added first, then the filetype modified). virtual bool SetFileType( const char *pFullPath, const char *pFileType ) = 0; +#endif // retreives the list of files in a path, using a known client spec virtual CUtlVector &GetFileListUsingClientSpec( const char *pPath, const char *pClientSpec ) = 0; @@ -186,6 +198,11 @@ abstract_class IP4 : public IAppSystem // retrieves the last error from the last op (which is likely to span multiple lines) // this is only valid after OpenFile[s]For{Add,Edit,Delete} or {Submit,Revert}File[s] virtual const char *GetLastError() = 0; + +#ifndef SDK_MP + // sets the name of the changelist to open files under, NULL for "Default" changelist + virtual void SetOpenFileChangeList( const char *pChangeListName ) = 0; +#endif }; diff --git a/src/public/particles/particles.h b/src/public/particles/particles.h index 3a7977f4993..9d10631ccbd 100644 --- a/src/public/particles/particles.h +++ b/src/public/particles/particles.h @@ -114,8 +114,10 @@ DEFPARTICLE_ATTRIBUTE( TRACE_P1, 18 ); // end pnt of trace DEFPARTICLE_ATTRIBUTE( TRACE_HIT_T, 19 ); // 0..1 if hit DEFPARTICLE_ATTRIBUTE( TRACE_HIT_NORMAL, 20 ); // 0 0 0 if no hit +#ifdef SDK_MP // target cp index DEFPARTICLE_ATTRIBUTE( CONTROL_POINT_INDEX, 21 ); +#endif #define MAX_PARTICLE_CONTROL_POINTS 64 @@ -126,7 +128,11 @@ DEFPARTICLE_ATTRIBUTE( CONTROL_POINT_INDEX, 21 ); PARTICLE_ATTRIBUTE_HITBOX_RELATIVE_XYZ_MASK ) #define ATTRIBUTES_WHICH_ARE_0_TO_1 (PARTICLE_ATTRIBUTE_ALPHA_MASK | PARTICLE_ATTRIBUTE_ALPHA2_MASK) #define ATTRIBUTES_WHICH_ARE_ANGLES (PARTICLE_ATTRIBUTE_ROTATION_MASK | PARTICLE_ATTRIBUTE_YAW_MASK ) +#ifdef SDK_MP #define ATTRIBUTES_WHICH_ARE_INTS (PARTICLE_ATTRIBUTE_PARTICLE_ID_MASK | PARTICLE_ATTRIBUTE_HITBOX_INDEX_MASK | PARTICLE_ATTRIBUTE_CONTROL_POINT_INDEX_MASK ) +#else +#define ATTRIBUTES_WHICH_ARE_INTS (PARTICLE_ATTRIBUTE_PARTICLE_ID_MASK | PARTICLE_ATTRIBUTE_HITBOX_INDEX_MASK ) +#endif #if defined( _X360 ) #define MAX_PARTICLES_IN_A_SYSTEM 2000 @@ -212,6 +218,7 @@ class CModelHitBoxesInfo }; +#ifdef SDK_MP //----------------------------------------------------------------------------- // ParticlesCheckFloat //----------------------------------------------------------------------------- @@ -224,6 +231,7 @@ FORCEINLINE bool ParticlesCheckFloat( const Vector& v ); FORCEINLINE bool ParticlesCheckFloat( const matrix3x4_t& v ); FORCEINLINE bool ParticlesCheckFloat( const Quaternion& v ); +#endif #endif //----------------------------------------------------------------------------- @@ -405,7 +413,9 @@ class CParticleSystemMgr // Cache/uncache materials used by particle systems void PrecacheParticleSystem( const char *pName ); void UncacheAllParticleSystems(); +#ifdef SDK_MP void RecreateDictionary(); +#endif // Sets the last simulation time, used for particle system sleeping logic void SetLastSimulationTime( float flTime ); @@ -685,7 +695,11 @@ class CParticleOperatorInstance } // should the constraint be run only once after all other constraints? +#ifdef SDK_MP virtual bool IsFinalConstraint( void ) const +#else + virtual bool IsFinalConstaint( void ) const +#endif { return false; } @@ -737,11 +751,13 @@ class CParticleOperatorInstance return false; } +#ifdef SDK_MP // Does this operator require that particles remain in the order they were emitted? virtual bool RequiresOrderInvariance( void ) const { return false; } +#endif // Called when the SFM wants to skip forward in time virtual void SkipToTime( float flTime, CParticleCollection *pParticles, void *pContext ) const {} @@ -986,7 +1002,9 @@ struct CParticleVisibilityData { float m_flAlphaVisibility; float m_flRadiusVisibility; +#ifdef SDK_MP float m_flCameraBias; +#endif bool m_bUseVisibility; }; @@ -1000,11 +1018,13 @@ struct CParticleControlPoint Vector m_UpVector = vec3_origin; Vector m_RightVector = vec3_origin; +#ifdef SDK_MP Vector m_vVelocity = vec3_origin; float m_flRadius = 0.; float m_flDensity = 1.; float m_flDuration = 0.; +#endif // reference to entity or whatever this control point comes from void *m_pObject = nullptr; @@ -1059,9 +1079,11 @@ class CParticleCollection // compute bounds from particle list void RecomputeBounds( void ); +#ifdef SDK_MP void ResetControlPoints( void ); void SetControlPointIndex( int nWhichPoint ); int GetControlPointIndex( void ) const { return m_nTargetCP; } +#endif void SetControlPoint( int nWhichPoint, const Vector &v ); void SetControlPointObject( int nWhichPoint, void *pObject ); @@ -1073,6 +1095,7 @@ class CParticleCollection void SetControlPointRightVector( int nWhichPoint, const Vector &v ); void SetControlPointParent( int nWhichPoint, int n ); +#ifdef SDK_MP // if unset, vel is [ 0 0 0] void SetControlPointVelocity( int nWhichPoint, Vector vVel ); // if unset, radius is 0 @@ -1081,6 +1104,7 @@ class CParticleCollection void SetControlPointDensity( int nWhichPoint, float flDensity ); // if unset, duration is 0 void SetControlPointDuration( int nWhichPoint, float flDuration ); +#endif // get the pointer to an attribute for a given particle. // !!speed!! if you find yourself calling this anywhere that matters, @@ -1099,7 +1123,9 @@ class CParticleCollection float *GetFloatAttributePtrForWrite( int nAttribute, int nParticleNumber ); fltx4 *GetM128AttributePtrForWrite( int nAttribute, size_t *pStrideOut ); FourVectors *Get4VAttributePtrForWrite( int nAttribute, size_t *pStrideOut ); +#ifdef SDK_MP FourInts *Get4IAttributePtrForWrite( int nAttribute, size_t *pStrideOut ) const; +#endif const float *GetInitialFloatAttributePtr( int nAttribute, int nParticleNumber ) const; const fltx4 *GetInitialM128AttributePtr( int nAttribute, size_t *pStrideOut ) const; @@ -1107,7 +1133,12 @@ class CParticleCollection float *GetInitialFloatAttributePtrForWrite( int nAttribute, int nParticleNumber ); fltx4 *GetInitialM128AttributePtrForWrite( int nAttribute, size_t *pStrideOut ); +#ifdef SDK_MP void Simulate( float dt, bool updateBboxOnly ); +#else + void Simulate( float dt ); + inline void Simulate( float dt, bool updateBboxOnly ) { Simulate( dt ); } +#endif void SkipToTime( float t ); // the camera objetc may be compared for equality against control point objects @@ -1137,6 +1168,7 @@ class CParticleCollection void GetControlPointTransformAtCurrentTime( int nControlPoint, VMatrix *pMat ); int GetControlPointParent( int nControlPoint ) const; +#ifdef SDK_MP float GetFloatAttributeValue( int nAttribute, int nParticleNumber ) const; Vector GetVectorAttributeValue( int nAttribute, int nParticleNumber ) const; @@ -1144,11 +1176,17 @@ class CParticleCollection float GetControlPointDensityAtCurrentTime( int nControlPoint ) const; float GetControlPointDurationAtCurrentTime( int nControlPoint ) const; Vector GetControlPointVelocityAtCurrentTime( int nControlPoint ) const; +#endif // Used to retrieve the position of a control point // somewhere between m_fCurTime and m_fCurTime - m_fPreviousDT +#ifdef SDK_MP void GetControlPointAtTime( int nControlPoint, float flTime, Vector *pControlPoint ) const; void GetControlPointAtPrevTime( int nControlPoint, Vector *pControlPoint ) const; +#else + void GetControlPointAtTime( int nControlPoint, float flTime, Vector *pControlPoint ); + void GetControlPointAtPrevTime( int nControlPoint, Vector *pControlPoint ); +#endif void GetControlPointOrientationAtTime( int nControlPoint, float flTime, Vector *pForward, Vector *pRight, Vector *pUp ); void GetControlPointTransformAtTime( int nControlPoint, float flTime, matrix3x4_t *pMat ); void GetControlPointTransformAtTime( int nControlPoint, float flTime, VMatrix *pMat ); @@ -1256,8 +1294,12 @@ class CParticleCollection void BloatBoundsUsingControlPoint(); private: +#ifdef SDK_MP int GenerateSortedIndexList( ParticleRenderData_t *pOut, Vector vecCamera, CParticleVisibilityData *pVisibilityData, bool bSorted ); int GenerateCulledSortedIndexList( ParticleRenderData_t *pOut, Vector vecCamera, Vector vecFwd, CParticleVisibilityData *pVisibilityData, bool bSorted ); +#else + void GenerateSortedIndexList( Vector vecCameraPos, CParticleVisibilityData *pVisibilityData, bool bSorted ); +#endif void Init( CParticleSystemDefinition *pDef, float flDelay, int nRandomSeed ); void InitStorage( CParticleSystemDefinition *pDef ); @@ -1306,7 +1348,9 @@ class CParticleCollection bool ComputeIsTranslucent(); bool ComputeIsTwoPass(); bool ComputeIsBatchable(); +#ifdef SDK_MP bool ComputeRequiresOrderInvariance(); +#endif void LabelTextureUsage( void ); @@ -1328,7 +1372,9 @@ class CParticleCollection int m_nMaxAllowedParticles; bool m_bDormant; bool m_bEmissionStopped; +#ifdef SDK_MP bool m_bRequiresOrderInvariance; +#endif int m_LocalLightingCP; Color m_LocalLighting; @@ -1337,7 +1383,9 @@ class CParticleCollection // particle control points can act as emitter centers, repulsions points, etc. what they are // used for depends on what operators and parameters your system has. CParticleControlPoint m_ControlPoints[MAX_PARTICLE_CONTROL_POINTS]; +#ifdef SDK_MP FORCEINLINE const CParticleControlPoint &ControlPoint( int nIdx ) const; +#endif CModelHitBoxesInfo m_ControlPointHitBoxes[MAX_PARTICLE_CONTROL_POINTS]; @@ -1363,7 +1411,9 @@ class CParticleCollection Vector m_MinBounds; Vector m_MaxBounds; int m_nHighestCP; //Highest CP set externally. Needs to assert if a system calls to an unassigned CP. +#ifdef SDK_MP int m_nTargetCP; // Active CP set externally. +#endif private: @@ -1398,7 +1448,9 @@ class CParticleCollection // How many frames have we drawn? int m_nDrawnFrames; +#ifdef SDK_MP int m_nSimulatedFrames; +#endif Vector m_Center; // average of particle centers @@ -1437,7 +1489,7 @@ class CParticleCollection -class CM128InitialAttributeIterator : public CStridedConstPtr +class CM128InitialAttributeIterator : public CFltx4StridedConstPtr { public: FORCEINLINE CM128InitialAttributeIterator( int nAttribute, CParticleCollection *pParticles ) @@ -1447,7 +1499,7 @@ class CM128InitialAttributeIterator : public CStridedConstPtr }; -class CM128AttributeIterator : public CStridedConstPtr +class CM128AttributeIterator : public CFltx4StridedConstPtr { public: FORCEINLINE CM128AttributeIterator( int nAttribute, CParticleCollection *pParticles ) @@ -1465,6 +1517,7 @@ class C4IAttributeIterator : public CStridedConstPtr } }; +#ifdef SDK_MP class C4IAttributeWriteIterator : public CStridedConstPtr { public: @@ -1473,8 +1526,9 @@ class C4IAttributeWriteIterator : public CStridedConstPtr m_pData = pParticles->Get4IAttributePtrForWrite( nAttribute, &m_nStride ); } }; +#endif -class CM128AttributeWriteIterator : public CStridedPtr +class CM128AttributeWriteIterator : public CFltx4StridedConstPtr { public: FORCEINLINE CM128AttributeWriteIterator( void ) @@ -1546,10 +1600,12 @@ inline void CParticleCollection::SwapPosAndPrevPos( void ) V_swap( m_pParticleAttributes[ PARTICLE_ATTRIBUTE_XYZ ], m_pParticleAttributes[ PARTICLE_ATTRIBUTE_PREV_XYZ ] ); } +#ifdef SDK_MP FORCEINLINE const CParticleControlPoint &CParticleCollection::ControlPoint( int nIdx ) const { return m_ControlPoints[nIdx]; } +#endif inline void CParticleCollection::LoanKillListTo( CParticleCollection *pBorrower ) const { @@ -1572,6 +1628,7 @@ inline void CParticleCollection::SetAttributeToConstant( int nAttribute, float f fconst[8] = fconst[9] = fconst[10] = fconst[11] = fValueZ; } +#ifdef SDK_MP inline void CParticleCollection::ResetControlPoints( void ) { m_nHighestCP = 0; @@ -1591,6 +1648,7 @@ inline void CParticleCollection::SetControlPointIndex( int nWhichPoint ) i->SetControlPointIndex( nWhichPoint ); } } +#endif inline void CParticleCollection::SetControlPoint( int nWhichPoint, const Vector &v ) { @@ -1703,6 +1761,7 @@ inline void CParticleCollection::SetControlPointParent( int nWhichPoint, int n ) } } +#ifdef SDK_MP inline void CParticleCollection::SetControlPointVelocity( int nWhichPoint, Vector vVelocity ) { //AssertDbg( ( nWhichPoint >= 0 ) && ( nWhichPoint < MAX_PARTICLE_CONTROL_POINTS ) ); @@ -1762,6 +1821,7 @@ inline void CParticleCollection::SetControlPointRadius( int nWhichPoint, float f i->SetControlPointRadius( nWhichPoint, flRadius ); } } +#endif // Returns the memory for a particular constant attribute inline float *CParticleCollection::GetConstantAttributeMemory( int nAttribute ) @@ -1899,6 +1959,7 @@ inline int *CParticleCollection::GetIntAttributePtrForWrite( int nAttribute, int return reinterpret_cast< int* >( GetFloatAttributePtrForWrite( nAttribute, nParticleNumber ) ); } +#ifdef SDK_MP inline float CParticleCollection::GetFloatAttributeValue( int nAttribute, int nParticleNumber ) const { return *GetFloatAttributePtr( nAttribute, nParticleNumber ); @@ -1910,6 +1971,7 @@ inline Vector CParticleCollection::GetVectorAttributeValue( int nAttribute, int Vector vRet( pValue[0], pValue[4], pValue[8] ); return vRet; } +#endif inline const int *CParticleCollection::GetIntAttributePtr( int nAttribute, int nParticleNumber ) const { @@ -1922,6 +1984,7 @@ inline const fltx4 *CParticleCollection::GetM128AttributePtr( int nAttribute, si return reinterpret_cast( m_pParticleAttributes[ nAttribute ] ); } +#ifdef SDK_MP inline const FourInts *CParticleCollection::Get4IAttributePtr( int nAttribute, size_t *pStrideOut ) const { *(pStrideOut) = m_nParticleFloatStrides[ nAttribute ]/4; @@ -1933,6 +1996,13 @@ inline FourInts *CParticleCollection::Get4IAttributePtrForWrite( int nAttribute, *(pStrideOut) = m_nParticleFloatStrides[ nAttribute ]/4; return reinterpret_cast( m_pParticleAttributes[ nAttribute ] ); } +#else +inline const FourInts *CParticleCollection::Get4IAttributePtr( int nAttribute, size_t *pStrideOut ) const +{ + *(pStrideOut) = m_nParticleFloatStrides[ nAttribute ]/4; + return reinterpret_cast( m_pParticleAttributes[ nAttribute ] ); +} +#endif inline const int32 *CParticleCollection::GetIntAttributePtr( int nAttribute, size_t *pStrideOut ) const { @@ -2412,6 +2482,7 @@ FORCEINLINE int CParticleCollection::GetControlPointParent( int nControlPoint ) return m_ControlPoints[nControlPoint].m_nParent; } +#ifdef SDK_MP FORCEINLINE float CParticleCollection::GetControlPointRadiusAtCurrentTime( int nControlPoint ) const { return ControlPoint( nControlPoint ).m_flRadius; @@ -2431,6 +2502,7 @@ FORCEINLINE Vector CParticleCollection::GetControlPointVelocityAtCurrentTime( in { return ControlPoint( nControlPoint ).m_vVelocity; } +#endif FORCEINLINE bool CParticleCollection::IsValid( void ) const { @@ -2438,6 +2510,7 @@ FORCEINLINE bool CParticleCollection::IsValid( void ) const } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Floating point validation // @@ -2608,5 +2681,6 @@ FORCEINLINE bool ParticlesCheckColorMasked( const FourVectors& fv, int nBlockInd #else #define PARTICLES_CHECK_FLOAT_NAME_SCOPE( ctx, name ) void(0) #endif // DBGFLAG_ASSERT +#endif #endif // PARTICLES_H diff --git a/src/public/renderparm.h b/src/public/renderparm.h index 0ab821c92e8..2a906615ef9 100644 --- a/src/public/renderparm.h +++ b/src/public/renderparm.h @@ -56,6 +56,11 @@ enum RenderParamInt_t INT_FLASHLIGHT_DEPTHTEXTURE_FALLBACK_FIRST, INT_FLASHLIGHT_DEPTHTEXTURE_FALLBACK_LAST = INT_FLASHLIGHT_DEPTHTEXTURE_FALLBACK_FIRST + 4, +#ifdef SDK_SP + // In lieu of dedicated interface functions + INT_RENDERPARM_FOG_TYPE, +#endif + MAX_INT_RENDER_PARMS = 20 }; @@ -63,6 +68,11 @@ enum RenderParamInt_t #define BACK_BUFFER_INDEX_DEFAULT 0 #define BACK_BUFFER_INDEX_HDR 1 +#ifdef SDK_SP +// For fog type workaround +#define MATERIAL_FOG_RANGE_RADIAL 3 +#endif + enum RenderParamTexture_t { TEXTURE_RENDERPARM_AMBIENT_OCCLUSION = 0, diff --git a/src/public/saverestoretypes.h b/src/public/saverestoretypes.h index 41e24a8252e..cd9e457f3c5 100644 --- a/src/public/saverestoretypes.h +++ b/src/public/saverestoretypes.h @@ -178,7 +178,7 @@ class CGameSaveRestoreInfo { public: CGameSaveRestoreInfo() - : m_iTableCount( 0 ), m_pTable( 0 ), m_pCurrentEntity( 0 ), m_EntityToIndex( 1024 ) + : tableCount( 0 ), pTable( 0 ), m_pCurrentEntity( 0 ), m_EntityToIndex( 1024 ) { memset( &levelInfo, 0, sizeof( levelInfo ) ); modelSpaceOffset.Init( 0, 0, 0 ); @@ -186,8 +186,8 @@ class CGameSaveRestoreInfo void InitEntityTable( entitytable_t *pNewTable = NULL, int size = 0 ) { - m_pTable = pNewTable; - m_iTableCount = size; + pTable = pNewTable; + tableCount = size; for ( int i = 0; i < NumEntities(); i++ ) { @@ -197,17 +197,17 @@ class CGameSaveRestoreInfo entitytable_t *DetachEntityTable() { - entitytable_t *pReturn = m_pTable; - m_pTable = NULL; - m_iTableCount = 0; + entitytable_t *pReturn = pTable; + pTable = NULL; + tableCount = 0; return pReturn; } CBaseEntity *GetCurrentEntityContext() { return m_pCurrentEntity; } void SetCurrentEntityContext(CBaseEntity *pEntity) { m_pCurrentEntity = pEntity; } - int NumEntities() { return m_iTableCount; } - entitytable_t *GetEntityInfo( int i ) { return (m_pTable + i); } + int NumEntities() { return tableCount; } + entitytable_t *GetEntityInfo( int i ) { return (pTable + i); } float GetBaseTime() const { return levelInfo.time; } Vector GetLandmark() const { return ( levelInfo.fUseLandmark ) ? levelInfo.vecLandmarkOffset : vec3_origin; } @@ -215,13 +215,13 @@ class CGameSaveRestoreInfo { #ifdef GAME_DLL int i; - entitytable_t *m_pTable; + entitytable_t *pTable; int nEntities = NumEntities(); for ( i = 0; i < nEntities; i++ ) { - m_pTable = GetEntityInfo( i ); - m_EntityToIndex.Insert( CHashElement( m_pTable->hEnt.Get(), i ) ); + pTable = GetEntityInfo( i ); + m_EntityToIndex.Insert( CHashElement( pTable->hEnt.Get(), i ) ); } #endif } @@ -266,8 +266,8 @@ class CGameSaveRestoreInfo Vector modelSpaceOffset; // used only for globaly entity brushes modelled in different coordinate systems. private: - int m_iTableCount; // Number of elements in the entity table - entitytable_t *m_pTable; // Array of entitytable_t elements (1 for each entity) + int tableCount; // Number of elements in the entity table + entitytable_t *pTable; // Array of entitytable_t elements (1 for each entity) CBaseEntity *m_pCurrentEntity; // only valid during the save functions of this entity, NULL otherwise diff --git a/src/public/scratchpad3d.h b/src/public/scratchpad3d.h index 30b2455cf54..7e9aad66eac 100644 --- a/src/public/scratchpad3d.h +++ b/src/public/scratchpad3d.h @@ -51,7 +51,7 @@ class CScratchPad3D : public IScratchPad3D m_pCachedRenderData = NULL; } - virtual ~CBaseCommand() + ~CBaseCommand() { ReleaseCachedRenderData(); } diff --git a/src/public/shaderapi/ishaderapi.h b/src/public/shaderapi/ishaderapi.h index aea349a7409..f4197b19f25 100644 --- a/src/public/shaderapi/ishaderapi.h +++ b/src/public/shaderapi/ishaderapi.h @@ -593,7 +593,11 @@ abstract_class IShaderAPI : public IShaderDynamicAPI virtual void AcquireThreadOwnership() = 0; virtual void ReleaseThreadOwnership() = 0; +#ifdef SDK_MP virtual bool SupportsNormalMapCompression() const { Assert( !"This has all been removed." ); return false; } +#else + virtual bool SupportsNormalMapCompression() const = 0; +#endif // Only does anything on XBox360. This is useful to eliminate stalls virtual void EnableBuffer2FramesAhead( bool bEnable ) = 0; @@ -613,6 +617,7 @@ abstract_class IShaderAPI : public IShaderDynamicAPI virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0; +#ifdef SDK_MP // Allows copying a render target to another texture by specifying them both. virtual void CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcRt, ShaderAPITextureHandle_t dstTex, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0; @@ -632,6 +637,7 @@ abstract_class IShaderAPI : public IShaderDynamicAPI virtual void SceneFogRadial( bool bRadial ) = 0; virtual bool GetSceneFogRadial() = 0; +#endif }; diff --git a/src/public/shaderapi/ishaderdynamic.h b/src/public/shaderapi/ishaderdynamic.h index 9bbbc0b73eb..01cd4ba018b 100644 --- a/src/public/shaderapi/ishaderdynamic.h +++ b/src/public/shaderapi/ishaderdynamic.h @@ -36,8 +36,13 @@ struct LightState_t { int m_nNumLights; bool m_bAmbientLight; +#ifdef SDK_MP bool m_bStaticLightVertex; bool m_bStaticLightTexel; +#else + bool m_bStaticLight; + #define m_bStaticLightVertex m_bStaticLight +#endif inline int HasDynamicLight() { return (m_bAmbientLight || (m_nNumLights > 0)) ? 1 : 0; } }; @@ -107,8 +112,10 @@ enum StandardTextureId_t // A snapshot of the frame buffer's depth. Currently only valid on the 360 TEXTURE_IDENTITY_LIGHTWARP, +#ifdef SDK_MP // Equivalent to the debug material for mat_luxels, in convenient texture form. TEXTURE_DEBUG_LUXELS, +#endif TEXTURE_MAX_STD_TEXTURES = 32 }; @@ -338,7 +345,17 @@ abstract_class IShaderDynamicAPI virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) = 0; +#ifdef SDK_MP virtual int GetPixelFogCombo1( bool bSupportsRadial ) = 0; +#else + FORCEINLINE int GetPixelFogCombo1( bool bSupportsRadial ) + { + if ( bSupportsRadial ) + return GetIntRenderingParameter( INT_RENDERPARM_FOG_TYPE ); + else + return GetPixelFogCombo(); + } +#endif }; // end class IShaderDynamicAPI diff --git a/src/public/shaderlib/BaseShader.h b/src/public/shaderlib/BaseShader.h index 6119183d48b..70c9c40146c 100644 --- a/src/public/shaderlib/BaseShader.h +++ b/src/public/shaderlib/BaseShader.h @@ -168,7 +168,9 @@ class CBaseShader : public IShader void BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrame = 0 ); void BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame = 0 ); +#ifdef SDK_MP void GetTextureDimensions( float* pOutWidth, float* pOutHeight, int nTextureVar ); +#endif // Is the texture translucent? bool TextureIsTranslucent( int textureVar, bool isBaseTexture ); diff --git a/src/public/shaderlib/cshader.h b/src/public/shaderlib/cshader.h index 9c693638bf8..6f105110c9b 100644 --- a/src/public/shaderlib/cshader.h +++ b/src/public/shaderlib/cshader.h @@ -34,6 +34,9 @@ // make "local variable is initialized but not referenced" warnings errors for combo checking macros #pragma warning ( error : 4189 ) +// Set for SP compatibility +#define SHADER_PREFIX + //----------------------------------------------------------------------------- // Global interfaces //----------------------------------------------------------------------------- @@ -122,7 +125,7 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag {\ typedef _baseclass CBaseClass;\ static const char *s_HelpString = help; \ - static const char *s_Name = #name; \ + static const char *s_Name = SHADER_PREFIX #name; \ static int s_nFlags = flags; \ class CShaderParam;\ static CUtlVector s_ShaderParams;\ @@ -299,7 +302,7 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag BEGIN_SHADER( _shadername, "" ) \ BEGIN_SHADER_PARAMS \ END_SHADER_PARAMS \ - SHADER_FALLBACK { return #_fallbackshadername; } \ + SHADER_FALLBACK { return SHADER_PREFIX #_fallbackshadername; } \ SHADER_INIT {} \ SHADER_DRAW {} \ END_SHADER @@ -333,7 +336,7 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag {\ namespace _name\ {\ - static const char *s_Name = #_name; \ + static const char *s_Name = SHADER_PREFIX #_name; \ static const char *s_HelpString = _help;\ static int s_nFlags = _flags;\ class CShader : public _base::CShader\ @@ -351,6 +354,7 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag #define BEGIN_INHERITED_SHADER( _name, _base, _help ) BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, 0 ) #define END_INHERITED_SHADER END_SHADER } +#ifdef SDK_MP // psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER #define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \ int declaredynpixshader_ ## shader ## _missingcurlybraces = 0; \ @@ -488,5 +492,144 @@ inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag NOTE_UNUSED( vsh_testAllCombos ); \ NOTE_UNUSED( vsh ## shader ); \ pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() ) +#else +// psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER +#define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \ + int declaredynpixshader_ ## shader ## _missingcurlybraces = 0; \ + declaredynpixshader_ ## shader ## _missingcurlybraces = declaredynpixshader_ ## shader ## _missingcurlybraces; \ + shader ## _Dynamic_Index _pshIndex; \ + int psh ## shader = 0 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_VERTEX_SHADER +#define DECLARE_DYNAMIC_VERTEX_SHADER( shader ) \ + int declaredynvertshader_ ## shader ## _missingcurlybraces = 0; \ + declaredynvertshader_ ## shader ## _missingcurlybraces = declaredynvertshader_ ## shader ## _missingcurlybraces; \ + shader ## _Dynamic_Index _vshIndex; \ + int vsh ## shader = 0 + + +// psh ## shader is used here to generate a warning if you don't ever call SET_STATIC_PIXEL_SHADER +#define DECLARE_STATIC_PIXEL_SHADER( shader ) \ + int declarestaticpixshader_ ## shader ## _missingcurlybraces = 0; \ + declarestaticpixshader_ ## shader ## _missingcurlybraces = declarestaticpixshader_ ## shader ## _missingcurlybraces; \ + shader ## _Static_Index _pshIndex; \ + int psh ## shader = 0 + +// vsh ## shader is used here to generate a warning if you don't ever call SET_STATIC_VERTEX_SHADER +#define DECLARE_STATIC_VERTEX_SHADER( shader ) \ + int declarestaticvertshader_ ## shader ## _missingcurlybraces = 0; \ + declarestaticvertshader_ ## shader ## _missingcurlybraces = declarestaticvertshader_ ## shader ## _missingcurlybraces; \ + shader ## _Static_Index _vshIndex; \ + int vsh ## shader = 0 + + +// psh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_PIXEL_SHADER block. +#define SET_DYNAMIC_PIXEL_SHADER_COMBO( var, val ) \ + int dynpixshadercombo_ ## var ## _missingcurlybraces = 0; \ + dynpixshadercombo_ ## var ## _missingcurlybraces = dynpixshadercombo_ ## var ## _missingcurlybraces; \ + _pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS dyn var %s = %d (%s)", #var, (int) val, #val );}; \ + int psh_forgot_to_set_dynamic_ ## var = 0 + +// vsh_forgot_to_set_dynamic_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_DYNAMIC_VERTEX_SHADER block. +#define SET_DYNAMIC_VERTEX_SHADER_COMBO( var, val ) \ + int dynvertshadercombo_ ## var ## _missingcurlybraces = 0; \ + dynvertshadercombo_ ## var ## _missingcurlybraces = dynvertshadercombo_ ## var ## _missingcurlybraces; \ + _vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS dyn var %s = %d (%s)", #var, (int) val, #val );}; \ + int vsh_forgot_to_set_dynamic_ ## var = 0 + + +// psh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_PIXEL_SHADER block. +#define SET_STATIC_PIXEL_SHADER_COMBO( var, val ) \ + int staticpixshadercombo_ ## var ## _missingcurlybraces = 0; \ + staticpixshadercombo_ ## var ## _missingcurlybraces = staticpixshadercombo_ ## var ## _missingcurlybraces; \ + _pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS stat var %s = %d (%s)", #var, (int) val, #val );}; \ + int psh_forgot_to_set_static_ ## var = 0 + +// vsh_forgot_to_set_static_ ## var is used to make sure that you set all +// all combos. If you don't, you will get an undefined variable used error +// in the SET_STATIC_VERTEX_SHADER block. +#define SET_STATIC_VERTEX_SHADER_COMBO( var, val ) \ + int staticvertshadercombo_ ## var ## _missingcurlybraces = 0; \ + staticvertshadercombo_ ## var ## _missingcurlybraces = staticvertshadercombo_ ## var ## _missingcurlybraces; \ + _vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS stat var %s = %d (%s)", #var, (int) val, #val );}; \ + int vsh_forgot_to_set_static_ ## var = 0 + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_DYNAMIC_PIXEL_SHADER +// was called for this particular shader. +#define SET_DYNAMIC_PIXEL_SHADER( shader ) \ + int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \ + dynamicpixshader_ ## shader ## _missingcurlybraces = dynamicpixshader_ ## shader ## _missingcurlybraces; \ + int psh_testAllCombos = shaderDynamicTest_ ## shader; \ + psh_testAllCombos = psh_testAllCombos; \ + psh ## shader = psh ## shader; \ + pShaderAPI->SetPixelShaderIndex( _pshIndex.GetIndex() ) + +#define SET_DYNAMIC_PIXEL_SHADER_CMD( cmdstream, shader ) \ + int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \ + dynamicpixshader_ ## shader ## _missingcurlybraces = dynamicpixshader_ ## shader ## _missingcurlybraces; \ + int psh_testAllCombos = shaderDynamicTest_ ## shader; \ + psh_testAllCombos = psh_testAllCombos; \ + psh ## shader = psh ## shader; \ + cmdstream.SetPixelShaderIndex( _pshIndex.GetIndex() ) + + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_dynamic_ ## var's from +// SET_DYNAMIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_DYNAMIC_VERTEX_SHADER +// was called for this particular shader. +#define SET_DYNAMIC_VERTEX_SHADER( shader ) \ + int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \ + dynamicvertshader_ ## shader ## _missingcurlybraces = dynamicvertshader_ ## shader ## _missingcurlybraces; \ + int vsh_testAllCombos = shaderDynamicTest_ ## shader; \ + vsh_testAllCombos = vsh_testAllCombos; \ + vsh ## shader = vsh ## shader; \ + pShaderAPI->SetVertexShaderIndex( _vshIndex.GetIndex() ) + +#define SET_DYNAMIC_VERTEX_SHADER_CMD( cmdstream, shader ) \ + int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \ + dynamicvertshader_ ## shader ## _missingcurlybraces = dynamicvertshader_ ## shader ## _missingcurlybraces; \ + int vsh_testAllCombos = shaderDynamicTest_ ## shader; \ + vsh_testAllCombos = vsh_testAllCombos; \ + vsh ## shader = vsh ## shader; \ + cmdstream.SetVertexShaderIndex( _vshIndex.GetIndex() ) + + +// psh_testAllCombos adds up all of the psh_forgot_to_set_static_ ## var's from +// SET_STATIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set. +// psh_testAllCombos is set to itself to avoid an unused variable warning. +// psh ## shader being set to itself ensures that DECLARE_STATIC_PIXEL_SHADER +// was called for this particular shader. +#define SET_STATIC_PIXEL_SHADER( shader ) \ + int staticpixshader_ ## shader ## _missingcurlybraces = 0; \ + staticpixshader_ ## shader ## _missingcurlybraces = staticpixshader_ ## shader ## _missingcurlybraces; \ + int psh_testAllCombos = shaderStaticTest_ ## shader; \ + psh_testAllCombos = psh_testAllCombos; \ + psh ## shader = psh ## shader; \ + pShaderShadow->SetPixelShader( SHADER_PREFIX #shader, _pshIndex.GetIndex() ) + +// vsh_testAllCombos adds up all of the vsh_forgot_to_set_static_ ## var's from +// SET_STATIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set. +// vsh_testAllCombos is set to itself to avoid an unused variable warning. +// vsh ## shader being set to itself ensures that DECLARE_STATIC_VERTEX_SHADER +// was called for this particular shader. +#define SET_STATIC_VERTEX_SHADER( shader ) \ + int staticvertshader_ ## shader ## _missingcurlybraces = 0; \ + staticvertshader_ ## shader ## _missingcurlybraces = staticvertshader_ ## shader ## _missingcurlybraces; \ + int vsh_testAllCombos = shaderStaticTest_ ## shader; \ + vsh_testAllCombos = vsh_testAllCombos; \ + vsh ## shader = vsh ## shader; \ + pShaderShadow->SetVertexShader( SHADER_PREFIX #shader, _vshIndex.GetIndex() ) +#endif #endif // CSHADER_H diff --git a/src/public/soundsystem/isoundsystem.h b/src/public/soundsystem/isoundsystem.h index f1aa26980df..d74affaebd2 100644 --- a/src/public/soundsystem/isoundsystem.h +++ b/src/public/soundsystem/isoundsystem.h @@ -41,6 +41,7 @@ enum FindAudioSourceFlags_t FINDAUDIOSOURCE_PLAYONCE = 0x4, }; +#ifdef SDK_MP #include "soundsystem/audio_mix.h" /* filter types */ @@ -67,6 +68,7 @@ class IAudioMix class CAudioMixState; class CAudioMixDescription; +#endif //----------------------------------------------------------------------------- // Purpose: DLL interface for low-level sound utilities diff --git a/src/public/steam/isteamapplist.h b/src/public/steam/isteamapplist.h index d0fe2c8d861..38f5365ffe5 100644 --- a/src/public/steam/isteamapplist.h +++ b/src/public/steam/isteamapplist.h @@ -32,9 +32,11 @@ class ISteamAppList #define STEAMAPPLIST_INTERFACE_VERSION "STEAMAPPLIST_INTERFACE_VERSION001" +#ifdef SDK_MP // Global interface accessor inline ISteamAppList *SteamAppList(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamAppList *, SteamAppList, STEAMAPPLIST_INTERFACE_VERSION ); +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamapps.h b/src/public/steam/isteamapps.h index 8a2197edd0d..f02a00225f4 100644 --- a/src/public/steam/isteamapps.h +++ b/src/public/steam/isteamapps.h @@ -78,6 +78,7 @@ class ISteamApps // Check for new launch parameters on callback NewUrlLaunchParameters_t virtual const char *GetLaunchQueryParam( const char *pchKey ) = 0; +#ifdef SDK_MP // get download progress for optional DLC virtual bool GetDlcDownloadProgress( AppId_t nAppID, uint64 *punBytesDownloaded, uint64 *punBytesTotal ) = 0; @@ -111,13 +112,18 @@ class ISteamApps // set current DLC AppID being played (or 0 if none). Allows Steam to track usage of major DLC extensions virtual bool SetDlcContext( AppId_t nAppID ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMAPPS_INTERFACE_VERSION "STEAMAPPS_INTERFACE_VERSION008" // Global interface accessor inline ISteamApps *SteamApps(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamApps *, SteamApps, STEAMAPPS_INTERFACE_VERSION ); +#else +#define STEAMAPPS_INTERFACE_VERSION "STEAMAPPS_INTERFACE_VERSION006" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamappticket.h b/src/public/steam/isteamappticket.h index 21fb9e13575..13a26bd3059 100644 --- a/src/public/steam/isteamappticket.h +++ b/src/public/steam/isteamappticket.h @@ -6,6 +6,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMAPPTICKET_H +#endif + #ifndef ISTEAMAPPTICKET_H #define ISTEAMAPPTICKET_H #pragma once diff --git a/src/public/steam/isteamchat.h b/src/public/steam/isteamchat.h index 58062f268ea..3d073438b5e 100644 --- a/src/public/steam/isteamchat.h +++ b/src/public/steam/isteamchat.h @@ -4,6 +4,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMCHAT_H +#endif + #ifndef ISTEAMCHAT_H #define ISTEAMCHAT_H diff --git a/src/public/steam/isteamclient.h b/src/public/steam/isteamclient.h index 8cd45891a9b..9ba950fc38c 100644 --- a/src/public/steam/isteamclient.h +++ b/src/public/steam/isteamclient.h @@ -56,7 +56,11 @@ class ISteamClient // set the local IP and Port to bind to // this must be set before CreateLocalUser() +#ifdef SDK_MP virtual void SetLocalIPBinding( const SteamIPAddress_t &unIP, uint16 usPort ) = 0; +#else + virtual void SetLocalIPBinding( uint32 unIP, uint16 usPort ) = 0; +#endif // returns the ISteamFriends interface virtual ISteamFriends *GetISteamFriends( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; @@ -91,8 +95,10 @@ class ISteamClient // user screenshots virtual ISteamScreenshots *GetISteamScreenshots( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; +#ifdef SDK_MP // game search virtual ISteamGameSearch *GetISteamGameSearch( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; +#endif // Deprecated. Applications should use SteamAPI_RunCallbacks() or SteamGameServer_RunCallbacks() instead. STEAM_PRIVATE_API( virtual void RunFrame() = 0; ) @@ -115,8 +121,13 @@ class ISteamClient // Expose HTTP interface virtual ISteamHTTP *GetISteamHTTP( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; +#ifdef SDK_MP // Deprecated - the ISteamUnifiedMessages interface is no longer intended for public consumption. STEAM_PRIVATE_API( virtual void *DEPRECATED_GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0 ; ) +#else + // Exposes the ISteamUnifiedMessages interface + virtual ISteamUnifiedMessages *GetISteamUnifiedMessages( HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; +#endif // Exposes the ISteamController interface - deprecated in favor of Steam Input virtual ISteamController *GetISteamController( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; @@ -137,6 +148,7 @@ class ISteamClient virtual ISteamHTMLSurface *GetISteamHTMLSurface(HSteamUser hSteamuser, HSteamPipe hSteamPipe, const char *pchVersion) = 0; // Helper functions for internal Steam usage +#ifdef SDK_MP STEAM_PRIVATE_API( virtual void DEPRECATED_Set_SteamAPI_CPostAPIResultInProcess( void (*)() ) = 0; ) STEAM_PRIVATE_API( virtual void DEPRECATED_Remove_SteamAPI_CPostAPIResultInProcess( void (*)() ) = 0; ) STEAM_PRIVATE_API( virtual void Set_SteamAPI_CCheckCallbackRegisteredInProcess( SteamAPI_CheckCallbackRegistered_t func ) = 0; ) @@ -160,12 +172,21 @@ class ISteamClient virtual ISteamRemotePlay *GetISteamRemotePlay( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion ) = 0; STEAM_PRIVATE_API( virtual void DestroyAllInterfaces() = 0; ) - +#else + virtual void Set_SteamAPI_CPostAPIResultInProcess( SteamAPI_PostAPIResultInProcess_t func ) = 0; + virtual void Remove_SteamAPI_CPostAPIResultInProcess( SteamAPI_PostAPIResultInProcess_t func ) = 0; + virtual void Set_SteamAPI_CCheckCallbackRegisteredInProcess( SteamAPI_CheckCallbackRegistered_t func ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMCLIENT_INTERFACE_VERSION "SteamClient020" +#else +#define STEAMCLIENT_INTERFACE_VERSION "SteamClient016" +#endif #ifndef STEAM_API_EXPORTS +#ifdef SDK_MP // Global ISteamClient interface accessor inline ISteamClient *SteamClient(); STEAM_DEFINE_INTERFACE_ACCESSOR( ISteamClient *, SteamClient, SteamInternal_CreateInterface( STEAMCLIENT_INTERFACE_VERSION ), "global", STEAMCLIENT_INTERFACE_VERSION ); @@ -173,6 +194,7 @@ STEAM_DEFINE_INTERFACE_ACCESSOR( ISteamClient *, SteamClient, SteamInternal_Crea // The internal ISteamClient used for the gameserver interface. // (This is actually the same thing. You really shouldn't need to access any of this stuff directly.) inline ISteamClient *SteamGameServerClient() { return SteamClient(); } +#endif #endif diff --git a/src/public/steam/isteamcontroller.h b/src/public/steam/isteamcontroller.h index d8074550555..58f8ba702dc 100644 --- a/src/public/steam/isteamcontroller.h +++ b/src/public/steam/isteamcontroller.h @@ -35,6 +35,63 @@ #define STEAM_CONTROLLER_MIN_ANALOG_ACTION_DATA -1.0f #define STEAM_CONTROLLER_MAX_ANALOG_ACTION_DATA 1.0f +#ifndef SDK_MP +#define STEAM_RIGHT_TRIGGER_MASK 0x0000001 +#define STEAM_LEFT_TRIGGER_MASK 0x0000002 +#define STEAM_RIGHT_BUMPER_MASK 0x0000004 +#define STEAM_LEFT_BUMPER_MASK 0x0000008 +#define STEAM_BUTTON_0_MASK 0x0000010 +#define STEAM_BUTTON_1_MASK 0x0000020 +#define STEAM_BUTTON_2_MASK 0x0000040 +#define STEAM_BUTTON_3_MASK 0x0000080 +#define STEAM_TOUCH_0_MASK 0x0000100 +#define STEAM_TOUCH_1_MASK 0x0000200 +#define STEAM_TOUCH_2_MASK 0x0000400 +#define STEAM_TOUCH_3_MASK 0x0000800 +#define STEAM_BUTTON_MENU_MASK 0x0001000 +#define STEAM_BUTTON_STEAM_MASK 0x0002000 +#define STEAM_BUTTON_ESCAPE_MASK 0x0004000 +#define STEAM_BUTTON_BACK_LEFT_MASK 0x0008000 +#define STEAM_BUTTON_BACK_RIGHT_MASK 0x0010000 +#define STEAM_BUTTON_LEFTPAD_CLICKED_MASK 0x0020000 +#define STEAM_BUTTON_RIGHTPAD_CLICKED_MASK 0x0040000 +#define STEAM_LEFTPAD_FINGERDOWN_MASK 0x0080000 +#define STEAM_RIGHTPAD_FINGERDOWN_MASK 0x0100000 +#define STEAM_JOYSTICK_BUTTON_MASK 0x0400000 + + +#pragma pack( push, 1 ) + +struct SteamControllerState001_t +{ + // If packet num matches that on your prior call, then the controller state hasn't been changed since + // your last call and there is no need to process it + uint32 unPacketNum; + + // bit flags for each of the buttons + uint64 ulButtons; + + // Left pad coordinates + short sLeftPadX; + short sLeftPadY; + + // Right pad coordinates + short sRightPadX; + short sRightPadY; + +}; + +#pragma pack( pop ) + +#define SteamControllerState_t SteamControllerState001_t + +enum ESteamControllerPad +{ + k_ESteamControllerPad_Left, + k_ESteamControllerPad_Right +}; +#endif + #ifndef ISTEAMINPUT_H enum ESteamControllerPad { @@ -601,6 +658,7 @@ class ISteamController // be called from somewhere before GetConnectedControllers will return any handles virtual void RunFrame() = 0; +#ifdef SDK_MP // Enumerate currently connected controllers // handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles // Returns the number of handles written to handlesOut @@ -716,12 +774,35 @@ class ISteamController // Get the binding revision for a given device. Returns false if the handle was not valid or if a mapping is not yet loaded for the device virtual bool GetControllerBindingRevision( ControllerHandle_t controllerHandle, int *pMajor, int *pMinor ) = 0; +#else + // Get the state of the specified controller, returns false if that controller is not connected + virtual bool GetControllerState( uint32 unControllerIndex, SteamControllerState_t *pState ) = 0; + + // Trigger a haptic pulse on the controller + virtual void TriggerHapticPulse( uint32 unControllerIndex, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec ) = 0; + + // Set the override mode which is used to choose to use different base/legacy bindings from your config file + virtual void SetOverrideMode( const char *pchMode ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMCONTROLLER_INTERFACE_VERSION "SteamController008" // Global interface accessor inline ISteamController *SteamController(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamController *, SteamController, STEAMCONTROLLER_INTERFACE_VERSION ); +#else +#define STEAMCONTROLLER_INTERFACE_VERSION "STEAMCONTROLLER_INTERFACE_VERSION" + +// callbacks +#if defined( VALVE_CALLBACK_PACK_SMALL ) +#pragma pack( push, 4 ) +#elif defined( VALVE_CALLBACK_PACK_LARGE ) +#pragma pack( push, 8 ) +#else +#error isteamclient.h must be included +#endif +#endif #endif // ISTEAMCONTROLLER_H diff --git a/src/public/steam/isteamfriends.h b/src/public/steam/isteamfriends.h index 234e9415ded..45571092b76 100644 --- a/src/public/steam/isteamfriends.h +++ b/src/public/steam/isteamfriends.h @@ -242,6 +242,7 @@ class ISteamFriends virtual bool GetFriendGamePlayed( CSteamID steamIDFriend, STEAM_OUT_STRUCT() FriendGameInfo_t *pFriendGameInfo ) = 0; // accesses old friends names - returns an empty string when their are no more items in the history virtual const char *GetFriendPersonaNameHistory( CSteamID steamIDFriend, int iPersonaName ) = 0; +#ifdef SDK_MP // friends steam level virtual int GetFriendSteamLevel( CSteamID steamIDFriend ) = 0; @@ -260,6 +261,10 @@ class ISteamFriends virtual int GetFriendsGroupMembersCount( FriendsGroupID_t friendsGroupID ) = 0; // gets up to nMembersCount members of the given friends group, if fewer exist than requested those positions' SteamIDs will be invalid virtual void GetFriendsGroupMembersList( FriendsGroupID_t friendsGroupID, STEAM_OUT_ARRAY_CALL(nMembersCount, GetFriendsGroupMembersCount, friendsGroupID ) CSteamID *pOutSteamIDMembers, int nMembersCount ) = 0; +#else + // Returns nickname the current user has set for the specified player. Returns NULL if the no nickname has been set for that player. + virtual const char *GetPlayerNickname( CSteamID steamIDPlayer ) = 0; +#endif // returns true if the specified user meets any of the criteria specified in iFriendFlags // iFriendFlags can be the union (binary or, |) of one or more k_EFriendFlags values @@ -274,8 +279,13 @@ class ISteamFriends virtual bool GetClanActivityCounts( CSteamID steamIDClan, int *pnOnline, int *pnInGame, int *pnChatting ) = 0; // for clans a user is a member of, they will have reasonably up-to-date information, but for others you'll have to download the info to have the latest +#ifdef SDK_MP STEAM_CALL_RESULT( DownloadClanActivityCountsResult_t ) virtual SteamAPICall_t DownloadClanActivityCounts( STEAM_ARRAY_COUNT(cClansToRequest) CSteamID *psteamIDClans, int cClansToRequest ) = 0; +#else + // for clans a user is a member of, they will have reasonably up-to-date information, but for others you'll have to download the info to have the latest + virtual SteamAPICall_t DownloadClanActivityCounts( CSteamID *psteamIDClans, int cClansToRequest ) = 0; +#endif // iterators for getting users in a chat room, lobby, game server or clan // note that large clans that cannot be iterated by the local user @@ -310,7 +320,11 @@ class ISteamFriends // activates game overlay web browser directly to the specified URL // full address with protocol type is required, e.g. http://www.steamgames.com/ +#ifdef SDK_MP virtual void ActivateGameOverlayToWebPage( const char *pchURL, EActivateGameOverlayToWebPageMode eMode = k_EActivateGameOverlayToWebPageMode_Default ) = 0; +#else + virtual void ActivateGameOverlayToWebPage( const char *pchURL ) = 0; +#endif // activates game overlay to store page for app virtual void ActivateGameOverlayToStore( AppId_t nAppID, EOverlayToStoreFlag eFlag ) = 0; @@ -345,7 +359,9 @@ class ISteamFriends // you can only ask about clans that a user is a member of // note that this won't download avatars automatically; if you get an officer, // and no avatar image is available, call RequestUserInformation( steamID, false ) to download the avatar +#ifdef SDK_MP STEAM_CALL_RESULT( ClanOfficerListResponse_t ) +#endif virtual SteamAPICall_t RequestClanOfficerList( CSteamID steamIDClan ) = 0; // iteration of clan officers - can only be done when a RequestClanOfficerList() call has completed @@ -402,7 +418,9 @@ class ISteamFriends // this allows in-game access to group (clan) chats from in the game // the behavior is somewhat sophisticated, because the user may or may not be already in the group chat from outside the game or in the overlay // use ActivateGameOverlayToUser( "chat", steamIDClan ) to open the in-game overlay version of the chat +#ifdef SDK_MP STEAM_CALL_RESULT( JoinClanChatRoomCompletionResult_t ) +#endif virtual SteamAPICall_t JoinClanChatRoom( CSteamID steamIDClan ) = 0; virtual bool LeaveClanChatRoom( CSteamID steamIDClan ) = 0; virtual int GetClanChatMemberCount( CSteamID steamIDClan ) = 0; @@ -430,6 +448,7 @@ class ISteamFriends STEAM_CALL_RESULT( FriendsEnumerateFollowingList_t ) virtual SteamAPICall_t EnumerateFollowingList( uint32 unStartIndex ) = 0; +#ifdef SDK_MP virtual bool IsClanPublic( CSteamID steamIDClan ) = 0; virtual bool IsClanOfficialGameGroup( CSteamID steamIDClan ) = 0; @@ -459,13 +478,18 @@ class ISteamFriends virtual bool BHasEquippedProfileItem( CSteamID steamID, ECommunityProfileItemType itemType ) = 0; virtual const char *GetProfileItemPropertyString( CSteamID steamID, ECommunityProfileItemType itemType, ECommunityProfileItemProperty prop ) = 0; virtual uint32 GetProfileItemPropertyUint( CSteamID steamID, ECommunityProfileItemType itemType, ECommunityProfileItemProperty prop ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMFRIENDS_INTERFACE_VERSION "SteamFriends017" // Global interface accessor inline ISteamFriends *SteamFriends(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamFriends *, SteamFriends, STEAMFRIENDS_INTERFACE_VERSION ); +#else +#define STEAMFRIENDS_INTERFACE_VERSION "SteamFriends014" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamgameserver.h b/src/public/steam/isteamgameserver.h index ba4d12517fb..bb3609d1e4d 100644 --- a/src/public/steam/isteamgameserver.h +++ b/src/public/steam/isteamgameserver.h @@ -136,6 +136,7 @@ class ISteamGameServer /// Region identifier. This is an optional field, the default value is empty, meaning the "world" region virtual void SetRegion( const char *pszRegion ) = 0; +#ifdef SDK_MP /// Indicate whether you wish to be listed on the master server list /// and/or respond to server browser / LAN discovery packets. /// The server starts with this value set to false. You should set all @@ -155,6 +156,47 @@ class ISteamGameServer // SteamNetworkingIdentity is an optional parameter to hold the public IP address of the entity you are connecting to // if an IP address is passed Steam will only allow the ticket to be used by an entity with that IP address virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket, const SteamNetworkingIdentity *pSnid ) = 0; +#else +// +// Player list management / authentication +// + + // Handles receiving a new connection from a Steam user. This call will ask the Steam + // servers to validate the users identity, app ownership, and VAC status. If the Steam servers + // are off-line, then it will validate the cached ticket itself which will validate app ownership + // and identity. The AuthBlob here should be acquired on the game client using SteamUser()->InitiateGameConnection() + // and must then be sent up to the game server for authentication. + // + // Return Value: returns true if the users ticket passes basic checks. pSteamIDUser will contain the Steam ID of this user. pSteamIDUser must NOT be NULL + // If the call succeeds then you should expect a GSClientApprove_t or GSClientDeny_t callback which will tell you whether authentication + // for the user has succeeded or failed (the steamid in the callback will match the one returned by this call) + virtual bool SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser ) = 0; + + // Creates a fake user (ie, a bot) which will be listed as playing on the server, but skips validation. + // + // Return Value: Returns a SteamID for the user to be tracked with, you should call HandleUserDisconnect() + // when this user leaves the server just like you would for a real user. + virtual CSteamID CreateUnauthenticatedUserConnection() = 0; + + // Should be called whenever a user leaves our game server, this lets Steam internally + // track which users are currently on which servers for the purposes of preventing a single + // account being logged into multiple servers, showing who is currently on a server, etc. + virtual void SendUserDisconnect( CSteamID steamIDUser ) = 0; + + // Update the data to be displayed in the server browser and matchmaking interfaces for a user + // currently connected to the server. For regular users you must call this after you receive a + // GSUserValidationSuccess callback. + // + // Return Value: true if successful, false if failure (ie, steamIDUser wasn't for an active player) + virtual bool BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore ) = 0; + + // New auth system APIs - do not mix with the old auth system APIs. + // ---------------------------------------------------------------- + + // Retrieve ticket to be sent to the entity who wishes to authenticate you ( using BeginAuthSession API ). + // pcbTicket retrieves the length of the actual ticket. + virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0; +#endif // Authenticate ticket ( from GetAuthSessionTicket ) from entity steamID to be sure it is valid and isnt reused // Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse ) @@ -206,6 +248,24 @@ class ISteamGameServer // Call this each frame until it returns 0. virtual int GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *pNetAdr, uint16 *pPort ) = 0; +#ifndef SDK_MP +// +// Control heartbeats / advertisement with master server +// + + // Call this as often as you like to tell the master server updater whether or not + // you want it to be active (default: off). + virtual void EnableHeartbeats( bool bActive ) = 0; + + // You usually don't need to modify this. + // Pass -1 to use the default value for iHeartbeatInterval. + // Some mods change this. + virtual void SetHeartbeatInterval( int iHeartbeatInterval ) = 0; + + // Force a heartbeat to steam at the next opportunity + virtual void ForceHeartbeat() = 0; +#endif + // // Server clan association // @@ -221,6 +281,7 @@ class ISteamGameServer +#ifdef SDK_MP // Handles receiving a new connection from a Steam user. This call will ask the Steam // servers to validate the users identity, app ownership, and VAC status. If the Steam servers // are off-line, then it will validate the cached ticket itself which will validate app ownership @@ -264,9 +325,14 @@ class ISteamGameServer virtual void SetMasterServerHeartbeatInterval_DEPRECATED( int iHeartbeatInterval ) = 0; virtual void ForceMasterServerHeartbeat_DEPRECATED() = 0; ) +#endif }; +#ifdef SDK_MP #define STEAMGAMESERVER_INTERFACE_VERSION "SteamGameServer015" +#else +#define STEAMGAMESERVER_INTERFACE_VERSION "SteamGameServer012" +#endif // Global accessor inline ISteamGameServer *SteamGameServer(); diff --git a/src/public/steam/isteamgameserverstats.h b/src/public/steam/isteamgameserverstats.h index 50192794e13..30a2ed21a87 100644 --- a/src/public/steam/isteamgameserverstats.h +++ b/src/public/steam/isteamgameserverstats.h @@ -1,4 +1,4 @@ -//====== Copyright © Valve Corporation, All rights reserved. ======= +//====== Copyright � Valve Corporation, All rights reserved. ======= // // Purpose: interface for game servers to steam stats and achievements // @@ -62,9 +62,11 @@ class ISteamGameServerStats }; #define STEAMGAMESERVERSTATS_INTERFACE_VERSION "SteamGameServerStats001" +#ifdef SDK_MP // Global accessor inline ISteamGameServerStats *SteamGameServerStats(); STEAM_DEFINE_GAMESERVER_INTERFACE_ACCESSOR( ISteamGameServerStats *, SteamGameServerStats, STEAMGAMESERVERSTATS_INTERFACE_VERSION ); +#endif // callbacks diff --git a/src/public/steam/isteamgamestats.h b/src/public/steam/isteamgamestats.h index aa40e2bdb2b..62b9941fb52 100644 --- a/src/public/steam/isteamgamestats.h +++ b/src/public/steam/isteamgamestats.h @@ -1,9 +1,14 @@ -//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2008, Valve Corporation, All rights reserved. ======= // // Purpose: interface to steam for game play statistics // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMGAMESTATS_H +#endif + #ifndef ISTEAMGAMESTATS_H #define ISTEAMGAMESTATS_H #ifdef _WIN32 diff --git a/src/public/steam/isteamhtmlsurface.h b/src/public/steam/isteamhtmlsurface.h index dd30fe249dd..4f604c0be9c 100644 --- a/src/public/steam/isteamhtmlsurface.h +++ b/src/public/steam/isteamhtmlsurface.h @@ -139,7 +139,11 @@ class ISteamHTMLSurface // keyboard interactions, native keycode is the virtual key code value from your OS, system key flags the key to not // be sent as a typed character as well as a key down +#ifdef SDK_MP virtual void KeyDown( HHTMLBrowser unBrowserHandle, uint32 nNativeKeyCode, EHTMLKeyModifiers eHTMLKeyModifiers, bool bIsSystemKey = false ) = 0; +#else + virtual void KeyDown( HHTMLBrowser unBrowserHandle, uint32 nNativeKeyCode, EHTMLKeyModifiers eHTMLKeyModifiers ) = 0; +#endif virtual void KeyUp( HHTMLBrowser unBrowserHandle, uint32 nNativeKeyCode, EHTMLKeyModifiers eHTMLKeyModifiers ) = 0; // cUnicodeChar is the unicode character point for this keypress (and potentially multiple chars per press) virtual void KeyChar( HHTMLBrowser unBrowserHandle, uint32 cUnicodeChar, EHTMLKeyModifiers eHTMLKeyModifiers ) = 0; @@ -172,6 +176,7 @@ class ISteamHTMLSurface // Zoom the current page by flZoom ( from 0.0 to 2.0, so to zoom to 120% use 1.2 ), zooming around point X,Y in the page (use 0,0 if you don't care) virtual void SetPageScaleFactor( HHTMLBrowser unBrowserHandle, float flZoom, int nPointX, int nPointY ) = 0; +#ifdef SDK_MP // Enable/disable low-resource background mode, where javascript and repaint timers are throttled, resources are // more aggressively purged from memory, and audio/video elements are paused. When background mode is enabled, // all HTML5 video and audio objects will execute ".pause()" and gain the property "._steam_background_paused = 1". @@ -184,6 +189,7 @@ class ISteamHTMLSurface // Open HTML/JS developer tools virtual void OpenDeveloperTools( HHTMLBrowser unBrowserHandle ) = 0; +#endif // CALLBACKS // @@ -204,11 +210,15 @@ class ISteamHTMLSurface virtual void FileLoadDialogResponse( HHTMLBrowser unBrowserHandle, const char **pchSelectedFiles ) = 0; }; +#ifdef SDK_MP #define STEAMHTMLSURFACE_INTERFACE_VERSION "STEAMHTMLSURFACE_INTERFACE_VERSION_005" // Global interface accessor inline ISteamHTMLSurface *SteamHTMLSurface(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamHTMLSurface *, SteamHTMLSurface, STEAMHTMLSURFACE_INTERFACE_VERSION ); +#else +#define STEAMHTMLSURFACE_INTERFACE_VERSION "STEAMHTMLSURFACE_INTERFACE_VERSION_002" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamhttp.h b/src/public/steam/isteamhttp.h index 1e5d043de3a..6ce145101d8 100644 --- a/src/public/steam/isteamhttp.h +++ b/src/public/steam/isteamhttp.h @@ -109,6 +109,7 @@ class ISteamHTTP // parameter will set the content-type header for the request so the server may know how to interpret the body. virtual bool SetHTTPRequestRawPostBody( HTTPRequestHandle hRequest, const char *pchContentType, uint8 *pubBody, uint32 unBodyLen ) = 0; +#ifdef SDK_MP // Creates a cookie container handle which you must later free with ReleaseCookieContainer(). If bAllowResponsesToModify=true // than any response to your requests using this cookie container may add new cookies which may be transmitted with // future requests. If bAllowResponsesToModify=false than only cookies you explicitly set will be sent. This API is just for @@ -138,8 +139,10 @@ class ISteamHTTP // Check if the reason the request failed was because we timed it out (rather than some harder failure) virtual bool GetHTTPRequestWasTimedOut( HTTPRequestHandle hRequest, bool *pbWasTimedOut ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMHTTP_INTERFACE_VERSION "STEAMHTTP_INTERFACE_VERSION003" // Global interface accessor @@ -149,6 +152,9 @@ STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamHTTP *, SteamHTTP, STEAMHTTP_INTERFA // Global accessor for the gameserver client inline ISteamHTTP *SteamGameServerHTTP(); STEAM_DEFINE_GAMESERVER_INTERFACE_ACCESSOR( ISteamHTTP *, SteamGameServerHTTP, STEAMHTTP_INTERFACE_VERSION ); +#else +#define STEAMHTTP_INTERFACE_VERSION "STEAMHTTP_INTERFACE_VERSION002" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteaminput.h b/src/public/steam/isteaminput.h index 9b30278520e..9bfa649c3d9 100644 --- a/src/public/steam/isteaminput.h +++ b/src/public/steam/isteaminput.h @@ -7,6 +7,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMINPUT_H +#endif + #ifndef ISTEAMINPUT_H #define ISTEAMINPUT_H #ifdef _WIN32 diff --git a/src/public/steam/isteaminventory.h b/src/public/steam/isteaminventory.h index 7066592078e..cc42a139587 100644 --- a/src/public/steam/isteaminventory.h +++ b/src/public/steam/isteaminventory.h @@ -1,9 +1,14 @@ -//====== Copyright © 1996-2014 Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2014 Valve Corporation, All rights reserved. ======= // // Purpose: interface to Steam Inventory // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMINVENTORY_H +#endif + #ifndef ISTEAMINVENTORY_H #define ISTEAMINVENTORY_H #ifdef _WIN32 diff --git a/src/public/steam/isteammatchmaking.h b/src/public/steam/isteammatchmaking.h index 12189c72b15..d30566d47ff 100644 --- a/src/public/steam/isteammatchmaking.h +++ b/src/public/steam/isteammatchmaking.h @@ -259,9 +259,11 @@ class ISteamMatchmaking }; #define STEAMMATCHMAKING_INTERFACE_VERSION "SteamMatchMaking009" +#ifdef SDK_MP // Global interface accessor inline ISteamMatchmaking *SteamMatchmaking(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamMatchmaking *, SteamMatchmaking, STEAMMATCHMAKING_INTERFACE_VERSION ); +#endif //----------------------------------------------------------------------------- // Callback interfaces for server list functions (see ISteamMatchmakingServers below) @@ -524,9 +526,11 @@ class ISteamMatchmakingServers }; #define STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION "SteamMatchMakingServers002" +#ifdef SDK_MP // Global interface accessor inline ISteamMatchmakingServers *SteamMatchmakingServers(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamMatchmakingServers *, SteamMatchmakingServers, STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION ); +#endif // game server flags const uint32 k_unFavoriteFlagNone = 0x00; @@ -552,6 +556,7 @@ enum EChatMemberStateChange +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: Functions for match making services for clients to get to favorites // and to operate on game lobbies. @@ -725,6 +730,7 @@ STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamParties *, SteamParties, STEAMPARTIE //----------------------------------------------------------------------------- // Callbacks for ISteamMatchmaking (which go through the regular Steam callback registration system) +#endif //----------------------------------------------------------------------------- // Purpose: a server was added/removed from the favorites list, you should refresh now @@ -918,6 +924,7 @@ struct FavoritesListAccountsUpdated_t +#ifdef SDK_MP //----------------------------------------------------------------------------- // Callbacks for ISteamGameSearch (which go through the regular Steam callback registration system) @@ -1082,6 +1089,7 @@ struct ActiveBeaconsUpdated_t #pragma pack( pop ) +#endif #endif // ISTEAMMATCHMAKING diff --git a/src/public/steam/isteammusic.h b/src/public/steam/isteammusic.h index ffa49a08933..4a84b601692 100644 --- a/src/public/steam/isteammusic.h +++ b/src/public/steam/isteammusic.h @@ -44,9 +44,11 @@ class ISteamMusic #define STEAMMUSIC_INTERFACE_VERSION "STEAMMUSIC_INTERFACE_VERSION001" +#ifdef SDK_MP // Global interface accessor inline ISteamMusic *SteamMusic(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamMusic *, SteamMusic, STEAMMUSIC_INTERFACE_VERSION ); +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteammusicremote.h b/src/public/steam/isteammusicremote.h index a36f4f873f9..5189f4c8eb1 100644 --- a/src/public/steam/isteammusicremote.h +++ b/src/public/steam/isteammusicremote.h @@ -64,9 +64,11 @@ class ISteamMusicRemote #define STEAMMUSICREMOTE_INTERFACE_VERSION "STEAMMUSICREMOTE_INTERFACE_VERSION001" +#ifdef SDK_MP // Global interface accessor inline ISteamMusicRemote *SteamMusicRemote(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamMusicRemote *, SteamMusicRemote, STEAMMUSICREMOTE_INTERFACE_VERSION ); +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamnetworking.h b/src/public/steam/isteamnetworking.h index b7e077a3b8a..7650e8e9a32 100644 --- a/src/public/steam/isteamnetworking.h +++ b/src/public/steam/isteamnetworking.h @@ -288,6 +288,7 @@ class ISteamNetworking // max packet size, in bytes virtual int GetMaxPacketSize( SNetSocket_t hSocket ) = 0; }; +#ifdef SDK_MP #define STEAMNETWORKING_INTERFACE_VERSION "SteamNetworking006" // Global interface accessor @@ -297,6 +298,9 @@ STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamNetworking *, SteamNetworking, STEAM // Global accessor for the gameserver client inline ISteamNetworking *SteamGameServerNetworking(); STEAM_DEFINE_GAMESERVER_INTERFACE_ACCESSOR( ISteamNetworking *, SteamGameServerNetworking, STEAMNETWORKING_INTERFACE_VERSION ); +#else +#define STEAMNETWORKING_INTERFACE_VERSION "SteamNetworking005" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamnetworkingmessages.h b/src/public/steam/isteamnetworkingmessages.h index b7a2cd0e554..0a3d6966708 100644 --- a/src/public/steam/isteamnetworkingmessages.h +++ b/src/public/steam/isteamnetworkingmessages.h @@ -1,5 +1,10 @@ //====== Copyright Valve Corporation, All rights reserved. ==================== +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMNETWORKINGMESSAGES +#endif + #ifndef ISTEAMNETWORKINGMESSAGES #define ISTEAMNETWORKINGMESSAGES #pragma once diff --git a/src/public/steam/isteamnetworkingsockets.h b/src/public/steam/isteamnetworkingsockets.h index b4e9ec332f8..889b1cc2f4f 100644 --- a/src/public/steam/isteamnetworkingsockets.h +++ b/src/public/steam/isteamnetworkingsockets.h @@ -1,5 +1,10 @@ //====== Copyright Valve Corporation, All rights reserved. ==================== +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMNETWORKINGSOCKETS +#endif + #ifndef ISTEAMNETWORKINGSOCKETS #define ISTEAMNETWORKINGSOCKETS #pragma once diff --git a/src/public/steam/isteamnetworkingutils.h b/src/public/steam/isteamnetworkingutils.h index 626efedf931..fef20ee562b 100644 --- a/src/public/steam/isteamnetworkingutils.h +++ b/src/public/steam/isteamnetworkingutils.h @@ -4,6 +4,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMNETWORKINGUTILS +#endif + #ifndef ISTEAMNETWORKINGUTILS #define ISTEAMNETWORKINGUTILS #pragma once diff --git a/src/public/steam/isteamparentalsettings.h b/src/public/steam/isteamparentalsettings.h index a1ff15205ed..7c95ed345ca 100644 --- a/src/public/steam/isteamparentalsettings.h +++ b/src/public/steam/isteamparentalsettings.h @@ -4,6 +4,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMPARENTALSETTINGS_H +#endif + #ifndef ISTEAMPARENTALSETTINGS_H #define ISTEAMPARENTALSETTINGS_H #ifdef _WIN32 diff --git a/src/public/steam/isteamremoteplay.h b/src/public/steam/isteamremoteplay.h index 569c2359d99..e232932d24f 100644 --- a/src/public/steam/isteamremoteplay.h +++ b/src/public/steam/isteamremoteplay.h @@ -1,5 +1,10 @@ //============ Copyright (c) Valve Corporation, All rights reserved. ============ +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMREMOTEPLAY_H +#endif + #ifndef ISTEAMREMOTEPLAY_H #define ISTEAMREMOTEPLAY_H #ifdef _WIN32 diff --git a/src/public/steam/isteamremotestorage.h b/src/public/steam/isteamremotestorage.h index 01b8dae3ae0..e861d9a6072 100644 --- a/src/public/steam/isteamremotestorage.h +++ b/src/public/steam/isteamremotestorage.h @@ -197,12 +197,14 @@ class ISteamRemoteStorage virtual bool FileWrite( const char *pchFile, const void *pvData, int32 cubData ) = 0; virtual int32 FileRead( const char *pchFile, void *pvData, int32 cubDataToRead ) = 0; +#ifdef SDK_MP STEAM_CALL_RESULT( RemoteStorageFileWriteAsyncComplete_t ) virtual SteamAPICall_t FileWriteAsync( const char *pchFile, const void *pvData, uint32 cubData ) = 0; STEAM_CALL_RESULT( RemoteStorageFileReadAsyncComplete_t ) virtual SteamAPICall_t FileReadAsync( const char *pchFile, uint32 nOffset, uint32 cubToRead ) = 0; virtual bool FileReadAsyncComplete( SteamAPICall_t hReadCall, void *pvBuffer, uint32 cubToRead ) = 0; +#endif virtual bool FileForget( const char *pchFile ) = 0; virtual bool FileDelete( const char *pchFile ) = 0; @@ -228,7 +230,11 @@ class ISteamRemoteStorage virtual const char *GetFileNameAndSize( int iFile, int32 *pnFileSizeInBytes ) = 0; // configuration management +#ifdef SDK_MP virtual bool GetQuota( uint64 *pnTotalBytes, uint64 *puAvailableBytes ) = 0; +#else + virtual bool GetQuota( int32 *pnTotalBytes, int32 *puAvailableBytes ) = 0; +#endif virtual bool IsCloudEnabledForAccount() = 0; virtual bool IsCloudEnabledForApp() = 0; virtual void SetCloudEnabledForApp( bool bEnabled ) = 0; @@ -310,6 +316,7 @@ class ISteamRemoteStorage STEAM_CALL_RESULT( RemoteStorageDownloadUGCResult_t ) virtual SteamAPICall_t UGCDownloadToLocation( UGCHandle_t hContent, const char *pchLocation, uint32 unPriority ) = 0; +#ifdef SDK_MP // Cloud dynamic state change notification virtual int32 GetLocalFileChangeCount() = 0; virtual const char *GetLocalFileChange( int iFile, ERemoteStorageLocalFileChange *pEChangeType, ERemoteStorageFilePathType *pEFilePathType ) = 0; @@ -318,13 +325,18 @@ class ISteamRemoteStorage // operations - for example, writing a game save that requires updating two files. virtual bool BeginFileWriteBatch() = 0; virtual bool EndFileWriteBatch() = 0; +#endif }; +#ifdef SDK_MP #define STEAMREMOTESTORAGE_INTERFACE_VERSION "STEAMREMOTESTORAGE_INTERFACE_VERSION016" // Global interface accessor inline ISteamRemoteStorage *SteamRemoteStorage(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamRemoteStorage *, SteamRemoteStorage, STEAMREMOTESTORAGE_INTERFACE_VERSION ); +#else +#define STEAMREMOTESTORAGE_INTERFACE_VERSION "STEAMREMOTESTORAGE_INTERFACE_VERSION012" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamscreenshots.h b/src/public/steam/isteamscreenshots.h index 18242682c34..c8165042773 100644 --- a/src/public/steam/isteamscreenshots.h +++ b/src/public/steam/isteamscreenshots.h @@ -68,6 +68,7 @@ class ISteamScreenshots // Tags a published file as being visible in the screenshot virtual bool TagPublishedFile( ScreenshotHandle hScreenshot, PublishedFileId_t unPublishedFileID ) = 0; +#ifdef SDK_MP // Returns true if the app has hooked the screenshot virtual bool IsScreenshotsHooked() = 0; @@ -77,13 +78,18 @@ class ISteamScreenshots // The return value is a handle that is valid for the duration of the game process and can be used to apply tags. // JPEG, TGA, and PNG formats are supported. virtual ScreenshotHandle AddVRScreenshotToLibrary( EVRScreenshotType eType, const char *pchFilename, const char *pchVRFilename ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMSCREENSHOTS_INTERFACE_VERSION "STEAMSCREENSHOTS_INTERFACE_VERSION003" // Global interface accessor inline ISteamScreenshots *SteamScreenshots(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamScreenshots *, SteamScreenshots, STEAMSCREENSHOTS_INTERFACE_VERSION ); +#else +#define STEAMSCREENSHOTS_INTERFACE_VERSION "STEAMSCREENSHOTS_INTERFACE_VERSION002" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamtimeline.h b/src/public/steam/isteamtimeline.h index 800c6bd1a8b..76ba6cc1a2b 100644 --- a/src/public/steam/isteamtimeline.h +++ b/src/public/steam/isteamtimeline.h @@ -1,9 +1,14 @@ -//====== Copyright © Valve Corporation, All rights reserved. ======= +//====== Copyright � Valve Corporation, All rights reserved. ======= // // Purpose: interface to Steam Timeline // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMTIMELINE_H +#endif + #ifndef ISTEAMTIMELINE_H #define ISTEAMTIMELINE_H #ifdef _WIN32 diff --git a/src/public/steam/isteamtv.h b/src/public/steam/isteamtv.h index 0760f8919a2..cb7904e0cfc 100644 --- a/src/public/steam/isteamtv.h +++ b/src/public/steam/isteamtv.h @@ -1,9 +1,14 @@ -//====== Copyright © 1996-2014 Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2014 Valve Corporation, All rights reserved. ======= // // Purpose: interface to Steam Video // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMTV_H +#endif + #ifndef ISTEAMTV_H #define ISTEAMTV_H #ifdef _WIN32 diff --git a/src/public/steam/isteamugc.h b/src/public/steam/isteamugc.h index a528f2d7b20..29e6edc7fa0 100644 --- a/src/public/steam/isteamugc.h +++ b/src/public/steam/isteamugc.h @@ -221,8 +221,10 @@ class ISteamUGC STEAM_FLAT_NAME( CreateQueryAllUGCRequestCursor ) virtual UGCQueryHandle_t CreateQueryAllUGCRequest( EUGCQuery eQueryType, EUGCMatchingUGCType eMatchingeMatchingUGCTypeFileType, AppId_t nCreatorAppID, AppId_t nConsumerAppID, const char *pchCursor = NULL ) = 0; +#ifdef SDK_MP // Query for the details of the given published file ids (the RequestUGCDetails call is deprecated and replaced with this) virtual UGCQueryHandle_t CreateQueryUGCDetailsRequest( PublishedFileId_t *pvecPublishedFileID, uint32 unNumPublishedFileIDs ) = 0; +#endif // Send the query to Steam STEAM_CALL_RESULT( SteamUGCQueryCompleted_t ) @@ -230,6 +232,7 @@ class ISteamUGC // Retrieve an individual result after receiving the callback for querying UGC virtual bool GetQueryUGCResult( UGCQueryHandle_t handle, uint32 index, SteamUGCDetails_t *pDetails ) = 0; +#ifdef SDK_MP virtual uint32 GetQueryUGCNumTags( UGCQueryHandle_t handle, uint32 index ) = 0; virtual bool GetQueryUGCTag( UGCQueryHandle_t handle, uint32 index, uint32 indexTag, STEAM_OUT_STRING_COUNT( cchValueSize ) char* pchValue, uint32 cchValueSize ) = 0; virtual bool GetQueryUGCTagDisplayName( UGCQueryHandle_t handle, uint32 index, uint32 indexTag, STEAM_OUT_STRING_COUNT( cchValueSize ) char* pchValue, uint32 cchValueSize ) = 0; @@ -247,11 +250,13 @@ class ISteamUGC virtual bool GetQueryUGCKeyValueTag( UGCQueryHandle_t handle, uint32 index, const char *pchKey, STEAM_OUT_STRING_COUNT(cchValueSize) char *pchValue, uint32 cchValueSize ) = 0; virtual uint32 GetQueryUGCContentDescriptors( UGCQueryHandle_t handle, uint32 index, EUGCContentDescriptorID *pvecDescriptors, uint32 cMaxEntries ) = 0; +#endif // Release the request to free up memory, after retrieving results virtual bool ReleaseQueryUGCRequest( UGCQueryHandle_t handle ) = 0; // Options to set for querying UGC +#ifdef SDK_MP virtual bool AddRequiredTag( UGCQueryHandle_t handle, const char *pTagName ) = 0; virtual bool AddRequiredTagGroup( UGCQueryHandle_t handle, const SteamParamStringArray_t *pTagGroups ) = 0; // match any of the tags in this group virtual bool AddExcludedTag( UGCQueryHandle_t handle, const char *pTagName ) = 0; @@ -265,6 +270,13 @@ class ISteamUGC virtual bool SetReturnPlaytimeStats( UGCQueryHandle_t handle, uint32 unDays ) = 0; virtual bool SetLanguage( UGCQueryHandle_t handle, const char *pchLanguage ) = 0; virtual bool SetAllowCachedResponse( UGCQueryHandle_t handle, uint32 unMaxAgeSeconds ) = 0; +#else + virtual bool AddRequiredTag( UGCQueryHandle_t handle, const char *pTagName ) = 0; + virtual bool AddExcludedTag( UGCQueryHandle_t handle, const char *pTagName ) = 0; + virtual bool SetReturnLongDescription( UGCQueryHandle_t handle, bool bReturnLongDescription ) = 0; + virtual bool SetReturnTotalOnly( UGCQueryHandle_t handle, bool bReturnTotalOnly ) = 0; + virtual bool SetAllowCachedResponse( UGCQueryHandle_t handle, uint32 unMaxAgeSeconds ) = 0; +#endif // Options only for querying user UGC virtual bool SetCloudFileNameFilter( UGCQueryHandle_t handle, const char *pMatchCloudFileName ) = 0; @@ -273,9 +285,11 @@ class ISteamUGC virtual bool SetMatchAnyTag( UGCQueryHandle_t handle, bool bMatchAnyTag ) = 0; virtual bool SetSearchText( UGCQueryHandle_t handle, const char *pSearchText ) = 0; virtual bool SetRankedByTrendDays( UGCQueryHandle_t handle, uint32 unDays ) = 0; +#ifdef SDK_MP virtual bool SetTimeCreatedDateRange( UGCQueryHandle_t handle, RTime32 rtStart, RTime32 rtEnd ) = 0; virtual bool SetTimeUpdatedDateRange( UGCQueryHandle_t handle, RTime32 rtStart, RTime32 rtEnd ) = 0; virtual bool AddRequiredKeyValueTag( UGCQueryHandle_t handle, const char *pKey, const char *pValue ) = 0; +#endif // DEPRECATED - Use CreateQueryUGCDetailsRequest call above instead! STEAM_CALL_RESULT( SteamUGCRequestUGCDetailsResult_t ) @@ -289,11 +303,14 @@ class ISteamUGC virtual bool SetItemTitle( UGCUpdateHandle_t handle, const char *pchTitle ) = 0; // change the title of an UGC item virtual bool SetItemDescription( UGCUpdateHandle_t handle, const char *pchDescription ) = 0; // change the description of an UGC item +#ifdef SDK_MP virtual bool SetItemUpdateLanguage( UGCUpdateHandle_t handle, const char *pchLanguage ) = 0; // specify the language of the title or description that will be set virtual bool SetItemMetadata( UGCUpdateHandle_t handle, const char *pchMetaData ) = 0; // change the metadata of an UGC item (max = k_cchDeveloperMetadataMax) +#endif virtual bool SetItemVisibility( UGCUpdateHandle_t handle, ERemoteStoragePublishedFileVisibility eVisibility ) = 0; // change the visibility of an UGC item virtual bool SetItemTags( UGCUpdateHandle_t updateHandle, const SteamParamStringArray_t *pTags ) = 0; // change the tags of an UGC item virtual bool SetItemContent( UGCUpdateHandle_t handle, const char *pszContentFolder ) = 0; // update item content from this local folder +#ifdef SDK_MP virtual bool SetItemPreview( UGCUpdateHandle_t handle, const char *pszPreviewFile ) = 0; // change preview image file for this item. pszPreviewFile points to local image file, which must be under 1MB in size virtual bool SetAllowLegacyUpload( UGCUpdateHandle_t handle, bool bAllowLegacyUpload ) = 0; // use legacy upload for a single small file. The parameter to SetItemContent() should either be a directory with one file or the full path to the file. The file must also be less than 10MB in size. virtual bool RemoveAllItemKeyValueTags( UGCUpdateHandle_t handle ) = 0; // remove all existing key-value tags (you can add new ones via the AddItemKeyValueTag function) @@ -306,6 +323,7 @@ class ISteamUGC virtual bool RemoveItemPreview( UGCUpdateHandle_t handle, uint32 index ) = 0; // remove a preview by index starting at 0 (previews are sorted) virtual bool AddContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) = 0; virtual bool RemoveContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) = 0; +#endif STEAM_CALL_RESULT( SubmitItemUpdateResult_t ) virtual SteamAPICall_t SubmitItemUpdate( UGCUpdateHandle_t handle, const char *pchChangeNote ) = 0; // commit update process started with StartItemUpdate() @@ -327,6 +345,7 @@ class ISteamUGC virtual uint32 GetNumSubscribedItems() = 0; // number of subscribed items virtual uint32 GetSubscribedItems( PublishedFileId_t* pvecPublishedFileID, uint32 cMaxEntries ) = 0; // all subscribed item PublishFileIDs +#ifdef SDK_MP // get EItemState flags about item on this client virtual uint32 GetItemState( PublishedFileId_t nPublishedFileID ) = 0; @@ -382,8 +401,13 @@ class ISteamUGC // Retrieve information related to the user's acceptance or not of the app's specific Workshop EULA STEAM_CALL_RESULT( WorkshopEULAStatus_t ) virtual SteamAPICall_t GetWorkshopEULAStatus() = 0; +#else + virtual bool GetItemInstallInfo( PublishedFileId_t nPublishedFileID, uint64 *punSizeOnDisk, char *pchFolder, uint32 cchFolderSize, bool *pbLegacyItem ) = 0; // returns true if item is installed + virtual bool GetItemUpdateInfo( PublishedFileId_t nPublishedFileID, bool *pbNeedsUpdate, bool *pbIsDownloading, uint64 *punBytesDownloaded, uint64 *punBytesTotal ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMUGC_INTERFACE_VERSION "STEAMUGC_INTERFACE_VERSION017" // Global interface accessor @@ -393,6 +417,9 @@ STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamUGC *, SteamUGC, STEAMUGC_INTERFACE_ // Global accessor for the gameserver client inline ISteamUGC *SteamGameServerUGC(); STEAM_DEFINE_GAMESERVER_INTERFACE_ACCESSOR( ISteamUGC *, SteamGameServerUGC, STEAMUGC_INTERFACE_VERSION ); +#else +#define STEAMUGC_INTERFACE_VERSION "STEAMUGC_INTERFACE_VERSION003" +#endif //----------------------------------------------------------------------------- // Purpose: Callback for querying UGC diff --git a/src/public/steam/isteamunifiedmessages.h b/src/public/steam/isteamunifiedmessages.h new file mode 100644 index 00000000000..0afdc941fd9 --- /dev/null +++ b/src/public/steam/isteamunifiedmessages.h @@ -0,0 +1,68 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Interface to unified messages client +// +// You should not need to use this interface except if your product is using a language other than C++. +// Contact your Steam Tech contact for more details. +// +//============================================================================= + +#ifdef SDK_MP +// Not in MP SDK +#define ISTEAMUNIFIEDMESSAGES_H +#endif + +#ifndef ISTEAMUNIFIEDMESSAGES_H +#define ISTEAMUNIFIEDMESSAGES_H +#ifdef _WIN32 +#pragma once +#endif + +typedef uint64 ClientUnifiedMessageHandle; + +class ISteamUnifiedMessages +{ +public: + static const ClientUnifiedMessageHandle k_InvalidUnifiedMessageHandle = 0; + + // Sends a service method (in binary serialized form) using the Steam Client. + // Returns a unified message handle (k_InvalidUnifiedMessageHandle if could not send the message). + virtual ClientUnifiedMessageHandle SendMethod( const char *pchServiceMethod, const void *pRequestBuffer, uint32 unRequestBufferSize, uint64 unContext ) = 0; + + // Gets the size of the response and the EResult. Returns false if the response is not ready yet. + virtual bool GetMethodResponseInfo( ClientUnifiedMessageHandle hHandle, uint32 *punResponseSize, EResult *peResult ) = 0; + + // Gets a response in binary serialized form (and optionally release the corresponding allocated memory). + virtual bool GetMethodResponseData( ClientUnifiedMessageHandle hHandle, void *pResponseBuffer, uint32 unResponseBufferSize, bool bAutoRelease ) = 0; + + // Releases the message and its corresponding allocated memory. + virtual bool ReleaseMethod( ClientUnifiedMessageHandle hHandle ) = 0; + + // Sends a service notification (in binary serialized form) using the Steam Client. + // Returns true if the notification was sent successfully. + virtual bool SendNotification( const char *pchServiceNotification, const void *pNotificationBuffer, uint32 unNotificationBufferSize ) = 0; +}; + +#define STEAMUNIFIEDMESSAGES_INTERFACE_VERSION "STEAMUNIFIEDMESSAGES_INTERFACE_VERSION001" + +// callbacks +#if defined( VALVE_CALLBACK_PACK_SMALL ) +#pragma pack( push, 4 ) +#elif defined( VALVE_CALLBACK_PACK_LARGE ) +#pragma pack( push, 8 ) +#else +#error isteamclient.h must be included +#endif + +struct SteamUnifiedMessagesSendMethodResult_t +{ + enum { k_iCallback = k_iClientUnifiedMessagesCallbacks + 1 }; + ClientUnifiedMessageHandle m_hHandle; // The handle returned by SendMethod(). + uint64 m_unContext; // Context provided when calling SendMethod(). + EResult m_eResult; // The result of the method call. + uint32 m_unResponseSize; // The size of the response. +}; + +#pragma pack( pop ) + +#endif // ISTEAMUNIFIEDMESSAGES_H diff --git a/src/public/steam/isteamuser.h b/src/public/steam/isteamuser.h index 182f02e7c3d..9aaf136dd27 100644 --- a/src/public/steam/isteamuser.h +++ b/src/public/steam/isteamuser.h @@ -47,17 +47,25 @@ class ISteamUser // // return value - returns the number of bytes written to pBlob. If the return is 0, then the buffer passed in was too small, and the call has failed // The contents of pBlob should then be sent to the game server, for it to use to complete the authentication process. +#ifdef SDK_MP // // DEPRECATED! This function will be removed from the SDK in an upcoming version. // Please migrate to BeginAuthSession and related functions. virtual int InitiateGameConnection_DEPRECATED( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) = 0; +#else + virtual int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) = 0; +#endif // notify of disconnect // needs to occur when the game client leaves the specified game server, needs to match with the InitiateGameConnection() call +#ifdef SDK_MP // // DEPRECATED! This function will be removed from the SDK in an upcoming version. // Please migrate to BeginAuthSession and related functions. virtual void TerminateGameConnection_DEPRECATED( uint32 unIPServer, uint16 usPortServer ) = 0; +#else + virtual void TerminateGameConnection( uint32 unIPServer, uint16 usPortServer ) = 0; +#endif // Legacy functions @@ -128,12 +136,16 @@ class ISteamUser // if an IP address is passed Steam will only allow the ticket to be used by an entity with that IP address // if a Steam ID is passed Steam will only allow the ticket to be used by that Steam ID // not to be used for "ISteamUserAuth\AuthenticateUserTicket" - it will fail +#ifdef SDK_MP virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket, const SteamNetworkingIdentity *pSteamNetworkingIdentity ) = 0; // Request a ticket which will be used for webapi "ISteamUserAuth\AuthenticateUserTicket" // pchIdentity is an optional input parameter to identify the service the ticket will be sent to // the ticket will be returned in callback GetTicketForWebApiResponse_t virtual HAuthTicket GetAuthTicketForWebApi( const char *pchIdentity ) = 0; +#else + virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0; +#endif // Authenticate ticket from entity steamID to be sure it is valid and isnt reused // Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse ) @@ -180,6 +192,7 @@ class ISteamUser // gets the Steam Level of the user, as shown on their profile virtual int GetPlayerSteamLevel() = 0; +#ifdef SDK_MP // Requests a URL which authenticates an in-game browser for store check-out, // and then redirects to the specified URL. As long as the in-game browser // accepts and handles session cookies, Steam microtransaction checkout pages @@ -216,14 +229,19 @@ class ISteamUser // This will prevent offline gameplay time from counting against a user's // playtime limits. virtual bool BSetDurationControlOnlineState( EDurationControlOnlineState eNewState ) = 0; +#endif }; +#ifdef SDK_MP #define STEAMUSER_INTERFACE_VERSION "SteamUser023" // Global interface accessor inline ISteamUser *SteamUser(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamUser *, SteamUser, STEAMUSER_INTERFACE_VERSION ); +#else +#define STEAMUSER_INTERFACE_VERSION "SteamUser017" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamuserstats.h b/src/public/steam/isteamuserstats.h index 8bb0c90f198..ec12dc76c6a 100644 --- a/src/public/steam/isteamuserstats.h +++ b/src/public/steam/isteamuserstats.h @@ -292,6 +292,7 @@ class ISteamUserStats STEAM_FLAT_NAME( GetGlobalStatHistoryDouble ) virtual int32 GetGlobalStatHistory( const char *pchStatName, STEAM_ARRAY_COUNT(cubData) double *pData, uint32 cubData ) = 0; +#ifdef SDK_MP // For achievements that have related Progress stats, use this to query what the bounds of that progress are. // You may want this info to selectively call IndicateAchievementProgress when appropriate milestones of progress // have been made, to show a progress notification to the user. @@ -300,14 +301,18 @@ class ISteamUserStats STEAM_FLAT_NAME( GetAchievementProgressLimitsFloat ) virtual bool GetAchievementProgressLimits( const char *pchName, float *pfMinProgress, float *pfMaxProgress ) = 0; - +#endif }; +#ifdef SDK_MP #define STEAMUSERSTATS_INTERFACE_VERSION "STEAMUSERSTATS_INTERFACE_VERSION012" // Global interface accessor inline ISteamUserStats *SteamUserStats(); STEAM_DEFINE_USER_INTERFACE_ACCESSOR( ISteamUserStats *, SteamUserStats, STEAMUSERSTATS_INTERFACE_VERSION ); +#else +#define STEAMUSERSTATS_INTERFACE_VERSION "STEAMUSERSTATS_INTERFACE_VERSION011" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) diff --git a/src/public/steam/isteamutils.h b/src/public/steam/isteamutils.h index c5651e763ca..675427594e6 100644 --- a/src/public/steam/isteamutils.h +++ b/src/public/steam/isteamutils.h @@ -158,6 +158,7 @@ class ISteamUtils // returns true if Steam itself is running in VR mode virtual bool IsSteamRunningInVR() = 0; +#ifdef SDK_MP // Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition. virtual void SetOverlayNotificationInset( int nHorizontalInset, int nVerticalInset ) = 0; @@ -215,8 +216,10 @@ class ISteamUtils // Dismisses the floating keyboard. virtual bool DismissFloatingGamepadTextInput() = 0; +#endif }; +#ifdef SDK_MP #define STEAMUTILS_INTERFACE_VERSION "SteamUtils010" // Global interface accessor @@ -226,6 +229,9 @@ STEAM_DEFINE_INTERFACE_ACCESSOR( ISteamUtils *, SteamUtils, SteamInternal_FindOr // Global accessor for the gameserver client inline ISteamUtils *SteamGameServerUtils(); STEAM_DEFINE_INTERFACE_ACCESSOR( ISteamUtils *, SteamGameServerUtils, SteamInternal_FindOrCreateGameServerInterface( 0, STEAMUTILS_INTERFACE_VERSION ), "gameserver", STEAMUTILS_INTERFACE_VERSION ); +#else +#define STEAMUTILS_INTERFACE_VERSION "SteamUtils007" +#endif // callbacks #if defined( VALVE_CALLBACK_PACK_SMALL ) @@ -262,8 +268,10 @@ struct SteamAPICallCompleted_t { enum { k_iCallback = k_iSteamUtilsCallbacks + 3 }; SteamAPICall_t m_hAsyncCall; +#ifdef SDK_MP int m_iCallback; uint32 m_cubParam; +#endif }; diff --git a/src/public/steam/isteamvideo.h b/src/public/steam/isteamvideo.h index cd7b1971530..619d245f354 100644 --- a/src/public/steam/isteamvideo.h +++ b/src/public/steam/isteamvideo.h @@ -1,9 +1,14 @@ -//====== Copyright © 1996-2014 Valve Corporation, All rights reserved. ======= +//====== Copyright � 1996-2014 Valve Corporation, All rights reserved. ======= // // Purpose: interface to Steam Video // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define ISTEAMVIDEO_H +#endif + #ifndef ISTEAMVIDEO_H #define ISTEAMVIDEO_H #ifdef _WIN32 diff --git a/src/public/steam/steam_api.h b/src/public/steam/steam_api.h index 494f1dd1ad0..8a4984b510e 100644 --- a/src/public/steam/steam_api.h +++ b/src/public/steam/steam_api.h @@ -11,6 +11,11 @@ // //============================================================================= +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "steam_api_sp.h" +#endif + #ifndef STEAM_API_H #define STEAM_API_H #ifdef _WIN32 diff --git a/src/public/steam/steam_api_common.h b/src/public/steam/steam_api_common.h index f3d93e25cff..7e0343fe6be 100644 --- a/src/public/steam/steam_api_common.h +++ b/src/public/steam/steam_api_common.h @@ -59,6 +59,9 @@ typedef int32 HSteamUser; // function prototype extern "C" typedef void ( S_CALLTYPE *SteamAPIWarningMessageHook_t )( int, const char * ); +#ifndef SDK_MP +extern "C" typedef void(*SteamAPI_PostAPIResultInProcess_t)(SteamAPICall_t callHandle, void *, uint32 unCallbackSize, int iCallbackNum); +#endif extern "C" typedef uint32 ( S_CALLTYPE *SteamAPI_CheckCallbackRegistered_t )( int iCallbackNum ); #if defined( __SNC__ ) #pragma diag_suppress=1700 // warning 1700: class "%s" has virtual functions but non-virtual destructor diff --git a/src/public/steam/steam_api_flat.h b/src/public/steam/steam_api_flat.h index ff3a2a18c8e..aca30d784b5 100644 --- a/src/public/steam/steam_api_flat.h +++ b/src/public/steam/steam_api_flat.h @@ -5,6 +5,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define STEAMAPIFLAT_H +#endif + #ifndef STEAMAPIFLAT_H #define STEAMAPIFLAT_H diff --git a/src/public/steam/steam_api_internal.h b/src/public/steam/steam_api_internal.h index 28251743928..95c1eb5c31a 100644 --- a/src/public/steam/steam_api_internal.h +++ b/src/public/steam/steam_api_internal.h @@ -237,6 +237,9 @@ class ISteamGameSearch; class ISteamInput; class ISteamParties; class ISteamRemotePlay; +#ifndef SDK_MP +class ISteamUnifiedMessages; +#endif // Forward declare types struct SteamNetworkingIdentity; @@ -266,7 +269,11 @@ enum { k_iSteam2AsyncCallbacks = 1900 }; enum { k_iSteamGameStatsCallbacks = 2000 }; enum { k_iSteamHTTPCallbacks = 2100 }; enum { k_iSteamScreenshotsCallbacks = 2300 }; +#ifdef SDK_MP // NOTE: 2500-2599 are reserved +#else +enum { k_iClientUnifiedMessagesCallbacks = 2500 }; +#endif enum { k_iSteamStreamLauncherCallbacks = 2600 }; enum { k_iSteamControllerCallbacks = 2800 }; enum { k_iSteamUGCCallbacks = 3400 }; @@ -308,6 +315,7 @@ enum { k_iSteamChatCallbacks = 5900 }; #define STEAM_CALL_BACK(RESULT_TYPE) STEAM_CLANG_ATTR("callback:" #RESULT_TYPE ";") #define STEAM_FLAT_NAME(NAME) STEAM_CLANG_ATTR("flat_name:" #NAME ";") +#ifdef SDK_MP // CSteamAPIContext encapsulates the Steamworks API global accessors into // a single object. // @@ -395,5 +403,6 @@ class CSteamGameServerAPIContext ISteamInventory *m_pSteamInventory; ISteamUGC *m_pSteamUGC; }; +#endif diff --git a/src/public/steam/steam_api_sp.h b/src/public/steam/steam_api_sp.h new file mode 100644 index 00000000000..915233fd649 --- /dev/null +++ b/src/public/steam/steam_api_sp.h @@ -0,0 +1,368 @@ +//====== Copyright 1996-2008, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#ifndef STEAM_API_H +#define STEAM_API_H +#ifdef _WIN32 +#pragma once +#endif + +#include "isteamclient.h" +#include "isteamuser.h" +#include "isteamfriends.h" +#include "isteamutils.h" +#include "isteammatchmaking.h" +#include "isteamuserstats.h" +#include "isteamapps.h" +#include "isteamnetworking.h" +#include "isteamremotestorage.h" +#include "isteamscreenshots.h" +#include "isteammusic.h" +#include "isteammusicremote.h" +#include "isteamhttp.h" +#include "isteamunifiedmessages.h" +#include "isteamcontroller.h" +#include "isteamugc.h" +#include "isteamapplist.h" +#include "isteamhtmlsurface.h" + +#if defined( _PS3 ) +#include "steamps3params.h" +#endif + +// Steam API export macro +#if defined( _WIN32 ) && !defined( _X360 ) + #if defined( STEAM_API_EXPORTS ) + #define S_API extern "C" __declspec( dllexport ) + #elif defined( STEAM_API_NODLL ) + #define S_API extern "C" + #else + #define S_API extern "C" __declspec( dllimport ) + #endif // STEAM_API_EXPORTS +#elif defined( GNUC ) + #if defined( STEAM_API_EXPORTS ) + #define S_API extern "C" __attribute__ ((visibility("default"))) + #else + #define S_API extern "C" + #endif // STEAM_API_EXPORTS +#else // !WIN32 + #if defined( STEAM_API_EXPORTS ) + #define S_API extern "C" + #else + #define S_API extern "C" + #endif // STEAM_API_EXPORTS +#endif + +//----------------------------------------------------------------------------------------------------------------------------------------------------------// +// Steam API setup & shutdown +// +// These functions manage loading, initializing and shutdown of the steamclient.dll +// +//----------------------------------------------------------------------------------------------------------------------------------------------------------// + +// S_API void SteamAPI_Init(); (see below) +S_API void S_CALLTYPE SteamAPI_Shutdown(); + +// checks if a local Steam client is running +S_API bool S_CALLTYPE SteamAPI_IsSteamRunning(); + +// Detects if your executable was launched through the Steam client, and restarts your game through +// the client if necessary. The Steam client will be started if it is not running. +// +// Returns: true if your executable was NOT launched through the Steam client. This function will +// then start your application through the client. Your current process should exit. +// +// false if your executable was started through the Steam client or a steam_appid.txt file +// is present in your game's directory (for development). Your current process should continue. +// +// NOTE: This function should be used only if you are using CEG or not using Steam's DRM. Once applied +// to your executable, Steam's DRM will handle restarting through Steam if necessary. +S_API bool S_CALLTYPE SteamAPI_RestartAppIfNecessary( uint32 unOwnAppID ); + +// crash dump recording functions +S_API void S_CALLTYPE SteamAPI_WriteMiniDump( uint32 uStructuredExceptionCode, void* pvExceptionInfo, uint32 uBuildID ); +S_API void S_CALLTYPE SteamAPI_SetMiniDumpComment( const char *pchMsg ); + +// interface pointers, configured by SteamAPI_Init() +S_API ISteamClient *S_CALLTYPE SteamClient(); + + +// +// VERSION_SAFE_STEAM_API_INTERFACES is usually not necessary, but it provides safety against releasing +// new steam_api.dll's without recompiling/rereleasing modules that use it. +// +// If you use VERSION_SAFE_STEAM_API_INTERFACES, then you should call SteamAPI_InitSafe(). Also, to get the +// Steam interfaces, you must create and Init() a CSteamAPIContext (below) and use the interfaces in there. +// +// If you don't use VERSION_SAFE_STEAM_API_INTERFACES, then you can use SteamAPI_Init() and the SteamXXXX() +// functions below to get at the Steam interfaces. +// +#ifdef VERSION_SAFE_STEAM_API_INTERFACES +S_API bool S_CALLTYPE SteamAPI_InitSafe(); +#else + +#if defined(_PS3) +S_API bool S_CALLTYPE SteamAPI_Init( SteamPS3Params_t *pParams ); +#else +S_API bool S_CALLTYPE SteamAPI_Init(); +#endif + +S_API ISteamUser *S_CALLTYPE SteamUser(); +S_API ISteamFriends *S_CALLTYPE SteamFriends(); +S_API ISteamUtils *S_CALLTYPE SteamUtils(); +S_API ISteamMatchmaking *S_CALLTYPE SteamMatchmaking(); +S_API ISteamUserStats *S_CALLTYPE SteamUserStats(); +S_API ISteamApps *S_CALLTYPE SteamApps(); +S_API ISteamNetworking *S_CALLTYPE SteamNetworking(); +S_API ISteamMatchmakingServers *S_CALLTYPE SteamMatchmakingServers(); +S_API ISteamRemoteStorage *S_CALLTYPE SteamRemoteStorage(); +S_API ISteamScreenshots *S_CALLTYPE SteamScreenshots(); +S_API ISteamHTTP *S_CALLTYPE SteamHTTP(); +S_API ISteamUnifiedMessages *S_CALLTYPE SteamUnifiedMessages(); +S_API ISteamController *S_CALLTYPE SteamController(); +S_API ISteamUGC *S_CALLTYPE SteamUGC(); +S_API ISteamAppList *S_CALLTYPE SteamAppList(); +S_API ISteamMusic *S_CALLTYPE SteamMusic(); +S_API ISteamMusicRemote *S_CALLTYPE SteamMusicRemote(); +S_API ISteamHTMLSurface *S_CALLTYPE SteamHTMLSurface(); +#ifdef _PS3 +S_API ISteamPS3OverlayRender *S_CALLTYPE SteamPS3OverlayRender(); +#endif +#endif // VERSION_SAFE_STEAM_API_INTERFACES + + +//----------------------------------------------------------------------------------------------------------------------------------------------------------// +// steamclient.dll private wrapper functions +// +// The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases +//----------------------------------------------------------------------------------------------------------------------------------------------------------// + +// pumps out all the steam messages, calling the register callback +S_API void Steam_RunCallbacks( HSteamPipe hSteamPipe, bool bGameServerCallbacks ); + +// register the callback funcs to use to interact with the steam dll +S_API void Steam_RegisterInterfaceFuncs( void *hModule ); + +// returns the HSteamUser of the last user to dispatch a callback +S_API HSteamUser Steam_GetHSteamUserCurrent(); + +// returns the filename path of the current running Steam process, used if you need to load an explicit steam dll by name +S_API const char *SteamAPI_GetSteamInstallPath(); + +// returns the pipe we are communicating to Steam with +S_API HSteamPipe SteamAPI_GetHSteamPipe(); + +// sets whether or not Steam_RunCallbacks() should do a try {} catch (...) {} around calls to issuing callbacks +S_API void SteamAPI_SetTryCatchCallbacks( bool bTryCatchCallbacks ); + +// backwards compat export, passes through to SteamAPI_ variants +S_API HSteamPipe GetHSteamPipe(); +S_API HSteamUser GetHSteamUser(); + +#ifdef VERSION_SAFE_STEAM_API_INTERFACES +//----------------------------------------------------------------------------------------------------------------------------------------------------------// +// VERSION_SAFE_STEAM_API_INTERFACES uses CSteamAPIContext to provide interfaces to each module in a way that +// lets them each specify the interface versions they are compiled with. +// +// It's important that these stay inlined in the header so the calling module specifies the interface versions +// for whatever Steam API version it has. +//----------------------------------------------------------------------------------------------------------------------------------------------------------// + +S_API HSteamUser SteamAPI_GetHSteamUser(); + +class CSteamAPIContext +{ +public: + CSteamAPIContext(); + void Clear(); + + bool Init(); + + ISteamUser* SteamUser() { return m_pSteamUser; } + ISteamFriends* SteamFriends() { return m_pSteamFriends; } + ISteamUtils* SteamUtils() { return m_pSteamUtils; } + ISteamMatchmaking* SteamMatchmaking() { return m_pSteamMatchmaking; } + ISteamUserStats* SteamUserStats() { return m_pSteamUserStats; } + ISteamApps* SteamApps() { return m_pSteamApps; } + ISteamMatchmakingServers* SteamMatchmakingServers() { return m_pSteamMatchmakingServers; } + ISteamNetworking* SteamNetworking() { return m_pSteamNetworking; } + ISteamRemoteStorage* SteamRemoteStorage() { return m_pSteamRemoteStorage; } + ISteamScreenshots* SteamScreenshots() { return m_pSteamScreenshots; } + ISteamHTTP* SteamHTTP() { return m_pSteamHTTP; } + ISteamUnifiedMessages* SteamUnifiedMessages() { return m_pSteamUnifiedMessages; } + ISteamController* SteamController() { return m_pController; } + ISteamUGC* SteamUGC() { return m_pSteamUGC; } + ISteamAppList* SteamAppList() { return m_pSteamAppList; } + ISteamMusic* SteamMusic() { return m_pSteamMusic; } + ISteamMusicRemote* SteamMusicRemote() { return m_pSteamMusicRemote; } + ISteamHTMLSurface* SteamHTMLSurface() { return m_pSteamHTMLSurface; } +#ifdef _PS3 + ISteamPS3OverlayRender* SteamPS3OverlayRender() { return m_pSteamPS3OverlayRender; } +#endif + +private: + ISteamUser *m_pSteamUser; + ISteamFriends *m_pSteamFriends; + ISteamUtils *m_pSteamUtils; + ISteamMatchmaking *m_pSteamMatchmaking; + ISteamUserStats *m_pSteamUserStats; + ISteamApps *m_pSteamApps; + ISteamMatchmakingServers *m_pSteamMatchmakingServers; + ISteamNetworking *m_pSteamNetworking; + ISteamRemoteStorage *m_pSteamRemoteStorage; + ISteamScreenshots *m_pSteamScreenshots; + ISteamHTTP *m_pSteamHTTP; + ISteamUnifiedMessages*m_pSteamUnifiedMessages; + ISteamController *m_pController; + ISteamUGC *m_pSteamUGC; + ISteamAppList *m_pSteamAppList; + ISteamMusic *m_pSteamMusic; + ISteamMusicRemote *m_pSteamMusicRemote; + ISteamHTMLSurface *m_pSteamHTMLSurface; +#ifdef _PS3 + ISteamPS3OverlayRender *m_pSteamPS3OverlayRender; +#endif +}; + +inline CSteamAPIContext::CSteamAPIContext() +{ + Clear(); +} + +inline void CSteamAPIContext::Clear() +{ + m_pSteamUser = NULL; + m_pSteamFriends = NULL; + m_pSteamUtils = NULL; + m_pSteamMatchmaking = NULL; + m_pSteamUserStats = NULL; + m_pSteamApps = NULL; + m_pSteamMatchmakingServers = NULL; + m_pSteamNetworking = NULL; + m_pSteamRemoteStorage = NULL; + m_pSteamHTTP = NULL; + m_pSteamScreenshots = NULL; + m_pSteamMusic = NULL; + m_pSteamUnifiedMessages = NULL; + m_pController = NULL; + m_pSteamUGC = NULL; + m_pSteamAppList = NULL; + m_pSteamMusic = NULL; + m_pSteamMusicRemote= NULL; + m_pSteamHTMLSurface = NULL; +#ifdef _PS3 + m_pSteamPS3OverlayRender = NULL; +#endif +} + +// This function must be inlined so the module using steam_api.dll gets the version names they want. +inline bool CSteamAPIContext::Init() +{ + if ( !SteamClient() ) + return false; + + HSteamUser hSteamUser = SteamAPI_GetHSteamUser(); + HSteamPipe hSteamPipe = SteamAPI_GetHSteamPipe(); + + m_pSteamUser = SteamClient()->GetISteamUser( hSteamUser, hSteamPipe, STEAMUSER_INTERFACE_VERSION ); + if ( !m_pSteamUser ) + return false; + + m_pSteamFriends = SteamClient()->GetISteamFriends( hSteamUser, hSteamPipe, STEAMFRIENDS_INTERFACE_VERSION ); + if ( !m_pSteamFriends ) + return false; + + m_pSteamUtils = SteamClient()->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION ); + if ( !m_pSteamUtils ) + return false; + + m_pSteamMatchmaking = SteamClient()->GetISteamMatchmaking( hSteamUser, hSteamPipe, STEAMMATCHMAKING_INTERFACE_VERSION ); + if ( !m_pSteamMatchmaking ) + return false; + + m_pSteamMatchmakingServers = SteamClient()->GetISteamMatchmakingServers( hSteamUser, hSteamPipe, STEAMMATCHMAKINGSERVERS_INTERFACE_VERSION ); + if ( !m_pSteamMatchmakingServers ) + return false; + + m_pSteamUserStats = SteamClient()->GetISteamUserStats( hSteamUser, hSteamPipe, STEAMUSERSTATS_INTERFACE_VERSION ); + if ( !m_pSteamUserStats ) + return false; + + m_pSteamApps = SteamClient()->GetISteamApps( hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION ); + if ( !m_pSteamApps ) + return false; + + m_pSteamNetworking = SteamClient()->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION ); + if ( !m_pSteamNetworking ) + return false; + + m_pSteamRemoteStorage = SteamClient()->GetISteamRemoteStorage( hSteamUser, hSteamPipe, STEAMREMOTESTORAGE_INTERFACE_VERSION ); + if ( !m_pSteamRemoteStorage ) + return false; + + m_pSteamScreenshots = SteamClient()->GetISteamScreenshots( hSteamUser, hSteamPipe, STEAMSCREENSHOTS_INTERFACE_VERSION ); + if ( !m_pSteamScreenshots ) + return false; + + m_pSteamHTTP = SteamClient()->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION ); + if ( !m_pSteamHTTP ) + return false; + + m_pSteamUnifiedMessages = SteamClient()->GetISteamUnifiedMessages( hSteamUser, hSteamPipe, STEAMUNIFIEDMESSAGES_INTERFACE_VERSION ); + if ( !m_pSteamUnifiedMessages ) + return false; + + m_pController = SteamClient()->GetISteamController( hSteamUser, hSteamPipe, STEAMCONTROLLER_INTERFACE_VERSION ); + if ( !m_pController ) + return false; + + m_pSteamUGC = SteamClient()->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION ); + if ( !m_pSteamUGC ) + return false; + + m_pSteamAppList = SteamClient()->GetISteamAppList( hSteamUser, hSteamPipe, STEAMAPPLIST_INTERFACE_VERSION ); + if ( !m_pSteamAppList ) + return false; + + m_pSteamMusic = SteamClient()->GetISteamMusic( hSteamUser, hSteamPipe, STEAMMUSIC_INTERFACE_VERSION ); + if ( !m_pSteamMusic ) + { + return false; + } + + m_pSteamMusicRemote = SteamClient()->GetISteamMusicRemote( hSteamUser, hSteamPipe, STEAMMUSICREMOTE_INTERFACE_VERSION ); + if ( !m_pSteamMusicRemote ) + { + return false; + } + + m_pSteamHTMLSurface = SteamClient()->GetISteamHTMLSurface( hSteamUser, hSteamPipe, STEAMHTMLSURFACE_INTERFACE_VERSION ); + if ( !m_pSteamHTMLSurface ) + { + return false; + } + +#ifdef _PS3 + m_pSteamPS3OverlayRender = SteamClient()->GetISteamPS3OverlayRender(); +#endif + + return true; +} + +#endif // VERSION_SAFE_STEAM_API_INTERFACES + +#if defined(USE_BREAKPAD_HANDLER) || defined(STEAM_API_EXPORTS) +// this should be called before the game initialized the steam APIs +// pchDate should be of the format "Mmm dd yyyy" (such as from the __DATE__ macro ) +// pchTime should be of the format "hh:mm:ss" (such as from the __TIME__ macro ) +// bFullMemoryDumps (Win32 only) -- writes out a uuid-full.dmp in the client/dumps folder +// pvContext-- can be NULL, will be the void * context passed into m_pfnPreMinidumpCallback +// PFNPreMinidumpCallback m_pfnPreMinidumpCallback -- optional callback which occurs just before a .dmp file is written during a crash. Applications can hook this to allow adding additional information into the .dmp comment stream. +S_API void S_CALLTYPE SteamAPI_UseBreakpadCrashHandler( char const *pchVersion, char const *pchDate, char const *pchTime, bool bFullMemoryDumps, void *pvContext, PFNPreMinidumpCallback m_pfnPreMinidumpCallback ); +S_API void S_CALLTYPE SteamAPI_SetBreakpadAppID( uint32 unAppID ); +#endif + +#endif // STEAM_API_H \ No newline at end of file diff --git a/src/public/steam/steam_gameserver.h b/src/public/steam/steam_gameserver.h index 28a436f56dd..f463ec4d7e9 100644 --- a/src/public/steam/steam_gameserver.h +++ b/src/public/steam/steam_gameserver.h @@ -53,6 +53,7 @@ inline bool SteamGameServer_Init( uint32 unIP, uint16 usGamePort, uint16 usQuery // Shutdown SteamGameSeverXxx interfaces, log out, and free resources. S_API void SteamGameServer_Shutdown(); +#ifdef SDK_MP // Most Steam API functions allocate some amount of thread-local memory for // parameter storage. Calling SteamGameServer_ReleaseCurrentThreadMemory() // will free all API-related memory associated with the calling thread. @@ -71,6 +72,13 @@ S_API uint64 SteamGameServer_GetSteamID(); // SteamGameServer_InitSafe has been replaced with SteamGameServer_Init and // is no longer supported. Use SteamGameServer_Init instead. //S_API void S_CALLTYPE SteamGameServer_InitSafe(); +#else +S_API void SteamGameServer_Shutdown(); +S_API void SteamGameServer_RunCallbacks(); + +S_API bool SteamGameServer_BSecure(); +S_API uint64 SteamGameServer_GetSteamID(); +#endif //============================================================================= // @@ -78,6 +86,7 @@ S_API uint64 SteamGameServer_GetSteamID(); // //============================================================================= +#ifdef SDK_MP #ifndef STEAM_API_EXPORTS // This function must be declared inline in the header so the module using steam_api.dll gets the version names they want. inline bool CSteamGameServerAPIContext::Init() @@ -113,5 +122,90 @@ inline void SteamGameServer_ReleaseCurrentThreadMemory() { SteamAPI_ReleaseCurrentThreadMemory(); } +#else +S_API HSteamPipe SteamGameServer_GetHSteamPipe(); + +#ifdef VERSION_SAFE_STEAM_API_INTERFACES +//----------------------------------------------------------------------------------------------------------------------------------------------------------// +// VERSION_SAFE_STEAM_API_INTERFACES uses CSteamAPIContext to provide interfaces to each module in a way that +// lets them each specify the interface versions they are compiled with. +// +// It's important that these stay inlined in the header so the calling module specifies the interface versions +// for whatever Steam API version it has. +//----------------------------------------------------------------------------------------------------------------------------------------------------------// + +S_API HSteamUser SteamGameServer_GetHSteamUser(); + +class CSteamGameServerAPIContext +{ +public: + CSteamGameServerAPIContext(); + void Clear(); + + bool Init(); + + ISteamGameServer *SteamGameServer() { return m_pSteamGameServer; } + ISteamUtils *SteamGameServerUtils() { return m_pSteamGameServerUtils; } + ISteamNetworking *SteamGameServerNetworking() { return m_pSteamGameServerNetworking; } + ISteamGameServerStats *SteamGameServerStats() { return m_pSteamGameServerStats; } + ISteamHTTP *SteamHTTP() { return m_pSteamHTTP; } + +private: + ISteamGameServer *m_pSteamGameServer; + ISteamUtils *m_pSteamGameServerUtils; + ISteamNetworking *m_pSteamGameServerNetworking; + ISteamGameServerStats *m_pSteamGameServerStats; + ISteamHTTP *m_pSteamHTTP; +}; + +inline CSteamGameServerAPIContext::CSteamGameServerAPIContext() +{ + Clear(); +} + +inline void CSteamGameServerAPIContext::Clear() +{ + m_pSteamGameServer = NULL; + m_pSteamGameServerUtils = NULL; + m_pSteamGameServerNetworking = NULL; + m_pSteamGameServerStats = NULL; + m_pSteamHTTP = NULL; +} + +S_API ISteamClient *g_pSteamClientGameServer; +// This function must be inlined so the module using steam_api.dll gets the version names they want. +inline bool CSteamGameServerAPIContext::Init() +{ + if ( !g_pSteamClientGameServer ) + return false; + + HSteamUser hSteamUser = SteamGameServer_GetHSteamUser(); + HSteamPipe hSteamPipe = SteamGameServer_GetHSteamPipe(); + + m_pSteamGameServer = g_pSteamClientGameServer->GetISteamGameServer( hSteamUser, hSteamPipe, STEAMGAMESERVER_INTERFACE_VERSION ); + if ( !m_pSteamGameServer ) + return false; + + m_pSteamGameServerUtils = g_pSteamClientGameServer->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION ); + if ( !m_pSteamGameServerUtils ) + return false; + + m_pSteamGameServerNetworking = g_pSteamClientGameServer->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION ); + if ( !m_pSteamGameServerNetworking ) + return false; + + m_pSteamGameServerStats = g_pSteamClientGameServer->GetISteamGameServerStats( hSteamUser, hSteamPipe, STEAMGAMESERVERSTATS_INTERFACE_VERSION ); + if ( !m_pSteamGameServerStats ) + return false; + + m_pSteamHTTP = g_pSteamClientGameServer->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION ); + if ( !m_pSteamHTTP ) + return false; + + return true; +} + +#endif // VERSION_SAFE_STEAM_API_INTERFACES +#endif #endif // STEAM_GAMESERVER_H diff --git a/src/public/steam/steamclientpublic.h b/src/public/steam/steamclientpublic.h index 05e76618ca1..da3a143fa7b 100644 --- a/src/public/steam/steamclientpublic.h +++ b/src/public/steam/steamclientpublic.h @@ -755,6 +755,10 @@ class CSteamID // simple accessors void SetAccountID( uint32 unAccountID ) { m_steamid.m_comp.m_unAccountID = unAccountID; } void SetAccountInstance( uint32 unInstance ){ m_steamid.m_comp.m_unAccountInstance = unInstance; } +#ifndef SDK_MP + void ClearIndividualInstance() { if ( BIndividualAccount() ) m_steamid.m_comp.m_unAccountInstance = 0; } + bool HasNoIndividualInstance() const { return BIndividualAccount() && (m_steamid.m_comp.m_unAccountInstance==0); } +#endif AccountID_t GetAccountID() const { return m_steamid.m_comp.m_unAccountID; } uint32 GetUnAccountInstance() const { return m_steamid.m_comp.m_unAccountInstance; } @@ -775,6 +779,9 @@ class CSteamID // and is preferred when the caller knows it's safe to be strict. // Returns whether the string parsed correctly. bool SetFromStringStrict( const char *pchSteamID, EUniverse eDefaultUniverse ); +#ifndef SDK_MP + bool SetFromSteam2String( const char *pchSteam2ID, EUniverse eUniverse ); +#endif inline bool operator==( const CSteamID &val ) const { return m_steamid.m_unAll64Bits == val.m_steamid.m_unAll64Bits; } inline bool operator!=( const CSteamID &val ) const { return !operator==( val ); } diff --git a/src/public/steam/steamnetworkingtypes.h b/src/public/steam/steamnetworkingtypes.h index 5d5a84a6199..823036058ba 100644 --- a/src/public/steam/steamnetworkingtypes.h +++ b/src/public/steam/steamnetworkingtypes.h @@ -4,6 +4,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define STEAMNETWORKINGTYPES +#endif + #ifndef STEAMNETWORKINGTYPES #define STEAMNETWORKINGTYPES #pragma once diff --git a/src/public/steam/steamrealm.h b/src/public/steam/steamrealm.h index 09728d46f82..c3dff5852a8 100644 --- a/src/public/steam/steamrealm.h +++ b/src/public/steam/steamrealm.h @@ -4,6 +4,11 @@ // //============================================================================= +#ifdef SDK_SP +// Not in SP SDK +#define STEAMREALM_H +#endif + #ifndef STEAMREALM_H #define STEAMREALM_H diff --git a/src/public/steam/steamtypes.h b/src/public/steam/steamtypes.h index 6d6324a4643..38cc97c7888 100644 --- a/src/public/steam/steamtypes.h +++ b/src/public/steam/steamtypes.h @@ -111,6 +111,7 @@ enum ESteamIPType #pragma pack( push, 1 ) +#ifdef SDK_MP struct SteamIPAddress_t { union { @@ -175,6 +176,9 @@ struct SteamIPAddress_t return ipOut; } }; +#else +typedef uint32 SteamIPAddress_t; +#endif #pragma pack( pop ) diff --git a/src/public/studio.cpp b/src/public/studio.cpp index 355cc70d056..775f5e7a147 100644 --- a/src/public/studio.cpp +++ b/src/public/studio.cpp @@ -530,7 +530,11 @@ void studiohdr_t::SetAttachmentBone( int iAttachment, int iBone ) // Purpose: //----------------------------------------------------------------------------- +#ifdef SDK_MP char *studiohdr_t::pszNodeName( int iNode ) +#else +const char *studiohdr_t::pszNodeName( int iNode ) +#endif { if (numincludemodels == 0) { @@ -1189,7 +1193,11 @@ void CStudioHdr::SetAttachmentBone( int iAttachment, int iBone ) // Purpose: //----------------------------------------------------------------------------- +#ifdef SDK_MP char *CStudioHdr::pszNodeName( int iNode ) +#else +const char *CStudioHdr::pszNodeName( int iNode ) +#endif { if (m_pVModel == NULL) { @@ -1589,6 +1597,16 @@ void CStudioHdr::RunFlexRules( const float *src, float *dest ) const mstudioflexcontroller_t *const pCloseLid = pFlexcontroller( static_cast< LocalFlexController_t >( (int)stack[ k - 1 ] ) ); const float flCloseLid = RemapValClamped( src[ pCloseLid->localToGlobal ], pCloseLid->min, pCloseLid->max, 0.0f, 1.0f ); +#ifndef SDK_MP + int nBlinkIndex = static_cast< int >( stack[ k - 2 ] ); + float flBlink = 0.0f; + if ( nBlinkIndex >= 0 ) + { + const mstudioflexcontroller_t *const pBlink = pFlexcontroller( static_cast< LocalFlexController_t >( (int)stack[ k - 2 ] ) ); + flBlink = RemapValClamped( src[ pBlink->localToGlobal ], pBlink->min, pBlink->max, 0.0f, 1.0f ); + } +#endif + int nEyeUpDownIndex = static_cast< int >( stack[ k - 3 ] ); float flEyeUpDown = 0.0f; if ( nEyeUpDownIndex >= 0 ) @@ -1621,6 +1639,16 @@ void CStudioHdr::RunFlexRules( const float *src, float *dest ) const mstudioflexcontroller_t *const pCloseLid = pFlexcontroller( static_cast< LocalFlexController_t >( (int)stack[ k - 1 ] ) ); const float flCloseLid = RemapValClamped( src[ pCloseLid->localToGlobal ], pCloseLid->min, pCloseLid->max, 0.0f, 1.0f ); +#ifndef SDK_MP + int nBlinkIndex = static_cast< int >( stack[ k - 2 ] ); + float flBlink = 0.0f; + if ( nBlinkIndex >= 0 ) + { + const mstudioflexcontroller_t *const pBlink = pFlexcontroller( static_cast< LocalFlexController_t >( (int)stack[ k - 2 ] ) ); + flBlink = RemapValClamped( src[ pBlink->localToGlobal ], pBlink->min, pBlink->max, 0.0f, 1.0f ); + } +#endif + int nEyeUpDownIndex = static_cast< int >( stack[ k - 3 ] ); float flEyeUpDown = 0.0f; if ( nEyeUpDownIndex >= 0 ) @@ -1678,7 +1706,9 @@ void CStudioHdr::RunFlexRules( const float *src, float *dest ) //----------------------------------------------------------------------------- #define iabs(i) (( (i) >= 0 ) ? (i) : -(i) ) +#ifdef SDK_MP CUtlSymbolTable g_ActivityModifiersTable; +#endif extern void SetActivityForSequence( CStudioHdr *pstudiohdr, int i ); void CStudioHdr::CActivityToSequenceMapping::Initialize( CStudioHdr * __restrict pstudiohdr ) @@ -1799,6 +1829,7 @@ void CStudioHdr::CActivityToSequenceMapping::Initialize( CStudioHdr * __restrict int tupleOffset = seqsPerAct[seqdesc.activity]; Assert( tupleOffset < element.count ); +#ifdef SDK_MP if ( seqdesc.numactivitymodifiers > 0 ) { // add entries for this model's activity modifiers @@ -1815,6 +1846,7 @@ void CStudioHdr::CActivityToSequenceMapping::Initialize( CStudioHdr * __restrict (tupleList + element.startingIdx + tupleOffset)->pActivityModifiers = NULL; (tupleList + element.startingIdx + tupleOffset)->iNumActivityModifiers = 0; } +#endif // You might be tempted to collapse this pointer math into a single pointer -- // don't! the tuple list is marked __restrict above. diff --git a/src/public/studio.h b/src/public/studio.h index 9480d15d95a..b8d1e17a5a5 100644 --- a/src/public/studio.h +++ b/src/public/studio.h @@ -26,7 +26,9 @@ #include "datamap.h" #include "generichash.h" #include "localflexcontroller.h" +#ifdef SDK_MP #include "utlsymbol.h" +#endif #define STUDIO_ENABLE_PERF_COUNTERS @@ -106,6 +108,7 @@ struct mstudiodata_t #define STUDIO_PROC_AIMATATTACH 4 #define STUDIO_PROC_JIGGLE 5 +#ifdef SDK_MP // If you want to embed a pointer into one of the structures that is serialized, use this class! It will ensure that the pointers consume the // right amount of space and work correctly across 32 and 64 bit. It also makes sure that there is no surprise about how large the structure // is when placed in the middle of another structure, and supports Intel's desired behavior on 64-bit that pointers are always 8-byte aligned. @@ -137,6 +140,7 @@ struct ALIGN4 serializedstudioptr_t } ALIGN4_POST; #pragma pack( pop ) +#endif struct mstudioaxisinterpbone_t @@ -788,6 +792,7 @@ struct mstudioautolayer_t float end; // end of all influence }; +#ifdef SDK_MP struct mstudioactivitymodifier_t { DECLARE_BYTESWAP_DATADESC(); @@ -795,6 +800,7 @@ struct mstudioactivitymodifier_t int sznameindex; inline char *pszName() { return (sznameindex) ? (char *)(((byte *)this) + sznameindex ) : NULL; } }; +#endif // sequence descriptions struct mstudioseqdesc_t @@ -892,11 +898,15 @@ struct mstudioseqdesc_t int cycleposeindex; // index of pose parameter to use as cycle index +#ifdef SDK_MP int activitymodifierindex; int numactivitymodifiers; inline mstudioactivitymodifier_t *pActivityModifier( int i ) const { Assert( i >= 0 && i < numactivitymodifiers); return activitymodifierindex != 0 ? (mstudioactivitymodifier_t *)(((byte *)this) + activitymodifierindex) + i : NULL; }; int unused[5]; // remove/add as appropriate (grow back to 8 ints on version change!) +#else + int unused[7]; // remove/add as appropriate (grow back to 8 ints on version change!) +#endif mstudioseqdesc_t() = default; private: @@ -2269,7 +2279,11 @@ struct studiohdr_t //public: int EntryNode( int iSequence ); int ExitNode( int iSequence ); +#ifdef SDK_MP char *pszNodeName( int iNode ); +#else + const char *pszNodeName( int iNode ); +#endif int GetTransition( int iFrom, int iTo ) const; int numflexdesc; @@ -2472,12 +2486,17 @@ class CStudioHdr inline const studiohdr_t *GetRenderHdr( void ) const { return m_pStudioHdr; }; const studiohdr_t *pSeqStudioHdr( int sequence ); const studiohdr_t *pAnimStudioHdr( int animation ); +#ifdef SDK_MP const virtualmodel_t * ResetVModel( const virtualmodel_t *pVModel ) const; +#endif private: mutable const studiohdr_t *m_pStudioHdr; mutable virtualmodel_t *m_pVModel; +#ifndef SDK_MP + const virtualmodel_t * ResetVModel( const virtualmodel_t *pVModel ) const; +#endif const studiohdr_t *GroupStudioHdr( int group ); mutable CUtlVector< const studiohdr_t * > m_pStudioHdrCache; @@ -2513,7 +2532,11 @@ class CStudioHdr int EntryNode( int iSequence ); int ExitNode( int iSequence ); +#ifdef SDK_MP char *pszNodeName( int iNode ); +#else + const char *pszNodeName( int iNode ); +#endif // FIXME: where should this one be? int GetTransition( int iFrom, int iTo ) const; @@ -2629,8 +2652,10 @@ class CStudioHdr { short seqnum; short weight; // the absolute value of the weight from the sequence header +#ifdef SDK_MP CUtlSymbol *pActivityModifiers; // list of activity modifier symbols int iNumActivityModifiers; +#endif }; // The type of the hash's stored data, a composite of both key and value @@ -2703,10 +2728,12 @@ class CStudioHdr { if ( m_pSequenceTuples != NULL ) { +#ifdef SDK_MP if ( m_pSequenceTuples->pActivityModifiers != NULL ) { delete[] m_pSequenceTuples->pActivityModifiers; } +#endif delete[] m_pSequenceTuples; } } @@ -2737,8 +2764,10 @@ class CStudioHdr /// A more efficient version of the old SelectWeightedSequence() function in animation.cpp. int SelectWeightedSequence( CStudioHdr *pstudiohdr, int activity, int curSequence ); +#ifdef SDK_MP // selects the sequence with the most matching modifiers int SelectWeightedSequenceFromModifiers( CStudioHdr *pstudiohdr, int activity, CUtlSymbol *pActivityModifiers, int iModifierCount ); +#endif // Actually a big array, into which the hash values index. SequenceTuple *m_pSequenceTuples; @@ -2761,8 +2790,13 @@ class CStudioHdr const void *m_expectedVModel; // double-check that the data I point to hasn't changed +#ifdef SDK_MP bool ValidateAgainst( const CStudioHdr * RESTRICT pstudiohdr ) RESTRICT; void SetValidationPair( const CStudioHdr *RESTRICT pstudiohdr ) RESTRICT; +#else + bool ValidateAgainst( const CStudioHdr * RESTRICT pstudiohdr ); + void SetValidationPair( const CStudioHdr *RESTRICT pstudiohdr ); +#endif friend class CStudioHdr; }; @@ -2784,6 +2818,7 @@ class CStudioHdr return m_ActivityToSequence.SelectWeightedSequence( this, activity, curSequence ); } +#ifdef SDK_MP inline int SelectWeightedSequenceFromModifiers( int activity, CUtlSymbol *pActivityModifiers, int iModifierCount ) { #if STUDIO_SEQUENCE_ACTIVITY_LAZY_INITIALIZE @@ -2796,6 +2831,7 @@ class CStudioHdr #endif return m_ActivityToSequence.SelectWeightedSequenceFromModifiers( this, activity, pActivityModifiers, iModifierCount ); } +#endif /// True iff there is at least one sequence for the given activity. inline bool HaveSequenceForActivity( int activity ) diff --git a/src/public/studio_virtualmodel.cpp b/src/public/studio_virtualmodel.cpp index df9ffecd637..bdf22067412 100644 --- a/src/public/studio_virtualmodel.cpp +++ b/src/public/studio_virtualmodel.cpp @@ -80,7 +80,11 @@ CModelLookupContext::~CModelLookupContext() void virtualmodel_t::AppendModels( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif // build a search table if necesary CModelLookupContext ctx(group, pStudioHdr); @@ -141,7 +145,11 @@ void virtualmodel_t::AppendModels( int group, const studiohdr_t *pStudioHdr ) void virtualmodel_t::AppendSequences( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_seq.Count(); int j, k; @@ -219,7 +227,11 @@ void virtualmodel_t::AppendSequences( int group, const studiohdr_t *pStudioHdr ) void virtualmodel_t::UpdateAutoplaySequences( const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int autoplayCount = pStudioHdr->CountAutoplaySequences(); m_autoplaySequences.SetCount( autoplayCount ); pStudioHdr->CopyAutoplaySequences( m_autoplaySequences.Base(), autoplayCount ); @@ -231,7 +243,11 @@ void virtualmodel_t::UpdateAutoplaySequences( const studiohdr_t *pStudioHdr ) void virtualmodel_t::AppendAnimations( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_anim.Count(); CUtlVector< virtualgeneric_t > anim; @@ -297,7 +313,11 @@ void virtualmodel_t::AppendAnimations( int group, const studiohdr_t *pStudioHdr void virtualmodel_t::AppendBonemap( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif MEM_ALLOC_CREDIT(); const studiohdr_t *pBaseStudioHdr = m_group[ 0 ].GetStudioHdr( ); @@ -364,7 +384,11 @@ void virtualmodel_t::AppendBonemap( int group, const studiohdr_t *pStudioHdr ) void virtualmodel_t::AppendAttachments( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_attachment.Count(); CUtlVector< virtualgeneric_t > attachment; @@ -437,7 +461,11 @@ void virtualmodel_t::AppendAttachments( int group, const studiohdr_t *pStudioHdr void virtualmodel_t::AppendPoseParameters( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_pose.Count(); CUtlVector< virtualgeneric_t > pose; @@ -493,7 +521,11 @@ void virtualmodel_t::AppendPoseParameters( int group, const studiohdr_t *pStudio void virtualmodel_t::AppendNodes( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_node.Count(); CUtlVector< virtualgeneric_t > node; @@ -539,7 +571,11 @@ void virtualmodel_t::AppendNodes( int group, const studiohdr_t *pStudioHdr ) void virtualmodel_t::AppendIKLocks( int group, const studiohdr_t *pStudioHdr ) { +#ifdef SDK_MP AUTO_LOCK( m_Lock ); +#else + AUTO_LOCK_( CThreadTerminalMutex, m_Lock ); +#endif int numCheck = m_iklock.Count(); CUtlVector< virtualgeneric_t > iklock; diff --git a/src/public/texture_group_names.h b/src/public/texture_group_names.h index 92b3127945f..4aeaa04acb8 100644 --- a/src/public/texture_group_names.h +++ b/src/public/texture_group_names.h @@ -23,7 +23,9 @@ #define TEXTURE_GROUP_PRECACHED "Precached" // TODO: assign texture groups to the precached materials #define TEXTURE_GROUP_CUBE_MAP "CubeMap textures" #define TEXTURE_GROUP_RENDER_TARGET "RenderTargets" +#ifdef SDK_MP #define TEXTURE_GROUP_RUNTIME_COMPOSITE "Runtime Composite" +#endif #define TEXTURE_GROUP_UNACCOUNTED "Unaccounted textures" // Textures that weren't assigned a texture group. //#define TEXTURE_GROUP_STATIC_VERTEX_BUFFER "Static Vertex" #define TEXTURE_GROUP_STATIC_INDEX_BUFFER "Static Indices" diff --git a/src/public/tier0/dbg.h b/src/public/tier0/dbg.h index 8bc1ed878b5..4b6b7d22093 100644 --- a/src/public/tier0/dbg.h +++ b/src/public/tier0/dbg.h @@ -204,7 +204,9 @@ DBG_INTERFACE void _SpewInfo( SpewType_t type, const tchar* pFile, int line ); DBG_INTERFACE SpewRetval_t _SpewMessage( PRINTF_FORMAT_STRING const tchar* pMsg, ... ) FMTFUNCTION( 1, 2 ); DBG_INTERFACE SpewRetval_t _DSpewMessage( const tchar *pGroupName, int level, PRINTF_FORMAT_STRING const tchar* pMsg, ... ) FMTFUNCTION( 3, 4 ); DBG_INTERFACE SpewRetval_t ColorSpewMessage( SpewType_t type, const Color *pColor, PRINTF_FORMAT_STRING const tchar* pMsg, ... ) FMTFUNCTION( 3, 4 ); +#ifdef SDK_MP DBG_INTERFACE SpewRetval_t ColorSpewMessage2( SpewType_t type, const Color &color, PRINTF_FORMAT_STRING const tchar* pMsg, ... ) FMTFUNCTION( 3, 4 ); +#endif DBG_INTERFACE void _ExitOnFatalAssert( const tchar* pFile, int line ); DBG_INTERFACE bool ShouldUseNewAssertDialog(); @@ -222,8 +224,19 @@ typedef void (*AssertFailedNotifyFunc_t)( const char *pchFile, int nLine, const DBG_INTERFACE void SetAssertFailedNotifyFunc( AssertFailedNotifyFunc_t func ); DBG_INTERFACE void CallAssertFailedNotifyFunc( const char *pchFile, int nLine, const char *pchMessage ); +#ifdef SDK_MP /* True if -hushasserts was passed on command line. */ DBG_INTERFACE bool HushAsserts(); +#else + +#ifdef _DEBUG +#include "icommandline.h" +#define HushAsserts() CommandLine()->FindParm("-hushasserts") +#else +#define HushAsserts() true +#endif + +#endif #if defined( USE_SDL ) DBG_INTERFACE void SetAssertDialogParent( struct SDL_Window *window ); @@ -432,7 +445,9 @@ DBG_INTERFACE void LogV( PRINTF_FORMAT_STRING const tchar *pMsg, va_list arglist DBG_INTERFACE void Error( PRINTF_FORMAT_STRING const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 ); #else DBG_INTERFACE void NORETURN Error( PRINTF_FORMAT_STRING const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 ); +#ifdef SDK_MP DBG_INTERFACE void NORETURN ErrorV( PRINTF_FORMAT_STRING const tchar *pMsg, va_list arglist ); +#endif #endif diff --git a/src/public/tier0/icommandline.h b/src/public/tier0/icommandline.h index 3dea4fa4180..b59bd57435d 100644 --- a/src/public/tier0/icommandline.h +++ b/src/public/tier0/icommandline.h @@ -41,6 +41,7 @@ abstract_class ICommandLine // copies the string passwed virtual void SetParm( int nIndex, char const *pNewParm ) =0; +#ifdef SDK_MP virtual const char *ParmValueByIndex( int nIndex, const char *pDefaultVal = 0 ) const = 0; // A bool return of whether param exists, useful for just checking if param that is just a flag is set @@ -51,6 +52,7 @@ abstract_class ICommandLine // Newer call with flag to control paramfile behavior virtual void CreateCmdLine1( const char *commandline, bool bParseParamFiles ) = 0; virtual void CreateCmdLine1( int argc, char **argv, bool bParseParamFiles ) = 0; +#endif }; //----------------------------------------------------------------------------- diff --git a/src/public/tier0/mem.h b/src/public/tier0/mem.h index c7973a6f7d0..9714cf34d7f 100644 --- a/src/public/tier0/mem.h +++ b/src/public/tier0/mem.h @@ -5,6 +5,11 @@ // $NoKeywords: $ //=============================================================================// +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "../../public_sp/tier0/mem.h" +#endif + #ifndef TIER0_MEM_H #define TIER0_MEM_H diff --git a/src/public/tier0/memalloc.h b/src/public/tier0/memalloc.h index 7b853b43de4..a5267e3cd50 100644 --- a/src/public/tier0/memalloc.h +++ b/src/public/tier0/memalloc.h @@ -7,6 +7,11 @@ // $NoKeywords: $ //=============================================================================// +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "../../public_sp/tier0/memalloc.h" +#endif + #ifndef TIER0_MEMALLOC_H #define TIER0_MEMALLOC_H diff --git a/src/public/tier0/memdbgoff.h b/src/public/tier0/memdbgoff.h index 1cd09dae686..f645e2d2721 100644 --- a/src/public/tier0/memdbgoff.h +++ b/src/public/tier0/memdbgoff.h @@ -7,6 +7,11 @@ // $NoKeywords: $ //=============================================================================// +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "../../public_sp/tier0/memdbgoff.h" +#endif + #ifdef MEM_OVERRIDE_ON #undef malloc diff --git a/src/public/tier0/memdbgon.h b/src/public/tier0/memdbgon.h index a93fb902556..19de1b67fd4 100644 --- a/src/public/tier0/memdbgon.h +++ b/src/public/tier0/memdbgon.h @@ -7,6 +7,11 @@ // $NoKeywords: $ //=============================================================================// +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "../../public_sp/tier0/memdbgon.h" +#else + // SPECIAL NOTE! This file must *not* use include guards; we need to be able // to include this potentially multiple times (since we can deactivate debugging // by including memdbgoff.h) @@ -312,3 +317,5 @@ inline void *valve_aligned_malloc_check_oom( size_t size, size_t alignment ) #undef _aligned_malloc #endif // NO_MALLOC_OVERRIDE + +#endif // SDK_SP diff --git a/src/public/tier0/minidump.h b/src/public/tier0/minidump.h index 2bd0547075c..cdfe8b15bc7 100644 --- a/src/public/tier0/minidump.h +++ b/src/public/tier0/minidump.h @@ -75,11 +75,13 @@ PLATFORM_INTERFACE bool WriteMiniDumpUsingExceptionInfo( tchar *ptchMinidumpFileNameBuffer = NULL ); +#ifdef SDK_MP // A slightly smart wrapper around WriteMiniDumpUsingExceptionInfo that tries to select the right minidump type on // context. PLATFORM_INTERFACE void AutoWriteMiniDumpUsingExceptionInfo( unsigned int uStructuredExceptionCode, _EXCEPTION_POINTERS * pExceptionInfo, const char *pszFilenameSuffix ); +#endif // Call this to enable a handler for unhandled exceptions. PLATFORM_INTERFACE void MinidumpSetUnhandledExceptionFunction( FnMiniDump pfn ); @@ -90,6 +92,7 @@ PLATFORM_INTERFACE void EnableCrashingOnCrashes(); #endif // defined(_WIN32) && !defined(_X360) +#ifdef SDK_MP // // Minidump User Stream Info Comments. // @@ -105,6 +108,7 @@ PLATFORM_INTERFACE void MinidumpUserStreamInfoAppend( const char *pFormat, ... ) // Returns NULL when you've reached the end of the comment string array // Empty strings ("\0") can be returned if comment hasn't been set PLATFORM_INTERFACE const char *MinidumpUserStreamInfoGet( int Index ); +#endif #endif // MINIDUMP_H diff --git a/src/public/tier0/platform.h b/src/public/tier0/platform.h index 318db212d24..a65a5c1dfe4 100644 --- a/src/public/tier0/platform.h +++ b/src/public/tier0/platform.h @@ -145,6 +145,14 @@ #define IsX360() true #define IsPS3() false #endif + #ifndef SDK_MP + // Adding IsPlatformOpenGL() to help fix a bunch of code that was using IsPosix() to infer if the DX->GL translation layer was being used. + #if defined( DX_TO_GL_ABSTRACTION ) + #define IsPlatformOpenGL() true + #else + #define IsPlatformOpenGL() false + #endif + #endif #elif defined(POSIX) #define IsPC() true #define IsWindows() false @@ -164,6 +172,9 @@ #endif #define IsPosix() true + #ifndef SDK_MP + #define IsPlatformOpenGL() true + #endif #else #error #endif @@ -1197,8 +1208,13 @@ PLATFORM_INTERFACE bool Plat_IsInBenchmarkMode(); PLATFORM_INTERFACE double Plat_FloatTime(); // Returns time in seconds since the module was loaded. PLATFORM_INTERFACE uint32 Plat_MSTime(); // Time in milliseconds. +#ifdef SDK_MP PLATFORM_INTERFACE uint64 Plat_USTime(); // Time in microseconds. +#else +PLATFORM_INTERFACE char * Plat_asctime( const struct tm *tm, char *buf ); +#endif PLATFORM_INTERFACE char * Plat_ctime( const time_t *timep, char *buf, size_t bufsize ); +#ifdef SDK_MP PLATFORM_INTERFACE void Plat_GetModuleFilename( char *pOut, int nMaxBytes ); PLATFORM_INTERFACE void Plat_ExitProcess( int nCode ); @@ -1224,6 +1240,7 @@ PLATFORM_INTERFACE void Plat_ExitProcessWithError( int nCode, bool bGenerateM //to be terminated typedef bool (*ExitProcessWithErrorCBFn)( int nCode ); PLATFORM_INTERFACE void Plat_SetExitProcessWithErrorCB( ExitProcessWithErrorCBFn pfnCB ); +#endif PLATFORM_INTERFACE struct tm * Plat_gmtime( const time_t *timep, struct tm *result ); PLATFORM_INTERFACE time_t Plat_timegm( struct tm *timeptr ); @@ -1328,6 +1345,7 @@ struct CPUInformation // extern "C" implied by PLATFORM_INTERFACE. PLATFORM_INTERFACE const CPUInformation* GetCPUInformation(); +#ifdef SDK_MP #define MEMORY_INFORMATION_VERSION 0 struct MemoryInformation @@ -1349,6 +1367,7 @@ struct MemoryInformation // Returns true if the passed in MemoryInformation structure was filled out, otherwise false. PLATFORM_INTERFACE bool GetMemoryInformation( MemoryInformation *pOutMemoryInfo ); +#endif PLATFORM_INTERFACE float GetCPUUsage(); @@ -1425,7 +1444,11 @@ PLATFORM_INTERFACE void* Plat_SimpleLog( const tchar* file, int line ); // Returns true if debugger attached, false otherwise //----------------------------------------------------------------------------- #if defined(_WIN32) || defined(LINUX) || defined(OSX) +#ifdef SDK_MP +PLATFORM_INTERFACE bool Plat_IsInDebugSession( bool bForceRecheck = false ); +#else PLATFORM_INTERFACE bool Plat_IsInDebugSession(); +#endif PLATFORM_INTERFACE void Plat_DebugString( const char * ); #else inline bool Plat_IsInDebugSession( bool bForceRecheck = false ) { return false; } @@ -1836,6 +1859,7 @@ class CDynamicFunction #endif +#ifdef SDK_MP // Watchdog timer support. Call Plat_BeginWatchdogTimer( nn ) to kick the timer off. if you don't call // Plat_EndWatchdogTimer within nn seconds, the program will kick off an exception. This is for making // sure that hung dedicated servers abort (and restart) instead of staying hung. Calling @@ -1897,6 +1921,7 @@ DECLARE_ALIGNED_BYTE_ARRAY(16); DECLARE_ALIGNED_BYTE_ARRAY(32); DECLARE_ALIGNED_BYTE_ARRAY(64); DECLARE_ALIGNED_BYTE_ARRAY(128); +#endif //----------------------------------------------------------------------------- diff --git a/src/public/tier0/valve_minmax_on.h b/src/public/tier0/valve_minmax_on.h index 738eabc162a..2835f503d8a 100644 --- a/src/public/tier0/valve_minmax_on.h +++ b/src/public/tier0/valve_minmax_on.h @@ -1,5 +1,5 @@ //========= Copyright Valve Corporation, All rights reserved. ============// -#if !defined(POSIX) +#if !defined(POSIX) && !defined(MINMAX_H) #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif diff --git a/src/public/tier1/convar.h b/src/public/tier1/convar.h index 12508acb44e..9bd35e88385 100644 --- a/src/public/tier1/convar.h +++ b/src/public/tier1/convar.h @@ -342,10 +342,12 @@ friend class ConVarRef; ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, FnChangeCallback_t callback ); +#ifdef SDK_MP ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, bool bCompMin, float fCompMin, bool bCompMax, float fCompMax, FnChangeCallback_t callback ); +#endif @@ -385,12 +387,14 @@ friend class ConVarRef; const char *GetDefault( void ) const; void SetDefault( const char *pszDefault ); +#ifdef SDK_MP // True if it has a min/max competitive setting bool GetCompMin( float& minVal ) const; bool GetCompMax( float& maxVal ) const; FORCEINLINE_CVAR bool IsCompetitiveRestricted() const; bool SetCompetitiveMode( bool bCompetitive ); +#endif private: // Called by CCvar when the value of a var is changing. @@ -402,6 +406,7 @@ friend class ConVarRef; virtual bool ClampValue( float& value ); virtual void ChangeStringValue( const char *tempVal, float flOldValue ); +#ifdef SDK_MP virtual void Create_Vtbl( const char *pName, const char *pDefaultValue, int flags = 0, const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); @@ -412,13 +417,22 @@ friend class ConVarRef; bool bCompMin = false, float fCompMin = 0.0, bool bCompMax = false, float fCompMax = 0.0, FnChangeCallback_t callback = 0 ); +#else + virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, + const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, + bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); +#endif // Used internally by OneTimeInit to initialize. virtual void Init(); int GetFlags() { return m_pParent->m_nFlags; } +#ifdef SDK_MP virtual void InternalSetFloatValue2( float fNewValue, bool bForce = false ); +#else + inline void InternalSetFloatValue2( float fNewValue, bool bForce = false ) { this->InternalSetFloatValue( fNewValue ); } +#endif inline void InternalSetFloatValue( float fNewValue, bool bForce ) { this->InternalSetFloatValue2( fNewValue, bForce ); @@ -451,6 +465,7 @@ friend class ConVarRef; // Call this function when ConVar changes FnChangeCallback_t m_fnChangeCallback; +#ifdef SDK_MP // Min/Max values for competitive. bool m_bHasCompMin; float m_fCompMinVal; @@ -458,6 +473,7 @@ friend class ConVarRef; float m_fCompMaxVal; bool m_bCompetitiveRestrictions; +#endif }; @@ -502,6 +518,7 @@ FORCEINLINE_CVAR const char *ConVar::GetString( void ) const return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: Return whether this convar is restricted for competitive play. // Output : bool @@ -516,6 +533,7 @@ FORCEINLINE_CVAR bool ConVar::IsCompetitiveRestricted() const return bHasCompSettings || !( bClientCanAdjust || bInternalUseOnly ); } +#endif //----------------------------------------------------------------------------- @@ -536,12 +554,16 @@ class ConVarRef // Get/Set value float GetFloat( void ) const; int GetInt( void ) const; +#ifndef SDK_MP Color GetColor( void ) const; +#endif bool GetBool() const { return !!GetInt(); } const char *GetString( void ) const; +#ifdef SDK_MP // True if it has a min/max setting bool GetMin( float& minVal ) const; bool GetMax( float& maxVal ) const; +#endif void SetValue( const char *pValue ); void SetValue( float flValue ); @@ -594,6 +616,7 @@ FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const return m_pConVarState->m_nValue; } +#ifndef SDK_MP //----------------------------------------------------------------------------- // Purpose: Return ConVar value as a color // Output : Color @@ -603,6 +626,7 @@ FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const unsigned char *pColorElement = ((unsigned char *)&m_pConVarState->m_nValue); return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] ); } +#endif //----------------------------------------------------------------------------- // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. @@ -613,6 +637,7 @@ FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const return m_pConVarState->m_pszString; } +#ifdef SDK_MP FORCEINLINE_CVAR bool ConVarRef::GetMin( float& minVal ) const { return m_pConVarState->GetMin( minVal ); @@ -622,6 +647,7 @@ FORCEINLINE_CVAR bool ConVarRef::GetMax( float& maxVal ) const { return m_pConVarState->GetMax( maxVal ); } +#endif FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) { @@ -648,6 +674,7 @@ FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const return m_pConVarState->m_pszDefaultValue; } +#ifdef SDK_MP class IVEngineClient; // Josh: // This class is here to solve the problem @@ -693,6 +720,9 @@ class UIConVarRef : public ConVarRef IVEngineClient *m_pEngine; }; +#else +typedef ConVarRef UIConVarRef; +#endif //----------------------------------------------------------------------------- // Called by the framework to register ConCommands with the ICVar @@ -768,7 +798,7 @@ class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, pu static void name( const CCommand &args ); \ static ConCommand name##_command( #name, name, description ); \ static void name( const CCommand &args ) - + #ifdef CLIENT_DLL #define CON_COMMAND_SHARED( name, description ) \ static void name( const CCommand &args ); \ diff --git a/src/public/tier1/datamanager.h b/src/public/tier1/datamanager.h index 856b825cf56..5ee3ec28963 100644 --- a/src/public/tier1/datamanager.h +++ b/src/public/tier1/datamanager.h @@ -133,6 +133,7 @@ class CDataManager : public CDataManagerBase typedef CDataManagerBase BaseClass; public: +#ifdef SDK_MP CDataManager( unsigned int size = (unsigned)-1 ) : BaseClass(size) {} @@ -141,6 +142,16 @@ class CDataManager : public CDataManagerBase // NOTE: This must be called in all implementations of CDataManager FreeAllLists(); } +#else + CDataManager( unsigned int size = (unsigned)-1 ) : BaseClass(size) {} + + + ~CDataManager() + { + // NOTE: This must be called in all implementations of CDataManager + FreeAllLists(); + } +#endif // Use GetData() to translate pointer to LOCK_TYPE LOCK_TYPE LockResource( memhandle_t hMem ) @@ -180,10 +191,17 @@ class CDataManager : public CDataManagerBase // Wrapper to match implementation of allocation with typed storage & alloc params. memhandle_t CreateResource( const CREATE_PARAMS &createParams, bool bCreateLocked = false ) { +#ifdef SDK_MP BaseClass::EnsureCapacity((unsigned int)STORAGE_TYPE::EstimatedSize(createParams)); unsigned short memoryIndex = BaseClass::CreateHandle( bCreateLocked ); STORAGE_TYPE *pStore = STORAGE_TYPE::CreateResource( createParams ); return BaseClass::StoreResourceInHandle( memoryIndex, pStore, (unsigned int) pStore->Size() ); +#else + BaseClass::EnsureCapacity(STORAGE_TYPE::EstimatedSize(createParams)); + unsigned short memoryIndex = BaseClass::CreateHandle( bCreateLocked ); + STORAGE_TYPE *pStore = STORAGE_TYPE::CreateResource( createParams ); + return BaseClass::StoreResourceInHandle( memoryIndex, pStore, pStore->Size() ); +#endif } // Iteration. Must lock first diff --git a/src/public/tier1/fmtstr.h b/src/public/tier1/fmtstr.h index bcac9a264c5..15e8e9f1b8b 100644 --- a/src/public/tier1/fmtstr.h +++ b/src/public/tier1/fmtstr.h @@ -109,6 +109,7 @@ class CFmtStrN return m_szBuf; } +#ifdef SDK_MP // Same as sprintf above, but for compatibility with Steam interface const char *Format( PRINTF_FORMAT_STRING const char *pszFormat, ... ) FMTFUNCTION( 2, 3 ) { @@ -116,7 +117,7 @@ class CFmtStrN FmtStrVSNPrintf( m_szBuf, SIZE_BUF, m_bQuietTruncation, &pszFormat, 0, pszFormat ); return m_szBuf; } - +#endif // Use this for va_list formatting const char *sprintf_argv(const char *pszFormat, va_list arg_ptr) diff --git a/src/public/tier1/iconvar.h b/src/public/tier1/iconvar.h index cdbbda8a6c9..05b6576af1b 100644 --- a/src/public/tier1/iconvar.h +++ b/src/public/tier1/iconvar.h @@ -75,11 +75,17 @@ class CCommand; #define FCVAR_SERVER_CANNOT_QUERY (1<<29)// If this is set, then the server is not allowed to query this cvar's value (via IServerPluginHelpers::StartQueryCvarValue). #define FCVAR_CLIENTCMD_CAN_EXECUTE (1<<30) // IVEngineClient::ClientCmd is allowed to execute this command. // Note: IVEngineClient::ClientCmd_Unrestricted can run any client command. +#ifdef SDK_MP #define FCVAR_EXEC_DESPITE_DEFAULT (1<<31) // -default causes a lot of commands to be ignored (but still be recorded as though they had run). // This causes them to be executed anyways. #define FCVAR_INTERNAL_USE (1<<15) // This var isn't archived, but is exposed to players--and its use is allowed in competitive play. #define FCVAR_ALLOWED_IN_COMPETITIVE (1<<18) // This convar can be changed in competitive (strict) settings mode even though it is not archived. Meant for one-offs like cl_showfps that are not user facing settings but are benign +#else +#define FCVAR_EXEC_DESPITE_DEFAULT (1<<31) // MP ONLY +#define FCVAR_INTERNAL_USE (1<<15) // MP ONLY +#define FCVAR_ALLOWED_IN_COMPETITIVE (1<<18) // MP ONLY +#endif // #define FCVAR_AVAILABLE (1<<19) // #define FCVAR_AVAILABLE (1<<26) // #define FCVAR_AVAILABLE (1<<27) diff --git a/src/public/tier1/strtools.h b/src/public/tier1/strtools.h index fc6136fa897..016547172e6 100644 --- a/src/public/tier1/strtools.h +++ b/src/public/tier1/strtools.h @@ -1378,4 +1378,10 @@ bool PATHSEPARATOR( char c ); // returns <0 if strings do not match even in a case-insensitive way int _V_stricmp_NegativeForUnequal ( const char *s1, const char *s2 ); +#if defined(SDK_SP) && defined(_WIN32) +// SP's dmxloader.lib uses this, but it does not appear to be defined anywhere (toolset difference?) +// For now, just redirects to sscanf_s +int _sscanf_s( const char *pBuffer, PRINTF_FORMAT_STRING const char *const pFormat, ... ) FMTFUNCTION( 3, 4 ); +#endif + #endif // TIER1_STRTOOLS_H diff --git a/src/public/tier1/utlbuffer.h b/src/public/tier1/utlbuffer.h index ea8725c5b38..f69ea7162b5 100644 --- a/src/public/tier1/utlbuffer.h +++ b/src/public/tier1/utlbuffer.h @@ -152,8 +152,10 @@ class CUtlBuffer // Takes ownership of the passed memory, including freeing it when this buffer is destroyed. void AssumeMemory( void *pMemory, int nSize, int nInitialPut, int nFlags = 0 ); +#ifdef SDK_MP void* Detach(); void* DetachMemory(); +#endif // copies data from another buffer void CopyBuffer( const CUtlBuffer &buffer ); @@ -196,6 +198,7 @@ class CUtlBuffer float GetFloat( ); double GetDouble( ); void * GetPtr(); +#ifdef SDK_MP template void GetString( char( &pString )[maxLenInChars] ) { GetStringInternal( pString, maxLenInChars ); @@ -209,6 +212,18 @@ class CUtlBuffer { GetStringInternal( pString, maxLenInChars ); } +#else + void GetString( char* pString, int nMaxChars = 0 ); + + template FORCEINLINE void GetString( char( &pString )[maxLenInChars] ) + { + GetString( pString, (int)maxLenInChars ); + } + void FORCEINLINE GetStringManualCharCount( char *pString, size_t maxLenInChars ) + { + GetString( pString, (int)maxLenInChars ); + } +#endif void Get( void* pMem, int size ); void GetLine( char* pLine, int nMaxChars = 0 ); @@ -405,7 +420,9 @@ class CUtlBuffer // Call this to peek arbitrarily long into memory. It doesn't fail unless // it can't read *anything* new bool CheckArbitraryPeekGet( int nOffset, int &nIncrement ); +#ifdef SDK_MP void GetStringInternal( char *pString, size_t maxLenInChars ); +#endif template void GetType( T& dest, const char *pszFmt ); template void GetTypeBin( T& dest ); @@ -1149,12 +1166,14 @@ inline void CUtlBuffer::CopyBuffer( const void *pubData, int cubData ) } } +#ifdef SDK_MP inline void *CUtlBuffer::Detach() { void *p = m_Memory.Detach(); Clear(); return p; } +#endif #endif // UTLBUFFER_H diff --git a/src/public/tier1/utlmemory.h b/src/public/tier1/utlmemory.h index ff64a796660..c8f99a92527 100644 --- a/src/public/tier1/utlmemory.h +++ b/src/public/tier1/utlmemory.h @@ -95,8 +95,10 @@ class CUtlMemory void SetExternalBuffer( const T* pMemory, int numElements ); // Takes ownership of the passed memory, including freeing it when this buffer is destroyed. void AssumeMemory( T *pMemory, int nSize ); +#ifdef SDK_MP T* Detach(); void* DetachMemory(); +#endif // Fast swap void Swap( CUtlMemory< T, I > &mem ); @@ -546,6 +548,7 @@ void CUtlMemory::AssumeMemory( T* pMemory, int numElements ) m_nAllocationCount = numElements; } +#ifdef SDK_MP template< class T, class I > void *CUtlMemory::DetachMemory() { @@ -563,6 +566,7 @@ inline T* CUtlMemory::Detach() { return (T*)DetachMemory(); } +#endif //----------------------------------------------------------------------------- // element access diff --git a/src/public/tier1/utlsoacontainer.h b/src/public/tier1/utlsoacontainer.h index 86b87309c42..2dfe0315850 100644 --- a/src/public/tier1/utlsoacontainer.h +++ b/src/public/tier1/utlsoacontainer.h @@ -109,6 +109,10 @@ template class CStridedConstPtr } }; +#ifdef SDK_MP +#define CFltx4StridedPtr CStridedPtr +#define CFltx4StridedConstPtr CStridedConstPtr +#else class CFltx4StridedPtr { private: @@ -197,6 +201,7 @@ class CFltx4StridedConstPtr m_pData += nNumElements*m_nStride; } }; +#endif // allowed field data types. if you change these values, you need to change the tables in the .cpp file enum EAttributeDataType diff --git a/src/public/tier1/utlstring.h b/src/public/tier1/utlstring.h index 3d41c066cee..bcd5209fefd 100644 --- a/src/public/tier1/utlstring.h +++ b/src/public/tier1/utlstring.h @@ -1,5 +1,10 @@ //====== Copyright Valve Corporation, All rights reserved. ======= +#ifdef SDK_SP +// SP counterpart too different to combine cleanly +#include "../../public_sp/tier1/utlstring.h" +#endif + #ifndef UTLSTRING_H #define UTLSTRING_H #ifdef _WIN32 diff --git a/src/public/tier1/utlvector.h b/src/public/tier1/utlvector.h index 7c6e3d76f47..ed6f0b3ee9b 100644 --- a/src/public/tier1/utlvector.h +++ b/src/public/tier1/utlvector.h @@ -26,6 +26,7 @@ #include "tier1/strtools.h" #include "vstdlib/random.h" +#ifdef SDK_MP #define FOR_EACH_VEC( vecName, iteratorName ) \ for ( int iteratorName = 0; (vecName).IsUtlVector && iteratorName < (vecName).Count(); iteratorName++ ) #define FOR_EACH_VEC_BACK( vecName, iteratorName ) \ @@ -37,6 +38,12 @@ struct base_vector_t public: enum { IsUtlVector = true }; // Used to match this at compiletime }; +#else +#define FOR_EACH_VEC( vecName, iteratorName ) \ + for ( int iteratorName = 0; iteratorName < (vecName).Count(); iteratorName++ ) +#define FOR_EACH_VEC_BACK( vecName, iteratorName ) \ + for ( int iteratorName = (vecName).Count()-1; iteratorName >= 0; iteratorName-- ) +#endif //----------------------------------------------------------------------------- // The CUtlVector class: @@ -47,7 +54,11 @@ struct base_vector_t // by index (they should *never* maintain pointers to elements in the vector). //----------------------------------------------------------------------------- template< class T, class A = CUtlMemory > +#ifdef SDK_MP class CUtlVector : public base_vector_t +#else +class CUtlVector +#endif { typedef A CAllocator; public: @@ -77,8 +88,10 @@ class CUtlVector : public base_vector_t const T& Head() const; T& Tail(); const T& Tail() const; +#ifdef SDK_MP T& Random(); const T& Random() const; +#endif // STL compatible member functions. These allow easier use of std::sort // and they are forward compatible with the C++ 11 range-based for loops. @@ -109,7 +122,9 @@ class CUtlVector : public base_vector_t // Adds an element, uses default constructor int AddToHead(); int AddToTail(); +#ifdef SDK_MP T *AddToTailGetPtr(); +#endif int InsertBefore( int elem ); int InsertAfter( int elem ); @@ -121,10 +136,15 @@ class CUtlVector : public base_vector_t // Adds multiple elements, uses default constructor int AddMultipleToHead( int num ); +#ifdef SDK_MP int AddMultipleToTail( int num ); int AddMultipleToTail( int num, const T *pToCopy ); int InsertMultipleBefore( int elem, int num ); int InsertMultipleBefore( int elem, int num, const T *pToCopy ); +#else + int AddMultipleToTail( int num, const T *pToCopy = NULL ); + int InsertMultipleBefore( int elem, int num, const T *pToCopy = NULL ); // If pToCopy is set, then it's an array of length 'num' and +#endif int InsertMultipleAfter( int elem, int num ); // Calls RemoveAll() then AddMultipleToTail. @@ -148,6 +168,7 @@ class CUtlVector : public base_vector_t // Finds an element (element needs operator== defined) int Find( const T& src ) const; +#ifdef SDK_MP // Helper to find using std::find_if with a predicate // e.g. [] -> bool ( T &a ) { return a.IsTheThingIWant(); } // @@ -156,6 +177,7 @@ class CUtlVector : public base_vector_t int FindPredicate( F&& predicate ) const; void FillWithValue( const T& src ); +#endif bool HasElement( const T& src ) const; @@ -193,22 +215,26 @@ class CUtlVector : public base_vector_t void Sort( int (__cdecl *pfnCompare)(const T *, const T *) ); +#ifdef SDK_MP void Shuffle( IUniformRandomStream* pSteam = NULL ); // Call this to quickly sort non-contiguously allocated vectors void InPlaceQuickSort( int (__cdecl *pfnCompare)(const T *, const T *) ); // reverse the order of elements void Reverse( ); +#endif #ifdef DBGFLAG_VALIDATE void Validate( CValidator &validator, char *pchName ); // Validate our internal structures #endif // DBGFLAG_VALIDATE +#ifdef SDK_MP /// sort using std:: and expecting a "<" function to be defined for the type void Sort( void ); /// sort using std:: with a predicate. e.g. [] -> bool ( T &a, T &b ) { return a < b; } template void SortPredicate( F &&predicate ); +#endif protected: // Can't copy this unless we explicitly do it! @@ -238,7 +264,9 @@ class CUtlVector : public base_vector_t #endif private: +#ifdef SDK_MP void InPlaceQuickSort_r( int (__cdecl *pfnCompare)(const T *, const T *), int nLeft, int nRight ); +#endif }; @@ -538,7 +566,9 @@ class CUtlVectorUltraConservative : private A return false; } +#ifdef SDK_MP bool DebugCompileError_ANonVectorIsUsedInThe_FOR_EACH_VEC_Macro( void ) const { return true; } +#endif struct Data_t { @@ -750,6 +780,7 @@ inline int CUtlVector::Size() const return m_Size; } +#ifdef SDK_MP template< typename T, class A > inline T& CUtlVector::Random() { @@ -780,6 +811,7 @@ void CUtlVector::Shuffle( IUniformRandomStream* pSteam ) } } } +#endif template< typename T, class A > inline int CUtlVector::Count() const @@ -788,6 +820,7 @@ inline int CUtlVector::Count() const } +#ifdef SDK_MP //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Reverse - reverse the order of elements, akin to std::vector<>::reverse() @@ -806,6 +839,7 @@ void CUtlVector::Reverse( ) #endif } } +#endif //----------------------------------------------------------------------------- @@ -881,6 +915,7 @@ void CUtlVector::Sort( int (__cdecl *pfnCompare)(const T *, const T *) ) } +#ifdef SDK_MP //---------------------------------------------------------------------------------------------- // Private function that does the in-place quicksort for non-contiguously allocated vectors. //---------------------------------------------------------------------------------------------- @@ -950,6 +985,7 @@ void CUtlVector::SortPredicate( F &&predicate ) { std::sort( Base(), Base() + Count(), predicate ); } +#endif //----------------------------------------------------------------------------- // Makes sure we have enough memory allocated to store a requested # of elements @@ -1019,11 +1055,13 @@ inline int CUtlVector::AddToTail() return InsertBefore( m_Size ); } +#ifdef SDK_MP template< typename T, class A > inline T *CUtlVector::AddToTailGetPtr() { return &Element( AddToTail() ); } +#endif template< typename T, class A > inline int CUtlVector::InsertAfter( int elem ) @@ -1096,11 +1134,13 @@ inline int CUtlVector::AddMultipleToHead( int num ) return InsertMultipleBefore( 0, num ); } +#ifdef SDK_MP template< typename T, class A > inline int CUtlVector::AddMultipleToTail( int num ) { return InsertMultipleBefore( m_Size, num ); } +#endif template< typename T, class A > inline int CUtlVector::AddMultipleToTail( int num, const T *pToCopy ) @@ -1183,6 +1223,7 @@ int CUtlVector::AddVectorToTail( CUtlVector const &src ) return base; } +#ifdef SDK_MP template< typename T, class A > inline int CUtlVector::InsertMultipleBefore( int elem, int num ) { @@ -1203,6 +1244,7 @@ inline int CUtlVector::InsertMultipleBefore( int elem, int num ) return elem; } +#endif template< typename T, class A > inline int CUtlVector::InsertMultipleBefore( int elem, int num, const T *pToInsert ) @@ -1216,6 +1258,7 @@ inline int CUtlVector::InsertMultipleBefore( int elem, int num, const T *p GrowVector(num); ShiftElementsRight( elem, num ); +#ifdef SDK_MP // Invoke default constructors if ( !pToInsert ) { @@ -1231,6 +1274,20 @@ inline int CUtlVector::InsertMultipleBefore( int elem, int num, const T *p CopyConstruct( &Element( elem+i ), pToInsert[i] ); } } +#else + // Invoke default constructors + for (int i = 0; i < num; ++i ) + Construct( &Element( elem+i ) ); + + // Copy stuff in? + if ( pToInsert ) + { + for ( int i=0; i < num; i++ ) + { + Element( elem+i ) = pToInsert[i]; + } + } +#endif return elem; } @@ -1250,6 +1307,7 @@ int CUtlVector::Find( const T& src ) const return -1; } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Finds an element using a predicate, using std::find_if //----------------------------------------------------------------------------- @@ -1279,6 +1337,7 @@ void CUtlVector::FillWithValue( const T& src ) Element(i) = src; } } +#endif template< typename T, class A > bool CUtlVector::HasElement( const T& src ) const @@ -1531,6 +1590,7 @@ inline void CSplitString::Set( const char *pString, const char **pSeparators, in Construct( pString, pSeparators, nSeparators ); } +#ifdef SDK_MP // A fixed growable vector that's castable to CUtlVector template< class T, size_t FIXED_SIZE > class CUtlVectorFixedGrowableCompat : public CUtlVector< T > @@ -1546,5 +1606,6 @@ class CUtlVectorFixedGrowableCompat : public CUtlVector< T > AlignedByteArray_t< FIXED_SIZE, T > m_FixedMemory; }; +#endif #endif // CCVECTOR_H diff --git a/src/public/tier3/mdlutils.h b/src/public/tier3/mdlutils.h index 6da78136a14..c2c7d450245 100644 --- a/src/public/tier3/mdlutils.h +++ b/src/public/tier3/mdlutils.h @@ -76,7 +76,9 @@ class CMDL bool m_bWorldSpaceViewTarget; void *m_pProxyData; +#ifdef SDK_MP CJiggleBones *m_pJiggleBones; +#endif }; diff --git a/src/public/toolframework/itoolentity.h b/src/public/toolframework/itoolentity.h index 38790ef2626..6e5959d2e02 100644 --- a/src/public/toolframework/itoolentity.h +++ b/src/public/toolframework/itoolentity.h @@ -32,9 +32,11 @@ class CBaseAnimating; class CTakeDamageInfo; class ITempEntsSystem; class IEntityFactoryDictionary; +#ifdef SDK_MP class CBaseTempEntity; class CGlobalEntityList; class IEntityFindFilter; +#endif //----------------------------------------------------------------------------- @@ -220,6 +222,7 @@ class IServerTools : public IBaseInterface virtual void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore ) = 0; virtual ITempEntsSystem *GetTempEntsSystem( void ) = 0; +#ifdef SDK_MP virtual CBaseTempEntity *GetTempEntList( void ) = 0; virtual CGlobalEntityList *GetEntityList( void ) = 0; @@ -240,15 +243,22 @@ class IServerTools : public IBaseInterface virtual CBaseEntity *FindEntityNearestFacing( const Vector &origin, const Vector &facing, float threshold ) = 0; virtual CBaseEntity *FindEntityClassNearestFacing( const Vector &origin, const Vector &facing, float threshold, char *classname ) = 0; virtual CBaseEntity *FindEntityProcedural( const char *szName, CBaseEntity *pSearchingEntity = NULL, CBaseEntity *pActivator = NULL, CBaseEntity *pCaller = NULL ) = 0; +#endif }; typedef IServerTools IServerTools001; typedef IServerTools IServerTools002; +#ifdef SDK_MP #define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001" #define VSERVERTOOLS_INTERFACE_VERSION_2 "VSERVERTOOLS002" #define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS003" #define VSERVERTOOLS_INTERFACE_VERSION_INT 3 +#else +#define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001" +#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS002" +#define VSERVERTOOLS_INTERFACE_VERSION_INT 2 +#endif //----------------------------------------------------------------------------- // Purpose: Client side tool interace (right now just handles IClientRenderables). diff --git a/src/public/vgui/Cursor.h b/src/public/vgui/Cursor.h index 2025915efe5..604e874bf07 100644 --- a/src/public/vgui/Cursor.h +++ b/src/public/vgui/Cursor.h @@ -40,8 +40,6 @@ enum CursorCode dc_alwaysvisible_pop, }; -typedef uint32 HCursor; - } #endif // CURSOR_H diff --git a/src/public/vgui/IImage.h b/src/public/vgui/IImage.h index 7a5bc27cecc..04eb17c740c 100644 --- a/src/public/vgui/IImage.h +++ b/src/public/vgui/IImage.h @@ -19,8 +19,6 @@ class Color; namespace vgui { -typedef uint32 HTexture; - enum iimage_rotation_t { ROTATED_UNROTATED = 0, diff --git a/src/public/vgui/IInput.h b/src/public/vgui/IInput.h index 78bda1b6de3..eee569fb067 100644 --- a/src/public/vgui/IInput.h +++ b/src/public/vgui/IInput.h @@ -21,7 +21,6 @@ namespace vgui { class Cursor; -typedef uint32 HCursor; #define VGUI_GCS_COMPREADSTR 0x0001 #define VGUI_GCS_COMPREADATTR 0x0002 diff --git a/src/public/vgui/IScheme.h b/src/public/vgui/IScheme.h index bccf0707c35..ac7e90fbefa 100644 --- a/src/public/vgui/IScheme.h +++ b/src/public/vgui/IScheme.h @@ -21,9 +21,6 @@ class KeyValues; namespace vgui { -typedef uint32 HScheme; -typedef uint32 HTexture; - class IBorder; class IImage; @@ -64,10 +61,14 @@ class IScheme : public IBaseInterface // Get color data virtual const KeyValues *GetColorData() const = 0; +#ifdef SDK_MP // returns a pointer to an existing border virtual IBorder* GetBorder2( const char* borderName ) = 0; virtual VPANEL GetSizingPanel() = 0; +#else + FORCEINLINE IBorder *GetBorder2( const char* borderName ) { return GetBorder( borderName ); } +#endif }; @@ -134,7 +135,9 @@ class ISchemeManager: public IBaseInterface // Returns true if image evicted, false otherwise virtual bool DeleteImage( const char *pImageName ) = 0; +#ifdef SDK_MP virtual void UpdateBorders() = 0; +#endif }; #define VGUI_SCHEME_INTERFACE_VERSION "VGUI_Scheme010" diff --git a/src/public/vgui/ISurface.h b/src/public/vgui/ISurface.h index 8cc67d95e4f..4d386983066 100644 --- a/src/public/vgui/ISurface.h +++ b/src/public/vgui/ISurface.h @@ -40,11 +40,6 @@ class IImage; class Image; class Point; -// handles -typedef uint32 HCursor; -typedef uint32 HTexture; -typedef uint32 HFont; - //SRC only defines diff --git a/src/public/vgui/IVGui.h b/src/public/vgui/IVGui.h index 7c47c36f8a8..47b10d0c484 100644 --- a/src/public/vgui/IVGui.h +++ b/src/public/vgui/IVGui.h @@ -24,8 +24,11 @@ namespace vgui { // safe handle to a panel - can be converted to and from a VPANEL -typedef uint32 HPanel; +#ifdef SDK_MP typedef uint32 HContext; +#else +typedef unsigned long HContext; +#endif enum : vgui::HContext { @@ -101,10 +104,12 @@ class IVGui : public IAppSystem // add a tick signal like above, but to the head of the list of tick signals virtual void AddTickSignalToHead( VPANEL panel, int intervalMilliseconds = 0 ) = 0; +#ifdef SDK_MP virtual IVEngineClient *GetVGUIEngine() = 0; virtual void InvalidateMdlCache() = 0; virtual uint32 GetMdlCacheSerial() = 0; +#endif }; #define VGUI_IVGUI_INTERFACE_VERSION "VGUI_ivgui008" diff --git a/src/public/vgui/MouseCode.h b/src/public/vgui/MouseCode.h index 9b13fc81423..7ba162147af 100644 --- a/src/public/vgui/MouseCode.h +++ b/src/public/vgui/MouseCode.h @@ -18,15 +18,6 @@ namespace vgui { typedef ButtonCode_t MouseCode; - -static inline int MouseButtonBit(MouseCode code) -{ - if (code < MOUSE_FIRST || code > MOUSE_LAST) { - Assert(false); - return 0; - } - return 1 << (code - MOUSE_FIRST); -} } #endif // MOUSECODE_H diff --git a/src/public/vgui/VGUI.h b/src/public/vgui/VGUI.h index d209e05350b..d626bd72aad 100644 --- a/src/public/vgui/VGUI.h +++ b/src/public/vgui/VGUI.h @@ -55,14 +55,23 @@ typedef uintp VPANEL; // handles to vgui objects // NULL values signify an invalid value +#ifdef SDK_MP typedef uint32 HScheme; // Both -1 and 0 are used for invalid textures. Be careful. typedef uint32 HTexture; typedef uint32 HCursor; typedef uint32 HPanel; -const HPanel INVALID_PANEL = 0xffffffff; typedef uint32 HFont; +#else +typedef unsigned long HScheme; +// Both -1 and 0 are used for invalid textures. Be careful. +typedef unsigned long HTexture; +typedef unsigned long HCursor; +typedef unsigned long HPanel; +typedef unsigned long HFont; +#endif const HFont INVALID_FONT = 0; // the value of an invalid font handle +const HPanel INVALID_PANEL = 0xffffffff; } #include "tier1/strtools.h" diff --git a/src/public/vgui_controls/EditablePanel.h b/src/public/vgui_controls/EditablePanel.h index e2ebc6248c4..1a30f4e6ee0 100644 --- a/src/public/vgui_controls/EditablePanel.h +++ b/src/public/vgui_controls/EditablePanel.h @@ -69,8 +69,15 @@ class EditablePanel : public Panel // as above, but copies the result into the specified buffer instead of a static buffer virtual void GetControlString(const char *controlName, char *buf, int bufSize, const char *defaultString = ""); // sets the enabled state of a control +#ifdef SDK_MP virtual void SetControlEnabled(const char *controlName, bool enabled, bool bRecurseDown = false ); virtual void SetControlVisible(const char *controlName, bool visible, bool bRecurseDown = false ); +#else + virtual void SetControlEnabled( const char *controlName, bool enabled ); + virtual void SetControlVisible( const char *controlName, bool visible ); + inline void SetControlEnabled( const char *controlName, bool enabled, bool bRecurseDown ) { SetControlEnabled( controlName, enabled ); } + inline void SetControlVisible( const char *controlName, bool visible, bool bRecurseDown ) { SetControlVisible( controlName, visible ); } +#endif // localization variables (used in constructing UI strings) // after the variable is set, causes all the necessary sub-panels to update diff --git a/src/public/vgui_controls/Panel.h b/src/public/vgui_controls/Panel.h index f01730273d4..b2cdafd8c1a 100644 --- a/src/public/vgui_controls/Panel.h +++ b/src/public/vgui_controls/Panel.h @@ -256,7 +256,11 @@ class Panel : public IClientPanel, virtual public IForceVirtualInheritancePanel virtual void SetSilentMode( bool bSilent ); //change the panel's silent mode; if silent, the panel will not post any action signals // install a mouse handler +#ifdef SDK_MP virtual void InstallMouseHandler( Panel *pHandler, bool bThisHandlesAsWell = false, bool bMovementEvents = false ); // mouse events will be send to handler panel instead and, by default, not this panel +#else + virtual void InstallMouseHandler( Panel *pHandler ); +#endif PHandle GetMouseHandlerPanel() const { return m_hMouseEventHandler; } // drawing state @@ -939,10 +943,17 @@ class Panel : public IClientPanel, virtual public IForceVirtualInheritancePanel // 1 == Textured (TextureId1 only) // 2 == Rounded Corner Box CPanelAnimationVar( int, m_nPaintBackgroundType, "PaintBackgroundType", "0" ); +#ifdef SDK_MP CPanelAnimationVarAliasType( int, m_nBgTextureId1, "Texture1", "vgui/hud/8x800corner1", "textureid" ); CPanelAnimationVarAliasType( int, m_nBgTextureId2, "Texture2", "vgui/hud/8x800corner2", "textureid" ); CPanelAnimationVarAliasType( int, m_nBgTextureId3, "Texture3", "vgui/hud/8x800corner3", "textureid" ); CPanelAnimationVarAliasType( int, m_nBgTextureId4, "Texture4", "vgui/hud/8x800corner4", "textureid" ); +#else + CPanelAnimationVarAliasType( int, m_nBgTextureId1, "Texture1", "vgui/hud/800corner1", "textureid" ); + CPanelAnimationVarAliasType( int, m_nBgTextureId2, "Texture2", "vgui/hud/800corner2", "textureid" ); + CPanelAnimationVarAliasType( int, m_nBgTextureId3, "Texture3", "vgui/hud/800corner3", "textureid" ); + CPanelAnimationVarAliasType( int, m_nBgTextureId4, "Texture4", "vgui/hud/800corner4", "textureid" ); +#endif //============================================================================= // HPE_BEGIN: @@ -1032,7 +1043,11 @@ class CSortedPanelYLess void VguiPanelGetSortedChildPanelList( Panel *pParentPanel, void *pSortedPanels ); +#ifdef SDK_MP +void VguiPanelGetSortedChildButtonList( Panel *pParentPanel, void *pSortedPanels, char *pchFilter = NULL, int nFilterType = 0 ); +#else void VguiPanelGetSortedChildButtonList( Panel *pParentPanel, void *pSortedPanels, const char *pchFilter = NULL, int nFilterType = 0 ); +#endif int VguiPanelNavigateSortedChildButtonList( void *pSortedPanels, int nDir ); int ComputeWide(Panel* pPanel, unsigned int& nBuildFlags, KeyValues *inResourceData, int nParentWide, int nParentTall, bool bComputingForTall); int ComputeTall(Panel* pPanel, unsigned int& nBuildFlags, KeyValues *inResourceData, int nParentWide, int nParentTall, bool bComputingForWide); diff --git a/src/public/vgui_controls/consoledialog.h b/src/public/vgui_controls/consoledialog.h index 7bbc8dd4bd1..46b3189a768 100644 --- a/src/public/vgui_controls/consoledialog.h +++ b/src/public/vgui_controls/consoledialog.h @@ -58,7 +58,11 @@ class CConsolePanel : public vgui::EditablePanel, public IConsoleDisplayFunc virtual void ColorPrint( const Color& clr, const char *pMessage ); virtual void Print( const char *pMessage ); virtual void DPrint( const char *pMessage ); +#ifdef SDK_MP virtual void GetConsoleText( char *pchText, int nBufSize ) const; +#else + virtual void GetConsoleText( char *pchText, size_t nBufSize ) const; +#endif // clears the console void Clear(); diff --git a/src/public/vgui_controls/cvartogglecheckbutton.h b/src/public/vgui_controls/cvartogglecheckbutton.h index 65c255a2798..71fde6134d8 100644 --- a/src/public/vgui_controls/cvartogglecheckbutton.h +++ b/src/public/vgui_controls/cvartogglecheckbutton.h @@ -54,7 +54,11 @@ class CvarToggleCheckButton : public CheckButton //----------------------------------------------------------------------------- template< class T > CvarToggleCheckButton::CvarToggleCheckButton( Panel *parent, const char *panelName, const char *text, char const *cvarname, bool ignoreMissingCvar ) +#ifdef SDK_MP : CheckButton( parent, panelName, text ), m_cvar( g_pVGui->GetVGUIEngine(), (cvarname)?cvarname:"", (cvarname)?ignoreMissingCvar:true ) +#else + : CheckButton( parent, panelName, text ), m_cvar( (cvarname)?cvarname:"", (cvarname)?ignoreMissingCvar:true ) +#endif { m_bIgnoreMissingCvar = ignoreMissingCvar; @@ -181,7 +185,11 @@ void CvarToggleCheckButton::ApplySettings( KeyValues *inResourceData ) else m_bStartValue = false; +#ifdef SDK_MP m_cvar.Init( g_pVGui->GetVGUIEngine(), cvarName, m_bIgnoreMissingCvar ); +#else + m_cvar.Init( cvarName, m_bIgnoreMissingCvar ); +#endif if ( m_cvar.IsValid() ) { SetSelected( m_cvar.GetBool() ); diff --git a/src/public/video/ivideoservices.h b/src/public/video/ivideoservices.h index 6ffe05a591a..c323129041f 100644 --- a/src/public/video/ivideoservices.h +++ b/src/public/video/ivideoservices.h @@ -102,7 +102,9 @@ namespace VideoSystem WMV, QUICKTIME, WEBM, +#ifdef SDK_MP SOURCE2_WRAPPER, +#endif VIDEO_SYSTEM_COUNT, VIDEO_SYSTEM_FIRST = 1, diff --git a/src/public/vstdlib/IKeyValuesSystem.h b/src/public/vstdlib/IKeyValuesSystem.h index a2e97687513..feb072e20ef 100644 --- a/src/public/vstdlib/IKeyValuesSystem.h +++ b/src/public/vstdlib/IKeyValuesSystem.h @@ -43,6 +43,7 @@ class IKeyValuesSystem virtual void AddKeyValuesToMemoryLeakList(void *pMem, HKeySymbol name) = 0; virtual void RemoveKeyValuesFromMemoryLeakList(void *pMem) = 0; +#ifdef SDK_MP // maintain a cache of KeyValues we load from disk. This saves us quite a lot of time on app startup. virtual void AddFileKeyValuesToCache( const KeyValues* _kv, const char *resourceName, const char *pathID ) = 0; virtual bool LoadFileKeyValuesFromCache( KeyValues* _outKv, const char *resourceName, const char *pathID, IBaseFileSystem *filesystem ) const = 0; @@ -56,6 +57,7 @@ class IKeyValuesSystem // symbol table access from code with case-preserving requirements (used for key names) virtual HKeySymbol GetSymbolForStringCaseSensitive( HKeySymbol &hCaseInsensitiveSymbol, const char *name, bool bCreate = true ) = 0; +#endif }; VSTDLIB_INTERFACE IKeyValuesSystem *KeyValuesSystem(); diff --git a/src/public/vtf/vtf.h b/src/public/vtf/vtf.h index 87e571e31ad..c5b466dfd54 100644 --- a/src/public/vtf/vtf.h +++ b/src/public/vtf/vtf.h @@ -56,11 +56,17 @@ enum CompiledVtfFlags TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000, TEXTUREFLAGS_SINGLECOPY = 0x00040000, +#ifdef SDK_MP TEXTUREFLAGS_STAGING_MEMORY = 0x00080000, TEXTUREFLAGS_IMMEDIATE_CLEANUP = 0x00100000, TEXTUREFLAGS_IGNORE_PICMIP = 0x00200000, +#else + TEXTUREFLAGS_UNUSED_00080000 = 0x00080000, + TEXTUREFLAGS_UNUSED_00100000 = 0x00100000, + TEXTUREFLAGS_UNUSED_00200000 = 0x00200000, +#endif - TEXTUREFLAGS_UNUSED_00400000 = 0x00400000, + TEXTUREFLAGS_UNUSED_00400000 = 0x00400000, TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000, @@ -77,9 +83,14 @@ enum CompiledVtfFlags // Clamp to border color on all texture coordinates TEXTUREFLAGS_BORDER = 0x20000000, +#ifdef SDK_MP TEXTUREFLAGS_STREAMABLE_COARSE = 0x40000000, TEXTUREFLAGS_STREAMABLE_FINE = 0x80000000, TEXTUREFLAGS_STREAMABLE = ( TEXTUREFLAGS_STREAMABLE_COARSE | TEXTUREFLAGS_STREAMABLE_FINE ) +#else + TEXTUREFLAGS_UNUSED_40000000 = 0x40000000, + TEXTUREFLAGS_UNUSED_80000000 = 0x80000000, +#endif }; @@ -354,12 +365,14 @@ class IVTFTexture // Sets post-processing flags (settings are copied, pointer passed to distinguish between structure versions) virtual void SetPostProcessingSettings( VtfProcessingOptions const *pOptions ) = 0; +#ifdef SDK_MP // Like Unserialize, but allows you to additionally specify some flags to forcibly enable. virtual bool UnserializeEx( CUtlBuffer &buf, bool bHeaderOnly = false, int nForceFlags = 0, int nSkipMipLevels = 0 ) = 0; // Data is included in [ finest, coarsest ] mips--other ranges have garbage. This is particularly useful for // streaming textures. virtual void GetMipmapRange( int* pOutFinest, int* pOutCoarsest ) = 0; +#endif }; //----------------------------------------------------------------------------- diff --git a/src/public/zip_utils.cpp b/src/public/zip_utils.cpp index 6efacb10c11..ff72a28398c 100644 --- a/src/public/zip_utils.cpp +++ b/src/public/zip_utils.cpp @@ -23,12 +23,14 @@ #include "byteswap.h" #include "utlstring.h" +#ifdef SDK_MP #include "tier1/lzmaDecoder.h" // Not every user of zip utils wants to link LZMA encoder #ifdef ZIP_SUPPORT_LZMA_ENCODE #include "lzma/lzma.h" #endif +#endif #include "tier0/memdbgon.h" @@ -1172,6 +1174,7 @@ bool CZipFile::ReadFileFromZip( HANDLE hZipFile, const char *pRelativeName, bool pData = readBuffer.Base(); } +#ifdef SDK_MP CUtlBuffer decompressTransform; if ( pEntry->m_eCompressionType != IZip::eCompressionType_None ) { @@ -1203,6 +1206,7 @@ bool CZipFile::ReadFileFromZip( HANDLE hZipFile, const char *pRelativeName, bool return false; } } +#endif if ( bTextMode ) { @@ -1691,7 +1695,11 @@ class CZip : public IZip virtual void Reset() OVERRIDE; // Add a single file to a zip - maintains the zip's previous alignment state +#ifdef SDK_MP virtual void AddFileToZip( const char *relativename, const char *fullpath, eCompressionType compressionType ) OVERRIDE; +#else + virtual void AddFileToZip( const char *relativename, const char *fullpath ) OVERRIDE; +#endif // Whether a file is contained in a zip - maintains alignment virtual bool FileExistsInZip( const char *pRelativeName ) OVERRIDE; @@ -1713,8 +1721,12 @@ class CZip : public IZip virtual unsigned int EstimateSize( void ) OVERRIDE; // Add buffer to zip as a file with given name - uses current alignment size, default 0 (no alignment) +#ifdef SDK_MP virtual void AddBufferToZip( const char *relativename, void *data, int length, bool bTextMode, eCompressionType compressionType ) OVERRIDE; +#else + virtual void AddBufferToZip( const char *relativename, void *data, int length, bool bTextMode ) OVERRIDE; +#endif // Writes out zip file to a buffer - uses current alignment size // (set by file's previous alignment, or a call to ForceAlignment) @@ -1780,10 +1792,17 @@ void CZip::ActivateByteSwapping( bool bActivate ) m_ZipFile.ActivateByteSwapping( bActivate ); } +#ifdef SDK_MP void CZip::AddFileToZip( const char *relativename, const char *fullpath, eCompressionType compressionType ) { m_ZipFile.AddFileToZip( relativename, fullpath, compressionType ); } +#else +void CZip::AddFileToZip( const char *relativename, const char *fullpath ) +{ + m_ZipFile.AddFileToZip( relativename, fullpath, eCompressionType_None ); +} +#endif bool CZip::FileExistsInZip( const char *pRelativeName ) { @@ -1826,10 +1845,17 @@ unsigned int CZip::EstimateSize( void ) } // Add buffer to zip as a file with given name +#ifdef SDK_MP void CZip::AddBufferToZip( const char *relativename, void *data, int length, bool bTextMode, eCompressionType compressionType ) { m_ZipFile.AddBufferToZip( relativename, data, length, bTextMode, compressionType ); } +#else +void CZip::AddBufferToZip( const char *relativename, void *data, int length, bool bTextMode ) +{ + m_ZipFile.AddBufferToZip( relativename, data, length, bTextMode, eCompressionType_None ); +} +#endif void CZip::SaveToBuffer( CUtlBuffer& outbuf ) { diff --git a/src/public/zip_utils.h b/src/public/zip_utils.h index 2ac200528a4..da78aaac34d 100644 --- a/src/public/zip_utils.h +++ b/src/public/zip_utils.h @@ -28,7 +28,12 @@ abstract_class IZip virtual void Reset() = 0; // Add a single file to a zip - maintains the zip's previous alignment state. +#ifdef SDK_MP virtual void AddFileToZip ( const char *relativename, const char *fullpath, eCompressionType compressionType = eCompressionType_None ) = 0; +#else + virtual void AddFileToZip ( const char *relativename, const char *fullpath ) = 0; + FORCEINLINE void AddFileToZip( const char *relativename, const char *fullpath, eCompressionType compressionType ) { AddFileToZip( relativename, fullpath ); } +#endif // Whether a file is contained in a zip - maintains alignment virtual bool FileExistsInZip ( const char *pRelativeName ) = 0; @@ -50,7 +55,12 @@ abstract_class IZip virtual unsigned int EstimateSize ( void ) = 0; // Add buffer to zip as a file with given name - uses current alignment size, default 0 (no alignment) +#ifdef SDK_MP virtual void AddBufferToZip ( const char *relativename, void *data, int length, bool bTextMode, eCompressionType compressionType = eCompressionType_None ) = 0; +#else + virtual void AddBufferToZip ( const char *relativename, void *data, int length, bool bTextMode ) = 0; + FORCEINLINE void AddBufferToZip ( const char *relativename, void *data, int length, bool bTextMode, eCompressionType compressionType ) { AddBufferToZip( relativename, data, length, bTextMode ); } +#endif // Writes out zip file to a buffer - uses current alignment size // (set by file's previous alignment, or a call to ForceAlignment) diff --git a/src/public_sp/tier0/mem.h b/src/public_sp/tier0/mem.h new file mode 100644 index 00000000000..fc8807acd6d --- /dev/null +++ b/src/public_sp/tier0/mem.h @@ -0,0 +1,50 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Memory allocation! +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef TIER0_MEM_H +#define TIER0_MEM_H + +#ifdef _WIN32 +#pragma once +#endif + +#include +#ifdef LINUX +#undef offsetof +#define offsetof(s,m) (size_t)&(((s *)0)->m) +#endif + +#include "tier0/platform.h" + +#if !defined(STATIC_TIER0) && !defined(_STATIC_LINKED) + +#ifdef TIER0_DLL_EXPORT +# define MEM_INTERFACE DLL_EXPORT +#else +# define MEM_INTERFACE DLL_IMPORT +#endif + +#else // BUILD_AS_DLL + +#define MEM_INTERFACE extern + +#endif // BUILD_AS_DLL + + + +//----------------------------------------------------------------------------- +// DLL-exported methods for particular kinds of memory +//----------------------------------------------------------------------------- +MEM_INTERFACE void *MemAllocScratch( int nMemSize ); +MEM_INTERFACE void MemFreeScratch(); + +#ifdef _LINUX +MEM_INTERFACE void ZeroMemory( void *mem, size_t length ); +#endif + + +#endif /* TIER0_MEM_H */ diff --git a/src/public_sp/tier0/memalloc.h b/src/public_sp/tier0/memalloc.h new file mode 100644 index 00000000000..34e1ccb91e4 --- /dev/null +++ b/src/public_sp/tier0/memalloc.h @@ -0,0 +1,659 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This header should never be used directly from leaf code!!! +// Instead, just add the file memoverride.cpp into your project and all this +// will automagically be used +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef TIER0_MEMALLOC_H +#define TIER0_MEMALLOC_H + +#ifdef _WIN32 +#pragma once +#endif + +// These memory debugging switches aren't relevant under Linux builds since memoverride.cpp +// isn't built into Linux projects +#ifndef POSIX +// Define this in release to get memory tracking even in release builds +//#define USE_MEM_DEBUG 1 +#endif + +#if defined( _MEMTEST ) +#ifdef _WIN32 +#define USE_MEM_DEBUG 1 +#endif +#endif + +// Undefine this if using a compiler lacking threadsafe RTTI (like vc6) +#define MEM_DEBUG_CLASSNAME 1 + +#include +#if defined( OSX ) +#include +#endif + +#include "tier0/mem.h" + +#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) + +struct _CrtMemState; + +#define MEMALLOC_VERSION 1 + +typedef size_t (*MemAllocFailHandler_t)( size_t ); + +//----------------------------------------------------------------------------- +// NOTE! This should never be called directly from leaf code +// Just use new,delete,malloc,free etc. They will call into this eventually +//----------------------------------------------------------------------------- +abstract_class IMemAlloc +{ +public: + // Release versions + virtual void *Alloc( size_t nSize ) = 0; + virtual void *Realloc( void *pMem, size_t nSize ) = 0; + virtual void Free( void *pMem ) = 0; + virtual void *Expand_NoLongerSupported( void *pMem, size_t nSize ) = 0; + + // Debug versions + virtual void *Alloc( size_t nSize, const char *pFileName, int nLine ) = 0; + virtual void *Realloc( void *pMem, size_t nSize, const char *pFileName, int nLine ) = 0; + virtual void Free( void *pMem, const char *pFileName, int nLine ) = 0; + virtual void *Expand_NoLongerSupported( void *pMem, size_t nSize, const char *pFileName, int nLine ) = 0; + + // Returns size of a particular allocation + virtual size_t GetSize( void *pMem ) = 0; + + // Force file + line information for an allocation + virtual void PushAllocDbgInfo( const char *pFileName, int nLine ) = 0; + virtual void PopAllocDbgInfo() = 0; + + // FIXME: Remove when we have our own allocator + // these methods of the Crt debug code is used in our codebase currently + virtual long CrtSetBreakAlloc( long lNewBreakAlloc ) = 0; + virtual int CrtSetReportMode( int nReportType, int nReportMode ) = 0; + virtual int CrtIsValidHeapPointer( const void *pMem ) = 0; + virtual int CrtIsValidPointer( const void *pMem, unsigned int size, int access ) = 0; + virtual int CrtCheckMemory( void ) = 0; + virtual int CrtSetDbgFlag( int nNewFlag ) = 0; + virtual void CrtMemCheckpoint( _CrtMemState *pState ) = 0; + + // FIXME: Make a better stats interface + virtual void DumpStats() = 0; + virtual void DumpStatsFileBase( char const *pchFileBase ) = 0; + + // FIXME: Remove when we have our own allocator + virtual void* CrtSetReportFile( int nRptType, void* hFile ) = 0; + virtual void* CrtSetReportHook( void* pfnNewHook ) = 0; + virtual int CrtDbgReport( int nRptType, const char * szFile, + int nLine, const char * szModule, const char * pMsg ) = 0; + + virtual int heapchk() = 0; + + virtual bool IsDebugHeap() = 0; + + virtual void GetActualDbgInfo( const char *&pFileName, int &nLine ) = 0; + virtual void RegisterAllocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) = 0; + virtual void RegisterDeallocation( const char *pFileName, int nLine, int nLogicalSize, int nActualSize, unsigned nTime ) = 0; + + virtual int GetVersion() = 0; + + virtual void CompactHeap() = 0; + + // Function called when malloc fails or memory limits hit to attempt to free up memory (can come in any thread) + virtual MemAllocFailHandler_t SetAllocFailHandler( MemAllocFailHandler_t pfnMemAllocFailHandler ) = 0; + + virtual void DumpBlockStats( void * ) = 0; + +#if defined( _MEMTEST ) + virtual void SetStatsExtraInfo( const char *pMapName, const char *pComment ) = 0; +#endif + + // Returns 0 if no failure, otherwise the size_t of the last requested chunk + // "I'm sure this is completely thread safe!" Brian Deen 7/19/2012. + virtual size_t MemoryAllocFailed() = 0; + + // handles storing allocation info for coroutines + virtual uint32 GetDebugInfoSize() = 0; + virtual void SaveDebugInfo( void *pvDebugInfo ) = 0; + virtual void RestoreDebugInfo( const void *pvDebugInfo ) = 0; + virtual void InitDebugInfo( void *pvDebugInfo, const char *pchRootFileName, int nLine ) = 0; + + // Replacement for ::GlobalMemoryStatus which accounts for unused memory in our system + virtual void GlobalMemoryStatus( size_t *pUsedMemory, size_t *pFreeMemory ) = 0; +}; + +//----------------------------------------------------------------------------- +// Singleton interface +//----------------------------------------------------------------------------- +MEM_INTERFACE IMemAlloc *g_pMemAlloc; + +//----------------------------------------------------------------------------- + +#ifdef MEMALLOC_REGIONS +#ifndef MEMALLOC_REGION +#define MEMALLOC_REGION 0 +#endif +inline void *MemAlloc_Alloc( size_t nSize ) +{ + return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize ); +} + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize, pFileName, nLine ); +} +#else +#undef MEMALLOC_REGION +inline void *MemAlloc_Alloc( size_t nSize ) +{ + return g_pMemAlloc->Alloc( nSize ); +} + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Alloc( nSize, pFileName, nLine ); +} +#endif +inline void MemAlloc_Free( void *ptr ) +{ + g_pMemAlloc->Free( ptr ); +} +inline void MemAlloc_Free( void *ptr, const char *pFileName, int nLine ) +{ + g_pMemAlloc->Free( ptr, pFileName, nLine ); +} + +//----------------------------------------------------------------------------- + +inline bool ValueIsPowerOfTwo( size_t value ) // don't clash with mathlib definition +{ + return (value & ( value - 1 )) == 0; +} + +inline void *MemAlloc_AllocAligned( size_t size, size_t align ) +{ + unsigned char *pAlloc, *pResult; + + if (!IsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)g_pMemAlloc->Alloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + +inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile, int nLine ) +{ + unsigned char *pAlloc, *pResult; + + if (!IsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)g_pMemAlloc->Alloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + +inline void *MemAlloc_AllocAlignedUnattributed( size_t size, size_t align ) +{ + unsigned char *pAlloc, *pResult; + + if (!ValueIsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + +inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile, int nLine ) +{ + unsigned char *pAlloc, *pResult; + + if (!ValueIsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + +inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align ) +{ + if ( !IsPowerOfTwo( align ) ) + return NULL; + + // Don't change alignment between allocation + reallocation. + if ( ( (size_t)ptr & ( align - 1 ) ) != 0 ) + return NULL; + + if ( !ptr ) + return MemAlloc_AllocAligned( size, align ); + + void *pAlloc, *pResult; + + // Figure out the actual allocation point + pAlloc = ptr; + pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *)); + pAlloc = *( (void **)pAlloc ); + + // See if we have enough space + size_t nOffset = (size_t)ptr - (size_t)pAlloc; + size_t nOldSize = g_pMemAlloc->GetSize( pAlloc ); + if ( nOldSize >= size + nOffset ) + return ptr; + + pResult = MemAlloc_AllocAligned( size, align ); + memcpy( pResult, ptr, nOldSize - nOffset ); + g_pMemAlloc->Free( pAlloc ); + return pResult; +} + +inline void MemAlloc_FreeAligned( void *pMemBlock ) +{ + void *pAlloc; + + if ( pMemBlock == NULL ) + return; + + pAlloc = pMemBlock; + + // pAlloc points to the pointer to starting of the memory block + pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *)); + + // pAlloc is the pointer to the start of memory block + pAlloc = *( (void **)pAlloc ); + g_pMemAlloc->Free( pAlloc ); +} + +inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pFileName, int nLine ) +{ + void *pAlloc; + + if ( pMemBlock == NULL ) + return; + + pAlloc = pMemBlock; + + // pAlloc points to the pointer to starting of the memory block + pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *)); + + // pAlloc is the pointer to the start of memory block + pAlloc = *( (void **)pAlloc ); + g_pMemAlloc->Free( pAlloc, pFileName, nLine ); +} + +inline size_t MemAlloc_GetSizeAligned( void *pMemBlock ) +{ + void *pAlloc; + + if ( pMemBlock == NULL ) + return 0; + + pAlloc = pMemBlock; + + // pAlloc points to the pointer to starting of the memory block + pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *)); + + // pAlloc is the pointer to the start of memory block + pAlloc = *((void **)pAlloc ); + return g_pMemAlloc->GetSize( pAlloc ) - ( (byte *)pMemBlock - (byte *)pAlloc ); +} + +//----------------------------------------------------------------------------- + +#if (defined(_DEBUG) || defined(USE_MEM_DEBUG)) +#define MEM_ALLOC_CREDIT_(tag) CMemAllocAttributeAlloction memAllocAttributeAlloction( tag, __LINE__ ) +#define MemAlloc_PushAllocDbgInfo( pszFile, line ) g_pMemAlloc->PushAllocDbgInfo( pszFile, line ) +#define MemAlloc_PopAllocDbgInfo() g_pMemAlloc->PopAllocDbgInfo() +#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) g_pMemAlloc->RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) +#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) g_pMemAlloc->RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) +#else +#define MEM_ALLOC_CREDIT_(tag) ((void)0) +#define MemAlloc_PushAllocDbgInfo( pszFile, line ) ((void)0) +#define MemAlloc_PopAllocDbgInfo() ((void)0) +#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#endif + +#define MemAlloc_DumpStats() g_pMemAlloc->DumpStats() +#define MemAlloc_CompactHeap() g_pMemAlloc->CompactHeap() +#define MemAlloc_OutOfMemory() g_pMemAlloc->OutOfMemory() +#define MemAlloc_CompactIncremental() g_pMemAlloc->CompactIncremental() +#define MemAlloc_DumpStatsFileBase( _filename ) g_pMemAlloc->DumpStatsFileBase( _filename ) +#define MemAlloc_CrtCheckMemory() g_pMemAlloc->CrtCheckMemory() +#define MemAlloc_GlobalMemoryStatus( _usedMemory, _freeMemory ) g_pMemAlloc->GlobalMemoryStatus( _usedMemory, _freeMemory ) +#define MemAlloc_MemoryAllocFailed() g_pMemAlloc->MemoryAllocFailed() + +#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize() +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo ) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo ) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) +#define MemAlloc_GetSize( x ) g_pMemAlloc->GetSize( x ); +//----------------------------------------------------------------------------- + +class CMemAllocAttributeAlloction +{ +public: + CMemAllocAttributeAlloction( const char *pszFile, int line ) + { + MemAlloc_PushAllocDbgInfo( pszFile, line ); + } + + ~CMemAllocAttributeAlloction() + { + MemAlloc_PopAllocDbgInfo(); + } +}; + +#define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__) + +//----------------------------------------------------------------------------- + +#if defined(_WIN32) && ( defined(_DEBUG) || defined(USE_MEM_DEBUG) ) + + #pragma warning(disable:4290) + #pragma warning(push) + +#if _MSC_VER < 1900 + #include +#else + #include +#endif + + // MEM_DEBUG_CLASSNAME is opt-in. + // Note: typeid().name() is not threadsafe, so if the project needs to access it in multiple threads + // simultaneously, it'll need a mutex. + #if defined(_CPPRTTI) && defined(MEM_DEBUG_CLASSNAME) + #define MEM_ALLOC_CREDIT_CLASS() MEM_ALLOC_CREDIT_( typeid(*this).name() ) + #define MEM_ALLOC_CLASSNAME(type) (typeid((type*)(0)).name()) + #else + #define MEM_ALLOC_CREDIT_CLASS() MEM_ALLOC_CREDIT_( __FILE__ ) + #define MEM_ALLOC_CLASSNAME(type) (__FILE__) + #endif + + // MEM_ALLOC_CREDIT_FUNCTION is used when no this pointer is available ( inside 'new' overloads, for example ) + #ifdef _MSC_VER + #define MEM_ALLOC_CREDIT_FUNCTION() MEM_ALLOC_CREDIT_( __FUNCTION__ ) + #else + #define MEM_ALLOC_CREDIT_FUNCTION() (__FILE__) + #endif + + #pragma warning(pop) +#else + #define MEM_ALLOC_CREDIT_CLASS() + #define MEM_ALLOC_CLASSNAME(type) NULL + #define MEM_ALLOC_CREDIT_FUNCTION() +#endif + +//----------------------------------------------------------------------------- + +#if (defined(_DEBUG) || defined(USE_MEM_DEBUG)) +struct MemAllocFileLine_t +{ + const char *pszFile; + int line; +}; + +#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag ) \ + static CUtlMap g_##tag##Allocs( DefLessFunc( void *) ); \ + static const char *g_psz##tag##Alloc = strcpy( (char *)g_pMemAlloc->Alloc( strlen( #tag "Alloc" ) + 1, "intentional leak", 0 ), #tag "Alloc" ); + +#define MemAlloc_RegisterExternalAllocation( tag, p, size ) \ + if ( !p ) \ + ; \ + else \ + { \ + MemAllocFileLine_t fileLine = { g_psz##tag##Alloc, 0 }; \ + g_pMemAlloc->GetActualDbgInfo( fileLine.pszFile, fileLine.line ); \ + if ( fileLine.pszFile != g_psz##tag##Alloc ) \ + { \ + g_##tag##Allocs.Insert( p, fileLine ); \ + } \ + \ + MemAlloc_RegisterAllocation( fileLine.pszFile, fileLine.line, size, size, 0); \ + } + +#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) \ + if ( !p ) \ + ; \ + else \ + { \ + MemAllocFileLine_t fileLine = { g_psz##tag##Alloc, 0 }; \ + CUtlMap::IndexType_t iRecordedFileLine = g_##tag##Allocs.Find( p ); \ + if ( iRecordedFileLine != g_##tag##Allocs.InvalidIndex() ) \ + { \ + fileLine = g_##tag##Allocs[iRecordedFileLine]; \ + g_##tag##Allocs.RemoveAt( iRecordedFileLine ); \ + } \ + \ + MemAlloc_RegisterDeallocation( fileLine.pszFile, fileLine.line, size, size, 0); \ + } + +#else + +#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag ) +#define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0) +#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0) + +#endif + +//----------------------------------------------------------------------------- + +#elif defined( POSIX ) + +#if defined( OSX ) +// Mac always aligns allocs, don't need to call posix_memalign which doesn't exist in 10.5.8 which TF2 still needs to run on +//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;} +inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); return pTmp;} +#endif + +inline void *_aligned_malloc( size_t nSize, size_t align ) { return memalign( align, nSize ); } +inline void _aligned_free( void *ptr ) { free( ptr ); } + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName = NULL, int nLine = 0 ) { return malloc( nSize ); } +inline void MemAlloc_Free( void *ptr, const char *pFileName = NULL, int nLine = 0 ) { free( ptr ); } + +inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile = NULL, int nLine = 0 ) { free( pMemBlock ); } + +#if defined( OSX ) +inline size_t _msize( void *ptr ) { return malloc_size( ptr ); } +#else +inline size_t _msize( void *ptr ) { return malloc_usable_size( ptr ); } +#endif + +inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align ) +{ + void *ptr_new_aligned = memalign( align, size ); + + if( ptr_new_aligned ) + { + size_t old_size = _msize( ptr ); + size_t copy_size = ( size < old_size ) ? size : old_size; + + memcpy( ptr_new_aligned, ptr, copy_size ); + free( ptr ); + } + + return ptr_new_aligned; +} +#else +#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize() +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo ) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo ) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) + +#endif // !STEAM && !NO_MALLOC_OVERRIDE + +//----------------------------------------------------------------------------- + +#if !defined(STEAM) && defined(NO_MALLOC_OVERRIDE) + +#define MEM_ALLOC_CREDIT_(tag) ((void)0) +#define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__) +#define MEM_ALLOC_CREDIT_FUNCTION() +#define MEM_ALLOC_CREDIT_CLASS() +#define MEM_ALLOC_CLASSNAME(type) NULL + +#define MemAlloc_PushAllocDbgInfo( pszFile, line ) +#define MemAlloc_PopAllocDbgInfo() +#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#define MemAlloc_DumpStats() ((void)0) +#define MemAlloc_CompactHeap() ((void)0) +#define MemAlloc_OutOfMemory() ((void)0) +#define MemAlloc_CompactIncremental() ((void)0) +#define MemAlloc_DumpStatsFileBase( _filename ) ((void)0) +inline bool MemAlloc_CrtCheckMemory() { return true; } +inline void MemAlloc_GlobalMemoryStatus( size_t *pusedMemory, size_t *pfreeMemory ) +{ + *pusedMemory = 0; + *pfreeMemory = 0; +} +#define MemAlloc_MemoryAllocFailed() 0 + +#define MemAlloc_GetDebugInfoSize() 0 +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) ((void)0) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) ((void)0) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) ((void)0) + + +#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag ) +#define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0) +#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0) + +#endif // !STEAM && NO_MALLOC_OVERRIDE + +//----------------------------------------------------------------------------- + + + +// linux memory tracking via hooks. +#if defined( POSIX ) && !defined( NO_HOOK_MALLOC ) +PLATFORM_INTERFACE void MemoryLogMessage( char const *s ); // throw a message into the memory log +PLATFORM_INTERFACE void EnableMemoryLogging( bool bOnOff ); +PLATFORM_INTERFACE void DumpMemoryLog( int nThresh ); +PLATFORM_INTERFACE void DumpMemorySummary( void ); +PLATFORM_INTERFACE void SetMemoryMark( void ); +PLATFORM_INTERFACE void DumpChangedMemory( int nThresh ); + +#else +FORCEINLINE void MemoryLogMessage( char const *s ) +{ +} + +FORCEINLINE void EnableMemoryLogging( bool bOnOff ) +{ +} +FORCEINLINE void DumpMemoryLog( int nThresh ) +{ +} +FORCEINLINE void DumpMemorySummary( void ) +{ +} +FORCEINLINE void SetMemoryMark( void ) +{ +} +FORCEINLINE void DumpChangedMemory( int nThresh ) +{ +} + +#endif + +#ifdef POSIX +// ApproximateProcessMemoryUsage returns the approximate memory footprint of this process. +PLATFORM_INTERFACE size_t ApproximateProcessMemoryUsage( void ); +#else +FORCEINLINE size_t ApproximateProcessMemoryUsage( void ) +{ + return 0; +} + +#endif + +struct aligned_tmp_t +{ + // empty base class +}; + +/* +This class used to be required if you wanted an object to be allocated with a specific +alignment. ALIGN16 and ALIGN16_POST are not actually sufficient for this because they +guarantee that the globals, statics, locals, and function parameters are appropriately +aligned they do not affect memory allocation alignment. +However this class is usually not needed because as of 2012 our policy is that our +allocator should take care of this automatically. Any object whose size is a multiple +of 16 will be 16-byte aligned. Existing uses of this class were not changed because +the cost/benefit did not justify it. +*/ +// template here to allow adding alignment at levels of hierarchy that aren't the base +template< int bytesAlignment = 16, class T = aligned_tmp_t > +class CAlignedNewDelete : public T +{ + +public: + /* + Note that this class does not overload operator new[] and delete[] which means that + classes that depend on this for alignment may end up misaligned if an array is + allocated. This problem is now mostly theoretical because this class is mostly + obsolete. + */ + void *operator new( size_t nSize ) + { + return MemAlloc_AllocAligned( nSize, bytesAlignment ); + } + + void* operator new( size_t nSize, int nBlockUse, const char *pFileName, int nLine ) + { + return MemAlloc_AllocAlignedFileLine( nSize, bytesAlignment, pFileName, nLine ); + } + + void operator delete(void *pData) + { + if ( pData ) + { + MemAlloc_FreeAligned( pData ); + } + } + + void operator delete( void* pData, int nBlockUse, const char *pFileName, int nLine ) + { + if ( pData ) + { + MemAlloc_FreeAligned( pData, pFileName, nLine ); + } + } +}; + + +#endif /* TIER0_MEMALLOC_H */ diff --git a/src/public_sp/tier0/memdbgoff.h b/src/public_sp/tier0/memdbgoff.h new file mode 100644 index 00000000000..1cd09dae686 --- /dev/null +++ b/src/public_sp/tier0/memdbgoff.h @@ -0,0 +1,25 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This header, which must be the final line of a .h file, +// causes all crt methods to stop using debugging versions of the memory allocators. +// NOTE: Use memdbgon.h to re-enable memory debugging. +// +// $NoKeywords: $ +//=============================================================================// + +#ifdef MEM_OVERRIDE_ON + +#undef malloc +#undef realloc +#undef calloc +#undef free +#undef _expand +#undef _msize +#undef new +#undef _aligned_malloc +#undef _aligned_free +#undef _malloc_dbg + +#undef MEM_OVERRIDE_ON + +#endif diff --git a/src/public_sp/tier0/memdbgon.h b/src/public_sp/tier0/memdbgon.h new file mode 100644 index 00000000000..4e46839fc21 --- /dev/null +++ b/src/public_sp/tier0/memdbgon.h @@ -0,0 +1,248 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This header, which must be the final include in a .cpp (or .h) file, +// causes all crt methods to use debugging versions of the memory allocators. +// NOTE: Use memdbgoff.h to disable memory debugging. +// +// $NoKeywords: $ +//=============================================================================// + +// SPECIAL NOTE! This file must *not* use include guards; we need to be able +// to include this potentially multiple times (since we can deactivate debugging +// by including memdbgoff.h) + +#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) + +// SPECIAL NOTE #2: This must be the final include in a .cpp or .h file!!! + +#if defined(_DEBUG) && !defined(USE_MEM_DEBUG) +#define USE_MEM_DEBUG 1 +#endif + +#if defined(NO_HOOK_MALLOC) +#undef USE_MEM_DEBUG +#endif + +// If debug build or ndebug and not already included MS custom alloc files, or already included this file +#if (defined(_DEBUG) || !defined(_INC_CRTDBG)) || defined(MEMDBGON_H) + +#include "basetypes.h" +#ifdef _WIN32 +#include +#else +#include +#endif +#include +#include +#include "commonmacros.h" +#include "memalloc.h" + +#if USE_MEM_DEBUG + #if defined( POSIX ) + + #define _NORMAL_BLOCK 1 + + #include + #include + #include + #include + #if !defined( DID_THE_OPERATOR_NEW ) + #define DID_THE_OPERATOR_NEW + // posix doesn't have a new of this form, so we impl our own + void* operator new( size_t nSize, int blah, const char *pFileName, int nLine ); + void* operator new[]( size_t nSize, int blah, const char *pFileName, int nLine ); + #endif + + #else // defined(POSIX) + + // Include crtdbg.h and make sure _DEBUG is set to 1. + #if !defined(_DEBUG) + #define _DEBUG 1 + #include + #undef _DEBUG + #else + #include + #endif // !defined(_DEBUG) + + #endif // defined(POSIX) +#endif + +#include "tier0/memdbgoff.h" + +// -------------------------------------------------------- +// Debug/non-debug agnostic elements + +#define MEM_OVERRIDE_ON 1 + +#undef malloc +#undef realloc +#undef calloc +#undef _expand +#undef free +#undef _msize +#undef _aligned_malloc +#undef _aligned_free + +#ifndef MEMDBGON_H +inline void *MemAlloc_InlineCallocMemset( void *pMem, size_t nCount, size_t nElementSize) +{ + memset(pMem, 0, nElementSize * nCount); + return pMem; +} +#endif + +#define calloc(c, s) MemAlloc_InlineCallocMemset(malloc((c)*(s)), (c), (s)) +#define free(p) g_pMemAlloc->Free( p ) +#define _msize(p) g_pMemAlloc->GetSize( p ) +#define _expand(p, s) _expand_NoLongerSupported(p, s) +#define _aligned_free( p ) MemAlloc_FreeAligned( p ) + +// -------------------------------------------------------- +// Debug path +#if USE_MEM_DEBUG + +#define malloc(s) g_pMemAlloc->Alloc( s, __FILE__, __LINE__) +#define realloc(p, s) g_pMemAlloc->Realloc( p, s, __FILE__, __LINE__ ) +#define _aligned_malloc( s, a ) MemAlloc_AllocAligned( s, a, __FILE__, __LINE__ ) + +#define _malloc_dbg(s, t, f, l) WHYCALLINGTHISDIRECTLY(s) + +#if !defined( LINUX ) +#if defined(__AFX_H__) && defined(DEBUG_NEW) + #define new DEBUG_NEW +#else + #undef new + #define MEMALL_DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) + #define new MEMALL_DEBUG_NEW +#endif +#endif + +#undef _strdup +#undef strdup +#undef _wcsdup +#undef wcsdup + +#define _strdup(s) MemAlloc_StrDup(s, __FILE__, __LINE__) +#define strdup(s) MemAlloc_StrDup(s, __FILE__, __LINE__) +#define _wcsdup(s) MemAlloc_WcStrDup(s, __FILE__, __LINE__) +#define wcsdup(s) MemAlloc_WcStrDup(s, __FILE__, __LINE__) + +// Make sure we don't define strdup twice +#if !defined(MEMDBGON_H) + +inline char *MemAlloc_StrDup(const char *pString, const char *pFileName, unsigned nLine) +{ + char *pMemory; + + if (!pString) + return NULL; + + size_t len = strlen(pString) + 1; + if ((pMemory = (char *)g_pMemAlloc->Alloc(len, pFileName, nLine)) != NULL) + { + return strcpy( pMemory, pString ); + } + + return NULL; +} + +inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString, const char *pFileName, unsigned nLine) +{ + wchar_t *pMemory; + + if (!pString) + return NULL; + + size_t len = (wcslen(pString) + 1); + if ((pMemory = (wchar_t *)g_pMemAlloc->Alloc(len * sizeof(wchar_t), pFileName, nLine)) != NULL) + { + return wcscpy( pMemory, pString ); + } + + return NULL; +} + +#endif // DBMEM_DEFINED_STRDUP + +#else +// -------------------------------------------------------- +// Release path + +#define malloc(s) g_pMemAlloc->Alloc( s ) +#define realloc(p, s) g_pMemAlloc->Realloc( p, s ) +#define _aligned_malloc( s, a ) MemAlloc_AllocAligned( s, a ) + +#ifndef _malloc_dbg +#define _malloc_dbg(s, t, f, l) WHYCALLINGTHISDIRECTLY(s) +#endif + +#undef new + +#undef _strdup +#undef strdup +#undef _wcsdup +#undef wcsdup + +#define _strdup(s) MemAlloc_StrDup(s) +#define strdup(s) MemAlloc_StrDup(s) +#define _wcsdup(s) MemAlloc_WcStrDup(s) +#define wcsdup(s) MemAlloc_WcStrDup(s) + +// Make sure we don't define strdup twice +#if !defined(MEMDBGON_H) + +inline char *MemAlloc_StrDup(const char *pString) +{ + char *pMemory; + + if (!pString) + return NULL; + + size_t len = strlen(pString) + 1; + if ((pMemory = (char *)g_pMemAlloc->Alloc(len)) != NULL) + { + return strcpy( pMemory, pString ); + } + + return NULL; +} + +inline wchar_t *MemAlloc_WcStrDup(const wchar_t *pString) +{ + wchar_t *pMemory; + + if (!pString) + return NULL; + + size_t len = (wcslen(pString) + 1); + if ((pMemory = (wchar_t *)g_pMemAlloc->Alloc(len * sizeof(wchar_t))) != NULL) + { + return wcscpy( pMemory, pString ); + } + + return NULL; +} + +#endif // DBMEM_DEFINED_STRDUP + +#endif // USE_MEM_DEBUG + +#define MEMDBGON_H // Defined here so can be used above + +#else + +#if USE_MEM_DEBUG +#ifndef _STATIC_LINKED +#pragma message ("Note: file includes crtdbg.h directly, therefore will cannot use memdbgon.h in non-debug build") +#else +#error "Error: file includes crtdbg.h directly, therefore will cannot use memdbgon.h in non-debug build. Not recoverable in static build" +#endif +#endif +#endif // _INC_CRTDBG + +#else + +// Needed for MEM_ALLOC_CREDIT(), MemAlloc_Alloc(), etc. +#include "memalloc.h" + +#endif // !STEAM && !NO_MALLOC_OVERRIDE diff --git a/src/public_sp/tier0/memoverride.cpp b/src/public_sp/tier0/memoverride.cpp new file mode 100644 index 00000000000..5ff4dbb4257 --- /dev/null +++ b/src/public_sp/tier0/memoverride.cpp @@ -0,0 +1,1783 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Insert this file into all projects using the memory system +// It will cause that project to use the shader memory allocator +// +// $NoKeywords: $ +//=============================================================================// + + +#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) + +#undef PROTECTED_THINGS_ENABLE // allow use of _vsnprintf + +#if defined( _WIN32 ) && !defined( _X360 ) +#define WIN_32_LEAN_AND_MEAN +#include +#endif + +#include "tier0/dbg.h" +#include "tier0/memalloc.h" +#include +#include +#include "memdbgoff.h" + +#ifdef _WIN32 +// ARG: crtdbg is necessary for certain definitions below, +// but it also redefines malloc as a macro in release. +// To disable this, we gotta define _DEBUG before including it.. BLEAH! +#define _DEBUG 1 +#include "crtdbg.h" +#ifdef NDEBUG +#undef _DEBUG +#endif + +// Turn this back off in release mode. +#ifdef NDEBUG +#undef _DEBUG +#endif +#elif POSIX +#define __cdecl +#endif + +#undef _malloc_dbg +#undef _calloc_dbg +#undef _free_dbg +#undef _CrtSetCheckCount +#undef _CrtGetCheckCount +#undef _CrtSetDebugFillThreshold + +#if defined( _WIN32 ) && !defined( _X360 ) +const char *MakeModuleFileName() +{ +#if _MSC_VER < 1900 + if ( g_pMemAlloc->IsDebugHeap() ) + { + char *pszModuleName = (char *)HeapAlloc( GetProcessHeap(), 0, MAX_PATH ); // small leak, debug only + + MEMORY_BASIC_INFORMATION mbi; + static int dummy; + VirtualQuery( &dummy, &mbi, sizeof(mbi) ); + + GetModuleFileName( reinterpret_cast(mbi.AllocationBase), pszModuleName, MAX_PATH ); + char *pDot = strrchr( pszModuleName, '.' ); + if ( pDot ) + { + char *pSlash = strrchr( pszModuleName, '\\' ); + if ( pSlash ) + { + pszModuleName = pSlash + 1; + *pDot = 0; + } + } + + return pszModuleName; + } +#endif + return NULL; +} + +static void *AllocUnattributed( size_t nSize ) +{ +#if _MSC_VER < 1900 + static const char *pszOwner = MakeModuleFileName(); + + if ( !pszOwner ) + return g_pMemAlloc->Alloc(nSize); + else + return g_pMemAlloc->Alloc(nSize, pszOwner, 0); +#else + return g_pMemAlloc->Alloc(nSize); +#endif +} + +static void *ReallocUnattributed( void *pMem, size_t nSize ) +{ +#if _MSC_VER < 1900 + static const char *pszOwner = MakeModuleFileName(); + + if ( !pszOwner ) + return g_pMemAlloc->Realloc(pMem, nSize); + else + return g_pMemAlloc->Realloc(pMem, nSize, pszOwner, 0); +#else + return g_pMemAlloc->Realloc(pMem, nSize); +#endif +} + +#else +#define MakeModuleFileName() NULL +inline void *AllocUnattributed( size_t nSize ) +{ + return g_pMemAlloc->Alloc(nSize); +} + +inline void *ReallocUnattributed( void *pMem, size_t nSize ) +{ + return g_pMemAlloc->Realloc(pMem, nSize); +} +#endif + +//----------------------------------------------------------------------------- +// Standard functions in the CRT that we're going to override to call our allocator +//----------------------------------------------------------------------------- +#if defined(_WIN32) && !defined(_STATIC_LINKED) +// this magic only works under win32 +// under linux this malloc() overrides the libc malloc() and so we +// end up in a recursion (as g_pMemAlloc->Alloc() calls malloc) +#if _MSC_VER >= 1900 && !defined(_CRTNOALIAS) +#define _CRTNOALIAS +#endif +#if _MSC_VER >= 1400 +#define ALLOC_CALL _CRTNOALIAS _CRTRESTRICT +#define FREE_CALL _CRTNOALIAS +#else +#define ALLOC_CALL +#define FREE_CALL +#endif + +extern "C" +{ + +ALLOC_CALL void *malloc( size_t nSize ) +{ + return AllocUnattributed( nSize ); +} + +FREE_CALL void free( void *pMem ) +{ + g_pMemAlloc->Free(pMem); +} + +ALLOC_CALL void *realloc( void *pMem, size_t nSize ) +{ + return ReallocUnattributed( pMem, nSize ); +} + +ALLOC_CALL void *calloc( size_t nCount, size_t nElementSize ) +{ + void *pMem = AllocUnattributed( nElementSize * nCount ); + memset(pMem, 0, nElementSize * nCount); + return pMem; +} + +} // end extern "C" + +//----------------------------------------------------------------------------- +// Non-standard MSVC functions that we're going to override to call our allocator +//----------------------------------------------------------------------------- +extern "C" +{ + +// 64-bit +#ifdef _WIN64 +void* __cdecl _malloc_base( size_t nSize ) +{ + return AllocUnattributed( nSize ); +} +#elif _MSC_VER >= 1900 + __declspec(restrict) void* _malloc_base(size_t nSize) + { + return AllocUnattributed(nSize); + } +#else +void *_malloc_base( size_t nSize ) +{ + return AllocUnattributed( nSize ); +} +#endif + +#if _MSC_VER >= 1900 +__declspec(restrict) void* _calloc_base(size_t count, size_t nSize) +{ + void* pMem = AllocUnattributed(count * nSize); + memset(pMem, 0, count * nSize); + return pMem; +} +#else +void *_calloc_base( size_t nSize ) +{ + void *pMem = AllocUnattributed( nSize ); + memset(pMem, 0, nSize); + return pMem; +} +#endif + +#if _MSC_VER >= 1900 +__declspec(restrict) void* _realloc_base(void* pMem, size_t nSize) +{ + return ReallocUnattributed(pMem, nSize); +} +#else +void *_realloc_base( void *pMem, size_t nSize ) +{ + return ReallocUnattributed( pMem, nSize ); +} +#endif + +#if _MSC_VER >= 1900 +__declspec(restrict) void* _recalloc_base(void* pMem, size_t count, size_t nSize) +{ + return _recalloc(pMem, count, nSize); +} +#else +void *_recalloc_base( void *pMem, size_t nSize ) +{ + void *pMemOut = ReallocUnattributed( pMem, nSize ); + memset(pMemOut, 0, nSize); + return pMemOut; +} +#endif + +void _free_base( void *pMem ) +{ + g_pMemAlloc->Free(pMem); +} + +void *__cdecl _expand_base( void *pMem, size_t nNewSize, int nBlockUse ) +{ + Assert( 0 ); + return NULL; +} + +// crt +void * __cdecl _malloc_crt(size_t size) +{ + return AllocUnattributed( size ); +} + +void * __cdecl _calloc_crt(size_t count, size_t size) +{ +#if _MSC_VER >= 1900 + return _calloc_base(count, size); +#else + return _calloc_base( count * size ); +#endif +} + +void * __cdecl _realloc_crt(void *ptr, size_t size) +{ + return _realloc_base( ptr, size ); +} + +void * __cdecl _recalloc_crt(void *ptr, size_t count, size_t size) +{ +#if _MSC_VER >= 1900 + return _recalloc_base(ptr, count, size); +#else + return _recalloc_base( ptr, size * count ); +#endif +} + +ALLOC_CALL void * __cdecl _recalloc ( void * memblock, size_t count, size_t size ) +{ + const size_t oldSize = _msize(memblock); + const size_t newSize = count * size; + void* pMemOut = ReallocUnattributed(memblock, newSize); + + if (newSize > oldSize) + memset(((char*)pMemOut) + oldSize, 0, newSize - oldSize); + + return pMemOut; +} + +size_t _msize_base( void *pMem ) +#if _MSC_VER >= 1925 //VS2019+ + throw() +#endif +{ + return g_pMemAlloc->GetSize(pMem); +} + +size_t _msize( void *pMem ) +{ + return _msize_base(pMem); +} + +size_t msize( void *pMem ) +{ + return g_pMemAlloc->GetSize(pMem); +} + +void *__cdecl _heap_alloc( size_t nSize ) +{ + return AllocUnattributed( nSize ); +} + +void *__cdecl _nh_malloc( size_t nSize, int ) +{ + return AllocUnattributed( nSize ); +} + +void *__cdecl _expand( void *pMem, size_t nSize ) +{ + Assert( 0 ); + return NULL; +} + +unsigned int _amblksiz = 16; //BYTES_PER_PARA; + +#if _MSC_VER >= 1400 +HANDLE _crtheap = (HANDLE)1; // PatM Can't be 0 or CRT pukes +int __active_heap = 1; +#endif // _MSC_VER >= 1400 + +size_t __cdecl _get_sbh_threshold( void ) +{ + return 0; +} + +int __cdecl _set_sbh_threshold( size_t ) +{ + return 0; +} + +int _heapchk() +{ + return g_pMemAlloc->heapchk(); +} + +int _heapmin() +{ + return 1; +} + +int __cdecl _heapadd( void *, size_t ) +{ + return 0; +} + +int __cdecl _heapset( unsigned int ) +{ + return 0; +} + +size_t __cdecl _heapused( size_t *, size_t * ) +{ + return 0; +} + +#ifdef _WIN32 +int __cdecl _heapwalk( _HEAPINFO * ) +{ + return 0; +} +#endif + +} // end extern "C" + + +//----------------------------------------------------------------------------- +// Debugging functions that we're going to override to call our allocator +// NOTE: These have to be here for release + debug builds in case we +// link to a debug static lib!!! +//----------------------------------------------------------------------------- + +extern "C" +{ + +void *malloc_db( size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Alloc(nSize, pFileName, nLine); +} + +void free_db( void *pMem, const char *pFileName, int nLine ) +{ + g_pMemAlloc->Free(pMem, pFileName, nLine); +} + +void *realloc_db( void *pMem, size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Realloc(pMem, nSize, pFileName, nLine); +} + +} // end extern "C" + +//----------------------------------------------------------------------------- +// These methods are standard MSVC heap initialization + shutdown methods +//----------------------------------------------------------------------------- +extern "C" +{ + +#if !defined( _X360 ) + int __cdecl _heap_init() + { + return g_pMemAlloc != NULL; + } + + void __cdecl _heap_term() + { + } +#endif + +} +#endif + + +//----------------------------------------------------------------------------- +// Prevents us from using an inappropriate new or delete method, +// ensures they are here even when linking against debug or release static libs +//----------------------------------------------------------------------------- +#ifndef NO_MEMOVERRIDE_NEW_DELETE +#ifdef OSX +void *__cdecl operator new( size_t nSize ) throw (std::bad_alloc) +#else +void *__cdecl operator new( size_t nSize ) +#endif +{ + return AllocUnattributed( nSize ); +} + +void *__cdecl operator new( size_t nSize, int nBlockUse, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Alloc(nSize, pFileName, nLine); +} + +#ifdef OSX +void __cdecl operator delete( void *pMem ) throw() +#else +void __cdecl operator delete( void *pMem ) +#endif +{ + g_pMemAlloc->Free( pMem ); +} + +#ifdef OSX +void *__cdecl operator new[]( size_t nSize ) throw (std::bad_alloc) +#else +void *__cdecl operator new[]( size_t nSize ) +#endif +{ + return AllocUnattributed( nSize ); +} + +void *__cdecl operator new[] ( size_t nSize, int nBlockUse, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Alloc(nSize, pFileName, nLine); +} + +#ifdef OSX +void __cdecl operator delete[]( void *pMem ) throw() +#else +void __cdecl operator delete[]( void *pMem ) +#endif +{ + g_pMemAlloc->Free( pMem ); +} +#endif + + +//----------------------------------------------------------------------------- +// Override some debugging allocation methods in MSVC +// NOTE: These have to be here for release + debug builds in case we +// link to a debug static lib!!! +//----------------------------------------------------------------------------- +#ifndef _STATIC_LINKED +#ifdef _WIN32 + +// This here just hides the internal file names, etc of allocations +// made in the c runtime library +#define CRT_INTERNAL_FILE_NAME "C-runtime internal" + +class CAttibCRT +{ +public: + CAttibCRT(int nBlockUse) : m_nBlockUse(nBlockUse) + { + if (m_nBlockUse == _CRT_BLOCK) + { + g_pMemAlloc->PushAllocDbgInfo(CRT_INTERNAL_FILE_NAME, 0); + } + } + + ~CAttibCRT() + { + if (m_nBlockUse == _CRT_BLOCK) + { + g_pMemAlloc->PopAllocDbgInfo(); + } + } + +private: + int m_nBlockUse; +}; + + +#define AttribIfCrt() CAttibCRT _attrib(nBlockUse) +#elif defined(POSIX) +#define AttribIfCrt() +#endif // _WIN32 + + +extern "C" +{ + +void *__cdecl _nh_malloc_dbg( size_t nSize, int nFlag, int nBlockUse, + const char *pFileName, int nLine ) +{ + AttribIfCrt(); + return g_pMemAlloc->Alloc(nSize, pFileName, nLine); +} + +void *__cdecl _malloc_dbg( size_t nSize, int nBlockUse, + const char *pFileName, int nLine ) +{ + AttribIfCrt(); + return g_pMemAlloc->Alloc(nSize, pFileName, nLine); +} + +#if defined( _X360 ) +void *__cdecl _calloc_dbg_impl( size_t nNum, size_t nSize, int nBlockUse, + const char * szFileName, int nLine, int * errno_tmp ) +{ + return _calloc_dbg( nNum, nSize, nBlockUse, szFileName, nLine ); +} +#endif + +void *__cdecl _calloc_dbg( size_t nNum, size_t nSize, int nBlockUse, + const char *pFileName, int nLine ) +{ + AttribIfCrt(); + void *pMem = g_pMemAlloc->Alloc(nSize * nNum, pFileName, nLine); + memset(pMem, 0, nSize * nNum); + return pMem; +} + +void *__cdecl _calloc_dbg_impl( size_t nNum, size_t nSize, int nBlockUse, + const char * szFileName, int nLine, int * errno_tmp ) +{ + return _calloc_dbg( nNum, nSize, nBlockUse, szFileName, nLine ); +} + +#ifdef DEBUG +void *__cdecl _realloc_dbg( void *pMem, size_t nNewSize, int nBlockUse, + const char *pFileName, int nLine ) +{ + AttribIfCrt(); + return g_pMemAlloc->Realloc(pMem, nNewSize, pFileName, nLine); +} + +void *__cdecl _expand_dbg( void *pMem, size_t nNewSize, int nBlockUse, + const char *pFileName, int nLine ) +{ + Assert( 0 ); + return NULL; +} +#endif + +void __cdecl _free_dbg( void *pMem, int nBlockUse ) +{ + AttribIfCrt(); + g_pMemAlloc->Free(pMem); +} + +#ifdef DEBUG +size_t __cdecl _msize_dbg( void *pMem, int nBlockUse ) +{ +#ifdef _WIN32 + return _msize(pMem); +#elif POSIX + Assert( "_msize_dbg unsupported" ); + return 0; +#endif +} +#endif + + +#ifdef _WIN32 + +#if defined(_DEBUG) && _MSC_VER >= 1300 +// X360TBD: aligned and offset allocations may be important on the 360 + +// aligned base +ALLOC_CALL void *__cdecl _aligned_malloc_base( size_t size, size_t align ) +{ + return MemAlloc_AllocAligned( size, align ); +} + +ALLOC_CALL void *__cdecl _aligned_realloc_base( void *ptr, size_t size, size_t align ) +{ + return MemAlloc_ReallocAligned( ptr, size, align ); +} + +ALLOC_CALL void *__cdecl _aligned_recalloc_base( void *ptr, size_t size, size_t align ) +{ + Error( "Unsupported function\n" ); + return NULL; +} + +FREE_CALL void __cdecl _aligned_free_base( void *ptr ) +{ + MemAlloc_FreeAligned( ptr ); +} + +// aligned +ALLOC_CALL void * __cdecl _aligned_malloc( size_t size, size_t align ) +{ + return _aligned_malloc_base(size, align); +} + +ALLOC_CALL void *__cdecl _aligned_realloc(void *memblock, size_t size, size_t align) +{ + return _aligned_realloc_base(memblock, size, align); +} + +ALLOC_CALL void * __cdecl _aligned_recalloc( void * memblock, size_t count, size_t size, size_t align ) +{ + return _aligned_recalloc_base(memblock, count * size, align); +} + +FREE_CALL void __cdecl _aligned_free( void *memblock ) +{ + _aligned_free_base(memblock); +} + +// aligned offset base +ALLOC_CALL void * __cdecl _aligned_offset_malloc_base( size_t size, size_t align, size_t offset ) +{ + Assert( IsPC() || 0 ); + return NULL; +} + +ALLOC_CALL void * __cdecl _aligned_offset_realloc_base( void * memblock, size_t size, size_t align, size_t offset) +{ + Assert( IsPC() || 0 ); + return NULL; +} + +ALLOC_CALL void * __cdecl _aligned_offset_recalloc_base( void * memblock, size_t size, size_t align, size_t offset) +{ + Assert( IsPC() || 0 ); + return NULL; +} + +// aligned offset +ALLOC_CALL void *__cdecl _aligned_offset_malloc(size_t size, size_t align, size_t offset) +{ + return _aligned_offset_malloc_base( size, align, offset ); +} + +ALLOC_CALL void *__cdecl _aligned_offset_realloc(void *memblock, size_t size, size_t align, size_t offset) +{ + return _aligned_offset_realloc_base( memblock, size, align, offset ); +} + +ALLOC_CALL void * __cdecl _aligned_offset_recalloc( void * memblock, size_t count, size_t size, size_t align, size_t offset ) +{ + return _aligned_offset_recalloc_base( memblock, count * size, align, offset ); +} + +#endif // _MSC_VER >= 1400 + +#endif + +} // end extern "C" + + +//----------------------------------------------------------------------------- +// Override some the _CRT debugging allocation methods in MSVC +//----------------------------------------------------------------------------- +#ifdef _WIN32 + +extern "C" +{ + +#ifdef DEBUG +int _CrtDumpMemoryLeaks(void) +{ + return 0; +} + +_CRT_DUMP_CLIENT _CrtSetDumpClient( _CRT_DUMP_CLIENT dumpClient ) +{ + return NULL; +} + +int _CrtSetDbgFlag( int nNewFlag ) +{ + return g_pMemAlloc->CrtSetDbgFlag( nNewFlag ); +} +#endif + +// 64-bit port. +#define AFNAME(var) __p_ ## var +#define AFRET(var) &var + +#if _MSC_VER >= 1900 +int* __cdecl __p__crtDbgFlag(void) +{ + static int dummy = _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF; + return &dummy; +} + +long* __cdecl __p__crtBreakAlloc(void) +{ + static long dummy = 0; + return &dummy; +} +#else +int _crtDbgFlag = _CRTDBG_ALLOC_MEM_DF; +int* AFNAME(_crtDbgFlag)(void) +{ + return AFRET(_crtDbgFlag); +} + +long _crtBreakAlloc; /* Break on this allocation */ +long* AFNAME(_crtBreakAlloc) (void) +{ + return AFRET(_crtBreakAlloc); +} +#endif + +void __cdecl _CrtSetDbgBlockType( void *pMem, int nBlockUse ) +{ + DebuggerBreak(); +} + +#ifdef DEBUG +_CRT_ALLOC_HOOK __cdecl _CrtSetAllocHook( _CRT_ALLOC_HOOK pfnNewHook ) +{ + DebuggerBreak(); + return NULL; +} + +long __cdecl _CrtSetBreakAlloc( long lNewBreakAlloc ) +{ + return g_pMemAlloc->CrtSetBreakAlloc( lNewBreakAlloc ); +} + +int __cdecl _CrtIsValidHeapPointer( const void *pMem ) +{ + return g_pMemAlloc->CrtIsValidHeapPointer( pMem ); +} + +int __cdecl _CrtIsValidPointer( const void *pMem, unsigned int size, int access ) +{ + return g_pMemAlloc->CrtIsValidPointer( pMem, size, access ); +} + +int __cdecl _CrtCheckMemory( void ) +{ + // FIXME: Remove this when we re-implement the heap + return g_pMemAlloc->CrtCheckMemory( ); +} + +int __cdecl _CrtIsMemoryBlock( const void *pMem, unsigned int nSize, + long *plRequestNumber, char **ppFileName, int *pnLine ) +{ + DebuggerBreak(); + return 1; +} + +int __cdecl _CrtMemDifference( _CrtMemState *pState, const _CrtMemState * oldState, const _CrtMemState * newState ) +{ + DebuggerBreak(); + return FALSE; +} + +void __cdecl _CrtMemDumpStatistics( const _CrtMemState *pState ) +{ + DebuggerBreak(); +} + +void __cdecl _CrtMemCheckpoint( _CrtMemState *pState ) +{ + // FIXME: Remove this when we re-implement the heap + g_pMemAlloc->CrtMemCheckpoint( pState ); +} + +void __cdecl _CrtMemDumpAllObjectsSince( const _CrtMemState *pState ) +{ + DebuggerBreak(); +} + +void __cdecl _CrtDoForAllClientObjects( void (*pfn)(void *, void *), void * pContext ) +{ + DebuggerBreak(); +} +#endif + +//----------------------------------------------------------------------------- +// Methods in dbgrpt.cpp +//----------------------------------------------------------------------------- +long _crtAssertBusy = -1; + +#ifdef DEBUG +int __cdecl _CrtSetReportMode( int nReportType, int nReportMode ) +{ + return g_pMemAlloc->CrtSetReportMode( nReportType, nReportMode ); +} + +_HFILE __cdecl _CrtSetReportFile( int nRptType, _HFILE hFile ) +{ + return (_HFILE)g_pMemAlloc->CrtSetReportFile( nRptType, hFile ); +} + +_CRT_REPORT_HOOK __cdecl _CrtSetReportHook( _CRT_REPORT_HOOK pfnNewHook ) +{ + return (_CRT_REPORT_HOOK)g_pMemAlloc->CrtSetReportHook( pfnNewHook ); +} +#endif + +int __cdecl _CrtDbgReport( int nRptType, const char * szFile, + int nLine, const char * szModule, const char * szFormat, ... ) +{ + static char output[1024]; + va_list args; + if ( szFormat ) + { + va_start( args, szFormat ); + _vsnprintf( output, sizeof( output )-1, szFormat, args ); + va_end( args ); + } + else + { + output[0] = 0; + } + + return g_pMemAlloc->CrtDbgReport( nRptType, szFile, nLine, szModule, output ); +} + +#if _MSC_VER >= 1400 + +// Configure VS so that it will record crash dumps on pure-call violations +// and invalid parameter handlers. +// If you manage to call a pure-virtual function (easily done if you indirectly +// call a pure-virtual function from the base-class constructor or destructor) +// or if you invoke the invalid parameter handler (printf(NULL); is one way) +// then no crash dump will be created. +// This crash redirects the handlers for these two events so that crash dumps +// are created. +// +// The ErrorHandlerRegistrar object must be in memoverride.cpp so that it will +// be placed in every DLL and EXE. This is required because each DLL and EXE +// gets its own copy of the C run-time and these overrides are set on a per-CRT +// basis. + +/* +// This sample code will cause pure-call and invalid_parameter violations and +// was used for testing: +class Base +{ +public: + virtual void PureFunction() = 0; + + Base() + { + NonPureFunction(); + } + + void NonPureFunction() + { + PureFunction(); + } +}; + +class Derived : public Base +{ +public: + void PureFunction() OVERRIDE + { + } +}; + +void PureCallViolation() +{ + Derived derived; +} + +void InvalidParameterViolation() +{ + printf( NULL ); +} +*/ + +#include +#include "minidump.h" + +// Disable compiler optimizations. If we don't do this then VC++ generates code +// that confuses the Visual Studio debugger and causes it to display completely +// random call stacks. That makes the minidumps excruciatingly hard to understand. +#pragma optimize("", off) + +// Write a minidump file, unless running under the debugger in which case break +// into the debugger. +// The "int dummy" parameter is so that the callers can be unique so that the +// linker won't use its /opt:icf optimization to collapse them together. This +// makes reading the call stack easier. +void __cdecl WriteMiniDumpOrBreak( int dummy, const char *pchName ) +{ + if ( Plat_IsInDebugSession() ) + { + __debugbreak(); + // Continue at your peril... + } + else + { + WriteMiniDump( pchName ); + // Call Plat_ExitProcess so we don't continue in a bad state. + TerminateProcess(GetCurrentProcess(), 0); + } +} + +void __cdecl VPureCall() +{ + WriteMiniDumpOrBreak( 0, "PureClass" ); +} + +void VInvalidParameterHandler(const wchar_t* expression, + const wchar_t* function, + const wchar_t* file, + unsigned int line, + uintptr_t pReserved) +{ + WriteMiniDumpOrBreak( 1, "InvalidParameterHandler" ); +} + +// Restore compiler optimizations. +#pragma optimize("", on) + +// Helper class for registering error callbacks. See above for details. +class ErrorHandlerRegistrar +{ +public: + ErrorHandlerRegistrar(); +} s_ErrorHandlerRegistration; + +ErrorHandlerRegistrar::ErrorHandlerRegistrar() +{ + _set_purecall_handler( VPureCall ); + _set_invalid_parameter_handler( VInvalidParameterHandler ); +} + +#if 0 // defined( _DEBUG ) + +// wrapper which passes no debug info; not available in debug +#ifndef SUPPRESS_INVALID_PARAMETER_NO_INFO +void __cdecl _invalid_parameter_noinfo(void) +{ + Assert(0); +} +#endif + +#endif /* defined( _DEBUG ) */ + +#if defined( _DEBUG ) || defined( USE_MEM_DEBUG ) + +int __cdecl __crtMessageWindowW( int nRptType, const wchar_t * szFile, const wchar_t * szLine, + const wchar_t * szModule, const wchar_t * szUserMessage ) +{ + Assert(0); + return 0; +} + +int __cdecl _CrtDbgReportV( int nRptType, const wchar_t *szFile, int nLine, + const wchar_t *szModule, const wchar_t *szFormat, va_list arglist ) +{ + wchar_t buffer[256]; + vswprintf(buffer, 256, szFormat, arglist); + DevWarning("%ls", buffer); + return 0; +} + +int __cdecl _CrtDbgReportW( int nRptType, const wchar_t *szFile, int nLine, + const wchar_t *szModule, const wchar_t *szFormat, ...) +{ + wchar_t buffer[256]; + va_list args; + va_start(args, szFormat); + vswprintf(buffer, 256, szFormat, args); + va_end(args); + DevWarning("%ls", buffer); + return 0; +} + +#if _MSC_VER >= 1900 +int __cdecl _VCrtDbgReportA(int nRptType, void* returnAddress, const char* szFile, int nLine, + const char* szModule, const char* szFormat, va_list arglist) +#else +int __cdecl _VCrtDbgReportA( int nRptType, const wchar_t * szFile, int nLine, + const wchar_t * szModule, const wchar_t * szFormat, va_list arglist ) +#endif +{ +#if _MSC_VER >= 1900 + char buffer[256]; + vsnprintf(buffer, 256, szFormat, arglist); + DevWarning("%s", buffer); +#else + wchar_t buffer[256]; + vswprintf(buffer, 256, szFormat, arglist); + DevWarning("%ls", buffer); +#endif // _MSC_VER >= 1900 + return 0; +} + +int __cdecl _CrtSetReportHook2( int mode, _CRT_REPORT_HOOK pfnNewHook ) +{ + _CrtSetReportHook( pfnNewHook ); + return 0; +} + + +#endif /* defined( _DEBUG ) || defined( USE_MEM_DEBUG ) */ + +extern "C" int __crtDebugCheckCount = FALSE; + +extern "C" int __cdecl _CrtSetCheckCount( int fCheckCount ) +{ + int oldCheckCount = __crtDebugCheckCount; + return oldCheckCount; +} + +extern "C" int __cdecl _CrtGetCheckCount( void ) +{ + return __crtDebugCheckCount; +} + +#ifdef DEBUG +// aligned offset debug +extern "C" void * __cdecl _aligned_offset_recalloc_dbg( void * memblock, size_t count, size_t size, size_t align, size_t offset, const char * f_name, int line_n ) +{ + Assert( IsPC() || 0 ); + return ReallocUnattributed(memblock, size * count); +} + +extern "C" void * __cdecl _aligned_recalloc_dbg( void *memblock, size_t count, size_t size, size_t align, const char * f_name, int line_n ) +{ + return _aligned_offset_recalloc_dbg(memblock, count, size, align, 0, f_name, line_n); +} + +extern "C" void * __cdecl _recalloc_dbg ( void * memblock, size_t count, size_t size, int nBlockUse, const char * szFileName, int nLine ) +{ + return _aligned_offset_recalloc_dbg(memblock, count, size, 0, 0, szFileName, nLine); +} + +_CRT_REPORT_HOOK __cdecl _CrtGetReportHook( void ) +{ + return NULL; +} +#endif // DEBUG + +#endif + +#ifdef DEBUG +int __cdecl _CrtReportBlockType(const void * pUserData) +{ + return 0; +} +#endif + + +} // end extern "C" +#endif // _WIN32 + +// Most files include this file, so when it's used it adds an extra .ValveDbg section, +// to help identify debug binaries. +#ifdef _WIN32 + #ifndef NDEBUG // _DEBUG + #pragma data_seg("ValveDBG") + volatile const char* DBG = "*** DEBUG STUB ***"; + #endif +#endif + +#endif + +// Extras added prevent dbgheap.obj from being included - DAL +#ifdef _WIN32 + +extern "C" +{ +size_t __crtDebugFillThreshold = 0; + +extern "C" void * __cdecl _heap_alloc_base (size_t size) { + assert(0); + return NULL; +} + + +void * __cdecl _heap_alloc_dbg( size_t nSize, int nBlockUse, const char * szFileName, int nLine) +{ + return _heap_alloc(nSize); +} + +// 64-bit +#ifdef _WIN64 +static void * __cdecl realloc_help( void * pUserData, size_t * pnNewSize, int nBlockUse,const char * szFileName, + int nLine, int fRealloc ) +{ + Assert(0); // Shouldn't be needed + return NULL; +} +#else +static void * __cdecl realloc_help( void * pUserData, size_t nNewSize, int nBlockUse, const char * szFileName, + int nLine, int fRealloc) +{ + Assert(0); // Shouldn't be needed + return NULL; +} +#endif + +void __cdecl _free_nolock( void * pUserData) +{ + // I don't think the second param is used in memoverride + _free_dbg(pUserData, 0); +} + +void __cdecl _free_dbg_nolock( void * pUserData, int nBlockUse) +{ + _free_dbg(pUserData, 0); +} + +#ifdef DEBUG +_CRT_ALLOC_HOOK __cdecl _CrtGetAllocHook ( void) +{ + Assert(0); + return NULL; +} +#endif + +static int __cdecl CheckBytes( unsigned char * pb, unsigned char bCheck, size_t nSize) +{ + int bOkay = TRUE; + return bOkay; +} + +#ifdef DEBUG +_CRT_DUMP_CLIENT __cdecl _CrtGetDumpClient ( void) +{ + Assert(0); + return NULL; +} +#endif + +#if _MSC_VER >= 1400 +static void __cdecl _printMemBlockData( _locale_t plocinfo, _CrtMemBlockHeader * pHead) +{ +} + +static void __cdecl _CrtMemDumpAllObjectsSince_stat( const _CrtMemState * state, _locale_t plocinfo) +{ +} +#endif + +#if defined(DEBUG) && _MSC_VER >= 1900 +void * __cdecl _aligned_malloc_dbg( size_t size, size_t align, const char * f_name, int line_n) +{ + return _aligned_malloc(size, align); +} + +void * __cdecl _aligned_realloc_dbg( void *memblock, size_t size, size_t align, + const char * f_name, int line_n) +{ + return _aligned_realloc(memblock, size, align); +} + +void * __cdecl _aligned_offset_malloc_dbg( size_t size, size_t align, size_t offset, + const char * f_name, int line_n) +{ + return _aligned_offset_malloc(size, align, offset); +} + +void * __cdecl _aligned_offset_realloc_dbg( void * memblock, size_t size, size_t align, + size_t offset, const char * f_name, int line_n) +{ + return _aligned_offset_realloc(memblock, size, align, offset); +} + +void __cdecl _aligned_free_dbg( void * memblock) +{ + _aligned_free(memblock); +} +#endif // DEBUG + +#if _MSC_VER < 1900 +size_t __cdecl _CrtSetDebugFillThreshold( size_t _NewDebugFillThreshold) +{ + assert(0); + return 0; +} +#endif + +//=========================================== +// NEW!!! 64-bit +#ifndef PROTECTED_THINGS_DISABLE +char * __cdecl _strdup ( const char * string ) +{ + int nSize = (int)strlen(string) + 1; + // Check for integer underflow. + if ( nSize <= 0 ) + return NULL; + char *pCopy = (char*)AllocUnattributed( nSize ); + if ( pCopy ) + memcpy( pCopy, string, nSize ); + return pCopy; +} +#endif + +#if 0 +_TSCHAR * __cdecl _tfullpath_dbg ( _TSCHAR *UserBuf, const _TSCHAR *path, size_t maxlen, int nBlockUse, const char * szFileName, int nLine ) +{ + Assert(0); + return NULL; +} + +_TSCHAR * __cdecl _tfullpath ( _TSCHAR *UserBuf, const _TSCHAR *path, size_t maxlen ) +{ + Assert(0); + return NULL; +} + +_TSCHAR * __cdecl _tgetdcwd_lk_dbg ( int drive, _TSCHAR *pnbuf, int maxlen, int nBlockUse, const char * szFileName, int nLine ) +{ + Assert(0); + return NULL; +} + +_TSCHAR * __cdecl _tgetdcwd_nolock ( int drive, _TSCHAR *pnbuf, int maxlen ) +{ + Assert(0); + return NULL; +} + +errno_t __cdecl _tdupenv_s_helper ( _TSCHAR **pBuffer, size_t *pBufferSizeInTChars, const _TSCHAR *varname, int nBlockUse, const char * szFileName, int nLine ) +{ + Assert(0); + return 0; +} + +errno_t __cdecl _tdupenv_s_helper ( _TSCHAR **pBuffer, size_t *pBufferSizeInTChars, const _TSCHAR *varname ) +{ + Assert(0); + return 0; +} + +_TSCHAR * __cdecl _ttempnam_dbg ( const _TSCHAR *dir, const _TSCHAR *pfx, int nBlockUse, const char * szFileName, int nLine ) +{ + Assert(0); + return 0; +} + +_TSCHAR * __cdecl _ttempnam ( const _TSCHAR *dir, const _TSCHAR *pfx ) +{ + Assert(0); + return 0; +} + +wchar_t * __cdecl _wcsdup_dbg ( const wchar_t * string, int nBlockUse, const char * szFileName, int nLine ) +{ + Assert(0); + return 0; +} + +wchar_t * __cdecl _wcsdup ( const wchar_t * string ) +{ + Assert(0); + return 0; +} +#endif + +} // end extern "C" + +#if _MSC_VER >= 1400 + +//----------------------------------------------------------------------------- +// XBox Memory Allocator Override +//----------------------------------------------------------------------------- +#if defined( _X360 ) +#if defined( _DEBUG ) || defined( USE_MEM_DEBUG ) +#include "utlmap.h" + +MEMALLOC_DEFINE_EXTERNAL_TRACKING( XMem ); + +CThreadFastMutex g_XMemAllocMutex; + +void XMemAlloc_RegisterAllocation( void *p, DWORD dwAllocAttributes ) +{ + if ( !g_pMemAlloc ) + { + // core xallocs cannot be journaled until system is ready + return; + } + + AUTO_LOCK_FM( g_XMemAllocMutex ); + int size = XMemSize( p, dwAllocAttributes ); + MemAlloc_RegisterExternalAllocation( XMem, p, size ); +} + +void XMemAlloc_RegisterDeallocation( void *p, DWORD dwAllocAttributes ) +{ + if ( !g_pMemAlloc ) + { + // core xallocs cannot be journaled until system is ready + return; + } + + AUTO_LOCK_FM( g_XMemAllocMutex ); + int size = XMemSize( p, dwAllocAttributes ); + MemAlloc_RegisterExternalDeallocation( XMem, p, size ); +} + +#else + +#define XMemAlloc_RegisterAllocation( p, a ) ((void)0) +#define XMemAlloc_RegisterDeallocation( p, a ) ((void)0) + +#endif + +//----------------------------------------------------------------------------- +// XMemAlloc +// +// XBox Memory Allocator Override +//----------------------------------------------------------------------------- +LPVOID WINAPI XMemAlloc( SIZE_T dwSize, DWORD dwAllocAttributes ) +{ + LPVOID ptr; + XALLOC_ATTRIBUTES *pAttribs = (XALLOC_ATTRIBUTES *)&dwAllocAttributes; + bool bPhysical = ( pAttribs->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL ); + + if ( !bPhysical && !pAttribs->dwHeapTracksAttributes && pAttribs->dwAllocatorId != eXALLOCAllocatorId_XUI ) + { + MEM_ALLOC_CREDIT(); + switch ( pAttribs->dwAlignment ) + { + case XALLOC_ALIGNMENT_4: + ptr = g_pMemAlloc->Alloc( dwSize ); + break; + case XALLOC_ALIGNMENT_8: + ptr = MemAlloc_AllocAligned( dwSize, 8 ); + break; + case XALLOC_ALIGNMENT_DEFAULT: + case XALLOC_ALIGNMENT_16: + default: + ptr = MemAlloc_AllocAligned( dwSize, 16 ); + break; + } + if ( pAttribs->dwZeroInitialize != 0 ) + { + memset( ptr, 0, XMemSize( ptr, dwAllocAttributes ) ); + } + return ptr; + } + + ptr = XMemAllocDefault( dwSize, dwAllocAttributes ); + if ( ptr ) + { + XMemAlloc_RegisterAllocation( ptr, dwAllocAttributes ); + } + + return ptr; +} + +//----------------------------------------------------------------------------- +// XMemFree +// +// XBox Memory Allocator Override +//----------------------------------------------------------------------------- +VOID WINAPI XMemFree( PVOID pAddress, DWORD dwAllocAttributes ) +{ + if ( !pAddress ) + { + return; + } + + XALLOC_ATTRIBUTES *pAttribs = (XALLOC_ATTRIBUTES *)&dwAllocAttributes; + bool bPhysical = ( pAttribs->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL ); + + if ( !bPhysical && !pAttribs->dwHeapTracksAttributes && pAttribs->dwAllocatorId != eXALLOCAllocatorId_XUI ) + { + switch ( pAttribs->dwAlignment ) + { + case XALLOC_ALIGNMENT_4: + return g_pMemAlloc->Free( pAddress ); + default: + return MemAlloc_FreeAligned( pAddress ); + } + return; + } + + XMemAlloc_RegisterDeallocation( pAddress, dwAllocAttributes ); + + XMemFreeDefault( pAddress, dwAllocAttributes ); +} + +//----------------------------------------------------------------------------- +// XMemSize +// +// XBox Memory Allocator Override +//----------------------------------------------------------------------------- +SIZE_T WINAPI XMemSize( PVOID pAddress, DWORD dwAllocAttributes ) +{ + XALLOC_ATTRIBUTES *pAttribs = (XALLOC_ATTRIBUTES *)&dwAllocAttributes; + bool bPhysical = ( pAttribs->dwMemoryType == XALLOC_MEMTYPE_PHYSICAL ); + + if ( !bPhysical && !pAttribs->dwHeapTracksAttributes && pAttribs->dwAllocatorId != eXALLOCAllocatorId_XUI ) + { + switch ( pAttribs->dwAlignment ) + { + case XALLOC_ALIGNMENT_4: + return g_pMemAlloc->GetSize( pAddress ); + default: + return MemAlloc_GetSizeAligned( pAddress ); + } + } + + return XMemSizeDefault( pAddress, dwAllocAttributes ); +} +#endif // _X360 + +#define MAX_LANG_LEN 64 /* max language name length */ +#define MAX_CTRY_LEN 64 /* max country name length */ +#define MAX_MODIFIER_LEN 0 /* max modifier name length - n/a */ +#define MAX_LC_LEN (MAX_LANG_LEN+MAX_CTRY_LEN+MAX_MODIFIER_LEN+3) + +#if _MSC_VER >= 1700 // VS 11 +// Copied from C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\mtdll.h +#ifndef _SETLOC_STRUCT_DEFINED +struct _is_ctype_compatible { + unsigned long id; + int is_clike; +}; + +typedef struct setloc_struct { + /* getqloc static variables */ + wchar_t *pchLanguage; + wchar_t *pchCountry; + int iLocState; + int iPrimaryLen; + BOOL bAbbrevLanguage; + BOOL bAbbrevCountry; + UINT _cachecp; + wchar_t _cachein[MAX_LC_LEN]; + wchar_t _cacheout[MAX_LC_LEN]; + /* _setlocale_set_cat (LC_CTYPE) static variable */ + struct _is_ctype_compatible _Loc_c[5]; + wchar_t _cacheLocaleName[LOCALE_NAME_MAX_LENGTH]; +} _setloc_struct, *_psetloc_struct; +#define _SETLOC_STRUCT_DEFINED +#endif /* _SETLOC_STRUCT_DEFINED */ + +_CRTIMP extern unsigned long __cdecl __threadid(void); +#define _threadid (__threadid()) +_CRTIMP extern uintptr_t __cdecl __threadhandle(void); +#define _threadhandle (__threadhandle()) + +/* Structure for each thread's data */ + +#if _MSC_VER >= 1900 +typedef __crt_multibyte_data* pthreadmbcinfo; +typedef __crt_locale_data* pthreadlocinfo; +typedef __crt_locale_pointers _locale_tstruct; +#endif + +struct _tiddata { + unsigned long _tid; /* thread ID */ + + + uintptr_t _thandle; /* thread handle */ + + int _terrno; /* errno value */ + unsigned long _tdoserrno; /* _doserrno value */ + unsigned int _fpds; /* Floating Point data segment */ + unsigned long _holdrand; /* rand() seed value */ + char * _token; /* ptr to strtok() token */ + wchar_t * _wtoken; /* ptr to wcstok() token */ + unsigned char * _mtoken; /* ptr to _mbstok() token */ + + /* following pointers get malloc'd at runtime */ + char * _errmsg; /* ptr to strerror()/_strerror() buff */ + wchar_t * _werrmsg; /* ptr to _wcserror()/__wcserror() buff */ + char * _namebuf0; /* ptr to tmpnam() buffer */ + wchar_t * _wnamebuf0; /* ptr to _wtmpnam() buffer */ + char * _namebuf1; /* ptr to tmpfile() buffer */ + wchar_t * _wnamebuf1; /* ptr to _wtmpfile() buffer */ + char * _asctimebuf; /* ptr to asctime() buffer */ + wchar_t * _wasctimebuf; /* ptr to _wasctime() buffer */ + void * _gmtimebuf; /* ptr to gmtime() structure */ + char * _cvtbuf; /* ptr to ecvt()/fcvt buffer */ + unsigned char _con_ch_buf[MB_LEN_MAX]; + /* ptr to putch() buffer */ + unsigned short _ch_buf_used; /* if the _con_ch_buf is used */ + + /* following fields are needed by _beginthread code */ + void * _initaddr; /* initial user thread address */ + void * _initarg; /* initial user thread argument */ + + /* following three fields are needed to support signal handling and + * runtime errors */ + void * _pxcptacttab; /* ptr to exception-action table */ + void * _tpxcptinfoptrs; /* ptr to exception info pointers */ + int _tfpecode; /* float point exception code */ + + /* pointer to the copy of the multibyte character information used by + * the thread */ + pthreadmbcinfo ptmbcinfo; + + /* pointer to the copy of the locale information used by the thread */ + pthreadlocinfo ptlocinfo; + int _ownlocale; /* if 1, this thread owns its own locale */ + + /* following field is needed by NLG routines */ + unsigned long _NLG_dwCode; + + /* + * Per-Thread data needed by C++ Exception Handling + */ + void * _terminate; /* terminate() routine */ + void * _unexpected; /* unexpected() routine */ + void * _translator; /* S.E. translator */ + void * _purecall; /* called when pure virtual happens */ + void * _curexception; /* current exception */ + void * _curcontext; /* current exception context */ + int _ProcessingThrow; /* for uncaught_exception */ + void * _curexcspec; /* for handling exceptions thrown from std::unexpected */ +#if defined (_M_X64) || defined (_M_ARM) + void * _pExitContext; + void * _pUnwindContext; + void * _pFrameInfoChain; +#if defined (_WIN64) + unsigned __int64 _ImageBase; + unsigned __int64 _ThrowImageBase; +#else /* defined (_WIN64) */ + unsigned __int32 _ImageBase; + unsigned __int32 _ThrowImageBase; +#endif /* defined (_WIN64) */ + void * _pForeignException; +#elif defined (_M_IX86) + void * _pFrameInfoChain; +#endif /* defined (_M_IX86) */ + _setloc_struct _setloc_data; + + void * _reserved1; /* nothing */ + void * _reserved2; /* nothing */ + void * _reserved3; /* nothing */ +#ifdef _M_IX86 + void * _reserved4; /* nothing */ + void * _reserved5; /* nothing */ +#endif /* _M_IX86 */ + + int _cxxReThrow; /* Set to True if it's a rethrown C++ Exception */ + + unsigned long __initDomain; /* initial domain used by _beginthread[ex] for managed function */ +}; +#else +struct _is_ctype_compatible { + unsigned long id; + int is_clike; +}; + +typedef struct setloc_struct { + /* getqloc static variables */ + char *pchLanguage; + char *pchCountry; + int iLcidState; + int iPrimaryLen; + BOOL bAbbrevLanguage; + BOOL bAbbrevCountry; + LCID lcidLanguage; + LCID lcidCountry; + /* expand_locale static variables */ + LC_ID _cacheid; + UINT _cachecp; + char _cachein[MAX_LC_LEN]; + char _cacheout[MAX_LC_LEN]; + /* _setlocale_set_cat (LC_CTYPE) static variable */ + struct _is_ctype_compatible _Lcid_c[5]; +} _setloc_struct, *_psetloc_struct; + +struct _tiddata { + unsigned long _tid; /* thread ID */ + + + uintptr_t _thandle; /* thread handle */ + + int _terrno; /* errno value */ + unsigned long _tdoserrno; /* _doserrno value */ + unsigned int _fpds; /* Floating Point data segment */ + unsigned long _holdrand; /* rand() seed value */ + char * _token; /* ptr to strtok() token */ + wchar_t * _wtoken; /* ptr to wcstok() token */ + unsigned char * _mtoken; /* ptr to _mbstok() token */ + + /* following pointers get malloc'd at runtime */ + char * _errmsg; /* ptr to strerror()/_strerror() buff */ + wchar_t * _werrmsg; /* ptr to _wcserror()/__wcserror() buff */ + char * _namebuf0; /* ptr to tmpnam() buffer */ + wchar_t * _wnamebuf0; /* ptr to _wtmpnam() buffer */ + char * _namebuf1; /* ptr to tmpfile() buffer */ + wchar_t * _wnamebuf1; /* ptr to _wtmpfile() buffer */ + char * _asctimebuf; /* ptr to asctime() buffer */ + wchar_t * _wasctimebuf; /* ptr to _wasctime() buffer */ + void * _gmtimebuf; /* ptr to gmtime() structure */ + char * _cvtbuf; /* ptr to ecvt()/fcvt buffer */ + unsigned char _con_ch_buf[MB_LEN_MAX]; + /* ptr to putch() buffer */ + unsigned short _ch_buf_used; /* if the _con_ch_buf is used */ + + /* following fields are needed by _beginthread code */ + void * _initaddr; /* initial user thread address */ + void * _initarg; /* initial user thread argument */ + + /* following three fields are needed to support signal handling and + * runtime errors */ + void * _pxcptacttab; /* ptr to exception-action table */ + void * _tpxcptinfoptrs; /* ptr to exception info pointers */ + int _tfpecode; /* float point exception code */ + + /* pointer to the copy of the multibyte character information used by + * the thread */ + pthreadmbcinfo ptmbcinfo; + + /* pointer to the copy of the locale information used by the thread */ + pthreadlocinfo ptlocinfo; + int _ownlocale; /* if 1, this thread owns its own locale */ + + /* following field is needed by NLG routines */ + unsigned long _NLG_dwCode; + + /* + * Per-Thread data needed by C++ Exception Handling + */ + void * _terminate; /* terminate() routine */ + void * _unexpected; /* unexpected() routine */ + void * _translator; /* S.E. translator */ + void * _purecall; /* called when pure virtual happens */ + void * _curexception; /* current exception */ + void * _curcontext; /* current exception context */ + int _ProcessingThrow; /* for uncaught_exception */ + void * _curexcspec; /* for handling exceptions thrown from std::unexpected */ +#if defined (_M_IA64) || defined (_M_AMD64) + void * _pExitContext; + void * _pUnwindContext; + void * _pFrameInfoChain; + unsigned __int64 _ImageBase; +#if defined (_M_IA64) + unsigned __int64 _TargetGp; +#endif /* defined (_M_IA64) */ + unsigned __int64 _ThrowImageBase; + void * _pForeignException; +#elif defined (_M_IX86) + void * _pFrameInfoChain; +#endif /* defined (_M_IX86) */ + _setloc_struct _setloc_data; + + void * _encode_ptr; /* EncodePointer() routine */ + void * _decode_ptr; /* DecodePointer() routine */ + + void * _reserved1; /* nothing */ + void * _reserved2; /* nothing */ + void * _reserved3; /* nothing */ + + int _cxxReThrow; /* Set to True if it's a rethrown C++ Exception */ + + unsigned long __initDomain; /* initial domain used by _beginthread[ex] for managed function */ +}; +#endif + +typedef struct _tiddata * _ptiddata; + +class _LocaleUpdate +{ + _locale_tstruct localeinfo; + _ptiddata ptd; + bool updated; + public: + _LocaleUpdate(_locale_t plocinfo) + : updated(false) + { + /* + if (plocinfo == NULL) + { + ptd = _getptd(); + localeinfo.locinfo = ptd->ptlocinfo; + localeinfo.mbcinfo = ptd->ptmbcinfo; + + __UPDATE_LOCALE(ptd, localeinfo.locinfo); + __UPDATE_MBCP(ptd, localeinfo.mbcinfo); + if (!(ptd->_ownlocale & _PER_THREAD_LOCALE_BIT)) + { + ptd->_ownlocale |= _PER_THREAD_LOCALE_BIT; + updated = true; + } + } + else + { + localeinfo=*plocinfo; + } + */ + } + ~_LocaleUpdate() + { +// if (updated) +// ptd->_ownlocale = ptd->_ownlocale & ~_PER_THREAD_LOCALE_BIT; + } + _locale_t GetLocaleT() + { + return &localeinfo; + } +}; + + +#pragma warning(push) +#pragma warning(disable: 4483) +#if _MSC_FULL_VER >= 140050415 +#define _NATIVE_STARTUP_NAMESPACE __identifier("") +#else /* _MSC_FULL_VER >= 140050415 */ +#define _NATIVE_STARTUP_NAMESPACE __CrtImplementationDetails +#endif /* _MSC_FULL_VER >= 140050415 */ + +namespace _NATIVE_STARTUP_NAMESPACE +{ + class NativeDll + { + private: + static const unsigned int ProcessDetach = 0; + static const unsigned int ProcessAttach = 1; + static const unsigned int ThreadAttach = 2; + static const unsigned int ThreadDetach = 3; + static const unsigned int ProcessVerifier = 4; + + public: + + inline static bool IsInDllMain() + { + return false; + } + + inline static bool IsInProcessAttach() + { + return false; + } + + inline static bool IsInProcessDetach() + { + return false; + } + + inline static bool IsInVcclrit() + { + return false; + } + + inline static bool IsSafeForManagedCode() + { + if (!IsInDllMain()) + { + return true; + } + + if (IsInVcclrit()) + { + return true; + } + + return !IsInProcessAttach() && !IsInProcessDetach(); + } + }; +} +#pragma warning(pop) + +#endif // _MSC_VER >= 1400 + +#endif // !STEAM && !NO_MALLOC_OVERRIDE + +#endif // _WIN32 diff --git a/src/public_sp/tier0/threadtools.h b/src/public_sp/tier0/threadtools.h new file mode 100644 index 00000000000..db884ab1e4d --- /dev/null +++ b/src/public_sp/tier0/threadtools.h @@ -0,0 +1,1714 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A collection of utility classes to simplify thread handling, and +// as much as possible contain portability problems. Here avoiding +// including windows.h. +// +//============================================================================= + +#ifndef THREADTOOLS_H +#define THREADTOOLS_H + +#include + +#include "tier0/platform.h" +#include "tier0/dbg.h" +#include "tier0/vcrmode.h" + +#ifdef PLATFORM_WINDOWS_PC +#include +#endif + +#ifdef POSIX +#include +#include +#define WAIT_OBJECT_0 0 +#define WAIT_TIMEOUT 0x00000102 +#define WAIT_FAILED -1 +#define THREAD_PRIORITY_HIGHEST 2 +#endif + +#if defined( _WIN32 ) +#pragma once +#pragma warning(push) +#pragma warning(disable:4251) +#endif + +// #define THREAD_PROFILER 1 + +#ifndef _RETAIL +#define THREAD_MUTEX_TRACING_SUPPORTED +#if defined(_WIN32) && defined(_DEBUG) +#define THREAD_MUTEX_TRACING_ENABLED +#endif +#endif + +#ifdef _WIN32 +typedef void *HANDLE; +#endif + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +const unsigned TT_INFINITE = 0xffffffff; + +#ifndef NO_THREAD_LOCAL + +#ifndef THREAD_LOCAL +#ifdef _WIN32 +#define THREAD_LOCAL __declspec(thread) +#elif POSIX +#define THREAD_LOCAL __thread +#endif +#endif + +#endif // NO_THREAD_LOCAL + +typedef unsigned long ThreadId_t; + +//----------------------------------------------------------------------------- +// +// Simple thread creation. Differs from VCR mode/CreateThread/_beginthreadex +// in that it accepts a standard C function rather than compiler specific one. +// +//----------------------------------------------------------------------------- +FORWARD_DECLARE_HANDLE( ThreadHandle_t ); +typedef unsigned (*ThreadFunc_t)( void *pParam ); + +PLATFORM_OVERLOAD ThreadHandle_t CreateSimpleThread( ThreadFunc_t, void *pParam, ThreadId_t *pID, unsigned stackSize = 0 ); +PLATFORM_INTERFACE ThreadHandle_t CreateSimpleThread( ThreadFunc_t, void *pParam, unsigned stackSize = 0 ); +PLATFORM_INTERFACE bool ReleaseThreadHandle( ThreadHandle_t ); + + +//----------------------------------------------------------------------------- + +PLATFORM_INTERFACE void ThreadSleep(unsigned duration = 0); +PLATFORM_INTERFACE uint ThreadGetCurrentId(); +PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle(); +PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = NULL ); +PLATFORM_INTERFACE bool ThreadSetPriority( ThreadHandle_t hThread, int priority ); +inline bool ThreadSetPriority( int priority ) { return ThreadSetPriority( NULL, priority ); } +PLATFORM_INTERFACE bool ThreadInMainThread(); +PLATFORM_INTERFACE void DeclareCurrentThreadIsMainThread(); + +// NOTE: ThreadedLoadLibraryFunc_t needs to return the sleep time in milliseconds or TT_INFINITE +typedef int (*ThreadedLoadLibraryFunc_t)(); +PLATFORM_INTERFACE void SetThreadedLoadLibraryFunc( ThreadedLoadLibraryFunc_t func ); +PLATFORM_INTERFACE ThreadedLoadLibraryFunc_t GetThreadedLoadLibraryFunc(); + +#if defined( _WIN32 ) && !defined( _WIN64 ) && !defined( _X360 ) +extern "C" unsigned long __declspec(dllimport) __stdcall GetCurrentThreadId(); +#define ThreadGetCurrentId GetCurrentThreadId +#endif + +inline void ThreadPause() +{ +#if defined( PLATFORM_WINDOWS_PC ) + // Intrinsic for __asm pause; from + _mm_pause(); +#elif POSIX + __asm __volatile( "pause" ); +#elif defined( _X360 ) +#else +#error "implement me" +#endif +} + +PLATFORM_INTERFACE bool ThreadJoin( ThreadHandle_t, unsigned timeout = TT_INFINITE ); +// If you're not calling ThreadJoin, you need to call ThreadDetach so pthreads on Linux knows it can +// free the memory for this thread. Otherwise you wind up leaking threads until you run out and +// CreateSimpleThread() will fail. +PLATFORM_INTERFACE void ThreadDetach( ThreadHandle_t ); + +PLATFORM_INTERFACE void ThreadSetDebugName( ThreadId_t id, const char *pszName ); +inline void ThreadSetDebugName( const char *pszName ) { ThreadSetDebugName( (ThreadId_t)-1, pszName ); } + +PLATFORM_INTERFACE void ThreadSetAffinity( ThreadHandle_t hThread, int nAffinityMask ); + +//----------------------------------------------------------------------------- + +enum ThreadWaitResult_t +{ + TW_FAILED = 0xffffffff, // WAIT_FAILED + TW_TIMEOUT = 0x00000102, // WAIT_TIMEOUT +}; + +#ifdef _WIN32 +PLATFORM_INTERFACE int ThreadWaitForObjects( int nEvents, const HANDLE *pHandles, bool bWaitAll = true, unsigned timeout = TT_INFINITE ); +inline int ThreadWaitForObject( HANDLE handle, bool bWaitAll = true, unsigned timeout = TT_INFINITE ) { return ThreadWaitForObjects( 1, &handle, bWaitAll, timeout ); } +#endif + +//----------------------------------------------------------------------------- +// +// Interlock methods. These perform very fast atomic thread +// safe operations. These are especially relevant in a multi-core setting. +// +//----------------------------------------------------------------------------- + +#ifdef _WIN32 +#define NOINLINE +#elif POSIX +#define NOINLINE __attribute__ ((noinline)) +#endif + +// ThreadMemoryBarrier is a fence/barrier sufficient for most uses. It prevents reads +// from moving past reads, and writes moving past writes. It is sufficient for +// read-acquire and write-release barriers. It is not a full barrier and it does +// not prevent reads from moving past writes -- that would require a full __sync() +// on PPC and is significantly more expensive. +#if defined( _X360 ) || defined( _PS3 ) + #define ThreadMemoryBarrier() __lwsync() + +#elif defined(_MSC_VER) + // Prevent compiler reordering across this barrier. This is + // sufficient for most purposes on x86/x64. + + #if _MSC_VER < 1500 + // !KLUDGE! For VC 2005 + // http://connect.microsoft.com/VisualStudio/feedback/details/100051 + #pragma intrinsic(_ReadWriteBarrier) + #endif + #define ThreadMemoryBarrier() _ReadWriteBarrier() +#elif defined(GNUC) + // Prevent compiler reordering across this barrier. This is + // sufficient for most purposes on x86/x64. + // http://preshing.com/20120625/memory-ordering-at-compile-time + #define ThreadMemoryBarrier() asm volatile("" ::: "memory") +#else + #error Every platform needs to define ThreadMemoryBarrier to at least prevent compiler reordering +#endif + +#if defined(_WIN32) && !defined(_X360) + #if ( _MSC_VER >= 1310 ) + #define USE_INTRINSIC_INTERLOCKED + #endif +#endif + +#ifdef USE_INTRINSIC_INTERLOCKED +extern "C" +{ + long __cdecl _InterlockedIncrement(volatile long*); + long __cdecl _InterlockedDecrement(volatile long*); + long __cdecl _InterlockedExchange(volatile long*, long); + long __cdecl _InterlockedExchangeAdd(volatile long*, long); + long __cdecl _InterlockedCompareExchange(volatile long*, long, long); +} + +#pragma intrinsic( _InterlockedCompareExchange ) +#pragma intrinsic( _InterlockedDecrement ) +#pragma intrinsic( _InterlockedExchange ) +#pragma intrinsic( _InterlockedExchangeAdd ) +#pragma intrinsic( _InterlockedIncrement ) + +inline long ThreadInterlockedIncrement( long volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedIncrement( p ); } +inline long ThreadInterlockedDecrement( long volatile *p ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedDecrement( p ); } +inline long ThreadInterlockedExchange( long volatile *p, long value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchange( p, value ); } +inline long ThreadInterlockedExchangeAdd( long volatile *p, long value ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedExchangeAdd( p, value ); } +inline long ThreadInterlockedCompareExchange( long volatile *p, long value, long comperand ) { Assert( (size_t)p % 4 == 0 ); return _InterlockedCompareExchange( p, value, comperand ); } +inline bool ThreadInterlockedAssignIf( long volatile *p, long value, long comperand ) { Assert( (size_t)p % 4 == 0 ); return ( _InterlockedCompareExchange( p, value, comperand ) == comperand ); } +#else +PLATFORM_INTERFACE long ThreadInterlockedIncrement( long volatile * ); +PLATFORM_INTERFACE long ThreadInterlockedDecrement( long volatile * ); +PLATFORM_INTERFACE long ThreadInterlockedExchange( long volatile *, long value ); +PLATFORM_INTERFACE long ThreadInterlockedExchangeAdd( long volatile *, long value ); +PLATFORM_INTERFACE long ThreadInterlockedCompareExchange( long volatile *, long value, long comperand ); +PLATFORM_INTERFACE bool ThreadInterlockedAssignIf( long volatile *, long value, long comperand ); +#endif + +inline unsigned ThreadInterlockedExchangeSubtract( long volatile *p, long value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, -value ); } + +#if defined( USE_INTRINSIC_INTERLOCKED ) && !defined( _WIN64 ) +#define TIPTR() +inline void *ThreadInterlockedExchangePointer( void * volatile *p, void *value ) { return (void *)_InterlockedExchange( reinterpret_cast(p), reinterpret_cast(value) ); } +inline void *ThreadInterlockedCompareExchangePointer( void * volatile *p, void *value, void *comperand ) { return (void *)_InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ); } +inline bool ThreadInterlockedAssignPointerIf( void * volatile *p, void *value, void *comperand ) { return ( _InterlockedCompareExchange( reinterpret_cast(p), reinterpret_cast(value), reinterpret_cast(comperand) ) == reinterpret_cast(comperand) ); } +#else +PLATFORM_INTERFACE void *ThreadInterlockedExchangePointer( void * volatile *, void *value ) NOINLINE; +PLATFORM_INTERFACE void *ThreadInterlockedCompareExchangePointer( void * volatile *, void *value, void *comperand ) NOINLINE; +PLATFORM_INTERFACE bool ThreadInterlockedAssignPointerIf( void * volatile *, void *value, void *comperand ) NOINLINE; +#endif + +inline void const *ThreadInterlockedExchangePointerToConst( void const * volatile *p, void const *value ) { return ThreadInterlockedExchangePointer( const_cast < void * volatile * > ( p ), const_cast < void * > ( value ) ); } +inline void const *ThreadInterlockedCompareExchangePointerToConst( void const * volatile *p, void const *value, void const *comperand ) { return ThreadInterlockedCompareExchangePointer( const_cast < void * volatile * > ( p ), const_cast < void * > ( value ), const_cast < void * > ( comperand ) ); } +inline bool ThreadInterlockedAssignPointerToConstIf( void const * volatile *p, void const *value, void const *comperand ) { return ThreadInterlockedAssignPointerIf( const_cast < void * volatile * > ( p ), const_cast < void * > ( value ), const_cast < void * > ( comperand ) ); } + +#if defined( X64BITS ) +#if defined (_WIN32) +typedef __m128i int128; +inline int128 int128_zero() { return _mm_setzero_si128(); } +#else +typedef __int128_t int128; +#define int128_zero() 0 +#endif + +PLATFORM_INTERFACE bool ThreadInterlockedAssignIf128( volatile int128 *pDest, const int128 &value, const int128 &comperand ) NOINLINE; + +#endif + +PLATFORM_INTERFACE int64 ThreadInterlockedIncrement64( int64 volatile * ) NOINLINE; +PLATFORM_INTERFACE int64 ThreadInterlockedDecrement64( int64 volatile * ) NOINLINE; +PLATFORM_INTERFACE int64 ThreadInterlockedCompareExchange64( int64 volatile *, int64 value, int64 comperand ) NOINLINE; +PLATFORM_INTERFACE int64 ThreadInterlockedExchange64( int64 volatile *, int64 value ) NOINLINE; +PLATFORM_INTERFACE int64 ThreadInterlockedExchangeAdd64( int64 volatile *, int64 value ) NOINLINE; +PLATFORM_INTERFACE bool ThreadInterlockedAssignIf64(volatile int64 *pDest, int64 value, int64 comperand ) NOINLINE; + +inline unsigned ThreadInterlockedExchangeSubtract( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } +inline unsigned ThreadInterlockedIncrement( unsigned volatile *p ) { return ThreadInterlockedIncrement( (long volatile *)p ); } +inline unsigned ThreadInterlockedDecrement( unsigned volatile *p ) { return ThreadInterlockedDecrement( (long volatile *)p ); } +inline unsigned ThreadInterlockedExchange( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchange( (long volatile *)p, value ); } +inline unsigned ThreadInterlockedExchangeAdd( unsigned volatile *p, unsigned value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } +inline unsigned ThreadInterlockedCompareExchange( unsigned volatile *p, unsigned value, unsigned comperand ) { return ThreadInterlockedCompareExchange( (long volatile *)p, value, comperand ); } +inline bool ThreadInterlockedAssignIf( unsigned volatile *p, unsigned value, unsigned comperand ) { return ThreadInterlockedAssignIf( (long volatile *)p, value, comperand ); } + +inline int ThreadInterlockedExchangeSubtract( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } +inline int ThreadInterlockedIncrement( int volatile *p ) { return ThreadInterlockedIncrement( (long volatile *)p ); } +inline int ThreadInterlockedDecrement( int volatile *p ) { return ThreadInterlockedDecrement( (long volatile *)p ); } +inline int ThreadInterlockedExchange( int volatile *p, int value ) { return ThreadInterlockedExchange( (long volatile *)p, value ); } +inline int ThreadInterlockedExchangeAdd( int volatile *p, int value ) { return ThreadInterlockedExchangeAdd( (long volatile *)p, value ); } +inline int ThreadInterlockedCompareExchange( int volatile *p, int value, int comperand ) { return ThreadInterlockedCompareExchange( (long volatile *)p, value, comperand ); } +inline bool ThreadInterlockedAssignIf( int volatile *p, int value, int comperand ) { return ThreadInterlockedAssignIf( (long volatile *)p, value, comperand ); } + +//----------------------------------------------------------------------------- +// Access to VTune thread profiling +//----------------------------------------------------------------------------- +#if defined(_WIN32) && defined(THREAD_PROFILER) +PLATFORM_INTERFACE void ThreadNotifySyncPrepare(void *p); +PLATFORM_INTERFACE void ThreadNotifySyncCancel(void *p); +PLATFORM_INTERFACE void ThreadNotifySyncAcquired(void *p); +PLATFORM_INTERFACE void ThreadNotifySyncReleasing(void *p); +#else +#define ThreadNotifySyncPrepare(p) ((void)0) +#define ThreadNotifySyncCancel(p) ((void)0) +#define ThreadNotifySyncAcquired(p) ((void)0) +#define ThreadNotifySyncReleasing(p) ((void)0) +#endif + +//----------------------------------------------------------------------------- +// Encapsulation of a thread local datum (needed because THREAD_LOCAL doesn't +// work in a DLL loaded with LoadLibrary() +//----------------------------------------------------------------------------- + +#ifndef __AFXTLS_H__ // not compatible with some Windows headers +#ifndef NO_THREAD_LOCAL + +class PLATFORM_CLASS CThreadLocalBase + { +public: + CThreadLocalBase(); + ~CThreadLocalBase(); + + void * Get() const; + void Set(void *); + +private: +#ifdef _WIN32 + uint32 m_index; +#elif POSIX + pthread_key_t m_index; +#endif + }; + + //--------------------------------------------------------- + +#ifndef __AFXTLS_H__ + + template + class CThreadLocal : public CThreadLocalBase + { + public: + CThreadLocal() + { + COMPILE_TIME_ASSERT( sizeof(T) == sizeof(void *) ); + } + + T Get() const + { + return reinterpret_cast( CThreadLocalBase::Get() ); + } + + void Set(T val) + { + CThreadLocalBase::Set( reinterpret_cast(val) ); + } + }; + +#endif + + //--------------------------------------------------------- + +template + class CThreadLocalInt : public CThreadLocal + { + public: + CThreadLocalInt() + { + COMPILE_TIME_ASSERT( sizeof(T) >= sizeof(int) ); + } + + operator const int() const { return (int)this->Get(); } + int operator=( int i ) { this->Set( (intp)i ); return i; } + + int operator++() { T i = this->Get(); this->Set( ++i ); return (int)i; } + int operator++(int) { T i = this->Get(); this->Set( i + 1 ); return (int)i; } + + int operator--() { T i = this->Get(); this->Set( --i ); return (int)i; } + int operator--(int) { T i = this->Get(); this->Set( i - 1 ); return (int)i; } + }; + + + //--------------------------------------------------------- + + template + class CThreadLocalPtr : private CThreadLocalBase + { + public: + CThreadLocalPtr() {} + + operator const void *() const { return (T *)Get(); } + operator void *() { return (T *)Get(); } + + operator const T *() const { return (T *)Get(); } + operator const T *() { return (T *)Get(); } + operator T *() { return (T *)Get(); } + + int operator=( int i ) { AssertMsg( i == 0, "Only NULL allowed on integer assign" ); Set( NULL ); return 0; } + T * operator=( T *p ) { Set( p ); return p; } + + bool operator !() const { return (!Get()); } + bool operator!=( int i ) const { AssertMsg( i == 0, "Only NULL allowed on integer compare" ); return (Get() != NULL); } + bool operator==( int i ) const { AssertMsg( i == 0, "Only NULL allowed on integer compare" ); return (Get() == NULL); } + bool operator==( const void *p ) const { return (Get() == p); } + bool operator!=( const void *p ) const { return (Get() != p); } + bool operator==( const T *p ) const { return operator==((void*)p); } + bool operator!=( const T *p ) const { return operator!=((void*)p); } + + T * operator->() { return (T *)Get(); } + T & operator *() { return *((T *)Get()); } + + const T * operator->() const { return (T *)Get(); } + const T & operator *() const { return *((T *)Get()); } + + const T & operator[]( int i ) const { return *((T *)Get() + i); } + T & operator[]( int i ) { return *((T *)Get() + i); } + + private: + // Disallowed operations + CThreadLocalPtr( T *pFrom ); + CThreadLocalPtr( const CThreadLocalPtr &from ); + T **operator &(); + T * const *operator &() const; + void operator=( const CThreadLocalPtr &from ); + bool operator==( const CThreadLocalPtr &p ) const; + bool operator!=( const CThreadLocalPtr &p ) const; + }; + +#endif // NO_THREAD_LOCAL +#endif // !__AFXTLS_H__ + +//----------------------------------------------------------------------------- +// +// A super-fast thread-safe integer A simple class encapsulating the notion of an +// atomic integer used across threads that uses the built in and faster +// "interlocked" functionality rather than a full-blown mutex. Useful for simple +// things like reference counts, etc. +// +//----------------------------------------------------------------------------- + +template +class CInterlockedIntT +{ +public: + CInterlockedIntT() : m_value( 0 ) { COMPILE_TIME_ASSERT( sizeof(T) == sizeof(long) ); } + CInterlockedIntT( T value ) : m_value( value ) {} + + T GetRaw() const { return m_value; } + + operator T() const { return m_value; } + + bool operator!() const { return ( m_value == 0 ); } + bool operator==( T rhs ) const { return ( m_value == rhs ); } + bool operator!=( T rhs ) const { return ( m_value != rhs ); } + + T operator++() { return (T)ThreadInterlockedIncrement( (long *)&m_value ); } + T operator++(int) { return operator++() - 1; } + + T operator--() { return (T)ThreadInterlockedDecrement( (long *)&m_value ); } + T operator--(int) { return operator--() + 1; } + + bool AssignIf( T conditionValue, T newValue ) { return ThreadInterlockedAssignIf( (long *)&m_value, (long)newValue, (long)conditionValue ); } + + T operator=( T newValue ) { ThreadInterlockedExchange((long *)&m_value, newValue); return m_value; } + + void operator+=( T add ) { ThreadInterlockedExchangeAdd( (long *)&m_value, (long)add ); } + void operator-=( T subtract ) { operator+=( -subtract ); } + void operator*=( T multiplier ) { + T original, result; + do + { + original = m_value; + result = original * multiplier; + } while ( !AssignIf( original, result ) ); + } + void operator/=( T divisor ) { + T original, result; + do + { + original = m_value; + result = original / divisor; + } while ( !AssignIf( original, result ) ); + } + + T operator+( T rhs ) const { return m_value + rhs; } + T operator-( T rhs ) const { return m_value - rhs; } + +private: + volatile T m_value; +}; + +typedef CInterlockedIntT CInterlockedInt; +typedef CInterlockedIntT CInterlockedUInt; + +//----------------------------------------------------------------------------- + +template +class CInterlockedPtr +{ +public: + CInterlockedPtr() : m_value( 0 ) {} + CInterlockedPtr( T *value ) : m_value( value ) {} + + operator T *() const { return m_value; } + + bool operator!() const { return ( m_value == 0 ); } + bool operator==( T *rhs ) const { return ( m_value == rhs ); } + bool operator!=( T *rhs ) const { return ( m_value != rhs ); } + +#ifdef X64BITS + T *operator++() { return ((T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, sizeof(T) )) + 1; } + T *operator++(int) { return (T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, sizeof(T) ); } + + T *operator--() { return ((T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, -sizeof(T) )) - 1; } + T *operator--(int) { return (T *)ThreadInterlockedExchangeAdd64( (int64 *)&m_value, -sizeof(T) ); } + + bool AssignIf( T *conditionValue, T *newValue ) { return ThreadInterlockedAssignPointerToConstIf( (void const **) &m_value, (void const *) newValue, (void const *) conditionValue ); } + + T *operator=( T *newValue ) { ThreadInterlockedExchangePointerToConst( (void const **) &m_value, (void const *) newValue ); return newValue; } + + void operator+=( int add ) { ThreadInterlockedExchangeAdd64( (int64 *)&m_value, add * sizeof(T) ); } +#else + T *operator++() { return ((T *)ThreadInterlockedExchangeAdd( (long *)&m_value, sizeof(T) )) + 1; } + T *operator++(int) { return (T *)ThreadInterlockedExchangeAdd( (long *)&m_value, sizeof(T) ); } + + T *operator--() { return ((T *)ThreadInterlockedExchangeAdd( (long *)&m_value, -sizeof(T) )) - 1; } + T *operator--(int) { return (T *)ThreadInterlockedExchangeAdd( (long *)&m_value, -sizeof(T) ); } + + bool AssignIf( T *conditionValue, T *newValue ) { return ThreadInterlockedAssignPointerToConstIf( (void const **) &m_value, (void const *) newValue, (void const *) conditionValue ); } + + T *operator=( T *newValue ) { ThreadInterlockedExchangePointerToConst( (void const **) &m_value, (void const *) newValue ); return newValue; } + + void operator+=( int add ) { ThreadInterlockedExchangeAdd( (long *)&m_value, add * sizeof(T) ); } +#endif + + void operator-=( int subtract ) { operator+=( -subtract ); } + + T *operator+( int rhs ) const { return m_value + rhs; } + T *operator-( int rhs ) const { return m_value - rhs; } + T *operator+( unsigned rhs ) const { return m_value + rhs; } + T *operator-( unsigned rhs ) const { return m_value - rhs; } + size_t operator-( T *p ) const { return m_value - p; } + size_t operator-( const CInterlockedPtr &p ) const { return m_value - p.m_value; } + +private: + T * volatile m_value; +}; + + +//----------------------------------------------------------------------------- +// +// Platform independent for critical sections management +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThreadMutex +{ +public: + CThreadMutex(); + ~CThreadMutex(); + + //------------------------------------------------------ + // Mutex acquisition/release. Const intentionally defeated. + //------------------------------------------------------ + void Lock(); + void Lock() const { (const_cast(this))->Lock(); } + void Unlock(); + void Unlock() const { (const_cast(this))->Unlock(); } + + bool TryLock(); + bool TryLock() const { return (const_cast(this))->TryLock(); } + + //------------------------------------------------------ + // Use this to make deadlocks easier to track by asserting + // when it is expected that the current thread owns the mutex + //------------------------------------------------------ + bool AssertOwnedByCurrentThread(); + + //------------------------------------------------------ + // Enable tracing to track deadlock problems + //------------------------------------------------------ + void SetTrace( bool ); + +private: + // Disallow copying + CThreadMutex( const CThreadMutex & ); + CThreadMutex &operator=( const CThreadMutex & ); + +#if defined( _WIN32 ) + // Efficient solution to breaking the windows.h dependency, invariant is tested. +#ifdef _WIN64 + #define TT_SIZEOF_CRITICALSECTION 40 +#else +#ifndef _X360 + #define TT_SIZEOF_CRITICALSECTION 24 +#else + #define TT_SIZEOF_CRITICALSECTION 28 +#endif // !_XBOX +#endif // _WIN64 + byte m_CriticalSection[TT_SIZEOF_CRITICALSECTION]; +#elif defined(POSIX) + pthread_mutex_t m_Mutex; + pthread_mutexattr_t m_Attr; +#else +#error +#endif + +#ifdef THREAD_MUTEX_TRACING_SUPPORTED + // Debugging (always here to allow mixed debug/release builds w/o changing size) + uint m_currentOwnerID; + uint16 m_lockCount; + bool m_bTrace; +#endif +}; + +//----------------------------------------------------------------------------- +// +// An alternative mutex that is useful for cases when thread contention is +// rare, but a mutex is required. Instances should be declared volatile. +// Sleep of 0 may not be sufficient to keep high priority threads from starving +// lesser threads. This class is not a suitable replacement for a critical +// section if the resource contention is high. +// +//----------------------------------------------------------------------------- + +#if !defined(THREAD_PROFILER) + +class CThreadFastMutex +{ +public: + CThreadFastMutex() + : m_ownerID( 0 ), + m_depth( 0 ) + { + } + +private: + FORCEINLINE bool TryLockInline( const uint32 threadId ) volatile + { + if ( threadId != m_ownerID && !ThreadInterlockedAssignIf( (volatile long *)&m_ownerID, (long)threadId, 0 ) ) + return false; + + ThreadMemoryBarrier(); + ++m_depth; + return true; + } + + bool TryLock( const uint32 threadId ) volatile + { + return TryLockInline( threadId ); + } + + PLATFORM_CLASS void Lock( const uint32 threadId, unsigned nSpinSleepTime ) volatile; + +public: + bool TryLock() volatile + { +#ifdef _DEBUG + if ( m_depth == INT_MAX ) + DebuggerBreak(); + + if ( m_depth < 0 ) + DebuggerBreak(); +#endif + return TryLockInline( ThreadGetCurrentId() ); + } + +#ifndef _DEBUG + FORCEINLINE +#endif + void Lock( unsigned int nSpinSleepTime = 0 ) volatile + { + const uint32 threadId = ThreadGetCurrentId(); + + if ( !TryLockInline( threadId ) ) + { + ThreadPause(); + Lock( threadId, nSpinSleepTime ); + } +#ifdef _DEBUG + if ( m_ownerID != ThreadGetCurrentId() ) + DebuggerBreak(); + + if ( m_depth == INT_MAX ) + DebuggerBreak(); + + if ( m_depth < 0 ) + DebuggerBreak(); +#endif + } + +#ifndef _DEBUG + FORCEINLINE +#endif + void Unlock() volatile + { +#ifdef _DEBUG + if ( m_ownerID != ThreadGetCurrentId() ) + DebuggerBreak(); + + if ( m_depth <= 0 ) + DebuggerBreak(); +#endif + + --m_depth; + if ( !m_depth ) + { + ThreadMemoryBarrier(); + ThreadInterlockedExchange( &m_ownerID, 0 ); + } + } + +#ifdef WIN32 + bool TryLock() const volatile { return (const_cast(this))->TryLock(); } + void Lock(unsigned nSpinSleepTime = 1 ) const volatile { (const_cast(this))->Lock( nSpinSleepTime ); } + void Unlock() const volatile { (const_cast(this))->Unlock(); } +#endif + // To match regular CThreadMutex: + bool AssertOwnedByCurrentThread() { return true; } + void SetTrace( bool ) {} + + uint32 GetOwnerId() const { return m_ownerID; } + int GetDepth() const { return m_depth; } +private: + volatile uint32 m_ownerID; + int m_depth; +}; + +class ALIGN128 CAlignedThreadFastMutex : public CThreadFastMutex +{ +public: + CAlignedThreadFastMutex() + { + Assert( (size_t)this % 128 == 0 && sizeof(*this) == 128 ); + } + +private: + uint8 pad[128-sizeof(CThreadFastMutex)]; +} ALIGN128_POST; + +#else +typedef CThreadMutex CThreadFastMutex; +#endif + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +class CThreadNullMutex +{ +public: + static void Lock() {} + static void Unlock() {} + + static bool TryLock() { return true; } + static bool AssertOwnedByCurrentThread() { return true; } + static void SetTrace( bool b ) {} + + static uint32 GetOwnerId() { return 0; } + static int GetDepth() { return 0; } +}; + +//----------------------------------------------------------------------------- +// +// A mutex decorator class used to control the use of a mutex, to make it +// less expensive when not multithreading +// +//----------------------------------------------------------------------------- + +template +class CThreadConditionalMutex : public BaseClass +{ +public: + void Lock() { if ( *pCondition ) BaseClass::Lock(); } + void Lock() const { if ( *pCondition ) BaseClass::Lock(); } + void Unlock() { if ( *pCondition ) BaseClass::Unlock(); } + void Unlock() const { if ( *pCondition ) BaseClass::Unlock(); } + + bool TryLock() { if ( *pCondition ) return BaseClass::TryLock(); else return true; } + bool TryLock() const { if ( *pCondition ) return BaseClass::TryLock(); else return true; } + bool AssertOwnedByCurrentThread() { if ( *pCondition ) return BaseClass::AssertOwnedByCurrentThread(); else return true; } + void SetTrace( bool b ) { if ( *pCondition ) BaseClass::SetTrace( b ); } +}; + +//----------------------------------------------------------------------------- +// Mutex decorator that blows up if another thread enters +//----------------------------------------------------------------------------- + +template +class CThreadTerminalMutex : public BaseClass +{ +public: + bool TryLock() { if ( !BaseClass::TryLock() ) { DebuggerBreak(); return false; } return true; } + bool TryLock() const { if ( !BaseClass::TryLock() ) { DebuggerBreak(); return false; } return true; } + void Lock() { if ( !TryLock() ) BaseClass::Lock(); } + void Lock() const { if ( !TryLock() ) BaseClass::Lock(); } + +}; + +//----------------------------------------------------------------------------- +// +// Class to Lock a critical section, and unlock it automatically +// when the lock goes out of scope +// +//----------------------------------------------------------------------------- + +template +class CAutoLockT +{ +public: + FORCEINLINE CAutoLockT( MUTEX_TYPE &lock) + : m_lock(lock) + { + m_lock.Lock(); + } + + FORCEINLINE CAutoLockT(const MUTEX_TYPE &lock) + : m_lock(const_cast(lock)) + { + m_lock.Lock(); + } + + FORCEINLINE ~CAutoLockT() + { + m_lock.Unlock(); + } + + +private: + MUTEX_TYPE &m_lock; + + // Disallow copying + CAutoLockT( const CAutoLockT & ); + CAutoLockT &operator=( const CAutoLockT & ); +}; + +typedef CAutoLockT CAutoLock; + +//--------------------------------------------------------- + +template struct CAutoLockTypeDeducer {}; +template <> struct CAutoLockTypeDeducer { typedef CThreadMutex Type_t; }; +template <> struct CAutoLockTypeDeducer { typedef CThreadNullMutex Type_t; }; +#if !defined(THREAD_PROFILER) +template <> struct CAutoLockTypeDeducer { typedef CThreadFastMutex Type_t; }; +template <> struct CAutoLockTypeDeducer { typedef CAlignedThreadFastMutex Type_t; }; +#endif + +#define AUTO_LOCK_( type, mutex ) \ + CAutoLockT< type > UNIQUE_ID( static_cast( mutex ) ) + +#if defined(GNUC) + +template T strip_cv_quals_for_mutex(T&); +template T strip_cv_quals_for_mutex(const T&); +template T strip_cv_quals_for_mutex(volatile T&); +template T strip_cv_quals_for_mutex(const volatile T&); + +#define AUTO_LOCK( mutex ) \ + AUTO_LOCK_( __typeof__(::strip_cv_quals_for_mutex(mutex)), mutex ) + +#else // GNUC + +#define AUTO_LOCK( mutex ) \ + AUTO_LOCK_( CAutoLockTypeDeducer::Type_t, mutex ) + +#endif + +#define AUTO_LOCK_FM( mutex ) \ + AUTO_LOCK_( CThreadFastMutex, mutex ) + +#define LOCAL_THREAD_LOCK_( tag ) \ + ; \ + static CThreadFastMutex autoMutex_##tag; \ + AUTO_LOCK( autoMutex_##tag ) + +#define LOCAL_THREAD_LOCK() \ + LOCAL_THREAD_LOCK_(_) + +//----------------------------------------------------------------------------- +// +// Base class for event, semaphore and mutex objects. +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThreadSyncObject +{ +public: + ~CThreadSyncObject(); + + //----------------------------------------------------- + // Query if object is useful + //----------------------------------------------------- + bool operator!() const; + + //----------------------------------------------------- + // Access handle + //----------------------------------------------------- +#ifdef _WIN32 + operator HANDLE() { return GetHandle(); } + const HANDLE GetHandle() const { return m_hSyncObject; } +#endif + //----------------------------------------------------- + // Wait for a signal from the object + //----------------------------------------------------- + bool Wait( uint32 dwTimeout = TT_INFINITE ); + +protected: + CThreadSyncObject(); + void AssertUseable(); + +#ifdef _WIN32 + HANDLE m_hSyncObject; + bool m_bCreatedHandle; +#elif defined(POSIX) + pthread_mutex_t m_Mutex; + pthread_cond_t m_Condition; + bool m_bInitalized; + int m_cSet; + bool m_bManualReset; + bool m_bWakeForEvent; +#else +#error "Implement me" +#endif + +private: + CThreadSyncObject( const CThreadSyncObject & ); + CThreadSyncObject &operator=( const CThreadSyncObject & ); +}; + + +//----------------------------------------------------------------------------- +// +// Wrapper for unnamed event objects +// +//----------------------------------------------------------------------------- + +#if defined( _WIN32 ) + +//----------------------------------------------------------------------------- +// +// CThreadSemaphore +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThreadSemaphore : public CThreadSyncObject +{ +public: + CThreadSemaphore(long initialValue, long maxValue); + + //----------------------------------------------------- + // Increases the count of the semaphore object by a specified + // amount. Wait() decreases the count by one on return. + //----------------------------------------------------- + bool Release(long releaseCount = 1, long * pPreviousCount = NULL ); + +private: + CThreadSemaphore(const CThreadSemaphore &); + CThreadSemaphore &operator=(const CThreadSemaphore &); +}; + + +//----------------------------------------------------------------------------- +// +// A mutex suitable for out-of-process, multi-processor usage +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThreadFullMutex : public CThreadSyncObject +{ +public: + CThreadFullMutex( bool bEstablishInitialOwnership = false, const char * pszName = NULL ); + + //----------------------------------------------------- + // Release ownership of the mutex + //----------------------------------------------------- + bool Release(); + + // To match regular CThreadMutex: + void Lock() { Wait(); } + void Lock( unsigned timeout ) { Wait( timeout ); } + void Unlock() { Release(); } + bool AssertOwnedByCurrentThread() { return true; } + void SetTrace( bool ) {} + +private: + CThreadFullMutex( const CThreadFullMutex & ); + CThreadFullMutex &operator=( const CThreadFullMutex & ); +}; +#endif + + +class PLATFORM_CLASS CThreadEvent : public CThreadSyncObject +{ +public: + CThreadEvent( bool fManualReset = false ); +#ifdef WIN32 + CThreadEvent( HANDLE hHandle ); +#endif + //----------------------------------------------------- + // Set the state to signaled + //----------------------------------------------------- + bool Set(); + + //----------------------------------------------------- + // Set the state to nonsignaled + //----------------------------------------------------- + bool Reset(); + + //----------------------------------------------------- + // Check if the event is signaled + //----------------------------------------------------- + bool Check(); + + bool Wait( uint32 dwTimeout = TT_INFINITE ); + +private: + CThreadEvent( const CThreadEvent & ); + CThreadEvent &operator=( const CThreadEvent & ); +}; + +// Hard-wired manual event for use in array declarations +class CThreadManualEvent : public CThreadEvent +{ +public: + CThreadManualEvent() + : CThreadEvent( true ) + { + } +}; + +inline int ThreadWaitForEvents( int nEvents, CThreadEvent * const *pEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE ) +{ +#ifdef POSIX + Assert( nEvents == 1); + if ( pEvents[0]->Wait( timeout ) ) + return WAIT_OBJECT_0; + else + return WAIT_TIMEOUT; +#else + HANDLE handles[64]; + for ( unsigned int i = 0; i < min( (unsigned int)nEvents, ARRAYSIZE(handles) ); i++ ) + handles[i] = pEvents[i]->GetHandle(); + return ThreadWaitForObjects( nEvents, handles, bWaitAll, timeout ); +#endif +} + +//----------------------------------------------------------------------------- +// +// CThreadRWLock +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThreadRWLock +{ +public: + CThreadRWLock(); + + void LockForRead(); + void UnlockRead(); + void LockForWrite(); + void UnlockWrite(); + + void LockForRead() const { const_cast(this)->LockForRead(); } + void UnlockRead() const { const_cast(this)->UnlockRead(); } + void LockForWrite() const { const_cast(this)->LockForWrite(); } + void UnlockWrite() const { const_cast(this)->UnlockWrite(); } + +private: + void WaitForRead(); + +#ifdef WIN32 + CThreadFastMutex m_mutex; +#else + CThreadMutex m_mutex; +#endif + CThreadEvent m_CanWrite; + CThreadEvent m_CanRead; + + int m_nWriters; + int m_nActiveReaders; + int m_nPendingReaders; +}; + +//----------------------------------------------------------------------------- +// +// CThreadSpinRWLock +// +//----------------------------------------------------------------------------- + +class ALIGN8 PLATFORM_CLASS CThreadSpinRWLock +{ +public: + CThreadSpinRWLock() { COMPILE_TIME_ASSERT( sizeof( LockInfo_t ) == sizeof( int64 ) ); Assert( (intp)this % 8 == 0 ); memset( this, 0, sizeof( *this ) ); } + + bool TryLockForWrite(); + bool TryLockForRead(); + + void LockForRead(); + void UnlockRead(); + void LockForWrite(); + void UnlockWrite(); + + bool TryLockForWrite() const { return const_cast(this)->TryLockForWrite(); } + bool TryLockForRead() const { return const_cast(this)->TryLockForRead(); } + void LockForRead() const { const_cast(this)->LockForRead(); } + void UnlockRead() const { const_cast(this)->UnlockRead(); } + void LockForWrite() const { const_cast(this)->LockForWrite(); } + void UnlockWrite() const { const_cast(this)->UnlockWrite(); } + +private: + struct LockInfo_t + { + uint32 m_writerId; + int m_nReaders; + }; + + bool AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand ); + bool TryLockForWrite( const uint32 threadId ); + void SpinLockForWrite( const uint32 threadId ); + + volatile LockInfo_t m_lockInfo; + CInterlockedInt m_nWriters; +} ALIGN8_POST; + +//----------------------------------------------------------------------------- +// +// A thread wrapper similar to a Java thread. +// +//----------------------------------------------------------------------------- + +class PLATFORM_CLASS CThread +{ +public: + CThread(); + virtual ~CThread(); + + //----------------------------------------------------- + + const char *GetName(); + void SetName( const char * ); + + size_t CalcStackDepth( void *pStackVariable ) { return ((byte *)m_pStackBase - (byte *)pStackVariable); } + + //----------------------------------------------------- + // Functions for the other threads + //----------------------------------------------------- + + // Start thread running - error if already running + virtual bool Start( unsigned nBytesStack = 0 ); + + // Returns true if thread has been created and hasn't yet exited + bool IsAlive(); + + // This method causes the current thread to wait until this thread + // is no longer alive. + bool Join( unsigned timeout = TT_INFINITE ); + +#ifdef _WIN32 + // Access the thread handle directly + HANDLE GetThreadHandle(); + uint GetThreadId(); +#elif defined( LINUX ) + uint GetThreadId(); +#endif + + //----------------------------------------------------- + + int GetResult(); + + //----------------------------------------------------- + // Functions for both this, and maybe, and other threads + //----------------------------------------------------- + + // Forcibly, abnormally, but relatively cleanly stop the thread + void Stop( int exitCode = 0 ); + + // Get the priority + int GetPriority() const; + + // Set the priority + bool SetPriority( int ); + + // Request a thread to suspend, this must ONLY be called from the thread itself, not the main thread + // This suspend variant causes the thread in question to suspend at a known point in its execution + // which means you don't risk the global deadlocks/hangs potentially caused by the raw Suspend() call + void SuspendCooperative(); + + // Resume a previously suspended thread from the Cooperative call + void ResumeCooperative(); + + // wait for a thread to execute its SuspendCooperative call + void BWaitForThreadSuspendCooperative(); + +#ifndef LINUX + // forcefully Suspend a thread + unsigned int Suspend(); + + // forcefully Resume a previously suspended thread + unsigned int Resume(); +#endif + + // Force hard-termination of thread. Used for critical failures. + bool Terminate( int exitCode = 0 ); + + //----------------------------------------------------- + // Global methods + //----------------------------------------------------- + + // Get the Thread object that represents the current thread, if any. + // Can return NULL if the current thread was not created using + // CThread + static CThread *GetCurrentCThread(); + + // Offer a context switch. Under Win32, equivalent to Sleep(0) +#ifdef Yield +#undef Yield +#endif + static void Yield(); + + // This method causes the current thread to yield and not to be + // scheduled for further execution until a certain amount of real + // time has elapsed, more or less. + static void Sleep( unsigned duration ); + +protected: + + // Optional pre-run call, with ability to fail-create. Note Init() + // is forced synchronous with Start() + virtual bool Init(); + + // Thread will run this function on startup, must be supplied by + // derived class, performs the intended action of the thread. + virtual int Run() = 0; + + // Called when the thread is about to exit, by the about-to-exit thread. + virtual void OnExit(); + + // Called after OnExit when a thread finishes or is killed. Not virtual because no inherited classes + // override it and we don't want to change the vtable from the published SDK version. + void Cleanup(); + + bool WaitForCreateComplete( CThreadEvent *pEvent ); + + // "Virtual static" facility + typedef unsigned (__stdcall *ThreadProc_t)( void * ); + virtual ThreadProc_t GetThreadProc(); + virtual bool IsThreadRunning(); + + CThreadMutex m_Lock; + +#ifdef WIN32 + const ThreadHandle_t GetThreadID() const { return (ThreadHandle_t)m_hThread; } +#else + const ThreadId_t GetThreadID() const { return (ThreadId_t)m_threadId; } +#endif + +private: + enum Flags + { + SUPPORT_STOP_PROTOCOL = 1 << 0 + }; + + // Thread initially runs this. param is actually 'this'. function + // just gets this and calls ThreadProc + struct ThreadInit_t + { + CThread * pThread; + CThreadEvent *pInitCompleteEvent; + bool * pfInitSuccess; + }; + + static unsigned __stdcall ThreadProc( void * pv ); + + // make copy constructor and assignment operator inaccessible + CThread( const CThread & ); + CThread &operator=( const CThread & ); + +#ifdef _WIN32 + HANDLE m_hThread; + ThreadId_t m_threadId; +#elif defined(POSIX) + pthread_t m_threadId; +#endif + CInterlockedInt m_nSuspendCount; + CThreadEvent m_SuspendEvent; + CThreadEvent m_SuspendEventSignal; + int m_result; + char m_szName[32]; + void * m_pStackBase; + unsigned m_flags; +}; + +//----------------------------------------------------------------------------- +// +// A helper class to let you sleep a thread for memory validation, you need to handle +// m_bSleepForValidate in your ::Run() call and set m_bSleepingForValidate when sleeping +// +//----------------------------------------------------------------------------- +class PLATFORM_CLASS CValidatableThread : public CThread +{ +public: + CValidatableThread() + { + m_bSleepForValidate = false; + m_bSleepingForValidate = false; + } + +#ifdef DBGFLAG_VALIDATE + virtual void SleepForValidate() { m_bSleepForValidate = true; } + bool BSleepingForValidate() { return m_bSleepingForValidate; } + virtual void WakeFromValidate() { m_bSleepForValidate = false; } +#endif +protected: + bool m_bSleepForValidate; + bool m_bSleepingForValidate; +}; + +//----------------------------------------------------------------------------- +// Simple thread class encompasses the notion of a worker thread, handing +// synchronized communication. +//----------------------------------------------------------------------------- + + +// These are internal reserved error results from a call attempt +enum WTCallResult_t +{ + WTCR_FAIL = -1, + WTCR_TIMEOUT = -2, + WTCR_THREAD_GONE = -3, +}; + +class CFunctor; +class PLATFORM_CLASS CWorkerThread : public CThread +{ +public: + CWorkerThread(); + + //----------------------------------------------------- + // + // Inter-thread communication + // + // Calls in either direction take place on the same "channel." + // Seperate functions are specified to make identities obvious + // + //----------------------------------------------------- + + // Master: Signal the thread, and block for a response + int CallWorker( unsigned, unsigned timeout = TT_INFINITE, bool fBoostWorkerPriorityToMaster = true, CFunctor *pParamFunctor = NULL ); + + // Worker: Signal the thread, and block for a response + int CallMaster( unsigned, unsigned timeout = TT_INFINITE ); + + // Wait for the next request + bool WaitForCall( unsigned dwTimeout, unsigned *pResult = NULL ); + bool WaitForCall( unsigned *pResult = NULL ); + + // Is there a request? + bool PeekCall( unsigned *pParam = NULL, CFunctor **ppParamFunctor = NULL ); + + // Reply to the request + void Reply( unsigned ); + + // Wait for a reply in the case when CallWorker() with timeout != TT_INFINITE + int WaitForReply( unsigned timeout = TT_INFINITE ); + + // If you want to do WaitForMultipleObjects you'll need to include + // this handle in your wait list or you won't be responsive + CThreadEvent &GetCallHandle(); + // Find out what the request was + unsigned GetCallParam( CFunctor **ppParamFunctor = NULL ) const; + + // Boost the worker thread to the master thread, if worker thread is lesser, return old priority + int BoostPriority(); + +protected: +#ifndef _WIN32 +#define __stdcall +#endif + typedef uint32 (__stdcall *WaitFunc_t)( int nEvents, CThreadEvent * const *pEvents, int bWaitAll, uint32 timeout ); + + int Call( unsigned, unsigned timeout, bool fBoost, WaitFunc_t = NULL, CFunctor *pParamFunctor = NULL ); + int WaitForReply( unsigned timeout, WaitFunc_t ); + +private: + CWorkerThread( const CWorkerThread & ); + CWorkerThread &operator=( const CWorkerThread & ); + + CThreadEvent m_EventSend; + CThreadEvent m_EventComplete; + + unsigned m_Param; + CFunctor *m_pParamFunctor; + int m_ReturnVal; +}; + + +// a unidirectional message queue. A queue of type T. Not especially high speed since each message +// is malloced/freed. Note that if your message class has destructors/constructors, they MUST be +// thread safe! +template class CMessageQueue +{ + CThreadEvent SignalEvent; // signals presence of data + CThreadMutex QueueAccessMutex; + + // the parts protected by the mutex + struct MsgNode + { + MsgNode *Next; + T Data; + }; + + MsgNode *Head; + MsgNode *Tail; + +public: + CMessageQueue( void ) + { + Head = Tail = NULL; + } + + // check for a message. not 100% reliable - someone could grab the message first + bool MessageWaiting( void ) + { + return ( Head != NULL ); + } + + void WaitMessage( T *pMsg ) + { + for(;;) + { + while( ! MessageWaiting() ) + SignalEvent.Wait(); + QueueAccessMutex.Lock(); + if (! Head ) + { + // multiple readers could make this null + QueueAccessMutex.Unlock(); + continue; + } + *( pMsg ) = Head->Data; + MsgNode *remove_this = Head; + Head = Head->Next; + if (! Head) // if empty, fix tail ptr + Tail = NULL; + QueueAccessMutex.Unlock(); + delete remove_this; + break; + } + } + + void QueueMessage( T const &Msg) + { + MsgNode *new1=new MsgNode; + new1->Data=Msg; + new1->Next=NULL; + QueueAccessMutex.Lock(); + if ( Tail ) + { + Tail->Next=new1; + Tail = new1; + } + else + { + Head = new1; + Tail = new1; + } + SignalEvent.Set(); + QueueAccessMutex.Unlock(); + } +}; + + +//----------------------------------------------------------------------------- +// +// CThreadMutex. Inlining to reduce overhead and to allow client code +// to decide debug status (tracing) +// +//----------------------------------------------------------------------------- + +#ifdef _WIN32 +typedef struct _RTL_CRITICAL_SECTION RTL_CRITICAL_SECTION; +typedef RTL_CRITICAL_SECTION CRITICAL_SECTION; + +#ifndef _X360 +extern "C" +{ + void __declspec(dllimport) __stdcall InitializeCriticalSection(CRITICAL_SECTION *); + void __declspec(dllimport) __stdcall EnterCriticalSection(CRITICAL_SECTION *); + void __declspec(dllimport) __stdcall LeaveCriticalSection(CRITICAL_SECTION *); + void __declspec(dllimport) __stdcall DeleteCriticalSection(CRITICAL_SECTION *); +}; +#endif + +//--------------------------------------------------------- + +inline void CThreadMutex::Lock() +{ +#ifdef THREAD_MUTEX_TRACING_ENABLED + uint thisThreadID = ThreadGetCurrentId(); + if ( m_bTrace && m_currentOwnerID && ( m_currentOwnerID != thisThreadID ) ) + Msg( "Thread %u about to wait for lock %p owned by %u\n", ThreadGetCurrentId(), (CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID ); + #endif + + VCRHook_EnterCriticalSection((CRITICAL_SECTION *)&m_CriticalSection); + + #ifdef THREAD_MUTEX_TRACING_ENABLED + if (m_lockCount == 0) + { + // we now own it for the first time. Set owner information + m_currentOwnerID = thisThreadID; + if ( m_bTrace ) + Msg( "Thread %u now owns lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection ); + } + m_lockCount++; + #endif +} + +//--------------------------------------------------------- + +inline void CThreadMutex::Unlock() +{ + #ifdef THREAD_MUTEX_TRACING_ENABLED + AssertMsg( m_lockCount >= 1, "Invalid unlock of thread lock" ); + m_lockCount--; + if (m_lockCount == 0) + { + if ( m_bTrace ) + Msg( "Thread %u releasing lock %p\n", m_currentOwnerID, (CRITICAL_SECTION *)&m_CriticalSection ); + m_currentOwnerID = 0; + } + #endif + LeaveCriticalSection((CRITICAL_SECTION *)&m_CriticalSection); +} + +//--------------------------------------------------------- + +inline bool CThreadMutex::AssertOwnedByCurrentThread() +{ +#ifdef THREAD_MUTEX_TRACING_ENABLED + if (ThreadGetCurrentId() == m_currentOwnerID) + return true; + AssertMsg3( 0, "Expected thread %u as owner of lock %p, but %u owns", ThreadGetCurrentId(), (CRITICAL_SECTION *)&m_CriticalSection, m_currentOwnerID ); + return false; +#else + return true; +#endif +} + +//--------------------------------------------------------- + +inline void CThreadMutex::SetTrace( bool bTrace ) +{ +#ifdef THREAD_MUTEX_TRACING_ENABLED + m_bTrace = bTrace; +#endif +} + +//--------------------------------------------------------- + +#elif defined(POSIX) + +inline CThreadMutex::CThreadMutex() +{ + // enable recursive locks as we need them + pthread_mutexattr_init( &m_Attr ); + pthread_mutexattr_settype( &m_Attr, PTHREAD_MUTEX_RECURSIVE ); + pthread_mutex_init( &m_Mutex, &m_Attr ); +} + +//--------------------------------------------------------- + +inline CThreadMutex::~CThreadMutex() +{ + pthread_mutex_destroy( &m_Mutex ); +} + +//--------------------------------------------------------- + +inline void CThreadMutex::Lock() +{ + pthread_mutex_lock( &m_Mutex ); +} + +//--------------------------------------------------------- + +inline void CThreadMutex::Unlock() +{ + pthread_mutex_unlock( &m_Mutex ); +} + +//--------------------------------------------------------- + +inline bool CThreadMutex::AssertOwnedByCurrentThread() +{ + return true; +} + +//--------------------------------------------------------- + +inline void CThreadMutex::SetTrace(bool fTrace) +{ +} + +#endif // POSIX + +//----------------------------------------------------------------------------- +// +// CThreadRWLock inline functions +// +//----------------------------------------------------------------------------- + +inline CThreadRWLock::CThreadRWLock() +: m_CanRead( true ), + m_nWriters( 0 ), + m_nActiveReaders( 0 ), + m_nPendingReaders( 0 ) +{ +} + +inline void CThreadRWLock::LockForRead() +{ + m_mutex.Lock(); + if ( m_nWriters) + { + WaitForRead(); + } + m_nActiveReaders++; + m_mutex.Unlock(); +} + +inline void CThreadRWLock::UnlockRead() +{ + m_mutex.Lock(); + m_nActiveReaders--; + if ( m_nActiveReaders == 0 && m_nWriters != 0 ) + { + m_CanWrite.Set(); + } + m_mutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// +// CThreadSpinRWLock inline functions +// +//----------------------------------------------------------------------------- + +inline bool CThreadSpinRWLock::AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand ) +{ + return ThreadInterlockedAssignIf64( (int64 *)&m_lockInfo, *((int64 *)&newValue), *((int64 *)&comperand) ); +} + +inline bool CThreadSpinRWLock::TryLockForWrite( const uint32 threadId ) +{ + // In order to grab a write lock, there can be no readers and no owners of the write lock + if ( m_lockInfo.m_nReaders > 0 || ( m_lockInfo.m_writerId && m_lockInfo.m_writerId != threadId ) ) + { + return false; + } + + static const LockInfo_t oldValue = { 0, 0 }; + LockInfo_t newValue = { threadId, 0 }; + const bool bSuccess = AssignIf( newValue, oldValue ); +#if defined(_X360) + if ( bSuccess ) + { + // X360TBD: Serious perf implications. Not Yet. __sync(); + } +#endif + return bSuccess; +} + +inline bool CThreadSpinRWLock::TryLockForWrite() +{ + m_nWriters++; + if ( !TryLockForWrite( ThreadGetCurrentId() ) ) + { + m_nWriters--; + return false; + } + return true; +} + +inline bool CThreadSpinRWLock::TryLockForRead() +{ + if ( m_nWriters != 0 ) + { + return false; + } + // In order to grab a write lock, the number of readers must not change and no thread can own the write + LockInfo_t oldValue; + LockInfo_t newValue; + + oldValue.m_nReaders = m_lockInfo.m_nReaders; + oldValue.m_writerId = 0; + newValue.m_nReaders = oldValue.m_nReaders + 1; + newValue.m_writerId = 0; + + const bool bSuccess = AssignIf( newValue, oldValue ); +#if defined(_X360) + if ( bSuccess ) + { + // X360TBD: Serious perf implications. Not Yet. __sync(); + } +#endif + return bSuccess; +} + +inline void CThreadSpinRWLock::LockForWrite() +{ + const uint32 threadId = ThreadGetCurrentId(); + + m_nWriters++; + + if ( !TryLockForWrite( threadId ) ) + { + ThreadPause(); + SpinLockForWrite( threadId ); + } +} + +// read data from a memory address +template FORCEINLINE T ReadVolatileMemory( T const *pPtr ) +{ + volatile const T * pVolatilePtr = ( volatile const T * ) pPtr; + return *pVolatilePtr; +} + +//----------------------------------------------------------------------------- + +#if defined( _WIN32 ) +#pragma warning(pop) +#endif + +#endif // THREADTOOLS_H diff --git a/src/public_sp/tier1/utlstring.h b/src/public_sp/tier1/utlstring.h new file mode 100644 index 00000000000..833fd642413 --- /dev/null +++ b/src/public_sp/tier1/utlstring.h @@ -0,0 +1,319 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef UTLSTRING_H +#define UTLSTRING_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "tier1/utlbinaryblock.h" + +#if defined( OSX ) +#define wcsdup wcsdup_osx +inline wchar_t *wcsdup_osx(const wchar_t *pString) +{ + wchar_t *pMemory; + + if (!pString) + return NULL; + + size_t len = (wcslen(pString) + 1); + if ((pMemory = (wchar_t *)malloc(len * sizeof(wchar_t))) != NULL) + { + return wcscpy( pMemory, pString ); + } + + return NULL; +} +#endif + + +//----------------------------------------------------------------------------- +// Simple string class. +// NOTE: This is *not* optimal! Use in tools, but not runtime code +//----------------------------------------------------------------------------- +class CUtlString +{ +public: + typedef enum + { + PATTERN_NONE = 0x00000000, + PATTERN_DIRECTORY = 0x00000001 + } TUtlStringPattern; + +public: + CUtlString(); + CUtlString( const char *pString ); + CUtlString( const CUtlString& string ); + + // Attaches the string to external memory. Useful for avoiding a copy + CUtlString( void* pMemory, int nSizeInBytes, int nInitialLength ); + CUtlString( const void* pMemory, int nSizeInBytes ); + + const char *Get( ) const; + void Set( const char *pValue ); + + void Clear() { Set( NULL ); } + + // Converts to c-strings + operator const char*() const; + + // for compatibility switching items from UtlSymbol + const char *String() const { return Get(); } + + // Returns strlen + int Length() const; + bool IsEmpty() const; + + // Sets the length (used to serialize into the buffer ) + // Note: If nLen != 0, then this adds an extra byte for a null-terminator. + void SetLength( int nLen ); + char *Get(); +#ifdef SDK_SP + FORCEINLINE char *GetForModify() { return Get(); } +#endif + void Purge(); + + // Case Change + void ToLower(); + void ToUpper(); + + void Append( const char *pchAddition ); + + // Strips the trailing slash + void StripTrailingSlash(); + + CUtlString &operator=( const CUtlString &src ); + CUtlString &operator=( const char *src ); + + // Test for equality + bool operator==( const CUtlString &src ) const; + bool operator==( const char *src ) const; + bool operator!=( const CUtlString &src ) const { return !operator==( src ); } + bool operator!=( const char *src ) const { return !operator==( src ); } + + // If these are not defined, CUtlString as rhs will auto-convert + // to const char* and do logical operations on the raw pointers. Ugh. + inline friend bool operator==( const char *lhs, const CUtlString &rhs ) { return rhs.operator==( lhs ); } + inline friend bool operator!=( const char *lhs, const CUtlString &rhs ) { return rhs.operator!=( lhs ); } + + CUtlString &operator+=( const CUtlString &rhs ); + CUtlString &operator+=( const char *rhs ); + CUtlString &operator+=( char c ); + CUtlString &operator+=( int rhs ); + CUtlString &operator+=( double rhs ); + + // is valid? + bool IsValid() const; + + bool MatchesPattern( const CUtlString &Pattern, int nFlags = 0 ); // case SENSITIVE, use * for wildcard in pattern string + + int Format( PRINTF_FORMAT_STRING const char *pFormat, ... ); + void SetDirect( const char *pValue, int nChars ); + + // Defining AltArgumentType_t hints that associative container classes should + // also implement Find/Insert/Remove functions that take const char* params. + typedef const char *AltArgumentType_t; + + // Take a piece out of the string. + // If you only specify nStart, it'll go from nStart to the end. + // You can use negative numbers and it'll wrap around to the start. + CUtlString Slice( int32 nStart=0, int32 nEnd=INT_MAX ); + + // Grab a substring starting from the left or the right side. + CUtlString Left( int32 nChars ); + CUtlString Right( int32 nChars ); + + // Replace all instances of one character with another. + CUtlString Replace( char cFrom, char cTo ); + + // Calls right through to V_MakeAbsolutePath. + CUtlString AbsPath( const char *pStartingDir=NULL ); + + // Gets the filename (everything except the path.. c:\a\b\c\somefile.txt -> somefile.txt). + CUtlString UnqualifiedFilename(); + + // Strips off one directory. Uses V_StripLastDir but strips the last slash also! + CUtlString DirName(); + + // Works like V_ComposeFileName. + static CUtlString PathJoin( const char *pStr1, const char *pStr2 ); + + // These can be used for utlvector sorts. + static int __cdecl SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 ); + static int __cdecl SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 ); + +private: + CUtlBinaryBlock m_Storage; +}; + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline bool CUtlString::IsEmpty() const +{ + return Length() == 0; +} + +inline bool CUtlString::IsValid() const +{ + return ( String() != NULL ); +} + +inline int __cdecl CUtlString::SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 ) +{ + return V_stricmp( pString1->String(), pString2->String() ); +} + +inline int __cdecl CUtlString::SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 ) +{ + return V_strcmp( pString1->String(), pString2->String() ); +} + +//----------------------------------------------------------------------------- +// Purpose: Implementation of low-level string functionality for character types. +//----------------------------------------------------------------------------- + +template < typename T > +class StringFuncs +{ +public: + static T *Duplicate( const T *pValue ); + // Note that this function takes a character count, and does not guarantee null-termination. + static void Copy( T *out_pOut, const T *pIn, int iLengthInChars ); + static int Compare( const T *pLhs, const T *pRhs ); + static int CaselessCompare( const T *pLhs, const T *pRhs ); + static int Length( const T *pValue ); + static const T *FindChar( const T *pStr, const T cSearch ); + static const T *EmptyString(); + static const T *NullDebugString(); +}; + +template < > +class StringFuncs +{ +public: + static char *Duplicate( const char *pValue ) { return strdup( pValue ); } + // Note that this function takes a character count, and does not guarantee null-termination. + static void Copy( OUT_CAP(iLengthInChars) char *out_pOut, const char *pIn, int iLengthInChars ) { strncpy( out_pOut, pIn, iLengthInChars ); } + static int Compare( const char *pLhs, const char *pRhs ) { return strcmp( pLhs, pRhs ); } + static int CaselessCompare( const char *pLhs, const char *pRhs ) { return Q_strcasecmp( pLhs, pRhs ); } + static int Length( const char *pValue ) { return (int)strlen( pValue ); } + static const char *FindChar( const char *pStr, const char cSearch ) { return strchr( pStr, cSearch ); } + static const char *EmptyString() { return ""; } + static const char *NullDebugString() { return "(null)"; } +}; + +template < > +class StringFuncs +{ +public: + static wchar_t *Duplicate( const wchar_t *pValue ) { return wcsdup( pValue ); } + // Note that this function takes a character count, and does not guarantee null-termination. + static void Copy( OUT_CAP(iLengthInChars) wchar_t *out_pOut, const wchar_t *pIn, int iLengthInChars ) { wcsncpy( out_pOut, pIn, iLengthInChars ); } + static int Compare( const wchar_t *pLhs, const wchar_t *pRhs ) { return wcscmp( pLhs, pRhs ); } + static int CaselessCompare( const wchar_t *pLhs, const wchar_t *pRhs ); // no implementation? + static int Length( const wchar_t *pValue ) { return (int)wcslen( pValue ); } + static const wchar_t *FindChar( const wchar_t *pStr, const wchar_t cSearch ) { return wcschr( pStr, cSearch ); } + static const wchar_t *EmptyString() { return L""; } + static const wchar_t *NullDebugString() { return L"(null)"; } +}; + +//----------------------------------------------------------------------------- +// Dirt-basic auto-release string class. Not intended for manipulation, +// can be stored in a container or forwarded as a functor parameter. +// Note the benefit over CUtlString: sizeof(CUtlConstString) == sizeof(char*). +// Also note: null char* pointers are treated identically to empty strings. +//----------------------------------------------------------------------------- + +template < typename T = char > +class CUtlConstStringBase +{ +public: + CUtlConstStringBase() : m_pString( NULL ) {} + explicit CUtlConstStringBase( const T *pString ) : m_pString( NULL ) { Set( pString ); } + CUtlConstStringBase( const CUtlConstStringBase& src ) : m_pString( NULL ) { Set( src.m_pString ); } + ~CUtlConstStringBase() { Set( NULL ); } + + void Set( const T *pValue ); + void Clear() { Set( NULL ); } + + const T *Get() const { return m_pString ? m_pString : StringFuncs::EmptyString(); } + operator const T*() const { return m_pString ? m_pString : StringFuncs::EmptyString(); } + + bool IsEmpty() const { return m_pString == NULL; } // Note: empty strings are never stored by Set + + int Compare( const T *rhs ) const; + + // Logical ops + bool operator<( const T *rhs ) const { return Compare( rhs ) < 0; } + bool operator==( const T *rhs ) const { return Compare( rhs ) == 0; } + bool operator!=( const T *rhs ) const { return Compare( rhs ) != 0; } + bool operator<( const CUtlConstStringBase &rhs ) const { return Compare( rhs.m_pString ) < 0; } + bool operator==( const CUtlConstStringBase &rhs ) const { return Compare( rhs.m_pString ) == 0; } + bool operator!=( const CUtlConstStringBase &rhs ) const { return Compare( rhs.m_pString ) != 0; } + + // If these are not defined, CUtlConstString as rhs will auto-convert + // to const char* and do logical operations on the raw pointers. Ugh. + inline friend bool operator<( const T *lhs, const CUtlConstStringBase &rhs ) { return rhs.Compare( lhs ) > 0; } + inline friend bool operator==( const T *lhs, const CUtlConstStringBase &rhs ) { return rhs.Compare( lhs ) == 0; } + inline friend bool operator!=( const T *lhs, const CUtlConstStringBase &rhs ) { return rhs.Compare( lhs ) != 0; } + + CUtlConstStringBase &operator=( const T *src ) { Set( src ); return *this; } + CUtlConstStringBase &operator=( const CUtlConstStringBase &src ) { Set( src.m_pString ); return *this; } + + // Defining AltArgumentType_t is a hint to containers that they should + // implement Find/Insert/Remove functions that take const char* params. + typedef const T *AltArgumentType_t; + +protected: + const T *m_pString; +}; + +template < typename T > +void CUtlConstStringBase::Set( const T *pValue ) +{ + if ( pValue != m_pString ) + { + free( ( void* ) m_pString ); + m_pString = pValue && pValue[0] ? StringFuncs::Duplicate( pValue ) : NULL; + } +} + +template < typename T > +int CUtlConstStringBase::Compare( const T *rhs ) const +{ + // Empty or null RHS? + if ( !rhs || !rhs[0] ) + return m_pString ? 1 : 0; + + // Empty *this, non-empty RHS? + if ( !m_pString ) + return -1; + + // Neither empty + return StringFuncs::Compare( m_pString, rhs ); +} + +typedef CUtlConstStringBase CUtlConstString; +typedef CUtlConstStringBase CUtlConstWideString; + +//----------------------------------------------------------------------------- +// Helper functor objects. +//----------------------------------------------------------------------------- + +template < typename T > struct UTLConstStringCaselessStringLessFunctor { bool operator()( const CUtlConstStringBase& a, const char *b ) const { return StringFuncs::CaselessCompare( a.Get(), b ) < 0; } }; +template < typename T > struct UTLConstStringCaselessStringEqualFunctor { bool operator()( const CUtlConstStringBase& a, const char *b ) const { return StringFuncs::CaselessCompare( a.Get(), b ) == 0; } }; + +#ifdef SDK_SP +// Helper function for CUtlMaps with a CUtlString key +inline bool UtlStringLessFunc( const CUtlString &lhs, const CUtlString &rhs ) { return V_strcmp( lhs.Get(), rhs.Get() ) < 0; } +inline bool UtlStringCaseInsensitiveLessFunc( const CUtlString &lhs, const CUtlString &rhs ) { return V_stricmp( lhs.Get(), rhs.Get() ) < 0; } +#endif + +#endif // UTLSTRING_H diff --git a/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/libprotobuf.lib b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/libprotobuf.lib new file mode 100644 index 00000000000..8e43e70063e Binary files /dev/null and b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/libprotobuf.lib differ diff --git a/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/protoc.exe b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/protoc.exe new file mode 100644 index 00000000000..29aaada8631 Binary files /dev/null and b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/debug/protoc.exe differ diff --git a/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/libprotobuf.lib b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/libprotobuf.lib new file mode 100644 index 00000000000..0d2ee726f99 Binary files /dev/null and b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/libprotobuf.lib differ diff --git a/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/protoc.exe b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/protoc.exe new file mode 100644 index 00000000000..bd2feed55b8 Binary files /dev/null and b/src/thirdparty/protobuf-2.6.1/bin/win32/2015/staticcrt/release/protoc.exe differ diff --git a/src/tier0/tier0_exclude.vpc b/src/tier0/tier0_exclude.vpc index 15dce799f77..25a727b8362 100644 --- a/src/tier0/tier0_exclude.vpc +++ b/src/tier0/tier0_exclude.vpc @@ -13,6 +13,8 @@ $Project } $Folder "Source Files" { - -$File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + -$File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + -$File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] } } diff --git a/src/tier1/KeyValues.cpp b/src/tier1/KeyValues.cpp index 1e4fca43508..a786aba0955 100644 --- a/src/tier1/KeyValues.cpp +++ b/src/tier1/KeyValues.cpp @@ -656,6 +656,7 @@ bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceN Assert( IsX360() || ( IsPC() && _heapchk() == _HEAPOK ) ); #endif +#ifdef SDK_MP /* People are cheating with the keyvalue cache enabled by doing the below, so disable it. @@ -693,6 +694,7 @@ bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceN COM_TimestampedLog( "KeyValues::LoadFromFile(%s%s%s): End / CacheHit", pathID ? pathID : "", pathID && resourceName ? "/" : "", resourceName ? resourceName : "" ); return true; } +#endif FileHandle_t f = filesystem->Open(resourceName, "rb", pathID); if ( !f ) @@ -721,13 +723,15 @@ bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceN buffer[fileSize+1] = 0; // double NULL terminating in case this is a unicode file bRetOK = LoadFromBuffer( resourceName, buffer, filesystem ); } - + +#ifdef SDK_MP // The cache relies on the KeyValuesSystem string table, which will only be valid if we're // using classic mode. if ( bUseCacheForWrite && bRetOK ) { KeyValuesSystem()->AddFileKeyValuesToCache( this, resourceName, pathID ); } +#endif ( (IFileSystem *)filesystem )->FreeOptimalReadBuffer( buffer ); @@ -752,10 +756,12 @@ bool KeyValues::SaveToFile( IBaseFileSystem *filesystem, const char *resourceNam return false; } +#ifdef SDK_MP KeyValuesSystem()->InvalidateCacheForFile( resourceName, pathID ); if ( bCacheResult ) { KeyValuesSystem()->AddFileKeyValuesToCache( this, resourceName, pathID ); } +#endif RecursiveSaveToFile(filesystem, f, NULL, 0, sortKeys, bAllowEmptyString ); filesystem->Close(f); diff --git a/src/tier1/convar.cpp b/src/tier1/convar.cpp index d2a09b15e18..81f3cd52e1d 100644 --- a/src/tier1/convar.cpp +++ b/src/tier1/convar.cpp @@ -673,18 +673,28 @@ ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags, const c ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, FnChangeCallback_t callback ) { +#ifdef SDK_MP Create( pName, pDefaultValue, flags, pHelpString, false, 0.0, false, 0.0, false, 0.0, false, 0.0, callback ); +#else + Create( pName, pDefaultValue, flags, pHelpString, false, 0.0, false, 0.0, callback ); +#endif } ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, FnChangeCallback_t callback ) { +#ifdef SDK_MP Create( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax, false, 0.0, false, 0.0, callback ); +#else + Create( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax, callback ); +#endif } +#ifdef SDK_MP ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags, const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, bool bCompMin, float fCompMin, bool bCompMax, float fCompMax, FnChangeCallback_t callback ) { Create( pName, pDefaultValue, flags, pHelpString, bMin, fMin, bMax, fMax, bCompMin, fCompMin, bCompMax, fCompMax, callback ); } +#endif //----------------------------------------------------------------------------- @@ -865,6 +875,7 @@ void ConVar::ChangeStringValue( const char *tempVal, float flOldValue ) //----------------------------------------------------------------------------- bool ConVar::ClampValue( float& value ) { +#ifdef SDK_MP // Competitive /should/ be more restrictive, so do it first. if ( m_bCompetitiveRestrictions ) { @@ -890,6 +901,7 @@ bool ConVar::ClampValue( float& value ) } } } +#endif if ( m_bHasMin && ( value < m_fMinVal ) ) { @@ -906,19 +918,28 @@ bool ConVar::ClampValue( float& value ) return false; } +#ifdef SDK_MP void ConVar::InternalSetFloatValue( float fNewValue ) { InternalSetFloatValue2( fNewValue ); } +#endif //----------------------------------------------------------------------------- // Purpose: // Input : *value - //----------------------------------------------------------------------------- +#ifdef SDK_MP void ConVar::InternalSetFloatValue2( float fNewValue, bool bForce /*= false */ ) { if ( fNewValue == m_fValue && !bForce ) return; +#else +void ConVar::InternalSetFloatValue( float fNewValue ) +{ + if ( fNewValue == m_fValue ) + return; +#endif if ( IsFlagSet( FCVAR_MATERIAL_THREAD_MASK ) ) { @@ -994,6 +1015,7 @@ void ConVar::InternalSetIntValue( int nValue ) } } +#ifdef SDK_MP void ConVar::Create_Vtbl( const char *pName, const char *pDefaultValue, int flags /* = 0 */, const char *pHelpString /* = 0 */, bool bMin /* = false */, float fMin /* = 0.0 */, bool bMax /* = false */, float fMax /* = false */, FnChangeCallback_t callback /* = 0 */ ) @@ -1009,6 +1031,14 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*= bool bMax /*= false*/, float fMax /*= false*/, bool bCompMin /*= false */, float fCompMin /*= 0.0*/, bool bCompMax /*= false*/, float fCompMax /*= 0.0*/, FnChangeCallback_t callback /*= NULL*/ ) +#else +//----------------------------------------------------------------------------- +// Purpose: Private creation +//----------------------------------------------------------------------------- +void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*= 0*/, + const char *pHelpString /*= NULL*/, bool bMin /*= false*/, float fMin /*= 0.0*/, + bool bMax /*= false*/, float fMax /*= false*/, FnChangeCallback_t callback /*= NULL*/ ) +#endif { m_pParent = this; @@ -1024,12 +1054,14 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*= m_bHasMax = bMax; m_fMaxVal = fMax; +#ifdef SDK_MP m_bHasCompMin = bCompMin; m_fCompMinVal = fCompMin; m_bHasCompMax = bCompMax; m_fCompMaxVal = fCompMax; m_bCompetitiveRestrictions = false; +#endif m_fnChangeCallback = callback; @@ -1104,6 +1136,7 @@ bool ConVar::GetMax( float& maxVal ) const return m_pParent->m_bHasMax; } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Purpose: // Input : minVal - @@ -1161,6 +1194,7 @@ bool ConVar::SetCompetitiveMode( bool bCompetitive ) Assert( !bForceToDefault || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK ) || ( var->m_fValue == fDefaultAsFloat ) ); return true; } +#endif @@ -1179,6 +1213,7 @@ void ConVar::SetDefault( const char *pszDefault ) Assert( m_pszDefaultValue ); } +#ifdef SDK_MP // Josh: // See comments in convar.h about UIConVarRef // and it's purpose/implementation. @@ -1237,6 +1272,7 @@ bool UIConVarRef::CanSetWithoutEngine() { return !IsFlagSet( FCVAR_UNREGISTERED | FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED | FCVAR_CHEAT | FCVAR_SPONLY ); } +#endif //----------------------------------------------------------------------------- diff --git a/src/tier1/datamanager.cpp b/src/tier1/datamanager.cpp index 4dd88386e3b..bb37a24d691 100644 --- a/src/tier1/datamanager.cpp +++ b/src/tier1/datamanager.cpp @@ -11,6 +11,10 @@ DECLARE_POINTER_HANDLE( memhandle_t ); +#ifndef SDK_MP +#define AUTO_LOCK_DM() AUTO_LOCK_( CDataManagerBase, *this ) +#endif + CDataManagerBase::CDataManagerBase( unsigned int maxSize ) { m_targetMemorySize = maxSize; @@ -151,7 +155,11 @@ void CDataManagerBase::DestroyResource( memhandle_t handle ) void *CDataManagerBase::LockResource( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() ) @@ -171,7 +179,11 @@ void *CDataManagerBase::LockResource( memhandle_t handle ) int CDataManagerBase::UnlockResource( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() ) { @@ -193,7 +205,11 @@ int CDataManagerBase::UnlockResource( memhandle_t handle ) void *CDataManagerBase::GetResource_NoLockNoLRUTouch( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() ) { @@ -205,7 +221,11 @@ void *CDataManagerBase::GetResource_NoLockNoLRUTouch( memhandle_t handle ) void *CDataManagerBase::GetResource_NoLock( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() ) { @@ -217,13 +237,21 @@ void *CDataManagerBase::GetResource_NoLock( memhandle_t handle ) void CDataManagerBase::TouchResource( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif TouchByIndex( FromHandle(handle) ); } void CDataManagerBase::MarkAsStale( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() ) { @@ -237,7 +265,11 @@ void CDataManagerBase::MarkAsStale( memhandle_t handle ) int CDataManagerBase::BreakLock( memhandle_t handle ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif unsigned short memoryIndex = FromHandle(handle); if ( memoryIndex != m_memoryLists.InvalidIndex() && m_memoryLists[memoryIndex].lockCount ) { @@ -253,7 +285,11 @@ int CDataManagerBase::BreakLock( memhandle_t handle ) int CDataManagerBase::BreakAllLocks() { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif int nBroken = 0; int node; int nextNode; @@ -275,7 +311,11 @@ int CDataManagerBase::BreakAllLocks() unsigned short CDataManagerBase::CreateHandle( bool bCreateLocked ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif int memoryIndex = m_memoryLists.Head(m_freeList); unsigned short list = ( bCreateLocked ) ? m_lockList : m_lruList; if ( memoryIndex != m_memoryLists.InvalidIndex() ) @@ -298,7 +338,11 @@ unsigned short CDataManagerBase::CreateHandle( bool bCreateLocked ) memhandle_t CDataManagerBase::StoreResourceInHandle( unsigned short memoryIndex, void *pStore, unsigned int realSize ) { +#ifdef SDK_MP AUTO_LOCK( *this ); +#else + AUTO_LOCK_DM(); +#endif resource_lru_element_t &mem = m_memoryLists[memoryIndex]; mem.pStore = pStore; m_memUsed += realSize; diff --git a/src/tier1/exprevaluator.cpp b/src/tier1/exprevaluator.cpp index 2a1a03dd44f..72f5233d922 100644 --- a/src/tier1/exprevaluator.cpp +++ b/src/tier1/exprevaluator.cpp @@ -87,7 +87,11 @@ bool DefaultConditionalSymbolProc( const char *pKey ) } // don't know it at compile time, so fall through to installed symbol values +#ifdef SDK_MP return KeyValuesSystem()->GetKeyValuesExpressionSymbol( pKey ); +#else + return false; +#endif } void DefaultConditionalErrorProc( const char *pReason ) diff --git a/src/tier1/strtools.cpp b/src/tier1/strtools.cpp index c46c708b3de..98f3b320fe7 100644 --- a/src/tier1/strtools.cpp +++ b/src/tier1/strtools.cpp @@ -4614,3 +4614,18 @@ void V_StripAndPreserveHTML( CUtlBuffer *pbuffer, const char *pchHTML, const cha const char *rgszNoCloseTags[] = { "br", "img" }; V_StripAndPreserveHTMLCore( pbuffer, pchHTML, rgszPreserveTags, cPreserveTags, rgszNoCloseTags, V_ARRAYSIZE( rgszNoCloseTags ), cMaxResultSize ); } + +#if defined(SDK_SP) && defined(_WIN32) +// SP's dmxloader.lib uses this, but it does not appear to be defined anywhere (toolset difference?) +// For now, just redirects to sscanf_s +int _sscanf_s( const char *pBuffer, const char *const pFormat, ... ) +{ + va_list args; + + va_start( args, pFormat ); + int i = sscanf_s( pBuffer, pFormat, args ); + va_end( args ); + + return i; +} +#endif diff --git a/src/tier1/tier1.vpc b/src/tier1/tier1.vpc index 2c7dd366cb6..f9eebdd22ce 100644 --- a/src/tier1/tier1.vpc +++ b/src/tier1/tier1.vpc @@ -74,7 +74,8 @@ $Project "tier1" $File "uniqueid.cpp" $File "utlbuffer.cpp" $File "utlbufferutil.cpp" - $File "utlstring.cpp" + $File "utlstring.cpp" [$WIN64||$LINUX64] // SDK_MP + $File "utlstring_sp.cpp" [$WIN32||$LINUX32] // SDK_SP $File "utlsymbol.cpp" $File "utlbinaryblock.cpp" $File "pathmatch.cpp" [$LINUXALL] @@ -160,7 +161,8 @@ $Project "tier1" $File "$SRCDIR\public\tier1\utlrbtree.h" $File "$SRCDIR\public\tier1\UtlSortVector.h" $File "$SRCDIR\public\tier1\utlstack.h" - $File "$SRCDIR\public\tier1\utlstring.h" + $File "$SRCDIR\public\tier1\utlstring.h" [$WIN64||$LINUX64] // SDK_MP + $File "$SRCDIR\public_sp\tier1\utlstring.h" [$WIN32||$LINUX32] // SDK_SP $File "$SRCDIR\public\tier1\UtlStringMap.h" $File "$SRCDIR\public\tier1\utlsymbol.h" $File "$SRCDIR\public\tier1\utlsymbollarge.h" diff --git a/src/tier1/utlbuffer.cpp b/src/tier1/utlbuffer.cpp index 74dc17d45d7..427df655bf2 100644 --- a/src/tier1/utlbuffer.cpp +++ b/src/tier1/utlbuffer.cpp @@ -21,6 +21,10 @@ #include "tier0/memdbgon.h" +#ifndef SDK_MP +#define GetStringInternal GetString +#endif + //----------------------------------------------------------------------------- // Character conversions for C strings //----------------------------------------------------------------------------- @@ -324,6 +328,7 @@ void CUtlBuffer::AssumeMemory( void *pMemory, int nSize, int nInitialPut, int nF AddNullTermination(); } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Allows the caller to control memory //----------------------------------------------------------------------------- @@ -337,6 +342,7 @@ void* CUtlBuffer::DetachMemory() m_nOffset = 0; return m_Memory.DetachMemory( ); } +#endif //----------------------------------------------------------------------------- @@ -622,7 +628,11 @@ int CUtlBuffer::PeekDelimitedStringLength( CUtlCharConversion *pConv, bool bActu //----------------------------------------------------------------------------- // Reads a null-terminated string //----------------------------------------------------------------------------- +#ifdef SDK_MP void CUtlBuffer::GetStringInternal( char *pString, size_t maxLenInChars ) +#else +void CUtlBuffer::GetString( char *pString, int maxLenInChars ) +#endif { if ( !IsValid() ) { @@ -630,9 +640,11 @@ void CUtlBuffer::GetStringInternal( char *pString, size_t maxLenInChars ) return; } +#ifdef SDK_MP // This can legitimately be zero if we were told that the buffer is zero length, and // we're asking to duplicate the buffer, so let that pass, too. Assert( maxLenInChars != 0 || PeekStringLength() == 0 ); +#endif if ( maxLenInChars == 0 ) { @@ -655,7 +667,11 @@ void CUtlBuffer::GetStringInternal( char *pString, size_t maxLenInChars ) return; } +#ifdef SDK_MP const size_t nCharsToRead = min( (size_t)nLen, maxLenInChars ) - 1; +#else + const size_t nCharsToRead = min( (size_t)nLen, (size_t)maxLenInChars ) - 1; +#endif Get( pString, (int) nCharsToRead ); pString[nCharsToRead] = 0; diff --git a/src/tier1/utlstring_sp.cpp b/src/tier1/utlstring_sp.cpp new file mode 100644 index 00000000000..3d1b802129b --- /dev/null +++ b/src/tier1/utlstring_sp.cpp @@ -0,0 +1,438 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "tier1/utlstring.h" +#include "tier1/strtools.h" +#include + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Simple string class. +//----------------------------------------------------------------------------- +CUtlString::CUtlString() +{ +} + +CUtlString::CUtlString( const char *pString ) +{ + Set( pString ); +} + +CUtlString::CUtlString( const CUtlString& string ) +{ + Set( string.Get() ); +} + +// Attaches the string to external memory. Useful for avoiding a copy +CUtlString::CUtlString( void* pMemory, int nSizeInBytes, int nInitialLength ) : m_Storage( pMemory, nSizeInBytes, nInitialLength ) +{ +} + +CUtlString::CUtlString( const void* pMemory, int nSizeInBytes ) : m_Storage( pMemory, nSizeInBytes ) +{ +} + + +//----------------------------------------------------------------------------- +// Purpose: Set directly and don't look for a null terminator in pValue. +//----------------------------------------------------------------------------- +void CUtlString::SetDirect( const char *pValue, int nChars ) +{ + Assert( !m_Storage.IsReadOnly() ); + m_Storage.Set( pValue, nChars + 1 ); + + // Make sure to null terminate the copied string + *(((char *)m_Storage.Get()) + nChars) = NULL; +} + + +void CUtlString::Set( const char *pValue ) +{ + Assert( !m_Storage.IsReadOnly() ); + int nLen = pValue ? Q_strlen(pValue) + 1 : 0; + m_Storage.Set( pValue, nLen ); +} + + +// Returns strlen +int CUtlString::Length() const +{ + return m_Storage.Length() ? m_Storage.Length() - 1 : 0; +} + +// Sets the length (used to serialize into the buffer ) +void CUtlString::SetLength( int nLen ) +{ + Assert( !m_Storage.IsReadOnly() ); + + // Add 1 to account for the NULL + m_Storage.SetLength( nLen > 0 ? nLen + 1 : 0 ); +} + +const char *CUtlString::Get( ) const +{ + if ( m_Storage.Length() == 0 ) + { + return ""; + } + + return reinterpret_cast< const char* >( m_Storage.Get() ); +} + +// Converts to c-strings +CUtlString::operator const char*() const +{ + return Get(); +} + +char *CUtlString::Get() +{ + Assert( !m_Storage.IsReadOnly() ); + + if ( m_Storage.Length() == 0 ) + { + // In general, we optimise away small mallocs for empty strings + // but if you ask for the non-const bytes, they must be writable + // so we can't return "" here, like we do for the const version - jd + m_Storage.SetLength( 1 ); + m_Storage[ 0 ] = '\0'; + } + + return reinterpret_cast< char* >( m_Storage.Get() ); +} + +void CUtlString::Purge() +{ + m_Storage.Purge(); +} + + +void CUtlString::ToLower() +{ + for( int nLength = Length() - 1; nLength >= 0; nLength-- ) + { + m_Storage[ nLength ] = tolower( m_Storage[ nLength ] ); + } +} + + +void CUtlString::ToUpper() +{ + for( int nLength = Length() - 1; nLength >= 0; nLength-- ) + { + m_Storage[ nLength ] = toupper( m_Storage[ nLength ] ); + } +} + + +CUtlString &CUtlString::operator=( const CUtlString &src ) +{ + Assert( !m_Storage.IsReadOnly() ); + m_Storage = src.m_Storage; + return *this; +} + +CUtlString &CUtlString::operator=( const char *src ) +{ + Assert( !m_Storage.IsReadOnly() ); + Set( src ); + return *this; +} + +bool CUtlString::operator==( const CUtlString &src ) const +{ + return m_Storage == src.m_Storage; +} + +bool CUtlString::operator==( const char *src ) const +{ + return ( strcmp( Get(), src ) == 0 ); +} + +CUtlString &CUtlString::operator+=( const CUtlString &rhs ) +{ + Assert( !m_Storage.IsReadOnly() ); + + const int lhsLength( Length() ); + const int rhsLength( rhs.Length() ); + const int requestedLength( lhsLength + rhsLength ); + + SetLength( requestedLength ); + const int allocatedLength( Length() ); + const int copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength ); + memcpy( Get() + lhsLength, rhs.Get(), copyLength ); + m_Storage[ allocatedLength ] = '\0'; + + return *this; +} + +CUtlString &CUtlString::operator+=( const char *rhs ) +{ + Assert( !m_Storage.IsReadOnly() ); + + const int lhsLength( Length() ); + const int rhsLength( Q_strlen( rhs ) ); + const int requestedLength( lhsLength + rhsLength ); + + SetLength( requestedLength ); + const int allocatedLength( Length() ); + const int copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength ); + memcpy( Get() + lhsLength, rhs, copyLength ); + m_Storage[ allocatedLength ] = '\0'; + + return *this; +} + +CUtlString &CUtlString::operator+=( char c ) +{ + Assert( !m_Storage.IsReadOnly() ); + + int nLength = Length(); + SetLength( nLength + 1 ); + m_Storage[ nLength ] = c; + m_Storage[ nLength+1 ] = '\0'; + return *this; +} + +CUtlString &CUtlString::operator+=( int rhs ) +{ + Assert( !m_Storage.IsReadOnly() ); + Assert( sizeof( rhs ) == 4 ); + + char tmpBuf[ 12 ]; // Sufficient for a signed 32 bit integer [ -2147483648 to +2147483647 ] + Q_snprintf( tmpBuf, sizeof( tmpBuf ), "%d", rhs ); + tmpBuf[ sizeof( tmpBuf ) - 1 ] = '\0'; + + return operator+=( tmpBuf ); +} + +CUtlString &CUtlString::operator+=( double rhs ) +{ + Assert( !m_Storage.IsReadOnly() ); + + char tmpBuf[ 256 ]; // How big can doubles be??? Dunno. + Q_snprintf( tmpBuf, sizeof( tmpBuf ), "%lg", rhs ); + tmpBuf[ sizeof( tmpBuf ) - 1 ] = '\0'; + + return operator+=( tmpBuf ); +} + +bool CUtlString::MatchesPattern( const CUtlString &Pattern, int nFlags ) +{ + const char *pszSource = String(); + const char *pszPattern = Pattern.String(); + bool bExact = true; + + while( 1 ) + { + if ( ( *pszPattern ) == 0 ) + { + return ( (*pszSource ) == 0 ); + } + + if ( ( *pszPattern ) == '*' ) + { + pszPattern++; + + if ( ( *pszPattern ) == 0 ) + { + return true; + } + + bExact = false; + continue; + } + + int nLength = 0; + + while( ( *pszPattern ) != '*' && ( *pszPattern ) != 0 ) + { + nLength++; + pszPattern++; + } + + while( 1 ) + { + const char *pszStartPattern = pszPattern - nLength; + const char *pszSearch = pszSource; + + for( int i = 0; i < nLength; i++, pszSearch++, pszStartPattern++ ) + { + if ( ( *pszSearch ) == 0 ) + { + return false; + } + + if ( ( *pszSearch ) != ( *pszStartPattern ) ) + { + break; + } + } + + if ( pszSearch - pszSource == nLength ) + { + break; + } + + if ( bExact == true ) + { + return false; + } + + if ( ( nFlags & PATTERN_DIRECTORY ) != 0 ) + { + if ( ( *pszPattern ) != '/' && ( *pszSource ) == '/' ) + { + return false; + } + } + + pszSource++; + } + + pszSource += nLength; + } +} + + +int CUtlString::Format( const char *pFormat, ... ) +{ + Assert( !m_Storage.IsReadOnly() ); + + char tmpBuf[ 4096 ]; //< Nice big 4k buffer, as much memory as my first computer had, a Radio Shack Color Computer + + va_list marker; + + va_start( marker, pFormat ); +#ifdef _WIN32 + int len = _vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker ); +#elif POSIX + int len = vsnprintf( tmpBuf, sizeof( tmpBuf ) - 1, pFormat, marker ); +#else +#error "define vsnprintf type." +#endif + va_end( marker ); + + // Len > maxLen represents an overflow on POSIX, < 0 is an overflow on windows + if( len < 0 || len >= sizeof( tmpBuf ) - 1 ) + { + len = sizeof( tmpBuf ) - 1; + tmpBuf[sizeof( tmpBuf ) - 1] = 0; + } + + Set( tmpBuf ); + + return len; +} + +//----------------------------------------------------------------------------- +// Strips the trailing slash +//----------------------------------------------------------------------------- +void CUtlString::StripTrailingSlash() +{ + if ( IsEmpty() ) + return; + + int nLastChar = Length() - 1; + char c = m_Storage[ nLastChar ]; + if ( c == '\\' || c == '/' ) + { + m_Storage[ nLastChar ] = 0; + m_Storage.SetLength( m_Storage.Length() - 1 ); + } +} + +CUtlString CUtlString::Slice( int32 nStart, int32 nEnd ) +{ + if ( nStart < 0 ) + nStart = Length() - (-nStart % Length()); + else if ( nStart >= Length() ) + nStart = Length(); + + if ( nEnd == 0x7FFFFFFF ) + nEnd = Length(); + else if ( nEnd < 0 ) + nEnd = Length() - (-nEnd % Length()); + else if ( nEnd >= Length() ) + nEnd = Length(); + + if ( nStart >= nEnd ) + return CUtlString( "" ); + + const char *pIn = String(); + + CUtlString ret; + ret.m_Storage.SetLength( nEnd - nStart + 1 ); + char *pOut = (char*)ret.m_Storage.Get(); + + memcpy( ret.m_Storage.Get(), &pIn[nStart], nEnd - nStart ); + pOut[nEnd - nStart] = 0; + + return ret; +} + +// Grab a substring starting from the left or the right side. +CUtlString CUtlString::Left( int32 nChars ) +{ + return Slice( 0, nChars ); +} + +CUtlString CUtlString::Right( int32 nChars ) +{ + return Slice( -nChars ); +} + +CUtlString CUtlString::Replace( char cFrom, char cTo ) +{ + CUtlString ret = *this; + int len = ret.Length(); + for ( int i=0; i < len; i++ ) + { + if ( ret.m_Storage[i] == cFrom ) + ret.m_Storage[i] = cTo; + } + + return ret; +} + +CUtlString CUtlString::AbsPath( const char *pStartingDir ) +{ + char szNew[MAX_PATH]; + V_MakeAbsolutePath( szNew, sizeof( szNew ), this->String(), pStartingDir ); + return CUtlString( szNew ); +} + +CUtlString CUtlString::UnqualifiedFilename() +{ + const char *pFilename = V_UnqualifiedFileName( this->String() ); + return CUtlString( pFilename ); +} + +CUtlString CUtlString::DirName() +{ + CUtlString ret( this->String() ); + V_StripLastDir( (char*)ret.m_Storage.Get(), ret.m_Storage.Length() ); + V_StripTrailingSlash( (char*)ret.m_Storage.Get() ); + return ret; +} + +CUtlString CUtlString::PathJoin( const char *pStr1, const char *pStr2 ) +{ + char szPath[MAX_PATH]; + V_ComposeFileName( pStr1, pStr2, szPath, sizeof( szPath ) ); + return CUtlString( szPath ); +} + +//----------------------------------------------------------------------------- +// Purpose: concatenate the provided string to our current content +//----------------------------------------------------------------------------- +void CUtlString::Append( const char *pchAddition ) +{ + *this += pchAddition; +} diff --git a/src/utils/common/bsplib.cpp b/src/utils/common/bsplib.cpp index 607bb5ef041..d26c9901e96 100644 --- a/src/utils/common/bsplib.cpp +++ b/src/utils/common/bsplib.cpp @@ -26,8 +26,10 @@ #include "tier0/dbg.h" #include "lumpfiles.h" #include "vtf/vtf.h" +#ifdef SDK_MP #include "lzma/lzma.h" #include "tier1/lzmaDecoder.h" +#endif #include "tier0/memdbgon.h" @@ -49,7 +51,11 @@ BEGIN_BYTESWAP_DATADESC( lump_t ) DEFINE_FIELD( fileofs, FIELD_INTEGER ), DEFINE_FIELD( filelen, FIELD_INTEGER ), DEFINE_FIELD( version, FIELD_INTEGER ), +#ifdef SDK_MP DEFINE_FIELD( uncompressedSize, FIELD_INTEGER ), +#else + DEFINE_ARRAY( fourCC, FIELD_CHARACTER, 4 ), +#endif END_BYTESWAP_DATADESC() BEGIN_BYTESWAP_DATADESC( dflagslump_t ) @@ -1357,7 +1363,14 @@ static void AddOcclusionLump( ) lump->fileofs = g_pFileSystem->Tell( g_hBSPFile ); lump->filelen = nLumpLength; lump->version = LUMP_OCCLUSION_VERSION; +#ifdef SDK_MP lump->uncompressedSize = 0; +#else + lump->fourCC[0] = ( char )0; + lump->fourCC[1] = ( char )0; + lump->fourCC[2] = ( char )0; + lump->fourCC[3] = ( char )0; +#endif // Data is swapped in place, so the 'Count' variables aren't safe to use after they're written WriteData( FIELD_INTEGER, &nOccluderCount ); @@ -2274,10 +2287,12 @@ void LoadBSPFile( const char *filename ) CopyLump( FIELD_CHARACTER, LUMP_TEXDATA_STRING_DATA, g_TexDataStringData ); CopyLump( FIELD_INTEGER, LUMP_TEXDATA_STRING_TABLE, g_TexDataStringTable ); +#ifdef SDK_MP // It's assumed by other code that the data lump is filled with C strings. We need to make sure that // the buffer as a whole ends with a '\0'. if ( g_TexDataStringData.Count() > 0 && g_TexDataStringData.Tail() != 0 ) Error( "Cannot load corrupted bsp file %s", filename ); +#endif g_nOverlayCount = CopyLump( LUMP_OVERLAYS, g_Overlays ); g_nWaterOverlayCount = CopyLump( LUMP_WATEROVERLAYS, g_WaterOverlays ); @@ -2555,7 +2570,14 @@ static void AddLumpInternal( int lumpnum, void *data, int len, int version ) lump->fileofs = g_pFileSystem->Tell( g_hBSPFile ); lump->filelen = len; lump->version = version; +#ifdef SDK_MP lump->uncompressedSize = 0; +#else + lump->fourCC[0] = ( char )0; + lump->fourCC[1] = ( char )0; + lump->fourCC[2] = ( char )0; + lump->fourCC[3] = ( char )0; +#endif SafeWrite( g_hBSPFile, data, len ); @@ -4467,6 +4489,8 @@ bool CompressGameLump( dheader_t *pInBSPHeader, dheader_t *pOutBSPHeader, CUtlBu } unsigned int newOffset = outputBuffer.TellPut(); + +#ifdef SDK_MP // Make room for gamelump header and gamelump structs, which we'll write at the end outputBuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, sizeof( dgamelumpheader_t ) ); outputBuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, pInGameLumpHeader->lumpCount * sizeof( dgamelump_t ) ); @@ -4559,10 +4583,63 @@ bool CompressGameLump( dheader_t *pInBSPHeader, dheader_t *pOutBSPHeader, CUtlBu outputBuffer.Put( &sOutGameLumpHeader, sizeof( dgamelumpheader_t ) ); outputBuffer.Put( sOutGameLumpBuf.Base(), sOutGameLumpBuf.TellPut() ); outputBuffer.SeekPut( CUtlBuffer::SEEK_HEAD, endOffset ); +#else + outputBuffer.Put( pInGameLumpHeader, sizeof( dgamelumpheader_t ) ); + outputBuffer.Put( pInGameLump, pInGameLumpHeader->lumpCount * sizeof( dgamelump_t ) ); + + dgamelumpheader_t* pOutGameLumpHeader = (dgamelumpheader_t*)((byte *)outputBuffer.Base() + newOffset); + dgamelump_t* pOutGameLump = (dgamelump_t*)(pOutGameLumpHeader + 1); + + // add a dummy terminal gamelump + // purposely NOT updating the .filelen to reflect the compressed size, but leaving as original size + // callers use the next entry offset to determine compressed size + pOutGameLumpHeader->lumpCount++; + dgamelump_t dummyLump = { 0 }; + outputBuffer.Put( &dummyLump, sizeof( dgamelump_t ) ); + + for ( int i = 0; i < pInGameLumpHeader->lumpCount; i++ ) + { + CUtlBuffer inputBuffer; + CUtlBuffer compressedBuffer; + + pOutGameLump[i].fileofs = AlignBuffer( outputBuffer, 4 ); + + if ( pInGameLump[i].filelen ) + { + inputBuffer.SetExternalBuffer( ((byte *)pInBSPHeader) + pInGameLump[i].fileofs, pInGameLump[i].filelen, pInGameLump[i].filelen ); + + bool bCompressed = pCompressFunc( inputBuffer, compressedBuffer ); + if ( bCompressed ) + { + pOutGameLump[i].flags |= GAMELUMPFLAG_COMPRESSED; + + outputBuffer.Put( compressedBuffer.Base(), compressedBuffer.TellPut() ); + compressedBuffer.Purge(); + } + else + { + // as is + outputBuffer.Put( inputBuffer.Base(), inputBuffer.TellPut() ); + } + } + } + + // fix the dummy terminal lump + int lastLump = pOutGameLumpHeader->lumpCount-1; + pOutGameLump[lastLump].fileofs = outputBuffer.TellPut(); + + // fix the output for 360, swapping it back + byteSwap.SwapFieldsToTargetEndian( pOutGameLump, pOutGameLumpHeader->lumpCount ); + byteSwap.SwapFieldsToTargetEndian( pOutGameLumpHeader ); + + pOutBSPHeader->lumps[LUMP_GAME_LUMP].fileofs = newOffset; + pOutBSPHeader->lumps[LUMP_GAME_LUMP].filelen = outputBuffer.TellPut() - newOffset; +#endif return true; } +#ifdef SDK_MP //----------------------------------------------------------------------------- // Compress callback for RepackBSP //----------------------------------------------------------------------------- @@ -4757,6 +4834,106 @@ bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFunc_ return true; } +#else +bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFunc_t pCompressFunc ) +{ + CByteswap byteSwap; + + dheader_t *pInBSPHeader = (dheader_t *)inputBuffer.Base(); + if ( pInBSPHeader->ident != BigLong( IDBSPHEADER ) || !pCompressFunc ) + { + // only compress 360 bsp's + return false; + } + + // bsp is 360, swap the header back + byteSwap.ActivateByteSwapping( true ); + byteSwap.SwapFieldsToTargetEndian( pInBSPHeader ); + + // output will be smaller, use input size as upper bound + outputBuffer.EnsureCapacity( inputBuffer.TellMaxPut() ); + outputBuffer.Put( pInBSPHeader, sizeof( dheader_t ) ); + + dheader_t *pOutBSPHeader = (dheader_t *)outputBuffer.Base(); + + // must adhere to input lump's offset order and process according to that, NOT lump num + // sort by offset order + CUtlVector< SortedLump_t > sortedLumps; + for ( int i = 0; i < HEADER_LUMPS; i++ ) + { + int iIndex = sortedLumps.AddToTail(); + sortedLumps[iIndex].lumpNum = i; + sortedLumps[iIndex].pLump = &pInBSPHeader->lumps[i]; + } + sortedLumps.Sort( SortLumpsByOffset ); + + // iterate in sorted order + for ( int i = 0; i < HEADER_LUMPS; ++i ) + { + SortedLump_t *pSortedLump = &sortedLumps[i]; + int lumpNum = pSortedLump->lumpNum; + + if ( !pSortedLump->pLump->filelen ) + { + // degenerate + pOutBSPHeader->lumps[lumpNum].fileofs = 0; + } + else + { + int alignment = 4; + if ( lumpNum == LUMP_PAKFILE ) + { + alignment = 2048; + } + unsigned int newOffset = AlignBuffer( outputBuffer, alignment ); + + // only set by compressed lumps, hides the uncompressed size + *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = 0; + + CUtlBuffer inputBuffer; + inputBuffer.SetExternalBuffer( ((byte *)pInBSPHeader) + pSortedLump->pLump->fileofs, pSortedLump->pLump->filelen, pSortedLump->pLump->filelen ); + + if ( lumpNum == LUMP_GAME_LUMP ) + { + // the game lump has to have each of its components individually compressed + CompressGameLump( pInBSPHeader, pOutBSPHeader, outputBuffer, pCompressFunc ); + } + else if ( lumpNum == LUMP_PAKFILE ) + { + // add as is + pOutBSPHeader->lumps[lumpNum].fileofs = newOffset; + outputBuffer.Put( inputBuffer.Base(), inputBuffer.TellPut() ); + } + else + { + CUtlBuffer compressedBuffer; + bool bCompressed = pCompressFunc( inputBuffer, compressedBuffer ); + if ( bCompressed ) + { + // placing the uncompressed size in the unused fourCC, will decode at runtime + *((unsigned int *)pOutBSPHeader->lumps[lumpNum].fourCC) = BigLong( inputBuffer.TellPut() ); + pOutBSPHeader->lumps[lumpNum].filelen = compressedBuffer.TellPut(); + pOutBSPHeader->lumps[lumpNum].fileofs = newOffset; + outputBuffer.Put( compressedBuffer.Base(), compressedBuffer.TellPut() ); + compressedBuffer.Purge(); + } + else + { + // add as is + pOutBSPHeader->lumps[lumpNum].fileofs = newOffset; + outputBuffer.Put( inputBuffer.Base(), inputBuffer.TellPut() ); + } + } + } + } + + // fix the output for 360, swapping it back + byteSwap.SetTargetBigEndian( true ); + byteSwap.SwapFieldsToTargetEndian( pOutBSPHeader ); + + return true; +} +#endif //----------------------------------------------------------------------------- // For all lumps in a bsp: Loads the lump from file A, swaps it, writes it to file B. diff --git a/src/utils/common/bsplib.h b/src/utils/common/bsplib.h index 18a907f27a4..b9f59228591 100644 --- a/src/utils/common/bsplib.h +++ b/src/utils/common/bsplib.h @@ -297,8 +297,13 @@ void PrintBSPFileSizes(void); void PrintBSPPackDirectory(void); void ReleasePakFileLumps(void); +#ifdef SDK_MP bool RepackBSPCallback_LZMA( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer ); bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFunc_t pCompressFunc, IZip::eCompressionType packfileCompression ); +#else +bool CompressBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFunc_t pCompressFunc ); +FORCEINLINE bool RepackBSP( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer, CompressFunc_t pCompressFunc, IZip::eCompressionType packfileCompression ) { return CompressBSP( inputBuffer, outputBuffer, pCompressFunc ); } +#endif bool SwapBSPFile( const char *filename, const char *swapFilename, bool bSwapOnLoad, VTFConvertFunc_t pVTFConvertFunc, VHVFixupFunc_t pVHVFixupFunc, CompressFunc_t pCompressFunc ); bool GetPakFileLump( const char *pBSPFilename, void **pPakData, int *pPakSize ); diff --git a/src/utils/height2normal/height2normal.vpc b/src/utils/height2normal/height2normal.vpc index f6ea82bf30d..14f0a74dedd 100644 --- a/src/utils/height2normal/height2normal.vpc +++ b/src/utils/height2normal/height2normal.vpc @@ -21,7 +21,9 @@ $Project "Height2Normal" { $Folder "Source Files" { - -$File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + -$File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + -$File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] $File "height2normal.cpp" } diff --git a/src/utils/qc_eyes/qc_eyes.vpc b/src/utils/qc_eyes/qc_eyes.vpc index a5f9da740cb..f2b5a2816d6 100644 --- a/src/utils/qc_eyes/qc_eyes.vpc +++ b/src/utils/qc_eyes/qc_eyes.vpc @@ -30,7 +30,9 @@ $Project "QC Eyes" { $Folder "Source Files" { - -$File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + -$File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + -$File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] $File "QC_Eyes.cpp" $File "QC_Eyes.rc" diff --git a/src/utils/vbsp/staticprop.cpp b/src/utils/vbsp/staticprop.cpp index ecef50110c6..efb5f51d78e 100644 --- a/src/utils/vbsp/staticprop.cpp +++ b/src/utils/vbsp/staticprop.cpp @@ -54,8 +54,10 @@ struct StaticPropBuild_t float m_flForcedFadeScale; unsigned short m_nMinDXLevel; unsigned short m_nMaxDXLevel; +#ifdef SDK_MP int m_LightmapResolutionX; int m_LightmapResolutionY; +#endif }; @@ -520,8 +522,10 @@ static void AddStaticPropToLump( StaticPropBuild_t const& build ) } } +#ifdef SDK_MP propLump.m_nLightmapResolutionX = build.m_LightmapResolutionX; propLump.m_nLightmapResolutionY = build.m_LightmapResolutionY; +#endif // Add the leaves to the leaf lump for (int j = 0; j < leafList.Size(); ++j) @@ -661,6 +665,7 @@ void EmitStaticProps() build.m_Flags |= STATIC_PROP_SCREEN_SPACE_FADE; } +#ifdef SDK_MP if (IntForKey( &entities[i], "generatelightmaps") == 0) { build.m_Flags |= STATIC_PROP_NO_PER_TEXEL_LIGHTING; @@ -672,6 +677,7 @@ void EmitStaticProps() build.m_LightmapResolutionX = IntForKey( &entities[i], "lightmapresolutionx" ); build.m_LightmapResolutionY = IntForKey( &entities[i], "lightmapresolutiony" ); } +#endif const char *pKey = ValueForKey( &entities[i], "fadescale" ); if ( pKey && pKey[0] ) diff --git a/src/utils/vbsp/vbsp.vpc b/src/utils/vbsp/vbsp.vpc index 3cbdd4fc8d7..3cbb69b4541 100644 --- a/src/utils/vbsp/vbsp.vpc +++ b/src/utils/vbsp/vbsp.vpc @@ -190,7 +190,7 @@ $Project "VBSP" $Lib mathlib $Lib tier2 $Lib vtf - $Lib "$LIBCOMMON/lzma" + $Lib "$LIBCOMMON/lzma" [$WIN64||$LINUX64] // SDK_MP $Lib vscript [$MAPBASE_VSCRIPT] } diff --git a/src/utils/vrad/vrad_dll.vpc b/src/utils/vrad/vrad_dll.vpc index 6c1a4d0006e..2661bd7fc47 100644 --- a/src/utils/vrad/vrad_dll.vpc +++ b/src/utils/vrad/vrad_dll.vpc @@ -15,7 +15,7 @@ $Configuration $Compiler { $AdditionalIncludeDirectories "$BASE,..\common,..\vmpi,..\vmpi\mysql\mysqlpp\include,..\vmpi\mysql\include" - $PreprocessorDefinitions "$BASE;MPI" [$WIN32] + //$PreprocessorDefinitions "$BASE;MPI" [$WIN32] // SDK_SP compat $PreprocessorDefinitions "$BASE;PROTECTED_THINGS_DISABLE;VRAD" } @@ -40,10 +40,10 @@ $Project "VRAD" $File "$SRCDIR\public\loadcmdline.cpp" $File "$SRCDIR\public\lumpfiles.cpp" $File "macro_texture.cpp" - $File "..\common\mpi_stats.cpp" [$WIN32] - $File "mpivrad.cpp" [$WIN32] - $File "$SRCDIR\public\filesystem_init.cpp" [!$WIN32] - $File "..\common\filesystem_tools.cpp" [!$WIN32] + //$File "..\common\mpi_stats.cpp" [$WIN32] // SDK_SP compat + //$File "mpivrad.cpp" [$WIN32] // SDK_SP compat + $File "$SRCDIR\public\filesystem_init.cpp" //[!$WIN32] // SDK_SP compat + $File "..\common\filesystem_tools.cpp" //[!$WIN32] // SDK_SP compat $File "..\common\MySqlDatabase.cpp" $File "..\common\pacifier.cpp" $File "..\common\physdll.cpp" @@ -52,8 +52,8 @@ $Project "VRAD" $File "trace.cpp" $File "..\common\utilmatlib.cpp" $File "vismat.cpp" - $File "..\common\vmpi_tools_shared.cpp" [$WIN32] - $File "..\common\vmpi_tools_shared.h" [$WIN32] + //$File "..\common\vmpi_tools_shared.cpp" [$WIN32] // SDK_SP compat + //$File "..\common\vmpi_tools_shared.h" [$WIN32] // SDK_SP compat $File "vrad.cpp" $File "VRAD_DispColl.cpp" $File "VradDetailProps.cpp" @@ -110,24 +110,24 @@ $Project "VRAD" $File "..\common\bsplib.h" $File "..\common\cmdlib.h" $File "..\common\consolewnd.h" - $File "..\vmpi\ichannel.h" [$WIN32] - $File "..\vmpi\imysqlwrapper.h" [$WIN32] - $File "..\vmpi\iphelpers.h" [$WIN32] + //$File "..\vmpi\ichannel.h" [$WIN32] // SDK_SP compat + //$File "..\vmpi\imysqlwrapper.h" [$WIN32] // SDK_SP compat + //$File "..\vmpi\iphelpers.h" [$WIN32] // SDK_SP compat $File "..\common\ISQLDBReplyTarget.h" $File "..\common\map_shared.h" - $File "..\vmpi\messbuf.h" [$WIN32] - $File "..\common\mpi_stats.h" [$WIN32] + //$File "..\vmpi\messbuf.h" [$WIN32] // SDK_SP compat + //$File "..\common\mpi_stats.h" [$WIN32] // SDK_SP compat $File "..\common\MySqlDatabase.h" $File "..\common\pacifier.h" $File "..\common\polylib.h" $File "..\common\scriplib.h" - $File "..\vmpi\threadhelpers.h" [$WIN32] + //$File "..\vmpi\threadhelpers.h" [$WIN32] // SDK_SP compat $File "..\common\threads.h" $File "..\common\utilmatlib.h" - $File "..\vmpi\vmpi_defs.h" [$WIN32] - $File "..\vmpi\vmpi_dispatch.h" [$WIN32] - $File "..\vmpi\vmpi_distribute_work.h" [$WIN32] - $File "..\vmpi\vmpi_filesystem.h" [$WIN32] + //$File "..\vmpi\vmpi_defs.h" [$WIN32] // SDK_SP compat + //$File "..\vmpi\vmpi_dispatch.h" [$WIN32] // SDK_SP compat + //$File "..\vmpi\vmpi_distribute_work.h" [$WIN32] // SDK_SP compat + //$File "..\vmpi\vmpi_filesystem.h" [$WIN32] // SDK_SP compat } $Folder "Public Header Files" @@ -204,7 +204,7 @@ $Project "VRAD" $File "$SRCDIR\public\mathlib\vector2d.h" $File "$SRCDIR\public\mathlib\vector4d.h" $File "$SRCDIR\public\mathlib\vmatrix.h" - $File "..\vmpi\vmpi.h" [$WIN32] + //$File "..\vmpi\vmpi.h" [$WIN32] // SDK_SP compat $File "$SRCDIR\public\vphysics_interface.h" $File "$SRCDIR\public\mathlib\vplane.h" $File "$SRCDIR\public\tier0\vprof.h" @@ -221,10 +221,10 @@ $Project "VRAD" $Lib mathlib $Lib raytrace $Lib tier2 - $Lib vmpi [$WIN32] + //$Lib vmpi [$WIN32] // SDK_SP compat $Lib vtf - $Lib "$LIBCOMMON/lzma" - $File "$SRCDIR\thirdparty\libcurl\lib\win32\libcurl.lib" [$WIN32] + $Lib "$LIBCOMMON/lzma" [$WIN64||$LINUX64] // SDK_MP + //$File "$SRCDIR\thirdparty\libcurl\lib\win32\libcurl.lib" [$WIN32] // SDK_SP compat } $File "notes.txt" diff --git a/src/utils/vrad/vradstaticprops.cpp b/src/utils/vrad/vradstaticprops.cpp index 8864fe9396d..352d07f4d6f 100644 --- a/src/utils/vrad/vradstaticprops.cpp +++ b/src/utils/vrad/vradstaticprops.cpp @@ -77,13 +77,18 @@ class CComputeStaticPropLightingResults ~CComputeStaticPropLightingResults() { m_ColorVertsArrays.PurgeAndDeleteElements(); +#ifdef SDK_MP m_ColorTexelsArrays.PurgeAndDeleteElements(); +#endif } CUtlVector< CUtlVector* > m_ColorVertsArrays; +#ifdef SDK_MP CUtlVector< CUtlVector* > m_ColorTexelsArrays; +#endif }; +#ifdef SDK_MP //----------------------------------------------------------------------------- struct Rasterizer { @@ -217,6 +222,7 @@ void Rasterizer::Build() } } } +#endif //----------------------------------------------------------------------------- @@ -295,8 +301,13 @@ class CVradStaticPropMgr : public IVradStaticPropMgr struct MeshData_t { +#ifdef SDK_MP CUtlVector m_VertexColors; CUtlMemory m_TexelsEncoded; +#else + CUtlVector m_Verts; + #define m_VertexColors m_Verts +#endif int m_nLod; }; @@ -314,6 +325,7 @@ class CVradStaticPropMgr : public IVradStaticPropMgr int m_Flags; bool m_bLightingOriginValid; +#ifdef SDK_MP // Note that all lightmaps for a given prop share the same resolution (and format)--and there can be multiple lightmaps // per prop (if there are multiple pieces--the watercooler is an example). // This is effectively because there's not a good way in hammer for a prop to say "this should be the resolution @@ -321,6 +333,7 @@ class CVradStaticPropMgr : public IVradStaticPropMgr ImageFormat m_LightmapImageFormat; unsigned int m_LightmapImageWidth; unsigned int m_LightmapImageHeight; +#endif }; @@ -1048,11 +1061,13 @@ void CVradStaticPropMgr::UnserializeModels( CUtlBuffer& buf ) m_StaticProps[i].m_Handle = TREEDATA_INVALID_HANDLE; m_StaticProps[i].m_Flags = lump.m_Flags; +#ifdef SDK_MP // Changed this from using DXT1 to RGB888 because the compression artifacts were pretty nasty. // TODO: Consider changing back or basing this on user selection in hammer. m_StaticProps[i].m_LightmapImageFormat = IMAGE_FORMAT_RGB888; m_StaticProps[i].m_LightmapImageWidth = lump.m_nLightmapResolutionX; m_StaticProps[i].m_LightmapImageHeight = lump.m_nLightmapResolutionY; +#endif } } @@ -1216,7 +1231,11 @@ void ComputeDirectLightingAtPoint( Vector &position, Vector &normal, Vector &out //----------------------------------------------------------------------------- void CVradStaticPropMgr::ApplyLightingToStaticProp( int iStaticProp, CStaticProp &prop, const CComputeStaticPropLightingResults *pResults ) { +#ifdef SDK_MP if ( pResults->m_ColorVertsArrays.Count() == 0 && pResults->m_ColorTexelsArrays.Count() == 0 ) +#else + if ( pResults->m_ColorVertsArrays.Count() == 0 ) +#endif return; StaticPropDict_t &dict = m_StaticPropDict[prop.m_ModelIdx]; @@ -1225,7 +1244,9 @@ void CVradStaticPropMgr::ApplyLightingToStaticProp( int iStaticProp, CStaticProp Assert( pStudioHdr && pVtxHdr ); int iCurColorVertsArray = 0; +#ifdef SDK_MP int iCurColorTexelsArray = 0; +#endif for ( int bodyID = 0; bodyID < pStudioHdr->numbodyparts; ++bodyID ) { @@ -1238,7 +1259,9 @@ void CVradStaticPropMgr::ApplyLightingToStaticProp( int iStaticProp, CStaticProp mstudiomodel_t *pStudioModel = pBodyPart->pModel( modelID ); const CUtlVector *colorVerts = pResults->m_ColorVertsArrays.Count() ? pResults->m_ColorVertsArrays[iCurColorVertsArray++] : nullptr; +#ifdef SDK_MP const CUtlVector *colorTexels = pResults->m_ColorTexelsArrays.Count() ? pResults->m_ColorTexelsArrays[iCurColorTexelsArray++] : nullptr; +#endif for ( int nLod = 0; nLod < pVtxHdr->numLODs; nLod++ ) { @@ -1268,6 +1291,7 @@ void CVradStaticPropMgr::ApplyLightingToStaticProp( int iStaticProp, CStaticProp } } +#ifdef SDK_MP if (colorTexels) { // TODO: Consider doing this work in the worker threads, because then we distribute it. @@ -1300,6 +1324,7 @@ void CVradStaticPropMgr::ApplyLightingToStaticProp( int iStaticProp, CStaticProp DumpLightmapLinear( buffer, (*colorTexels), prop.m_LightmapImageWidth, prop.m_LightmapImageHeight ); } } +#endif } } } @@ -1326,11 +1351,16 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr return; } +#ifdef SDK_MP const bool withVertexLighting = (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING) == 0; const bool withTexelLighting = (prop.m_Flags & STATIC_PROP_NO_PER_TEXEL_LIGHTING) == 0; if (!withVertexLighting && !withTexelLighting) return; +#else + if (prop.m_Flags & STATIC_PROP_NO_PER_VERTEX_LIGHTING ) + return; +#endif const int skip_prop = (g_bDisablePropSelfShadowing || (prop.m_Flags & STATIC_PROP_NO_SELF_SHADOWING)) ? prop_index : -1; const int nFlags = ( prop.m_Flags & STATIC_PROP_IGNORE_NORMALS ) ? GATHERLFLAGS_IGNORE_NORMALS : 0; @@ -1345,19 +1375,25 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr for ( int bodyID = 0; bodyID < pStudioHdr->numbodyparts; ++bodyID ) { +#ifdef SDK_MP OptimizedModel::BodyPartHeader_t* pVtxBodyPart = pVtxHdr->pBodyPart( bodyID ); +#endif mstudiobodyparts_t *pBodyPart = pStudioHdr->pBodypart( bodyID ); for ( int modelID = 0; modelID < pBodyPart->nummodels; ++modelID ) { +#ifdef SDK_MP OptimizedModel::ModelHeader_t* pVtxModel = pVtxBodyPart->pModel(modelID); +#endif mstudiomodel_t *pStudioModel = pBodyPart->pModel( modelID ); +#ifdef SDK_MP if (withTexelLighting) { CUtlVector *pColorTexelArray = new CUtlVector; pResults->m_ColorTexelsArrays.AddToTail(pColorTexelArray); } +#endif // light all unique vertexes CUtlVector *pColorVertsArray = new CUtlVector; @@ -1375,11 +1411,13 @@ void CVradStaticPropMgr::ComputeLighting( CStaticProp &prop, int iThread, int pr Assert(vertData); // This can only return NULL on X360 for now +#ifdef SDK_MP // TODO: Move this into its own function. In fact, refactor this whole function. if (withTexelLighting) { GenerateLightmapSamplesForMesh( matPos, matNormal, iThread, skip_prop, nFlags, prop.m_LightmapImageWidth, prop.m_LightmapImageHeight, pStudioHdr, pStudioModel, pVtxModel, meshID, pResults ); } +#endif // If we do lightmapping, we also do vertex lighting as a potential fallback. This may change. for ( int vertexID = 0; vertexID < pStudioMesh->numvertices; ++vertexID ) @@ -1605,6 +1643,7 @@ void CVradStaticPropMgr::SerializeLighting() AddBufferToPak( GetPakFile(), filename, (void*)pVhvHdr, pVertexData - (unsigned char*)pVhvHdr, false ); } +#ifdef SDK_MP for (int i = 0; i < count; ++i) { const int kAlignment = 512; @@ -1661,6 +1700,7 @@ void CVradStaticPropMgr::SerializeLighting() AddBufferToPak(GetPakFile(), filename, (void*)pVhtHdr, pTexelData - (unsigned char*)pVhtHdr, false); } +#endif } #ifdef MPI @@ -1700,6 +1740,7 @@ void CVradStaticPropMgr::VMPI_ProcessStaticProp( int iThread, int iStaticProp, M pBuf->write( curList.Base(), curList.Count() * sizeof( colorVertex_t ) ); } +#ifdef SDK_MP nLists = results.m_ColorTexelsArrays.Count(); pBuf->write(&nLists, sizeof(nLists)); @@ -1710,6 +1751,7 @@ void CVradStaticPropMgr::VMPI_ProcessStaticProp( int iThread, int iStaticProp, M pBuf->write(&count, sizeof(count)); pBuf->write(curList.Base(), curList.Count() * sizeof(colorTexel_t)); } +#endif } //----------------------------------------------------------------------------- @@ -1734,6 +1776,7 @@ void CVradStaticPropMgr::VMPI_ReceiveStaticPropResults( int iStaticProp, Message pBuf->read( pList->Base(), count * sizeof( colorVertex_t ) ); } +#ifdef SDK_MP pBuf->read(&nLists, sizeof(nLists)); for (int i = 0; i < nLists; i++) @@ -1746,6 +1789,7 @@ void CVradStaticPropMgr::VMPI_ReceiveStaticPropResults( int iStaticProp, Message pList->SetSize(count); pBuf->read(pList->Base(), count * sizeof(colorTexel_t)); } +#endif // Apply the results. ApplyLightingToStaticProp( iStaticProp, m_StaticProps[iStaticProp], &results ); @@ -2246,6 +2290,7 @@ const vertexFileHeader_t * mstudiomodel_t::CacheVertexData( void *pModelData ) return pVvdHdr; } +#ifdef SDK_MP // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ @@ -2719,3 +2764,4 @@ static void DumpLightmapLinear( const char* _dstFilename, const CUtlVectorGetFirstSubKey(); controlKeys != NULL; controlKeys = controlKeys->GetNextKey()) diff --git a/src/vgui2/vgui_controls/EditablePanel.cpp b/src/vgui2/vgui_controls/EditablePanel.cpp index 592fe7f3978..2ac00df1f49 100644 --- a/src/vgui2/vgui_controls/EditablePanel.cpp +++ b/src/vgui2/vgui_controls/EditablePanel.cpp @@ -873,9 +873,15 @@ Panel *EditablePanel::HasHotkey(wchar_t key) //----------------------------------------------------------------------------- // Purpose: Shortcut function to setting enabled state of control //----------------------------------------------------------------------------- +#ifdef SDK_MP void EditablePanel::SetControlEnabled(const char *controlName, bool enabled, bool bRecurseDown /*= false*/ ) { Panel *control = FindChildByName(controlName, bRecurseDown); +#else +void EditablePanel::SetControlEnabled(const char *controlName, bool enabled) +{ + Panel *control = FindChildByName(controlName); +#endif if (control) { control->SetEnabled(enabled); @@ -885,9 +891,15 @@ void EditablePanel::SetControlEnabled(const char *controlName, bool enabled, boo //----------------------------------------------------------------------------- // Purpose: Shortcut function to setting visibility state of control //----------------------------------------------------------------------------- +#ifdef SDK_MP void EditablePanel::SetControlVisible(const char *controlName, bool visible, bool bRecurseDown /*= false*/ ) { Panel *control = FindChildByName(controlName, bRecurseDown); +#else +void EditablePanel::SetControlVisible(const char *controlName, bool visible) +{ + Panel *control = FindChildByName(controlName); +#endif if (control) { control->SetVisible(visible); diff --git a/src/vgui2/vgui_controls/Panel.cpp b/src/vgui2/vgui_controls/Panel.cpp index a61e66f330b..02bb45326f6 100644 --- a/src/vgui2/vgui_controls/Panel.cpp +++ b/src/vgui2/vgui_controls/Panel.cpp @@ -5508,12 +5508,19 @@ void Panel::SetSilentMode( bool bSilent ) //----------------------------------------------------------------------------- // Purpose: mouse events will be send to handler panel instead of this panel //----------------------------------------------------------------------------- +#ifdef SDK_MP void Panel::InstallMouseHandler( Panel *pHandler, bool bThisHandlesAsWell /* = false */, bool bMovementEvents /* = false */ ) { m_hMouseEventHandler = pHandler; m_bActOnHandledMouseInput = bThisHandlesAsWell; m_bSendMoveEventsToHandler = bMovementEvents; } +#else +void Panel::InstallMouseHandler( Panel *pHandler ) +{ + m_hMouseEventHandler = pHandler; +} +#endif //----------------------------------------------------------------------------- // Purpose: Prepares the hierarchy panel maps for use (with message maps etc) @@ -8635,7 +8642,11 @@ void VguiPanelGetSortedChildPanelList( Panel *pParentPanel, void *pSortedPanels } } +#ifdef SDK_MP +void VguiPanelGetSortedChildButtonList( Panel *pParentPanel, void *pSortedPanels, char *pchFilter /*= NULL*/, int nFilterType /*= 0*/ ) +#else void VguiPanelGetSortedChildButtonList( Panel *pParentPanel, void *pSortedPanels, const char *pchFilter /*= NULL*/, int nFilterType /*= 0*/ ) +#endif { CUtlSortVector< SortedPanel_t, CSortedPanelYLess > *pList = reinterpret_cast< CUtlSortVector< SortedPanel_t, CSortedPanelYLess >* >( pSortedPanels ); diff --git a/src/vgui2/vgui_controls/PerforceFileExplorer.cpp b/src/vgui2/vgui_controls/PerforceFileExplorer.cpp index dc0f705d38c..efc24afecf9 100644 --- a/src/vgui2/vgui_controls/PerforceFileExplorer.cpp +++ b/src/vgui2/vgui_controls/PerforceFileExplorer.cpp @@ -102,7 +102,11 @@ void PerforceFileExplorer::SetCurrentDirectory( const char *pFullPath ) m_CurrentDirectory = pFullPath; m_CurrentDirectory.StripTrailingSlash(); +#ifdef SDK_MP m_CurrentDirectory.FixSlashes(); +#else + Q_FixSlashes( m_CurrentDirectory.Get() ); +#endif PopulateFileList(); PopulateDriveList(); diff --git a/src/vgui2/vgui_controls/RichText.cpp b/src/vgui2/vgui_controls/RichText.cpp index a7d630fc8a7..2dfcc59d3e2 100644 --- a/src/vgui2/vgui_controls/RichText.cpp +++ b/src/vgui2/vgui_controls/RichText.cpp @@ -2557,12 +2557,20 @@ int RichText::ParseTextStringForUrls( const char *text, int startPos, char *pchU // get the url i += Q_strlen( "" ); +#ifdef SDK_MP Q_strncpy( pchURL, text + i, (int)min( pchURLEnd - text - i + 1, cchURL ) ); +#else + Q_strncpy( pchURL, text + i, min( pchURLEnd - text - i + 1, cchURL ) ); +#endif i += ( pchURLEnd - text - i + 1 ); // get the url text pchURLEnd = Q_strstr( text, "" ); +#ifdef SDK_MP Q_strncpy( pchURLText, text + i, (int)min( pchURLEnd - text - i + 1, cchURLText ) ); +#else + Q_strncpy( pchURLText, text + i, min( pchURLEnd - text - i + 1, cchURLText ) ); +#endif i += ( pchURLEnd - text - i ); i += Q_strlen( "" ); diff --git a/src/vgui2/vgui_controls/consoledialog.cpp b/src/vgui2/vgui_controls/consoledialog.cpp index d1bc4e08208..40592edbbbe 100644 --- a/src/vgui2/vgui_controls/consoledialog.cpp +++ b/src/vgui2/vgui_controls/consoledialog.cpp @@ -1035,7 +1035,11 @@ void CConsolePanel::AddToHistory( const char *commandText, const char *extraText free( extra ); } +#ifdef SDK_MP void CConsolePanel::GetConsoleText( char *pchText, int nBufSize ) const +#else +void CConsolePanel::GetConsoleText( char *pchText, size_t nBufSize ) const +#endif { wchar_t *temp = new wchar_t[nBufSize]; m_pHistory->GetText( 0, temp, nBufSize * (int)sizeof( wchar_t ) ); diff --git a/src/vpc_scripts/groups.vgc b/src/vpc_scripts/groups.vgc index d1fecec5574..78e92e6e958 100644 --- a/src/vpc_scripts/groups.vgc +++ b/src/vpc_scripts/groups.vgc @@ -30,7 +30,8 @@ $Group "game" $Group "shaders" { - //"game_shader_generic_example" + // Differentiated through SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + "game_shader_generic_example" "game_shader_generic_std" "mathlib" @@ -67,10 +68,9 @@ $Group "everything" "vvis_dll" "vvis_launcher" - //"game_shader_generic_example" - - // For Mapbase, we want to override all shaders - "game_shader_generic_std" + // Differentiated through SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + "game_shader_generic_example" + "game_shader_generic_std" // For Mapbase, we want to override all shaders } $Group "dedicated" diff --git a/src/vpc_scripts/projects.vgc b/src/vpc_scripts/projects.vgc index a745d1d8597..a360c2a91ea 100644 --- a/src/vpc_scripts/projects.vgc +++ b/src/vpc_scripts/projects.vgc @@ -28,20 +28,20 @@ $Project "fgdlib" $Project "game_shader_generic_example" { - "materialsystem\stdshaders\game_shader_generic_example_hl2mp.vpc" [$HL2MP] - "materialsystem\stdshaders\game_shader_generic_example_tf.vpc" [$TF] - "materialsystem\stdshaders\game_shader_generic_example_hl2.vpc" [$HL2] - "materialsystem\stdshaders\game_shader_generic_example_episodic.vpc" [$EPISODIC] + "materialsystem\stdshaders\game_shader_generic_example_hl2mp.vpc" [$HL2MP && ($WIN32||$LINUX32)] // SDK_SP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_example_tf.vpc" [$TF && ($WIN32||$LINUX32)] // SDK_SP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_example_hl2.vpc" [$HL2 && ($WIN32||$LINUX32)] // SDK_SP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_example_episodic.vpc" [$EPISODIC && ($WIN32||$LINUX32)] // SDK_SP (see sdk_sp_branch.vpc) } // Use this project if you want to override all std shaders with your own. // By default it will override ALL of them. So feel free to cut it down if you want :) $Project "game_shader_generic_std" { - "materialsystem\stdshaders\game_shader_generic_std_hl2mp.vpc" [$HL2MP] - "materialsystem\stdshaders\game_shader_generic_std_tf.vpc" [$TF] - "materialsystem\stdshaders\game_shader_generic_std_hl2.vpc" [$HL2] - "materialsystem\stdshaders\game_shader_generic_std_episodic.vpc" [$EPISODIC] + "materialsystem\stdshaders\game_shader_generic_std_hl2mp.vpc" [$HL2MP && ($WIN64||$LINUX64)] // SDK_MP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_std_tf.vpc" [$TF && ($WIN64||$LINUX64)] // SDK_MP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_std_hl2.vpc" [$HL2 && ($WIN64||$LINUX64)] // SDK_MP (see sdk_sp_branch.vpc) + "materialsystem\stdshaders\game_shader_generic_std_episodic.vpc" [$EPISODIC && ($WIN64||$LINUX64)] // SDK_MP (see sdk_sp_branch.vpc) } $Project "glview" @@ -66,8 +66,8 @@ $Project "launcher_main" { "launcher_main\launcher_main_mod_hl2mp.vpc" [$HL2MP] "launcher_main\launcher_main_mod_tf.vpc" [$TF] - "launcher_main\launcher_main_mod_hl2.vpc" [$HL2] - "launcher_main\launcher_main_mod_episodic.vpc" [$EPISODIC] + "launcher_main\launcher_main_mod_hl2.vpc" [$HL2&&$SP_LAUNCHER] // SDK_SP (see sdk_sp_branch.vpc) + "launcher_main\launcher_main_mod_episodic.vpc" [$EPISODIC&&$SP_LAUNCHER] // SDK_SP (see sdk_sp_branch.vpc) } $Project "responserules" @@ -82,7 +82,7 @@ $Project "mathlib" $Project "matsys_controls" { - "vgui2\matsys_controls\matsys_controls.vpc" + "vgui2\matsys_controls\matsys_controls.vpc" [$WIN64||$LINUX64] // SDK_MP (see sdk_sp_branch.vpc) } $Project "motionmapper" @@ -92,7 +92,7 @@ $Project "motionmapper" $Project "phonemeextractor" { - "utils\phonemeextractor\phonemeextractor.vpc" [$WIN32] + "utils\phonemeextractor\phonemeextractor.vpc" [$WIN32&&!$CI_RUNNER] } $Project "raytrace" diff --git a/src/vpc_scripts/protobuf_builder.vpc b/src/vpc_scripts/protobuf_builder.vpc index fe1c75eae73..a97e388779c 100644 --- a/src/vpc_scripts/protobuf_builder.vpc +++ b/src/vpc_scripts/protobuf_builder.vpc @@ -11,13 +11,17 @@ $CustomBuildStep "proto" $CommandLine "if not exist $GENERATED_PROTO_DIR mkdir $GENERATED_PROTO_DIR" "\n" \ "$SRCDIR\thirdparty\protobuf-2.6.1\bin\win64\2015\staticcrt\release\protoc.exe --proto_path=$SRCDIR\thirdparty\protobuf-2.6.1\src" \ " --proto_path=$(InputDir) --proto_path=$SRCDIR\gcsdk --proto_path=$SRCDIR\game\shared" \ - " $ADDITIONAL_PROTOC_ARGS --cpp_out=$GENERATED_PROTO_DIR $(InputPath)" [$WINDOWS] + " $ADDITIONAL_PROTOC_ARGS --cpp_out=$GENERATED_PROTO_DIR $(InputPath)" [$WINDOWS&&!$WIN32] $CommandLine "mkdir -p $GENERATED_PROTO_DIR 2> /dev/null;" \ "$SRCDIR/thirdparty/protobuf-2.6.1/bin/linux32/protoc --proto_path=$SRCDIR\thirdparty\protobuf-2.6.1\src" \ " --proto_path=$(InputDir) --proto_path=$SRCDIR\gcsdk --proto_path=$SRCDIR\game\shared" \ " $ADDITIONAL_PROTOC_ARGS --cpp_out=$GENERATED_PROTO_DIR $(InputPath)" [$LINUXALL] + // SP branch support (see sdk_sp_branch.vpc) + $CommandLine "if not exist $GENERATED_PROTO_DIR mkdir $GENERATED_PROTO_DIR" "\n" \ + "$SRCDIR\thirdparty\protobuf-2.6.1\bin\win32\2015\staticcrt\release\protoc.exe --proto_path=$SRCDIR\thirdparty\protobuf-2.6.1\src --proto_path=$(InputDir) --proto_path=$SRCDIR\gcsdk --cpp_out=$GENERATED_PROTO_DIR $(InputPath)" [$WINDOWS&&$WIN32] + $Outputs "$GENERATED_PROTO_DIR\$(InputName).pb.cc;$GENERATED_PROTO_DIR\$(InputName).pb.h" } diff --git a/src/vpc_scripts/sdk_sp_branch.vpc b/src/vpc_scripts/sdk_sp_branch.vpc new file mode 100644 index 00000000000..d0f751dc289 --- /dev/null +++ b/src/vpc_scripts/sdk_sp_branch.vpc @@ -0,0 +1,41 @@ +//----------------------------------------------------------------------------- +// SDK_SP_BRANCH.VPC +// +// This codebase integrates the libraries from Source 2013's singleplayer branch +// as the 32-bit equivalents to the default 64-bit MP libraries. +// They can be switched by specifying "/win32" or "/linux32" in the VPC generation +// options. +// +// More complex logic may be needed if and when 64-bit support is added to singleplayer, +// or if this is expanded to include support for the pre-TF2 SDK MP branch. +// This VPC can be used as a base for that. +// +//----------------------------------------------------------------------------- + +// You can also enable the following conditionals through additional "/define" options +// when calling VPC, rather than changing them here. + +// Enable this if you want to have the launcher exe in your SP game project. +$Conditional SP_LAUNCHER "0" + +//----------------------------------------------------------------------------- + +$Configuration "Debug" +{ + $Compiler + { + // SDK branch conditionals (based on platform for now) + $PreprocessorDefinitions "$BASE;SDK_MP" [$WIN64||$LINUX64] // SDK_MP + $PreprocessorDefinitions "$BASE;SDK_SP;RAD_TELEMETRY_DISABLED" [$WIN32||$LINUX32] // SDK_SP + } +} + +$Configuration "Release" +{ + $Compiler + { + // SDK branch conditionals (based on platform for now) + $PreprocessorDefinitions "$BASE;SDK_MP" [$WIN64||$LINUX64] // SDK_MP + $PreprocessorDefinitions "$BASE;SDK_SP;RAD_TELEMETRY_DISABLED" [$WIN32||$LINUX32] // SDK_SP + } +} diff --git a/src/vpc_scripts/source_base.vpc b/src/vpc_scripts/source_base.vpc index d8639e706a0..84b7773e764 100644 --- a/src/vpc_scripts/source_base.vpc +++ b/src/vpc_scripts/source_base.vpc @@ -51,3 +51,8 @@ $Configuration "Release" $PreprocessorDefinitions "$BASE;MAPBASE_MP" [$MAPBASE&&($HL2MP||$TF)] } } + +//----------------------------------------------------------------------------- + +// MP/SP compatibility +$Include "$SRCDIR\vpc_scripts\sdk_sp_branch.vpc" diff --git a/src/vpc_scripts/source_dll_posix_base.vpc b/src/vpc_scripts/source_dll_posix_base.vpc index 86f3ad32f3d..42f9c32033c 100644 --- a/src/vpc_scripts/source_dll_posix_base.vpc +++ b/src/vpc_scripts/source_dll_posix_base.vpc @@ -35,7 +35,18 @@ $Project { $Folder "Source Files" { - $File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + $File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Not Using Precompiled Headers" + } + } + } + $File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] { $Configuration { diff --git a/src/vpc_scripts/source_dll_win32_base.vpc b/src/vpc_scripts/source_dll_win32_base.vpc index f486cd28455..0575969f97f 100644 --- a/src/vpc_scripts/source_dll_win32_base.vpc +++ b/src/vpc_scripts/source_dll_win32_base.vpc @@ -97,7 +97,18 @@ $Project { $Folder "Source Files" { - $File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + $File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Not Using Precompiled Headers" + } + } + } + $File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] { $Configuration { diff --git a/src/vpc_scripts/source_dll_win32_debug.vpc b/src/vpc_scripts/source_dll_win32_debug.vpc index 01056b4be91..42bd7db3d11 100644 --- a/src/vpc_scripts/source_dll_win32_debug.vpc +++ b/src/vpc_scripts/source_dll_win32_debug.vpc @@ -55,7 +55,8 @@ $Configuration "Debug" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "Program Database for Edit And Continue (/ZI)" [$WIN32] $DebugInformationFormat "Program Database (/Zi)" [$WIN64] diff --git a/src/vpc_scripts/source_dll_win32_release.vpc b/src/vpc_scripts/source_dll_win32_release.vpc index 25abab3e6c8..18ad03f77ac 100644 --- a/src/vpc_scripts/source_dll_win32_release.vpc +++ b/src/vpc_scripts/source_dll_win32_release.vpc @@ -59,7 +59,8 @@ $Configuration "Release" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "Program Database (/Zi)" $SuppressStartupBanner diff --git a/src/vpc_scripts/source_exe_posix_base.vpc b/src/vpc_scripts/source_exe_posix_base.vpc index 01d75bfe45d..552588a575e 100644 --- a/src/vpc_scripts/source_exe_posix_base.vpc +++ b/src/vpc_scripts/source_exe_posix_base.vpc @@ -49,7 +49,18 @@ $Project { $Folder "Source Files" { - $File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + $File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Not Using Precompiled Headers" + } + } + } + $File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] { $Configuration { diff --git a/src/vpc_scripts/source_exe_win_win32_base.vpc b/src/vpc_scripts/source_exe_win_win32_base.vpc index 9e72d23fc62..dafd91b0e80 100644 --- a/src/vpc_scripts/source_exe_win_win32_base.vpc +++ b/src/vpc_scripts/source_exe_win_win32_base.vpc @@ -98,7 +98,18 @@ $Project { $Folder "Source Files" { - $File "$SRCDIR\public\tier0\memoverride.cpp" + // SP/MP branch separation (see sdk_sp_branch.vpc.vpc) + $File "$SRCDIR\public_sp\tier0\memoverride.cpp" [$WIN32||$LINUX32] + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Not Using Precompiled Headers" + } + } + } + $File "$SRCDIR\public\tier0\memoverride.cpp" [$WIN64||$LINUX64] { $Configuration { diff --git a/src/vpc_scripts/source_exe_win_win32_debug.vpc b/src/vpc_scripts/source_exe_win_win32_debug.vpc index ea0cf6e9696..1da1898cb7d 100644 --- a/src/vpc_scripts/source_exe_win_win32_debug.vpc +++ b/src/vpc_scripts/source_exe_win_win32_debug.vpc @@ -55,7 +55,8 @@ $Configuration "Debug" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "Program Database for Edit And Continue (/ZI)" [$WIN32] $DebugInformationFormat "Program Database (/Zi)" [$WIN64] diff --git a/src/vpc_scripts/source_exe_win_win32_release.vpc b/src/vpc_scripts/source_exe_win_win32_release.vpc index b22fb14d110..04f73b0a466 100644 --- a/src/vpc_scripts/source_exe_win_win32_release.vpc +++ b/src/vpc_scripts/source_exe_win_win32_release.vpc @@ -59,7 +59,8 @@ $Configuration "Release" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "Program Database (/Zi)" $SuppressStartupBanner diff --git a/src/vpc_scripts/source_lib_win32_debug.vpc b/src/vpc_scripts/source_lib_win32_debug.vpc index c34c7da6aec..8a3d95b9856 100644 --- a/src/vpc_scripts/source_lib_win32_debug.vpc +++ b/src/vpc_scripts/source_lib_win32_debug.vpc @@ -54,7 +54,8 @@ $Configuration "Debug" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "Program Database for Edit And Continue (/ZI)" [$WIN32] $DebugInformationFormat "Program Database (/Zi)" [$WIN64] diff --git a/src/vpc_scripts/source_lib_win32_release.vpc b/src/vpc_scripts/source_lib_win32_release.vpc index 781a711dd10..6b695a0a2f4 100644 --- a/src/vpc_scripts/source_lib_win32_release.vpc +++ b/src/vpc_scripts/source_lib_win32_release.vpc @@ -56,7 +56,8 @@ $Configuration "Release" $Compiler { // General - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $Resolve#UsingReferences $DebugInformationFormat "C7 Compatible (/Z7)" $SuppressStartupBanner diff --git a/src/vpc_scripts/source_posix_base.vpc b/src/vpc_scripts/source_posix_base.vpc index 05358827a1c..0a3245c4b03 100644 --- a/src/vpc_scripts/source_posix_base.vpc +++ b/src/vpc_scripts/source_posix_base.vpc @@ -42,7 +42,8 @@ $Configuration $Compiler { - $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public_sp;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN32||$LINUX32] // SDK_SP + $AdditionalIncludeDirectories "$SRCDIR\common;$SRCDIR\public;$SRCDIR\public\tier0;$SRCDIR\public\tier1" [$WIN64||$LINUX64] // SDK_MP $PreprocessorDefinitions "$BASE;GNUC;POSIX;COMPILER_GCC;_DLL_EXT=$_DLL_EXT" $PreprocessorDefinitions "$BASE;DEDICATED" [$DEDICATED] // the 10240 in the following line is the output of `sysctl -n kern.maxfilesperproc` @@ -70,7 +71,19 @@ $Configuration $Project { - + $Folder "Source Files" + { + $File "$SRCDIR\devtools\sp_gcc9+support.cpp" [$WIN32||$LINUX32] // SDK_SP + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Not Using Precompiled Headers" + } + } + } + } $Folder "Link Libraries" { $ImpLib "$LIBPUBLIC\tier0" [!$IS_LIB_PROJECT] diff --git a/src/vpc_scripts/source_posix_ninja.vpc b/src/vpc_scripts/source_posix_ninja.vpc index fd5ce53a1bf..67431105d2a 100644 --- a/src/vpc_scripts/source_posix_ninja.vpc +++ b/src/vpc_scripts/source_posix_ninja.vpc @@ -29,7 +29,12 @@ $Macro NINJA_C_DEV_FLAGS "-fstack-protector -fcf-protection" [$DEVELOPMENT_ONL $Macro NINJA_C_FLAGS "$NINJA_ARCH_FLAGS $NINJA_WARN_FLAGS_C $NINJA_C_DEV_FLAGS " \ "-fpch-preprocess -fvar-tracking-assignments " \ "-DVPROF_LEVEL=1 -DGNUC -DNO_HOOK_MALLOC -D_FILE_OFFSET_BITS=64 -fPIC -pipe " \ - "-fdiagnostics-color -fdiagnostics-show-option " + "-fdiagnostics-color -fdiagnostics-show-option " [$WIN64||$LINUX64] // SDK_MP + +$Macro NINJA_C_FLAGS "$NINJA_ARCH_FLAGS $NINJA_WARN_FLAGS_C $NINJA_C_DEV_FLAGS " \ + "-fpch-preprocess -fvar-tracking-assignments " \ + "-DVPROF_LEVEL=1 -DGNUC -DNO_HOOK_MALLOC -DNO_MALLOC_OVERRIDE -fPIC -pipe " \ + "-fdiagnostics-color -fdiagnostics-show-option " [$WIN32||$LINUX32] // SDK_SP // TODO: // Consider -fno-plt? diff --git a/src/vscript/vscript_squirrel.cpp b/src/vscript/vscript_squirrel.cpp index 49dc6b79454..4084a52b71e 100644 --- a/src/vscript/vscript_squirrel.cpp +++ b/src/vscript/vscript_squirrel.cpp @@ -2191,8 +2191,10 @@ bool SquirrelVM::Init() //sqstd_register_iolib(vm_); //sqstd_register_systemlib(vm_); +#ifdef SDK_MP // Save/restore doesn't like it. Use different method for disabling? // bloblib is used in the TF2 SDK sqstd_register_bloblib(vm_); +#endif // There is no vulnerability in getting time. sqstd_register_timelib(vm_);