From 4b72afb74fb5777320aff325450eb5ad6a4e3d89 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 25 May 2022 14:18:29 +0200 Subject: [PATCH] Light refactor for logging Moved logging functions to dbg.h (tier0) and export them from the dll. Added additional functions for checking bad pointers (debug only!). Reduced output code size. --- r5dev/common/netmessages.cpp | 1 - r5dev/core/stdafx.h | 1 + r5dev/cpp.hint | 1 + r5dev/datacache/mdlcache.cpp | 1 - r5dev/ebisusdk/EbisuSDK.cpp | 1 - r5dev/engine/client/cl_rcon.cpp | 1 - r5dev/engine/cmodel_bsp.cpp | 1 - r5dev/engine/host_state.cpp | 1 - r5dev/engine/modelloader.cpp | 1 - r5dev/engine/net.cpp | 1 - r5dev/engine/net_chan.cpp | 1 - r5dev/engine/server/server.cpp | 1 - r5dev/engine/server/sv_main.cpp | 1 - r5dev/engine/server/sv_rcon.cpp | 1 - r5dev/engine/sys_dll.cpp | 1 - r5dev/engine/sys_dll2.cpp | 1 - r5dev/engine/sys_utils.cpp | 262 -------------- r5dev/engine/sys_utils.h | 45 --- r5dev/game/server/ai_network.cpp | 1 - r5dev/game/server/ai_networkmanager.cpp | 1 - r5dev/gameui/IBrowser.cpp | 1 - r5dev/materialsystem/cmaterialsystem.cpp | 1 - r5dev/networksystem/r5net.cpp | 1 - r5dev/public/bansystem.cpp | 1 - r5dev/public/binstream.cpp | 1 - r5dev/rtech/rtech_game.cpp | 1 - r5dev/rtech/rtech_utils.cpp | 1 - r5dev/server/vengineserver_impl.cpp | 1 - r5dev/squirrel/sqinit.cpp | 1 - r5dev/squirrel/sqvm.cpp | 1 - r5dev/thirdparty/imgui/src/imgui_utility.cpp | 1 - r5dev/tier0/dbg.cpp | 338 ++++++++++++++++++ r5dev/tier0/dbg.h | 100 ++++++ r5dev/tier0/dbgflag.h | 68 ++++ r5dev/tier0/platform.h | 345 +++++++++++++++++++ r5dev/tier0/valve_off.h | 33 ++ r5dev/tier0/valve_on.h | 37 ++ r5dev/tier0/wchartypes.h | 115 +++++++ r5dev/tier1/IConVar.cpp | 2 - r5dev/tier1/cmd.cpp | 1 - r5dev/vphysics/QHull.cpp | 1 - r5dev/vpklib/packedstore.cpp | 1 - r5dev/vproj/clientsdk.vcxproj | 6 + r5dev/vproj/clientsdk.vcxproj.filters | 18 + r5dev/vproj/dedicated.vcxproj | 6 + r5dev/vproj/dedicated.vcxproj.filters | 18 + r5dev/vproj/gamesdk.vcxproj | 6 + r5dev/vproj/gamesdk.vcxproj.filters | 18 + r5dev/vstdlib/callback.cpp | 1 - r5dev/windows/id3dx.cpp | 1 - 50 files changed, 1110 insertions(+), 341 deletions(-) create mode 100644 r5dev/tier0/dbg.cpp create mode 100644 r5dev/tier0/dbg.h create mode 100644 r5dev/tier0/dbgflag.h create mode 100644 r5dev/tier0/valve_off.h create mode 100644 r5dev/tier0/valve_on.h create mode 100644 r5dev/tier0/wchartypes.h diff --git a/r5dev/common/netmessages.cpp b/r5dev/common/netmessages.cpp index 5b190197..fb4eac9a 100644 --- a/r5dev/common/netmessages.cpp +++ b/r5dev/common/netmessages.cpp @@ -10,7 +10,6 @@ /////////////////////////////////////////////////////////////////////////////////// #include "core/stdafx.h" #include "common/netmessages.h" -#include "engine/sys_utils.h" bool SVC_Print::Process() { diff --git a/r5dev/core/stdafx.h b/r5dev/core/stdafx.h index fbea967e..3a4ec341 100644 --- a/r5dev/core/stdafx.h +++ b/r5dev/core/stdafx.h @@ -86,6 +86,7 @@ #include "core/termutil.h" #include "tier0/basetypes.h" #include "tier0/platform.h" +#include "tier0/dbg.h" #if !defined(SDKLAUNCHER) && !defined (NETCONSOLE) #if !defined (DEDICATED) diff --git a/r5dev/cpp.hint b/r5dev/cpp.hint index 15955c79..6a8c58eb 100644 --- a/r5dev/cpp.hint +++ b/r5dev/cpp.hint @@ -7,3 +7,4 @@ #define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) #define IM_FMTARGS(FMT) __attribute__((format(gnu_printf, FMT, FMT+1))) #define IM_FMTARGS(FMT) +#define PLATFORM_INTERFACE diff --git a/r5dev/datacache/mdlcache.cpp b/r5dev/datacache/mdlcache.cpp index 190c3fab..b62821d0 100644 --- a/r5dev/datacache/mdlcache.cpp +++ b/r5dev/datacache/mdlcache.cpp @@ -11,7 +11,6 @@ #include "datacache/mdlcache.h" #include "datacache/imdlcache.h" #include "datacache/idatacache.h" -#include "engine/sys_utils.h" #include "rtech/rtech_utils.h" #include "public/include/studio.h" #include "tier1/utldict.h" diff --git a/r5dev/ebisusdk/EbisuSDK.cpp b/r5dev/ebisusdk/EbisuSDK.cpp index dc1e7b85..839b6809 100644 --- a/r5dev/ebisusdk/EbisuSDK.cpp +++ b/r5dev/ebisusdk/EbisuSDK.cpp @@ -1,6 +1,5 @@ #include "core/stdafx.h" #include "ebisusdk/EbisuSDK.h" -#include "engine/sys_utils.h" //----------------------------------------------------------------------------- // Purpose: sets the EbisuSDK globals for dedicated to satisfy command callbacks diff --git a/r5dev/engine/client/cl_rcon.cpp b/r5dev/engine/client/cl_rcon.cpp index faab96a3..f8513cba 100644 --- a/r5dev/engine/client/cl_rcon.cpp +++ b/r5dev/engine/client/cl_rcon.cpp @@ -11,7 +11,6 @@ #include "protoc/sv_rcon.pb.h" #include "protoc/cl_rcon.pb.h" #include "engine/client/cl_rcon.h" -#include "engine/sys_utils.h" #include "squirrel/sqvm.h" #include "common/igameserverdata.h" diff --git a/r5dev/engine/cmodel_bsp.cpp b/r5dev/engine/cmodel_bsp.cpp index b09cd692..5db19ff1 100644 --- a/r5dev/engine/cmodel_bsp.cpp +++ b/r5dev/engine/cmodel_bsp.cpp @@ -8,7 +8,6 @@ #include "core/stdafx.h" #include "tier0/jobthread.h" #include "engine/host_cmd.h" -#include "engine/sys_utils.h" #include "engine/cmodel_bsp.h" #include "rtech/rtech_utils.h" #include "rtech/rtech_game.h" diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index 4b6528b2..b2496db6 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -28,7 +28,6 @@ #include "engine/host_cmd.h" #include "engine/host_state.h" #include "engine/sys_engine.h" -#include "engine/sys_utils.h" #include "engine/modelloader.h" #include "engine/cmodel_bsp.h" #ifndef CLIENT_DLL diff --git a/r5dev/engine/modelloader.cpp b/r5dev/engine/modelloader.cpp index 9f451ee6..8157da05 100644 --- a/r5dev/engine/modelloader.cpp +++ b/r5dev/engine/modelloader.cpp @@ -9,7 +9,6 @@ #include "engine/cmodel_bsp.h" #include "engine/modelloader.h" #include "datacache/mdlcache.h" -#include "engine/sys_utils.h" model_t* pErrorMDL = nullptr; diff --git a/r5dev/engine/net.cpp b/r5dev/engine/net.cpp index dc4564e7..8cf1157f 100644 --- a/r5dev/engine/net.cpp +++ b/r5dev/engine/net.cpp @@ -11,7 +11,6 @@ #include "tier1/cvar.h" #include "vstdlib/callback.h" #include "mathlib/color.h" -#include "engine/sys_utils.h" #include "engine/net.h" #include "engine/net_chan.h" #ifndef CLIENT_DLL diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index d14b820f..9c94a86b 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -6,7 +6,6 @@ #include "core/stdafx.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" #include "engine/net.h" #include "engine/net_chan.h" diff --git a/r5dev/engine/server/server.cpp b/r5dev/engine/server/server.cpp index 776f38c6..3653b036 100644 --- a/r5dev/engine/server/server.cpp +++ b/r5dev/engine/server/server.cpp @@ -11,7 +11,6 @@ #include "core/stdafx.h" #include "common/protocol.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" #include "engine/server/sv_main.h" #include "engine/server/server.h" #include "networksystem/r5net.h" diff --git a/r5dev/engine/server/sv_main.cpp b/r5dev/engine/server/sv_main.cpp index ee7053cc..8939d972 100644 --- a/r5dev/engine/server/sv_main.cpp +++ b/r5dev/engine/server/sv_main.cpp @@ -1,5 +1,4 @@ #include "core/stdafx.h" -#include "engine/sys_utils.h" #include "engine/server/sv_main.h" #include "networksystem/r5net.h" #include "public/include/bansystem.h" diff --git a/r5dev/engine/server/sv_rcon.cpp b/r5dev/engine/server/sv_rcon.cpp index 9d97ac84..970e497d 100644 --- a/r5dev/engine/server/sv_rcon.cpp +++ b/r5dev/engine/server/sv_rcon.cpp @@ -10,7 +10,6 @@ #include "tier1/IConVar.h" #include "tier1/NetAdr2.h" #include "tier2/socketcreator.h" -#include "engine/sys_utils.h" #include "engine/server/sv_rcon.h" #include "protoc/sv_rcon.pb.h" #include "protoc/cl_rcon.pb.h" diff --git a/r5dev/engine/sys_dll.cpp b/r5dev/engine/sys_dll.cpp index b5439134..3b8a9674 100644 --- a/r5dev/engine/sys_dll.cpp +++ b/r5dev/engine/sys_dll.cpp @@ -1,6 +1,5 @@ #include "core/stdafx.h" #include "engine/sys_dll.h" -#include "engine/sys_utils.h" //----------------------------------------------------------------------------- // Sys_Error_Internal diff --git a/r5dev/engine/sys_dll2.cpp b/r5dev/engine/sys_dll2.cpp index e3f36776..7da36751 100644 --- a/r5dev/engine/sys_dll2.cpp +++ b/r5dev/engine/sys_dll2.cpp @@ -10,7 +10,6 @@ #include "tier1/cvar.h" #include "engine/sys_dll.h" #include "engine/sys_dll2.h" -#include "engine/sys_utils.h" #include "client/vengineclient_impl.h" //----------------------------------------------------------------------------- diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index 746cfdde..eb63baa7 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -89,268 +89,6 @@ void HCon_NPrintf(int pos, const char* fmt, ...) } #endif // !DEDICATED -//----------------------------------------------------------------------------- -// Purpose: Show logs to all console interfaces -// Input : idx - -// *fmt - ... - -//----------------------------------------------------------------------------- -void DevMsg(eDLL_T idx, const char* fmt, ...) -{ - static char szBuf[2048] = {}; - - static std::string svOut; - static std::string svAnsiOut; - - static std::regex rxAnsiExp("\\\033\\[.*?m"); - - static std::shared_ptr iconsole = spdlog::get("game_console"); - static std::shared_ptr wconsole = spdlog::get("win_console"); - static std::shared_ptr sqlogger = spdlog::get("sdk_info"); - - s_LogMutex.lock(); - {///////////////////////////// - va_list args{}; - va_start(args, fmt); - - vsnprintf(szBuf, sizeof(szBuf), fmt, args); - - szBuf[sizeof(szBuf) - 1] = 0; - va_end(args); - }///////////////////////////// - - svOut = sDLL_T[static_cast(idx)].c_str(); - svOut.append(szBuf); - svOut = std::regex_replace(svOut, rxAnsiExp, ""); - - char szNewLine = svOut.back(); - if (szNewLine != '\n') - { - svOut.append("\n"); - } - - if (!g_bSpdLog_UseAnsiClr) - { - wconsole->debug(svOut); -#ifdef DEDICATED - g_pRConServer->Send(svOut.c_str()); -#endif // DEDICATED - } - else - { - svAnsiOut = sANSI_DLL_T[static_cast(idx)].c_str(); - svAnsiOut.append(szBuf); - - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') - { - svAnsiOut.append("\n"); - } - wconsole->debug(svAnsiOut); -#ifdef DEDICATED - g_pRConServer->Send(svAnsiOut.c_str()); -#endif // DEDICATED - } - - sqlogger->debug(svOut); - -#ifndef DEDICATED - iconsole->info(svOut); - - int nLog = static_cast(idx) + 3; // RUI log enum is shifted by 3 for scripts. - LogType_t tLog = static_cast(nLog); - - ImVec4 color; - switch (idx) - { - case eDLL_T::SERVER: - color = ImVec4(0.23f, 0.47f, 0.85f, 1.00f); - break; - case eDLL_T::CLIENT: - color = ImVec4(0.46f, 0.46f, 0.46f, 1.00f); - break; - case eDLL_T::UI: - color = ImVec4(0.59f, 0.35f, 0.46f, 1.00f); - break; - case eDLL_T::ENGINE: - color = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); - break; - case eDLL_T::FS: - color = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); - break; - case eDLL_T::RTECH: - color = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); - break; - case eDLL_T::MS: - color = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); - break; - default: - color = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); - break; - } - - g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), color)); - g_pLogSystem.AddLog(tLog, g_spd_sys_w_oss.str()); - - g_spd_sys_w_oss.str(""); - g_spd_sys_w_oss.clear(); -#endif // !DEDICATED - s_LogMutex.unlock(); -} - -//----------------------------------------------------------------------------- -// Purpose: Print engine and SDK errors -// Input : idx - -// *fmt - ... - -//----------------------------------------------------------------------------- -void Warning(eDLL_T idx, const char* fmt, ...) -{ - static char szBuf[2048] = {}; - - static std::string svOut; - static std::string svAnsiOut; - - static std::regex rxAnsiExp("\\\033\\[.*?m"); - - static std::shared_ptr iconsole = spdlog::get("game_console"); - static std::shared_ptr wconsole = spdlog::get("win_console"); - static std::shared_ptr sqlogger = spdlog::get("sdk_warn"); - - s_LogMutex.lock(); - {///////////////////////////// - va_list args{}; - va_start(args, fmt); - - vsnprintf(szBuf, sizeof(szBuf), fmt, args); - - szBuf[sizeof(szBuf) - 1] = 0; - va_end(args); - }///////////////////////////// - - svOut = sDLL_T[static_cast(idx)].c_str(); - svOut.append(szBuf); - svOut = std::regex_replace(svOut, rxAnsiExp, ""); - - char szNewLine = svOut.back(); - if (szNewLine != '\n') - { - svOut.append("\n"); - } - - if (!g_bSpdLog_UseAnsiClr) - { - wconsole->debug(svOut); -#ifdef DEDICATED - g_pRConServer->Send(svOut.c_str()); -#endif // DEDICATED - } - else - { - svAnsiOut = sANSI_DLL_T[static_cast(idx)].c_str(); - svAnsiOut.append(g_svYellowF.c_str()); - svAnsiOut.append(szBuf); - - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') - { - svAnsiOut.append("\n"); - } - wconsole->debug(svAnsiOut); -#ifdef DEDICATED - g_pRConServer->Send(svAnsiOut.c_str()); -#endif // DEDICATED - } - - sqlogger->debug(svOut); - -#ifndef DEDICATED - iconsole->info(svOut); - - g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); - g_pLogSystem.AddLog(LogType_t::WARNING_C, g_spd_sys_w_oss.str()); - - g_spd_sys_w_oss.str(""); - g_spd_sys_w_oss.clear(); -#endif // !DEDICATED - s_LogMutex.unlock(); -} - -//----------------------------------------------------------------------------- -// Purpose: Print engine and SDK errors -// Input : idx - -// *fmt - ... - -//----------------------------------------------------------------------------- -void Error(eDLL_T idx, const char* fmt, ...) -{ - static char szBuf[2048] = {}; - - static std::string svOut; - static std::string svAnsiOut; - - static std::regex rxAnsiExp("\\\033\\[.*?m"); - - static std::shared_ptr iconsole = spdlog::get("game_console"); - static std::shared_ptr wconsole = spdlog::get("win_console"); - static std::shared_ptr sqlogger = spdlog::get("sdk_error"); - - s_LogMutex.lock(); - {///////////////////////////// - va_list args{}; - va_start(args, fmt); - - vsnprintf(szBuf, sizeof(szBuf), fmt, args); - - szBuf[sizeof(szBuf) - 1] = 0; - va_end(args); - }///////////////////////////// - - svOut = sDLL_T[static_cast(idx)].c_str(); - svOut.append(szBuf); - svOut = std::regex_replace(svOut, rxAnsiExp, ""); - - char szNewLine = svOut.back(); - if (szNewLine != '\n') - { - svOut.append("\n"); - } - - if (!g_bSpdLog_UseAnsiClr) - { - wconsole->debug(svOut); -#ifdef DEDICATED - g_pRConServer->Send(svOut.c_str()); -#endif // DEDICATED - } - else - { - svAnsiOut = sANSI_DLL_T[static_cast(idx)].c_str(); - svAnsiOut.append(g_svRedF.c_str()); - svAnsiOut.append(szBuf); - - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') - { - svAnsiOut.append("\n"); - } - wconsole->debug(svAnsiOut); -#ifdef DEDICATED - g_pRConServer->Send(svAnsiOut.c_str()); -#endif // DEDICATED - } - - sqlogger->debug(svOut); - -#ifndef DEDICATED - iconsole->info(svOut); - - g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 0.00f, 0.00f, 1.00f))); - g_pLogSystem.AddLog(LogType_t::ERROR_C, g_spd_sys_w_oss.str()); - - g_spd_sys_w_oss.str(""); - g_spd_sys_w_oss.clear(); -#endif // !DEDICATED - s_LogMutex.unlock(); -} - //----------------------------------------------------------------------------- // Purpose: Load assets from a custom directory if file exists // Input : *lpFileName - diff --git a/r5dev/engine/sys_utils.h b/r5dev/engine/sys_utils.h index 0bca76aa..49a858dc 100644 --- a/r5dev/engine/sys_utils.h +++ b/r5dev/engine/sys_utils.h @@ -12,55 +12,10 @@ inline auto Sys_LoadAssetHelper = p_Sys_LoadAssetHelper.RCast(); - -inline std::mutex s_LogMutex; /* ==== ------- ========================================================================================================================================================= */ -enum class eDLL_T : int -{ - SERVER = 0, // Game DLL - CLIENT = 1, // Game DLL - UI = 2, // Game DLL - ENGINE = 3, // Wrapper - FS = 4, // File System - RTECH = 5, // RTech API - MS = 6, // Material System - NETCON = 7, // Net Console - NONE = 8 -}; - -const string sDLL_T[9] = -{ - "Native(S):", - "Native(C):", - "Native(U):", - "Native(E):", - "Native(F):", - "Native(R):", - "Native(M):", - "Netcon(X):", - "" -}; - -const static string sANSI_DLL_T[9] = -{ - "\033[38;2;059;120;218mNative(S):", - "\033[38;2;118;118;118mNative(C):", - "\033[38;2;151;090;118mNative(U):", - "\033[38;2;204;204;204mNative(E):", - "\033[38;2;097;214;214mNative(F):", - "\033[38;2;092;181;089mNative(R):", - "\033[38;2;192;105;173mNative(M):", - "\033[38;2;204;204;204mNetcon(X):", - "" -}; - /////////////////////////////////////////////////////////////////////////////// void HSys_Error(char* fmt, ...); -void DevMsg(eDLL_T idx, const char* fmt, ...); -void Warning(eDLL_T idx, const char* fmt, ...); -void Error(eDLL_T idx, const char* fmt, ...); - void SysUtils_Attach(); void SysUtils_Detach(); diff --git a/r5dev/game/server/ai_network.cpp b/r5dev/game/server/ai_network.cpp index 3ebbc9e6..395bab2d 100644 --- a/r5dev/game/server/ai_network.cpp +++ b/r5dev/game/server/ai_network.cpp @@ -5,7 +5,6 @@ //=============================================================================// #include "core/stdafx.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" #include "game/server/ai_network.h" int g_DebugConnectNode1 = -1; diff --git a/r5dev/game/server/ai_networkmanager.cpp b/r5dev/game/server/ai_networkmanager.cpp index ec0560ba..b585a64d 100644 --- a/r5dev/game/server/ai_networkmanager.cpp +++ b/r5dev/game/server/ai_networkmanager.cpp @@ -12,7 +12,6 @@ #include "public/include/edict.h" #include "public/include/utility.h" #include "engine/host_state.h" -#include "engine/sys_utils.h" #include "game/server/ai_node.h" #include "game/server/ai_network.h" #include "game/server/ai_networkmanager.h" diff --git a/r5dev/gameui/IBrowser.cpp b/r5dev/gameui/IBrowser.cpp index b0763efb..5c1892b4 100644 --- a/r5dev/gameui/IBrowser.cpp +++ b/r5dev/gameui/IBrowser.cpp @@ -21,7 +21,6 @@ History: #include "windows/console.h" #include "windows/resource.h" #include "engine/net.h" -#include "engine/sys_utils.h" #include "engine/host_state.h" #ifndef CLIENT_DLL #include "engine/server/server.h" diff --git a/r5dev/materialsystem/cmaterialsystem.cpp b/r5dev/materialsystem/cmaterialsystem.cpp index 7e545069..c9802616 100644 --- a/r5dev/materialsystem/cmaterialsystem.cpp +++ b/r5dev/materialsystem/cmaterialsystem.cpp @@ -5,7 +5,6 @@ //===========================================================================// #include "core/stdafx.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" #include "materialsystem/cmaterialsystem.h" //--------------------------------------------------------------------------------- diff --git a/r5dev/networksystem/r5net.cpp b/r5dev/networksystem/r5net.cpp index 3dbb48a5..da4b3501 100644 --- a/r5dev/networksystem/r5net.cpp +++ b/r5dev/networksystem/r5net.cpp @@ -3,7 +3,6 @@ #include "core/stdafx.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" #include "networksystem/r5net.h" //----------------------------------------------------------------------------- diff --git a/r5dev/public/bansystem.cpp b/r5dev/public/bansystem.cpp index 675beb50..d6517cd2 100644 --- a/r5dev/public/bansystem.cpp +++ b/r5dev/public/bansystem.cpp @@ -7,7 +7,6 @@ #include "core/stdafx.h" #include "engine/net.h" -#include "engine/sys_utils.h" #include "engine/client/client.h" #include "public/include/bansystem.h" diff --git a/r5dev/public/binstream.cpp b/r5dev/public/binstream.cpp index ff95077d..88e2734f 100644 --- a/r5dev/public/binstream.cpp +++ b/r5dev/public/binstream.cpp @@ -1,5 +1,4 @@ #include "core/stdafx.h" -#include "engine/sys_utils.h" #include "public/include/binstream.h" //----------------------------------------------------------------------------- diff --git a/r5dev/rtech/rtech_game.cpp b/r5dev/rtech/rtech_game.cpp index a9d882ff..549b8061 100644 --- a/r5dev/rtech/rtech_game.cpp +++ b/r5dev/rtech/rtech_game.cpp @@ -5,7 +5,6 @@ //=============================================================================// #include "core/stdafx.h" #include "engine/host_cmd.h" -#include "engine/sys_utils.h" #include "engine/host_state.h" #include "engine/cmodel_bsp.h" #include "rtech/rtech_game.h" diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index 2ba28ce7..cad03b55 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -1,5 +1,4 @@ #include "core/stdafx.h" -#include "engine/sys_utils.h" #include "rtech/rtech_utils.h" /****************************************************************************** diff --git a/r5dev/server/vengineserver_impl.cpp b/r5dev/server/vengineserver_impl.cpp index 10751679..95c50a81 100644 --- a/r5dev/server/vengineserver_impl.cpp +++ b/r5dev/server/vengineserver_impl.cpp @@ -7,7 +7,6 @@ #include "core/stdafx.h" #include "tier1/cvar.h" #include "common/protocol.h" -#include "engine/sys_utils.h" #include "engine/client/client.h" #include "server/vengineserver_impl.h" diff --git a/r5dev/squirrel/sqinit.cpp b/r5dev/squirrel/sqinit.cpp index 2722c22a..9cf96403 100644 --- a/r5dev/squirrel/sqinit.cpp +++ b/r5dev/squirrel/sqinit.cpp @@ -12,7 +12,6 @@ //=============================================================================// #include "core/stdafx.h" -#include "engine/sys_utils.h" #ifndef CLIENT_DLL #include "engine/server/server.h" #endif // CLIENT_DLL diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 95dc0475..3ae9d625 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -9,7 +9,6 @@ #include "tier0/commandline.h" #include "tier1/cvar.h" #include "tier1/IConVar.h" -#include "engine/sys_utils.h" #ifdef DEDICATED #include "engine/server/sv_rcon.h" #else // DEDICATED diff --git a/r5dev/thirdparty/imgui/src/imgui_utility.cpp b/r5dev/thirdparty/imgui/src/imgui_utility.cpp index 22ad18a2..827b1740 100644 --- a/r5dev/thirdparty/imgui/src/imgui_utility.cpp +++ b/r5dev/thirdparty/imgui/src/imgui_utility.cpp @@ -3,7 +3,6 @@ *-----------------------------------------------------------------------------*/ #include "core/stdafx.h" -#include "engine/sys_utils.h" #include "thirdparty/imgui/include/imgui_utility.h" int Stricmp(const char* s1, const char* s2) diff --git a/r5dev/tier0/dbg.cpp b/r5dev/tier0/dbg.cpp new file mode 100644 index 00000000..6e900f8e --- /dev/null +++ b/r5dev/tier0/dbg.cpp @@ -0,0 +1,338 @@ +//==== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. =====// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include "core/stdafx.h" +#include "core/logdef.h" +#include "tier0/platform.h" +#include "tier0/threadtools.h" +#include "tier0/dbg.h" +#ifndef DEDICATED +#include "vgui/vgui_debugpanel.h" +#include "gameui/IConsole.h" +#else +#include "engine/server/sv_rcon.h" +#endif + +#if defined( _X360 ) +#include "xbox/xbox_console.h" +#endif +std::mutex s_LogMutex; + +//----------------------------------------------------------------------------- +// Templates to assist in validating pointers: +//----------------------------------------------------------------------------- +PLATFORM_INTERFACE void _AssertValidReadPtr(void* ptr, int count/* = 1*/) +{ +#if defined( _WIN32 ) && !defined( _X360 ) + Assert(!IsBadReadPtr(ptr, count)); +#else + Assert(!count || ptr); +#endif +} + +PLATFORM_INTERFACE void _AssertValidWritePtr(void* ptr, int count/* = 1*/) +{ +#if defined( _WIN32 ) && !defined( _X360 ) + Assert(!IsBadWritePtr(ptr, count)); +#else + Assert(!count || ptr); +#endif +} + +PLATFORM_INTERFACE void _AssertValidReadWritePtr(void* ptr, int count/* = 1*/) +{ +#if defined( _WIN32 ) && !defined( _X360 ) + Assert(!(IsBadWritePtr(ptr, count) || IsBadReadPtr(ptr, count))); +#else + Assert(!count || ptr); +#endif +} + +PLATFORM_INTERFACE void _AssertValidStringPtr(const TCHAR* ptr, int maxchar/* = 0xFFFFFF */) +{ +#if defined( _WIN32 ) && !defined( _X360 ) +#ifdef TCHAR_IS_CHAR + Assert(!IsBadStringPtr(ptr, maxchar)); +#else + Assert(!IsBadStringPtrW(ptr, maxchar)); +#endif +#else + Assert(ptr); +#endif +} + +PLATFORM_INTERFACE void AssertValidWStringPtr(const wchar_t* ptr, int maxchar/* = 0xFFFFFF */) +{ +#if defined( _WIN32 ) && !defined( _X360 ) + Assert(!IsBadStringPtrW(ptr, maxchar)); +#else + Assert(ptr); +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: Show logs to all console interfaces +// Input : idx - +// *fmt - ... - +//----------------------------------------------------------------------------- +void DevMsg(eDLL_T context, const char* fmt, ...) +{ + static char szBuf[2048] = {}; + + static std::string svOut; + static std::string svAnsiOut; + + static std::regex rxAnsiExp("\\\033\\[.*?m"); + + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("sdk_info"); + + s_LogMutex.lock(); + {///////////////////////////// + va_list args{}; + va_start(args, fmt); + + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + + szBuf[sizeof(szBuf) - 1] = 0; + va_end(args); + }///////////////////////////// + + svOut = sDLL_T[static_cast(context)].c_str(); + svOut.append(szBuf); + svOut = std::regex_replace(svOut, rxAnsiExp, ""); + + char szNewLine = svOut.back(); + if (szNewLine != '\n') + { + svOut.append("\n"); + } + + if (!g_bSpdLog_UseAnsiClr) + { + wconsole->debug(svOut); +#ifdef DEDICATED + g_pRConServer->Send(svOut.c_str()); +#endif // DEDICATED + } + else + { + svAnsiOut = sANSI_DLL_T[static_cast(context)].c_str(); + svAnsiOut.append(szBuf); + + char szNewLine = svAnsiOut.back(); + if (szNewLine != '\n') + { + svAnsiOut.append("\n"); + } + wconsole->debug(svAnsiOut); +#ifdef DEDICATED + g_pRConServer->Send(svAnsiOut.c_str()); +#endif // DEDICATED + } + + sqlogger->debug(svOut); + +#ifndef DEDICATED + iconsole->info(svOut); + + int nLog = static_cast(context) + 3; // RUI log enum is shifted by 3 for scripts. + LogType_t tLog = static_cast(nLog); + + ImVec4 color; + switch (context) + { + case eDLL_T::SERVER: + color = ImVec4(0.23f, 0.47f, 0.85f, 1.00f); + break; + case eDLL_T::CLIENT: + color = ImVec4(0.46f, 0.46f, 0.46f, 1.00f); + break; + case eDLL_T::UI: + color = ImVec4(0.59f, 0.35f, 0.46f, 1.00f); + break; + case eDLL_T::ENGINE: + color = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); + break; + case eDLL_T::FS: + color = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); + break; + case eDLL_T::RTECH: + color = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); + break; + case eDLL_T::MS: + color = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); + break; + default: + color = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); + break; + } + + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), color)); + g_pLogSystem.AddLog(tLog, g_spd_sys_w_oss.str()); + + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); +#endif // !DEDICATED + s_LogMutex.unlock(); +} + +//----------------------------------------------------------------------------- +// Purpose: Print engine and SDK errors +// Input : idx - +// *fmt - ... - +//----------------------------------------------------------------------------- +void Warning(eDLL_T context, const char* fmt, ...) +{ + static char szBuf[2048] = {}; + + static std::string svOut; + static std::string svAnsiOut; + + static std::regex rxAnsiExp("\\\033\\[.*?m"); + + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("sdk_warn"); + + s_LogMutex.lock(); + {///////////////////////////// + va_list args{}; + va_start(args, fmt); + + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + + szBuf[sizeof(szBuf) - 1] = 0; + va_end(args); + }///////////////////////////// + + svOut = sDLL_T[static_cast(context)].c_str(); + svOut.append(szBuf); + svOut = std::regex_replace(svOut, rxAnsiExp, ""); + + char szNewLine = svOut.back(); + if (szNewLine != '\n') + { + svOut.append("\n"); + } + + if (!g_bSpdLog_UseAnsiClr) + { + wconsole->debug(svOut); +#ifdef DEDICATED + g_pRConServer->Send(svOut.c_str()); +#endif // DEDICATED + } + else + { + svAnsiOut = sANSI_DLL_T[static_cast(context)].c_str(); + svAnsiOut.append(g_svYellowF.c_str()); + svAnsiOut.append(szBuf); + + char szNewLine = svAnsiOut.back(); + if (szNewLine != '\n') + { + svAnsiOut.append("\n"); + } + wconsole->debug(svAnsiOut); +#ifdef DEDICATED + g_pRConServer->Send(svAnsiOut.c_str()); +#endif // DEDICATED + } + + sqlogger->debug(svOut); + +#ifndef DEDICATED + iconsole->info(svOut); + + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); + g_pLogSystem.AddLog(LogType_t::WARNING_C, g_spd_sys_w_oss.str()); + + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); +#endif // !DEDICATED + s_LogMutex.unlock(); +} + +//----------------------------------------------------------------------------- +// Purpose: Print engine and SDK errors +// Input : idx - +// *fmt - ... - +//----------------------------------------------------------------------------- +void Error(eDLL_T context, const char* fmt, ...) +{ + static char szBuf[2048] = {}; + + static std::string svOut; + static std::string svAnsiOut; + + static std::regex rxAnsiExp("\\\033\\[.*?m"); + + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("sdk_error"); + + s_LogMutex.lock(); + {///////////////////////////// + va_list args{}; + va_start(args, fmt); + + vsnprintf(szBuf, sizeof(szBuf), fmt, args); + + szBuf[sizeof(szBuf) - 1] = 0; + va_end(args); + }///////////////////////////// + + svOut = sDLL_T[static_cast(context)].c_str(); + svOut.append(szBuf); + svOut = std::regex_replace(svOut, rxAnsiExp, ""); + + char szNewLine = svOut.back(); + if (szNewLine != '\n') + { + svOut.append("\n"); + } + + if (!g_bSpdLog_UseAnsiClr) + { + wconsole->debug(svOut); +#ifdef DEDICATED + g_pRConServer->Send(svOut.c_str()); +#endif // DEDICATED + } + else + { + svAnsiOut = sANSI_DLL_T[static_cast(context)].c_str(); + svAnsiOut.append(g_svRedF.c_str()); + svAnsiOut.append(szBuf); + + char szNewLine = svAnsiOut.back(); + if (szNewLine != '\n') + { + svAnsiOut.append("\n"); + } + wconsole->debug(svAnsiOut); +#ifdef DEDICATED + g_pRConServer->Send(svAnsiOut.c_str()); +#endif // DEDICATED + } + + sqlogger->debug(svOut); + +#ifndef DEDICATED + iconsole->info(svOut); + + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 0.00f, 0.00f, 1.00f))); + g_pLogSystem.AddLog(LogType_t::ERROR_C, g_spd_sys_w_oss.str()); + + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); +#endif // !DEDICATED + s_LogMutex.unlock(); +} \ No newline at end of file diff --git a/r5dev/tier0/dbg.h b/r5dev/tier0/dbg.h new file mode 100644 index 00000000..ead33f24 --- /dev/null +++ b/r5dev/tier0/dbg.h @@ -0,0 +1,100 @@ +//===== Copyright (c) Valve Corporation, All rights reserved. ========// +// +// Purpose: +// +// $NoKeywords: $ +// +//====================================================================// +#ifndef DBG_H +#define DBG_H +#define Assert assert +#include "tier0/dbgflag.h" + +//----------------------------------------------------------------------------- +enum class eDLL_T : int +{ + SERVER = 0, // Game DLL + CLIENT = 1, // Game DLL + UI = 2, // Game DLL + ENGINE = 3, // Wrapper + FS = 4, // File System + RTECH = 5, // RTech API + MS = 6, // Material System + NETCON = 7, // Net Console + NONE = 8 +}; + +const string sDLL_T[9] = +{ + "Native(S):", + "Native(C):", + "Native(U):", + "Native(E):", + "Native(F):", + "Native(R):", + "Native(M):", + "Netcon(X):", + "" +}; + +const static string sANSI_DLL_T[9] = +{ + "\033[38;2;059;120;218mNative(S):", + "\033[38;2;118;118;118mNative(C):", + "\033[38;2;151;090;118mNative(U):", + "\033[38;2;204;204;204mNative(E):", + "\033[38;2;097;214;214mNative(F):", + "\033[38;2;092;181;089mNative(R):", + "\033[38;2;192;105;173mNative(M):", + "\033[38;2;204;204;204mNetcon(X):", + "" +}; +extern std::mutex s_LogMutex; + +////////////////////////////////////////////////////////////////////////// +// Legacy Logging System +////////////////////////////////////////////////////////////////////////// + +// These functions do not return. +PLATFORM_INTERFACE void DevMsg(eDLL_T context, const char* fmt, ...) FMTFUNCTION(2, 3); +PLATFORM_INTERFACE void Warning(eDLL_T context, const char* fmt, ...) FMTFUNCTION(1, 2); +PLATFORM_INTERFACE void Error(eDLL_T context, const char* fmt, ...) FMTFUNCTION(1, 2); + +// You can use this macro like a runtime assert macro. +// If the condition fails, then Error is called with the message. This macro is called +// like AssertMsg, where msg must be enclosed in parenthesis: +// +// ErrorIfNot( bCondition, ("a b c %d %d %d", 1, 2, 3) ); +#define ErrorIfNot( condition, msg ) \ + if ( (condition) ) \ + ; \ + else \ + { \ + Error msg; \ + } + +//----------------------------------------------------------------------------- +// Templates to assist in validating pointers: + +// Have to use these stubs so we don't have to include windows.h here. +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); + +#ifdef DBGFLAG_ASSERT +inline void AssertValidStringPtr(const TCHAR* ptr, int maxchar = 0xFFFFFF) { _AssertValidStringPtr(ptr, maxchar); } +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)) + +#else + +inline void AssertValidStringPtr(const TCHAR* ptr, int maxchar = 0xFFFFFF) { } +template inline void AssertValidReadPtr(T* ptr, int count = 1) { } +template inline void AssertValidWritePtr(T* ptr, int count = 1) { } +template inline void AssertValidReadWritePtr(T* ptr, int count = 1) { } +#define AssertValidThis() +#endif +#endif /* DBG_H */ diff --git a/r5dev/tier0/dbgflag.h b/r5dev/tier0/dbgflag.h new file mode 100644 index 00000000..e387e346 --- /dev/null +++ b/r5dev/tier0/dbgflag.h @@ -0,0 +1,68 @@ +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: This file sets all of our debugging flags. It should be +// called before all other header files. +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef DBGFLAG_H +#define DBGFLAG_H +#ifdef _WIN32 +#pragma once +#endif + + +// Here are all the flags we support: +// DBGFLAG_MEMORY: Enables our memory debugging system, which overrides malloc & free +// DBGFLAG_MEMORY_NEWDEL: Enables new / delete tracking for memory debug system. Requires DBGFLAG_MEMORY to be enabled. +// DBGFLAG_VALIDATE: Enables our recursive validation system for checking integrity and memory leaks +// DBGFLAG_ASSERT: Turns Assert on or off (when off, it isn't compiled at all) +// DBGFLAG_ASSERTFATAL: Turns AssertFatal on or off (when off, it isn't compiled at all) +// DBGFLAG_ASSERTDLG: Turns assert dialogs on or off and debug breaks on or off when not under the debugger. +// (Dialogs will always be on when process is being debugged.) +// DBGFLAG_STRINGS: Turns on hardcore string validation (slow but safe) + +#undef DBGFLAG_MEMORY +#undef DBGFLAG_MEMORY_NEWDEL +#undef DBGFLAG_VALIDATE +#undef DBGFLAG_ASSERT +#undef DBGFLAG_ASSERTFATAL +#undef DBGFLAG_ASSERTDLG +#undef DBGFLAG_STRINGS + +//----------------------------------------------------------------------------- +// Default flags for debug builds +//----------------------------------------------------------------------------- +#if defined( _DEBUG ) && !defined( PS3MEMOVERRIDEWRAP ) + +#define DBGFLAG_MEMORY +#ifdef _SERVER // only enable new & delete tracking for server; on client it conflicts with CRT mem leak tracking +#define DBGFLAG_MEMORY_NEWDEL +#endif +#ifdef STEAM +#define DBGFLAG_VALIDATE +#endif +#define DBGFLAG_ASSERT +#define DBGFLAG_ASSERTFATAL +#define DBGFLAG_ASSERTDLG +#define DBGFLAG_STRINGS + + +//----------------------------------------------------------------------------- +// Default flags for release builds +//----------------------------------------------------------------------------- +#else // _DEBUG +#ifdef STEAM +#define DBGFLAG_ASSERT +#endif +#define DBGFLAG_ASSERTFATAL // note: fatal asserts are enabled in release builds +#define DBGFLAG_ASSERTDLG + +#endif // _DEBUG + +#if defined( _CERT ) +#define DBGFLAG_STRINGS_STRIP +#endif + +#endif // DBGFLAG_H diff --git a/r5dev/tier0/platform.h b/r5dev/tier0/platform.h index 6d447457..b16a8aeb 100644 --- a/r5dev/tier0/platform.h +++ b/r5dev/tier0/platform.h @@ -5,6 +5,145 @@ #pragma intrinsic(__rdtsc) #endif + +#define TIER0_DLL_EXPORT +#define COMPILER_MSVC + +//----------------------------------------------------------------------------- +// Set up platform defines. +//----------------------------------------------------------------------------- +#ifdef _WIN32 +#define IsPlatformLinux() 0 +#define IsPlatformPosix() 0 +#define IsPlatformOSX() 0 +#define IsOSXOpenGL() 0 +#define IsPlatformPS3() 0 +#define IsPlatformPS3_PPU() 0 +#define IsPlatformPS3_SPU() 0 +#define PLATFORM_WINDOWS 1 +#define PLATFORM_OPENGL 0 + +#ifndef _X360 +#define IsPlatformX360() 0 +#define IsPlatformWindowsPC() 1 +#define PLATFORM_WINDOWS_PC 1 + +#ifdef _WIN64 +#define IsPlatformWindowsPC64() 1 +#define IsPlatformWindowsPC32() 0 +#define PLATFORM_WINDOWS_PC64 1 +#else +#define IsPlatformWindowsPC64() 0 +#define IsPlatformWindowsPC32() 1 +#define PLATFORM_WINDOWS_PC32 1 +#endif + +#else // _X360 + +#define IsPlatformWindowsPC() 0 +#define IsPlatformWindowsPC64() 0 +#define IsPlatformWindowsPC32() 0 +#define IsPlatformX360() 1 +#define PLATFORM_X360 1 + +#endif // _X360 +#elif defined(_PS3) + +// Adding IsPlatformOpenGL() to help fix a bunch of code that was using IsPosix() to infer if the DX->GL translation layer was being used. +#if defined( DX_TO_GL_ABSTRACTION ) +#define IsPlatformOpenGL() true +#else +#define IsPlatformOpenGL() false +#endif + +#define IsPlatformX360() 0 +#define IsPlatformPS3() 1 +#ifdef SPU +#define IsPlatformPS3_PPU() 0 +#define IsPlatformPS3_SPU() 1 +#else +#define IsPlatformPS3_PPU() 1 +#define IsPlatformPS3_SPU() 0 +#endif +#define IsPlatformWindowsPC() 0 +#define IsPlatformWindowsPC64() 0 +#define IsPlatformWindowsPC32() 0 +#define IsPlatformPosix() 1 +#define PLATFORM_POSIX 1 +#define PLATFORM_OPENGL 0 + +#define IsPlatformLinux() 0 +#define IsPlatformOSX() 0 +#define IsOSXOpenGL() 0 + + +#elif defined(POSIX) +#define IsPlatformX360() 0 +#define IsPlatformPS3() 0 +#define IsPlatformPS3_PPU() 0 +#define IsPlatformPS3_SPU() 0 +#define IsPlatformWindowsPC() 0 +#define IsPlatformWindowsPC64() 0 +#define IsPlatformWindowsPC32() 0 +#define IsPlatformPosix() 1 +#define PLATFORM_POSIX 1 + +#if defined( LINUX ) && !defined( OSX ) // for havok we define both symbols, so don't let the osx build wander down here +#define IsPlatformLinux() 1 +#define IsPlatformOSX() 0 +#define IsOSXOpenGL() 0 +#define PLATFORM_OPENGL 0 +#define PLATFORM_LINUX 1 +#elif defined ( OSX ) +#define IsPlatformLinux() 0 +#define IsPlatformOSX() 1 +#define IsOSXOpenGL() 1 +#define PLATFORM_OSX 1 +#define PLATFORM_OPENGL 1 +#else +#define IsPlatformLinux() 0 +#define IsPlatformOSX() 0 +#define IsOSXOpenGL() 0 +#define PLATFORM_OPENGL 0 +#endif + +#else +#error +#endif + +//----------------------------------------------------------------------------- +// Old-school defines we're going to support since much code uses them +//----------------------------------------------------------------------------- +#if CROSS_PLATFORM_VERSION < 2 + +#define IsLinux() IsPlatformLinux() +#define IsOSX() IsPlatformOSX() +#define IsPosix() IsPlatformPosix() +#define IsX360() IsPlatformX360() +#define IsPS3() IsPlatformPS3() + +// Setup platform defines. +#ifdef COMPILER_MSVC +#define MSVC 1 +#endif + +#ifdef COMPILER_GCC +#define GNUC 1 +#endif + +#if defined( _WIN32 ) +#define _WINDOWS 1 +#endif + +#ifdef PLATFORM_WINDOWS_PC +#define IS_WINDOWS_PC 1 +#endif + +#endif // CROSS_PLATFORM_VERSION < 2 + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- inline uint64_t Plat_Rdtsc() { #if defined( _X360 ) @@ -31,7 +170,213 @@ inline uint64_t Plat_Rdtsc() #endif } +//----------------------------------------------------------------------------- +// Stack-based allocation related helpers +//----------------------------------------------------------------------------- +#if defined( COMPILER_GCC ) || defined( COMPILER_SNC ) + +#define stackalloc( _size ) alloca( ALIGN_VALUE( _size, 16 ) ) + +#ifdef PLATFORM_OSX +#define mallocsize( _p ) ( malloc_size( _p ) ) +#else +#define mallocsize( _p ) ( malloc_usable_size( _p ) ) +#endif + +#elif defined ( COMPILER_MSVC ) + +#define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) +#define mallocsize( _p ) ( _msize( _p ) ) + +#endif + +//----------------------------------------------------------------------------- +// Various compiler-specific keywords +//----------------------------------------------------------------------------- +#ifdef COMPILER_MSVC + +#ifdef FORCEINLINE +#undef FORCEINLINE +#endif +#define STDCALL __stdcall +#ifndef FASTCALL +#define FASTCALL __fastcall +#endif +#define FORCEINLINE __forceinline +#define FORCEINLINE_TEMPLATE __forceinline +#define NULLTERMINATED __nullterminated + +// This can be used to ensure the size of pointers to members when declaring +// a pointer type for a class that has only been forward declared +#define SINGLE_INHERITANCE __single_inheritance +#define MULTIPLE_INHERITANCE __multiple_inheritance +#define EXPLICIT explicit +#define NO_VTABLE __declspec( novtable ) + +// gcc doesn't allow storage specifiers on explicit template instatiation, but visual studio needs them to avoid link errors. +#define TEMPLATE_STATIC static + +// Used for dll exporting and importing +#define DLL_EXPORT extern "C" __declspec( dllexport ) +#define DLL_IMPORT extern "C" __declspec( dllimport ) + +// Can't use extern "C" when DLL exporting a class +#define DLL_CLASS_EXPORT __declspec( dllexport ) +#define DLL_CLASS_IMPORT __declspec( dllimport ) + +// Can't use extern "C" when DLL exporting a global +#define DLL_GLOBAL_EXPORT extern __declspec( dllexport ) +#define DLL_GLOBAL_IMPORT extern __declspec( dllimport ) + +// Pass hints to the compiler to prevent it from generating unnessecary / stupid code +// in certain situations. Several compilers other than MSVC also have an equivilent +// construct. +// +// Essentially the 'Hint' is that the condition specified is assumed to be true at +// that point in the compilation. If '0' is passed, then the compiler assumes that +// any subsequent code in the same 'basic block' is unreachable, and thus usually +// removed. +#define HINT(THE_HINT) __assume((THE_HINT)) + +// decls for aligning data +#define DECL_ALIGN(x) __declspec( align( x ) ) + +// GCC had a few areas where it didn't construct objects in the same order +// that Windows does. So when CVProfile::CVProfile() would access g_pMemAlloc, +// it would crash because the allocator wasn't initalized yet. +#define CONSTRUCT_EARLY + +#define SELECTANY __declspec(selectany) + +#define RESTRICT __restrict +#define RESTRICT_FUNC __declspec(restrict) +#define FMTFUNCTION( a, b ) +#define NOINLINE + +#if !defined( NO_THREAD_LOCAL ) +#define DECL_THREAD_LOCAL __declspec(thread) +#endif + +#define DISABLE_VC_WARNING( x ) __pragma(warning(disable:4310) ) +#define DEFAULT_VC_WARNING( x ) __pragma(warning(default:4310) ) + + +#elif defined ( COMPILER_GCC ) || defined( COMPILER_SNC ) + +#if defined( COMPILER_SNC ) || defined( PLATFORM_64BITS ) +#define STDCALL +#define __stdcall +#elif (CROSS_PLATFORM_VERSION >= 1) && !defined( PLATFORM_64BITS ) && !defined( COMPILER_PS3 ) +#define STDCALL __attribute__ ((__stdcall__)) +#else +#define STDCALL +#define __stdcall __attribute__ ((__stdcall__)) +#endif + +#define FASTCALL +#ifdef _LINUX_DEBUGGABLE +#define FORCEINLINE +#else +#ifdef _PS3 + // [IESTYN 7/29/2010] As of SDK 3.4.0, this causes bad code generation in NET_Tick::ReadFromBuffer in netmessages.cpp, + // which caused (seeming) random network packet corruption. It probably causes other bugs too. +#define FORCEINLINE inline /* __attribute__ ((always_inline)) */ +#else +#define FORCEINLINE inline __attribute__ ((always_inline)) +#endif +#endif + +// GCC 3.4.1 has a bug in supporting forced inline of templated functions +// this macro lets us not force inlining in that case +#define FORCEINLINE_TEMPLATE inline +#define SINGLE_INHERITANCE +#define MULTIPLE_INHERITANCE +#define EXPLICIT +#define NO_VTABLE + +#define NULLTERMINATED + +#if defined( COMPILER_SNC ) +#define TEMPLATE_STATIC static +#else +#define TEMPLATE_STATIC +#endif + + // Used for dll exporting and importing +#ifdef COMPILER_SNC +#define DLL_DECLARATION_DEFAULT_VISIBILITY +#else +#define DLL_DECLARATION_DEFAULT_VISIBILITY __attribute__ ((visibility("default"))) +#endif +#define DLL_EXPORT extern "C" DLL_DECLARATION_DEFAULT_VISIBILITY +#define DLL_IMPORT extern "C" + +// Can't use extern "C" when DLL exporting a class +#if !defined( _PS3 ) && !defined( LINUX ) && !defined( PLATFORM_64BITS ) +#define __stdcall __attribute__ ((__stdcall__)) +#endif +#define DLL_CLASS_EXPORT DLL_DECLARATION_DEFAULT_VISIBILITY +#define DLL_CLASS_IMPORT + +// Can't use extern "C" when DLL exporting a global +#define DLL_GLOBAL_EXPORT DLL_DECLARATION_DEFAULT_VISIBILITY +#define DLL_GLOBAL_IMPORT extern + +#define HINT(THE_HINT) __builtin_expect( THE_HINT, 1 ) +#define DECL_ALIGN(x) __attribute__( ( aligned( x ) ) ) +#define CONSTRUCT_EARLY __attribute__((init_priority(101))) +#define SELECTANY __attribute__((weak)) +#if defined(__clang__) + // [will] - clang is very strict about restrict, and we have a bunch of core functions that use the keyword which have issues with it. + // This seemed to be a cleaner solution for now so we don't have to fill core code with tons of #ifdefs. +#define RESTRICT +#else +#define RESTRICT __restrict__ +#endif +#define RESTRICT_FUNC RESTRICT_FUNC_NOT_YET_DEFINED_FOR_THIS_COMPILER +#define FMTFUNCTION( fmtargnumber, firstvarargnumber ) __attribute__ (( format( printf, fmtargnumber, firstvarargnumber ))) +#define NOINLINE __attribute__ ((noinline)) + +#if !defined( NO_THREAD_LOCAL ) +#define DECL_THREAD_LOCAL __thread +#endif + +#define DISABLE_VC_WARNING( x ) +#define DEFAULT_VC_WARNING( x ) + +#else + +#define DECL_ALIGN(x) /* */ +#define SELECTANY static + +#endif + +//----------------------------------------------------------------------------- +// DLL export for platform utilities +//----------------------------------------------------------------------------- +#ifndef STATIC_TIER0 + +#ifdef TIER0_DLL_EXPORT +#define PLATFORM_INTERFACE DLL_EXPORT +#define PLATFORM_OVERLOAD DLL_GLOBAL_EXPORT +#define PLATFORM_CLASS DLL_CLASS_EXPORT +#else +#define PLATFORM_INTERFACE DLL_IMPORT +#define PLATFORM_OVERLOAD DLL_GLOBAL_IMPORT +#define PLATFORM_CLASS DLL_CLASS_IMPORT +#endif + +#else // BUILD_AS_DLL + +#define PLATFORM_INTERFACE extern +#define PLATFORM_OVERLOAD +#define PLATFORM_CLASS + +#endif // BUILD_AS_DLL + +//----------------------------------------------------------------------------- // Processor Information: +//----------------------------------------------------------------------------- struct CPUInformation { int m_Size; // Size of this structure, for forward compatability. diff --git a/r5dev/tier0/valve_off.h b/r5dev/tier0/valve_off.h new file mode 100644 index 00000000..6d8b1957 --- /dev/null +++ b/r5dev/tier0/valve_off.h @@ -0,0 +1,33 @@ +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: This turns off all Valve-specific #defines. Because we sometimes +// call external include files from inside .cpp files, we need to +// wrap those includes like this: +// #include "tier0/valve_off.h" +// #include +// #include "tier0/valve_on.h" +// +// $NoKeywords: $ +//=============================================================================// + + +#ifdef STEAM + +//----------------------------------------------------------------------------- +// Unicode-related #defines (see wchartypes.h) +//----------------------------------------------------------------------------- +#undef char + + +//----------------------------------------------------------------------------- +// Memory-related #defines +//----------------------------------------------------------------------------- +#undef malloc +#undef realloc +#undef _expand +#undef free + +#endif // STEAM + +// Allow long to be used in 3rd-party headers +#undef long \ No newline at end of file diff --git a/r5dev/tier0/valve_on.h b/r5dev/tier0/valve_on.h new file mode 100644 index 00000000..4dc3b4b0 --- /dev/null +++ b/r5dev/tier0/valve_on.h @@ -0,0 +1,37 @@ +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: This turns on all Valve-specific #defines. Because we sometimes +// call external include files from inside .cpp files, we need to +// wrap those includes like this: +// #include "tier0/valve_off.h" +// #include +// #include "tier0/valve_on.h" +// +// $NoKeywords: $ +//=============================================================================// + + +#ifdef STEAM +//----------------------------------------------------------------------------- +// Unicode-related #defines (see wchartypes.h) +//----------------------------------------------------------------------------- +#ifdef ENFORCE_WCHAR +#define char DontUseChar_SeeWcharOn.h +#endif + + +//----------------------------------------------------------------------------- +// Memory-related #defines +//----------------------------------------------------------------------------- +#define malloc( cub ) HEY_DONT_USE_MALLOC_USE_PVALLOC +#define realloc( pvOld, cub ) HEY_DONT_USE_REALLOC_USE_PVREALLOC +#define _expand( pvOld, cub ) HEY_DONT_USE_EXPAND_USE_PVEXPAND +#define free( pv ) HEY_DONT_USE_FREE_USE_FREEPV + +#endif + + +// Long is evil because it's treated differently by different compilers +#ifdef DISALLOW_USE_OF_LONG +#define long long_is_the_devil_stop_using_it_use_int32_or_int64 +#endif diff --git a/r5dev/tier0/wchartypes.h b/r5dev/tier0/wchartypes.h new file mode 100644 index 00000000..0568a9c5 --- /dev/null +++ b/r5dev/tier0/wchartypes.h @@ -0,0 +1,115 @@ +//========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: All of our code is completely Unicode. Instead of char, you should +// use wchar, uint8, or char8, as explained below. +// +// $NoKeywords: $ +//=============================================================================// + + +#ifndef WCHARTYPES_H +#define WCHARTYPES_H +#ifdef _WIN32 +#pragma once +#endif + +#ifdef _INC_TCHAR +#error ("Must include tier0 type headers before tchar.h") +#endif + +// Temporarily turn off Valve defines +#include "tier0/valve_off.h" + +#if !defined(_WCHAR_T_DEFINED) && !defined( __WCHAR_TYPE__ ) && !defined(GNUC) +typedef unsigned short wchar_t; +#define _WCHAR_T_DEFINED +#endif + +// char8 +// char8 is equivalent to char, and should be used when you really need a char +// (for example, when calling an external function that's declared to take +// chars). +typedef char char8; + +// uint8 +// uint8 is equivalent to byte (but is preferred over byte for clarity). Use this +// whenever you mean a byte (for example, one byte of a network packet). +typedef unsigned char uint8; +typedef unsigned char BYTE; +typedef unsigned char byte; + +// wchar +// wchar is a single character of text (currently 16 bits, as all of our text is +// Unicode). Use this whenever you mean a piece of text (for example, in a string). +typedef wchar_t wchar; +//typedef char wchar; + +// __WFILE__ +// This is a Unicode version of __FILE__ +#define WIDEN2(x) L ## x +#define WIDEN(x) WIDEN2(x) +#define __WFILE__ WIDEN(__FILE__) + +#ifdef STEAM +#ifndef _UNICODE +#define FORCED_UNICODE +#endif +#define _UNICODE +#endif + +#if defined( POSIX ) +#define _tcsstr strstr +#define _tcsicmp stricmp +#define _tcscmp strcmp +#define _tcscpy strcpy +#define _tcsncpy strncpy +#define _tcsrchr strrchr +#define _tcslen strlen +#define _tfopen fopen +#define _stprintf sprintf +#define _ftprintf fprintf +#define _vsntprintf _vsnprintf +#define _tprintf printf +#define _sntprintf _snprintf +#define _T(s) s +#else +#include +#endif + +#if defined(_UNICODE) +typedef wchar tchar; +#define tstring wstring +#define __TFILE__ __WFILE__ +#define TCHAR_IS_WCHAR +#else +typedef char tchar; +#define tstring string +#define __TFILE__ __FILE__ +#define TCHAR_IS_CHAR +#endif + +#ifdef FORCED_UNICODE +#undef _UNICODE +#endif + +#if defined( _MSC_VER ) || defined( WIN32 ) +typedef wchar_t uchar16; +typedef unsigned int uchar32; +#else +typedef unsigned short uchar16; +typedef wchar_t uchar32; +#endif + +#ifdef GNUC +typedef unsigned short ucs2; // wchar_t is 4 bytes on sane os's, specially define a ucs2 type so we can read out localization files and the list saved as 2 byte wchar (or ucs16 Matt tells me) +#elif defined(_MSC_VER) +typedef wchar_t ucs2; // under windows wchar_t is ucs2 +#endif + +// Turn valve defines back on +#include "tier0/valve_on.h" + + +#endif // WCHARTYPES + + diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index 38731ddd..0c94f706 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -8,8 +8,6 @@ #include "tier0/tslist.h" #include "tier1/IConVar.h" #include "tier1/cvar.h" -#include "engine/sys_utils.h" -#include "engine/sys_dll2.h" #include "mathlib/bits.h" #include "vstdlib/callback.h" diff --git a/r5dev/tier1/cmd.cpp b/r5dev/tier1/cmd.cpp index 4446aed0..fd9ddcbc 100644 --- a/r5dev/tier1/cmd.cpp +++ b/r5dev/tier1/cmd.cpp @@ -9,7 +9,6 @@ #include "tier1/cmd.h" #include "tier1/cvar.h" #include "vstdlib/callback.h" -#include "engine/sys_utils.h" //----------------------------------------------------------------------------- // Purpose: returns max command lenght diff --git a/r5dev/vphysics/QHull.cpp b/r5dev/vphysics/QHull.cpp index f1decd0f..0e47a65f 100644 --- a/r5dev/vphysics/QHull.cpp +++ b/r5dev/vphysics/QHull.cpp @@ -1,7 +1,6 @@ #include "core/stdafx.h" #include "core/logdef.h" #include "vphysics/QHull.h" -#include "engine/sys_utils.h" #ifndef DEDICATED #include "gameui/IConsole.h" #endif // !DEDICATED diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 445b286f..52439160 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -11,7 +11,6 @@ #include "tier1/cvar.h" #include "mathlib/adler32.h" #include "mathlib/crc32.h" -#include "engine/sys_utils.h" #include "vpklib/packedstore.h" //----------------------------------------------------------------------------- diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index 1d4f61d4..a24d03eb 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -88,6 +88,7 @@ + @@ -407,12 +408,17 @@ + + + + + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index 6db30db1..658bba73 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -495,6 +495,9 @@ sdk\engine + + sdk\tier0 + @@ -1472,6 +1475,21 @@ sdk\engine + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index db0bfa9e..8aac8560 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -397,12 +397,17 @@ + + + + + @@ -496,6 +501,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 9c02c973..6336be98 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1092,6 +1092,21 @@ sdk\public\include + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + @@ -1337,6 +1352,9 @@ sdk\engine + + sdk\tier0 + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 77f4d361..6f218a8c 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -95,6 +95,7 @@ + @@ -426,11 +427,16 @@ + + + + + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 118a288b..b2a6bf5b 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -525,6 +525,9 @@ sdk\engine + + sdk\tier0 + @@ -1535,6 +1538,21 @@ sdk\public\include + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + + + sdk\tier0 + diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index a367e386..8a035892 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -13,7 +13,6 @@ #endif // !DEDICATED #include "engine/client/client.h" #include "engine/net.h" -#include "engine/sys_utils.h" #include "rtech/rtech_game.h" #include "rtech/rtech_utils.h" #include "filesystem/basefilesystem.h" diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index cbb1582e..05ec584d 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -7,7 +7,6 @@ #include "windows/input.h" #include "gameui/IConsole.h" #include "gameui/IBrowser.h" -#include "engine/sys_utils.h" #include "inputsystem/inputsystem.h" #include "public/include/stb_image.h"