Merge branch 'experimental' into dev
This commit is contained in:
36
src/td/simulation/GameHistory.cpp
Normal file
36
src/td/simulation/GameHistory.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <td/simulation/GameHistory.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
GameHistory::GameHistory() : m_History(std::numeric_limits<HistorySizeType>::max()) {}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void GameHistory::FromPacket(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));
|
||||
}
|
||||
}
|
||||
|
||||
protocol::packets::LockStepsPacket GameHistory::ToPacket(HistorySizeType a_StartIndex) {
|
||||
std::array<protocol::LockStep, LOCKSTEP_BUFFER_SIZE> 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
|
||||
Reference in New Issue
Block a user