mirror of
https://github.com/Jous99/F4MP.git
synced 2026-01-12 17:10:54 +01:00
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <Events/PacketEvent.h>
|
|
#include <DateTime.h>
|
|
#include <Structs/GameId.h>
|
|
|
|
struct World;
|
|
struct UpdateEvent;
|
|
struct PlayerJoinEvent;
|
|
|
|
/**
|
|
* @brief Manages time and date of the world.
|
|
*/
|
|
class CalendarService
|
|
{
|
|
public:
|
|
CalendarService(World& aWorld, entt::dispatcher& aDispatcher);
|
|
|
|
// we use these types for SOL
|
|
// this is done this way because SOL
|
|
// provides direct support for these
|
|
using TTime = std::pair<int, int>;
|
|
using TDate = std::tuple<int, int, int>;
|
|
|
|
bool SetTime(int aHour, int aMinutes, float aScale) noexcept;
|
|
bool SetDate(int aDay, int aMonth, float aYear) noexcept;
|
|
|
|
// returns hours, minutes
|
|
TTime GetTime() const noexcept;
|
|
static TTime GetRealTime() noexcept;
|
|
|
|
// returns dd/mm/yy
|
|
TDate GetDate() const noexcept;
|
|
|
|
float GetTimeScale() const noexcept { return m_dateTime.m_timeModel.TimeScale; }
|
|
bool SetTimeScale(float aScale) noexcept;
|
|
|
|
private:
|
|
void OnUpdate(const UpdateEvent&) noexcept;
|
|
void OnPlayerJoin(const PlayerJoinEvent&) noexcept;
|
|
void SendTimeResync() noexcept;
|
|
|
|
DateTime m_dateTime;
|
|
uint64_t m_lastTick = 0;
|
|
bool m_timeSetFromFirstPlayer = false;
|
|
|
|
World& m_world;
|
|
|
|
entt::scoped_connection m_updateConnection;
|
|
entt::scoped_connection m_joinConnection;
|
|
};
|