From c1f1615dcae20601fd40a56b19b895ebbde4a082 Mon Sep 17 00:00:00 2001 From: John Magdy Lotfy Kamel <19735243+Zorono@users.noreply.github.com> Date: Tue, 14 Jul 2026 00:38:04 +0300 Subject: [PATCH 1/2] attempt to implement new features for Timers --- SDK | 2 +- Server/Components/Pawn/Manager/Manager.cpp | 7 ++ Server/Components/Pawn/utils.hpp | 92 ++++++++++++++++++++++ Server/Components/Timers/timer.hpp | 36 ++++++++- Server/Components/Timers/timers_main.cpp | 6 ++ 5 files changed, 141 insertions(+), 2 deletions(-) diff --git a/SDK b/SDK index 3ee7bc4ab..c0cf0b86e 160000 --- a/SDK +++ b/SDK @@ -1 +1 @@ -Subproject commit 3ee7bc4ab20c22359c34c08c38f93815b44bffd5 +Subproject commit c0cf0b86e760613383a69b382dbf9cf3808a9e9d diff --git a/Server/Components/Pawn/Manager/Manager.cpp b/Server/Components/Pawn/Manager/Manager.cpp index e0dd77471..1e69a3e44 100644 --- a/Server/Components/Pawn/Manager/Manager.cpp +++ b/Server/Components/Pawn/Manager/Manager.cpp @@ -495,6 +495,13 @@ void PawnManager::openAMX(PawnScript& script, bool isEntryScript, bool restartin script.Register("IsRepeatingTimer", &utils::pawn_IsRepeatingTimer); script.Register("GetTimerRemaining", &utils::pawn_GetTimerRemaining); script.Register("GetTimerInterval", &utils::pawn_GetTimerInterval); + script.Register("SetTimerInterval", &utils::pawn_SetTimerInterval); + script.Register("PauseTimer", &utils::pawn_PauseTimer); + script.Register("ContinueTimer", &utils::pawn_ContinueTimer); + script.Register("IsTimerPaused", &utils::pawn_IsTimerPaused); + script.Register("KillAllTimers", &utils::pawn_KillAllTimers); + script.Register("IsTimerRunning", &utils::pawn_IsTimerRunning); + script.Register("GetRunningTimersCount", &utils::pawn_GetRunningTimersCount); script.Register("SetModeRestartTime", &utils::pawn_SetModeRestartTime); script.Register("GetModeRestartTime", &utils::pawn_GetModeRestartTime); diff --git a/Server/Components/Pawn/utils.hpp b/Server/Components/Pawn/utils.hpp index 4769a521d..ac536264c 100644 --- a/Server/Components/Pawn/utils.hpp +++ b/Server/Components/Pawn/utils.hpp @@ -15,6 +15,7 @@ #include "format.hpp" #include "timers.hpp" +#include "../Timers/timer.hpp" extern "C" { @@ -235,12 +236,103 @@ inline cell AMX_NATIVE_CALL pawn_GetTimerInterval(AMX* amx, cell const* params) return timer->interval().count(); } +inline cell AMX_NATIVE_CALL pawn_SetTimerInterval(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("SetTimerInterval", params, 2); + ITimer* timer = PawnTimerImpl::Get()->getTimer(params[1]); + if (timer == nullptr || !timer->running()) + { + return false; + } + + int interval = static_cast(params[2]); + + if(interval < 1) + { + return false; + } + + timer->setInterval(static_cast(interval)); + return true; +} + +inline cell AMX_NATIVE_CALL pawn_KillAllTimers(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("KillAllTimers", params, 0); + ITimersComponent* timers = PawnManager::Get()->timers; + for (int timerid = 0; timerid < timers->count(); timerid++) + { + ITimer* timer = PawnTimerImpl::Get()->getTimer(timerid); + if (timer == nullptr || !timer->running()) + { + return false; + } + timer->kill(); + } + return true; +} + +inline cell AMX_NATIVE_CALL pawn_IsTimerRunning(AMX* amx, cell const* params) +{ + GET_TIMER(timer, "IsTimerRunning", false) + return timer->running(); +} + inline cell AMX_NATIVE_CALL pawn_IsRepeatingTimer(AMX* amx, cell const* params) { GET_TIMER(timer, "IsRepeatingTimer", false) return timer->calls() == 0; } +inline cell AMX_NATIVE_CALL pawn_GetRunningTimersCount(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("GetRunningTimersCount", params, 0); + return PawnManager::Get()->timers->count(); +} + +inline cell AMX_NATIVE_CALL pawn_IsTimerPaused(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("IsTimerPaused", params, 1); + ITimer* timer = PawnTimerImpl::Get()->getTimer(params[1]); + if (timer == nullptr || !timer->running()) + { + return false; + } + + if (!timer->paused()) + { + return false; + } + + return true; +} + +inline cell AMX_NATIVE_CALL pawn_PauseTimer(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("PauseTimer", params, 1); + ITimer* timer = PawnTimerImpl::Get()->getTimer(params[1]); + if (timer == nullptr || !timer->running()) + { + return false; + } + + timer->togglePause(true); + return true; +} + +inline cell AMX_NATIVE_CALL pawn_ContinueTimer(AMX* amx, cell const* params) +{ + AMX_MIN_PARAMETERS("ContinueTimer", params, 1); + ITimer* timer = PawnTimerImpl::Get()->getTimer(params[1]); + if (timer == nullptr || !timer->running()) + { + return false; + } + + timer->togglePause(false); + return true; +} + inline cell AMX_NATIVE_CALL pawn_SetModeRestartTime(AMX* amx, cell const* params) { AMX_CHECK_PARAMETERS("SetModeRestartTime", params, 1); diff --git a/Server/Components/Timers/timer.hpp b/Server/Components/Timers/timer.hpp index 1b76c8c8f..810f9cf98 100644 --- a/Server/Components/Timers/timer.hpp +++ b/Server/Components/Timers/timer.hpp @@ -12,9 +12,11 @@ class Timer final : public ITimer { private: bool running_; + bool paused_; unsigned int count_; - const Milliseconds interval_; + Milliseconds interval_; TimePoint timeout_; + TimePoint pausedTime_; TimerTimeOutHandler* const handler_; public: @@ -28,6 +30,27 @@ class Timer final : public ITimer timeout_ = timeout; } + TimePoint getPausedTime() const + { + return pausedTime_; + } + + void togglePause(bool paused) override + { + paused_ = paused; + + if (paused) + { + pausedTime_ = Time::now(); + } + else + { + TimePoint now = Time::now(); + Milliseconds pauseDuration = duration_cast(now - pausedTime_); + timeout_ += pauseDuration; + } + } + Timer(TimerTimeOutHandler* handler, Milliseconds initial, Milliseconds interval, unsigned int count) : running_(true) , count_(count) @@ -42,6 +65,11 @@ class Timer final : public ITimer return running_; } + bool paused() const override + { + return paused_; + } + Milliseconds remaining() const override { return duration_cast(timeout_ - Time::now()); @@ -57,6 +85,12 @@ class Timer final : public ITimer return interval_; } + void setInterval(Milliseconds interval) override + { + interval_ = interval; + timeout_ = Time::now() + interval_; + } + TimerTimeOutHandler* handler() const override { return handler_; diff --git a/Server/Components/Timers/timers_main.cpp b/Server/Components/Timers/timers_main.cpp index c45d0878f..ad3556d46 100644 --- a/Server/Components/Timers/timers_main.cpp +++ b/Server/Components/Timers/timers_main.cpp @@ -73,6 +73,12 @@ class TimersComponent final : public ITimersComponent, public CoreEventHandler } else { + if (timer->paused()) + { + ++it; + continue; + } + const TimePoint now = Time::now(); const Milliseconds diff = duration_cast(now - timer->getTimeout()); if (diff.count() >= 0) From ddffc7b1b9bfdc374dc063665144e428bb9f4d84 Mon Sep 17 00:00:00 2001 From: John Magdy Lotfy Kamel <19735243+Zorono@users.noreply.github.com> Date: Wed, 15 Jul 2026 22:12:37 +0300 Subject: [PATCH 2/2] some fixes for Clang Format --- SDK | 2 +- Server/Components/Pawn/format.cpp | 2 +- Server/Components/Pawn/utils.hpp | 16 ++++++++-------- Server/Components/Timers/timer.hpp | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SDK b/SDK index c0cf0b86e..889886069 160000 --- a/SDK +++ b/SDK @@ -1 +1 @@ -Subproject commit c0cf0b86e760613383a69b382dbf9cf3808a9e9d +Subproject commit 8898860695d7ac91e1709c3c5e29aa8563969a1c diff --git a/Server/Components/Pawn/format.cpp b/Server/Components/Pawn/format.cpp index 31a454651..ecb0733b3 100644 --- a/Server/Components/Pawn/format.cpp +++ b/Server/Components/Pawn/format.cpp @@ -580,7 +580,7 @@ void AddOctal(U** buf_p, size_t& maxlen, unsigned int val, int width, int flags) *buf_p = buf; } -//#define ATCPRINTF_ADVANCE(fmt, ispacked) atcadvance(fmt, ispacked) +// #define ATCPRINTF_ADVANCE(fmt, ispacked) atcadvance(fmt, ispacked) template static inline unsigned char atcadvance(unsigned char const** fmt, bool ispacked) diff --git a/Server/Components/Pawn/utils.hpp b/Server/Components/Pawn/utils.hpp index ac536264c..a51c5bd0d 100644 --- a/Server/Components/Pawn/utils.hpp +++ b/Server/Components/Pawn/utils.hpp @@ -247,7 +247,7 @@ inline cell AMX_NATIVE_CALL pawn_SetTimerInterval(AMX* amx, cell const* params) int interval = static_cast(params[2]); - if(interval < 1) + if (interval < 1) { return false; } @@ -261,14 +261,14 @@ inline cell AMX_NATIVE_CALL pawn_KillAllTimers(AMX* amx, cell const* params) AMX_MIN_PARAMETERS("KillAllTimers", params, 0); ITimersComponent* timers = PawnManager::Get()->timers; for (int timerid = 0; timerid < timers->count(); timerid++) - { - ITimer* timer = PawnTimerImpl::Get()->getTimer(timerid); + { + ITimer* timer = PawnTimerImpl::Get()->getTimer(timerid); if (timer == nullptr || !timer->running()) - { - return false; - } - timer->kill(); - } + { + return false; + } + timer->kill(); + } return true; } diff --git a/Server/Components/Timers/timer.hpp b/Server/Components/Timers/timer.hpp index 810f9cf98..98ad03a8b 100644 --- a/Server/Components/Timers/timer.hpp +++ b/Server/Components/Timers/timer.hpp @@ -65,7 +65,7 @@ class Timer final : public ITimer return running_; } - bool paused() const override + bool paused() const override { return paused_; }