too many things
This commit is contained in:
21
include/td/simulation/CommandApply.h
Normal file
21
include/td/simulation/CommandApply.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/World.h>
|
||||
#include <td/protocol/command/Commands.h>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
class CommandApply : public protocol::CommandHandler {
|
||||
private:
|
||||
const game::World& m_World;
|
||||
WorldSnapshot& m_Snapshot;
|
||||
|
||||
public:
|
||||
CommandApply(const game::World& a_World, WorldSnapshot& a_Snapshot);
|
||||
|
||||
virtual void Handle(const protocol::cdata::SpawnTroop& a_SpawnTroop) override;
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
37
include/td/simulation/GameHistory.h
Normal file
37
include/td/simulation/GameHistory.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <td/protocol/command/Commands.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class GameHistory {
|
||||
private:
|
||||
using HistorySizeType = std::uint16_t;
|
||||
|
||||
std::vector<std::optional<protocol::LockStep>> m_History;
|
||||
|
||||
HistorySizeType m_Cursor;
|
||||
|
||||
public:
|
||||
GameHistory();
|
||||
|
||||
void SetLockStep(HistorySizeType a_Index, protocol::LockStep&& a_LockStep);
|
||||
|
||||
const protocol::LockStep& GetLockStep(HistorySizeType a_Index) const;
|
||||
|
||||
bool HasLockStep(HistorySizeType a_Index) const;
|
||||
|
||||
const protocol::LockStep& GetNextStep();
|
||||
|
||||
bool HasNextStep() const;
|
||||
|
||||
void FromPacket(td::protocol::pdata::LockSteps&& a_Steps);
|
||||
|
||||
td::protocol::packets::LockStepsPacket ToPacket(HistorySizeType a_StartIndex);
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
26
include/td/simulation/RealTimeSimulation.h
Normal file
26
include/td/simulation/RealTimeSimulation.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/World.h>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
using GameHistory = std::vector<td::protocol::LockStep>;
|
||||
|
||||
class RealTimeSimulation {
|
||||
private:
|
||||
std::uint64_t m_StepTime;
|
||||
game::World& m_World;
|
||||
GameHistory m_History;
|
||||
std::uint64_t m_CurrentTime;
|
||||
std::uint64_t m_LastTime;
|
||||
std::size_t m_CurrentStep;
|
||||
|
||||
public:
|
||||
RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime);
|
||||
|
||||
void Update();
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
17
include/td/simulation/WorldSnapshot.h
Normal file
17
include/td/simulation/WorldSnapshot.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/WorldTypes.h>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
struct WorldSnapshot {
|
||||
game::MobList m_Mobs;
|
||||
|
||||
game::TowerList m_Towers;
|
||||
|
||||
game::TeamList m_Teams;
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
40
include/td/simulation/WorldTicker.h
Normal file
40
include/td/simulation/WorldTicker.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/protocol/command/Commands.h>
|
||||
#include <td/simulation/WorldSnapshot.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace sim {
|
||||
|
||||
class IWorldSystem {
|
||||
public:
|
||||
virtual void Tick(const game::World& a_World, WorldSnapshot& a_State, FpFloat a_Delta) = 0;
|
||||
};
|
||||
|
||||
class WorldTicker {
|
||||
private:
|
||||
std::vector<std::unique_ptr<IWorldSystem>> m_Systems;
|
||||
|
||||
public:
|
||||
WorldTicker();
|
||||
|
||||
WorldSnapshot NextStep(
|
||||
const game::World& a_World, const WorldSnapshot& a_PreviousState, const protocol::LockStep& a_LockStep, FpFloat a_Delta);
|
||||
|
||||
private:
|
||||
void ApplySteps(const game::World& a_World, WorldSnapshot& a_State, const protocol::LockStep& a_LockStep);
|
||||
void Tick(const game::World& a_World, WorldSnapshot& a_State, FpFloat a_Delta);
|
||||
WorldSnapshot CreateNext(const WorldSnapshot& a_PreviousState);
|
||||
|
||||
template <typename T>
|
||||
void AddSystem() {
|
||||
m_Systems.push_back(std::move(std::make_unique<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
14
include/td/simulation/system/EntityMove.h
Normal file
14
include/td/simulation/system/EntityMove.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/simulation/WorldTicker.h>
|
||||
|
||||
namespace td {
|
||||
namespace sim {
|
||||
|
||||
class EntityMove : public IWorldSystem {
|
||||
public:
|
||||
virtual void Tick(const game::World& a_World, WorldSnapshot& a_State, FpFloat a_Delta) override;
|
||||
};
|
||||
|
||||
} // namespace sim
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user