diff --git a/common/xbox/xboxstubs.h b/common/xbox/xboxstubs.h index 9b3255cf..fa65d6a8 100644 --- a/common/xbox/xboxstubs.h +++ b/common/xbox/xboxstubs.h @@ -96,8 +96,14 @@ typedef enum // XVRB_ALL, //} xverbose_e; +#ifdef POSIX +#ifndef WORD typedef unsigned short WORD; -typedef unsigned long DWORD; +#endif +#ifndef DWORD +typedef unsigned int DWORD; +#endif +#endif #ifndef POSIX typedef void* HANDLE; @@ -115,7 +121,7 @@ typedef int32 COLORREF; /* * Internet address (old style... should be updated) */ -#ifdef _POSIX +#ifdef POSIX struct ip4_addr { union { struct { unsigned char s_b1,s_b2,s_b3,s_b4; } S_un_b; @@ -321,7 +327,7 @@ enum XUSER_SIGNIN_STATE eXUserSigninState_SignedInToLive, }; -#if (defined(_POSIX)) +#if (defined(POSIX)) typedef size_t ULONG_PTR; #else typedef _W64 unsigned long ULONG_PTR; @@ -332,7 +338,7 @@ typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; typedef void * PXOVERLAPPED_COMPLETION_ROUTINE; -#ifndef _POSIX +#ifndef POSIX typedef struct _XOVERLAPPED { ULONG_PTR InternalLow; ULONG_PTR InternalHigh; diff --git a/interfaces/interfaces.cpp b/interfaces/interfaces.cpp new file mode 100644 index 00000000..d8a267f3 --- /dev/null +++ b/interfaces/interfaces.cpp @@ -0,0 +1,230 @@ +//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: A higher level link library for general use in the game and tools. +// +//=============================================================================// + +/* This is totally reverse-engineered code and may be wrong */ + +#include "interfaces/interfaces.h" +#include "tier0/dbg.h" + +ICvar *cvar, *g_pCVar; +IEventSystem *g_pEventSystem; +IProcessUtils *g_pProcessUtils; +IPhysics2 *g_pPhysics2; +IPhysics2ActorManager *g_pPhysics2ActorManager; +IPhysics2ResourceManager *g_pPhysics2ResourceManager; +IFileSystem *g_pFullFileSystem; +IAsyncFileSystem *g_pAsyncFileSystem; +IResourceSystem *g_pResourceSystem; +IMaterialSystem *materials, *g_pMaterialSystem; +IMaterialSystem2 *g_pMaterialSystem2; +IInputSystem *g_pInputSystem; +IInputStackSystem *g_pInputStackSystem; +INetworkSystem *g_pNetworkSystem; +IRenderDeviceMgr *g_pRenderDeviceMgr; +IMaterialSystemHardwareConfig *g_pMaterialSystemHardwareConfig; +ISoundSystem *g_pSoundSystem; +IDebugTextureInfo *g_pMaterialSystemDebugTextureInfo; +IVBAllocTracker *g_VBAllocTracker; +IColorCorrectionSystem *colorcorrection; +IP4 *p4; +IMdlLib *mdllib; +IQueuedLoader *g_pQueuedLoader; +IResourceAccessControl *g_pResourceAccessControl; +IPrecacheSystem *g_pPrecacheSystem; +IStudioRender *g_pStudioRender, *studiorender; +vgui::IVGui *g_pVGui; +vgui::IInput *g_pVGuiInput; +vgui::IPanel *g_pVGuiPanel; +vgui::ISurface *g_pVGuiSurface; +vgui::ISchemeManager *g_pVGuiSchemeManager; +vgui::ISystem *g_pVGuiSystem; +ILocalize *g_pLocalize; +vgui::ILocalize *g_pVGuiLocalize; +IMatSystemSurface *g_pMatSystemSurface; +IDataCache *g_pDataCache; +IMDLCache *g_pMDLCache, *mdlcache; +IAvi *g_pAVI; +IBik *g_pBIK; +IDmeMakefileUtils *g_pDmeMakefileUtils; +IPhysicsCollision *g_pPhysicsCollision; +ISoundEmitterSystemBase *g_pSoundEmitterSystem; +IMeshSystem *g_pMeshSystem; +IRenderDevice *g_pRenderDevice; +IRenderHardwareConfig *g_pRenderHardwareConfig; +ISceneSystem *g_pSceneSystem; +IWorldRendererMgr *g_pWorldRendererMgr; +IVGuiRenderSurface *g_pVGuiRenderSurface; +IMatchFramework *g_pMatchFramework; +IGameUISystemMgr *g_pGameUISystemMgr; + +struct InterfaceGlobals_t +{ + const char *m_pInterfaceName; + void *m_ppGlobal; +}; + +struct ConnectionRegistration_t +{ + void *m_ppGlobalStorage; + int m_nConnectionPhase; +}; + +static const InterfaceGlobals_t g_pInterfaceGlobals[] = +{ + { CVAR_INTERFACE_VERSION, cvar }, + { CVAR_INTERFACE_VERSION, g_pCVar }, + { EVENTSYSTEM_INTERFACE_VERSION, g_pEventSystem }, + { PROCESS_UTILS_INTERFACE_VERSION, g_pProcessUtils }, + { VPHYSICS2_INTERFACE_VERSION, g_pPhysics2 }, + { VPHYSICS2_ACTOR_MGR_INTERFACE_VERSION, g_pPhysics2ActorManager }, + { VPHYSICS2_RESOURCE_MGR_INTERFACE_VERSION, g_pPhysics2ResourceManager }, + { FILESYSTEM_INTERFACE_VERSION, g_pFullFileSystem }, + { ASYNCFILESYSTEM_INTERFACE_VERSION, g_pAsyncFileSystem }, + { RESOURCESYSTEM_INTERFACE_VERSION, g_pResourceSystem }, + { MATERIAL_SYSTEM_INTERFACE_VERSION, materials }, + { MATERIAL_SYSTEM_INTERFACE_VERSION, g_pMaterialSystem }, + { MATERIAL_SYSTEM2_INTERFACE_VERSION, g_pMaterialSystem2 }, + { INPUTSYSTEM_INTERFACE_VERSION, g_pInputSystem }, + { INPUTSTACKSYSTEM_INTERFACE_VERSION, g_pInputStackSystem }, + { NETWORKSYSTEM_INTERFACE_VERSION, g_pNetworkSystem }, + { RENDER_DEVICE_MGR_INTERFACE_VERSION, g_pRenderDeviceMgr }, + { MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, g_pMaterialSystemHardwareConfig }, + { SOUNDSYSTEM_INTERFACE_VERSION, g_pSoundSystem }, + { DEBUG_TEXTURE_INFO_VERSION, g_pMaterialSystemDebugTextureInfo }, + { VB_ALLOC_TRACKER_INTERFACE_VERSION, g_VBAllocTracker }, + { COLORCORRECTION_INTERFACE_VERSION, colorcorrection }, + { P4_INTERFACE_VERSION, p4 }, + { MDLLIB_INTERFACE_VERSION, mdllib }, + { QUEUEDLOADER_INTERFACE_VERSION, g_pQueuedLoader }, + { RESOURCE_ACCESS_CONTROL_INTERFACE_VERSION, g_pResourceAccessControl }, + { PRECACHE_SYSTEM_INTERFACE_VERSION, g_pPrecacheSystem }, + { STUDIO_RENDER_INTERFACE_VERSION, g_pStudioRender }, + { STUDIO_RENDER_INTERFACE_VERSION, studiorender }, + { VGUI_IVGUI_INTERFACE_VERSION, g_pVGui }, + { VGUI_INPUT_INTERFACE_VERSION, g_pVGuiInput }, + { VGUI_PANEL_INTERFACE_VERSION, g_pVGuiPanel }, + { VGUI_SURFACE_INTERFACE_VERSION, g_pVGuiSurface }, + { VGUI_SCHEME_INTERFACE_VERSION, g_pVGuiSchemeManager }, + { VGUI_SYSTEM_INTERFACE_VERSION, g_pVGuiSystem }, + { LOCALIZE_INTERFACE_VERSION, g_pLocalize }, + { LOCALIZE_INTERFACE_VERSION, g_pVGuiLocalize }, + { MAT_SYSTEM_SURFACE_INTERFACE_VERSION, g_pMatSystemSurface }, + { DATACACHE_INTERFACE_VERSION, g_pDataCache }, + { MDLCACHE_INTERFACE_VERSION, g_pMDLCache }, + { MDLCACHE_INTERFACE_VERSION, mdlcache }, + { AVI_INTERFACE_VERSION, g_pAVI }, + { BIK_INTERFACE_VERSION, g_pBIK }, + { DMEMAKEFILE_UTILS_INTERFACE_VERSION, g_pDmeMakefileUtils }, + { VPHYSICS_COLLISION_INTERFACE_VERSION, g_pPhysicsCollision }, + { SOUNDEMITTERSYSTEM_INTERFACE_VERSION, g_pSoundEmitterSystem }, + { MESHSYSTEM_INTERFACE_VERSION, g_pMeshSystem }, + { RENDER_DEVICE_INTERFACE_VERSION, g_pRenderDevice }, + { RENDER_HARDWARECONFIG_INTERFACE_VERSION, g_pRenderHardwareConfig }, + { SCENESYSTEM_INTERFACE_VERSION, g_pSceneSystem }, + { WORLD_RENDERER_MGR_INTERFACE_VERSION, g_pWorldRendererMgr }, + { RENDER_SYSTEM_SURFACE_INTERFACE_VERSION, g_pVGuiRenderSurface }, + { MATCHFRAMEWORK_INTERFACE_VERSION, g_pMatchFramework }, + { GAMEUISYSTEMMGR_INTERFACE_VERSION, g_pGameUISystemMgr } +}; + +static const int NUM_INTERFACES = sizeof(g_pInterfaceGlobals) / sizeof(InterfaceGlobals_t); + +static int s_nConnectionCount; +static int s_nRegistrationCount; + +static ConnectionRegistration_t s_pConnectionRegistration[NUM_INTERFACES + 1]; + +void ReconnectInterface(CreateInterfaceFn factory, char const *pInterfaceName, void **w); + +void ConnectInterfaces(CreateInterfaceFn *pFactoryList, int nFactoryCount) +{ + if (s_nRegistrationCount < 0) + { + Error("APPSYSTEM: In ConnectInterfaces(), s_nRegistrationCount is %d!\n", s_nRegistrationCount); + s_nConnectionCount++; + return; + } + + if (s_nRegistrationCount) + { + for (int i = 0; i < nFactoryCount; i++) + { + for (int j = 0; j < NUM_INTERFACES; j++) + { + ReconnectInterface(pFactoryList[i], g_pInterfaceGlobals[j].m_pInterfaceName, (void **)g_pInterfaceGlobals[j].m_ppGlobal); + } + } + + s_nConnectionCount++; + return; + } + + for (int i = 0; i < nFactoryCount; i++) + { + for (int j = 0; j < NUM_INTERFACES; j++) + { + const InterfaceGlobals_t &iface = g_pInterfaceGlobals[j]; + + if (!(*(void **)iface.m_ppGlobal)) + { + void *ptr = pFactoryList[i](iface.m_pInterfaceName, NULL); + *(void **)iface.m_ppGlobal = ptr; + if (ptr) + { + ConnectionRegistration_t ® = s_pConnectionRegistration[s_nRegistrationCount++]; + reg.m_ppGlobalStorage = iface.m_ppGlobal; + reg.m_nConnectionPhase = s_nConnectionCount; + } + } + } + } + + s_nConnectionCount++; +} + +void DisconnectInterfaces() +{ + if (--s_nConnectionCount >= 0) + { + for (int i = 0; i < s_nRegistrationCount; i++) + { + ConnectionRegistration_t ® = s_pConnectionRegistration[i]; + if (reg.m_nConnectionPhase == s_nConnectionCount) + reg.m_ppGlobalStorage = NULL; + } + } +} + +void ReconnectInterface(CreateInterfaceFn factory, char const *pInterfaceName, void **ppGlobal) +{ + bool got = false; + + *ppGlobal = factory(pInterfaceName, NULL); + + for (int i = 0; i < s_nRegistrationCount; i++) + { + if (s_pConnectionRegistration[i].m_ppGlobalStorage == ppGlobal) + got = true; + } + + if ((s_nRegistrationCount <= 0 || !got) && *ppGlobal) + { + ConnectionRegistration_t ® = s_pConnectionRegistration[s_nRegistrationCount++]; + reg.m_ppGlobalStorage = ppGlobal; + reg.m_nConnectionPhase = s_nConnectionCount; + } +} + +void ReconnectInterface(CreateInterfaceFn factory, const char *pInterfaceName) +{ + for (int i = 0; i < NUM_INTERFACES; i++) + { + const InterfaceGlobals_t &iface = g_pInterfaceGlobals[i]; + + if (strcmp(iface.m_pInterfaceName, pInterfaceName) == 0) + ReconnectInterface(factory, iface.m_pInterfaceName, (void **)iface.m_ppGlobal); + } +} diff --git a/interfaces/interfaces.sln b/interfaces/interfaces.sln new file mode 100644 index 00000000..494c3199 --- /dev/null +++ b/interfaces/interfaces.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "interfaces", "interfaces.vcxproj", "{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.ActiveCfg = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.Build.0 = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.ActiveCfg = Release|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/interfaces/interfaces.vcxproj b/interfaces/interfaces.vcxproj new file mode 100644 index 00000000..994f27bc --- /dev/null +++ b/interfaces/interfaces.vcxproj @@ -0,0 +1,226 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + interfaces + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720} + tier1 + + + + StaticLibrary + + + StaticLibrary + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + ..\lib\public\ + true + true + true + ..\lib\public\ + true + true + true + AllRules.ruleset + + + AllRules.ruleset + + + + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories) + WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + true + + + EnableFastChecks + MultiThreadedDebug + false + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + EditAndContinue + CompileAsCpp + Prompt + Level3 + + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + + MaxSpeed + AnySuitable + true + Speed + ..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories) + WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + OldStyle + CompileAsCpp + Prompt + Level3 + + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interfaces/interfaces.vcxproj.filters b/interfaces/interfaces.vcxproj.filters new file mode 100644 index 00000000..2173ec6e --- /dev/null +++ b/interfaces/interfaces.vcxproj.filters @@ -0,0 +1,182 @@ + + + + + {aba1d919-d95c-4c3f-a495-be0375bab184} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {0295d938-2af6-4393-9785-4b7b122313c9} + h;hpp;hxx;hm;inl + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/lib/linux/interfaces_i486.a b/lib/linux/interfaces_i486.a new file mode 100644 index 00000000..7f34364a Binary files /dev/null and b/lib/linux/interfaces_i486.a differ diff --git a/lib/linux/libtier0.so b/lib/linux/libtier0.so new file mode 100644 index 00000000..e51b654d Binary files /dev/null and b/lib/linux/libtier0.so differ diff --git a/lib/linux/libvstdlib.so b/lib/linux/libvstdlib.so new file mode 100644 index 00000000..d34d259c Binary files /dev/null and b/lib/linux/libvstdlib.so differ diff --git a/lib/linux/mathlib_i486.a b/lib/linux/mathlib_i486.a new file mode 100644 index 00000000..12d40221 Binary files /dev/null and b/lib/linux/mathlib_i486.a differ diff --git a/lib/linux/tier1_i486.a b/lib/linux/tier1_i486.a new file mode 100644 index 00000000..c8077cfc Binary files /dev/null and b/lib/linux/tier1_i486.a differ diff --git a/lib/public/interfaces.lib b/lib/public/interfaces.lib index 69cc5418..bcc89e0f 100644 Binary files a/lib/public/interfaces.lib and b/lib/public/interfaces.lib differ diff --git a/lib/public/mathlib.lib b/lib/public/mathlib.lib index 03783b48..1a659850 100644 Binary files a/lib/public/mathlib.lib and b/lib/public/mathlib.lib differ diff --git a/lib/public/tier1.lib b/lib/public/tier1.lib index 7cbf1785..1bdcf949 100644 Binary files a/lib/public/tier1.lib and b/lib/public/tier1.lib differ diff --git a/linux_sdk/Makefile b/linux_sdk/Makefile index b39b926e..ec2f968e 100644 --- a/linux_sdk/Makefile +++ b/linux_sdk/Makefile @@ -63,13 +63,13 @@ LIB_DIR = $(SRC_DIR)/lib/linux # the CPU target for the build, must be i486 for now ARCH = i486 -ARCH_CFLAGS = -mtune=i686 -march=pentium3 -mmmx -m32 +ARCH_CFLAGS = -mtune=i686 -march=pentium3 -mmmx -msse -m32 -DEFINES = -D_LINUX -DLINUX -DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp \ - -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp +DEFINES = -D_LINUX -DLINUX -DCOMPILER_GCC -DPOSIX -DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp \ + -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp UNDEF = -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE -BASE_CFLAGS = -fno-strict-aliasing -Wall -Werror -Wconversion -Wno-non-virtual-dtor -Wno-invalid-offsetof +BASE_CFLAGS = -fno-strict-aliasing -Wall -Werror -Wno-conversion -Wno-non-virtual-dtor -Wno-invalid-offsetof SHLIBEXT = so SHLIBCFLAGS = -fPIC SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt -Wl @@ -100,6 +100,7 @@ MAKE_VCPM = Makefile.vcpm MAKE_PLUGIN = Makefile.plugin MAKE_TIER1 = Makefile.tier1 MAKE_MATH = Makefile.mathlib +MAKE_IFACE = Makefile.interfaces MAKE_CHOREO = Makefile.choreo all: check vcpm mod @@ -131,6 +132,9 @@ tier1: mathlib: $(MAKE) -f $(MAKE_MATH) $(BASE_DEFINES) +interfaces: + $(MAKE) -f $(MAKE_IFACE) $(BASE_DEFINES) + choreo: $(MAKE) -f $(MAKE_CHOREO) $(BASE_DEFINES) @@ -147,4 +151,5 @@ clean: $(MAKE) -f $(MAKE_SERVER) $(BASE_DEFINES) clean $(MAKE) -f $(MAKE_TIER1) $(BASE_DEFINES) clean $(MAKE) -f $(MAKE_MATH) $(BASE_DEFINES) clean + $(MAKE) -f $(MAKE_IFACE) $(BASE_DEFINES) clean $(MAKE) -f $(MAKE_CHOREO) $(BASE_DEFINES) clean diff --git a/linux_sdk/Makefile.interfaces b/linux_sdk/Makefile.interfaces new file mode 100644 index 00000000..b3753b6f --- /dev/null +++ b/linux_sdk/Makefile.interfaces @@ -0,0 +1,51 @@ +# +# Tier1 Static Library Makefile +# + +override NAME = interfaces + +LIB_SRC_DIR = $(SRC_DIR)/$(NAME) +PUBLIC_SRC_DIR = $(SRC_DIR)/public +TIER0_PUBLIC_SRC_DIR = $(SRC_DIR)/public/tier0 +TIER1_PUBLIC_SRC_DIR = $(SRC_DIR)/public/tier1 + +LIB_OBJ_DIR=$(BUILD_OBJ_DIR)/$(NAME)_$(ARCH) + +# Extension of linux static library +override SHLIBEXT = a + +INCLUDEDIRS = -I$(PUBLIC_SRC_DIR) -I$(TIER0_PUBLIC_SRC_DIR) -I$(TIER1_PUBLIC_SRC_DIR) -D_LIB + +DO_CC = $(CPLUS) $(INCLUDEDIRS) -DARCH=$(ARCH) + +ifeq "$(DEBUG)" "true" + DO_CC += $(DBG_DEFINES) $(DBG_CFLAGS) +else + DO_CC += -DNDEBUG $(CFLAGS) +endif + +DO_CC += -o $@ -c $< + +##################################################################### + +LIB_OBJS= \ + $(LIB_OBJ_DIR)/interfaces.o \ + +all: dirs $(NAME)_$(ARCH).$(SHLIBEXT) + +dirs: + -mkdir -p $(BUILD_OBJ_DIR) + -mkdir -p $(LIB_OBJ_DIR) + +$(NAME)_$(ARCH).$(SHLIBEXT): $(LIB_OBJS) + $(AR) $(LIB_DIR)/$@ $(LIB_OBJS) + +$(LIB_OBJ_DIR)/%.o: $(LIB_SRC_DIR)/%.cpp + $(DO_CC) + +install: + cp -f $(NAME)_$(ARCH).$(SHLIBEXT) $(LIB_DIR)/$(NAME)_$(ARCH).$(SHLIBEXT) + +clean: + -rm -rf $(LIB_OBJ_DIR) + diff --git a/linux_sdk/Makefile.mathlib b/linux_sdk/Makefile.mathlib index c2a55e6a..638c4df6 100644 --- a/linux_sdk/Makefile.mathlib +++ b/linux_sdk/Makefile.mathlib @@ -30,7 +30,6 @@ DO_CC += -o $@ -c $< ##################################################################### LIB_OBJS= \ - $(LIB_OBJ_DIR)/3dnow.o \ $(LIB_OBJ_DIR)/anorms.o \ $(LIB_OBJ_DIR)/bumpvects.o \ $(LIB_OBJ_DIR)/color_conversion.o \ diff --git a/linux_sdk/Makefile.tier1 b/linux_sdk/Makefile.tier1 index fac93119..1b451ce7 100644 --- a/linux_sdk/Makefile.tier1 +++ b/linux_sdk/Makefile.tier1 @@ -50,7 +50,6 @@ LIB_OBJS= \ $(LIB_OBJ_DIR)/stringpool.o \ $(LIB_OBJ_DIR)/strtools.o \ $(LIB_OBJ_DIR)/tier1.o \ - $(LIB_OBJ_DIR)/tokenreader.o \ $(LIB_OBJ_DIR)/undiff.o \ $(LIB_OBJ_DIR)/uniqueid.o \ $(LIB_OBJ_DIR)/utlbuffer.o \ diff --git a/mathlib/anorms.cpp b/mathlib/anorms.cpp index 443bd58f..224181f4 100644 --- a/mathlib/anorms.cpp +++ b/mathlib/anorms.cpp @@ -6,6 +6,7 @@ #if !defined(_STATIC_LINKED) || defined(_SHARED_LIB) +#include "mathlib/mathlib.h" #include "mathlib/vector.h" #include "mathlib/anorms.h" diff --git a/mathlib/halton.cpp b/mathlib/halton.cpp index be539908..ef477fc1 100644 --- a/mathlib/halton.cpp +++ b/mathlib/halton.cpp @@ -5,6 +5,7 @@ //=====================================================================================// #include +#include "mathlib/mathlib.h" HaltonSequenceGenerator_t::HaltonSequenceGenerator_t(int b) { diff --git a/mathlib/imagequant.cpp b/mathlib/imagequant.cpp index bdba52a6..ce712427 100644 --- a/mathlib/imagequant.cpp +++ b/mathlib/imagequant.cpp @@ -6,6 +6,7 @@ // //=============================================================================// #include +#include "tier0/basetypes.h" #define N_EXTRAVALUES 1 #define N_DIMENSIONS (3+N_EXTRAVALUES) diff --git a/mathlib/lightdesc.cpp b/mathlib/lightdesc.cpp index 23c51c76..8a4d7f30 100644 --- a/mathlib/lightdesc.cpp +++ b/mathlib/lightdesc.cpp @@ -27,12 +27,12 @@ void LightDesc_t::RecalculateDerivedValues(void) { // note - this quantity is very sensitive to round off error. the sse // reciprocal approximation won't cut it here. - OneOver_ThetaDot_Minus_PhiDot=1.0/spread; + m_OneOverThetaDotMinusPhiDot=1.0/spread; } else { // hard falloff instead of divide by zero - OneOver_ThetaDot_Minus_PhiDot=1.0; + m_OneOverThetaDotMinusPhiDot=1.0; } } if (m_Type==MATERIAL_LIGHT_DIRECTIONAL) @@ -140,7 +140,7 @@ void LightDesc_t::ComputeLightAtPoints( const FourVectors &pos, const FourVector fltx4 dot2=SubSIMD(Four_Zeros,delta*m_Direction); // dot position with spot light dir for cone falloff - fltx4 cone_falloff_scale=MulSIMD(ReplicateX4(OneOver_ThetaDot_Minus_PhiDot), + fltx4 cone_falloff_scale=MulSIMD(ReplicateX4(m_OneOverThetaDotMinusPhiDot), SubSIMD(dot2,ReplicateX4(m_PhiDot))); cone_falloff_scale=MinSIMD(cone_falloff_scale,Four_Ones); @@ -236,7 +236,7 @@ void LightDesc_t::ComputeNonincidenceLightAtPoints( const FourVectors &pos, Four fltx4 dot2=SubSIMD(Four_Zeros,delta*m_Direction); // dot position with spot light dir for cone falloff - fltx4 cone_falloff_scale=MulSIMD(ReplicateX4(OneOver_ThetaDot_Minus_PhiDot), + fltx4 cone_falloff_scale=MulSIMD(ReplicateX4(m_OneOverThetaDotMinusPhiDot), SubSIMD(dot2,ReplicateX4(m_PhiDot))); cone_falloff_scale=MinSIMD(cone_falloff_scale,Four_Ones); diff --git a/mathlib/mathlib.sln b/mathlib/mathlib.sln new file mode 100644 index 00000000..e478e141 --- /dev/null +++ b/mathlib/mathlib.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mathlib", "mathlib.vcxproj", "{884C66F2-7F84-4570-AE6C-B634C1113D69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Debug|Win32.ActiveCfg = Debug|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Debug|Win32.Build.0 = Debug|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Release|Win32.ActiveCfg = Release|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/mathlib/mathlib.vcproj b/mathlib/mathlib.vcproj new file mode 100644 index 00000000..ff590e86 --- /dev/null +++ b/mathlib/mathlib.vcproj @@ -0,0 +1,407 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mathlib/mathlib.vcxproj b/mathlib/mathlib.vcxproj new file mode 100644 index 00000000..90360ae1 --- /dev/null +++ b/mathlib/mathlib.vcxproj @@ -0,0 +1,212 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {884C66F2-7F84-4570-AE6C-B634C1113D69} + mathlib + + + + StaticLibrary + + + StaticLibrary + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + ..\lib\public\ + true + true + true + ..\lib\public\ + true + true + true + AllRules.ruleset + + + AllRules.ruleset + + + + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;..\public\mathlib;%(AdditionalIncludeDirectories) + WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + true + true + + + EnableFastChecks + MultiThreadedDebug + false + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + Level4 + EditAndContinue + CompileAsCpp + Prompt + + + + + + + false + true + + + true + + + true + $(OutDir)mathlib.bsc + + + + + + + + + MaxSpeed + AnySuitable + true + Speed + ..\public;..\public\tier0;..\public\tier1;..\public\mathlib;%(AdditionalIncludeDirectories) + WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + Level4 + OldStyle + CompileAsCpp + Prompt + + + + + + + false + true + + + true + + + true + $(OutDir)mathlib.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mathlib/mathlib.vcxproj.filters b/mathlib/mathlib.vcxproj.filters new file mode 100644 index 00000000..58ce7df8 --- /dev/null +++ b/mathlib/mathlib.vcxproj.filters @@ -0,0 +1,153 @@ + + + + + {00f9c713-dc8b-4f56-b6a8-0f7252d1a270} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {c9fa2f3a-719d-4fab-aa39-714cf6391317} + h + + + {7f621938-4fe8-4d3f-a1b1-e00a41531e16} + h;hpp;hxx;hm;inl + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 353dc2af..d8068ea6 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -24,13 +24,12 @@ #include "mathlib/mathlib.h" #include "mathlib/vector.h" #if !defined( _X360 ) -#include "mathlib/amd3dx.h" -#include "3dnow.h" #include "sse.h" #endif #include "mathlib/ssemath.h" #include "mathlib/ssequaternion.h" +#include "mathlib/vplane.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -42,7 +41,6 @@ bool s_bMathlibInitialized = false; void Sys_Error (char *error, ...); #endif -const Vector vec3_origin(0,0,0); const QAngle vec3_angle(0,0,0); const Vector vec3_invalid( FLT_MAX, FLT_MAX, FLT_MAX ); const int nanmask = 255<<23; @@ -63,10 +61,10 @@ float _rsqrtf(float x) return 1.f / _sqrtf( x ); } -float FASTCALL _VectorNormalize (Vector& vec) +float VectorNormalize (Vector& vec) { #ifdef _VPROF_MATHLIB - VPROF_BUDGET( "_VectorNormalize", "Mathlib" ); + VPROF_BUDGET( "VectorNormalize", "Mathlib" ); #endif Assert( s_bMathlibInitialized ); float radius = sqrtf(vec.x*vec.x + vec.y*vec.y + vec.z*vec.z); @@ -81,6 +79,8 @@ float FASTCALL _VectorNormalize (Vector& vec) return radius; } + + // TODO: Add fast C VectorNormalizeFast. // Perhaps use approximate rsqrt trick, if the accuracy isn't too bad. void FASTCALL _VectorNormalizeFast (Vector& vec) @@ -109,7 +109,6 @@ float _InvRSquared(const float* v) float (*pfSqrt)(float x) = _sqrtf; float (*pfRSqrt)(float x) = _rsqrtf; float (*pfRSqrtFast)(float x) = _rsqrtf; -float (FASTCALL *pfVectorNormalize)(Vector& v) = _VectorNormalize; void (FASTCALL *pfVectorNormalizeFast)(Vector& v) = _VectorNormalizeFast; float (*pfInvRSquared)(const float* v) = _InvRSquared; void (*pfFastSinCos)(float x, float* s, float* c) = SinCos; @@ -382,9 +381,9 @@ void MatrixInvert( const matrix3x4_t& in, matrix3x4_t& out ) Assert( s_bMathlibInitialized ); if ( &in == &out ) { - swap(out[0][1],out[1][0]); - swap(out[0][2],out[2][0]); - swap(out[1][2],out[2][1]); + V_swap(out[0][1],out[1][0]); + V_swap(out[0][2],out[2][0]); + V_swap(out[1][2],out[2][1]); } else { @@ -1266,18 +1265,18 @@ bool SolveInverseQuadraticMonotonic( float x1, float y1, float x2, float y2, flo // first, sort parameters if (x1>x2) { - swap(x1,x2); - swap(y1,y2); + V_swap(x1,x2); + V_swap(y1,y2); } if (x2>x3) { - swap(x2,x3); - swap(y2,y3); + V_swap(x2,x3); + V_swap(y2,y3); } if (x1>x2) { - swap(x1,x2); - swap(y1,y2); + V_swap(x1,x2); + V_swap(y1,y2); } // this code is not fast. what it does is when the curve would be non-monotonic, slowly shifts // the center point closer to the linear line between the endpoints. Should anyone need htis @@ -3198,7 +3197,6 @@ bool CalcLineToLineIntersectionSegment( #pragma optimize( "", on ) #endif -static bool s_b3DNowEnabled = false; static bool s_bMMXEnabled = false; static bool s_bSSEEnabled = false; static bool s_bSSE2Enabled = false; @@ -3218,7 +3216,6 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright pfSqrt = _sqrtf; pfRSqrt = _rsqrtf; pfRSqrtFast = _rsqrtf; - pfVectorNormalize = _VectorNormalize; pfVectorNormalizeFast = _VectorNormalizeFast; pfInvRSquared = _InvRSquared; pfFastSinCos = SinCos; @@ -3235,31 +3232,11 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright s_bMMXEnabled = false; } - // SSE Generally performs better than 3DNow when present, so this is placed - // first to allow SSE to override these settings. - if ( bAllow3DNow && pi.m_b3DNow ) - { - s_b3DNowEnabled = true; - - // Select the 3DNow specific routines if available; - pfVectorNormalize = _3DNow_VectorNormalize; - pfVectorNormalizeFast = _3DNow_VectorNormalizeFast; - pfInvRSquared = _3DNow_InvRSquared; - pfSqrt = _3DNow_Sqrt; - pfRSqrt = _3DNow_RSqrt; - pfRSqrtFast = _3DNow_RSqrt; - } - else - { - s_b3DNowEnabled = false; - } - if ( bAllowSSE && pi.m_bSSE ) { s_bSSEEnabled = true; // Select the SSE specific routines if available - pfVectorNormalize = _VectorNormalize; pfVectorNormalizeFast = _SSE_VectorNormalizeFast; pfInvRSquared = _SSE_InvRSquared; pfSqrt = _SSE_Sqrt; @@ -3295,12 +3272,6 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright BuildGammaTable( gamma, texGamma, brightness, overbright ); } -bool MathLib_3DNowEnabled( void ) -{ - Assert( s_bMathlibInitialized ); - return s_b3DNowEnabled; -} - bool MathLib_MMXEnabled( void ) { Assert( s_bMathlibInitialized ); @@ -3319,20 +3290,6 @@ bool MathLib_SSE2Enabled( void ) return s_bSSE2Enabled; } -float Approach( float target, float value, float speed ) -{ - float delta = target - value; - - if ( delta > speed ) - value += speed; - else if ( delta < -speed ) - value -= speed; - else - value = target; - - return value; -} - // BUGBUG: Why doesn't this call angle diff?!?!? float ApproachAngle( float target, float value, float speed ) { @@ -3816,8 +3773,8 @@ void GeneratePerspectiveFrustum( const Vector& origin, const Vector &forward, float flIntercept = DotProduct( origin, forward ); // Setup the near and far planes. - frustum.SetPlane( FRUSTUM_FARZ, PLANE_ANYZ, -forward, -flZFar - flIntercept ); - frustum.SetPlane( FRUSTUM_NEARZ, PLANE_ANYZ, forward, flZNear + flIntercept ); + frustum.SetPlane( FRUSTUM_FARZ, -forward, -flZFar - flIntercept ); + frustum.SetPlane( FRUSTUM_NEARZ, forward, flZNear + flIntercept ); flFovX *= 0.5f; flFovY *= 0.5f; @@ -3834,8 +3791,8 @@ void GeneratePerspectiveFrustum( const Vector& origin, const Vector &forward, VectorNormalize( normalPos ); VectorNormalize( normalNeg ); - frustum.SetPlane( FRUSTUM_LEFT, PLANE_ANYZ, normalPos, normalPos.Dot( origin ) ); - frustum.SetPlane( FRUSTUM_RIGHT, PLANE_ANYZ, normalNeg, normalNeg.Dot( origin ) ); + frustum.SetPlane( FRUSTUM_LEFT, normalPos, normalPos.Dot( origin ) ); + frustum.SetPlane( FRUSTUM_RIGHT,normalNeg, normalNeg.Dot( origin ) ); VectorMA( up, flTanY, forward, normalPos ); VectorMA( normalPos, -2.0f, up, normalNeg ); @@ -3843,8 +3800,8 @@ void GeneratePerspectiveFrustum( const Vector& origin, const Vector &forward, VectorNormalize( normalPos ); VectorNormalize( normalNeg ); - frustum.SetPlane( FRUSTUM_BOTTOM, PLANE_ANYZ, normalPos, normalPos.Dot( origin ) ); - frustum.SetPlane( FRUSTUM_TOP, PLANE_ANYZ, normalNeg, normalNeg.Dot( origin ) ); + frustum.SetPlane( FRUSTUM_BOTTOM, normalPos, normalPos.Dot( origin ) ); + frustum.SetPlane( FRUSTUM_TOP, normalNeg, normalNeg.Dot( origin ) ); } @@ -3859,23 +3816,40 @@ void GeneratePerspectiveFrustum( const Vector& origin, const QAngle &angles, flo GeneratePerspectiveFrustum( origin, vecForward, vecRight, vecUp, flZNear, flZFar, flFovX, flFovY, frustum ); } +inline cplane_t *ToPlane(cplane_t *out, const Frustum_t &frustum, int type) +{ + Vector vecNormal; + float dist; + + frustum.GetPlane(type, &vecNormal, &dist); + + out->normal = vecNormal; + out->dist = dist; + out->type = PLANE_ANYZ; + out->signbits = SignbitsForPlane(out); + + return out; +} + bool R_CullBox( const Vector& mins, const Vector& maxs, const Frustum_t &frustum ) { - return (( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_RIGHT) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_LEFT) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_TOP) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_BOTTOM) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_NEARZ) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_FARZ) ) == 2 ) ); + cplane_t p; + return (( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_RIGHT) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_LEFT) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_TOP) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_BOTTOM) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_NEARZ) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_FARZ) ) == 2 ) ); } bool R_CullBoxSkipNear( const Vector& mins, const Vector& maxs, const Frustum_t &frustum ) { - return (( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_RIGHT) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_LEFT) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_TOP) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_BOTTOM) ) == 2 ) || - ( BoxOnPlaneSide( mins, maxs, frustum.GetPlane(FRUSTUM_FARZ) ) == 2 ) ); + cplane_t p; + return (( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_RIGHT) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_LEFT) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_TOP) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_BOTTOM) ) == 2 ) || + ( BoxOnPlaneSide( mins, maxs, ToPlane(&p, frustum, FRUSTUM_FARZ) ) == 2 ) ); } @@ -4088,3 +4062,208 @@ void GetInterpolationData( float const *pKnotPositions, *pInterpolationValue = FLerp( 0, 1, 0, flSizeOfGap, flOffsetFromStartOfGap ); return; } + +/* Reverse engineered code ahead */ + +void fourplanes_t::ComputeSignbits() +{ + xSign = CmpLtSIMD(nX, Four_Zeros); + ySign = CmpLtSIMD(nY, Four_Zeros); + zSign = CmpLtSIMD(nZ, Four_Zeros); + nXAbs = fabs(nX); + nYAbs = fabs(nY); + nZAbs = fabs(nZ); +} + +void fourplanes_t::Set4Planes( const VPlane *pPlanes ) +{ + nX = *(fltx4 *)pPlanes; + nY = *(fltx4 *)++pPlanes; + nZ = *(fltx4 *)++pPlanes; + dist = *(fltx4 *)++pPlanes; + TransposeSIMD(nX, nY, nZ, dist); + + ComputeSignbits(); +} + +void fourplanes_t::Set2Planes( const VPlane *pPlanes ) +{ + nX = *(fltx4 *)pPlanes; + nY = *(fltx4 *)++pPlanes; + nZ = Four_Zeros; + dist = Four_Zeros; + TransposeSIMD(nX, nY, nZ, dist); + + ComputeSignbits(); +} + +void fourplanes_t::Get4Planes( VPlane *pPlanesOut ) +{ + fltx4 tempX = nX; + fltx4 tempY = nY; + fltx4 tempZ = nZ; + fltx4 tempDist = dist; + + TransposeSIMD(tempX, tempY, tempZ, tempDist); + + *(fltx4 *)pPlanesOut = tempX; + *(fltx4 *)++pPlanesOut = tempY; + *(fltx4 *)++pPlanesOut = tempZ; + *(fltx4 *)++pPlanesOut = tempDist; +} + +void fourplanes_t::Get2Planes( VPlane *pPlanesOut ) +{ + fltx4 tempX = nX; + fltx4 tempY = nY; + fltx4 tempZ = nZ; + fltx4 tempDist = dist; + + TransposeSIMD(tempX, tempY, tempZ, tempDist); + + *(fltx4 *)pPlanesOut = tempX; + *(fltx4 *)++pPlanesOut = tempY; +} + +void fourplanes_t::GetPlane( int index, Vector *pNormal, float *pDist ) const +{ + pNormal->x = SubFloat(nX, index); + pNormal->y = SubFloat(nY, index); + pNormal->z = SubFloat(nZ, index); + *pDist = SubFloat(dist, index); +} + +void fourplanes_t::SetPlane( int index, const Vector &vecNormal, float planeDist ) +{ + SubFloat(nX, index) = vecNormal.x; + SubFloat(nY, index) = vecNormal.y; + SubFloat(nZ, index) = vecNormal.z; + SubFloat(dist, index) = planeDist; + ComputeSignbits(); +} + +Frustum_t::Frustum_t() +{ + memset(planes, 0, sizeof(planes)); +} + +void Frustum_t::SetPlane( int i, const Vector &vecNormal, float dist ) +{ + if (i < 4) + planes[0].SetPlane(i, vecNormal, dist); + else + planes[1].SetPlane(i - 4, vecNormal, dist); +} + +void Frustum_t::GetPlane( int i, Vector *pNormalOut, float *pDistOut) const +{ + if (i < 4) + planes[0].GetPlane(i, pNormalOut, pDistOut); + else + planes[1].GetPlane(i - 4, pNormalOut, pDistOut); +} + +void Frustum_t::SetPlanes( const VPlane *pPlanes ) +{ + planes[0].Set4Planes(pPlanes); + planes[1].Set2Planes(pPlanes + 4); +} + +void Frustum_t::GetPlanes( VPlane *pPlanesOut ) +{ + planes[0].Get4Planes(pPlanesOut); + planes[1].Get2Planes(pPlanesOut + 4); +} + +bool Frustum_t::CullBox( const Vector &mins, const Vector &maxs ) const +{ + fltx4 mins4 = LoadUnalignedSIMD(&mins); + fltx4 maxs4 = LoadUnalignedSIMD(&maxs); + fltx4 minX = SplatXSIMD(mins4); + fltx4 minY = SplatYSIMD(mins4); + fltx4 minZ = SplatZSIMD(mins4); + fltx4 maxX = SplatXSIMD(maxs4); + fltx4 maxY = SplatYSIMD(maxs4); + fltx4 maxZ = SplatZSIMD(maxs4); + + for (int i = 0; i < 2; i++) + { + fltx4 xTotalBack = MulSIMD(planes[i].nX, MaskedAssign(planes[i].xSign, minX, maxX)); + fltx4 yTotalBack = MulSIMD(planes[i].nY, MaskedAssign(planes[i].ySign, minY, maxY)); + fltx4 zTotalBack = MulSIMD(planes[i].nZ, MaskedAssign(planes[i].zSign, minZ, maxZ)); + fltx4 dotBack = AddSIMD(xTotalBack, AddSIMD(yTotalBack, zTotalBack)); + + if (IsAnyNegative(CmpLtSIMD(dotBack, planes[i].dist))) + return true; + } + return false; +} + +bool Frustum_t::CullBoxCenterExtents( const Vector ¢er, const Vector &extents ) const +{ + fltx4 center4 = LoadUnalignedSIMD(¢er); + fltx4 extents4 = LoadUnalignedSIMD(&extents); + fltx4 centerX = SplatXSIMD(center4); + fltx4 centerY = SplatYSIMD(center4); + fltx4 centerZ = SplatZSIMD(center4); + fltx4 extentsX = SplatXSIMD(extents4); + fltx4 extentsY = SplatYSIMD(extents4); + fltx4 extentsZ = SplatZSIMD(extents4); + + for (int i = 0; i < 2; i++) + { + fltx4 xTotalBack = AddSIMD(MulSIMD(planes[i].nX, centerX), MulSIMD(planes[i].nXAbs, extentsX)); + fltx4 yTotalBack = AddSIMD(MulSIMD(planes[i].nY, centerY), MulSIMD(planes[i].nYAbs, extentsY)); + fltx4 zTotalBack = AddSIMD(MulSIMD(planes[i].nZ, centerZ), MulSIMD(planes[i].nZAbs, extentsZ)); + fltx4 dotBack = AddSIMD(xTotalBack, AddSIMD(yTotalBack, zTotalBack)); + + if (IsAnyNegative(CmpLtSIMD(dotBack, planes[i].dist))) + return true; + } + return false; +} + +bool Frustum_t::CullBox( const fltx4 &fl4Mins, const fltx4 &fl4Maxs ) const +{ + fltx4 minX = SplatXSIMD(fl4Mins); + fltx4 minY = SplatYSIMD(fl4Mins); + fltx4 minZ = SplatZSIMD(fl4Mins); + fltx4 maxX = SplatXSIMD(fl4Maxs); + fltx4 maxY = SplatYSIMD(fl4Maxs); + fltx4 maxZ = SplatZSIMD(fl4Maxs); + + for (int i = 0; i < 2; i++) + { + fltx4 xTotalBack = MulSIMD(planes[i].nX, MaskedAssign(planes[i].xSign, minX, maxX)); + fltx4 yTotalBack = MulSIMD(planes[i].nY, MaskedAssign(planes[i].ySign, minY, maxY)); + fltx4 zTotalBack = MulSIMD(planes[i].nZ, MaskedAssign(planes[i].zSign, minZ, maxZ)); + fltx4 dotBack = AddSIMD(xTotalBack, AddSIMD(yTotalBack, zTotalBack)); + + if (IsAnyNegative(CmpLtSIMD(dotBack, planes[i].dist))) + return true; + } + return false; +} + +bool Frustum_t::CullBoxCenterExtents( const fltx4 &fl4Center, const fltx4 &fl4Extents ) const +{ + fltx4 centerX = SplatXSIMD(fl4Center); + fltx4 centerY = SplatYSIMD(fl4Center); + fltx4 centerZ = SplatZSIMD(fl4Center); + fltx4 extentsX = SplatXSIMD(fl4Extents); + fltx4 extentsY = SplatYSIMD(fl4Extents); + fltx4 extentsZ = SplatZSIMD(fl4Extents); + + for (int i = 0; i < 2; i++) + { + fltx4 xTotalBack = AddSIMD(MulSIMD(planes[i].nX, centerX), MulSIMD(planes[i].nXAbs, extentsX)); + fltx4 yTotalBack = AddSIMD(MulSIMD(planes[i].nY, centerY), MulSIMD(planes[i].nYAbs, extentsY)); + fltx4 zTotalBack = AddSIMD(MulSIMD(planes[i].nZ, centerZ), MulSIMD(planes[i].nZAbs, extentsZ)); + fltx4 dotBack = AddSIMD(xTotalBack, AddSIMD(yTotalBack, zTotalBack)); + + if (IsAnyNegative(CmpLtSIMD(dotBack, planes[i].dist))) + return true; + } + return false; +} + diff --git a/mathlib/quantize.cpp b/mathlib/quantize.cpp index dbaf15f2..2f4b64f2 100644 --- a/mathlib/quantize.cpp +++ b/mathlib/quantize.cpp @@ -21,6 +21,8 @@ #include +#include "tier0/basetypes.h" + static int current_ndims; static struct QuantizedValue *current_root; static int current_ssize; diff --git a/mathlib/sse.cpp b/mathlib/sse.cpp index d524d2b7..d39c24f8 100644 --- a/mathlib/sse.cpp +++ b/mathlib/sse.cpp @@ -172,7 +172,7 @@ float _SSE_RSqrtFast(float x) { Assert( s_bMathlibInitialized ); - float rroot; + float rroot = 0.0f; #ifdef _WIN32 _asm { diff --git a/mathlib/vector.cpp b/mathlib/vector.cpp index 318f7ec1..30710908 100644 --- a/mathlib/vector.cpp +++ b/mathlib/vector.cpp @@ -6,7 +6,8 @@ // //=============================================================================// +#include "mathlib/mathlib.h" #include "mathlib/vector.h" -Vector vec3_origin(0,0,0); +const Vector vec3_origin(0,0,0); diff --git a/mathlib/vmatrix.cpp b/mathlib/vmatrix.cpp index e4aa096f..23423596 100644 --- a/mathlib/vmatrix.cpp +++ b/mathlib/vmatrix.cpp @@ -11,6 +11,7 @@ #include "basetypes.h" #include "mathlib/vmatrix.h" #include "mathlib/mathlib.h" +#include "mathlib/ssemath.h" #include #include "mathlib/vector4d.h" #include "tier0/dbg.h" @@ -1177,27 +1178,27 @@ void FrustumPlanesFromMatrix( const VMatrix &clipToWorld, Frustum_t &frustum ) FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 0.0f, 0.0f, 0.0f ), Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 0.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_NEARZ, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_NEARZ, normal, dist ); FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 0.0f, 0.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_FARZ, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_FARZ, normal, dist ); FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 1.0f, 0.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 1.0f, 1.0f, 0.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_RIGHT, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_RIGHT, normal, dist ); FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 0.0f, 0.0f, 0.0f ), Vector( 0.0f, 1.0f, 1.0f ), Vector( 0.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_LEFT, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_LEFT, normal, dist ); FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 1.0f, 1.0f, 0.0f ), Vector( 1.0f, 1.0f, 1.0f ), Vector( 0.0f, 1.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_TOP, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_TOP, normal, dist ); FrustumPlanesFromMatrixHelper( clipToWorld, Vector( 1.0f, 0.0f, 0.0f ), Vector( 0.0f, 0.0f, 1.0f ), Vector( 1.0f, 0.0f, 1.0f ), normal, dist ); - frustum.SetPlane( FRUSTUM_BOTTOM, PLANE_ANYZ, normal, dist ); + frustum.SetPlane( FRUSTUM_BOTTOM, normal, dist ); } void MatrixBuildOrtho( VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar ) diff --git a/public/bitmap/imageformat.h b/public/bitmap/imageformat.h index 8a9e8f03..b5bdf43b 100644 --- a/public/bitmap/imageformat.h +++ b/public/bitmap/imageformat.h @@ -33,7 +33,9 @@ typedef enum DXGI_FORMAT; //----------------------------------------------------------------------------- // don't bitch that inline functions aren't used!!!! +#ifdef _MSC_VER #pragma warning(disable : 4514) +#endif enum ImageFormat { @@ -170,24 +172,31 @@ typedef enum _D3DFORMAT //----------------------------------------------------------------------------- // Color structures //----------------------------------------------------------------------------- +#ifdef _MSC_VER #pragma warning ( disable : 4293 ) +#endif template< int nBitCount > FORCEINLINE int ConvertTo10Bit( int x ) { switch ( nBitCount ) { - case 1: - return ( x & 0x1 ) ? 0x3FF : 0; - case 2: - return ( x << 8 ) | ( x << 6 ) | ( x << 4 ) | ( x << 2 ) | x; - case 3: - return ( x << 7 ) | ( x << 4 ) | ( x << 1 ) | ( x >> 2 ); - case 4: - return ( x << 6 ) | ( x << 2 ) | ( x >> 2 ); - default: - return ( x << ( 10 - nBitCount ) ) | ( x >> ( nBitCount - ( 10 - nBitCount ) ) ); + case 1: + return ( x & 0x1 ) ? 0x3FF : 0; + case 2: + return ( x << 8 ) | ( x << 6 ) | ( x << 4 ) | ( x << 2 ) | x; + case 3: + return ( x << 7 ) | ( x << 4 ) | ( x << 1 ) | ( x >> 2 ); + case 4: + return ( x << 6 ) | ( x << 2 ) | ( x >> 2 ); + default: + { + int rshift = ( nBitCount - ( 10 - nBitCount ) ); + return ( x << ( 10 - nBitCount ) ) | ( x >> rshift ); + } } } +#ifdef _MSC_VER #pragma warning ( default : 4293 ) +#endif template< int nBitCount > FORCEINLINE int ConvertFrom10Bit( int x ) { @@ -622,7 +631,7 @@ namespace ImageLoader struct ResampleInfo_t { - ResampleInfo_t() : m_nFlags(0), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nSrcDepth(1), m_nDestDepth(1) + ResampleInfo_t() : m_nSrcDepth(1), m_nDestDepth(1), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nFlags(0) { m_flColorScale[0] = 1.0f, m_flColorScale[1] = 1.0f, m_flColorScale[2] = 1.0f, m_flColorScale[3] = 1.0f; m_flColorGoal[0] = 0.0f, m_flColorGoal[1] = 0.0f, m_flColorGoal[2] = 0.0f, m_flColorGoal[3] = 0.0f; diff --git a/public/bspfile.h b/public/bspfile.h index 8083fdd4..c69483dc 100644 --- a/public/bspfile.h +++ b/public/bspfile.h @@ -882,7 +882,9 @@ struct dfaceid_t #if defined( _X360 ) #pragma bitfield_order( push, lsb_to_msb ) #endif +#ifdef _MSC_VER #pragma warning( disable:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif struct dleaf_version_0_t { DECLARE_BYTESWAP_DATADESC(); @@ -936,7 +938,9 @@ struct dleaf_t // Precaculated light info for entities. // CompressedLightCube m_AmbientLighting; }; +#ifdef _MSC_VER #pragma warning( default:4201 ) // C4201: nonstandard extension used: nameless struct/union +#endif #if defined( _X360 ) #pragma bitfield_order( pop ) #endif diff --git a/public/datacache/idatacache.h b/public/datacache/idatacache.h index f0d7191c..0ff98db4 100644 --- a/public/datacache/idatacache.h +++ b/public/datacache/idatacache.h @@ -16,7 +16,7 @@ #include "tier0/dbg.h" -#include "appframework/iappsystem.h" +#include "appframework/IAppSystem.h" #include "tier3/tier3.h" class IDataCache; diff --git a/public/datacache/imdlcache.h b/public/datacache/imdlcache.h index a46154c0..8ab212cd 100644 --- a/public/datacache/imdlcache.h +++ b/public/datacache/imdlcache.h @@ -19,7 +19,7 @@ #pragma once #endif -#include "appframework/iappsystem.h" +#include "appframework/IAppSystem.h" //----------------------------------------------------------------------------- // Forward declarations diff --git a/public/dt_common.h b/public/dt_common.h index de9a4933..41f97dfb 100644 --- a/public/dt_common.h +++ b/public/dt_common.h @@ -138,7 +138,7 @@ public: switch ( m_Type ) { case DPT_Int : - Q_snprintf( text, sizeof(text), "%i", m_Int ); + Q_snprintf( text, sizeof(text), "%i", (int)m_Int ); break; case DPT_Float : Q_snprintf( text, sizeof(text), "%.3f", m_Float ); @@ -170,7 +170,7 @@ public: Q_snprintf( text, sizeof(text), "DataTable" ); break; case DPT_Int64: - Q_snprintf( text, sizeof(text), "%I64d", m_Int64 ); + Q_snprintf( text, sizeof(text), "%lld", m_Int64 ); break; default : Q_snprintf( text, sizeof(text), "DVariant type %i unknown", m_Type ); diff --git a/public/filesystem.h b/public/filesystem.h index a2337cc9..1c125bf0 100644 --- a/public/filesystem.h +++ b/public/filesystem.h @@ -20,7 +20,7 @@ #include "tier1/interface.h" #include "tier1/utlsymbol.h" #include "tier1/utlstring.h" -#include "tier1/functors.h" +//#include "tier1/functors.h" #include "tier1/checksum_crc.h" #include "tier1/utlqueue.h" #include "appframework/IAppSystem.h" @@ -539,7 +539,7 @@ public: ) = 0; virtual void FindFileAbsoluteList( - CUtlVector> &output, + CUtlVector &output, const char *pWildCard, const char *pPathID ) = 0; diff --git a/public/filesystem_passthru.h b/public/filesystem_passthru.h index 182e6c3f..01db1a93 100644 --- a/public/filesystem_passthru.h +++ b/public/filesystem_passthru.h @@ -166,7 +166,7 @@ public: FileFindHandle_t *pHandle ) { return m_pFileSystemPassThru->FindFirstEx( pWildCard, pPathID, pHandle ); } virtual void FindFileAbsoluteList( - CUtlVector> &output, + CUtlVector &output, const char *pWildCard, const char *pPathID ) { m_pFileSystemPassThru->FindFileAbsoluteList( output, pWildCard, pPathID ); } diff --git a/public/inetchannel.h b/public/inetchannel.h index 46388397..218d7a21 100644 --- a/public/inetchannel.h +++ b/public/inetchannel.h @@ -61,7 +61,7 @@ public: virtual bool SendNetMsg(INetMessage &msg, bool bForceReliable = false, bool bVoice = false ) = 0; #ifdef POSIX - FORCEINLINE bool SendNetMsg(INetMessage const &msg, bool bForceReliable = false, bool bVoice = false ) { SendNetMsg( *( (INetMessage *) &msg ), bForceReliable, bVoice ); } + FORCEINLINE bool SendNetMsg(INetMessage const &msg, bool bForceReliable = false, bool bVoice = false ) { return SendNetMsg( *( (INetMessage *) &msg ), bForceReliable, bVoice ); } #endif virtual bool SendData(bf_write &msg, bool bReliable = true) = 0; virtual bool SendFile(const char *filename, unsigned int transferID, bool isReplayDemo) = 0; diff --git a/public/mathlib/ssemath.h b/public/mathlib/ssemath.h index cf00a14e..e54e444c 100644 --- a/public/mathlib/ssemath.h +++ b/public/mathlib/ssemath.h @@ -2844,6 +2844,7 @@ FORCEINLINE fltx4 LoadAndConvertUint16SIMD( const uint16 *pInts ) SubFloat( retval, 1 ) = pInts[1]; SubFloat( retval, 2 ) = pInts[2]; SubFloat( retval, 3 ) = pInts[3]; + return retval; #else __m128i inA = _mm_loadl_epi64( (__m128i const*) pInts); // Load the lower 64 bits of the value pointed to by p into the lower 64 bits of the result, zeroing the upper 64 bits of the result. inA = _mm_unpacklo_epi16( inA, _mm_setzero_si128() ); // unpack unsigned 16's to signed 32's @@ -4057,7 +4058,7 @@ public: FORCEINLINE void Init( void ) { - for( int i = 0; i < ARRAYSIZE( m_Mins ); i++ ) + for( int i = 0; i < (int)ARRAYSIZE( m_Mins ); i++ ) { m_Mins[i] = Four_FLT_MAX; m_Maxes[i] = Four_Negative_FLT_MAX; diff --git a/public/mathlib/ssequaternion.h b/public/mathlib/ssequaternion.h index 234cff5b..ce55cc66 100644 --- a/public/mathlib/ssequaternion.h +++ b/public/mathlib/ssequaternion.h @@ -811,7 +811,7 @@ FORCEINLINE FourQuaternions FourQuaternions::ScaleAngle( const fltx4 &scale ) co { FourQuaternions ret; static const fltx4 OneMinusEpsilon = {1.0f - 0.000001f, 1.0f - 0.000001f, 1.0f - 0.000001f, 1.0f - 0.000001f }; - static const fltx4 tiny = { 0.00001f, 0.00001f, 0.00001f, 0.00001f }; + //static const fltx4 tiny = { 0.00001f, 0.00001f, 0.00001f, 0.00001f }; const fltx4 Zero = Four_Zeros; fltx4 signMask = LoadAlignedSIMD( (float *) g_SIMD_signmask ); // work out if there are any tiny scales or angles, which are unstable diff --git a/public/studio.h b/public/studio.h index b318f40b..665e9558 100644 --- a/public/studio.h +++ b/public/studio.h @@ -2716,7 +2716,7 @@ public: // ctor CActivityToSequenceMapping( void ) - : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), m_ActToSeqHash(8,0,0), m_expectedVModel(NULL), m_pStudioHdr(NULL) + : m_pSequenceTuples(NULL), m_iSequenceTuplesCount(0), m_ActToSeqHash(8,0,0), m_pStudioHdr(NULL), m_expectedVModel(NULL) {}; // dtor -- not virtual because this class has no inheritors diff --git a/public/tier0/dbg.h b/public/tier0/dbg.h index 1eb3455c..cad625b8 100644 --- a/public/tier0/dbg.h +++ b/public/tier0/dbg.h @@ -352,11 +352,12 @@ PLATFORM_INTERFACE void _AssertValidReadPtr( void* ptr, int count = 1 ); PLATFORM_INTERFACE void _AssertValidWritePtr( void* ptr, int count = 1 ); PLATFORM_INTERFACE void _AssertValidReadWritePtr( void* ptr, int count = 1 ); -PLATFORM_INTERFACE void AssertValidStringPtr( const tchar* ptr, int maxchar = 0xFFFFFF ); +PLATFORM_INTERFACE void _AssertValidStringPtr( const tchar* ptr, int maxchar = 0xFFFFFF ); template inline void AssertValidReadPtr( T* ptr, int count = 1 ) { _AssertValidReadPtr( (void*)ptr, count ); } template inline void AssertValidWritePtr( T* ptr, int count = 1 ) { _AssertValidWritePtr( (void*)ptr, count ); } template inline void AssertValidReadWritePtr( T* ptr, int count = 1 ) { _AssertValidReadWritePtr( (void*)ptr, count ); } + #define AssertValidThis() AssertValidReadWritePtr(this,sizeof(*this)) //----------------------------------------------------------------------------- diff --git a/public/tier0/fasttimer.h b/public/tier0/fasttimer.h index 57c7a5d9..9778cc76 100644 --- a/public/tier0/fasttimer.h +++ b/public/tier0/fasttimer.h @@ -293,8 +293,10 @@ inline void CCycleCount::Init( uint64 cycles ) m_Int64 = cycles; } +#ifdef COMPILER_MSVC #pragma warning(push) #pragma warning(disable : 4189) // warning C4189: local variable is initialized but not referenced +#endif inline void CCycleCount::Sample() { @@ -341,7 +343,9 @@ inline void CCycleCount::Sample() #endif } +#ifdef COMPILER_MSVC #pragma warning(pop) +#endif inline CCycleCount& CCycleCount::operator+=( CCycleCount const &other ) diff --git a/public/tier0/logging.h b/public/tier0/logging.h index b75f727b..2fa6c45b 100644 --- a/public/tier0/logging.h +++ b/public/tier0/logging.h @@ -14,7 +14,7 @@ #pragma once #endif -#include "color.h" +#include "Color.h" #include "icommandline.h" #include @@ -133,7 +133,7 @@ typedef int LoggingChannelID_t; //----------------------------------------------------------------------------- // A sentinel value indicating an invalid logging channel ID. //----------------------------------------------------------------------------- -const LoggingChannelID_t INVALID_LOGGING_CHANNEL_ID = -1; +static const LoggingChannelID_t INVALID_LOGGING_CHANNEL_ID = -1; //----------------------------------------------------------------------------- // The severity of a logging operation. @@ -337,7 +337,7 @@ public: // A logging listener with Win32 console API color support which which prints // to stdout and the debug channel. //----------------------------------------------------------------------------- -#ifndef _X360 +#if !defined _X360 && defined COMPILER_MSVC class CColorizedLoggingListener : public CSimpleLoggingListener { public: @@ -743,4 +743,4 @@ PLATFORM_OVERLOAD LoggingResponse_t LoggingSystem_Log( LoggingChannelID_t channe PLATFORM_INTERFACE LoggingResponse_t LoggingSystem_LogDirect( LoggingChannelID_t channelID, LoggingSeverity_t severity, Color spewColor, const char *pMessage ); PLATFORM_INTERFACE LoggingResponse_t LoggingSystem_LogAssert( const char *pMessageFormat, ... ) FMTFUNCTION( 1, 2 ); -#endif // LOGGING_H \ No newline at end of file +#endif // LOGGING_H diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 4d78bd4c..1233e0aa 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -101,7 +101,9 @@ typedef void * HINSTANCE; #define IsPlatformOSX() false #define IsPlatformPS3() false #define IsPlatformWindows() true + #ifndef PLATFORM_WINDOWS #define PLATFORM_WINDOWS 1 + #endif #ifndef _X360 #define IsPlatformX360() false @@ -136,16 +138,22 @@ typedef void * HINSTANCE; #define IsPlatformWindowsPC64() false #define IsPlatformWindowsPC32() false #define IsPlatformPosix() true + #ifndef PLATFORM_POSIX #define PLATFORM_POSIX 1 + #endif #if defined( LINUX ) #define IsPlatformLinux() true #define IsPlatformOSX() false + #ifndef PLATFORM_LINUX #define PLATFORM_LINUX 1 + #endif #elif defined ( OSX ) #define IsPlatformLinux() false #define IsPlatformOSX() true + #ifndef PLATFORM_OSX #define PLATFORM_OSX 1 + #endif #else #define IsPlatformLinux() false #define IsPlatformOSX() false @@ -701,6 +709,7 @@ PLATFORM_INTERFACE void Plat_MessageBox( const char *pTitle, const tchar *pMessa #define _putenv putenv #define _chdir chdir #define _access access +#define _strtoi64 strtoll #if !defined( _snprintf ) // some vpc's define this on the command line #define _snprintf snprintf @@ -1596,9 +1605,15 @@ int V_strncasecmp (const char *s1, const char *s2, int n); // returns <0 if strings do not match even in a case-insensitive way int _V_stricmp_NegativeForUnequal ( const char *s1, const char *s2 ); +#ifndef stricmp #define stricmp(s1,s2) _V_stricmp(s1, s2) +#endif +#ifndef strcmpi #define strcmpi(s1,s2) _V_stricmp(s1, s2) -#define strnicmp V_strncasecmp +#endif +#ifndef strnicmp +#define strnicmp V_strncasecmp +#endif #endif #endif /* PLATFORM_H */ diff --git a/public/tier0/threadtools.h b/public/tier0/threadtools.h index 262259e5..9fbf74ed 100644 --- a/public/tier0/threadtools.h +++ b/public/tier0/threadtools.h @@ -1681,8 +1681,8 @@ FORCEINLINE bool CThreadSpinRWLock::TryLockForWrite( const uint32 threadId ) return false; } - static const LockInfo_t oldValue = { 0, 0 }; - LockInfo_t newValue = { threadId, 0 }; + static const LockInfo_t oldValue = {{ 0, 0 }}; + LockInfo_t newValue = {{ threadId, 0 }}; if ( AssignIf( newValue, oldValue ) ) { ThreadMemoryBarrier(); diff --git a/public/tier1/KeyValues.h b/public/tier1/KeyValues.h index 98488cda..9eeb47bd 100644 --- a/public/tier1/KeyValues.h +++ b/public/tier1/KeyValues.h @@ -21,7 +21,7 @@ #endif #include "utlvector.h" -#include "color.h" +#include "Color.h" #include "exprevaluator.h" class IBaseFileSystem; diff --git a/public/tier1/bitbuf.h b/public/tier1/bitbuf.h index 702f86f2..ad8c9dad 100644 --- a/public/tier1/bitbuf.h +++ b/public/tier1/bitbuf.h @@ -778,7 +778,7 @@ public: } else { - StoreLittleDWord( m_pDataOut, 0, LoadLittleDWord(m_pDataOut,0) & ~s_nMaskTable[ 32 - m_nOutBitsAvail ] | m_nOutBufWord ); + StoreLittleDWord( m_pDataOut, 0, (LoadLittleDWord(m_pDataOut,0) & ~s_nMaskTable[ 32 - m_nOutBitsAvail ]) | m_nOutBufWord ); } } m_bFlushed = true; diff --git a/public/tier1/byteswap.h b/public/tier1/byteswap.h index c41aefc5..54699620 100644 --- a/public/tier1/byteswap.h +++ b/public/tier1/byteswap.h @@ -240,7 +240,7 @@ private: Assert( "Invalid size in CByteswap::LowLevelByteSwap" && 0 ); } #else - for( int i = 0; i < sizeof(T); i++ ) + for( size_t i = 0; i < sizeof(T); i++ ) { ((unsigned char* )&temp)[i] = ((unsigned char*)input)[sizeof(T)-(i+1)]; } diff --git a/public/tier1/characterset.h b/public/tier1/characterset.h index 53734a27..6465893e 100644 --- a/public/tier1/characterset.h +++ b/public/tier1/characterset.h @@ -37,7 +37,7 @@ extern void CharacterSetBuild( characterset_t *pSetBuffer, const char *pSetStrin // character - character to lookup // Output : int - 1 if the character was in the set //----------------------------------------------------------------------------- -#define IN_CHARACTERSET( SetBuffer, character ) ((SetBuffer).set[(character)]) +#define IN_CHARACTERSET( SetBuffer, character ) ((SetBuffer).set[static_cast(character)]) #endif // CHARACTERSET_H diff --git a/public/tier1/convar.h b/public/tier1/convar.h index 6acbd8c9..29fddb72 100644 --- a/public/tier1/convar.h +++ b/public/tier1/convar.h @@ -20,7 +20,7 @@ #include "tier1/iconvar.h" #include "tier1/utlvector.h" #include "tier1/utlstring.h" -#include "color.h" +#include "Color.h" #include "icvar.h" #ifdef _WIN32 @@ -874,7 +874,9 @@ void ConVar_PrintDescription( const ConCommandBase *pVar ); //----------------------------------------------------------------------------- // Purpose: Utility class to quickly allow ConCommands to call member methods //----------------------------------------------------------------------------- +#ifdef _MSC_VER #pragma warning (disable : 4355 ) +#endif template< class T > class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback @@ -921,8 +923,9 @@ private: FnMemberCommandCompletionCallback_t m_CompletionFunc; }; +#ifdef _MSC_VER #pragma warning ( default : 4355 ) - +#endif //----------------------------------------------------------------------------- // Purpose: Utility macros to quicky generate a simple console command diff --git a/public/tier1/iconvar.h b/public/tier1/iconvar.h index 3a865733..722960b7 100644 --- a/public/tier1/iconvar.h +++ b/public/tier1/iconvar.h @@ -19,7 +19,7 @@ #include "tier0/dbg.h" #include "tier0/platform.h" #include "tier1/strtools.h" -#include "color.h" +#include "Color.h" //----------------------------------------------------------------------------- diff --git a/public/tier1/tier1.h b/public/tier1/tier1.h index 1281f8ed..35a3bff2 100644 --- a/public/tier1/tier1.h +++ b/public/tier1/tier1.h @@ -12,7 +12,7 @@ #pragma once #endif -#include "appframework/iappsystem.h" +#include "appframework/IAppSystem.h" #include "tier1/convar.h" //----------------------------------------------------------------------------- diff --git a/public/tier1/utlblockmemory.h b/public/tier1/utlblockmemory.h index f1d952ed..5d30c49d 100644 --- a/public/tier1/utlblockmemory.h +++ b/public/tier1/utlblockmemory.h @@ -21,8 +21,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#ifdef _MSC_VER #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/public/tier1/utlbuffer.h b/public/tier1/utlbuffer.h index d1a12d8a..f2c4284b 100644 --- a/public/tier1/utlbuffer.h +++ b/public/tier1/utlbuffer.h @@ -41,7 +41,7 @@ public: struct ConversionArray_t { char m_nActualChar; - char *m_pReplacementString; + const char *m_pReplacementString; }; CUtlCharConversion( char nEscapeChar, const char *pDelimiter, int nCount, ConversionArray_t *pArray ); @@ -60,7 +60,7 @@ protected: struct ConversionInfo_t { int m_nLength; - char *m_pReplacementString; + const char *m_pReplacementString; }; char m_nEscapeChar; @@ -110,13 +110,13 @@ typedef unsigned short ushort; template < class A > static const char *GetFmtStr( int nRadix = 10, bool bPrint = true ) { Assert( 0 ); return ""; } -template <> static const char *GetFmtStr< short > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hd"; } -template <> static const char *GetFmtStr< ushort > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hu"; } -template <> static const char *GetFmtStr< int > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%d"; } -template <> static const char *GetFmtStr< uint > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 || nRadix == 16 ); return nRadix == 16 ? "%x" : "%u"; } -template <> static const char *GetFmtStr< int64 > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%I64d"; } -template <> static const char *GetFmtStr< float > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%f"; } -template <> static const char *GetFmtStr< double > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return bPrint ? "%.15lf" : "%lf"; } // force Printf to print DBL_DIG=15 digits of precision for doubles - defaults to FLT_DIG=6 +template <> inline const char *GetFmtStr< short > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hd"; } +template <> inline const char *GetFmtStr< ushort > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%hu"; } +template <> inline const char *GetFmtStr< int > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%d"; } +template <> inline const char *GetFmtStr< uint > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 || nRadix == 16 ); return nRadix == 16 ? "%x" : "%u"; } +template <> inline const char *GetFmtStr< int64 > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%lld"; } +template <> inline const char *GetFmtStr< float > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return "%f"; } +template <> inline const char *GetFmtStr< double > ( int nRadix, bool bPrint ) { Assert( nRadix == 10 ); return bPrint ? "%.15lf" : "%lf"; } // force Printf to print DBL_DIG=15 digits of precision for doubles - defaults to FLT_DIG=6 //----------------------------------------------------------------------------- @@ -784,14 +784,14 @@ inline int64 StringToNumber( char *pString, char **ppEnd, int nRadix ) template <> inline float StringToNumber( char *pString, char **ppEnd, int nRadix ) { - /*UNUSED*/( nRadix ); + // /*UNUSED*/( nRadix ); return ( float )strtod( pString, ppEnd ); } template <> inline double StringToNumber( char *pString, char **ppEnd, int nRadix ) { - /*UNUSED*/( nRadix ); + // /*UNUSED*/( nRadix ); return ( double )strtod( pString, ppEnd ); } @@ -1349,7 +1349,7 @@ inline void CUtlBuffer::Spew( ) while( IsValid() && GetBytesRemaining() ) { V_memset( pTmpLine, 0, sizeof(pTmpLine) ); - Get( pTmpLine, MIN( GetBytesRemaining(), sizeof(pTmpLine-1) ) ); + Get( pTmpLine, MIN( (unsigned int)GetBytesRemaining(), sizeof(pTmpLine-1) ) ); Msg( _T( "%s" ), pTmpLine ); } } diff --git a/public/tier1/utlfixedmemory.h b/public/tier1/utlfixedmemory.h index 178a49f1..c832ac7e 100644 --- a/public/tier1/utlfixedmemory.h +++ b/public/tier1/utlfixedmemory.h @@ -20,8 +20,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#ifdef _MSC_VER #pragma warning (disable:4100) #pragma warning (disable:4514) +#endif //----------------------------------------------------------------------------- diff --git a/public/tier1/utllinkedlist.h b/public/tier1/utllinkedlist.h index 984680ca..8db437bc 100644 --- a/public/tier1/utllinkedlist.h +++ b/public/tier1/utllinkedlist.h @@ -198,7 +198,7 @@ public: return false; #ifdef _DEBUG // it's safe to skip this here, since the only way to get indices after m_LastAlloc is to use MaxElementIndex - if ( Memory().IsIdxAfter( i, this->m_LastAlloc ) ) + if ( this->Memory().IsIdxAfter( i, this->m_LastAlloc ) ) { Assert( 0 ); return false; // don't read values that have been allocated, but not constructed @@ -339,8 +339,10 @@ inline I CUtlLinkedList::Next( I i ) const // Are nodes in the list or valid? //----------------------------------------------------------------------------- +#ifdef _MSC_VER #pragma warning(push) #pragma warning( disable: 4310 ) // Allows "(I)(S)M::INVALID_INDEX" below +#endif template inline bool CUtlLinkedList::IndexInRange( I index ) // Static method { @@ -359,7 +361,9 @@ inline bool CUtlLinkedList::IndexInRange( I index ) // Static method return ( ( (S)index == index ) && ( (S)index != InvalidIndex() ) ); } +#ifdef _MSC_VER #pragma warning(pop) +#endif template inline bool CUtlLinkedList::IsValidIndex( I i ) const diff --git a/public/tier1/utlmemory.h b/public/tier1/utlmemory.h index 2f7a41dc..601e722d 100644 --- a/public/tier1/utlmemory.h +++ b/public/tier1/utlmemory.h @@ -21,9 +21,10 @@ #include "tier0/memalloc.h" #include "tier0/memdbgon.h" +#ifdef _MSC_VER #pragma warning (disable:4100) #pragma warning (disable:4514) - +#endif //----------------------------------------------------------------------------- diff --git a/public/tier1/utlrbtree.h b/public/tier1/utlrbtree.h index 9929a723..5b55004b 100644 --- a/public/tier1/utlrbtree.h +++ b/public/tier1/utlrbtree.h @@ -360,8 +360,8 @@ protected: template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( int growSize, int initSize, const LessFunc_t &lessfunc ) : -m_Elements( growSize, initSize ), m_LessFunc( lessfunc ), +m_Elements( growSize, initSize ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -372,8 +372,8 @@ m_LastAlloc( m_Elements.InvalidIterator() ) template < class T, class I, typename L, class M > inline CUtlRBTree::CUtlRBTree( const LessFunc_t &lessfunc ) : -m_Elements( 0, 0 ), m_LessFunc( lessfunc ), +m_Elements( 0, 0 ), m_Root( InvalidIndex() ), m_NumElements( 0 ), m_FirstFree( InvalidIndex() ), @@ -648,8 +648,10 @@ inline void CUtlRBTree::SetColor( I i, typename CUtlRBTree I CUtlRBTree::NewNode() { @@ -694,7 +696,9 @@ I CUtlRBTree::NewNode() return elem; } +#ifdef _MSC_VER #pragma warning(pop) +#endif template < class T, class I, typename L, class M > void CUtlRBTree::FreeNode( I i ) diff --git a/public/tier1/utlsoacontainer.h b/public/tier1/utlsoacontainer.h index 3fcae9dc..592391a9 100644 --- a/public/tier1/utlsoacontainer.h +++ b/public/tier1/utlsoacontainer.h @@ -441,13 +441,13 @@ class CSOAAttributeReference; // define binary op class to allow this construct without temps: // dest( FBM_ATTR_RED ) = src( FBM_ATTR_BLUE ) + src( FBM_ATTR_GREEN ) -template class CSOAAttributeReferenceBinaryOp +template class CSOAAttributeReferenceBinaryOp { public: - CSOAAttributeReference m_opA; - CSOAAttributeReference m_opB; + Ref m_opA; + Ref m_opB; - CSOAAttributeReferenceBinaryOp( CSOAAttributeReference const &a, CSOAAttributeReference const & b ) + CSOAAttributeReferenceBinaryOp( Ref const &a, Ref const & b ) { a.CopyTo( m_opA ); b.CopyTo( m_opB ); @@ -456,9 +456,9 @@ public: }; #define DEFINE_OP( opname, fnname ) \ -FORCEINLINE CSOAAttributeReferenceBinaryOp operator opname( CSOAAttributeReference const &other ) const \ +FORCEINLINE CSOAAttributeReferenceBinaryOp operator opname( CSOAAttributeReference const &other ) const \ { \ - return CSOAAttributeReferenceBinaryOp( *this, other ); \ + return CSOAAttributeReferenceBinaryOp( *this, other ); \ } class CSOAAttributeReference @@ -498,18 +498,18 @@ public: DEFINE_OP( -, SubSIMD ); DEFINE_OP( /, DivSIMD ); - template FORCEINLINE void operator =( CSOAAttributeReferenceBinaryOp const &op ); + template FORCEINLINE void operator =( CSOAAttributeReferenceBinaryOp const &op ); FORCEINLINE void CopyTo( CSOAAttributeReference &other ) const; // since operator= is over-ridden }; -template FORCEINLINE void CSOAAttributeReference::operator =( CSOAAttributeReferenceBinaryOp const &op ) +template FORCEINLINE void CSOAAttributeReference::operator =( CSOAAttributeReferenceBinaryOp const &op ) { m_pContainer->AssertDataType( m_nAttributeID, ATTRDATATYPE_FLOAT ); fltx4 *pOut = m_pContainer->RowPtr( m_nAttributeID, 0 ); - fltx4 *pInA = op.m_opA.m_pContainer->RowPtr( op.m_opA.m_nAttributeID, 0 ); - fltx4 *pInB = op.m_opB.m_pContainer->RowPtr( op.m_opB.m_nAttributeID, 0 ); + fltx4 *pInA = op.m_opA.m_pContainer->template RowPtr( op.m_opA.m_nAttributeID, 0 ); + fltx4 *pInB = op.m_opB.m_pContainer->template RowPtr( op.m_opB.m_nAttributeID, 0 ); size_t nRowToRowStride = m_pContainer->RowToRowStep( m_nAttributeID ) / sizeof( fltx4 ); int nRowCtr = m_pContainer->NumRows() * m_pContainer->NumSlices(); do @@ -576,7 +576,8 @@ template void CSOAContainer::App int nColCtr = NumQuadsPerRow(); do { - *( pOut++ ) = fn1( fn2( *pOut, fl4FnArg2 ), fl4FnArg1 ); + *( pOut ) = fn1( fn2( *pOut, fl4FnArg2 ), fl4FnArg1 ); + pOut++; } while ( --nColCtr ); pOut += nRowToRowStride; } while ( --nRowCtr ); @@ -613,7 +614,8 @@ template void CSOAContainer::ApplyBinaryFunctionToAttr( i int nColCtr = NumQuadsPerRow(); do { - *(pOut++) = fn( *pOut, fl4FnArg1 ); + *(pOut) = fn( *pOut, fl4FnArg1 ); + pOut++; } while ( --nColCtr ); pOut += nRowToRowStride; } while ( --nRowCtr ); diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h index bb15df23..f397038a 100644 --- a/public/tier1/utlvector.h +++ b/public/tier1/utlvector.h @@ -259,9 +259,11 @@ public: // Especialy useful if you have a lot of vectors that are sparse, or if you're // carefully packing holders of vectors //----------------------------------------------------------------------------- +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union #pragma warning(disable : 4815 ) // warning C4815: 'staticData' : zero-sized array in stack object will have no elements +#endif class CUtlVectorUltraConservativeAllocator { @@ -499,8 +501,9 @@ private: } }; +#ifdef _MSC_VER #pragma warning(pop) - +#endif //----------------------------------------------------------------------------- // The CCopyableUtlVector class: diff --git a/public/vstdlib/iprocessutils.h b/public/vstdlib/iprocessutils.h index feecb009..2aec95ca 100644 --- a/public/vstdlib/iprocessutils.h +++ b/public/vstdlib/iprocessutils.h @@ -12,7 +12,6 @@ #endif -#include "appframework/iappsystem.h" #include "appframework/IAppSystem.h" #include "tier1/utlstring.h" #include "tier1/utlbuffer.h" diff --git a/public/vstdlib/random.h b/public/vstdlib/random.h index 94ae57b1..cace9fa9 100644 --- a/public/vstdlib/random.h +++ b/public/vstdlib/random.h @@ -16,8 +16,10 @@ #define NTAB 32 +#ifdef _MSC_VER #pragma warning(push) #pragma warning( disable:4251 ) +#endif //----------------------------------------------------------------------------- // A generator of uniformly distributed random numbers @@ -102,8 +104,9 @@ VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev //----------------------------------------------------------------------------- VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream ); - +#ifdef _MSC_VER #pragma warning(pop) +#endif #endif // VSTDLIB_RANDOM_H diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index 18b1c220..2b10730f 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -275,7 +275,9 @@ KeyValues::KeyValues( const char *setName, const char *firstKey, int firstValue, //----------------------------------------------------------------------------- void KeyValues::Init() { - m_iKeyName = INVALID_KEY_SYMBOL; + m_iKeyName = 0; + m_iKeyNameCaseSensitive1 = 0; + m_iKeyNameCaseSensitive2 = 0; m_iDataType = TYPE_NONE; m_pSub = NULL; @@ -287,9 +289,6 @@ void KeyValues::Init() m_pValue = NULL; m_bHasEscapeSequences = false; - - // for future proof - memset( unused, 0, sizeof(unused) ); } //----------------------------------------------------------------------------- @@ -472,7 +471,7 @@ void KeyValues::UsesEscapeSequences(bool state) //----------------------------------------------------------------------------- // Purpose: Load keyValues from disk //----------------------------------------------------------------------------- -bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID ) +bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceName, const char *pathID, GetSymbolProc_t pfnEvaluateSymbolProc ) { Assert(filesystem); #ifndef _LINUX @@ -500,7 +499,7 @@ bool KeyValues::LoadFromFile( IBaseFileSystem *filesystem, const char *resourceN if ( bRetOK ) { buffer[fileSize] = 0; // null terminate file as EOF - bRetOK = LoadFromBuffer( resourceName, buffer, filesystem ); + bRetOK = LoadFromBuffer( resourceName, buffer, filesystem, pathID, pfnEvaluateSymbolProc); } ((IFileSystem *)filesystem)->FreeOptimalReadBuffer( buffer ); @@ -676,7 +675,7 @@ void KeyValues::RecursiveSaveToFile( IBaseFileSystem *filesystem, FileHandle_t f char buf[32]; // write "0x" + 16 char 0-padded hex encoded 64 bit value - Q_snprintf( buf, sizeof( buf ), "0x%016I64X", *( (uint64 *)dat->m_sValue ) ); + Q_snprintf( buf, sizeof( buf ), "0x%016llX", *( (uint64 *)dat->m_sValue ) ); INTERNALWRITE(buf, Q_strlen(buf)); INTERNALWRITE("\"\n", 2); @@ -1136,7 +1135,7 @@ const char *KeyValues::GetString( const char *keyName, const char *defaultValue SetString( keyName, buf ); break; case TYPE_UINT64: - Q_snprintf( buf, sizeof( buf ), "%I64i", *((uint64 *)(dat->m_sValue)) ); + Q_snprintf( buf, sizeof( buf ), "%llu", *((uint64 *)(dat->m_sValue)) ); SetString( keyName, buf ); break; @@ -1225,9 +1224,9 @@ const wchar_t *KeyValues::GetWString( const char *keyName, const wchar_t *defaul //----------------------------------------------------------------------------- // Purpose: Gets a color //----------------------------------------------------------------------------- -Color KeyValues::GetColor( const char *keyName ) +Color KeyValues::GetColor( const char *keyName, const Color &defaultColor ) { - Color color(0, 0, 0, 0); + Color color = defaultColor; KeyValues *dat = FindKey( keyName, false ); if ( dat ) { @@ -1701,7 +1700,8 @@ void KeyValues::AppendIncludedKeys( CUtlVector< KeyValues * >& includedKeys ) } void KeyValues::ParseIncludedKeys( char const *resourceName, const char *filetoinclude, - IBaseFileSystem* pFileSystem, const char *pPathID, CUtlVector< KeyValues * >& includedKeys ) + IBaseFileSystem* pFileSystem, const char *pPathID, CUtlVector< KeyValues * >& includedKeys, + GetSymbolProc_t pfnEvaluateSymbolProc ) { Assert( resourceName ); Assert( filetoinclude ); @@ -1747,7 +1747,7 @@ void KeyValues::ParseIncludedKeys( char const *resourceName, const char *filetoi newKV->UsesEscapeSequences( m_bHasEscapeSequences != 0 ); // use same format as parent - if ( newKV->LoadFromFile( pFileSystem, fullpath, pPathID ) ) + if ( newKV->LoadFromFile( pFileSystem, fullpath, pPathID, pfnEvaluateSymbolProc ) ) { includedKeys.AddToTail( newKV ); } @@ -1818,7 +1818,7 @@ void KeyValues::RecursiveMergeKeyValues( KeyValues *baseKV ) // Returns whether a keyvalues conditional evaluates to true or false // Needs more flexibility with conditionals, checking convars would be nice. //----------------------------------------------------------------------------- -bool EvaluateConditional( const char *str ) +bool KeyValues::EvaluateConditional( const char *str, GetSymbolProc_t pfnEvaluateSymbolProc ) { bool bResult = false; bool bXboxUI = IsX360(); @@ -1839,7 +1839,7 @@ bool EvaluateConditional( const char *str ) //----------------------------------------------------------------------------- // Read from a buffer... //----------------------------------------------------------------------------- -bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBaseFileSystem* pFileSystem, const char *pPathID ) +bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBaseFileSystem* pFileSystem, const char *pPathID, GetSymbolProc_t pfnEvaluateSymbolProc ) { KeyValues *pPreviousKey = NULL; KeyValues *pCurrentKey = this; @@ -1868,7 +1868,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase } else { - ParseIncludedKeys( resourceName, s, pFileSystem, pPathID, includedKeys ); + ParseIncludedKeys( resourceName, s, pFileSystem, pPathID, includedKeys, pfnEvaluateSymbolProc ); } continue; @@ -1884,7 +1884,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase } else { - ParseIncludedKeys( resourceName, s, pFileSystem, pPathID, baseKeys ); + ParseIncludedKeys( resourceName, s, pFileSystem, pPathID, baseKeys, pfnEvaluateSymbolProc ); } continue; @@ -1912,7 +1912,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase if ( wasConditional ) { - bAccepted = EvaluateConditional( s ); + bAccepted = EvaluateConditional( s, pfnEvaluateSymbolProc ); // Now get the '{' s = ReadToken( buf, wasQuoted, wasConditional ); @@ -1921,7 +1921,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase if ( s && *s == '{' && !wasQuoted ) { // header is valid so load the file - pCurrentKey->RecursiveLoadFromBuffer( resourceName, buf ); + pCurrentKey->RecursiveLoadFromBuffer( resourceName, buf, pfnEvaluateSymbolProc ); } else { @@ -1965,7 +1965,7 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase } } - g_KeyValuesErrorStack.SetFilename( "" ); + g_KeyValuesErrorStack.SetFilename( "" ); return true; } @@ -1974,20 +1974,20 @@ bool KeyValues::LoadFromBuffer( char const *resourceName, CUtlBuffer &buf, IBase //----------------------------------------------------------------------------- // Read from a buffer... //----------------------------------------------------------------------------- -bool KeyValues::LoadFromBuffer( char const *resourceName, const char *pBuffer, IBaseFileSystem* pFileSystem, const char *pPathID ) +bool KeyValues::LoadFromBuffer( char const *resourceName, const char *pBuffer, IBaseFileSystem* pFileSystem, const char *pPathID, GetSymbolProc_t pfnEvaluateSymbolProc ) { if ( !pBuffer ) return true; int nLen = Q_strlen( pBuffer ); CUtlBuffer buf( pBuffer, nLen, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER ); - return LoadFromBuffer( resourceName, buf, pFileSystem, pPathID ); + return LoadFromBuffer( resourceName, buf, pFileSystem, pPathID, pfnEvaluateSymbolProc ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &buf ) +void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &buf, GetSymbolProc_t pfnEvaluateSymbolProc ) { CKeyErrorContext errorReport(this); bool wasQuoted; @@ -2027,7 +2027,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b if ( wasConditional && value ) { - bAccepted = EvaluateConditional( value ); + bAccepted = EvaluateConditional( value, pfnEvaluateSymbolProc ); // get the real value value = ReadToken( buf, wasQuoted, wasConditional ); @@ -2050,7 +2050,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b // this isn't a key, it's a section errorKey.Reset( INVALID_KEY_SYMBOL ); // sub value list - dat->RecursiveLoadFromBuffer( resourceName, buf ); + dat->RecursiveLoadFromBuffer( resourceName, buf, pfnEvaluateSymbolProc ); } else { @@ -2125,7 +2125,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b const char *peek = ReadToken( buf, wasQuoted, wasConditional ); if ( wasConditional ) { - bAccepted = EvaluateConditional( peek ); + bAccepted = EvaluateConditional( peek, pfnEvaluateSymbolProc ); } else { diff --git a/tier1/bitbuf.cpp b/tier1/bitbuf.cpp index f49f5ea0..5279692d 100644 --- a/tier1/bitbuf.cpp +++ b/tier1/bitbuf.cpp @@ -115,10 +115,10 @@ CBitWriteMasksInit g_BitWriteMasksInit; // ---------------------------------------------------------------------------------------- // -// old_bf_write +// bf_write // ---------------------------------------------------------------------------------------- // -old_bf_write::old_bf_write() +bf_write::bf_write() { m_pData = NULL; m_nDataBytes = 0; @@ -129,21 +129,21 @@ old_bf_write::old_bf_write() m_pDebugName = NULL; } -old_bf_write::old_bf_write( const char *pDebugName, void *pData, int nBytes, int nBits ) -{ - m_bAssertOnOverflow = true; - m_pDebugName = pDebugName; - StartWriting( pData, nBytes, 0, nBits ); -} - -old_bf_write::old_bf_write( void *pData, int nBytes, int nBits ) +bf_write::bf_write( void *pData, int nBytes, int nMaxBits ) { m_bAssertOnOverflow = true; m_pDebugName = NULL; - StartWriting( pData, nBytes, 0, nBits ); + StartWriting( pData, nBytes, 0, nMaxBits ); } -void old_bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nBits ) +bf_write::bf_write( const char *pDebugName, void *pData, int nBytes, int nMaxBits ) +{ + m_bAssertOnOverflow = true; + m_pDebugName = pDebugName; + StartWriting( pData, nBytes, 0, nMaxBits ); +} + +void bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nMaxBits ) { // Make sure it's dword aligned and padded. Assert( (nBytes % 4) == 0 ); @@ -155,53 +155,53 @@ void old_bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nBi m_pData = (unsigned char*)pData; m_nDataBytes = nBytes; - if ( nBits == -1 ) + if ( nMaxBits == -1 ) { m_nDataBits = nBytes << 3; } else { - Assert( nBits <= nBytes*8 ); - m_nDataBits = nBits; + Assert( nMaxBits <= nBytes*8 ); + m_nDataBits = nMaxBits; } m_iCurBit = iStartBit; m_bOverflow = false; } -void old_bf_write::Reset() +void bf_write::Reset() { m_iCurBit = 0; m_bOverflow = false; } -void old_bf_write::SetAssertOnOverflow( bool bAssert ) +void bf_write::SetAssertOnOverflow( bool bAssert ) { m_bAssertOnOverflow = bAssert; } -const char* old_bf_write::GetDebugName() +const char* bf_write::GetDebugName() { return m_pDebugName; } -void old_bf_write::SetDebugName( const char *pDebugName ) +void bf_write::SetDebugName( const char *pDebugName ) { m_pDebugName = pDebugName; } -void old_bf_write::SeekToBit( int bitPos ) +void bf_write::SeekToBit( int bitPos ) { m_iCurBit = bitPos; } // Sign bit comes first -void old_bf_write::WriteSBitLong( int data, int numbits ) +void bf_write::WriteSBitLong( int data, int numbits ) { // Do we have a valid # of bits to encode with? Assert( numbits >= 1 ); @@ -250,7 +250,7 @@ inline unsigned int BitCountNeededToEncode(unsigned int data) #endif // _WIN32 // writes an unsigned integer with variable bit length -void old_bf_write::WriteUBitVar( unsigned int data ) +void bf_write::WriteUBitVar( unsigned int data ) { if ( ( data &0xf ) == data ) { @@ -305,7 +305,7 @@ void old_bf_write::WriteUBitVar( unsigned int data ) #endif } -void old_bf_write::WriteBitLong(unsigned int data, int numbits, bool bSigned) +void bf_write::WriteBitLong(unsigned int data, int numbits, bool bSigned) { if(bSigned) WriteSBitLong((int)data, numbits); @@ -313,10 +313,10 @@ void old_bf_write::WriteBitLong(unsigned int data, int numbits, bool bSigned) WriteUBitLong(data, numbits); } -bool old_bf_write::WriteBits(const void *pInData, int nBits) +bool bf_write::WriteBits(const void *pInData, int nBits) { #if defined( BB_PROFILING ) - VPROF( "old_bf_write::WriteBits" ); + VPROF( "bf_write::WriteBits" ); #endif unsigned char *pOut = (unsigned char*)pInData; @@ -403,7 +403,7 @@ bool old_bf_write::WriteBits(const void *pInData, int nBits) } -bool old_bf_write::WriteBitsFromBuffer( bf_read *pIn, int nBits ) +bool bf_write::WriteBitsFromBuffer( bf_read *pIn, int nBits ) { // This could be optimized a little by while ( nBits > 32 ) @@ -417,7 +417,7 @@ bool old_bf_write::WriteBitsFromBuffer( bf_read *pIn, int nBits ) } -void old_bf_write::WriteBitAngle( float fAngle, int numbits ) +void bf_write::WriteBitAngle( float fAngle, int numbits ) { int d; unsigned int mask; @@ -432,14 +432,14 @@ void old_bf_write::WriteBitAngle( float fAngle, int numbits ) WriteUBitLong((unsigned int)d, numbits); } -void old_bf_write::WriteBitCoordMP( const float f, bool bIntegral, bool bLowPrecision ) +void bf_write::WriteBitCoordMP( const float f, EBitCoordType coordType ) { #if defined( BB_PROFILING ) - VPROF( "old_bf_write::WriteBitCoordMP" ); + VPROF( "bf_write::WriteBitCoordMP" ); #endif - int signbit = (f <= -( bLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION )); + int signbit = (f <= -( coordType == kCW_LowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION )); int intval = (int)fabs(f); - int fractval = bLowPrecision ? + int fractval = coordType == kCW_LowPrecision ? ( abs((int)(f*COORD_DENOMINATOR_LOWPRECISION)) & (COORD_DENOMINATOR_LOWPRECISION-1) ) : ( abs((int)(f*COORD_DENOMINATOR)) & (COORD_DENOMINATOR-1) ); @@ -448,7 +448,7 @@ void old_bf_write::WriteBitCoordMP( const float f, bool bIntegral, bool bLowPrec WriteOneBit( bInBounds ); - if ( bIntegral ) + if ( coordType == kCW_Integral ) { // Send the sign bit WriteOneBit( intval ); @@ -488,14 +488,35 @@ void old_bf_write::WriteBitCoordMP( const float f, bool bIntegral, bool bLowPrec WriteUBitLong( (unsigned int)intval, COORD_INTEGER_BITS ); } } - WriteUBitLong( (unsigned int)fractval, bLowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); + WriteUBitLong( (unsigned int)fractval, coordType == kCW_LowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); } } -void old_bf_write::WriteBitCoord (const float f) +void bf_write::WriteBitCellCoord( const float f, int bits, EBitCoordType coordType ) { #if defined( BB_PROFILING ) - VPROF( "old_bf_write::WriteBitCoord" ); + VPROF( "bf_write::WriteCellBitCoordMP" ); +#endif + int intval = (int)fabs(f); + int fractval = coordType == kCW_LowPrecision ? + ( abs((int)(f*COORD_DENOMINATOR_LOWPRECISION)) & (COORD_DENOMINATOR_LOWPRECISION-1) ) : + ( abs((int)(f*COORD_DENOMINATOR)) & (COORD_DENOMINATOR-1) ); + + if ( coordType == kCW_Integral ) + { + WriteUBitLong( (unsigned int)intval, bits ); + } + else + { + WriteUBitLong( (unsigned int)intval, bits ); + WriteUBitLong( (unsigned int)fractval, coordType == kCW_LowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); + } +} + +void bf_write::WriteBitCoord (const float f) +{ +#if defined( BB_PROFILING ) + VPROF( "bf_write::WriteBitCoord" ); #endif int signbit = (f <= -COORD_RESOLUTION); int intval = (int)fabs(f); @@ -527,7 +548,7 @@ void old_bf_write::WriteBitCoord (const float f) } } -void old_bf_write::WriteBitFloat(float val) +void bf_write::WriteBitFloat(float val) { long intVal; @@ -538,7 +559,7 @@ void old_bf_write::WriteBitFloat(float val) WriteUBitLong( intVal, 32 ); } -void old_bf_write::WriteBitVec3Coord( const Vector& fa ) +void bf_write::WriteBitVec3Coord( const Vector& fa ) { int xflag, yflag, zflag; @@ -558,7 +579,7 @@ void old_bf_write::WriteBitVec3Coord( const Vector& fa ) WriteBitCoord( fa[2] ); } -void old_bf_write::WriteBitNormal( float f ) +void bf_write::WriteBitNormal( float f ) { int signbit = (f <= -NORMAL_RESOLUTION); @@ -576,7 +597,7 @@ void old_bf_write::WriteBitNormal( float f ) WriteUBitLong( fractval, NORMAL_FRACTIONAL_BITS ); } -void old_bf_write::WriteBitVec3Normal( const Vector& fa ) +void bf_write::WriteBitVec3Normal( const Vector& fa ) { int xflag, yflag; @@ -596,39 +617,39 @@ void old_bf_write::WriteBitVec3Normal( const Vector& fa ) WriteOneBit( signbit ); } -void old_bf_write::WriteBitAngles( const QAngle& fa ) +void bf_write::WriteBitAngles( const QAngle& fa ) { // FIXME: Vector tmp( fa.x, fa.y, fa.z ); WriteBitVec3Coord( tmp ); } -void old_bf_write::WriteChar(int val) +void bf_write::WriteChar(int val) { WriteSBitLong(val, sizeof(char) << 3); } -void old_bf_write::WriteByte(int val) +void bf_write::WriteByte(unsigned int val) { WriteUBitLong(val, sizeof(unsigned char) << 3); } -void old_bf_write::WriteShort(int val) +void bf_write::WriteShort(int val) { WriteSBitLong(val, sizeof(short) << 3); } -void old_bf_write::WriteWord(int val) +void bf_write::WriteWord(unsigned int val) { WriteUBitLong(val, sizeof(unsigned short) << 3); } -void old_bf_write::WriteLong(long val) +void bf_write::WriteLong(long val) { WriteSBitLong(val, sizeof(long) << 3); } -void old_bf_write::WriteLongLong(int64 val) +void bf_write::WriteLongLong(int64 val) { uint *pLongs = (uint*)&val; @@ -639,7 +660,7 @@ void old_bf_write::WriteLongLong(int64 val) WriteUBitLong(pLongs[*idx], sizeof(long) << 3); } -void old_bf_write::WriteFloat(float val) +void bf_write::WriteFloat(float val) { // Pre-swap the float, since WriteBits writes raw data LittleFloat( &val, &val ); @@ -647,12 +668,12 @@ void old_bf_write::WriteFloat(float val) WriteBits(&val, sizeof(val) << 3); } -bool old_bf_write::WriteBytes( const void *pBuf, int nBytes ) +bool bf_write::WriteBytes( const void *pBuf, int nBytes ) { return WriteBits(pBuf, nBytes << 3); } -bool old_bf_write::WriteString(const char *pStr) +bool bf_write::WriteString(const char *pStr) { if(pStr) { @@ -670,6 +691,25 @@ bool old_bf_write::WriteString(const char *pStr) return !IsOverflowed(); } +bool bf_write::WriteString(const wchar_t *pStr) +{ + if(pStr) + { + do + { + WriteSBitLong( *pStr, 16 ); + ++pStr; + } while ( (*pStr-1) != 0 ); + } + else + { + WriteUBitLong( 0, 15 ); + WriteOneBit( 0 ); + } + + return !IsOverflowed(); +} + // ---------------------------------------------------------------------------------------- // // old_bf_read // ---------------------------------------------------------------------------------------- // @@ -995,18 +1035,18 @@ float old_bf_read::ReadBitCoord (void) return value; } -float old_bf_read::ReadBitCoordMP( bool bIntegral, bool bLowPrecision ) +float old_bf_read::ReadBitCoordMP( EBitCoordType coordType ) { #if defined( BB_PROFILING ) VPROF( "old_bf_write::ReadBitCoordMP" ); #endif int intval=0,fractval=0,signbit=0; float value = 0.0; - + bool bInBounds = ReadOneBit() ? true : false; - if ( bIntegral ) + if ( coordType == kCW_Integral ) { // Read the required integer and fraction flags intval = ReadOneBit(); @@ -1050,10 +1090,10 @@ float old_bf_read::ReadBitCoordMP( bool bIntegral, bool bLowPrecision ) } // If there's a fraction, read it in - fractval = ReadUBitLong( bLowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); + fractval = ReadUBitLong( coordType == kCW_LowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); // Calculate the correct floating point value - value = intval + ((float)fractval * ( bLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION ) ); + value = intval + ((float)fractval * ( coordType == kCW_LowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION ) ); } // Fixup the sign if negative. @@ -1250,7 +1290,7 @@ void old_bf_read::ExciseBits( int startbit, int bitstoremove ) int endbit = startbit + bitstoremove; int remaining_to_end = m_nDataBits - endbit; - old_bf_write temp; + bf_write temp; temp.StartWriting( (void *)m_pData, m_nDataBits << 3, startbit ); Seek( endbit ); diff --git a/tier1/byteswap.cpp b/tier1/byteswap.cpp index 9ebcee26..0c42a38d 100644 --- a/tier1/byteswap.cpp +++ b/tier1/byteswap.cpp @@ -62,7 +62,7 @@ void CByteswap::SwapFieldToTargetEndian( void* pOutputBuffer, void *pData, typed break; default: - assert(0); + Assert(0); } } diff --git a/tier1/convar.cpp b/tier1/convar.cpp index 17dd3fbb..6ed56de5 100644 --- a/tier1/convar.cpp +++ b/tier1/convar.cpp @@ -683,10 +683,10 @@ ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags, const c //----------------------------------------------------------------------------- ConVar::~ConVar( void ) { - if ( m_pszString ) + if ( m_Value.m_pszString ) { - delete[] m_pszString; - m_pszString = NULL; + delete[] m_Value.m_pszString; + m_Value.m_pszString = NULL; } } @@ -694,15 +694,24 @@ ConVar::~ConVar( void ) //----------------------------------------------------------------------------- // Install a change callback (there shouldn't already be one....) //----------------------------------------------------------------------------- -void ConVar::InstallChangeCallback( FnChangeCallback_t callback ) +void ConVar::InstallChangeCallback( FnChangeCallback_t callback, bool bInvoke ) { - Assert( !m_pParent->m_fnChangeCallback || !callback ); - m_pParent->m_fnChangeCallback = callback; - - if ( m_pParent->m_fnChangeCallback ) + if (callback) { - // Call it immediately to set the initial value... - m_pParent->m_fnChangeCallback( this, m_pszString, m_fValue ); + if (m_fnChangeCallbacks.Find(callback) != -1) + { + m_fnChangeCallbacks.AddToTail(callback); + if (bInvoke) + callback(this, m_Value.m_pszString, m_Value.m_fValue); + } + else + { + Warning("InstallChangeCallback ignoring duplicate change callback!!!\n"); + } + } + else + { + Warning("InstallChangeCallback called with NULL callback, ignoring!!!\n"); } } @@ -780,7 +789,7 @@ void ConVar::InternalSetValue( const char *value ) Assert(m_pParent == this); // Only valid for root convars. - float flOldValue = m_fValue; + float flOldValue = m_Value.m_fValue; val = (char *)value; fNewValue = ( float )atof( value ); @@ -792,8 +801,8 @@ void ConVar::InternalSetValue( const char *value ) } // Redetermine value - m_fValue = fNewValue; - m_nValue = ( int )( m_fValue ); + m_Value.m_fValue = fNewValue; + m_Value.m_nValue = ( int )( fNewValue ); if ( !( m_nFlags & FCVAR_NEVER_AS_STRING ) ) { @@ -809,33 +818,32 @@ void ConVar::ChangeStringValue( const char *tempVal, float flOldValue ) { Assert( !( m_nFlags & FCVAR_NEVER_AS_STRING ) ); - char* pszOldValue = (char*)stackalloc( m_StringLength ); - memcpy( pszOldValue, m_pszString, m_StringLength ); + char* pszOldValue = (char*)stackalloc( m_Value.m_StringLength ); + memcpy( pszOldValue, m_Value.m_pszString, m_Value.m_StringLength ); int len = Q_strlen(tempVal) + 1; - if ( len > m_StringLength) + if ( len > m_Value.m_StringLength) { - if (m_pszString) + if (m_Value.m_pszString) { - delete[] m_pszString; + delete[] m_Value.m_pszString; } - m_pszString = new char[len]; - m_StringLength = len; + m_Value.m_pszString = new char[len]; + m_Value.m_StringLength = len; } - memcpy( m_pszString, tempVal, len ); + memcpy( m_Value.m_pszString, tempVal, len ); // Invoke any necessary callback function - if ( m_fnChangeCallback ) + for (int i = 0; i < m_fnChangeCallbacks.Count(); i++) { - m_fnChangeCallback( this, pszOldValue, flOldValue ); + m_fnChangeCallbacks[i]( this, pszOldValue, flOldValue ); } - g_pCVar->CallGlobalChangeCallbacks( this, pszOldValue, flOldValue ); - - stackfree( pszOldValue ); + if (g_pCVar) + g_pCVar->CallGlobalChangeCallbacks( this, pszOldValue, flOldValue ); } //----------------------------------------------------------------------------- @@ -866,7 +874,7 @@ bool ConVar::ClampValue( float& value ) //----------------------------------------------------------------------------- void ConVar::InternalSetFloatValue( float fNewValue ) { - if ( fNewValue == m_fValue ) + if ( fNewValue == m_Value.m_fValue ) return; Assert( m_pParent == this ); // Only valid for root convars. @@ -875,19 +883,19 @@ void ConVar::InternalSetFloatValue( float fNewValue ) ClampValue( fNewValue ); // Redetermine value - float flOldValue = m_fValue; - m_fValue = fNewValue; - m_nValue = ( int )m_fValue; + float flOldValue = m_Value.m_fValue; + m_Value.m_fValue = fNewValue; + m_Value.m_nValue = ( int )fNewValue; if ( !( m_nFlags & FCVAR_NEVER_AS_STRING ) ) { char tempVal[ 32 ]; - Q_snprintf( tempVal, sizeof( tempVal), "%f", m_fValue ); + Q_snprintf( tempVal, sizeof( tempVal), "%f", m_Value.m_fValue ); ChangeStringValue( tempVal, flOldValue ); } else { - Assert( !m_fnChangeCallback ); + Assert( m_fnChangeCallbacks.Count() == 0 ); } } @@ -897,7 +905,7 @@ void ConVar::InternalSetFloatValue( float fNewValue ) //----------------------------------------------------------------------------- void ConVar::InternalSetIntValue( int nValue ) { - if ( nValue == m_nValue ) + if ( nValue == m_Value.m_nValue ) return; Assert( m_pParent == this ); // Only valid for root convars. @@ -909,19 +917,19 @@ void ConVar::InternalSetIntValue( int nValue ) } // Redetermine value - float flOldValue = m_fValue; - m_fValue = fValue; - m_nValue = nValue; + float flOldValue = m_Value.m_fValue; + m_Value.m_fValue = fValue; + m_Value.m_nValue = nValue; if ( !( m_nFlags & FCVAR_NEVER_AS_STRING ) ) { char tempVal[ 32 ]; - Q_snprintf( tempVal, sizeof( tempVal ), "%d", m_nValue ); + Q_snprintf( tempVal, sizeof( tempVal ), "%d", m_Value.m_nValue ); ChangeStringValue( tempVal, flOldValue ); } else { - Assert( !m_fnChangeCallback ); + Assert( m_fnChangeCallbacks.Count() == 0 ); } } @@ -950,31 +958,32 @@ void ConVar::Create( const char *pName, const char *pDefaultValue, int flags /*= m_pszDefaultValue = pDefaultValue ? pDefaultValue : empty_string; Assert( m_pszDefaultValue ); - m_StringLength = strlen( m_pszDefaultValue ) + 1; - m_pszString = new char[m_StringLength]; - memcpy( m_pszString, m_pszDefaultValue, m_StringLength ); + m_Value.m_StringLength = strlen( m_pszDefaultValue ) + 1; + m_Value.m_pszString = new char[m_Value.m_StringLength]; + memcpy( m_Value.m_pszString, m_pszDefaultValue, m_Value.m_StringLength ); m_bHasMin = bMin; m_fMinVal = fMin; m_bHasMax = bMax; m_fMaxVal = fMax; - m_fnChangeCallback = callback; + if (callback) + m_fnChangeCallbacks.AddToTail(callback); - m_fValue = ( float )atof( m_pszString ); + m_Value.m_fValue = ( float )atof( m_Value.m_pszString ); // Bounds Check, should never happen, if it does, no big deal - if ( m_bHasMin && ( m_fValue < m_fMinVal ) ) + if ( m_bHasMin && ( m_Value.m_fValue < m_fMinVal ) ) { Assert( 0 ); } - if ( m_bHasMax && ( m_fValue > m_fMaxVal ) ) + if ( m_bHasMax && ( m_Value.m_fValue > m_fMaxVal ) ) { Assert( 0 ); } - m_nValue = ( int )m_fValue; + m_Value.m_nValue = ( int )m_Value.m_fValue; BaseClass::Create( pName, pHelpString, flags ); } @@ -1205,7 +1214,7 @@ void ConVar_PrintDescription( const ConCommandBase *pVar ) float fMin, fMax; const char *pStr; - assert( pVar ); + Assert( pVar ); Color clr; clr.SetColor( 255, 100, 100, 255 ); diff --git a/tier1/generichash.cpp b/tier1/generichash.cpp index af784fc4..f251f1c4 100644 --- a/tier1/generichash.cpp +++ b/tier1/generichash.cpp @@ -142,7 +142,7 @@ unsigned FASTCALL HashInt( const int n ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -163,7 +163,7 @@ unsigned FASTCALL Hash4( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -185,7 +185,7 @@ unsigned FASTCALL Hash8( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -213,7 +213,7 @@ unsigned FASTCALL Hash12( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -247,7 +247,7 @@ unsigned FASTCALL Hash16( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 8252e570..dbad03a6 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -37,10 +37,14 @@ // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" +#if !defined COMPILER_MSVC && !defined HMODULE +#define HMODULE void * +#endif + // ------------------------------------------------------------------------------------ // // InterfaceReg. // ------------------------------------------------------------------------------------ // -InterfaceReg *InterfaceReg::s_pInterfaceRegs = NULL; +InterfaceReg *s_pInterfaceRegs = NULL; InterfaceReg::InterfaceReg( InstantiateInterfaceFn fn, const char *pName ) : m_pName(pName) @@ -59,7 +63,7 @@ void* CreateInterface( const char *pName, int *pReturnCode ) { InterfaceReg *pCur; - for (pCur=InterfaceReg::s_pInterfaceRegs; pCur; pCur=pCur->m_pNext) + for (pCur=s_pInterfaceRegs; pCur; pCur=pCur->m_pNext) { if (strcmp(pCur->m_pName, pName) == 0) { @@ -201,7 +205,7 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName ) #endif unsigned int nTimeout = 0; - while( ThreadWaitForObject( h, true, nTimeout ) == TW_TIMEOUT ) + while( WaitForSingleObject(h, nTimeout) == WAIT_TIMEOUT ) { nTimeout = threadFunc(); } diff --git a/tier1/mempool.cpp b/tier1/mempool.cpp index 14663a39..8a69a0ea 100644 --- a/tier1/mempool.cpp +++ b/tier1/mempool.cpp @@ -19,13 +19,13 @@ // Should be last include #include "tier0/memdbgon.h" -MemoryPoolReportFunc_t CMemoryPool::g_ReportFunc = 0; +MemoryPoolReportFunc_t CUtlMemoryPool::g_ReportFunc = 0; //----------------------------------------------------------------------------- // Error reporting... (debug only) //----------------------------------------------------------------------------- -void CMemoryPool::SetErrorReportFunc( MemoryPoolReportFunc_t func ) +void CUtlMemoryPool::SetErrorReportFunc( MemoryPoolReportFunc_t func ) { g_ReportFunc = func; } @@ -33,7 +33,7 @@ void CMemoryPool::SetErrorReportFunc( MemoryPoolReportFunc_t func ) //----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- -CMemoryPool::CMemoryPool( int blockSize, int numElements, int growMode, const char *pszAllocOwner, int nAlignment ) +CUtlMemoryPool::CUtlMemoryPool( int blockSize, int numElements, int growMode, const char *pszAllocOwner, int nAlignment ) { #ifdef _X360 if( numElements > 0 && growMode != GROW_NONE ) @@ -63,7 +63,7 @@ CMemoryPool::CMemoryPool( int blockSize, int numElements, int growMode, const ch // any further use. // Input : *memPool - the mempool to shutdown //----------------------------------------------------------------------------- -CMemoryPool::~CMemoryPool() +CUtlMemoryPool::~CUtlMemoryPool() { if (m_BlocksAllocated > 0) { @@ -76,7 +76,7 @@ CMemoryPool::~CMemoryPool() //----------------------------------------------------------------------------- // Resets the pool //----------------------------------------------------------------------------- -void CMemoryPool::Init() +void CUtlMemoryPool::Init() { m_NumBlobs = 0; m_BlocksAllocated = 0; @@ -88,7 +88,7 @@ void CMemoryPool::Init() //----------------------------------------------------------------------------- // Frees everything //----------------------------------------------------------------------------- -void CMemoryPool::Clear() +void CUtlMemoryPool::Clear() { // Free everything.. CBlob *pNext; @@ -104,7 +104,7 @@ void CMemoryPool::Clear() // Purpose: Reports memory leaks //----------------------------------------------------------------------------- -void CMemoryPool::ReportLeaks() +void CUtlMemoryPool::ReportLeaks() { if (!g_ReportFunc) return; @@ -155,7 +155,7 @@ void CMemoryPool::ReportLeaks() //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -void CMemoryPool::AddNewBlob() +void CUtlMemoryPool::AddNewBlob() { MEM_ALLOC_CREDIT_(m_pszAllocOwner); @@ -172,7 +172,7 @@ void CMemoryPool::AddNewBlob() // Can only have one allocation when we're in this mode if( m_NumBlobs != 0 ) { - Assert( !"CMemoryPool::AddNewBlob: mode == GROW_NONE" ); + Assert( !"CUtlMemoryPool::AddNewBlob: mode == GROW_NONE" ); return; } } @@ -210,13 +210,13 @@ void CMemoryPool::AddNewBlob() } -void* CMemoryPool::Alloc() +void* CUtlMemoryPool::Alloc() { return Alloc( m_BlockSize ); } -void* CMemoryPool::AllocZero() +void* CUtlMemoryPool::AllocZero() { return AllocZero( m_BlockSize ); } @@ -226,7 +226,7 @@ void* CMemoryPool::AllocZero() // Purpose: Allocs a single block of memory from the pool. // Input : amount - //----------------------------------------------------------------------------- -void *CMemoryPool::Alloc( size_t amount ) +void *CUtlMemoryPool::Alloc( size_t amount ) { void *returnBlock; @@ -238,7 +238,7 @@ void *CMemoryPool::Alloc( size_t amount ) // returning NULL is fine in GROW_NONE if( m_GrowMode == GROW_NONE ) { - //Assert( !"CMemoryPool::Alloc: tried to make new blob with GROW_NONE" ); + //Assert( !"CUtlMemoryPool::Alloc: tried to make new blob with GROW_NONE" ); return NULL; } @@ -248,7 +248,7 @@ void *CMemoryPool::Alloc( size_t amount ) // still failure, error out if( !m_pHeadOfFreeList ) { - Assert( !"CMemoryPool::Alloc: ran out of memory" ); + Assert( !"CUtlMemoryPool::Alloc: ran out of memory" ); return NULL; } } @@ -267,7 +267,7 @@ void *CMemoryPool::Alloc( size_t amount ) // Purpose: Allocs a single block of memory from the pool, zeroes the memory before returning // Input : amount - //----------------------------------------------------------------------------- -void *CMemoryPool::AllocZero( size_t amount ) +void *CUtlMemoryPool::AllocZero( size_t amount ) { void *mem = Alloc( amount ); if ( mem ) @@ -281,7 +281,7 @@ void *CMemoryPool::AllocZero( size_t amount ) // Purpose: Frees a block of memory // Input : *memBlock - the memory to free //----------------------------------------------------------------------------- -void CMemoryPool::Free( void *memBlock ) +void CUtlMemoryPool::Free( void *memBlock ) { if ( !memBlock ) return; // trying to delete NULL pointer, ignore diff --git a/tier1/newbitbuf.cpp b/tier1/newbitbuf.cpp index 420556ec..39cfd217 100644 --- a/tier1/newbitbuf.cpp +++ b/tier1/newbitbuf.cpp @@ -179,11 +179,11 @@ void CBitWrite::WriteBitCoord (const float f) } } -void CBitWrite::WriteBitCoordMP (const float f, bool bIntegral, bool bLowPrecision ) +void CBitWrite::WriteBitCoordMP (const float f, EBitCoordType coordType ) { - int signbit = (f <= -( bLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION )); + int signbit = (f <= -( coordType == kCW_LowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION )); int intval = (int)fabs(f); - int fractval = bLowPrecision ? + int fractval = coordType == kCW_LowPrecision ? ( abs((int)(f*COORD_DENOMINATOR_LOWPRECISION)) & (COORD_DENOMINATOR_LOWPRECISION-1) ) : ( abs((int)(f*COORD_DENOMINATOR)) & (COORD_DENOMINATOR-1) ); @@ -191,7 +191,7 @@ void CBitWrite::WriteBitCoordMP (const float f, bool bIntegral, bool bLowPrecisi WriteOneBit( bInBounds ); - if ( bIntegral ) + if ( coordType == kCW_Integral ) { // Send the sign bit WriteOneBit( intval ); @@ -232,7 +232,7 @@ void CBitWrite::WriteBitCoordMP (const float f, bool bIntegral, bool bLowPrecisi WriteUBitLong( (unsigned int)intval, COORD_INTEGER_BITS ); } } - WriteUBitLong( (unsigned int)fractval, bLowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); + WriteUBitLong( (unsigned int)fractval, coordType == kCW_LowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); } } @@ -575,14 +575,14 @@ float CBitRead::ReadBitCoord (void) return value; } -float CBitRead::ReadBitCoordMP( bool bIntegral, bool bLowPrecision ) +float CBitRead::ReadBitCoordMP( EBitCoordType coordType ) { int intval=0,fractval=0,signbit=0; float value = 0.0; bool bInBounds = ReadOneBit() ? true : false; - if ( bIntegral ) + if ( coordType == kCW_Integral ) { // Read the required integer and fraction flags intval = ReadOneBit(); @@ -626,10 +626,10 @@ float CBitRead::ReadBitCoordMP( bool bIntegral, bool bLowPrecision ) } // If there's a fraction, read it in - fractval = ReadUBitLong( bLowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); + fractval = ReadUBitLong( coordType == kCW_LowPrecision ? COORD_FRACTIONAL_BITS_MP_LOWPRECISION : COORD_FRACTIONAL_BITS ); // Calculate the correct floating point value - value = intval + ((float)fractval * ( bLowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION ) ); + value = intval + ((float)fractval * ( coordType == kCW_LowPrecision ? COORD_RESOLUTION_LOWPRECISION : COORD_RESOLUTION ) ); } // Fixup the sign if negative. diff --git a/tier1/rangecheckedvar.cpp b/tier1/rangecheckedvar.cpp index a342dcd9..1633fbab 100644 --- a/tier1/rangecheckedvar.cpp +++ b/tier1/rangecheckedvar.cpp @@ -4,6 +4,7 @@ // //=============================================================================// +#include "mathlib/mathlib.h" #include "rangecheckedvar.h" // memdbgon must be the last include file in a .cpp file!!! diff --git a/tier1/stringpool.cpp b/tier1/stringpool.cpp index 8924034e..7aecdb83 100644 --- a/tier1/stringpool.cpp +++ b/tier1/stringpool.cpp @@ -18,16 +18,22 @@ // Purpose: Comparison function for string sorted associative data structures //----------------------------------------------------------------------------- -bool StrLess( const char * const &pszLeft, const char * const &pszRight ) +bool StrLessSensitive( const char * const &pszLeft, const char * const &pszRight ) { - return ( Q_stricmp( pszLeft, pszRight) < 0 ); + return ( Q_strcmp( pszLeft, pszRight) < 0 ); } +bool StrLessInsensitive( const char * const &pszLeft, const char * const &pszRight ) +{ + return ( Q_stricmp( pszLeft, pszRight) < 0 ); +} + + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -CStringPool::CStringPool() - : m_Strings( 32, 256, StrLess ) +CStringPool::CStringPool( StringPoolCase_t caseSensitivity ) + : m_Strings( 32, 256, caseSensitivity == StringPoolCaseInsensitive ? StrLessInsensitive : StrLessSensitive ) { } @@ -94,7 +100,7 @@ void CStringPool::FreeAll() //----------------------------------------------------------------------------- -CCountedStringPool::CCountedStringPool() +CCountedStringPool::CCountedStringPool( StringPoolCase_t caseSensitivity ) { MEM_ALLOC_CREDIT(); m_HashTable.EnsureCount(HASH_TABLE_SIZE); @@ -109,6 +115,8 @@ CCountedStringPool::CCountedStringPool() m_Elements[0].pString = NULL; m_Elements[0].nReferenceCount = 0; m_Elements[0].nNextElement = INVALID_ELEMENT; + + m_caseSensitivity = caseSensitivity; } CCountedStringPool::~CCountedStringPool() @@ -154,7 +162,7 @@ unsigned short CCountedStringPool::FindStringHandle( const char* pIntrinsic ) if( pIntrinsic == NULL ) return INVALID_ELEMENT; - unsigned short nHashBucketIndex = (HashStringCaseless(pIntrinsic ) %HASH_TABLE_SIZE); + unsigned short nHashBucketIndex = (m_caseSensitivity ? HashString( pIntrinsic ) : HashStringCaseless( pIntrinsic ) %HASH_TABLE_SIZE); unsigned short nCurrentBucket = m_HashTable[ nHashBucketIndex ]; // Does the bucket already exist? @@ -187,7 +195,7 @@ unsigned short CCountedStringPool::ReferenceStringHandle( const char* pIntrinsic if( pIntrinsic == NULL ) return INVALID_ELEMENT; - unsigned short nHashBucketIndex = (HashStringCaseless( pIntrinsic ) % HASH_TABLE_SIZE); + unsigned short nHashBucketIndex = (m_caseSensitivity ? HashString( pIntrinsic ) : HashStringCaseless( pIntrinsic ) % HASH_TABLE_SIZE); unsigned short nCurrentBucket = m_HashTable[ nHashBucketIndex ]; // Does the bucket already exist? @@ -244,7 +252,7 @@ void CCountedStringPool::DereferenceString( const char* pIntrinsic ) if (!pIntrinsic) return; - unsigned short nHashBucketIndex = (HashStringCaseless( pIntrinsic ) % m_HashTable.Count()); + unsigned short nHashBucketIndex = (m_caseSensitivity ? HashString( pIntrinsic ) : HashStringCaseless( pIntrinsic ) % m_HashTable.Count()); unsigned short nCurrentBucket = m_HashTable[ nHashBucketIndex ]; // If there isn't anything in the bucket, just return. @@ -292,6 +300,14 @@ char* CCountedStringPool::HandleToString( unsigned short handle ) return m_Elements[handle].pString; } +unsigned CCountedStringPool::Hash( const char *pszKey ) +{ + if (m_caseSensitivity == StringPoolCaseSensitive) + return HashString( pszKey ); + + return HashStringCaseless( pszKey ); +} + void CCountedStringPool::SpewStrings() { int i; diff --git a/tier1/strtools.cpp b/tier1/strtools.cpp index 3188f209..fb1cced7 100644 --- a/tier1/strtools.cpp +++ b/tier1/strtools.cpp @@ -75,7 +75,7 @@ #endif #include "tier0/memdbgon.h" -void _V_memset (const char* file, int line, void *dest, int fill, int count) +void _V_memset (void *dest, int fill, int count) { Assert( count >= 0 ); AssertValidWritePtr( dest, count ); @@ -83,7 +83,7 @@ void _V_memset (const char* file, int line, void *dest, int fill, int count) memset(dest,fill,count); } -void _V_memcpy (const char* file, int line, void *dest, const void *src, int count) +void _V_memcpy (void *dest, const void *src, int count) { Assert( count >= 0 ); AssertValidReadPtr( src, count ); @@ -92,7 +92,7 @@ void _V_memcpy (const char* file, int line, void *dest, const void *src, int cou memcpy( dest, src, count ); } -void _V_memmove(const char* file, int line, void *dest, const void *src, int count) +void _V_memmove(void *dest, const void *src, int count) { Assert( count >= 0 ); AssertValidReadPtr( src, count ); @@ -101,7 +101,7 @@ void _V_memmove(const char* file, int line, void *dest, const void *src, int cou memmove( dest, src, count ); } -int _V_memcmp (const char* file, int line, const void *m1, const void *m2, int count) +int _V_memcmp (const void *m1, const void *m2, int count) { Assert( count >= 0 ); AssertValidReadPtr( m1, count ); @@ -110,28 +110,28 @@ int _V_memcmp (const char* file, int line, const void *m1, const void *m2, int c return memcmp( m1, m2, count ); } -int _V_strlen(const char* file, int line, const char *str) +int _V_strlen(const char *str) { - AssertValidStringPtr(str); + _AssertValidStringPtr(str); return strlen( str ); } -void _V_strcpy (const char* file, int line, char *dest, const char *src) +void _V_strcpy (char *dest, const char *src) { AssertValidWritePtr(dest); - AssertValidStringPtr(src); + _AssertValidStringPtr(src); strcpy( dest, src ); } -int _V_wcslen(const char* file, int line, const wchar_t *pwch) +int _V_wcslen(const wchar_t *pwch) { return wcslen( pwch ); } -char *_V_strrchr(const char* file, int line, const char *s, char c) +char *_V_strrchr(const char *s, char c) { - AssertValidStringPtr( s ); + _AssertValidStringPtr( s ); int len = V_strlen(s); s += len; while (len--) @@ -139,15 +139,15 @@ char *_V_strrchr(const char* file, int line, const char *s, char c) return 0; } -int _V_strcmp (const char* file, int line, const char *s1, const char *s2) +int _V_strcmp (const char *s1, const char *s2) { - AssertValidStringPtr( s1 ); - AssertValidStringPtr( s2 ); + _AssertValidStringPtr( s1 ); + _AssertValidStringPtr( s2 ); return strcmp( s1, s2 ); } -int _V_wcscmp (const char* file, int line, const wchar_t *s1, const wchar_t *s2) +int _V_wcscmp (const wchar_t *s1, const wchar_t *s2) { while (1) { @@ -162,21 +162,23 @@ int _V_wcscmp (const char* file, int line, const wchar_t *s1, const wchar_t *s2) return -1; } +#ifdef PLATFORM_WINDOWS +#undef stricmp +#endif - -int _V_stricmp(const char* file, int line, const char *s1, const char *s2 ) +int _V_stricmp( const char *s1, const char *s2 ) { - AssertValidStringPtr( s1 ); - AssertValidStringPtr( s2 ); + _AssertValidStringPtr( s1 ); + _AssertValidStringPtr( s2 ); return stricmp( s1, s2 ); } -char *_V_strstr(const char* file, int line, const char *s1, const char *search ) +char *_V_strstr( const char *s1, const char *search ) { - AssertValidStringPtr( s1 ); - AssertValidStringPtr( search ); + _AssertValidStringPtr( s1 ); + _AssertValidStringPtr( search ); #if defined( _X360 ) return (char *)strstr( (char *)s1, search ); @@ -185,24 +187,24 @@ char *_V_strstr(const char* file, int line, const char *s1, const char *search #endif } -char *_V_strupr (const char* file, int line, char *start) +char *_V_strupr (char *start) { - AssertValidStringPtr( start ); + _AssertValidStringPtr( start ); return strupr( start ); } -char *_V_strlower (const char* file, int line, char *start) +char *_V_strlower (char *start) { - AssertValidStringPtr( start ); + _AssertValidStringPtr( start ); return strlwr(start); } int V_strncmp (const char *s1, const char *s2, int count) { Assert( count >= 0 ); - AssertValidStringPtr( s1, count ); - AssertValidStringPtr( s2, count ); + _AssertValidStringPtr( s1, count ); + _AssertValidStringPtr( s2, count ); while ( count-- > 0 ) { @@ -220,7 +222,7 @@ int V_strncmp (const char *s1, const char *s2, int count) char *V_strnlwr(char *s, size_t count) { Assert( count >= 0 ); - AssertValidStringPtr( s, count ); + _AssertValidStringPtr( s, count ); char* pRet = s; if ( !s ) @@ -247,8 +249,8 @@ char *V_strnlwr(char *s, size_t count) int V_strncasecmp (const char *s1, const char *s2, int n) { Assert( n >= 0 ); - AssertValidStringPtr( s1 ); - AssertValidStringPtr( s2 ); + _AssertValidStringPtr( s1 ); + _AssertValidStringPtr( s2 ); while ( n-- > 0 ) { @@ -273,8 +275,8 @@ int V_strncasecmp (const char *s1, const char *s2, int n) int V_strcasecmp( const char *s1, const char *s2 ) { - AssertValidStringPtr( s1 ); - AssertValidStringPtr( s2 ); + _AssertValidStringPtr( s1 ); + _AssertValidStringPtr( s2 ); return stricmp( s1, s2 ); } @@ -282,8 +284,8 @@ int V_strcasecmp( const char *s1, const char *s2 ) int V_strnicmp (const char *s1, const char *s2, int n) { Assert( n >= 0 ); - AssertValidStringPtr(s1); - AssertValidStringPtr(s2); + _AssertValidStringPtr(s1); + _AssertValidStringPtr(s2); return V_strncasecmp( s1, s2, n ); } @@ -291,8 +293,8 @@ int V_strnicmp (const char *s1, const char *s2, int n) const char *StringAfterPrefix( const char *str, const char *prefix ) { - AssertValidStringPtr( str ); - AssertValidStringPtr( prefix ); + _AssertValidStringPtr( str ); + _AssertValidStringPtr( prefix ); do { if ( !*prefix ) @@ -304,8 +306,8 @@ const char *StringAfterPrefix( const char *str, const char *prefix ) const char *StringAfterPrefixCaseSensitive( const char *str, const char *prefix ) { - AssertValidStringPtr( str ); - AssertValidStringPtr( prefix ); + _AssertValidStringPtr( str ); + _AssertValidStringPtr( prefix ); do { if ( !*prefix ) @@ -318,7 +320,7 @@ const char *StringAfterPrefixCaseSensitive( const char *str, const char *prefix int V_atoi (const char *str) { - AssertValidStringPtr( str ); + _AssertValidStringPtr( str ); int val; int sign; @@ -380,7 +382,7 @@ int V_atoi (const char *str) float V_atof (const char *str) { - AssertValidStringPtr( str ); + _AssertValidStringPtr( str ); double val; int sign; int c; @@ -489,8 +491,8 @@ void V_normalizeFloatString( char* pFloat ) //----------------------------------------------------------------------------- char const* V_stristr( char const* pStr, char const* pSearch ) { - AssertValidStringPtr(pStr); - AssertValidStringPtr(pSearch); + _AssertValidStringPtr(pStr); + _AssertValidStringPtr(pSearch); if (!pStr || !pSearch) return 0; @@ -532,8 +534,8 @@ char const* V_stristr( char const* pStr, char const* pSearch ) char* V_stristr( char* pStr, char const* pSearch ) { - AssertValidStringPtr( pStr ); - AssertValidStringPtr( pSearch ); + _AssertValidStringPtr( pStr ); + _AssertValidStringPtr( pSearch ); return (char*)V_stristr( (char const*)pStr, pSearch ); } @@ -543,8 +545,8 @@ char* V_stristr( char* pStr, char const* pSearch ) //----------------------------------------------------------------------------- char const* V_strnistr( char const* pStr, char const* pSearch, int n ) { - AssertValidStringPtr(pStr); - AssertValidStringPtr(pSearch); + _AssertValidStringPtr(pStr); + _AssertValidStringPtr(pSearch); if (!pStr || !pSearch) return 0; @@ -613,7 +615,7 @@ void V_strncpy( char *pDest, char const *pSrc, int maxLen ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); - AssertValidStringPtr( pSrc ); + _AssertValidStringPtr( pSrc ); strncpy( pDest, pSrc, maxLen ); if ( maxLen > 0 ) @@ -672,7 +674,7 @@ int V_snprintf( char *pDest, int maxLen, char const *pFormat, ... ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); - AssertValidStringPtr( pFormat ); + _AssertValidStringPtr( pFormat ); va_list marker; @@ -701,7 +703,7 @@ int V_vsnprintf( char *pDest, int maxLen, char const *pFormat, va_list params ) { Assert( maxLen > 0 ); AssertValidWritePtr( pDest, maxLen ); - AssertValidStringPtr( pFormat ); + _AssertValidStringPtr( pFormat ); int len = _vsnprintf( pDest, maxLen, pFormat, params ); @@ -730,8 +732,8 @@ char *V_strncat(char *pDest, const char *pSrc, size_t destBufferSize, int max_ch size_t charstocopy = (size_t)0; Assert( destBufferSize >= 0 ); - AssertValidStringPtr( pDest); - AssertValidStringPtr( pSrc ); + _AssertValidStringPtr( pDest); + _AssertValidStringPtr( pSrc ); size_t len = strlen(pDest); size_t srclen = strlen( pSrc ); @@ -888,21 +890,21 @@ char *V_pretifynum( int64 value ) if ( value >= 1000000000000LL ) { char *pchRender = out + V_strlen( out ); - V_snprintf( pchRender, 32, "%d,", value / 1000000000000LL ); + V_snprintf( pchRender, 32, "%lld,", value / 1000000000000LL ); } // Render trillions if ( value >= 1000000000000LL ) { char *pchRender = out + V_strlen( out ); - V_snprintf( pchRender, 32, "%d,", value / 1000000000000LL ); + V_snprintf( pchRender, 32, "%lld,", value / 1000000000000LL ); } // Render billions if ( value >= 1000000000 ) { char *pchRender = out + V_strlen( out ); - V_snprintf( pchRender, 32, "%d,", value / 1000000000 ); + V_snprintf( pchRender, 32, "%lld,", value / 1000000000 ); } // Render millions @@ -910,9 +912,9 @@ char *V_pretifynum( int64 value ) { char *pchRender = out + V_strlen( out ); if ( value >= 1000000000 ) - V_snprintf( pchRender, 32, "%03d,", ( value / 1000000 ) % 1000 ); + V_snprintf( pchRender, 32, "%03d,", (unsigned int)(( value / 1000000 ) % 1000 )); else - V_snprintf( pchRender, 32, "%d,", ( value / 1000000 ) % 1000 ); + V_snprintf( pchRender, 32, "%d,", (unsigned int)(( value / 1000000 ) % 1000 )); } // Render thousands @@ -920,17 +922,17 @@ char *V_pretifynum( int64 value ) { char *pchRender = out + V_strlen( out ); if ( value >= 1000000 ) - V_snprintf( pchRender, 32, "%03d,", ( value / 1000 ) % 1000 ); + V_snprintf( pchRender, 32, "%03d,", (unsigned int)(( value / 1000 ) % 1000 )); else - V_snprintf( pchRender, 32, "%d,", ( value / 1000 ) % 1000 ); + V_snprintf( pchRender, 32, "%d,", (unsigned int)(( value / 1000 ) % 1000 )); } // Render units char *pchRender = out + V_strlen( out ); if ( value > 1000 ) - V_snprintf( pchRender, 32, "%03d", value % 1000 ); + V_snprintf( pchRender, 32, "%03d", (unsigned int)(value % 1000) ); else - V_snprintf( pchRender, 32, "%d", value % 1000 ); + V_snprintf( pchRender, 32, "%d", (unsigned int)(value % 1000) ); return out; } @@ -941,7 +943,7 @@ char *V_pretifynum( int64 value ) //----------------------------------------------------------------------------- int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInBytes ) { - AssertValidStringPtr(pUTF8); + _AssertValidStringPtr(pUTF8); AssertValidWritePtr(pwchDest); pwchDest[0] = 0; @@ -959,7 +961,7 @@ int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInByte //----------------------------------------------------------------------------- int V_UnicodeToUTF8( const wchar_t *pUnicode, char *pUTF8, int cubDestSizeInBytes ) { - AssertValidStringPtr(pUTF8, cubDestSizeInBytes); + _AssertValidStringPtr(pUTF8, cubDestSizeInBytes); AssertValidReadPtr(pUnicode); pUTF8[0] = 0; diff --git a/tier1/tier1.cpp b/tier1/tier1.cpp index 7a20917d..c29dfcfc 100644 --- a/tier1/tier1.cpp +++ b/tier1/tier1.cpp @@ -6,20 +6,7 @@ #include #include "tier0/dbg.h" -#include "vstdlib/iprocessutils.h" -#include "icvar.h" - - -//----------------------------------------------------------------------------- -// These tier1 libraries must be set by any users of this library. -// They can be set by calling ConnectTier1Libraries or InitDefaultFileSystem. -// It is hoped that setting this, and using this library will be the common mechanism for -// allowing link libraries to access tier1 library interfaces -//----------------------------------------------------------------------------- -ICvar *cvar = 0; -ICvar *g_pCVar = 0; -IProcessUtils *g_pProcessUtils = 0; -static bool s_bConnected = false; +#include "interfaces/interfaces.h" // for utlsortvector.h #ifndef _WIN32 @@ -33,31 +20,10 @@ static bool s_bConnected = false; //----------------------------------------------------------------------------- void ConnectTier1Libraries( CreateInterfaceFn *pFactoryList, int nFactoryCount ) { - // Don't connect twice.. - if ( s_bConnected ) - return; - - s_bConnected = true; - - for ( int i = 0; i < nFactoryCount; ++i ) - { - if ( !g_pCVar ) - { - cvar = g_pCVar = ( ICvar * )pFactoryList[i]( CVAR_INTERFACE_VERSION, NULL ); - } - if ( !g_pProcessUtils ) - { - g_pProcessUtils = ( IProcessUtils * )pFactoryList[i]( PROCESS_UTILS_INTERFACE_VERSION, NULL ); - } - } + ConnectInterfaces( pFactoryList, nFactoryCount); } void DisconnectTier1Libraries() { - if ( !s_bConnected ) - return; - - g_pCVar = cvar = 0; - g_pProcessUtils = NULL; - s_bConnected = false; + DisconnectInterfaces(); } diff --git a/tier1/tier1.sln b/tier1/tier1.sln new file mode 100644 index 00000000..0cf1abae --- /dev/null +++ b/tier1/tier1.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tier1", "tier1.vcxproj", "{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.ActiveCfg = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.Build.0 = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.ActiveCfg = Release|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tier1/tier1.vcxproj b/tier1/tier1.vcxproj new file mode 100644 index 00000000..a1687450 --- /dev/null +++ b/tier1/tier1.vcxproj @@ -0,0 +1,254 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + tier1 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720} + tier1 + + + + StaticLibrary + + + StaticLibrary + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + ..\lib\public\ + true + true + true + ..\lib\public\ + true + true + true + AllRules.ruleset + + + AllRules.ruleset + + + + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;%(AdditionalIncludeDirectories) + WIN32;_WIN32;VEL': value '0' doesn't match value '2' in core_metamod.obj;COMPILER_MSVC;COMPILER_MSVC32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + true + + + EnableFastChecks + MultiThreadedDebug + false + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + CompileAsCpp + Prompt + Level3 + + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + + MaxSpeed + AnySuitable + true + Speed + ..\public;..\public\tier0;..\public\tier1;%(AdditionalIncludeDirectories) + WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + + + MultiThreaded + false + true + Fast + true + true + true + false + + + false + + + $(IntDir) + $(IntDir) + $(IntDir) + false + + + $(IntDir) + CompileAsCpp + Prompt + Level3 + + + + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + + + + + + + + + + + + + + Sync + Sync + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tier1/tier1.vcxproj.filters b/tier1/tier1.vcxproj.filters new file mode 100644 index 00000000..4668aac2 --- /dev/null +++ b/tier1/tier1.vcxproj.filters @@ -0,0 +1,257 @@ + + + + + {aba1d919-d95c-4c3f-a495-be0375bab184} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {0295d938-2af6-4393-9785-4b7b122313c9} + h;hpp;hxx;hm;inl + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file