From 49238f104c99d29113fac45ea28f1f35d0ba0d37 Mon Sep 17 00:00:00 2001 From: Pirulax Date: Wed, 18 Sep 2024 18:54:33 +0200 Subject: [PATCH] Fix bad performance of script command tracing (#751) * Fix bad performance of script command tracing * Update source/game_sa/Scripts/TheScripts.h Co-authored-by: yukani --------- Co-authored-by: yukani --- premake5.lua | 4 ++++ source/game_sa/Scripts/RunningScript.cpp | 8 +++++++- source/premake5.lua | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/premake5.lua b/premake5.lua index 03672f124d..bfa7cc9697 100644 --- a/premake5.lua +++ b/premake5.lua @@ -8,6 +8,10 @@ Options and Actions --]] +newoption { + trigger = "script-tracing", + description = "Enable script command trace logging (Slow!)" +} newoption { trigger = "outdir", value = "path", diff --git a/source/game_sa/Scripts/RunningScript.cpp b/source/game_sa/Scripts/RunningScript.cpp index a5af94f359..1e9dba2c79 100644 --- a/source/game_sa/Scripts/RunningScript.cpp +++ b/source/game_sa/Scripts/RunningScript.cpp @@ -933,7 +933,13 @@ OpcodeResult CRunningScript::ProcessOneCommand() { }; } op = { CTheScripts::Read2BytesFromScript(m_IP) }; - SPDLOG_LOGGER_TRACE(logger, "[{}][IP: {:#x} + {:#x}]: {} [{:#x}]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command), (size_t)op.command); +#ifdef NOTSA_SCRIPT_TRACING + // snprintf is faster (in debug at least) - Gotta stick to it for now + char msg[4096]; + sprintf_s(msg, "[%s][IP: 0x%X + 0x%X]: %s [0x%X]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command).data(), (size_t)op.command); + SPDLOG_LOGGER_TRACE(logger, msg); + //SPDLOG_LOGGER_TRACE(logger, "[{}][IP: {:#x} + {:#x}]: {} [{:#x}]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command), (size_t)op.command); +#endif m_bNotFlag = op.notFlag; diff --git a/source/premake5.lua b/source/premake5.lua index b2591e4d50..5586c233cb 100644 --- a/source/premake5.lua +++ b/source/premake5.lua @@ -41,6 +41,10 @@ project "gta_sa_modern" "../libs/tracy/public", "../libs/json/include" } + + filter "options:script-tracing" + defines { "NOTSA_SCRIPT_TRACING" } + filter {} defines { "NOMINMAX",