Finished tedious encapsulation of the packet classes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. packet_types ../utilities ../gameplay ../map
|
||||
INCLUDES+=. packet_types ../gameplay ../map ../utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -19,56 +19,54 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
#include "character_packet.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeCharacter(CharacterPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void CharacterPacket::Serialize(void* buffer) {
|
||||
serialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the character
|
||||
SERIALIZE(buffer, &packet->characterIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
||||
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
||||
serialize(&buffer, &characterIndex, sizeof(int));
|
||||
serialize(&buffer, &handle, PACKET_STRING_SIZE);
|
||||
serialize(&buffer, &avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//the owner
|
||||
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
serialize(&buffer, &accountIndex, sizeof(int));
|
||||
|
||||
//location
|
||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
SERIALIZE(buffer, &packet->motion.x, sizeof(double));
|
||||
SERIALIZE(buffer, &packet->motion.y, sizeof(double));
|
||||
serialize(&buffer, &roomIndex, sizeof(int));
|
||||
serialize(&buffer, &origin.x, sizeof(double));
|
||||
serialize(&buffer, &origin.y, sizeof(double));
|
||||
serialize(&buffer, &motion.x, sizeof(double));
|
||||
serialize(&buffer, &motion.y, sizeof(double));
|
||||
|
||||
//stats structure
|
||||
serializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
serializeStatistics(&buffer, &stats);
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
}
|
||||
|
||||
void deserializeCharacter(CharacterPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void CharacterPacket::Deserialize(void* buffer) {
|
||||
deserialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the character
|
||||
DESERIALIZE(buffer, &packet->characterIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
||||
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
||||
deserialize(&buffer, &characterIndex, sizeof(int));
|
||||
deserialize(&buffer, &handle, PACKET_STRING_SIZE);
|
||||
deserialize(&buffer, &avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//the owner
|
||||
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
deserialize(&buffer, &accountIndex, sizeof(int));
|
||||
|
||||
//location
|
||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
DESERIALIZE(buffer, &packet->motion.x, sizeof(double));
|
||||
DESERIALIZE(buffer, &packet->motion.y, sizeof(double));
|
||||
deserialize(&buffer, &roomIndex, sizeof(int));
|
||||
deserialize(&buffer, &origin.x, sizeof(double));
|
||||
deserialize(&buffer, &origin.y, sizeof(double));
|
||||
deserialize(&buffer, &motion.x, sizeof(double));
|
||||
deserialize(&buffer, &motion.y, sizeof(double));
|
||||
|
||||
//stats structure
|
||||
deserializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
deserializeStatistics(&buffer, &stats);
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
}
|
||||
|
||||
@@ -27,11 +27,49 @@
|
||||
#include "vector2.hpp"
|
||||
#include "statistics.hpp"
|
||||
|
||||
struct CharacterPacket : SerialPacketBase {
|
||||
#include <cstring>
|
||||
|
||||
class CharacterPacket : public SerialPacketBase {
|
||||
public:
|
||||
CharacterPacket() {}
|
||||
~CharacterPacket() {}
|
||||
|
||||
//indentity
|
||||
int SetCharacterIndex(int i) { return characterIndex = i; }
|
||||
const char* SetHandle(const char* s)
|
||||
{ return strncpy(handle, s, PACKET_STRING_SIZE); }
|
||||
const char* SetAvatar(const char* s)
|
||||
{ return strncpy(handle, s, PACKET_STRING_SIZE); }
|
||||
|
||||
int SetAccountIndex(int i) { return accountIndex = i; }
|
||||
|
||||
int GetCharacterIndex() { return characterIndex; }
|
||||
const char* GetHandle() { return handle; }
|
||||
const char* GetAvatar() { return avatar; }
|
||||
|
||||
int GetAccountIndex() { return accountIndex; }
|
||||
|
||||
//location
|
||||
int SetRoomIndex(int i) { return roomIndex = i; }
|
||||
Vector2 SetOrigin(Vector2 v) { return origin = v; }
|
||||
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
||||
|
||||
int GetRoomIndex() { return roomIndex; }
|
||||
Vector2 GetOrigin() { return origin; }
|
||||
Vector2 GetMotion() { return motion; }
|
||||
|
||||
//gameplay
|
||||
Statistics* GetStatistics() { return &stats; }
|
||||
|
||||
protected:
|
||||
virtual void Serialize(void* buffer) override;
|
||||
virtual void Deserialize(void* buffer) override;
|
||||
|
||||
private:
|
||||
//identify the character
|
||||
int characterIndex;
|
||||
char handle[PACKET_STRING_SIZE];
|
||||
char avatar[PACKET_STRING_SIZE];
|
||||
char handle[PACKET_STRING_SIZE+1];
|
||||
char avatar[PACKET_STRING_SIZE+1];
|
||||
|
||||
//the owner
|
||||
int accountIndex;
|
||||
|
||||
@@ -19,24 +19,22 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
#include "client_packet.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeClient(ClientPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void ClientPacket::Serialize(void* buffer) {
|
||||
serialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
SERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
||||
// SERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
||||
serialize(&buffer, &clientIndex, sizeof(int));
|
||||
serialize(&buffer, &accountIndex, sizeof(int));
|
||||
serialize(&buffer, username, PACKET_STRING_SIZE);
|
||||
}
|
||||
|
||||
void deserializeClient(ClientPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void ClientPacket::Deserialize(void* buffer) {
|
||||
deserialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
DESERIALIZE(buffer, &packet->clientIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
|
||||
// DESERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
|
||||
deserialize(&buffer, &clientIndex, sizeof(int));
|
||||
deserialize(&buffer, &accountIndex, sizeof(int));
|
||||
deserialize(&buffer, username, PACKET_STRING_SIZE);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,31 @@
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
struct ClientPacket : SerialPacketBase {
|
||||
#include <cstring>
|
||||
|
||||
class ClientPacket : public SerialPacketBase {
|
||||
public:
|
||||
ClientPacket() {}
|
||||
~ClientPacket() {}
|
||||
|
||||
//accessors & mutators
|
||||
int SetClientIndex(int i) { return clientIndex = i; }
|
||||
int SetAccountIndex(int i) { return accountIndex = i; }
|
||||
const char* SetUsername(const char* s)
|
||||
{ return strncpy(username, s, PACKET_STRING_SIZE); }
|
||||
|
||||
int GetClientIndex() { return clientIndex; }
|
||||
int GetAccountIndex() { return accountIndex; }
|
||||
const char* GetUsername() { return username; }
|
||||
|
||||
protected:
|
||||
virtual void Serialize(void* buffer) override;
|
||||
virtual void Deserialize(void* buffer) override;
|
||||
|
||||
private:
|
||||
int clientIndex;
|
||||
int accountIndex;
|
||||
char username[PACKET_STRING_SIZE];
|
||||
char username[PACKET_STRING_SIZE+1];
|
||||
// char password[PACKET_STRING_SIZE]; //hashed, not currently used
|
||||
};
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
|
||||
void serializeCombat(CombatPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the combat instance
|
||||
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
||||
|
||||
//combatants
|
||||
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
||||
SERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
|
||||
|
||||
//location
|
||||
SERIALIZE(buffer, &packet->mapIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
|
||||
//TODO: gameplay components: rewards
|
||||
}
|
||||
|
||||
void deserializeCombat(CombatPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the combat instance
|
||||
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
||||
|
||||
//combatants
|
||||
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
||||
DESERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
|
||||
|
||||
//location
|
||||
DESERIALIZE(buffer, &packet->mapIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
|
||||
//TODO: gameplay components: rewards
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef COMBATPACKET_HPP_
|
||||
#define COMBATPACKET_HPP_
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
#include "combat_defines.hpp"
|
||||
|
||||
struct CombatPacket : SerialPacketBase {
|
||||
//identify the combat instance
|
||||
int combatIndex;
|
||||
int difficulty;
|
||||
TerrainType terrainType;
|
||||
|
||||
//combatants
|
||||
int characterArray[COMBAT_MAX_CHARACTERS];
|
||||
int enemyArray[COMBAT_MAX_ENEMIES];
|
||||
|
||||
//location
|
||||
int mapIndex;
|
||||
Vector2 origin;
|
||||
|
||||
//TODO: gameplay components: rewards
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
|
||||
void serializeEnemy(EnemyPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the enemy
|
||||
SERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
||||
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//gameplay
|
||||
|
||||
//stats structure
|
||||
serializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
}
|
||||
|
||||
void deserializeEnemy(EnemyPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the enemy
|
||||
DESERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
|
||||
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//stats structure
|
||||
deserializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef ENEMYPACKET_HPP_
|
||||
#define ENEMYPACKET_HPP_
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
struct EnemyPacket : SerialPacketBase {
|
||||
//identify the enemy
|
||||
int enemyIndex;
|
||||
char handle[PACKET_STRING_SIZE];
|
||||
char avatar[PACKET_STRING_SIZE];
|
||||
|
||||
//gameplay
|
||||
Statistics stats;
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ..
|
||||
INCLUDES+=. .. ../../gameplay ../../map ../../utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -19,71 +19,61 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
#include "region_packet.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeRegionFormat(RegionPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void RegionPacket::Serialize(void* buffer) {
|
||||
serialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//format
|
||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
||||
}
|
||||
serialize(&buffer, &roomIndex, sizeof(int));
|
||||
serialize(&buffer, &x, sizeof(int));
|
||||
serialize(&buffer, &y, sizeof(int));
|
||||
|
||||
void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//format
|
||||
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
||||
if (type != SerialPacketType::REGION_CONTENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
//tiles
|
||||
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||
*reinterpret_cast<Region::type_t*>(buffer) = packet->region->GetTile(i, j, k);
|
||||
*reinterpret_cast<Region::type_t*>(buffer) = region->GetTile(i, j, k);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//solids
|
||||
SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
serialize(&buffer, region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
}
|
||||
|
||||
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void RegionPacket::Deserialize(void* buffer) {
|
||||
deserialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//format
|
||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->x, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->y, sizeof(int));
|
||||
}
|
||||
deserialize(&buffer, &roomIndex, sizeof(int));
|
||||
deserialize(&buffer, &x, sizeof(int));
|
||||
deserialize(&buffer, &y, sizeof(int));
|
||||
|
||||
void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//format
|
||||
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->x, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->y, sizeof(int));
|
||||
if (type != SerialPacketType::REGION_CONTENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
//an object to work on
|
||||
packet->region = new Region(packet->x, packet->y);
|
||||
region = new Region(x, y);
|
||||
|
||||
//tiles
|
||||
for (int i = 0; i < REGION_WIDTH; i++) {
|
||||
for (int j = 0; j < REGION_HEIGHT; j++) {
|
||||
for (int k = 0; k < REGION_DEPTH; k++) {
|
||||
packet->region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||
region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//solids
|
||||
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
deserialize(&buffer, region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
}
|
||||
@@ -26,7 +26,37 @@
|
||||
|
||||
#include "region.hpp"
|
||||
|
||||
struct RegionPacket : SerialPacketBase {
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
//define the memory footprint for the region's members
|
||||
constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH;
|
||||
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||
constexpr int REGION_METADATA_FOOTPRINT = sizeof(int) * 3;
|
||||
|
||||
class RegionPacket : public SerialPacketBase {
|
||||
public:
|
||||
RegionPacket() {}
|
||||
~RegionPacket() {}
|
||||
|
||||
//location
|
||||
int SetRoomIndex(int i) { return roomIndex = i; }
|
||||
int SetX(int i) { return x = i; }
|
||||
int SetY(int i) { return y = i; }
|
||||
|
||||
int GetRoomIndex() { return roomIndex; }
|
||||
int GetX() { return x; }
|
||||
int GetY() { return y; }
|
||||
|
||||
//the region itself
|
||||
Region* SetRegion(Region* r) { return region = r; }
|
||||
Region* GetRegion() { return region; }
|
||||
|
||||
protected:
|
||||
virtual void Serialize(void* buffer) override;
|
||||
virtual void Deserialize(void* buffer) override;
|
||||
|
||||
private:
|
||||
//location/identify the region
|
||||
int roomIndex;
|
||||
int x, y;
|
||||
|
||||
@@ -19,24 +19,24 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
#include "server_packet.hpp"
|
||||
|
||||
#include "serial_util.hpp"
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeServer(ServerPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void ServerPacket::Serialize(void* buffer) {
|
||||
serialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the server
|
||||
SERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
|
||||
SERIALIZE(buffer, &packet->playerCount, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->version, sizeof(int));
|
||||
serialize(&buffer, &name, PACKET_STRING_SIZE);
|
||||
serialize(&buffer, &playerCount, sizeof(int));
|
||||
serialize(&buffer, &version, sizeof(int));
|
||||
}
|
||||
|
||||
void deserializeServer(ServerPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
|
||||
void ServerPacket::Deserialize(void* buffer) {
|
||||
deserialize(&buffer, &type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the server
|
||||
DESERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
|
||||
DESERIALIZE(buffer, &packet->playerCount, sizeof(int));
|
||||
DESERIALIZE(buffer, &packet->version, sizeof(int));
|
||||
deserialize(&buffer, &name, PACKET_STRING_SIZE);
|
||||
deserialize(&buffer, &playerCount, sizeof(int));
|
||||
deserialize(&buffer, &version, sizeof(int));
|
||||
}
|
||||
|
||||
@@ -24,9 +24,29 @@
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
struct ServerPacket : SerialPacketBase {
|
||||
#include <cstring>
|
||||
|
||||
class ServerPacket : public SerialPacketBase {
|
||||
public:
|
||||
ServerPacket() {}
|
||||
~ServerPacket() {}
|
||||
|
||||
const char* SetName(const char* s)
|
||||
{ return strncpy(name, s, PACKET_STRING_SIZE); }
|
||||
int SetPlayerCount(int i) { return playerCount = i; }
|
||||
int SetVersion(int i) { return version = i; }
|
||||
|
||||
const char* GetName() { return name; }
|
||||
int GetPlayerCount() { return playerCount; }
|
||||
int GetVersion() { return version; }
|
||||
|
||||
protected:
|
||||
virtual void Serialize(void* buffer) override;
|
||||
virtual void Deserialize(void* buffer) override;
|
||||
|
||||
private:
|
||||
//identify the server
|
||||
char name[PACKET_STRING_SIZE];
|
||||
char name[PACKET_STRING_SIZE+1];
|
||||
int playerCount;
|
||||
int version;
|
||||
};
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include "serial_packet_base.hpp"
|
||||
#include "character_packet.hpp"
|
||||
#include "client_packet.hpp"
|
||||
#include "combat_packet.hpp"
|
||||
#include "enemy_packet.hpp"
|
||||
#include "region_packet.hpp"
|
||||
#include "server_packet.hpp"
|
||||
|
||||
@@ -44,10 +42,8 @@ constexpr int NETWORK_VERSION = 20140827;
|
||||
union _MaxPacket {
|
||||
CharacterPacket a;
|
||||
ClientPacket b;
|
||||
CombatPacket c;
|
||||
EnemyPacket d;
|
||||
RegionPacket e;
|
||||
ServerPacket f;
|
||||
RegionPacket c;
|
||||
ServerPacket d;
|
||||
};
|
||||
|
||||
constexpr int MAX_PACKET_SIZE = sizeof(_MaxPacket);
|
||||
@@ -62,8 +58,10 @@ constexpr int MAX_PACKET_SIZE = sizeof(_MaxPacket);
|
||||
* solid data (bitset)
|
||||
*/
|
||||
|
||||
constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH;
|
||||
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_TILE_FOOTPRINT + REGION_SOLID_FOOTPRINT;
|
||||
constexpr int PACKET_BUFFER_SIZE =
|
||||
sizeof(SerialPacketType) +
|
||||
REGION_METADATA_FOOTPRINT +
|
||||
REGION_TILE_FOOTPRINT +
|
||||
REGION_SOLID_FOOTPRINT;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,13 +39,12 @@ public:
|
||||
protected:
|
||||
friend class UDPNetworkUtility;
|
||||
|
||||
SerialPacketBase() = default;
|
||||
virtual ~SerialPacketBase() = default;
|
||||
SerialPacketBase() {};
|
||||
virtual ~SerialPacketBase() {};
|
||||
|
||||
virtual void Serialize(const void* buffer) = 0;
|
||||
virtual void Deserialize(const void* buffer) = 0;
|
||||
virtual void Serialize(void* buffer) = 0;
|
||||
virtual void Deserialize(void* buffer) = 0;
|
||||
|
||||
private:
|
||||
SerialPacketType type;
|
||||
IPaddress srcAddress;
|
||||
};
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
#include "statistics.hpp"
|
||||
|
||||
//raw memcpy
|
||||
inline void serialize(void** bufferHead, void* data, int size);
|
||||
inline void deserialize(void** bufferHead, void* data, int size);
|
||||
void serialize(void** bufferHead, void* data, int size);
|
||||
void deserialize(void** bufferHead, void* data, int size);
|
||||
|
||||
void serializeStatistics(void** bufferHead, Statistics* stats);
|
||||
void deserializeStatistics(void** bufferHead, Statistics* stats);
|
||||
Reference in New Issue
Block a user