diff --git a/.github/workflows/MP_linux.yml b/.github/workflows/MP_linux.yml new file mode 100644 index 00000000..2c7547b7 --- /dev/null +++ b/.github/workflows/MP_linux.yml @@ -0,0 +1,42 @@ +name: MP_Linux + +on: + push: + paths: + - '.github/**' + - 'mp/src/**' + pull_request: + paths: + - 'mp/src/**' + +jobs: + build: + runs-on: + ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential gcc-multilib g++-multilib + + - name: Create project + working-directory: mp/src + run: devtools/bin/vpc /sdk2013ce +game /mksln Game + + - name: Build project + working-directory: mp/src + run: make -f Game.mak + + - name: Pack + shell: bash + run: tar cJfv Linux.tar.xz --exclude="*.dbg" mp/game/mod_sdk2013ce/bin + + - name: Upload product + uses: actions/upload-artifact@v2 + with: + name: mp_sdk2013ce + path: Linux.tar.xz diff --git a/README.md b/README.md index d43c1ecb..8a2620ed 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,30 @@ You can find Source 2013 CE's roadmap by going to our [Trello board](https://tre And you can also give us suggestions for fixes and features that you'd like to see in our Discord channel (`#source-SDK-2013-ce`) found in the Source Modding Community server, which you can join [here](https://discord.gg/BD6WpY5). -# Requirements -To be able to use Source 2013 CE you will need to download **Visual Studio 2019** and install: -* MSVC v142 - VS 2019 C++ x64/x86 build tools -* C++ MFC Library for latest v142 build tools (x86 and x64) -* Windows 11 SDK (10.0.22000.0) - -As of July 2023, CE has been tested on Visual Studio 2022 with the latest versions of the requirements listed above. So if desired you can use that instead. +# Compiling + +## Compiling on Windows +1. Install Visual Studio: + Install **Visual Studio 2019** or **Visual Studio 2022** +2. Install dependencies: + - MSVC v142 - VS 2019 C++ x64/x86 build tools + - C++ MFC Library for latest v142 build tools (x86 and x64) + - Windows 11 SDK (10.0.22000.0) +3. Navigate to the source directory (`sp/src` or `mp/src`) +4. Generate the project files, use `createallprojects.bat` or `creategameprojects.bat` +5. Open `Everything.sln` or `Game.sln` +6. Build the project by clicking on "BUILD" on toolbar +7. Click on "Build Solution" +8. Locate the compiled mod(s) in the game folder + +## Compiling on Linux +1. Install dependencies: + - Debian/Ubuntu: `apt-get install build-essential gcc-multilib g++-multilib` + - Arch Linux: `pacman -S base-devel multilib-devel` +2. Navigate to the source directory (`sp/src` or `mp/src`) +3. Generate the project files, use `createallprojects` or `creategameprojects` +4. Build the project `make -f Everything.mak # or make -f Game.mak` +5. Locate the compiled mod(s) in the game folder # Contributing We appreciate any form of help so ideally if you want to help this project out the best way would be to make a pull request. diff --git a/mp/src/devtools/makefile_base_posix.mak b/mp/src/devtools/makefile_base_posix.mak index 7300f402..2e98ae93 100644 --- a/mp/src/devtools/makefile_base_posix.mak +++ b/mp/src/devtools/makefile_base_posix.mak @@ -14,7 +14,8 @@ # + command is executed even if Make is invoked in "do not exec" mode OS := $(shell uname) -HOSTNAME := $(shell hostname) +# Creates errors on Arch Linux and is unused +# HOSTNAME := $(shell hostname) -include $(SRCROOT)/devtools/steam_def.mak -include $(SRCROOT)/devtools/sourcesdk_def.mak diff --git a/mp/src/game/client/clientmode_shared.cpp b/mp/src/game/client/clientmode_shared.cpp index 622208a4..36c34420 100644 --- a/mp/src/game/client/clientmode_shared.cpp +++ b/mp/src/game/client/clientmode_shared.cpp @@ -1136,7 +1136,7 @@ void ClientModeShared::FireGameEvent( IGameEvent *event ) } } - if ( team == 0 && GetLocalTeam() > 0 ) + if ( team == 0 && GetLocalTeam() ) { bValidTeam = false; } diff --git a/mp/src/game/client/hl2/hud_damageindicator.cpp b/mp/src/game/client/hl2/hud_damageindicator.cpp index 9de538a0..710a57d4 100644 --- a/mp/src/game/client/hl2/hud_damageindicator.cpp +++ b/mp/src/game/client/hl2/hud_damageindicator.cpp @@ -179,7 +179,7 @@ void CHudDamageIndicator::DrawDamageIndicator(int side) int x1 = m_flDmgX; int x2 = m_flDmgX + m_flDmgWide; int y[4] = { (int)m_flDmgY, (int)(m_flDmgY + insetY), (int)(m_flDmgY + m_flDmgTall1 - insetY), (int)(m_flDmgY + m_flDmgTall1) }; - int alpha[4] = { 0.0f, 1.0f, 1.0f, 0.0f }; + int alpha[4] = { 0, 1, 1, 0 }; // see if we're high damage bool bHighDamage = false; @@ -192,10 +192,10 @@ void CHudDamageIndicator::DrawDamageIndicator(int side) y[1] = 0.0f; y[2] = GetTall(); y[3] = GetTall(); - alpha[0] = 1.0f; - alpha[1] = 0.0f; - alpha[2] = 0.0f; - alpha[3] = 1.0f; + alpha[0] = 1; + alpha[1] = 0; + alpha[2] = 0; + alpha[3] = 1; bHighDamage = true; } diff --git a/mp/src/game/client/vgui_netgraphpanel.cpp b/mp/src/game/client/vgui_netgraphpanel.cpp index adf3e4b9..f7b54898 100644 --- a/mp/src/game/client/vgui_netgraphpanel.cpp +++ b/mp/src/game/client/vgui_netgraphpanel.cpp @@ -54,9 +54,9 @@ static ConVar net_graphproportionalfont( "net_graphproportionalfont", "1", FCVAR #define NUM_LATENCY_SAMPLES 8 -#define GRAPH_RED (0.9 * 255) -#define GRAPH_GREEN (0.9 * 255) -#define GRAPH_BLUE (0.7 * 255) +#define GRAPH_RED (int32)(0.9 * 255) +#define GRAPH_GREEN (int32)(0.9 * 255) +#define GRAPH_BLUE (int32)(0.7 * 255) #define LERP_HEIGHT 24 diff --git a/mp/src/game/server/ai_behavior_standoff.cpp b/mp/src/game/server/ai_behavior_standoff.cpp index 4f5f7469..3c41653d 100644 --- a/mp/src/game/server/ai_behavior_standoff.cpp +++ b/mp/src/game/server/ai_behavior_standoff.cpp @@ -25,7 +25,7 @@ ConVar DrawBattleLines( "ai_drawbattlelines", "0", FCVAR_CHEAT ); -static AI_StandoffParams_t AI_DEFAULT_STANDOFF_PARAMS = { AIHCR_MOVE_ON_COVER, true, 1.5, 2.5, 1, 3, 25, 0 }; +static AI_StandoffParams_t AI_DEFAULT_STANDOFF_PARAMS = { AIHCR_MOVE_ON_COVER, true, false, 1.5, 2.5, 1, 3, 25, false, 0.0 }; #define MAKE_ACTMAP_KEY( posture, activity ) ( (((unsigned)(posture)) << 16) | ((unsigned)(activity)) ) diff --git a/mp/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp b/mp/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp index a798f27f..432ad796 100644 --- a/mp/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp +++ b/mp/src/game/shared/hl2mp/hl2mp_playeranimstate.cpp @@ -107,7 +107,8 @@ Activity CHL2MPPlayerAnimState::TranslateActivity( Activity actDesired ) if ( GetHL2MPPlayer()->GetActiveWeapon() ) { - translateActivity = GetHL2MPPlayer()->GetActiveWeapon()->ActivityOverride( translateActivity, false ); + bool activityOverrideValue = false; + translateActivity = GetHL2MPPlayer()->GetActiveWeapon()->ActivityOverride( translateActivity, &activityOverrideValue ); } return translateActivity; diff --git a/mp/src/lib/public/linux32/libtogl.so b/mp/src/lib/public/linux32/libtogl.so new file mode 100755 index 00000000..06f8ff45 Binary files /dev/null and b/mp/src/lib/public/linux32/libtogl.so differ diff --git a/mp/src/lib/public/linux32/mathlib.a b/mp/src/lib/public/linux32/mathlib.a index 51797819..1e8d7f35 100644 Binary files a/mp/src/lib/public/linux32/mathlib.a and b/mp/src/lib/public/linux32/mathlib.a differ diff --git a/mp/src/lib/public/linux32/raytrace.a b/mp/src/lib/public/linux32/raytrace.a index 575d0f78..1fba2a9d 100644 Binary files a/mp/src/lib/public/linux32/raytrace.a and b/mp/src/lib/public/linux32/raytrace.a differ diff --git a/mp/src/lib/public/linux32/tier1.a b/mp/src/lib/public/linux32/tier1.a index 4490368f..39641f11 100644 Binary files a/mp/src/lib/public/linux32/tier1.a and b/mp/src/lib/public/linux32/tier1.a differ diff --git a/mp/src/lib/public/linux32/vgui_controls.a b/mp/src/lib/public/linux32/vgui_controls.a index 12e4ea9e..86928e6b 100644 Binary files a/mp/src/lib/public/linux32/vgui_controls.a and b/mp/src/lib/public/linux32/vgui_controls.a differ diff --git a/mp/src/mathlib/sse.cpp b/mp/src/mathlib/sse.cpp index 7240e5ed..9b1cae62 100644 --- a/mp/src/mathlib/sse.cpp +++ b/mp/src/mathlib/sse.cpp @@ -62,8 +62,8 @@ _PS_EXTERN_CONST(am_pi_o_2, (float)(M_PI / 2.0)); _PS_EXTERN_CONST(am_2_o_pi, (float)(2.0 / M_PI)); _PS_EXTERN_CONST(am_pi_o_4, (float)(M_PI / 4.0)); _PS_EXTERN_CONST(am_4_o_pi, (float)(4.0 / M_PI)); -_PS_EXTERN_CONST_TYPE(am_sign_mask, int32, 0x80000000); -_PS_EXTERN_CONST_TYPE(am_inv_sign_mask, int32, ~0x80000000); +_PS_EXTERN_CONST_TYPE(am_sign_mask, int32, (int32)0x80000000); +_PS_EXTERN_CONST_TYPE(am_inv_sign_mask, int32, (int32)~0x80000000); _PS_EXTERN_CONST_TYPE(am_min_norm_pos,int32, 0x00800000); _PS_EXTERN_CONST_TYPE(am_mant_mask, int32, 0x7f800000); _PS_EXTERN_CONST_TYPE(am_inv_mant_mask, int32, ~0x7f800000); @@ -341,8 +341,8 @@ float _SSE_InvRSquared(const float* v) // #define _PS_CONST(Name, Val) static const ALIGN16 float _ps_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } #define _PS_CONST_TYPE(Name, Type, Val) static const ALIGN16 Type _ps_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } -_PS_CONST_TYPE(sign_mask, int, 0x80000000); -_PS_CONST_TYPE(inv_sign_mask, int, ~0x80000000); +_PS_CONST_TYPE(sign_mask, int, (int32)0x80000000); +_PS_CONST_TYPE(inv_sign_mask, int, (int32)~0x80000000); #define _PI32_CONST(Name, Val) static const ALIGN16 int _pi32_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } diff --git a/mp/src/mathlib/sseconst.cpp b/mp/src/mathlib/sseconst.cpp index 2f923193..b3dc57ba 100644 --- a/mp/src/mathlib/sseconst.cpp +++ b/mp/src/mathlib/sseconst.cpp @@ -39,23 +39,23 @@ const fltx4 g_QuatMultRowSign[4] = }; const int32 ALIGN16 g_SIMD_clear_signmask[4] ALIGN16_POST = {0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff}; -const int32 ALIGN16 g_SIMD_signmask[4] ALIGN16_POST = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; -const int32 ALIGN16 g_SIMD_lsbmask[4] ALIGN16_POST = { 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe }; -const int32 ALIGN16 g_SIMD_clear_wmask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; -const int32 ALIGN16 g_SIMD_AllOnesMask[4] ALIGN16_POST = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; // ~0,~0,~0,~0 +const int32 ALIGN16 g_SIMD_signmask[4] ALIGN16_POST = { (int32)0x80000000, (int32)0x80000000, (int32)0x80000000, (int32)0x80000000 }; +const int32 ALIGN16 g_SIMD_lsbmask[4] ALIGN16_POST = { (int32)0xfffffffe, (int32)0xfffffffe, (int32)0xfffffffe, (int32)0xfffffffe }; +const int32 ALIGN16 g_SIMD_clear_wmask[4] ALIGN16_POST = { (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff, 0 }; +const int32 ALIGN16 g_SIMD_AllOnesMask[4] ALIGN16_POST = { (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff }; // ~0,~0,~0,~0 const int32 ALIGN16 g_SIMD_Low16BitsMask[4] ALIGN16_POST = { 0xffff, 0xffff, 0xffff, 0xffff }; // 0xffff x 4 const int32 ALIGN16 g_SIMD_ComponentMask[4][4] ALIGN16_POST = { - { 0xFFFFFFFF, 0, 0, 0 }, { 0, 0xFFFFFFFF, 0, 0 }, { 0, 0, 0xFFFFFFFF, 0 }, { 0, 0, 0, 0xFFFFFFFF } + { (int32)0xFFFFFFFF, 0, 0, 0 }, { 0, (int32)0xFFFFFFFF, 0, 0 }, { 0, 0, (int32)0xFFFFFFFF, 0 }, { 0, 0, 0, (int32)0xFFFFFFFF } }; const int32 ALIGN16 g_SIMD_SkipTailMask[4][4] ALIGN16_POST = { - { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }, - { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 }, - { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 }, - { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 }, + { (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff }, + { (int32)0xffffffff, 0x00000000, 0x00000000, 0x00000000 }, + { (int32)0xffffffff, (int32)0xffffffff, 0x00000000, 0x00000000 }, + { (int32)0xffffffff, (int32)0xffffffff, (int32)0xffffffff, 0x00000000 }, }; diff --git a/mp/src/public/particles/particles.h b/mp/src/public/particles/particles.h index 4066d85e..37af4bf5 100644 --- a/mp/src/public/particles/particles.h +++ b/mp/src/public/particles/particles.h @@ -1391,7 +1391,7 @@ class CParticleCollection -class CM128InitialAttributeIterator : public CStridedConstPtr +class CM128InitialAttributeIterator : public CFltx4StridedConstPtr { public: FORCEINLINE CM128InitialAttributeIterator( int nAttribute, CParticleCollection *pParticles ) @@ -1401,7 +1401,7 @@ class CM128InitialAttributeIterator : public CStridedConstPtr }; -class CM128AttributeIterator : public CStridedConstPtr +class CM128AttributeIterator : public CFltx4StridedConstPtr { public: FORCEINLINE CM128AttributeIterator( int nAttribute, CParticleCollection *pParticles ) @@ -1419,7 +1419,7 @@ class C4IAttributeIterator : public CStridedConstPtr } }; -class CM128AttributeWriteIterator : public CStridedPtr +class CM128AttributeWriteIterator : public CFltx4StridedPtr { public: FORCEINLINE CM128AttributeWriteIterator( void ) diff --git a/mp/src/public/tier1/ilocalize.h b/mp/src/public/tier1/ilocalize.h index a2e2a246..cbdb8f6e 100644 --- a/mp/src/public/tier1/ilocalize.h +++ b/mp/src/public/tier1/ilocalize.h @@ -23,11 +23,10 @@ typedef unsigned short wchar_t; #define _WCHAR_T_DEFINED #endif -class CLocalizedStringArg; // direct references to localized strings typedef unsigned long StringIndex_t; -const unsigned long INVALID_LOCALIZE_STRING_INDEX = (StringIndex_t)-1; +const unsigned long INVALID_LOCALIZE_STRING_INDEX = (StringIndex_t) -1; //----------------------------------------------------------------------------- // Purpose: Handles localization of text @@ -36,154 +35,126 @@ const unsigned long INVALID_LOCALIZE_STRING_INDEX = (StringIndex_t)-1; abstract_class ILocalize { public: - // adds the contents of a file to the localization table - virtual bool AddFile(const char* fileName, const char* pPathID = NULL, bool bIncludeFallbackSearchPaths = false) = 0; + // adds the contents of a file to the localization table + virtual bool AddFile( const char *fileName, const char *pPathID = NULL, bool bIncludeFallbackSearchPaths = false ) = 0; + + // Remove all strings from the table + virtual void RemoveAll() = 0; + + // Finds the localized text for tokenName + virtual wchar_t *Find(char const *tokenName) = 0; + + // finds the index of a token by token name, INVALID_STRING_INDEX if not found + virtual StringIndex_t FindIndex(const char *tokenName) = 0; + + // gets the values by the string index + virtual const char *GetNameByIndex(StringIndex_t index) = 0; + virtual wchar_t *GetValueByIndex(StringIndex_t index) = 0; + + /////////////////////////////////////////////////////////////////// + // the following functions should only be used by localization editors + + // iteration functions + virtual StringIndex_t GetFirstStringIndex() = 0; + // returns the next index, or INVALID_STRING_INDEX if no more strings available + virtual StringIndex_t GetNextStringIndex(StringIndex_t index) = 0; + + // adds a single name/unicode string pair to the table + virtual void AddString( const char *tokenName, wchar_t *unicodeString, const char *fileName ) = 0; + + // changes the value of a string + virtual void SetValueByIndex(StringIndex_t index, wchar_t *newValue) = 0; + + // saves the entire contents of the token tree to the file + virtual bool SaveToFile( const char *fileName ) = 0; + + // iterates the filenames + virtual int GetLocalizationFileCount() = 0; + virtual const char *GetLocalizationFileName(int index) = 0; + + // returns the name of the file the specified localized string is stored in + virtual const char *GetFileNameByIndex(StringIndex_t index) = 0; + + // for development only, reloads localization files + virtual void ReloadLocalizationFiles( ) = 0; + + virtual const char *FindAsUTF8( const char *pchTokenName ) = 0; + + // need to replace the existing ConstructString with this + virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const char *tokenName, KeyValues *localizationVariables) = 0; + virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, StringIndex_t unlocalizedTextSymbol, KeyValues *localizationVariables) = 0; + + /////////////////////////////////////////////////////////////////// + // static interface + + // converts an english string to unicode + // returns the number of wchar_t in resulting string, including null terminator + static int ConvertANSIToUnicode(const char *ansi, OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicode, int unicodeBufferSizeInBytes); + + // converts an unicode string to an english string + // unrepresentable characters are converted to system default + // returns the number of characters in resulting string, including null terminator + static int ConvertUnicodeToANSI(const wchar_t *unicode, OUT_Z_BYTECAP(ansiBufferSize) char *ansi, int ansiBufferSize); - // Remove all strings from the table - virtual void RemoveAll() = 0; + // builds a localized formatted string + // uses the format strings first: %s1, %s2, ... unicode strings (wchar_t *) + template < typename T > + static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOuput, int unicodeBufferSizeInBytes, const T *formatString, int numFormatParameters, ...) + { + va_list argList; + va_start( argList, numFormatParameters ); - // Finds the localized text for tokenName - virtual wchar_t* Find(char const* tokenName) = 0; - - // finds the index of a token by token name, INVALID_STRING_INDEX if not found - virtual StringIndex_t FindIndex(const char* tokenName) = 0; - - // gets the values by the string index - virtual const char* GetNameByIndex(StringIndex_t index) = 0; - virtual wchar_t* GetValueByIndex(StringIndex_t index) = 0; - - /////////////////////////////////////////////////////////////////// - // the following functions should only be used by localization editors - - // iteration functions - virtual StringIndex_t GetFirstStringIndex() = 0; - // returns the next index, or INVALID_STRING_INDEX if no more strings available - virtual StringIndex_t GetNextStringIndex(StringIndex_t index) = 0; - - // adds a single name/unicode string pair to the table - virtual void AddString(const char* tokenName, wchar_t* unicodeString, const char* fileName) = 0; - - // changes the value of a string - virtual void SetValueByIndex(StringIndex_t index, wchar_t* newValue) = 0; - - // saves the entire contents of the token tree to the file - virtual bool SaveToFile(const char* fileName) = 0; - - // iterates the filenames - virtual int GetLocalizationFileCount() = 0; - virtual const char* GetLocalizationFileName(int index) = 0; - - // returns the name of the file the specified localized string is stored in - virtual const char* GetFileNameByIndex(StringIndex_t index) = 0; - - // for development only, reloads localization files - virtual void ReloadLocalizationFiles() = 0; - - virtual const char* FindAsUTF8(const char* pchTokenName) = 0; - - // need to replace the existing ConstructString with this - virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const char* tokenName, KeyValues* localizationVariables) = 0; - virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, StringIndex_t unlocalizedTextSymbol, KeyValues* localizationVariables) = 0; - - template - FORCEINLINE wchar_t* FindSafe(const char(&token)[len]) - { - if (wchar_t* find = Find(token)) - return find; - static wchar_t fallback[len]; - ConvertANSIToUnicode(token, fallback, sizeof(fallback)); - return fallback; - } - - /////////////////////////////////////////////////////////////////// - // static interface - - // converts an english string to unicode - // returns the number of wchar_t in resulting string, including null terminator - static int ConvertANSIToUnicode(const char* ansi, OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicode, int unicodeBufferSizeInBytes); - - // Converts given multi byte character array to wchar, whatever that is on this system. - // Output parameter *utf16 must be nullptr before getting passed in here as it will be allocated within. - // Returns amount of characters that the *utf16 buffer contains, including null terminator, not size in bytes (which would be multiply sizeof(wchar_t)). - static int ConvertUTF8ToUTF16(const char* utf8, wchar_t** utf16); - - // converts an unicode string to an english string - // unrepresentable characters are converted to system default - // returns the number of characters in resulting string, including null terminator - static int ConvertUnicodeToANSI(const wchar_t* unicode, OUT_Z_BYTECAP(ansiBufferSize) char* ansi, int ansiBufferSize); - - // Converts from a wchar character array to a dynamic multi byte array. - // Output parameter *utf8 must be nullptr before getting passed in here as it will be allocated within. - // Returns amount of characters that the *utf8 buffer contains, including null terminator, not size in bytes. - static int ConvertUTF16ToUTF8(const wchar_t* utf16, char** utf8); - - // builds a localized formatted string - // uses the format strings first: %s1, %s2, ... unicode strings (wchar_t *) - template < typename T > - static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOuput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, ...) - { - va_list argList; - va_start(argList, numFormatParameters); - - ConstructStringVArgsInternal(unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); - - va_end(argList); - } - - template < typename T > - static void ConstructStringVArgs(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOuput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, va_list argList) - { - ConstructStringVArgsInternal(unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); - } - - template < typename T > - static void ConstructStringArgs(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOuput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, const CLocalizedStringArg* argList) - { - ConstructStringArgsInternal(unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); - } + ConstructStringVArgsInternal( unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList ); - template < typename T > - static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOutput, int unicodeBufferSizeInBytes, const T* formatString, KeyValues* localizationVariables) - { - ConstructStringKeyValuesInternal(unicodeOutput, unicodeBufferSizeInBytes, formatString, localizationVariables); - } + va_end( argList ); + } + + template < typename T > + static void ConstructStringVArgs(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOuput, int unicodeBufferSizeInBytes, const T *formatString, int numFormatParameters, va_list argList) + { + ConstructStringVArgsInternal( unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList ); + } + + template < typename T > + static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T *unicodeOutput, int unicodeBufferSizeInBytes, const T *formatString, KeyValues *localizationVariables) + { + ConstructStringKeyValuesInternal( unicodeOutput, unicodeBufferSizeInBytes, formatString, localizationVariables ); + } private: - // internal "interface" - static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, int numFormatParameters, va_list argList); - static void ConstructStringArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, int numFormatParameters, const CLocalizedStringArg* argList); - static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, int numFormatParameters, va_list argList); - static void ConstructStringArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, int numFormatParameters, const CLocalizedStringArg* argList); - - static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, KeyValues* localizationVariables); - static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, KeyValues* localizationVariables); + // internal "interface" + static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char *unicodeOutput, int unicodeBufferSizeInBytes, const char *formatString, int numFormatParameters, va_list argList); + static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t *formatString, int numFormatParameters, va_list argList); + + static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char *unicodeOutput, int unicodeBufferSizeInBytes, const char *formatString, KeyValues *localizationVariables); + static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t *unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t *formatString, KeyValues *localizationVariables); }; #ifdef GC -typedef char locchar_t; + typedef char locchar_t; -#define loc_snprintf Q_snprintf -#define loc_sprintf_safe V_sprintf_safe -#define loc_sncat Q_strncat -#define loc_scat_safe V_strcat_safe -#define loc_sncpy Q_strncpy -#define loc_scpy_safe V_strcpy_safe -#define loc_strlen Q_strlen -#define LOCCHAR( x ) x + #define loc_snprintf Q_snprintf + #define loc_sprintf_safe V_sprintf_safe + #define loc_sncat Q_strncat + #define loc_scat_safe V_strcat_safe + #define loc_sncpy Q_strncpy + #define loc_scpy_safe V_strcpy_safe + #define loc_strlen Q_strlen + #define LOCCHAR( x ) x #else -typedef wchar_t locchar_t; + typedef wchar_t locchar_t; -#define loc_snprintf V_snwprintf -#define loc_sprintf_safe V_swprintf_safe -#define loc_sncat V_wcsncat -#define loc_scat_safe V_wcscat_safe -#define loc_sncpy Q_wcsncpy -#define loc_scpy_safe V_wcscpy_safe -#define loc_strlen Q_wcslen -#define LOCCHAR(x) L ## x + #define loc_snprintf V_snwprintf + #define loc_sprintf_safe V_swprintf_safe + #define loc_sncat V_wcsncat + #define loc_scat_safe V_wcscat_safe + #define loc_sncpy Q_wcsncpy + #define loc_scpy_safe V_wcscpy_safe + #define loc_strlen Q_wcslen + #define LOCCHAR(x) L ## x #endif @@ -195,8 +166,8 @@ template < typename T > class TypedKeyValuesStringHelper { public: - static const T* Read(KeyValues* pKeyValues, const char* pKeyName, const T* pDefaultValue); - static void Write(KeyValues* pKeyValues, const char* pKeyName, const T* pValue); + static const T *Read( KeyValues *pKeyValues, const char *pKeyName, const T *pDefaultValue ); + static void Write( KeyValues *pKeyValues, const char *pKeyName, const T *pValue ); }; // -------------------------------------------------------------------------- @@ -205,8 +176,8 @@ template < > class TypedKeyValuesStringHelper { public: - static const char* Read(KeyValues* pKeyValues, const char* pKeyName, const char* pDefaultValue) { return pKeyValues->GetString(pKeyName, pDefaultValue); } - static void Write(KeyValues* pKeyValues, const char* pKeyName, const char* pValue) { pKeyValues->SetString(pKeyName, pValue); } + static const char *Read( KeyValues *pKeyValues, const char *pKeyName, const char *pDefaultValue ) { return pKeyValues->GetString( pKeyName, pDefaultValue ); } + static void Write( KeyValues *pKeyValues, const char *pKeyName, const char *pValue ) { pKeyValues->SetString( pKeyName, pValue ); } }; // -------------------------------------------------------------------------- @@ -215,13 +186,13 @@ template < > class TypedKeyValuesStringHelper { public: - static const wchar_t* Read(KeyValues* pKeyValues, const char* pKeyName, const wchar_t* pDefaultValue) { return pKeyValues->GetWString(pKeyName, pDefaultValue); } - static void Write(KeyValues* pKeyValues, const char* pKeyName, const wchar_t* pValue) { pKeyValues->SetWString(pKeyName, pValue); } + static const wchar_t *Read( KeyValues *pKeyValues, const char *pKeyName, const wchar_t *pDefaultValue ) { return pKeyValues->GetWString( pKeyName, pDefaultValue ); } + static void Write( KeyValues *pKeyValues, const char *pKeyName, const wchar_t *pValue ) { pKeyValues->SetWString( pKeyName, pValue ); } }; // -------------------------------------------------------------------------- // Purpose: CLocalizedStringArg<> is a class that will take a variable of any -// arbitrary type and convert it to a string of whatever character type +// arbitary type and convert it to a string of whatever character type // we're using for localization (locchar_t). // // Independently it isn't very useful, though it can be used to sort-of- @@ -235,49 +206,95 @@ class TypedKeyValuesStringHelper // handle weird combinations of const/volatile/whatever automatically. // -------------------------------------------------------------------------- +// The base implementation doesn't do anything except fail to compile if you +// use it. Getting an "incomplete type" error here means that you tried to construct +// a localized string with a type that doesn't have a specialization. +template < typename T > +class CLocalizedStringArg; + // -------------------------------------------------------------------------- -#ifdef _WIN32 -#define ___WIDECHAR_PRINT_FORMAT_WIDECHAR LOCCHAR("%s") -#define ___WIDECHAR_PRINT_FORMAT_ANSICHAR LOCCHAR("%S") // Thanks, microsoft -#elif defined(POSIX) -#define ___WIDECHAR_PRINT_FORMAT_WIDECHAR LOCCHAR("%ls") -#define ___WIDECHAR_PRINT_FORMAT_ANSICHAR LOCCHAR("%s") -#else -#warning "ILocalize needs some string macros defined!" -#endif +template < typename T > +class CLocalizedStringArgStringImpl +{ +public: + enum { kIsValid = true }; + + CLocalizedStringArgStringImpl( const locchar_t *pStr ) : m_pStr( pStr ) { } + + const locchar_t *GetLocArg() const { Assert( m_pStr ); return m_pStr; } + +private: + const locchar_t *m_pStr; +}; + +// -------------------------------------------------------------------------- -class CLocalizedStringArg +template < typename T > +class CLocalizedStringArg : public CLocalizedStringArgStringImpl { public: - template , std::is_unsigned, std::bool_constant>, int> = 0> - CLocalizedStringArg(U value) : CLocalizedStringArg(value, LOCCHAR("%u")) {} - template , std::is_unsigned, std::bool_constant>, int> = 1> - CLocalizedStringArg(U value) : CLocalizedStringArg(value, LOCCHAR("%llu")) {} - template , std::is_signed, std::bool_constant>, int> = 2> - CLocalizedStringArg(U value) : CLocalizedStringArg(value, LOCCHAR("%d")) {} - template , std::is_signed, std::bool_constant>, int> = 3> - CLocalizedStringArg(U value) : CLocalizedStringArg(value, LOCCHAR("%lld")) {} - - template , int> = 4> - CLocalizedStringArg(U value) : CLocalizedStringArg(static_cast>(value)) {} - - template , int> = 5> - CLocalizedStringArg(U value) : CLocalizedStringArg(value, LOCCHAR("%.2f")) {} - - template , std::is_same>, int> = 6> - CLocalizedStringArg(U pszValue) : CLocalizedStringArg(pszValue, ___WIDECHAR_PRINT_FORMAT_ANSICHAR) {} - template , std::is_same>, int> = 7> - CLocalizedStringArg(U pszValue) : CLocalizedStringArg(pszValue, ___WIDECHAR_PRINT_FORMAT_WIDECHAR) {} + CLocalizedStringArg( const locchar_t *pStr ) : CLocalizedStringArgStringImpl( pStr ) { } +}; + +// -------------------------------------------------------------------------- +template < typename T > +class CLocalizedStringArgPrintfImpl +{ public: - const locchar_t* GetLocArg() const { return m_cBuffer; } + enum { kIsValid = true }; + + CLocalizedStringArgPrintfImpl( T value, const locchar_t *loc_Format ) { loc_snprintf( m_cBuffer, kBufferSize, loc_Format, value ); } + + const locchar_t *GetLocArg() const { return m_cBuffer; } private: - template CLocalizedStringArg(T value, const locchar_t* loc_Format) { loc_snprintf(m_cBuffer, kBufferSize, loc_Format, value); } + enum { kBufferSize = 128, }; + locchar_t m_cBuffer[ kBufferSize ]; +}; + +// -------------------------------------------------------------------------- + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg( uint16 unValue ) : CLocalizedStringArgPrintfImpl( unValue, LOCCHAR("%u") ) { } +}; + +// -------------------------------------------------------------------------- + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg( uint32 unValue ) : CLocalizedStringArgPrintfImpl( unValue, LOCCHAR("%u") ) { } +}; + +// -------------------------------------------------------------------------- + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg( uint64 unValue ) : CLocalizedStringArgPrintfImpl( unValue, LOCCHAR("%llu") ) { } +}; - static constexpr int kBufferSize = 128; - locchar_t m_cBuffer[kBufferSize]; +// -------------------------------------------------------------------------- + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + // Display one decimal point if we've got a value less than one, and no point + // if we're greater than one or are effectively zero. + CLocalizedStringArg( float fValue ) + : CLocalizedStringArgPrintfImpl( fValue, + fabsf( fValue ) <= FLT_EPSILON || fabsf( fValue ) >= 1.0f ? LOCCHAR("%.0f") : LOCCHAR("%.1f") ) + { + // + } }; // -------------------------------------------------------------------------- @@ -286,36 +303,151 @@ class CLocalizedStringArg class CConstructLocalizedString { public: - template < typename... T, typename = std::enable_if_t > - CConstructLocalizedString(const locchar_t* loc_Format, T... args) - { - m_loc_Buffer[0] = '\0'; - - if (loc_Format) - { - const CLocalizedStringArg locArgs[] = { args... }; - ::ILocalize::ConstructStringArgs(m_loc_Buffer, sizeof(m_loc_Buffer), loc_Format, ARRAYSIZE(locArgs), locArgs); - } - } - - CConstructLocalizedString(const locchar_t* loc_Format, KeyValues* pKeyValues) - { - m_loc_Buffer[0] = '\0'; - - if (loc_Format && pKeyValues) - { - ::ILocalize::ConstructString(m_loc_Buffer, sizeof(m_loc_Buffer), loc_Format, pKeyValues); - } - } - - operator const locchar_t* () const - { - return m_loc_Buffer; - } + template < typename T > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0 ) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, sizeof( m_loc_Buffer ), loc_Format, 1, CLocalizedStringArg( arg0 ).GetLocArg() ); + } + } + + template < typename T, typename U > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0, U arg1 ) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, sizeof( m_loc_Buffer ), loc_Format, 2, CLocalizedStringArg( arg0 ).GetLocArg(), CLocalizedStringArg( arg1 ).GetLocArg() ); + } + } + + template < typename T, typename U, typename V > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0, U arg1, V arg2 ) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, + sizeof( m_loc_Buffer ), + loc_Format, + 3, + CLocalizedStringArg( arg0 ).GetLocArg(), + CLocalizedStringArg( arg1 ).GetLocArg(), + CLocalizedStringArg( arg2 ).GetLocArg() ); + } + } + + template < typename T, typename U, typename V, typename W > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0, U arg1, V arg2, W arg3 ) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, + sizeof( m_loc_Buffer ), + loc_Format, + 4, + CLocalizedStringArg( arg0 ).GetLocArg(), + CLocalizedStringArg( arg1 ).GetLocArg(), + CLocalizedStringArg( arg2 ).GetLocArg(), + CLocalizedStringArg( arg3 ).GetLocArg() ); + } + } + + template < typename T, typename U, typename V, typename W, typename X, typename Y > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5 ) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, + sizeof( m_loc_Buffer ), + loc_Format, + 6, + CLocalizedStringArg( arg0 ).GetLocArg(), + CLocalizedStringArg( arg1 ).GetLocArg(), + CLocalizedStringArg( arg2 ).GetLocArg(), + CLocalizedStringArg( arg3 ).GetLocArg(), + CLocalizedStringArg( arg4 ).GetLocArg(), + CLocalizedStringArg( arg5 ).GetLocArg() ); + } + } + + template < typename T, typename U, typename V, typename W, typename X, typename Y, typename Z > + CConstructLocalizedString( const locchar_t *loc_Format, T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5, Z arg6) + { + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + COMPILE_TIME_ASSERT( CLocalizedStringArg::kIsValid ); + + m_loc_Buffer[0] = '\0'; + + if ( loc_Format ) + { + ::ILocalize::ConstructString( m_loc_Buffer, + sizeof( m_loc_Buffer ), + loc_Format, + 7, + CLocalizedStringArg( arg0 ).GetLocArg(), + CLocalizedStringArg( arg1 ).GetLocArg(), + CLocalizedStringArg( arg2 ).GetLocArg(), + CLocalizedStringArg( arg3 ).GetLocArg(), + CLocalizedStringArg( arg4 ).GetLocArg(), + CLocalizedStringArg( arg5 ).GetLocArg(), + CLocalizedStringArg( arg6 ).GetLocArg() ); + } + } + + CConstructLocalizedString( const locchar_t *loc_Format, KeyValues *pKeyValues ) + { + m_loc_Buffer[0] = '\0'; + + if ( loc_Format && pKeyValues ) + { + ::ILocalize::ConstructString( m_loc_Buffer, sizeof( m_loc_Buffer ), loc_Format, pKeyValues ); + } + } + + operator const locchar_t *() const + { + return m_loc_Buffer; + } private: - enum { kBufferSize = 512, }; - locchar_t m_loc_Buffer[kBufferSize]; + enum { kBufferSize = 512, }; + locchar_t m_loc_Buffer[ kBufferSize ]; }; -#endif // TIER1_ILOCALIZE_H \ No newline at end of file +#endif // TIER1_ILOCALIZE_H diff --git a/mp/src/public/tier1/utlsoacontainer.h b/mp/src/public/tier1/utlsoacontainer.h index b9440c5f..8c09e468 100644 --- a/mp/src/public/tier1/utlsoacontainer.h +++ b/mp/src/public/tier1/utlsoacontainer.h @@ -311,19 +311,102 @@ class CSOAContainer }; -class CFltX4AttributeIterator : public CStridedConstPtr +class CFltx4StridedPtr +{ +protected: + fltx4 *m_pData; + size_t m_nStride; + +public: + FORCEINLINE CFltx4StridedPtr( void *pData, size_t nByteStride ) + { + m_pData = reinterpret_cast( pData ); + m_nStride = nByteStride / sizeof( fltx4 ); + } + + FORCEINLINE CFltx4StridedPtr() = default; + fltx4 *operator->() const + { + return m_pData; + } + + fltx4 &operator*() const + { + return *m_pData; + } + + FORCEINLINE operator fltx4*() + { + return m_pData; + } + + FORCEINLINE CFltx4StridedPtr& operator++() + { + m_pData += m_nStride; + return *this; + } + + FORCEINLINE void operator+=( size_t nNumElements ) + { + m_pData += nNumElements * m_nStride; + } +}; + +class CFltx4StridedConstPtr +{ +protected: + const fltx4 *m_pData; + size_t m_nStride; + +public: + FORCEINLINE CFltx4StridedConstPtr( void const *pData, size_t nByteStride ) + { + m_pData = reinterpret_cast( pData ); + m_nStride = nByteStride / sizeof( fltx4 ); + } + + FORCEINLINE CFltx4StridedConstPtr() = default; + + const fltx4 *operator->() const + { + return m_pData; + } + + const fltx4 &operator*() const + { + return *m_pData; + } + + FORCEINLINE operator const fltx4 *() const + { + return m_pData; + } + + FORCEINLINE CFltx4StridedConstPtr &operator++() + { + m_pData += m_nStride; + return *this; + } + + FORCEINLINE void operator+=( size_t nNumElements ) + { + m_pData += nNumElements*m_nStride; + } +}; + +class CFltX4AttributeIterator : public CFltx4StridedConstPtr { FORCEINLINE CFltX4AttributeIterator( CSOAContainer const *pContainer, int nAttribute, int nRowNumber = 0 ) - : CStridedConstPtr( pContainer->ConstRowPtr( nAttribute, nRowNumber), + : CFltx4StridedConstPtr( pContainer->ConstRowPtr( nAttribute, nRowNumber), pContainer->ItemByteStride( nAttribute ) ) { } }; -class CFltX4AttributeWriteIterator : public CStridedPtr +class CFltX4AttributeWriteIterator : public CFltx4StridedPtr { FORCEINLINE CFltX4AttributeWriteIterator( CSOAContainer const *pContainer, int nAttribute, int nRowNumber = 0 ) - : CStridedPtr( pContainer->RowPtr( nAttribute, nRowNumber), + : CFltx4StridedPtr( pContainer->RowPtr( nAttribute, nRowNumber), pContainer->ItemByteStride( nAttribute ) ) { } diff --git a/mp/src/raytrace/trace2.cpp b/mp/src/raytrace/trace2.cpp index d2e50557..4544f50c 100644 --- a/mp/src/raytrace/trace2.cpp +++ b/mp/src/raytrace/trace2.cpp @@ -42,7 +42,7 @@ void MapLinearIntensities(FourVectors const &intens,uint32 *p1, uint32 *p2, uint *(p4)=(SubInt(r, 3))|(SubInt(g, 3)<<8)|(SubInt(b, 3)<<16); } -static ALIGN16 int32 signmask[4]={0x80000000,0x80000000,0x80000000,0x80000000}; +static ALIGN16 int32 signmask[4]={(int32)0x80000000,(int32)0x80000000,(int32)0x80000000,(int32)0x80000000}; static ALIGN16 int32 all_ones[4]={-1,-1,-1,-1}; static fltx4 all_zeros={0,0,0,0}; static fltx4 TraceLimit={1.0e20,1.0e20,1.0e20,1.0e20}; diff --git a/mp/src/tier1/ilocalize.cpp b/mp/src/tier1/ilocalize.cpp index 58773fda..66673e64 100644 --- a/mp/src/tier1/ilocalize.cpp +++ b/mp/src/tier1/ilocalize.cpp @@ -26,49 +26,6 @@ int ILocalize::ConvertANSIToUnicode(const char *ansi, wchar_t *unicode, int unic #endif } -int ILocalize::ConvertUTF8ToUTF16(const char* utf8, wchar_t** utf16) -{ - if (*utf16 != nullptr) - { - return 0; - } - - int size = Q_UTF8ToUTF16(utf8, nullptr, 0); - *utf16 = (wchar_t*)calloc(1, size); - -#ifdef POSIX - size = Q_UTF8ToUnicode(utf8, *utf16, size); -#else - size = Q_UTF8ToUTF16(utf8, *utf16, size); -#endif - - return size / sizeof(wchar_t); -} - -int ILocalize::ConvertUTF16ToUTF8(const wchar_t* utf16, char** utf8) -{ - if (*utf8 != nullptr) - { - return 0; - } - -#ifdef POSIX - int size = Q_UnicodeToUTF8(utf16, nullptr, 0); -#else - int size = Q_UTF16ToUTF8(utf16, nullptr, 0); -#endif - - * utf8 = (char*)calloc(1, size); - -#ifdef POSIX - size = Q_UnicodeToUTF8(utf16, *utf8, size); -#else - size = Q_UTF16ToUTF8(utf16, *utf8, size); -#endif - - return size; -} - //----------------------------------------------------------------------------- // Purpose: converts an unicode string to an english string //----------------------------------------------------------------------------- @@ -196,111 +153,6 @@ void ILocalize::ConstructStringVArgsInternal(wchar_t *unicodeOutput, int unicode ConstructStringVArgsInternal_Impl( unicodeOutput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList ); } -template < typename T > -void ConstructStringArgsInternal_Impl(T* unicodeOutput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, const CLocalizedStringArg* argList) -{ - static const int k_cMaxFormatStringArguments = 9; // We only look one character ahead and start at %s1 - Assert(numFormatParameters <= k_cMaxFormatStringArguments); - - // Safety check - if (unicodeOutput == NULL || unicodeBufferSizeInBytes < 1) - { - return; - } - - if (!formatString || numFormatParameters > k_cMaxFormatStringArguments) - { - unicodeOutput[0] = 0; - return; - } - - int unicodeBufferSize = unicodeBufferSizeInBytes / sizeof(T); - const T* searchPos = formatString; - T* outputPos = unicodeOutput; - - //assumes we can't have %s10 - //assume both are 0 terminated? - int formatLength = StringFuncs::Length(formatString); - - while (searchPos[0] != '\0' && unicodeBufferSize > 1) - { - if (formatLength >= 3 && searchPos[0] == '%' && searchPos[1] == 's') - { - //this is an escape sequence - %s1, %s2 etc, up to %s9 - - int argindex = (searchPos[2]) - '0' - 1; // 0 for %s1, 1 for %s2, etc. - - if (argindex < 0 || argindex > k_cMaxFormatStringArguments) - { - Warning("Bad format string in CLocalizeStringTable::ConstructString\n"); - *outputPos = '\0'; - return; - } - - if (argindex < numFormatParameters) - { - T const* param = (const T*)argList[argindex].GetLocArg(); - - if (param == NULL) - param = StringFuncs::NullDebugString(); - - int paramSize = StringFuncs::Length(param); - if (paramSize >= unicodeBufferSize) - { - paramSize = unicodeBufferSize - 1; - } - - memcpy(outputPos, param, paramSize * sizeof(T)); - - unicodeBufferSize -= paramSize; - outputPos += paramSize; - - searchPos += 3; - formatLength -= 3; - } - else - { - AssertMsg(argindex < numFormatParameters, "ConstructStringVArgsInternal_Impl() - Found a %%s# escape sequence whose index was more than the number of args."); - - //copy it over, char by char - *outputPos = *searchPos; - - outputPos++; - unicodeBufferSize--; - - searchPos++; - formatLength--; - } - } - else - { - //copy it over, char by char - *outputPos = *searchPos; - - outputPos++; - unicodeBufferSize--; - - searchPos++; - formatLength--; - } - } - - // ensure null termination - Assert(outputPos - unicodeOutput < unicodeBufferSizeInBytes / sizeof(T)); - *outputPos = L'\0'; -} - -void ILocalize::ConstructStringArgsInternal(char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, int numFormatParameters, const CLocalizedStringArg* argList) -{ - ConstructStringArgsInternal_Impl(unicodeOutput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); -} - -void ILocalize::ConstructStringArgsInternal(wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, int numFormatParameters, const CLocalizedStringArg* argList) -{ - ConstructStringArgsInternal_Impl(unicodeOutput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); -} - - //----------------------------------------------------------------------------- // Purpose: construct string helper //----------------------------------------------------------------------------- diff --git a/mp/src/tier1/strtools.cpp b/mp/src/tier1/strtools.cpp index 5b4cffda..5db4e097 100644 --- a/mp/src/tier1/strtools.cpp +++ b/mp/src/tier1/strtools.cpp @@ -1411,11 +1411,7 @@ int _V_UCS2ToUnicode( const ucs2 *pUCS2, wchar_t *pUnicode, int cubDestSizeInByt size_t nMaxUTF8 = cubDestSizeInBytes; char *pIn = (char *)pUCS2; char *pOut = (char *)pUnicode; -#ifdef SDK2013CE if ( conv_t != (iconv_t)-1 ) -#else - if ( conv_t > 0 ) -#endif { cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUTF8 ); iconv_close( conv_t ); @@ -1455,11 +1451,7 @@ int _V_UnicodeToUCS2( const wchar_t *pUnicode, int cubSrcInBytes, char *pUCS2, i size_t nMaxUCS2 = cubDestSizeInBytes; char *pIn = (char*)pUnicode; char *pOut = pUCS2; -#ifdef SDK2013CE if ( conv_t != (iconv_t)-1 ) -#else - if ( conv_t > 0 ) -#endif { cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUCS2 ); iconv_close( conv_t ); @@ -1507,11 +1499,7 @@ int _V_UCS2ToUTF8( const ucs2 *pUCS2, char *pUTF8, int cubDestSizeInBytes ) size_t nMaxUTF8 = cubDestSizeInBytes - 1; char *pIn = (char *)pUCS2; char *pOut = (char *)pUTF8; -#ifdef SDK2013CE if ( conv_t != (iconv_t)-1 ) -#else - if ( conv_t > 0 ) -#endif { const size_t nBytesToWrite = nMaxUTF8; cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUTF8 ); @@ -1556,11 +1544,7 @@ int _V_UTF8ToUCS2( const char *pUTF8, int cubSrcInBytes, ucs2 *pUCS2, int cubDes size_t nMaxUTF8 = cubDestSizeInBytes; char *pIn = (char *)pUTF8; char *pOut = (char *)pUCS2; -#ifdef SDK2013CE if ( conv_t != (iconv_t)-1 ) -#else - if ( conv_t > 0 ) -#endif { cchResult = iconv( conv_t, &pIn, &nLenUnicde, &pOut, &nMaxUTF8 ); iconv_close( conv_t ); diff --git a/mp/src/togl/linuxwin/glmgrbasics.cpp b/mp/src/togl/linuxwin/glmgrbasics.cpp index 5a19cccb..9b48bff4 100644 --- a/mp/src/togl/linuxwin/glmgrbasics.cpp +++ b/mp/src/togl/linuxwin/glmgrbasics.cpp @@ -2623,12 +2623,15 @@ bool GLMDetectOGLP( void ) // from http://blog.timac.org/?p=190 #ifndef _WIN32 - #include + #include #endif -#include -#ifndef _WIN32 - #include - #include +#include +#ifdef _LINUX + #include + #include +#elif OSX + #include + #include #endif // From Technical Q&A QA1361