Automatically finalize any delayed update objects

This commit is contained in:
Yousef Khadadeh 2025-12-18 23:37:37 +03:00
parent 8defbe7569
commit 66d372d810
4 changed files with 38 additions and 7 deletions

View file

@ -1,9 +1,17 @@
#include "DelayUpdateSerializedClassManager.hpp"
#include <chrono>
namespace NetworkingObjects {
void DelayUpdateSerializedClassManager::update() {
void DelayUpdateSerializedClassManager::update(NetworkingObjects::NetObjManager& netObjMan) {
for(auto& [objID, updatingObj] : updatingObjs) {
if(updatingObj.lastTemporaryUpdateTimePoint.has_value() && (std::chrono::steady_clock::now() - updatingObj.lastTemporaryUpdateTimePoint.value()) >= std::chrono::milliseconds(300)) {
updatingObj.sendFinalUpdate();
std::cout << "yay!" << std::endl;
updatingObj.lastTemporaryUpdateTimePoint = std::nullopt;
}
}
std::erase_if(updatingObjs, [](auto& updatingPair) {
if((std::chrono::steady_clock::now() - updatingPair.second.lastUpdateTimePoint) >= std::chrono::seconds(3)) {
if((std::chrono::steady_clock::now() - updatingPair.second.lastUpdateTimePoint) >= std::chrono::seconds(3) && !updatingPair.second.lastTemporaryUpdateTimePoint.has_value()) {
updatingPair.second.setDataAfterTimeout();
return true;
}