begin serversimulation

This commit is contained in:
2025-08-03 18:20:21 +02:00
parent c0a560a16e
commit 731c742346
6 changed files with 58 additions and 25 deletions

View File

@@ -21,10 +21,8 @@ struct UpgradeTower {
sp::BitField<std::uint8_t, 4> m_Upgrade;
};
using EntityTypeInt = std::uint8_t;
struct SpawnTroop {
sp::BitField<EntityTypeInt, 5> m_Type;
sp::BitField<EntityType, 5> m_Type;
sp::BitField<std::uint8_t, 3> m_Level;
EntityCoords m_Position;
PlayerID m_Sender;

View File

@@ -95,6 +95,16 @@ struct WorldData {
game::ChunkList m_Chunks;
};
struct SpawnTroop {
sp::BitField<EntityType, 5> m_Type;
sp::BitField<std::uint8_t, 3> m_Level;
};
struct PlaceTower {
TowerType m_Type;
TowerCoords m_Position;
};
} // namespace pdata
} // namespace protocol
} // namespace td

View File

@@ -9,7 +9,8 @@ namespace sim {
using GameHistory = std::vector<td::protocol::LockStep>;
using GameBuffer = std::vector<std::optional<td::protocol::LockStep>>;
class RealTimeSimulation {
// TODO: OnEnd signal
class ClientSimulation : public protocol::PacketHandler {
private:
std::uint64_t m_StepTime;
game::World& m_World;
@@ -28,21 +29,21 @@ class RealTimeSimulation {
* \brief Replay constructor
* \param a_StepTime in ms
*/
RealTimeSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime);
ClientSimulation(game::World& a_World, GameHistory&& a_History, std::uint64_t a_StepTime);
/**
* \brief Live update constructor (continuous game updates)
* \param a_StepTime in ms
*/
RealTimeSimulation(game::World& a_World, std::uint64_t a_StepTime);
ClientSimulation(game::World& a_World, std::uint64_t a_StepTime);
/**
* \return the progress [0-1] between two steps
*/
float Update();
void HandlePacket(const protocol::packets::LockStepsPacket& a_LockSteps);
void HandlePacket(const protocol::packets::PredictCommandPacket& a_Predict);
void Handle(const protocol::packets::LockStepsPacket& a_LockSteps) override;
void Handle(const protocol::packets::PredictCommandPacket& a_Predict) override;
private:
void Step();

View File

@@ -0,0 +1,22 @@
#pragma once
#include <td/game/World.h>
namespace td {
namespace sim {
// TODO: OnEnd signal
class ServerSimulation {
private:
game::World& m_World;
std::uint64_t m_StepTime;
std::uint64_t m_CurrentTime;
public:
ServerSimulation(game::World& a_World, std::uint64_t a_StepTime);
void Update();
};
} // namespace sim
} // namespace td