Files
Tower-Defense2/src/td/game/World.cpp
2024-10-25 17:12:13 +02:00

32 lines
704 B
C++

#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