This commit is contained in:
2024-10-25 17:12:13 +02:00
parent c0473e5a65
commit cd03175b98
12 changed files with 143 additions and 16 deletions

31
src/td/game/World.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <td/game/World.h>
#include <td/Constants.h>
#include <limits>
namespace td {
namespace game {
World::World() : m_WorldStates(std::numeric_limits<StepsType>::max()), m_OffsetTime(0) {}
void World::Tick(float a_Delta) {
m_OffsetTime += a_Delta;
if (GetCursorPos() > m_WorldStates.size()) {
if (!m_GameHistory.HasLockStep(GetCursorPos())) {
// oupsi
return;
}
WorldState& lastState = m_WorldStates.back();
WorldState nextState = lastState.GetNextState(m_GameHistory.GetLockStep(GetCursorPos()));
m_WorldStates.push_back(std::move(nextState));
}
}
std::uint16_t World::GetCursorPos() {
return (std::uint16_t) m_OffsetTime * TPS;
}
} // namespace game
} // namespace td