pupush
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
GameHistory::GameHistory() : m_History(std::numeric_limits<HistorySizeType>::max()), m_Cursor(0) {}
|
||||
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);
|
||||
@@ -17,14 +17,6 @@ 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];
|
||||
|
||||
31
src/td/game/World.cpp
Normal file
31
src/td/game/World.cpp
Normal 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
|
||||
43
src/td/game/WorldState.cpp
Normal file
43
src/td/game/WorldState.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <td/game/WorldState.h>
|
||||
|
||||
#include <td/Constants.h>
|
||||
|
||||
#include <td/protocol/command/CommandVisitor.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class CommandHandler : public protocol::CommandVisitor {
|
||||
private:
|
||||
WorldState& m_WorldState;
|
||||
|
||||
public:
|
||||
CommandHandler(WorldState& a_WorldState) : m_WorldState(a_WorldState) {}
|
||||
|
||||
void Visit(const protocol::commands::End&) override {}
|
||||
void Visit(const protocol::commands::PlaceTower&) override {}
|
||||
void Visit(const protocol::commands::PlayerJoin&) override {}
|
||||
void Visit(const protocol::commands::SpawnTroop&) override {}
|
||||
void Visit(const protocol::commands::TeamChange&) override {}
|
||||
void Visit(const protocol::commands::UpgradeTower&) override {}
|
||||
void Visit(const protocol::commands::UseItem&) override {}
|
||||
};
|
||||
|
||||
WorldState WorldState::GetNextState(const protocol::LockStep& a_Step) {
|
||||
WorldState newState = *this;
|
||||
CommandHandler handler(*this);
|
||||
for (auto command : a_Step) {
|
||||
handler.Check(*command);
|
||||
}
|
||||
newState.Tick(STEP_PERIOD);
|
||||
return newState;
|
||||
}
|
||||
|
||||
void WorldState::Tick(float a_Delta) {
|
||||
// move mobs
|
||||
// process towers
|
||||
// process damages
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user