summaryrefslogtreecommitdiff
path: root/src/managers/eventLoop/EventLoopTimer.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-04-16 01:37:48 +0100
committerVaxry <vaxry@vaxry.net>2025-04-16 01:37:48 +0100
commit877fb5b93ada9b25b4d2f5ca5f69370fa345f1ac (patch)
tree5b52ad19c695590ae50c7adae06b8e3aeccf34c1 /src/managers/eventLoop/EventLoopTimer.cpp
parent0e521788bcc414c9cf81648d3167757d83deb60f (diff)
time: move to stl's clocks and move timer
Diffstat (limited to 'src/managers/eventLoop/EventLoopTimer.cpp')
-rw-r--r--src/managers/eventLoop/EventLoopTimer.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/managers/eventLoop/EventLoopTimer.cpp b/src/managers/eventLoop/EventLoopTimer.cpp
index b8943b7c..d4633b0d 100644
--- a/src/managers/eventLoop/EventLoopTimer.cpp
+++ b/src/managers/eventLoop/EventLoopTimer.cpp
@@ -1,55 +1,55 @@
#include "EventLoopTimer.hpp"
#include <limits>
#include "EventLoopManager.hpp"
+#include "../../helpers/time/Time.hpp"
-CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) :
- cb(cb_), data(data_) {
+CEventLoopTimer::CEventLoopTimer(std::optional<Time::steady_dur> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) : m_cb(cb_), m_data(data_) {
if (!timeout.has_value())
- expires.reset();
+ m_expires.reset();
else
- expires = std::chrono::steady_clock::now() + *timeout;
+ m_expires = Time::steadyNow() + *timeout;
}
-void CEventLoopTimer::updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout) {
+void CEventLoopTimer::updateTimeout(std::optional<Time::steady_dur> timeout) {
if (!timeout.has_value()) {
- expires.reset();
+ m_expires.reset();
g_pEventLoopManager->nudgeTimers();
return;
}
- expires = std::chrono::steady_clock::now() + *timeout;
+ m_expires = Time::steadyNow() + *timeout;
g_pEventLoopManager->nudgeTimers();
}
bool CEventLoopTimer::passed() {
- if (!expires.has_value())
+ if (!m_expires.has_value())
return false;
- return std::chrono::steady_clock::now() > *expires;
+ return Time::steadyNow() > *m_expires;
}
void CEventLoopTimer::cancel() {
- wasCancelled = true;
- expires.reset();
+ m_wasCancelled = true;
+ m_expires.reset();
}
bool CEventLoopTimer::cancelled() {
- return wasCancelled;
+ return m_wasCancelled;
}
void CEventLoopTimer::call(SP<CEventLoopTimer> self) {
- expires.reset();
- cb(self, data);
+ m_expires.reset();
+ m_cb(self, m_data);
}
float CEventLoopTimer::leftUs() {
- if (!expires.has_value())
+ if (!m_expires.has_value())
return std::numeric_limits<float>::max();
- return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::steady_clock::now()).count();
+ return std::chrono::duration_cast<std::chrono::microseconds>(*m_expires - Time::steadyNow()).count();
}
bool CEventLoopTimer::armed() {
- return expires.has_value();
+ return m_expires.has_value();
}