diff --git a/include/td/game/GameHistory.h b/include/td/game/GameHistory.h index 9407c61..c5c4f61 100644 --- a/include/td/game/GameHistory.h +++ b/include/td/game/GameHistory.h @@ -2,6 +2,7 @@ #include #include +#include namespace td { namespace game { @@ -10,47 +11,26 @@ class GameHistory { private: using HistorySizeType = std::uint16_t; - std::vector> m_History {std::numeric_limits::max()}; + std::vector> m_History; - HistorySizeType m_Cursor = 0; + HistorySizeType m_Cursor; public: - GameHistory(){} + GameHistory(); - void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep) { - m_History[a_Index] = std::move(a_LockStep); - } + void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep); - const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const { - return *m_History[a_Index]; - } + const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const; - bool HasLockStep(HistorySizeType a_Index) const { - return m_History[a_Index].has_value(); - } + bool HasLockStep(HistorySizeType a_Index) const; - const protocol::LockStep& GetNextStep() { - return GetLockStep(m_Cursor++); - } + const protocol::LockStep& GetNextStep(); - bool HasNextStep() const { - return HasLockStep(m_Cursor); - } + bool HasNextStep() const; - void FromPacket(td::protocol::pdata::LockSteps&& a_Steps) { - for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) { - protocol::LockStep& step = a_Steps.m_LockSteps[i]; - SetLockStep(i + a_Steps.m_FirstFrameNumber, std::move(step)); - } - } + void FromPacket(td::protocol::pdata::LockSteps&& a_Steps); - td::protocol::packets::LockSteps ToPacket(HistorySizeType a_StartIndex) { - std::array steps; - for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) { - steps[i] = GetLockStep(a_StartIndex + i); - } - return {{a_StartIndex, std::move(steps)}}; - } + td::protocol::packets::LockSteps ToPacket(HistorySizeType a_StartIndex); }; } // namespace game diff --git a/src/td/game/GameHistory.cpp b/src/td/game/GameHistory.cpp new file mode 100644 index 0000000..2ed127e --- /dev/null +++ b/src/td/game/GameHistory.cpp @@ -0,0 +1,44 @@ +#include + +namespace td { +namespace game { + +GameHistory::GameHistory() : m_History(std::numeric_limits::max()), m_Cursor(0) {} + +void GameHistory::SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep) { + m_History[a_Index] = std::move(a_LockStep); +} + +const protocol::LockStep& GameHistory::GetLockStep(HistorySizeType a_Index) const { + return *m_History[a_Index]; +} + +bool GameHistory::HasLockStep(HistorySizeType a_Index) const { + return m_History[a_Index].has_value(); +} + +const protocol::LockStep& GameHistory::GetNextStep() { + return GetLockStep(m_Cursor++); +} + +bool GameHistory::HasNextStep() const { + return HasLockStep(m_Cursor); +} + +void GameHistory::FromPacket(td::protocol::pdata::LockSteps&& a_Steps) { + for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) { + protocol::LockStep& step = a_Steps.m_LockSteps[i]; + SetLockStep(i + a_Steps.m_FirstFrameNumber, std::move(step)); + } +} + +td::protocol::packets::LockSteps GameHistory::ToPacket(HistorySizeType a_StartIndex) { + std::array steps; + for (int i = 0; i < LOCKSTEP_BUFFER_SIZE; i++) { + steps[i] = GetLockStep(a_StartIndex + i); + } + return {{a_StartIndex, std::move(steps)}}; +} + +} // namespace game +} // namespace td