indent with tabs
This commit is contained in:
@@ -4,33 +4,33 @@ namespace td {
|
||||
namespace protocol {
|
||||
|
||||
void PacketDispatcher::RegisterHandler(PacketType type, PacketHandler* handler) {
|
||||
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
|
||||
if (found == m_Handlers[type].end())
|
||||
m_Handlers[type].push_back(handler);
|
||||
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
|
||||
if (found == m_Handlers[type].end())
|
||||
m_Handlers[type].push_back(handler);
|
||||
}
|
||||
|
||||
void PacketDispatcher::UnregisterHandler(PacketType type, PacketHandler* handler) {
|
||||
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
|
||||
if (found != m_Handlers[type].end())
|
||||
m_Handlers[type].erase(found);
|
||||
auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), handler);
|
||||
if (found != m_Handlers[type].end())
|
||||
m_Handlers[type].erase(found);
|
||||
}
|
||||
|
||||
void PacketDispatcher::UnregisterHandler(PacketHandler* handler) {
|
||||
for (auto& pair : m_Handlers) {
|
||||
if (pair.second.empty()) continue;
|
||||
for (auto& pair : m_Handlers) {
|
||||
if (pair.second.empty()) continue;
|
||||
|
||||
PacketType type = pair.first;
|
||||
PacketType type = pair.first;
|
||||
|
||||
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), handler), m_Handlers[type].end());
|
||||
}
|
||||
m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), handler), m_Handlers[type].end());
|
||||
}
|
||||
}
|
||||
|
||||
void PacketDispatcher::Dispatch(const PacketPtr& packet) {
|
||||
if (!packet) return;
|
||||
if (!packet) return;
|
||||
|
||||
PacketType type = packet->GetType();
|
||||
for (PacketHandler* handler : m_Handlers[type])
|
||||
packet->Dispatch(handler);
|
||||
PacketType type = packet->GetType();
|
||||
for (PacketHandler* handler : m_Handlers[type])
|
||||
packet->Dispatch(handler);
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
|
||||
@@ -9,38 +9,38 @@ namespace PacketFactory {
|
||||
using PacketCreator = std::function<PacketPtr()>;
|
||||
|
||||
static std::map<PacketType, PacketCreator> packets = {
|
||||
{PacketType::PlayerLogin, []() -> PacketPtr {return std::make_unique<PlayerLoginPacket>();} },
|
||||
{PacketType::WorldBeginData, []() -> PacketPtr {return std::make_unique<WorldBeginDataPacket>();} },
|
||||
{PacketType::WorldData, []() -> PacketPtr {return std::make_unique<WorldDataPacket>();} },
|
||||
{PacketType::KeepAlive, []() -> PacketPtr {return std::make_unique<KeepAlivePacket>();} },
|
||||
{PacketType::UpdateMoney, []() -> PacketPtr {return std::make_unique<UpdateMoneyPacket>();} },
|
||||
{PacketType::UpdateEXP, []() -> PacketPtr {return std::make_unique<UpdateExpPacket>();} },
|
||||
{PacketType::UpdateLobbyTime, []() -> PacketPtr {return std::make_unique<UpdateLobbyTimePacket>(); } },
|
||||
{PacketType::UpdateGameState, []() -> PacketPtr {return std::make_unique<UpdateGameStatePacket>(); } },
|
||||
{PacketType::PlayerList, []() -> PacketPtr {return std::make_unique<PlayerListPacket>(); } },
|
||||
{PacketType::PlayerJoin, []() -> PacketPtr {return std::make_unique<PlayerJoinPacket>(); } },
|
||||
{PacketType::PlayerLeave, []() -> PacketPtr {return std::make_unique<PlayerLeavePacket>(); } },
|
||||
{PacketType::ConnectionInfo, []() -> PacketPtr {return std::make_unique<ConnexionInfoPacket>(); } },
|
||||
{PacketType::SelectTeam, []() -> PacketPtr {return std::make_unique<SelectTeamPacket>(); } },
|
||||
{PacketType::UpdatePlayerTeam, []() -> PacketPtr {return std::make_unique<UpdatePlayerTeamPacket>(); } },
|
||||
{PacketType::Disconnect, []() -> PacketPtr {return std::make_unique<DisconnectPacket>(); } },
|
||||
{PacketType::ServerTps, []() -> PacketPtr {return std::make_unique<ServerTpsPacket>(); } },
|
||||
{PacketType::SpawnMob, []() -> PacketPtr {return std::make_unique<SpawnMobPacket>(); } },
|
||||
{PacketType::PlaceTower, []() -> PacketPtr {return std::make_unique<PlaceTowerPacket>(); } },
|
||||
{PacketType::WorldAddTower, []() -> PacketPtr {return std::make_unique<WorldAddTowerPacket>(); } },
|
||||
{PacketType::RemoveTower, []() -> PacketPtr {return std::make_unique<RemoveTowerPacket>(); } },
|
||||
{PacketType::SendMobs, []() -> PacketPtr {return std::make_unique<SendMobsPacket>(); } },
|
||||
{PacketType::UpgradeTower, []() -> PacketPtr {return std::make_unique<UpgradeTowerPacket>(); } },
|
||||
{PacketType::UpdateCastleLife, []() -> PacketPtr {return std::make_unique<UpdateCastleLifePacket>(); } },
|
||||
{PacketType::UpdateMobStates, []() -> PacketPtr {return std::make_unique<UpdateMobStatesPacket>(); } },
|
||||
{PacketType::PlayerBuyItem, []() -> PacketPtr {return std::make_unique<PlayerBuyItemPacket>(); } },
|
||||
{PacketType::PlayerBuyMobUpgrade, []() -> PacketPtr {return std::make_unique<PlayerBuyMobUpgradePacket>(); } },
|
||||
{PacketType::PlayerLogin, []() -> PacketPtr {return std::make_unique<PlayerLoginPacket>();} },
|
||||
{PacketType::WorldBeginData, []() -> PacketPtr {return std::make_unique<WorldBeginDataPacket>();} },
|
||||
{PacketType::WorldData, []() -> PacketPtr {return std::make_unique<WorldDataPacket>();} },
|
||||
{PacketType::KeepAlive, []() -> PacketPtr {return std::make_unique<KeepAlivePacket>();} },
|
||||
{PacketType::UpdateMoney, []() -> PacketPtr {return std::make_unique<UpdateMoneyPacket>();} },
|
||||
{PacketType::UpdateEXP, []() -> PacketPtr {return std::make_unique<UpdateExpPacket>();} },
|
||||
{PacketType::UpdateLobbyTime, []() -> PacketPtr {return std::make_unique<UpdateLobbyTimePacket>(); } },
|
||||
{PacketType::UpdateGameState, []() -> PacketPtr {return std::make_unique<UpdateGameStatePacket>(); } },
|
||||
{PacketType::PlayerList, []() -> PacketPtr {return std::make_unique<PlayerListPacket>(); } },
|
||||
{PacketType::PlayerJoin, []() -> PacketPtr {return std::make_unique<PlayerJoinPacket>(); } },
|
||||
{PacketType::PlayerLeave, []() -> PacketPtr {return std::make_unique<PlayerLeavePacket>(); } },
|
||||
{PacketType::ConnectionInfo, []() -> PacketPtr {return std::make_unique<ConnexionInfoPacket>(); } },
|
||||
{PacketType::SelectTeam, []() -> PacketPtr {return std::make_unique<SelectTeamPacket>(); } },
|
||||
{PacketType::UpdatePlayerTeam, []() -> PacketPtr {return std::make_unique<UpdatePlayerTeamPacket>(); } },
|
||||
{PacketType::Disconnect, []() -> PacketPtr {return std::make_unique<DisconnectPacket>(); } },
|
||||
{PacketType::ServerTps, []() -> PacketPtr {return std::make_unique<ServerTpsPacket>(); } },
|
||||
{PacketType::SpawnMob, []() -> PacketPtr {return std::make_unique<SpawnMobPacket>(); } },
|
||||
{PacketType::PlaceTower, []() -> PacketPtr {return std::make_unique<PlaceTowerPacket>(); } },
|
||||
{PacketType::WorldAddTower, []() -> PacketPtr {return std::make_unique<WorldAddTowerPacket>(); } },
|
||||
{PacketType::RemoveTower, []() -> PacketPtr {return std::make_unique<RemoveTowerPacket>(); } },
|
||||
{PacketType::SendMobs, []() -> PacketPtr {return std::make_unique<SendMobsPacket>(); } },
|
||||
{PacketType::UpgradeTower, []() -> PacketPtr {return std::make_unique<UpgradeTowerPacket>(); } },
|
||||
{PacketType::UpdateCastleLife, []() -> PacketPtr {return std::make_unique<UpdateCastleLifePacket>(); } },
|
||||
{PacketType::UpdateMobStates, []() -> PacketPtr {return std::make_unique<UpdateMobStatesPacket>(); } },
|
||||
{PacketType::PlayerBuyItem, []() -> PacketPtr {return std::make_unique<PlayerBuyItemPacket>(); } },
|
||||
{PacketType::PlayerBuyMobUpgrade, []() -> PacketPtr {return std::make_unique<PlayerBuyMobUpgradePacket>(); } },
|
||||
};
|
||||
|
||||
PacketPtr CreatePacket(PacketType type, DataBuffer& buffer) {
|
||||
PacketPtr packet = packets[type]();
|
||||
packet->Deserialize(buffer);
|
||||
return packet;
|
||||
PacketPtr packet = packets[type]();
|
||||
packet->Deserialize(buffer);
|
||||
return packet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,559 +13,559 @@ const int BITS_IN_BYTE = 8;
|
||||
const int BITS_IN_LONG = BITS_IN_BYTE * sizeof(std::uint64_t);
|
||||
|
||||
static unsigned int countBits(unsigned int number) {
|
||||
// log function in base 2
|
||||
// take only integer part
|
||||
return static_cast<unsigned int>(std::log2(number) + 1);
|
||||
// log function in base 2
|
||||
// take only integer part
|
||||
return static_cast<unsigned int>(std::log2(number) + 1);
|
||||
}
|
||||
|
||||
void Packet::WritePacketID(DataBuffer& data, bool packetID) const {
|
||||
if (packetID)
|
||||
data << GetID();
|
||||
if (packetID)
|
||||
data << GetID();
|
||||
}
|
||||
|
||||
static DataBuffer& operator<<(DataBuffer& buffer, game::TilePtr tile) {
|
||||
buffer << tile->GetType();
|
||||
buffer << tile->GetType();
|
||||
|
||||
switch (tile->GetType()) {
|
||||
switch (tile->GetType()) {
|
||||
|
||||
case game::TileType::Tower: {
|
||||
const game::TowerTile* towerTile = dynamic_cast<const game::TowerTile*>(tile.get());
|
||||
buffer << towerTile->color_palette_ref << towerTile->team_owner;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Tower: {
|
||||
const game::TowerTile* towerTile = dynamic_cast<const game::TowerTile*>(tile.get());
|
||||
buffer << towerTile->color_palette_ref << towerTile->team_owner;
|
||||
break;
|
||||
}
|
||||
|
||||
case game::TileType::Walk: {
|
||||
const game::WalkableTile* walkTile = dynamic_cast<const game::WalkableTile*>(tile.get());
|
||||
buffer << walkTile->direction;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Walk: {
|
||||
const game::WalkableTile* walkTile = dynamic_cast<const game::WalkableTile*>(tile.get());
|
||||
buffer << walkTile->direction;
|
||||
break;
|
||||
}
|
||||
|
||||
case game::TileType::Decoration: {
|
||||
const game::DecorationTile* decoTile = dynamic_cast<const game::DecorationTile*>(tile.get());
|
||||
buffer << decoTile->color_palette_ref;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Decoration: {
|
||||
const game::DecorationTile* decoTile = dynamic_cast<const game::DecorationTile*>(tile.get());
|
||||
buffer << decoTile->color_palette_ref;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static DataBuffer& operator>>(DataBuffer& buffer, game::TilePtr& tile) {
|
||||
game::TileType tileType;
|
||||
buffer >> tileType;
|
||||
switch (tileType) {
|
||||
case game::TileType::Tower: {
|
||||
auto tilePtr = std::make_shared<game::TowerTile>();
|
||||
buffer >> tilePtr->color_palette_ref >> tilePtr->team_owner;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Walk: {
|
||||
auto tilePtr = std::make_shared<game::WalkableTile>();
|
||||
buffer >> tilePtr->direction;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Decoration: {
|
||||
auto tilePtr = std::make_shared<game::DecorationTile>();
|
||||
buffer >> tilePtr->color_palette_ref;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
game::TileType tileType;
|
||||
buffer >> tileType;
|
||||
switch (tileType) {
|
||||
case game::TileType::Tower: {
|
||||
auto tilePtr = std::make_shared<game::TowerTile>();
|
||||
buffer >> tilePtr->color_palette_ref >> tilePtr->team_owner;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Walk: {
|
||||
auto tilePtr = std::make_shared<game::WalkableTile>();
|
||||
buffer >> tilePtr->direction;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
case game::TileType::Decoration: {
|
||||
auto tilePtr = std::make_shared<game::DecorationTile>();
|
||||
buffer >> tilePtr->color_palette_ref;
|
||||
tile = tilePtr;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
DataBuffer PlayerLoginPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerName;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerName;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerLoginPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_PlayerName;
|
||||
data >> m_PlayerName;
|
||||
}
|
||||
|
||||
DataBuffer WorldBeginDataPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
const game::TowerTileColorPalette& towerTilePalette = m_Header.m_World->GetTowerTileColorPalette();
|
||||
const std::vector<Color>& decoTilePalette = m_Header.m_World->GetDecorationPalette();
|
||||
DataBuffer data;
|
||||
const game::TowerTileColorPalette& towerTilePalette = m_Header.m_World->GetTowerTileColorPalette();
|
||||
const std::vector<Color>& decoTilePalette = m_Header.m_World->GetDecorationPalette();
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
WritePacketID(data, packetID);
|
||||
|
||||
data << towerTilePalette << m_Header.m_World->GetWalkableTileColor()
|
||||
<< static_cast<std::uint16_t>(decoTilePalette.size());
|
||||
data << towerTilePalette << m_Header.m_World->GetWalkableTileColor()
|
||||
<< static_cast<std::uint16_t>(decoTilePalette.size());
|
||||
|
||||
// deco color palette
|
||||
std::size_t bufferSize = data.GetSize();
|
||||
data.Resize(bufferSize + decoTilePalette.size() * sizeof(Color));
|
||||
// deco color palette
|
||||
std::size_t bufferSize = data.GetSize();
|
||||
data.Resize(bufferSize + decoTilePalette.size() * sizeof(Color));
|
||||
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(Color));
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(Color));
|
||||
|
||||
data << m_Header.m_World->GetBackgroundColor();
|
||||
data << m_Header.m_World->GetBackgroundColor();
|
||||
|
||||
const game::Spawn& redSpawn = m_Header.m_World->GetRedTeam().GetSpawn(), blueSpawn = m_Header.m_World->GetBlueTeam().GetSpawn();
|
||||
const game::TeamCastle& redCastle = m_Header.m_World->GetRedTeam().GetCastle(), blueCastle = m_Header.m_World->GetBlueTeam().GetCastle();
|
||||
const game::Spawn& redSpawn = m_Header.m_World->GetRedTeam().GetSpawn(), blueSpawn = m_Header.m_World->GetBlueTeam().GetSpawn();
|
||||
const game::TeamCastle& redCastle = m_Header.m_World->GetRedTeam().GetCastle(), blueCastle = m_Header.m_World->GetBlueTeam().GetCastle();
|
||||
|
||||
data << redSpawn << static_cast<utils::shape::Rectangle>(redCastle);
|
||||
data << blueSpawn << static_cast<utils::shape::Rectangle>(blueCastle);
|
||||
data << redSpawn << static_cast<utils::shape::Rectangle>(redCastle);
|
||||
data << blueSpawn << static_cast<utils::shape::Rectangle>(blueCastle);
|
||||
|
||||
// tile palette
|
||||
data << static_cast<std::uint64_t>(m_Header.m_World->GetTilePalette().size());
|
||||
// tile palette
|
||||
data << static_cast<std::uint64_t>(m_Header.m_World->GetTilePalette().size());
|
||||
|
||||
for (game::TilePtr tile : m_Header.m_World->GetTilePalette()) {
|
||||
data << tile;
|
||||
}
|
||||
for (game::TilePtr tile : m_Header.m_World->GetTilePalette()) {
|
||||
data << tile;
|
||||
}
|
||||
|
||||
data << m_Header.m_World->GetSpawnColors();
|
||||
data << m_Header.m_World->GetSpawnColors();
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
void WorldBeginDataPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_Header.m_TowerPlacePalette >> m_Header.m_WalkablePalette;
|
||||
data >> m_Header.m_TowerPlacePalette >> m_Header.m_WalkablePalette;
|
||||
|
||||
std::uint16_t decoPaletteSize;
|
||||
data >> decoPaletteSize;
|
||||
std::uint16_t decoPaletteSize;
|
||||
data >> decoPaletteSize;
|
||||
|
||||
std::size_t decoPalletteSizeByte = decoPaletteSize * sizeof(Color);
|
||||
std::size_t decoPalletteSizeByte = decoPaletteSize * sizeof(Color);
|
||||
|
||||
m_Header.m_DecorationPalette.resize(decoPaletteSize);
|
||||
m_Header.m_DecorationPalette.resize(decoPaletteSize);
|
||||
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(m_Header.m_DecorationPalette.data()), data.data() + data.GetReadOffset(), decoPalletteSizeByte);
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(m_Header.m_DecorationPalette.data()), data.data() + data.GetReadOffset(), decoPalletteSizeByte);
|
||||
|
||||
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
||||
data.SetReadOffset(data.GetReadOffset() + decoPalletteSizeByte);
|
||||
|
||||
data >> m_Header.m_Background;
|
||||
data >> m_Header.m_Background;
|
||||
|
||||
utils::shape::Rectangle redCastle, blueCastle;
|
||||
utils::shape::Rectangle redCastle, blueCastle;
|
||||
|
||||
data >> m_Header.m_RedSpawn >> redCastle;
|
||||
data >> m_Header.m_BlueSpawn >> blueCastle;
|
||||
data >> m_Header.m_RedSpawn >> redCastle;
|
||||
data >> m_Header.m_BlueSpawn >> blueCastle;
|
||||
|
||||
m_Header.m_RedCastle.SetShape(redCastle);
|
||||
m_Header.m_BlueCastle.SetShape(blueCastle);
|
||||
m_Header.m_RedCastle.SetShape(redCastle);
|
||||
m_Header.m_BlueCastle.SetShape(blueCastle);
|
||||
|
||||
std::uint64_t tilePaletteSize;
|
||||
data >> tilePaletteSize;
|
||||
std::uint64_t tilePaletteSize;
|
||||
data >> tilePaletteSize;
|
||||
|
||||
m_Header.m_TilePalette.reserve(tilePaletteSize);
|
||||
m_Header.m_TilePalette.reserve(tilePaletteSize);
|
||||
|
||||
for (std::uint64_t tileNumber = 0; tileNumber < tilePaletteSize; tileNumber++) {
|
||||
game::TilePtr tile;
|
||||
data >> tile;
|
||||
m_Header.m_TilePalette.push_back(tile);
|
||||
}
|
||||
for (std::uint64_t tileNumber = 0; tileNumber < tilePaletteSize; tileNumber++) {
|
||||
game::TilePtr tile;
|
||||
data >> tile;
|
||||
m_Header.m_TilePalette.push_back(tile);
|
||||
}
|
||||
|
||||
data >> m_Header.m_SpawnColorPalette;
|
||||
data >> m_Header.m_SpawnColorPalette;
|
||||
}
|
||||
|
||||
typedef std::vector<uint64_t> ChunkPackedData;
|
||||
|
||||
DataBuffer WorldDataPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
WritePacketID(data, packetID);
|
||||
|
||||
data << m_World->GetChunks().size();
|
||||
for (const auto& pair : m_World->GetChunks()) {
|
||||
game::ChunkCoord coords = pair.first;
|
||||
game::ChunkPtr chunk = pair.second;
|
||||
data << m_World->GetChunks().size();
|
||||
for (const auto& pair : m_World->GetChunks()) {
|
||||
game::ChunkCoord coords = pair.first;
|
||||
game::ChunkPtr chunk = pair.second;
|
||||
|
||||
data << coords.x << coords.y << static_cast<std::uint64_t>(chunk->palette.size());
|
||||
data << coords.x << coords.y << static_cast<std::uint64_t>(chunk->palette.size());
|
||||
|
||||
std::size_t bufferSize = data.GetSize();
|
||||
data.Resize(data.GetSize() + chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunk->palette.data(), chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
||||
std::size_t bufferSize = data.GetSize();
|
||||
data.Resize(data.GetSize() + chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunk->palette.data(), chunk->palette.size() * sizeof(game::ChunkPalette::value_type));
|
||||
|
||||
std::uint8_t bitsPerTile = countBits(chunk->palette.size());
|
||||
std::uint8_t bitsPerTile = countBits(chunk->palette.size());
|
||||
|
||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
||||
|
||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
||||
|
||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
||||
std::size_t startLong = static_cast<std::size_t>((tileNumber * bitsPerTile) / BITS_IN_LONG);
|
||||
std::size_t startOffset = static_cast<std::size_t>((tileNumber * bitsPerTile) % BITS_IN_LONG);
|
||||
std::size_t endLong = static_cast<std::size_t>(((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG);
|
||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
||||
std::size_t startLong = static_cast<std::size_t>((tileNumber * bitsPerTile) / BITS_IN_LONG);
|
||||
std::size_t startOffset = static_cast<std::size_t>((tileNumber * bitsPerTile) % BITS_IN_LONG);
|
||||
std::size_t endLong = static_cast<std::size_t>(((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG);
|
||||
|
||||
std::uint64_t value = static_cast<std::uint64_t>(chunk->tiles[tileNumber]);
|
||||
std::uint64_t value = static_cast<std::uint64_t>(chunk->tiles[tileNumber]);
|
||||
|
||||
value &= individualValueMask;
|
||||
value &= individualValueMask;
|
||||
|
||||
chunkData[startLong] |= (value << startOffset);
|
||||
chunkData[startLong] |= (value << startOffset);
|
||||
|
||||
if (startLong != endLong) {
|
||||
chunkData[endLong] = (value >> (BITS_IN_LONG - startOffset));
|
||||
}
|
||||
}
|
||||
if (startLong != endLong) {
|
||||
chunkData[endLong] = (value >> (BITS_IN_LONG - startOffset));
|
||||
}
|
||||
}
|
||||
|
||||
bufferSize = data.GetSize();
|
||||
data.Resize(data.GetSize() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunkData.data(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
}
|
||||
return data;
|
||||
bufferSize = data.GetSize();
|
||||
data.Resize(data.GetSize() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
memcpy(reinterpret_cast<std::uint8_t*>(data.data()) + bufferSize, chunkData.data(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void WorldDataPacket::Deserialize(DataBuffer& data) {
|
||||
std::uint64_t chunkCount;
|
||||
data >> chunkCount;
|
||||
std::uint64_t chunkCount;
|
||||
data >> chunkCount;
|
||||
|
||||
for (std::uint64_t chunkNumber = 0; chunkNumber < chunkCount; chunkNumber++) {
|
||||
game::ChunkPtr chunk = std::make_shared<game::Chunk>();
|
||||
for (std::uint64_t chunkNumber = 0; chunkNumber < chunkCount; chunkNumber++) {
|
||||
game::ChunkPtr chunk = std::make_shared<game::Chunk>();
|
||||
|
||||
decltype(game::ChunkCoord::x) chunkX, chunkY;
|
||||
data >> chunkX >> chunkY;
|
||||
decltype(game::ChunkCoord::x) chunkX, chunkY;
|
||||
data >> chunkX >> chunkY;
|
||||
|
||||
std::uint64_t chunkPaletteSize;
|
||||
data >> chunkPaletteSize;
|
||||
std::uint64_t chunkPaletteSize;
|
||||
data >> chunkPaletteSize;
|
||||
|
||||
game::ChunkPalette chunkPalette(chunkPaletteSize);
|
||||
game::ChunkPalette chunkPalette(chunkPaletteSize);
|
||||
|
||||
memcpy(reinterpret_cast<void*>(chunkPalette.data()), data.data() + data.GetReadOffset(), chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
||||
data.SetReadOffset(data.GetReadOffset() + chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
||||
memcpy(reinterpret_cast<void*>(chunkPalette.data()), data.data() + data.GetReadOffset(), chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
||||
data.SetReadOffset(data.GetReadOffset() + chunkPaletteSize * sizeof(game::ChunkPalette::value_type));
|
||||
|
||||
chunk->palette = chunkPalette;
|
||||
chunk->palette = chunkPalette;
|
||||
|
||||
std::uint8_t bitsPerTile = countBits(chunkPaletteSize);
|
||||
std::uint8_t bitsPerTile = countBits(chunkPaletteSize);
|
||||
|
||||
// A bitmask that contains bitsPerTile set bits
|
||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
||||
// A bitmask that contains bitsPerTile set bits
|
||||
game::Chunk::ChunkData::value_type individualValueMask = ((1 << bitsPerTile) - 1);
|
||||
|
||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
||||
ChunkPackedData chunkData(game::Chunk::ChunkSize / (BITS_IN_BYTE * sizeof(ChunkPackedData::value_type) / bitsPerTile), 0);
|
||||
|
||||
memcpy(reinterpret_cast<void*>(chunkData.data()), data.data() + data.GetReadOffset(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
data.SetReadOffset(data.GetReadOffset() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
memcpy(reinterpret_cast<void*>(chunkData.data()), data.data() + data.GetReadOffset(), chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
data.SetReadOffset(data.GetReadOffset() + chunkData.size() * sizeof(ChunkPackedData::value_type));
|
||||
|
||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
||||
std::size_t startLong = (tileNumber * bitsPerTile) / BITS_IN_LONG;
|
||||
std::size_t startOffset = (tileNumber * bitsPerTile) % BITS_IN_LONG;
|
||||
std::size_t endLong = ((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG;
|
||||
for (unsigned int tileNumber = 0; tileNumber < game::Chunk::ChunkSize; tileNumber++) {
|
||||
std::size_t startLong = (tileNumber * bitsPerTile) / BITS_IN_LONG;
|
||||
std::size_t startOffset = (tileNumber * bitsPerTile) % BITS_IN_LONG;
|
||||
std::size_t endLong = ((tileNumber + 1) * bitsPerTile - 1) / BITS_IN_LONG;
|
||||
|
||||
game::Chunk::ChunkData::value_type value;
|
||||
if (startLong == endLong) {
|
||||
value = (chunkData[startLong] >> startOffset);
|
||||
} else {
|
||||
int endOffset = BITS_IN_LONG - startOffset;
|
||||
value = (chunkData[startLong] >> startOffset | chunkData[endLong] << endOffset);
|
||||
}
|
||||
value &= individualValueMask;
|
||||
game::Chunk::ChunkData::value_type value;
|
||||
if (startLong == endLong) {
|
||||
value = (chunkData[startLong] >> startOffset);
|
||||
} else {
|
||||
int endOffset = BITS_IN_LONG - startOffset;
|
||||
value = (chunkData[startLong] >> startOffset | chunkData[endLong] << endOffset);
|
||||
}
|
||||
value &= individualValueMask;
|
||||
|
||||
chunk->tiles[tileNumber] = value;
|
||||
}
|
||||
chunk->tiles[tileNumber] = value;
|
||||
}
|
||||
|
||||
|
||||
m_WorldData.m_Chunks.insert({ {chunkX, chunkY}, chunk });
|
||||
}
|
||||
m_WorldData.m_Chunks.insert({ {chunkX, chunkY}, chunk });
|
||||
}
|
||||
}
|
||||
|
||||
DataBuffer KeepAlivePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_AliveID;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_AliveID;
|
||||
return data;
|
||||
}
|
||||
|
||||
void KeepAlivePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_AliveID;
|
||||
data >> m_AliveID;
|
||||
}
|
||||
|
||||
DataBuffer UpdateMoneyPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_NewAmount;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_NewAmount;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateMoneyPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_NewAmount;
|
||||
data >> m_NewAmount;
|
||||
}
|
||||
|
||||
DataBuffer UpdateExpPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_NewAmount;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_NewAmount;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateExpPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_NewAmount;
|
||||
data >> m_NewAmount;
|
||||
}
|
||||
|
||||
DataBuffer UpdateLobbyTimePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_RemainingTime;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_RemainingTime;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateLobbyTimePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_RemainingTime;
|
||||
data >> m_RemainingTime;
|
||||
}
|
||||
|
||||
DataBuffer UpdateGameStatePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_GameState;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_GameState;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateGameStatePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_GameState;
|
||||
data >> m_GameState;
|
||||
}
|
||||
|
||||
DataBuffer PlayerListPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint8_t>(m_Players.size());
|
||||
for (auto [playerID, playerInfo] : m_Players) {
|
||||
data << playerID << playerInfo.name << playerInfo.team;
|
||||
}
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint8_t>(m_Players.size());
|
||||
for (auto [playerID, playerInfo] : m_Players) {
|
||||
data << playerID << playerInfo.name << playerInfo.team;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerListPacket::Deserialize(DataBuffer& data) {
|
||||
std::uint8_t playerCount;
|
||||
data >> playerCount;
|
||||
std::uint8_t playerCount;
|
||||
data >> playerCount;
|
||||
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
std::uint8_t playerID;
|
||||
PlayerInfo playerInfo;
|
||||
data >> playerID >> playerInfo.name >> playerInfo.team;
|
||||
m_Players.insert({ playerID, playerInfo });
|
||||
}
|
||||
for (int i = 0; i < playerCount; i++) {
|
||||
std::uint8_t playerID;
|
||||
PlayerInfo playerInfo;
|
||||
data >> playerID >> playerInfo.name >> playerInfo.team;
|
||||
m_Players.insert({ playerID, playerInfo });
|
||||
}
|
||||
}
|
||||
|
||||
DataBuffer PlayerJoinPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID << m_PlayerName;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID << m_PlayerName;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerJoinPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_PlayerID >> m_PlayerName;
|
||||
data >> m_PlayerID >> m_PlayerName;
|
||||
}
|
||||
|
||||
DataBuffer PlayerLeavePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerLeavePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_PlayerID;
|
||||
data >> m_PlayerID;
|
||||
}
|
||||
|
||||
DataBuffer ConnexionInfoPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_ConnectionID;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_ConnectionID;
|
||||
return data;
|
||||
}
|
||||
|
||||
void ConnexionInfoPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_ConnectionID;
|
||||
data >> m_ConnectionID;
|
||||
}
|
||||
|
||||
DataBuffer SelectTeamPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_SelectedTeam;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_SelectedTeam;
|
||||
return data;
|
||||
}
|
||||
|
||||
void SelectTeamPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_SelectedTeam;
|
||||
data >> m_SelectedTeam;
|
||||
}
|
||||
|
||||
DataBuffer UpdatePlayerTeamPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID << m_SelectedTeam;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID << m_SelectedTeam;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdatePlayerTeamPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_PlayerID >> m_SelectedTeam;
|
||||
data >> m_PlayerID >> m_SelectedTeam;
|
||||
}
|
||||
|
||||
DataBuffer DisconnectPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_Reason;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_Reason;
|
||||
return data;
|
||||
}
|
||||
|
||||
void DisconnectPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_Reason;
|
||||
data >> m_Reason;
|
||||
}
|
||||
|
||||
DataBuffer ServerTpsPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TPS << m_PacketSendTime;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TPS << m_PacketSendTime;
|
||||
return data;
|
||||
}
|
||||
|
||||
void ServerTpsPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_TPS >> m_PacketSendTime;
|
||||
data >> m_TPS >> m_PacketSendTime;
|
||||
}
|
||||
|
||||
DataBuffer SpawnMobPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_MobID << m_MobType << m_MobLevel << m_MobDirection
|
||||
<< m_Sender << m_MobX << m_MobY;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_MobID << m_MobType << m_MobLevel << m_MobDirection
|
||||
<< m_Sender << m_MobX << m_MobY;
|
||||
return data;
|
||||
}
|
||||
|
||||
void SpawnMobPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_MobID >> m_MobType >> m_MobLevel >> m_MobDirection
|
||||
>> m_Sender >> m_MobX >> m_MobY;
|
||||
data >> m_MobID >> m_MobType >> m_MobLevel >> m_MobDirection
|
||||
>> m_Sender >> m_MobX >> m_MobY;
|
||||
}
|
||||
|
||||
DataBuffer PlaceTowerPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerX << m_TowerY << m_TowerType;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerX << m_TowerY << m_TowerType;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlaceTowerPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_TowerX >> m_TowerY >> m_TowerType;
|
||||
data >> m_TowerX >> m_TowerY >> m_TowerType;
|
||||
}
|
||||
|
||||
DataBuffer WorldAddTowerPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID << m_TowerX << m_TowerY << m_TowerType << m_Builder;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID << m_TowerX << m_TowerY << m_TowerType << m_Builder;
|
||||
return data;
|
||||
}
|
||||
|
||||
void WorldAddTowerPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_TowerID >> m_TowerX >> m_TowerY >> m_TowerType >> m_Builder;
|
||||
data >> m_TowerID >> m_TowerX >> m_TowerY >> m_TowerType >> m_Builder;
|
||||
}
|
||||
|
||||
DataBuffer RemoveTowerPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID;
|
||||
return data;
|
||||
}
|
||||
|
||||
void RemoveTowerPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_TowerID;
|
||||
data >> m_TowerID;
|
||||
}
|
||||
|
||||
DataBuffer SendMobsPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint8_t>(m_MobSends.size());
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint8_t>(m_MobSends.size());
|
||||
|
||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobSends.data()), m_MobSends.size() * sizeof(m_MobSends));
|
||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobSends.data()), m_MobSends.size() * sizeof(m_MobSends));
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
void SendMobsPacket::Deserialize(DataBuffer& data) {
|
||||
std::uint8_t mobSendCount;
|
||||
data >> mobSendCount;
|
||||
std::uint8_t mobSendCount;
|
||||
data >> mobSendCount;
|
||||
|
||||
m_MobSends.resize(mobSendCount);
|
||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobSends.data()), mobSendCount * sizeof(MobSend));
|
||||
m_MobSends.resize(mobSendCount);
|
||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobSends.data()), mobSendCount * sizeof(MobSend));
|
||||
}
|
||||
|
||||
DataBuffer UpgradeTowerPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID << m_TowerLevel;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_TowerID << m_TowerLevel;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpgradeTowerPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_TowerID >> m_TowerLevel;
|
||||
data >> m_TowerID >> m_TowerLevel;
|
||||
}
|
||||
|
||||
DataBuffer UpdateCastleLifePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_CastleLife << m_Team;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_CastleLife << m_Team;
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateCastleLifePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_CastleLife >> m_Team;
|
||||
data >> m_CastleLife >> m_Team;
|
||||
}
|
||||
|
||||
DataBuffer UpdateMobStatesPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint64_t>(m_MobStates.size());
|
||||
WritePacketID(data, packetID);
|
||||
data << static_cast<std::uint64_t>(m_MobStates.size());
|
||||
|
||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobStates.data()), m_MobStates.size() * sizeof(MobState));
|
||||
return data;
|
||||
data.WriteSome(reinterpret_cast<const std::uint8_t*>(m_MobStates.data()), m_MobStates.size() * sizeof(MobState));
|
||||
return data;
|
||||
}
|
||||
|
||||
void UpdateMobStatesPacket::Deserialize(DataBuffer& data) {
|
||||
std::uint64_t mobCount;
|
||||
data >> mobCount;
|
||||
m_MobStates.resize(mobCount);
|
||||
|
||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobStates.data()), mobCount * sizeof(MobState));
|
||||
std::uint64_t mobCount;
|
||||
data >> mobCount;
|
||||
m_MobStates.resize(mobCount);
|
||||
|
||||
data.ReadSome(reinterpret_cast<std::uint8_t*>(m_MobStates.data()), mobCount * sizeof(MobState));
|
||||
}
|
||||
|
||||
DataBuffer PlayerBuyItemPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_ItemType << m_Count;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_ItemType << m_Count;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerBuyItemPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_ItemType >> m_Count;
|
||||
data >> m_ItemType >> m_Count;
|
||||
}
|
||||
|
||||
DataBuffer PlayerBuyMobUpgradePacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_MobType << m_MobLevel;
|
||||
return data;
|
||||
WritePacketID(data, packetID);
|
||||
data << m_MobType << m_MobLevel;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerBuyMobUpgradePacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_MobType >> m_MobLevel;
|
||||
data >> m_MobType >> m_MobLevel;
|
||||
}
|
||||
|
||||
REGISTER_DISPATCH_CLASS(PlayerLoginPacket)
|
||||
|
||||
Reference in New Issue
Block a user