small main refactor + msg cleanser interval

This commit is contained in:
Green Sky 2024-02-04 13:50:44 +01:00
parent 80bf8f5afd
commit e8e9126faa
No known key found for this signature in database
3 changed files with 20 additions and 12 deletions

View File

@ -44,6 +44,16 @@
#include <signal.h>
#endif
// why is min not variadic?
template<typename... T>
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<float>(
tox_interval,
pm_interval
);
last_min_interval = std::min<float>(
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

View File

@ -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;
}

View File

@ -14,5 +14,5 @@ class MessageCleanser {
MessageCleanser(Contact3Registry& cr, RegistryMessageModel& rmm);
~MessageCleanser(void);
void iterate(float time_delta);
float iterate(float time_delta);
};