From 34f939db3709b9599ee547b9111690b774676dee Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 05:51:15 -0400 Subject: [PATCH 01/34] Add SetPaused to timer class --- .../mods/deathmatch/logic/lua/CLuaTimer.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp index f632a1a237..387dd53140 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp @@ -23,6 +23,7 @@ CLuaTimer::CLuaTimer(const CLuaFunctionRef& iLuaFunction, const CLuaArguments& A m_uiRepeats = 1; m_iLuaFunction = iLuaFunction; m_Arguments = Arguments; + m_bPaused = false; } CLuaTimer::~CLuaTimer() @@ -64,9 +65,33 @@ void CLuaTimer::ExecuteTimer(CLuaMain* pLuaMain) } } +void CLuaTimer::SetPaused(bool bPaused) +{ + if (bPaused == IsPaused()) + return; + + CTickCount llTimeRemaining = GetTimeLeft(); + if (bPaused) + { + m_llPausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining; + } + else + { + CTickCount llCurrentTime = CTickCount::Now(); + CTickCount llNewStartTime = llCurrentTime - (m_llDelay - llTimeRemaining); + SetStartTime(llNewStartTime); + } + m_bPaused = bPaused; +} + + CTickCount CLuaTimer::GetTimeLeft() { CTickCount llCurrentTime = CTickCount::Now(); CTickCount llTimeLeft = m_llStartTime + m_llDelay - llCurrentTime; + + if (IsPaused()) + return m_llPausedRemainingTime; + return llTimeLeft.ToLongLong() < 0LL ? CTickCount(0LL) : llTimeLeft; } From 66440b7c17ff3355b53a47e9c0e60a9b28a7cfa5 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:00:58 -0400 Subject: [PATCH 02/34] Add pause variables to class --- Shared/mods/deathmatch/logic/lua/CLuaTimer.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h index 62bb3c97a5..b63aad1f75 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h @@ -35,6 +35,8 @@ class CLuaTimer unsigned int GetRepeats() const { return m_uiRepeats; }; void SetRepeats(unsigned int uiRepeats) { m_uiRepeats = uiRepeats; } + bool IsPaused() const { return m_bPaused; }; + void SetPaused(bool bPaused); void ExecuteTimer(class CLuaMain* pLuaMain); @@ -45,10 +47,12 @@ class CLuaTimer void SetLuaDebugInfo(const SLuaDebugInfo& luaDebugInfo) { m_LuaDebugInfo = luaDebugInfo; } private: + bool m_bPaused; CLuaFunctionRef m_iLuaFunction; CLuaArguments m_Arguments; CTickCount m_llStartTime; CTickCount m_llDelay; + CTickCount m_llPausedRemainingTime; unsigned int m_uiRepeats; uint m_uiScriptID; SLuaDebugInfo m_LuaDebugInfo; From 799913cdfda927a758032491225374ba69b6e512 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:10:43 -0400 Subject: [PATCH 03/34] Add new functions "pauseTimer" and "isTimerPaused" --- .../logic/luadefs/CLuaTimerDefs.cpp | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index 49c83bd576..30bfcf3db2 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -17,6 +17,7 @@ void CLuaTimerDefs::LoadFunctions() { constexpr static const std::pair functions[]{ {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, + {"pauseTimer", PauseTimer}, {"isTimerPaused", IsTimerPaused}, {"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails}, }; @@ -34,6 +35,9 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "reset", "resetTimer"); lua_classfunction(luaVM, "isValid", "isTimer"); + lua_classfunction(luaVM, "isPaused", "isTimerPaused"); + lua_classfunction(luaVM, "setPaused", "pauseTimer"); + lua_classfunction(luaVM, "getDetails", "getTimerDetails"); lua_classvariable(luaVM, "valid", NULL, "isTimer"); @@ -114,6 +118,60 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } +int CLuaTimerDefs::IsTimerPaused(lua_State* luaVM) +{ + // bool isTimerPaused ( timer theTimer ) + CLuaTimer* pLuaTimer; + + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(pLuaTimer); + + if (!argStream.HasErrors()) + { + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (luaMain) + { + bool bIsPaused = pLuaTimer->IsPaused(); + lua_pushboolean(luaVM, bIsPaused); + return 1; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return 1; +} + + +int CLuaTimerDefs::PauseTimer(lua_State* luaVM) +{ + // bool pauseTimer ( timer theTimer, bool paused ) + CLuaTimer* pLuaTimer; + bool bPaused; + + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(pLuaTimer); + argStream.ReadBool(bPaused); + + if (!argStream.HasErrors()) + { + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (luaMain) + { + luaMain->GetTimerManager()->PauseTimer(pLuaTimer, bPaused); + lua_pushboolean(luaVM, true); + return 1; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return 1; +} + + int CLuaTimerDefs::ResetTimer(lua_State* luaVM) { // bool resetTimer ( timer theTimer ) From 005ffe75090eabf130d0a7507aff0cdeaf94680a Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:11:34 -0400 Subject: [PATCH 04/34] Add new timer function defs - pauseTimer - isTimerPaused --- Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index fd37e2aaa4..b60d02989f 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -20,8 +20,10 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(SetTimer); LUA_DECLARE(KillTimer); + LUA_DECLARE(IsTimerPaused); + LUA_DECLARE(PauseTimer); LUA_DECLARE(ResetTimer); LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); LUA_DECLARE(GetTimerDetails); -}; \ No newline at end of file +}; From 51156482711a1ed434f262984b9c16d7e72045e3 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:13:49 -0400 Subject: [PATCH 05/34] Add "PauseTimer" to CLuaTimerManager --- .../deathmatch/logic/lua/CLuaTimerManager.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index fbd86eccaf..499bdb2ece 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -26,7 +26,11 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain) // Use a separate queue to avoid trouble // What kind of problems are we trying to avoid? Doing a copy each frame isn't quite efficient for (CFastList::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); ++iter) - m_ProcessQueue.push_back(*iter); + { + if (!(**iter).IsPaused()) + m_ProcessQueue.push_back(*iter); + } + while (!m_ProcessQueue.empty()) { @@ -113,6 +117,15 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } +void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) +{ + assert(pLuaTimer); + + pLuaTimer->SetPaused(bPaused); + if (!bPaused) + ListRemove(m_ProcessQueue, pLuaTimer); +} + void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer) { assert(pLuaTimer); From 69e2aee37f70b571386f4d834ab82d8094a0d219 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:14:59 -0400 Subject: [PATCH 06/34] Def "PauseTimer" in CLuaTimerManager --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h index d9d2fc41f2..a4c123d207 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,6 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } + void PauseTimer(CLuaTimer* pLuaTimer, bool bPaused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From 746ad739ae284a0ae5f3d68f51eadc699b87618e Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:16:53 -0400 Subject: [PATCH 07/34] Adds pauseTimer() and isTimerPaused() --- .../logic/luadefs/CLuaTimerDefs.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index 401abcfd96..fb4c9d12c4 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -15,6 +15,7 @@ void CLuaTimerDefs::LoadFunctions() { constexpr static const std::pair functions[]{ {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, + {"pauseTimer", PauseTimer}, {"isTimerPaused", IsTimerPaused}, {"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails}, }; @@ -32,6 +33,9 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "reset", "resetTimer"); lua_classfunction(luaVM, "isValid", "isTimer"); + lua_classfunction(luaVM, "isPaused", "isTimerPaused"); + lua_classfunction(luaVM, "setPaused", "pauseTimer"); + lua_classfunction(luaVM, "getDetails", "getTimerDetails"); lua_classvariable(luaVM, "valid", NULL, "isTimer"); @@ -111,6 +115,58 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } +int CLuaTimerDefs::IsTimerPaused(lua_State* luaVM) +{ + // bool isTimerPaused ( timer theTimer ) + CLuaTimer* pLuaTimer; + + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(pLuaTimer); + + if (!argStream.HasErrors()) + { + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (luaMain) + { + bool bIsPaused = pLuaTimer->IsPaused(); + lua_pushboolean(luaVM, bIsPaused); + return 1; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return 1; +} + +int CLuaTimerDefs::PauseTimer(lua_State* luaVM) +{ + // bool pauseTimer ( timer theTimer, bool paused ) + CLuaTimer* pLuaTimer; + bool bPaused; + + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(pLuaTimer); + argStream.ReadBool(bPaused); + + if (!argStream.HasErrors()) + { + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (luaMain) + { + luaMain->GetTimerManager()->PauseTimer(pLuaTimer, bPaused); + lua_pushboolean(luaVM, true); + return 1; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return 1; +} + int CLuaTimerDefs::ResetTimer(lua_State* luaVM) { // bool resetTimer ( timer theTimer ) From 7400bb9aff26e89a05e6b3e1bc6c32a524e0c3c9 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:18:30 -0400 Subject: [PATCH 08/34] Add new timer function defs --- Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index 671a329b28..2ca93f8ad9 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -20,6 +20,8 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(SetTimer); LUA_DECLARE(KillTimer); + LUA_DECLARE(IsTimerPaused); + LUA_DECLARE(PauseTimer); LUA_DECLARE(ResetTimer); LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); From ec73d9192a29f5c22e7fb6274a63044112d415d5 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:19:44 -0400 Subject: [PATCH 09/34] Add "PauseTimer" to CLuaTimerManager --- .../mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 317de7f16d..1a6a5c80ab 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -21,7 +21,10 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain) // Use a separate queue to avoid trouble for (CFastList::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); iter++) - m_ProcessQueue.push_back(*iter); + { + if (!(**iter).IsPaused()) + m_ProcessQueue.push_back(*iter); + } while (!m_ProcessQueue.empty()) { @@ -108,6 +111,15 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } +void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) +{ + assert(pLuaTimer); + + pLuaTimer->SetPaused(bPaused); + if (!bPaused) + ListRemove(m_ProcessQueue, pLuaTimer); +} + void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer) { assert(pLuaTimer); From 5372afa70bb57864a66bad4908fe8f3b72285921 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:20:18 -0400 Subject: [PATCH 10/34] Def "PauseTimer" in CLuaTimerManager --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h index 055b644fcb..77ca73e382 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,6 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } + void PauseTimer(CLuaTimer* pLuaTimer, bool bPaused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From 968bd033c29afa40a0ca5c187542d89e0513636d Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:24:39 -0400 Subject: [PATCH 11/34] fix typo --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 1a6a5c80ab..5d2b0c2bf9 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -116,7 +116,7 @@ void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) assert(pLuaTimer); pLuaTimer->SetPaused(bPaused); - if (!bPaused) + if (bPaused) ListRemove(m_ProcessQueue, pLuaTimer); } From 07da2bc695538ed2cb6141f268233ff2caa67647 Mon Sep 17 00:00:00 2001 From: justn <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:26:16 -0400 Subject: [PATCH 12/34] fix typo --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 499bdb2ece..e4a8d55fc1 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -122,7 +122,7 @@ void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) assert(pLuaTimer); pLuaTimer->SetPaused(bPaused); - if (!bPaused) + if (bPaused) ListRemove(m_ProcessQueue, pLuaTimer); } From d314dabccd925c1d6364b903924000fe227fbceb Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:53:15 -0400 Subject: [PATCH 13/34] A few minor adjustments --- Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp index 387dd53140..5e3c5c9e8f 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp @@ -23,7 +23,7 @@ CLuaTimer::CLuaTimer(const CLuaFunctionRef& iLuaFunction, const CLuaArguments& A m_uiRepeats = 1; m_iLuaFunction = iLuaFunction; m_Arguments = Arguments; - m_bPaused = false; + m_Paused = false; } CLuaTimer::~CLuaTimer() @@ -73,7 +73,7 @@ void CLuaTimer::SetPaused(bool bPaused) CTickCount llTimeRemaining = GetTimeLeft(); if (bPaused) { - m_llPausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining; + m_PausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining; } else { @@ -81,17 +81,15 @@ void CLuaTimer::SetPaused(bool bPaused) CTickCount llNewStartTime = llCurrentTime - (m_llDelay - llTimeRemaining); SetStartTime(llNewStartTime); } - m_bPaused = bPaused; + m_Paused = bPaused; } - CTickCount CLuaTimer::GetTimeLeft() { - CTickCount llCurrentTime = CTickCount::Now(); - CTickCount llTimeLeft = m_llStartTime + m_llDelay - llCurrentTime; - if (IsPaused()) - return m_llPausedRemainingTime; + return m_PausedRemainingTime; + CTickCount llCurrentTime = CTickCount::Now(); + CTickCount llTimeLeft = m_llStartTime + m_llDelay - llCurrentTime; return llTimeLeft.ToLongLong() < 0LL ? CTickCount(0LL) : llTimeLeft; } From 22a417744a7906ab28c9b1408861938c41ab3ac6 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:54:12 -0400 Subject: [PATCH 14/34] Minor adjustments #2 --- Shared/mods/deathmatch/logic/lua/CLuaTimer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h index b63aad1f75..31ee32022b 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h @@ -17,7 +17,7 @@ class CLuaTimer; #include "lua/LuaCommon.h" #include "lua/CLuaArguments.h" -#define LUA_TIMER_MIN_INTERVAL 0 +#define LUA_TIMER_MIN_INTERVAL 0 class CLuaTimer { @@ -35,7 +35,7 @@ class CLuaTimer unsigned int GetRepeats() const { return m_uiRepeats; }; void SetRepeats(unsigned int uiRepeats) { m_uiRepeats = uiRepeats; } - bool IsPaused() const { return m_bPaused; }; + bool IsPaused() const noexcept { return m_Paused; }; void SetPaused(bool bPaused); void ExecuteTimer(class CLuaMain* pLuaMain); @@ -47,12 +47,12 @@ class CLuaTimer void SetLuaDebugInfo(const SLuaDebugInfo& luaDebugInfo) { m_LuaDebugInfo = luaDebugInfo; } private: - bool m_bPaused; + bool m_Paused; CLuaFunctionRef m_iLuaFunction; CLuaArguments m_Arguments; CTickCount m_llStartTime; CTickCount m_llDelay; - CTickCount m_llPausedRemainingTime; + CTickCount m_PausedRemainingTime; unsigned int m_uiRepeats; uint m_uiScriptID; SLuaDebugInfo m_LuaDebugInfo; From ca63aa41cff5ba9f50e0efd07795f6431ecca053 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:55:44 -0400 Subject: [PATCH 15/34] Update to ArgumentParser --- .../logic/luadefs/CLuaTimerDefs.cpp | 67 +++++-------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index 30bfcf3db2..d53bc3b1e4 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -16,9 +16,9 @@ void CLuaTimerDefs::LoadFunctions() { constexpr static const std::pair functions[]{ - {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, - {"pauseTimer", PauseTimer}, {"isTimerPaused", IsTimerPaused}, - {"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails}, + {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, + {"setTimerPaused", ArgumentParser},{"isTimerPaused", ArgumentParser}, + {"getTimers", GetTimers}, {"isTimer", IsTimer},{"getTimerDetails", GetTimerDetails}, }; // Add functions @@ -34,13 +34,10 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "destroy", "killTimer"); lua_classfunction(luaVM, "reset", "resetTimer"); lua_classfunction(luaVM, "isValid", "isTimer"); - - lua_classfunction(luaVM, "isPaused", "isTimerPaused"); - lua_classfunction(luaVM, "setPaused", "pauseTimer"); - lua_classfunction(luaVM, "getDetails", "getTimerDetails"); lua_classvariable(luaVM, "valid", NULL, "isTimer"); + lua_classvariable(luaVM, "paused", "setTimerPaused", "isTimerPaused"); lua_registerclass(luaVM, "Timer"); } @@ -118,60 +115,28 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } -int CLuaTimerDefs::IsTimerPaused(lua_State* luaVM) +bool CLuaTimerDefs::IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer) { // bool isTimerPaused ( timer theTimer ) - CLuaTimer* pLuaTimer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pLuaTimer); - - if (!argStream.HasErrors()) - { - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (luaMain) - { - bool bIsPaused = pLuaTimer->IsPaused(); - lua_pushboolean(luaVM, bIsPaused); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) + return false; - lua_pushboolean(luaVM, false); - return 1; + bool bIsPaused = pLuaTimer->IsPaused(); + return bIsPaused; } - -int CLuaTimerDefs::PauseTimer(lua_State* luaVM) +bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused) { // bool pauseTimer ( timer theTimer, bool paused ) - CLuaTimer* pLuaTimer; - bool bPaused; + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) + return false; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pLuaTimer); - argStream.ReadBool(bPaused); - - if (!argStream.HasErrors()) - { - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (luaMain) - { - luaMain->GetTimerManager()->PauseTimer(pLuaTimer, bPaused); - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + luaMain->GetTimerManager()->SetTimerPaused(pLuaTimer, bPaused); + return true; } - int CLuaTimerDefs::ResetTimer(lua_State* luaVM) { // bool resetTimer ( timer theTimer ) From 36c6a9c100bcd4333c755cfef9e6023d18ae9577 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:56:29 -0400 Subject: [PATCH 16/34] Update to ArgumentParser --- Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index b60d02989f..ee9c146f9b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -20,10 +20,10 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(SetTimer); LUA_DECLARE(KillTimer); - LUA_DECLARE(IsTimerPaused); - LUA_DECLARE(PauseTimer); LUA_DECLARE(ResetTimer); LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); LUA_DECLARE(GetTimerDetails); + static bool IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer); + static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused); }; From a468297b584af3ca827f1ca78a4ef68a50d327f6 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:58:06 -0400 Subject: [PATCH 17/34] minor adjustment --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index e4a8d55fc1..b3764e44f4 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -27,10 +27,9 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain) // What kind of problems are we trying to avoid? Doing a copy each frame isn't quite efficient for (CFastList::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); ++iter) { - if (!(**iter).IsPaused()) + if (!(*iter)->IsPaused()) m_ProcessQueue.push_back(*iter); } - while (!m_ProcessQueue.empty()) { @@ -117,7 +116,7 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } -void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) +void CLuaTimerManager::SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused) { assert(pLuaTimer); From 850ae8eb4b575447dde81b68584df5e08681c478 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:59:27 -0400 Subject: [PATCH 18/34] Minor adjustment to function name --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h index a4c123d207..ed02fa4c43 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,7 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } - void PauseTimer(CLuaTimer* pLuaTimer, bool bPaused); + void SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From 769ae40ef8bfcf0e1cb979235efb584e23a693d9 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:00:49 -0400 Subject: [PATCH 19/34] Updated to ArgumentParser and changed function name --- .../logic/luadefs/CLuaTimerDefs.cpp | 68 +++++-------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index fb4c9d12c4..34fac9457d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -10,13 +10,14 @@ *****************************************************************************/ #include "StdInc.h" +#include void CLuaTimerDefs::LoadFunctions() { constexpr static const std::pair functions[]{ - {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, - {"pauseTimer", PauseTimer}, {"isTimerPaused", IsTimerPaused}, - {"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails}, + {"setTimer", SetTimer}, {"killTimer", KillTimer}, {"resetTimer", ResetTimer}, + {"setTimerPaused", ArgumentParser},{"isTimerPaused", ArgumentParser}, + {"getTimers", GetTimers}, {"isTimer", IsTimer}, {"getTimerDetails", GetTimerDetails}, }; // Add functions @@ -32,13 +33,10 @@ void CLuaTimerDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "destroy", "killTimer"); lua_classfunction(luaVM, "reset", "resetTimer"); lua_classfunction(luaVM, "isValid", "isTimer"); - - lua_classfunction(luaVM, "isPaused", "isTimerPaused"); - lua_classfunction(luaVM, "setPaused", "pauseTimer"); - lua_classfunction(luaVM, "getDetails", "getTimerDetails"); lua_classvariable(luaVM, "valid", NULL, "isTimer"); + lua_classvariable(luaVM, "paused", "setTimerPaused", "isTimerPaused"); lua_registerclass(luaVM, "Timer"); } @@ -115,56 +113,26 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } -int CLuaTimerDefs::IsTimerPaused(lua_State* luaVM) +bool CLuaTimerDefs::IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer) { // bool isTimerPaused ( timer theTimer ) - CLuaTimer* pLuaTimer; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pLuaTimer); + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) + return false; - if (!argStream.HasErrors()) - { - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (luaMain) - { - bool bIsPaused = pLuaTimer->IsPaused(); - lua_pushboolean(luaVM, bIsPaused); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + bool bIsPaused = pLuaTimer->IsPaused(); + return bIsPaused; } -int CLuaTimerDefs::PauseTimer(lua_State* luaVM) +bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused) { - // bool pauseTimer ( timer theTimer, bool paused ) - CLuaTimer* pLuaTimer; - bool bPaused; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pLuaTimer); - argStream.ReadBool(bPaused); - - if (!argStream.HasErrors()) - { - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (luaMain) - { - luaMain->GetTimerManager()->PauseTimer(pLuaTimer, bPaused); - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + // bool setTimerPaused ( timer theTimer, bool paused ) + CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); + if (!luaMain) + return false; - lua_pushboolean(luaVM, false); - return 1; + luaMain->GetTimerManager()->SetTimerPaused(pLuaTimer, bPaused); + return true; } int CLuaTimerDefs::ResetTimer(lua_State* luaVM) From 4ba657a47205cb30ed18753957fe35ca16077e09 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:01:22 -0400 Subject: [PATCH 20/34] Update to ArgumentParser --- Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index 2ca93f8ad9..ef15434717 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -20,10 +20,10 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(SetTimer); LUA_DECLARE(KillTimer); - LUA_DECLARE(IsTimerPaused); - LUA_DECLARE(PauseTimer); LUA_DECLARE(ResetTimer); LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); LUA_DECLARE(GetTimerDetails); + static bool IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer); + static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused); }; From aa3aaa9a0538f7c354b77c26753cf7a776e489b4 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:01:58 -0400 Subject: [PATCH 21/34] Minor adjustment to function name --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 5d2b0c2bf9..79c17828ae 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -22,7 +22,7 @@ void CLuaTimerManager::DoPulse(CLuaMain* pLuaMain) // Use a separate queue to avoid trouble for (CFastList::const_iterator iter = m_TimerList.begin(); iter != m_TimerList.end(); iter++) { - if (!(**iter).IsPaused()) + if (!(*iter)->IsPaused()) m_ProcessQueue.push_back(*iter); } @@ -111,7 +111,7 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } -void CLuaTimerManager::PauseTimer(CLuaTimer* pLuaTimer, bool bPaused) +void CLuaTimerManager::SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused) { assert(pLuaTimer); From 4b70ef267c102a7869227336ba82788532752a82 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:02:27 -0400 Subject: [PATCH 22/34] Minor adjustment to function name --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h index 77ca73e382..48a0232e2a 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,7 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } - void PauseTimer(CLuaTimer* pLuaTimer, bool bPaused); + void SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From 984132ea4327f92d5e2fe8a5108ab8f3e9c7be72 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:04:45 -0400 Subject: [PATCH 23/34] Removed hungarian notation --- Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp index 5e3c5c9e8f..bd0383222b 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.cpp @@ -23,7 +23,7 @@ CLuaTimer::CLuaTimer(const CLuaFunctionRef& iLuaFunction, const CLuaArguments& A m_uiRepeats = 1; m_iLuaFunction = iLuaFunction; m_Arguments = Arguments; - m_Paused = false; + m_paused = false; } CLuaTimer::~CLuaTimer() @@ -65,15 +65,15 @@ void CLuaTimer::ExecuteTimer(CLuaMain* pLuaMain) } } -void CLuaTimer::SetPaused(bool bPaused) +void CLuaTimer::SetPaused(bool paused) { - if (bPaused == IsPaused()) + if (paused == IsPaused()) return; CTickCount llTimeRemaining = GetTimeLeft(); - if (bPaused) + if (paused) { - m_PausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining; + m_pausedRemainingTime = llTimeRemaining.ToLongLong() == 0LL ? m_llDelay : llTimeRemaining; } else { @@ -81,13 +81,13 @@ void CLuaTimer::SetPaused(bool bPaused) CTickCount llNewStartTime = llCurrentTime - (m_llDelay - llTimeRemaining); SetStartTime(llNewStartTime); } - m_Paused = bPaused; + m_paused = paused; } CTickCount CLuaTimer::GetTimeLeft() { if (IsPaused()) - return m_PausedRemainingTime; + return m_pausedRemainingTime; CTickCount llCurrentTime = CTickCount::Now(); CTickCount llTimeLeft = m_llStartTime + m_llDelay - llCurrentTime; From c937f0e81dbb42f70587ba62084e282a83018858 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:06:09 -0400 Subject: [PATCH 24/34] Removed hungarian notation --- Shared/mods/deathmatch/logic/lua/CLuaTimer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h index 31ee32022b..9534c2c47f 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaTimer.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaTimer.h @@ -35,8 +35,8 @@ class CLuaTimer unsigned int GetRepeats() const { return m_uiRepeats; }; void SetRepeats(unsigned int uiRepeats) { m_uiRepeats = uiRepeats; } - bool IsPaused() const noexcept { return m_Paused; }; - void SetPaused(bool bPaused); + bool IsPaused() const noexcept { return m_paused; }; + void SetPaused(bool paused); void ExecuteTimer(class CLuaMain* pLuaMain); @@ -47,12 +47,12 @@ class CLuaTimer void SetLuaDebugInfo(const SLuaDebugInfo& luaDebugInfo) { m_LuaDebugInfo = luaDebugInfo; } private: - bool m_Paused; + bool m_paused; CLuaFunctionRef m_iLuaFunction; CLuaArguments m_Arguments; CTickCount m_llStartTime; CTickCount m_llDelay; - CTickCount m_PausedRemainingTime; + CTickCount m_pausedRemainingTime; unsigned int m_uiRepeats; uint m_uiScriptID; SLuaDebugInfo m_LuaDebugInfo; From 910b54fd013d8c76d23ae52fb8229b5a91f7d300 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:07:57 -0400 Subject: [PATCH 25/34] Removed hungarian notation & useless luaState --- .../deathmatch/logic/luadefs/CLuaTimerDefs.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index d53bc3b1e4..c3e0478c8b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -115,25 +115,19 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } -bool CLuaTimerDefs::IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer) +bool CLuaTimerDefs::IsTimerPaused(CLuaTimer* timer) noexcept { - // bool isTimerPaused ( timer theTimer ) - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (!luaMain) - return false; - - bool bIsPaused = pLuaTimer->IsPaused(); - return bIsPaused; + return timer->IsPaused(); } -bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused) +bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused) { - // bool pauseTimer ( timer theTimer, bool paused ) + // bool setTimerPaused ( timer theTimer, bool paused ) CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) return false; - luaMain->GetTimerManager()->SetTimerPaused(pLuaTimer, bPaused); + luaMain->GetTimerManager()->SetTimerPaused(timer, paused); return true; } From ead0c52337bf8e72650fd58c97969d38d54312d8 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:08:50 -0400 Subject: [PATCH 26/34] Removed hungarian notation & useless luaState --- Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index ee9c146f9b..abf1b725d6 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -24,6 +24,6 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); LUA_DECLARE(GetTimerDetails); - static bool IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer); - static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused); + static bool IsTimerPaused(CLuaTimer* timer) noexcept; + static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused); }; From aa1fdba8d7354ec9e4b30aacfcca63c921e951d9 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:09:43 -0400 Subject: [PATCH 27/34] Removed hungarian notations --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index b3764e44f4..0af771b289 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -116,13 +116,13 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } -void CLuaTimerManager::SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused) +void CLuaTimerManager::SetTimerPaused(CLuaTimer* timer, bool paused) { - assert(pLuaTimer); + assert(timer); - pLuaTimer->SetPaused(bPaused); - if (bPaused) - ListRemove(m_ProcessQueue, pLuaTimer); + timer->SetPaused(paused); + if (paused) + ListRemove(m_ProcessQueue, timer); } void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer) From 99da369cdf8fc60b3efaf6eb68a33ef05552ee3b Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:10:21 -0400 Subject: [PATCH 28/34] Removed hungarian notation --- Server/mods/deathmatch/logic/lua/CLuaTimerManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h index ed02fa4c43..d63e659147 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Server/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,7 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } - void SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused); + void SetTimerPaused(CLuaTimer* timer, bool paused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From 9e8bc21c0501b0838f127549556fcd0c01fc3712 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:11:51 -0400 Subject: [PATCH 29/34] Removed hungarian notation & useless luaState --- .../deathmatch/logic/luadefs/CLuaTimerDefs.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp index 34fac9457d..e0c8a96ba0 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.cpp @@ -113,25 +113,19 @@ int CLuaTimerDefs::KillTimer(lua_State* luaVM) return 1; } -bool CLuaTimerDefs::IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer) +bool CLuaTimerDefs::IsTimerPaused(CLuaTimer* timer) noexcept { - // bool isTimerPaused ( timer theTimer ) - CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); - if (!luaMain) - return false; - - bool bIsPaused = pLuaTimer->IsPaused(); - return bIsPaused; + return timer->IsPaused(); } -bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused) +bool CLuaTimerDefs::SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused) { // bool setTimerPaused ( timer theTimer, bool paused ) CLuaMain* luaMain = m_pLuaManager->GetVirtualMachine(luaVM); if (!luaMain) return false; - luaMain->GetTimerManager()->SetTimerPaused(pLuaTimer, bPaused); + luaMain->GetTimerManager()->SetTimerPaused(timer, paused); return true; } From 44a72f2d7bac02dfbb1b54ac6be5a22eeb733444 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:12:24 -0400 Subject: [PATCH 30/34] Removed hungarian notation & useless luaState --- Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h index ef15434717..db6cac48a9 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaTimerDefs.h @@ -24,6 +24,6 @@ class CLuaTimerDefs : public CLuaDefs LUA_DECLARE(GetTimers); LUA_DECLARE(IsTimer); LUA_DECLARE(GetTimerDetails); - static bool IsTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer); - static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* pLuaTimer, bool bPaused); + static bool IsTimerPaused(CLuaTimer* timer) noexcept; + static bool SetTimerPaused(lua_State* luaVM, CLuaTimer* timer, bool paused); }; From 76225a7f8c837b06dbf3226962fa1535c0ce3997 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:12:58 -0400 Subject: [PATCH 31/34] Removed hungarian notations --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp index 79c17828ae..4c70d03f04 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.cpp @@ -111,15 +111,16 @@ void CLuaTimerManager::RemoveAllTimers() m_pProcessingTimer = NULL; } -void CLuaTimerManager::SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused) +void CLuaTimerManager::SetTimerPaused(CLuaTimer* timer, bool paused) { - assert(pLuaTimer); + assert(timer); - pLuaTimer->SetPaused(bPaused); - if (bPaused) - ListRemove(m_ProcessQueue, pLuaTimer); + timer->SetPaused(paused); + if (paused) + ListRemove(m_ProcessQueue, timer); } + void CLuaTimerManager::ResetTimer(CLuaTimer* pLuaTimer) { assert(pLuaTimer); From 116085e6cc8bd41461d864d9b2df47204d2e0dd4 Mon Sep 17 00:00:00 2001 From: justns <39979049+jvstns@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:13:33 -0400 Subject: [PATCH 32/34] Removed hungarian notations --- Client/mods/deathmatch/logic/lua/CLuaTimerManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h index 48a0232e2a..c4f97d2626 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h +++ b/Client/mods/deathmatch/logic/lua/CLuaTimerManager.h @@ -36,7 +36,7 @@ class CLuaTimerManager void RemoveAllTimers(); unsigned long GetTimerCount() const { return m_TimerList.size(); } - void SetTimerPaused(CLuaTimer* pLuaTimer, bool bPaused); + void SetTimerPaused(CLuaTimer* timer, bool paused); void ResetTimer(CLuaTimer* pLuaTimer); CFastList::const_iterator IterBegin() { return m_TimerList.begin(); } From c12f678e4ca329364ce93ff1b7c2c14d17302155 Mon Sep 17 00:00:00 2001 From: TEDERIs Date: Tue, 24 Dec 2024 17:24:36 +0700 Subject: [PATCH 33/34] dxDrawModel3D lighting argument --- Client/game_sa/CRendererSA.cpp | 13 +++++++++++-- Client/game_sa/CRendererSA.h | 2 +- Client/mods/deathmatch/logic/CModelRenderer.cpp | 8 ++++---- Client/mods/deathmatch/logic/CModelRenderer.h | 8 +++++--- .../deathmatch/logic/luadefs/CLuaDrawingDefs.cpp | 4 ++-- .../mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h | 2 +- Client/sdk/game/CRenderer.h | 3 ++- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Client/game_sa/CRendererSA.cpp b/Client/game_sa/CRendererSA.cpp index bad607d5ba..04face6248 100644 --- a/Client/game_sa/CRendererSA.cpp +++ b/Client/game_sa/CRendererSA.cpp @@ -15,6 +15,9 @@ #include "CMatrix.h" #include "gamesa_renderware.h" +#define SetLightColoursForPedsCarsAndObjects(fMult) ((RpLight*(__cdecl*)(float))0x735D90)(fMult) +#define SetAmbientColours() ((RpLight*(__cdecl*)())0x735D30)() + CRendererSA::CRendererSA() { } @@ -23,7 +26,7 @@ CRendererSA::~CRendererSA() { } -void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) +void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) { CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface(); if (!pModelInfoSAInterface) @@ -40,7 +43,10 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) rwMatrix.up = (RwV3d&)matrix.vFront; rwMatrix.at = (RwV3d&)matrix.vUp; rwMatrix.pos = (RwV3d&)matrix.vPos; - RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE); + RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE); + + // Setup ambient light multiplier + SetLightColoursForPedsCarsAndObjects(lighting); if (pRwObject->type == RP_TYPE_ATOMIC) { @@ -52,4 +58,7 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) RpClump* pClump = reinterpret_cast(pRwObject); RpClumpRender(pClump); } + + // Restore ambient light + SetAmbientColours(); } diff --git a/Client/game_sa/CRendererSA.h b/Client/game_sa/CRendererSA.h index e71a83665e..eb09edae72 100644 --- a/Client/game_sa/CRendererSA.h +++ b/Client/game_sa/CRendererSA.h @@ -19,5 +19,5 @@ class CRendererSA : public CRenderer CRendererSA(); ~CRendererSA(); - void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) override; + void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) override; }; diff --git a/Client/mods/deathmatch/logic/CModelRenderer.cpp b/Client/mods/deathmatch/logic/CModelRenderer.cpp index 2f06c836ec..ed05fa4ae4 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.cpp +++ b/Client/mods/deathmatch/logic/CModelRenderer.cpp @@ -13,14 +13,14 @@ #include "game\CRenderer.h" #include "game\CVisibilityPlugins.h" -bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix) +bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) { if (g_pCore->IsWindowMinimized()) return false; if (pModelInfo && pModelInfo->IsLoaded()) { - m_Queue.emplace_back(pModelInfo, matrix); + m_Queue.emplace_back(pModelInfo, matrix, lighting); return true; } @@ -54,7 +54,7 @@ void CModelRenderer::Render() for (auto& modelDesc : m_Queue) { if (modelDesc.pModelInfo->IsLoaded() && !modelDesc.pModelInfo->GetIdeFlag(eModelIdeFlag::DRAW_LAST)) - pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix); + pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting); } m_Queue.clear(); @@ -68,5 +68,5 @@ void CModelRenderer::RenderEntity(SModelToRender* modelDesc, float distance) CRenderer* pRenderer = g_pGame->GetRenderer(); assert(pRenderer); - pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix); + pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting); } diff --git a/Client/mods/deathmatch/logic/CModelRenderer.h b/Client/mods/deathmatch/logic/CModelRenderer.h index d923db6c7f..a2dba3030b 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.h +++ b/Client/mods/deathmatch/logic/CModelRenderer.h @@ -18,15 +18,17 @@ class CModelRenderer final { CModelInfo* pModelInfo; CMatrix matrix; + float lighting; - SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix) : + SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f) : pModelInfo(pModelInfo), - matrix(matrix) + matrix(matrix), + lighting(lighting) { } }; - bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix); + bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting); void Update(); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index f54378944d..adc83a1224 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -2123,7 +2123,7 @@ bool CLuaDrawingDefs::DxDrawWiredSphere(lua_State* const luaVM, const CVector po return true; } -bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale) +bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale, const std::optional lighting) { CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelID); if (!pModelInfo) @@ -2138,5 +2138,5 @@ bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVe ConvertDegreesToRadians(rotation); return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo, - CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}); + CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f)); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h index 55dc3adda1..d01d6ec214 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h @@ -82,7 +82,7 @@ class CLuaDrawingDefs : public CLuaDefs static bool DxDrawWiredSphere(lua_State* const luaVM, const CVector position, const float radius, const std::optional color, const std::optional lineWidth, const std::optional iterations); - static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale); + static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional scale, const std::optional lighting); private: static void AddDxMaterialClass(lua_State* luaVM); diff --git a/Client/sdk/game/CRenderer.h b/Client/sdk/game/CRenderer.h index 65d6a8bdca..0e6a0da141 100644 --- a/Client/sdk/game/CRenderer.h +++ b/Client/sdk/game/CRenderer.h @@ -13,11 +13,12 @@ class CModelInfo; class CMatrix; +class CVector; class CRenderer { public: virtual ~CRenderer() {} - virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix) = 0; + virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) = 0; }; From da5d7059f15b553576529a5c93be3ab72235bd1c Mon Sep 17 00:00:00 2001 From: TEDERIs Date: Tue, 24 Dec 2024 17:39:11 +0700 Subject: [PATCH 34/34] Cleanup --- Client/sdk/game/CRenderer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/sdk/game/CRenderer.h b/Client/sdk/game/CRenderer.h index 0e6a0da141..19a9465224 100644 --- a/Client/sdk/game/CRenderer.h +++ b/Client/sdk/game/CRenderer.h @@ -13,7 +13,6 @@ class CModelInfo; class CMatrix; -class CVector; class CRenderer {