mirror of
https://github.com/Jous99/F4MP.git
synced 2026-01-12 17:10:54 +01:00
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#include "StringCache.h"
|
|
|
|
#include <GameServer.h>
|
|
#include <Services/StringCacheService.h>
|
|
#include <Events/UpdateEvent.h>
|
|
#include <Game/Player.h>
|
|
|
|
StringCacheService::StringCacheService(World& aWorld, entt::dispatcher& aDispatcher)
|
|
: m_world(aWorld)
|
|
, m_updateConnection(aDispatcher.sink<UpdateEvent>().connect<&StringCacheService::HandleUpdate>(this))
|
|
{
|
|
}
|
|
|
|
void StringCacheService::HandleUpdate(const UpdateEvent&) const noexcept
|
|
{
|
|
static std::chrono::steady_clock::time_point lastSendTimePoint;
|
|
constexpr auto cDelayBetweenSnapshots = 2000ms;
|
|
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (now - lastSendTimePoint < cDelayBetweenSnapshots)
|
|
return;
|
|
|
|
lastSendTimePoint = now;
|
|
|
|
auto& stringCache = StringCache::Get();
|
|
|
|
if (!stringCache.ProcessDirty())
|
|
return;
|
|
|
|
for (const auto pPlayer : m_world.GetPlayerManager())
|
|
{
|
|
auto startId = pPlayer->GetStringCacheId();
|
|
auto update = stringCache.Serialize(startId);
|
|
pPlayer->SetStringCacheId(startId);
|
|
|
|
pPlayer->Send(update);
|
|
}
|
|
}
|