finish serialize

This commit is contained in:
2024-10-18 15:36:00 +02:00
parent 69d96b40ec
commit 871caf9056
9 changed files with 337 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ enum class Team : std::uint8_t {
Red,
};
enum class CastleType : std::uint8_t {
enum class TowerType : std::uint8_t {
Archer = 0,
Leach,
Artillery,
@@ -49,11 +49,11 @@ enum class ShopItem : std::uint8_t {
Heal,
};
using CastleID = std::uint16_t;
using TowerID = std::uint16_t;
using PlayerID = std::uint8_t;
using EntityID = std::uint16_t;
struct CastleCoords {
struct TowerCoords {
std::int16_t x;
std::int16_t y;
};

View File

@@ -1,8 +1,8 @@
#pragma once
#include <array>
#include <string>
#include <td/Types.h>
#include <array>
namespace td {
namespace protocol {
@@ -11,13 +11,13 @@ namespace cdata {
struct PlaceTower {
CastleType m_Type : 4;
TowerType m_Type : 4;
PlayerID m_Placer : 4;
CastleCoords m_Position;
TowerCoords m_Position;
};
struct UpgradeTower {
CastleID m_Tower : 12;
TowerID m_Tower : 12;
std::uint8_t m_Upgrade : 4;
};

View File

@@ -8,11 +8,11 @@ namespace protocol {
namespace CommandFactory {
template <typename CommandDerived, typename = typename std::enable_if<std::is_base_of<Command, CommandDerived>::value>::type>
std::unique_ptr<CommandDerived> CreateCommand() {
return std::make_unique<CommandDerived>();
std::shared_ptr<CommandDerived> CreateCommand() {
return std::make_shared<CommandDerived>();
}
const std::unique_ptr<Command>& CreateReadOnlyCommand(CommandType a_Type);
const std::shared_ptr<Command>& CreateReadOnlyCommand(CommandType a_Type);
} // namespace CommandFactory
} // namespace protocol

View File

@@ -8,13 +8,13 @@ namespace protocol {
class Command;
using CommandPtr = std::unique_ptr<Command>;
using CommandPtr = std::shared_ptr<Command>;
namespace CommandSerializer {
DataBuffer Serialize(const Command& a_Command);
std::unique_ptr<Command> Deserialize(DataBuffer& a_Data);
std::shared_ptr<Command> Deserialize(DataBuffer& a_Data);
} // namespace CommandSerializer
} // namespace protocol