begin client-server
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <sp/common/DataBufferOperators.h>
|
||||
|
||||
namespace td {
|
||||
|
||||
@@ -183,6 +183,35 @@ T Lerp(T v0, T v1, T t) {
|
||||
|
||||
} // namespace maths
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec2<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec3<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec3<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec4<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z << a_Vec.w;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec4<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z >> a_Vec.w;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
||||
@@ -12,6 +12,10 @@ namespace td {
|
||||
|
||||
using FpFloat = fpm::fixed_16_16;
|
||||
|
||||
using StepTime = std::uint16_t;
|
||||
|
||||
constexpr int STEP_TIME = 50;
|
||||
|
||||
enum class TeamColor : std::int8_t {
|
||||
None = -1,
|
||||
Blue,
|
||||
@@ -61,15 +65,11 @@ using TowerID = std::uint16_t;
|
||||
using PlayerID = std::uint8_t;
|
||||
using EntityID = std::uint16_t;
|
||||
|
||||
struct TowerCoords {
|
||||
std::int16_t x;
|
||||
std::int16_t y;
|
||||
};
|
||||
using TowerCoords = Vec2<std::int16_t>;
|
||||
|
||||
using EntityCoords = Vec2<FpFloat>;
|
||||
|
||||
using PeerID = std::uint16_t;
|
||||
using StepsType = std::uint16_t;
|
||||
|
||||
enum class Direction : std::uint8_t {
|
||||
PositiveX = 1 << 0,
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/simulation/WorldTicker.h>
|
||||
#include <td/game/WorldTypes.h>
|
||||
#include <td/protocol/packet/Packets.h>
|
||||
#include <td/simulation/WorldTicker.h>
|
||||
|
||||
namespace td {
|
||||
namespace game {
|
||||
|
||||
class World {
|
||||
protected:
|
||||
// header
|
||||
TowerTileColorPalette m_TowerPlacePalette;
|
||||
Color m_WalkablePalette;
|
||||
std::vector<Color> m_DecorationPalette;
|
||||
Color m_Background;
|
||||
|
||||
ChunkList m_Chunks;
|
||||
|
||||
SpawnColorPalette m_SpawnColorPalette;
|
||||
|
||||
TilePalette m_TilePalette;
|
||||
|
||||
//data
|
||||
ChunkList m_Chunks;
|
||||
|
||||
std::shared_ptr<sim::WorldSnapshot> m_CurrentState;
|
||||
std::shared_ptr<sim::WorldSnapshot> m_NextState;
|
||||
|
||||
@@ -28,6 +28,7 @@ class World {
|
||||
|
||||
public:
|
||||
World();
|
||||
World(World&&) = default;
|
||||
|
||||
bool LoadMap(const protocol::pdata::WorldHeader& worldHeader);
|
||||
bool LoadMap(const protocol::pdata::WorldData& worldData);
|
||||
@@ -130,8 +131,9 @@ class World {
|
||||
private:
|
||||
void TickMobs(std::uint64_t delta);
|
||||
void CleanDeadMobs();
|
||||
|
||||
};
|
||||
|
||||
using WorldPtr = std::shared_ptr<World>;
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
@@ -7,7 +7,11 @@
|
||||
#include <td/game/WorldTypes.h>
|
||||
|
||||
// Make it dynamic ?
|
||||
#ifdef NDEBUG
|
||||
#define LOCKSTEP_BUFFER_SIZE 10
|
||||
#else
|
||||
#define LOCKSTEP_BUFFER_SIZE 1
|
||||
#endif
|
||||
|
||||
namespace td {
|
||||
namespace protocol {
|
||||
@@ -45,7 +49,7 @@ struct PlayerLeave {
|
||||
|
||||
struct PredictCommand {
|
||||
CommandPtr m_Command;
|
||||
std::uint16_t m_FrameNumber;
|
||||
StepTime m_FrameNumber;
|
||||
};
|
||||
|
||||
/** Keep alive */
|
||||
@@ -73,7 +77,7 @@ struct BeginGame {
|
||||
};
|
||||
|
||||
struct LockSteps {
|
||||
std::uint16_t m_FirstFrameNumber;
|
||||
StepTime m_FirstFrameNumber;
|
||||
std::array<LockStep, LOCKSTEP_BUFFER_SIZE> m_LockSteps;
|
||||
};
|
||||
|
||||
@@ -95,6 +99,7 @@ struct WorldData {
|
||||
game::ChunkList m_Chunks;
|
||||
};
|
||||
|
||||
// TODO: spawn multiple troops at the same time
|
||||
struct SpawnTroop {
|
||||
sp::BitField<EntityType, 5> m_Type;
|
||||
sp::BitField<std::uint8_t, 3> m_Level;
|
||||
|
||||
@@ -4,36 +4,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec2<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec3<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec3<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec4<T>& a_Vec) {
|
||||
return a_Buffer << a_Vec.x << a_Vec.y << a_Vec.z << a_Vec.w;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, Vec4<T>& a_Vec) {
|
||||
return a_Buffer >> a_Vec.x >> a_Vec.y >> a_Vec.z >> a_Vec.w;
|
||||
}
|
||||
|
||||
namespace game {
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#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 = StepsType;
|
||||
|
||||
std::vector<std::optional<protocol::LockStep>> m_History;
|
||||
|
||||
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;
|
||||
|
||||
void FromPacket(td::protocol::pdata::LockSteps&& a_Steps);
|
||||
|
||||
td::protocol::packets::LockStepsPacket ToPacket(HistorySizeType a_StartIndex);
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace td
|
||||
@@ -25,6 +25,8 @@ class ServerSimulation : public protocol::CommandHandler {
|
||||
|
||||
protocol::packets::LockStepsPacket Update();
|
||||
|
||||
protocol::packets::LockStepsPacket MakePacket();
|
||||
|
||||
// no checks are done !
|
||||
|
||||
virtual void Handle(const protocol::commands::SpawnTroopCommand& a_SpawnTroop) override;
|
||||
|
||||
Reference in New Issue
Block a user