diff --git a/src/main.cpp b/src/main.cpp index 71a4efd..d1b225d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,16 @@ #include #endif +// why is min not variadic? +template +float min_var(float v0, T... args) { + if constexpr (sizeof...(args) == 0) { + return v0; + } else { + return std::min(v0, min_var(args...)); + } +} + std::atomic_bool quit = false; #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) @@ -310,19 +320,15 @@ int main(int argc, char** argv) { mts.iterate(); const float pm_interval = pm.tick(time_delta_tick); - - mc.iterate(time_delta_tick); - + const float mc_interval = mc.iterate(time_delta_tick); const float mcd_interval = mcd.iterate(time_delta_tick); const float tox_interval = std::pow(tc.toxIterationInterval(), 1.6f) / 1000.f; - last_min_interval = std::min( - tox_interval, - pm_interval - ); - last_min_interval = std::min( - last_min_interval, - mcd_interval + last_min_interval = min_var( + pm_interval, + mc_interval, + mcd_interval, + tox_interval ); // dont sleep and do an extra check diff --git a/src/message_cleanser.cpp b/src/message_cleanser.cpp index 58864b7..18444de 100644 --- a/src/message_cleanser.cpp +++ b/src/message_cleanser.cpp @@ -14,7 +14,7 @@ MessageCleanser::MessageCleanser(Contact3Registry& cr, RegistryMessageModel& rmm MessageCleanser::~MessageCleanser(void) { } -void MessageCleanser::iterate(float time_delta) { +float MessageCleanser::iterate(float time_delta) { _timer += time_delta; if (_timer >= _interval) { _timer = 0.f; @@ -52,4 +52,6 @@ void MessageCleanser::iterate(float time_delta) { std::cout << "MC: cleaned up " << deleted_count << "\n"; } } + + return _interval - _timer; } diff --git a/src/message_cleanser.hpp b/src/message_cleanser.hpp index 7691235..fcaa245 100644 --- a/src/message_cleanser.hpp +++ b/src/message_cleanser.hpp @@ -14,5 +14,5 @@ class MessageCleanser { MessageCleanser(Contact3Registry& cr, RegistryMessageModel& rmm); ~MessageCleanser(void); - void iterate(float time_delta); + float iterate(float time_delta); };