Compare commits
3 Commits
949929f490
...
2c80406795
Author | SHA1 | Date | |
---|---|---|---|
2c80406795 | |||
e8e9126faa | |||
80bf8f5afd |
10
external/CMakeLists.txt
vendored
10
external/CMakeLists.txt
vendored
@ -2,16 +2,6 @@ cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR)
|
|||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
# TODO: move entt dep into solanaceae_contact
|
|
||||||
if (NOT TARGET EnTT::EnTT)
|
|
||||||
FetchContent_Declare(EnTT
|
|
||||||
GIT_REPOSITORY https://github.com/skypjack/entt.git
|
|
||||||
GIT_TAG v3.12.2
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(EnTT)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT TARGET solanaceae_util)
|
if (NOT TARGET solanaceae_util)
|
||||||
FetchContent_Declare(solanaceae_util
|
FetchContent_Declare(solanaceae_util
|
||||||
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_util.git
|
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_util.git
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -44,6 +44,16 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#endif
|
#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;
|
std::atomic_bool quit = false;
|
||||||
|
|
||||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
|
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
|
||||||
@ -172,7 +182,7 @@ int main(int argc, char** argv) {
|
|||||||
Contact3Registry cr;
|
Contact3Registry cr;
|
||||||
RegistryMessageModel rmm{cr};
|
RegistryMessageModel rmm{cr};
|
||||||
MessageTimeSort mts{rmm};
|
MessageTimeSort mts{rmm};
|
||||||
MessageCleanser mc{cr, rmm};
|
MessageCleanser mc{cr, rmm, conf};
|
||||||
MessageCommandDispatcher mcd{cr, rmm, conf};
|
MessageCommandDispatcher mcd{cr, rmm, conf};
|
||||||
|
|
||||||
{ // setup basic commands for bot
|
{ // setup basic commands for bot
|
||||||
@ -310,19 +320,15 @@ int main(int argc, char** argv) {
|
|||||||
mts.iterate();
|
mts.iterate();
|
||||||
|
|
||||||
const float pm_interval = pm.tick(time_delta_tick);
|
const float pm_interval = pm.tick(time_delta_tick);
|
||||||
|
const float mc_interval = mc.iterate(time_delta_tick);
|
||||||
mc.iterate(time_delta_tick);
|
|
||||||
|
|
||||||
const float mcd_interval = mcd.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;
|
const float tox_interval = std::pow(tc.toxIterationInterval(), 1.6f) / 1000.f;
|
||||||
|
|
||||||
last_min_interval = std::min<float>(
|
last_min_interval = min_var(
|
||||||
tox_interval,
|
pm_interval,
|
||||||
pm_interval
|
mc_interval,
|
||||||
);
|
mcd_interval,
|
||||||
last_min_interval = std::min<float>(
|
tox_interval
|
||||||
last_min_interval,
|
|
||||||
mcd_interval
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// dont sleep and do an extra check
|
// dont sleep and do an extra check
|
||||||
|
@ -2,19 +2,26 @@
|
|||||||
|
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
|
#include <solanaceae/util/utils.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
MessageCleanser::MessageCleanser(Contact3Registry& cr, RegistryMessageModel& rmm) : _cr(cr), _rmm(rmm) {
|
MessageCleanser::MessageCleanser(
|
||||||
// config
|
Contact3Registry& cr,
|
||||||
// has MessageCleanser::old_age
|
RegistryMessageModel& rmm,
|
||||||
|
ConfigModelI& conf
|
||||||
|
) : _cr(cr), _rmm(rmm), _conf(conf) {
|
||||||
|
if (!_conf.has_int("MessageCleanser", "old_age_minutes")) {
|
||||||
|
_conf.set("MessageCleanser", "old_age_minutes", int64_t(_old_age_default));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageCleanser::~MessageCleanser(void) {
|
MessageCleanser::~MessageCleanser(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageCleanser::iterate(float time_delta) {
|
float MessageCleanser::iterate(float time_delta) {
|
||||||
_timer += time_delta;
|
_timer += time_delta;
|
||||||
if (_timer >= _interval) {
|
if (_timer >= _interval) {
|
||||||
_timer = 0.f;
|
_timer = 0.f;
|
||||||
@ -23,17 +30,27 @@ void MessageCleanser::iterate(float time_delta) {
|
|||||||
|
|
||||||
uint64_t now_ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
uint64_t now_ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
uint64_t deleted_count{0};
|
|
||||||
|
|
||||||
// TODO: iterate rmm directly
|
// TODO: iterate rmm directly
|
||||||
//_rmm.get();
|
//_rmm.get();
|
||||||
// workaround by iterating contacts
|
// workaround by iterating contacts
|
||||||
for (const auto& c : _cr.view<Contact::Components::TagBig>()) {
|
for (const auto& c : _cr.view<Contact::Components::TagBig>()) {
|
||||||
if (auto* reg = _rmm.get(c); reg != nullptr) {
|
if (auto* reg = _rmm.get(c); reg != nullptr) {
|
||||||
|
float old_age {0.f};
|
||||||
|
{ // old age from conf
|
||||||
|
// TODO: find some way to extract this (maybe map into contact reg?)
|
||||||
|
if (const auto* id_comp = _cr.try_get<Contact::Components::ID>(c); id_comp != nullptr) {
|
||||||
|
const auto id_hex = bin2hex(id_comp->data);
|
||||||
|
old_age = _conf.get_int("MessageCleanser", "old_age_minutes", id_hex).value_or(_old_age_default);
|
||||||
|
} else {
|
||||||
|
old_age = _conf.get_int("MessageCleanser", "old_age_minutes").value_or(_old_age_default);
|
||||||
|
}
|
||||||
|
old_age *= 60.f; // to sec
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Message3> to_remove;
|
std::vector<Message3> to_remove;
|
||||||
// assuming all messages have Timestamp comp
|
// assuming all messages have Timestamp comp
|
||||||
reg->view<Message::Components::Timestamp>().each([this, now_ts, &to_remove](const Message3 ent, const Message::Components::Timestamp& ts) {
|
reg->view<Message::Components::Timestamp>().each([this, now_ts, old_age, &to_remove](const Message3 ent, const Message::Components::Timestamp& ts) {
|
||||||
if (now_ts >= ts.ts + static_cast<uint64_t>(_old_age*1000.f)) {
|
if (now_ts >= ts.ts + static_cast<uint64_t>(old_age*1000.f)) {
|
||||||
to_remove.push_back(ent);
|
to_remove.push_back(ent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -44,12 +61,13 @@ void MessageCleanser::iterate(float time_delta) {
|
|||||||
_rmm.throwEventDestroy(*reg, c);
|
_rmm.throwEventDestroy(*reg, c);
|
||||||
reg->destroy(c);
|
reg->destroy(c);
|
||||||
}
|
}
|
||||||
deleted_count += to_remove.size();
|
|
||||||
|
if (!to_remove.empty()) {
|
||||||
|
std::cout << "MC: cleaned up " << to_remove.size() << ", age >= " << old_age << "sec\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted_count > 0) {
|
|
||||||
std::cout << "MC: cleaned up " << deleted_count << "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return _interval - _timer;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <solanaceae/message3/registry_message_model.hpp>
|
#include <solanaceae/message3/registry_message_model.hpp>
|
||||||
|
#include <solanaceae/util/config_model.hpp>
|
||||||
|
|
||||||
class MessageCleanser {
|
class MessageCleanser {
|
||||||
Contact3Registry& _cr;
|
Contact3Registry& _cr;
|
||||||
RegistryMessageModel& _rmm;
|
RegistryMessageModel& _rmm;
|
||||||
|
ConfigModelI& _conf;
|
||||||
|
|
||||||
|
static constexpr int64_t _old_age_default{150}; // minutes
|
||||||
|
|
||||||
float _old_age{150.f*60.f}; // max 150min
|
|
||||||
float _interval{3.f*60.f}; // every 3min
|
float _interval{3.f*60.f}; // every 3min
|
||||||
float _timer{0.f};
|
float _timer{0.f};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MessageCleanser(Contact3Registry& cr, RegistryMessageModel& rmm);
|
MessageCleanser(
|
||||||
|
Contact3Registry& cr,
|
||||||
|
RegistryMessageModel& rmm,
|
||||||
|
ConfigModelI& conf
|
||||||
|
);
|
||||||
~MessageCleanser(void);
|
~MessageCleanser(void);
|
||||||
|
|
||||||
void iterate(float time_delta);
|
float iterate(float time_delta);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user