diff --git a/common/network/packet_types/sanity_check.cpp b/common/network/packet_types/sanity_check.cpp deleted file mode 100644 index f250d69..0000000 --- a/common/network/packet_types/sanity_check.cpp +++ /dev/null @@ -1,28 +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. -*/ -#include "serial_packet.hpp" - -/* DOCS: Sanity check, read more - * Since most/all of the files in this directory are header files, I've created - * this source file as a "sanity check", to ensure that the above header files - * are written correctly via make. -*/ diff --git a/common/network/packet_types/serial.cpp b/common/network/packet_types/serial.cpp deleted file mode 100644 index 45c9c32..0000000 --- a/common/network/packet_types/serial.cpp +++ /dev/null @@ -1,182 +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" - -//simple type functions -void serializeType(SerialPacketBase* packet, void* buffer) { - SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType)); -} - -void deserializeType(SerialPacketBase* packet, void* buffer) { - DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType)); -} - -//main switch functions -void serializePacket(SerialPacketBase* packet, void* buffer) { - switch(packet->type) { - //no extra data - case SerialPacketType::NONE: - case SerialPacketType::PING: - case SerialPacketType::PONG: - case SerialPacketType::BROADCAST_REQUEST: - - //all rejections - case SerialPacketType::JOIN_REJECTION: - case SerialPacketType::CHARACTER_REJECTION: - case SerialPacketType::ENEMY_REJECTION: - case SerialPacketType::COMBAT_REJECTION: - - serializeType(packet, buffer); - break; - - //character info - case SerialPacketType::CHARACTER_NEW: - case SerialPacketType::CHARACTER_DELETE: - case SerialPacketType::CHARACTER_UPDATE: - case SerialPacketType::CHARACTER_STATS_REQUEST: - case SerialPacketType::CHARACTER_STATS_RESPONSE: - serializeCharacter(static_cast(packet), buffer); - break; - - //client info - case SerialPacketType::JOIN_REQUEST: - case SerialPacketType::JOIN_RESPONSE: - case SerialPacketType::SYNCHRONIZE: - case SerialPacketType::DISCONNECT: - case SerialPacketType::SHUTDOWN: - serializeClient(static_cast(packet), buffer); - break; - - //combat info - case SerialPacketType::COMBAT_NEW: - case SerialPacketType::COMBAT_DELETE: - case SerialPacketType::COMBAT_UPDATE: - - case SerialPacketType::COMBAT_ENTER_REQUEST: - case SerialPacketType::COMBAT_ENTER_RESPONSE: - case SerialPacketType::COMBAT_EXIT_REQUEST: - case SerialPacketType::COMBAT_EXIT_RESPONSE: - - serializeCombat(static_cast(packet), buffer); - break; - - //enemy info - case SerialPacketType::ENEMY_NEW: - case SerialPacketType::ENEMY_DELETE: - case SerialPacketType::ENEMY_UPDATE: - case SerialPacketType::ENEMY_STATS_REQUEST: - case SerialPacketType::ENEMY_STATS_RESPONSE: - serializeEnemy(static_cast(packet), buffer); - break; - - //region info - case SerialPacketType::REGION_REQUEST: - serializeRegionFormat(static_cast(packet), buffer); - break; - - case SerialPacketType::REGION_CONTENT: - serializeRegionContent(static_cast(packet), buffer); - break; - - //server info - case SerialPacketType::BROADCAST_RESPONSE: - serializeServer(static_cast(packet), buffer); - break; - } -} - -void deserializePacket(SerialPacketBase* packet, void* buffer) { - //find the type, so that you can actually deserialize the packet! - deserializeType(packet, buffer); - switch(packet->type) { - //no extra data - case SerialPacketType::NONE: - case SerialPacketType::PING: - case SerialPacketType::PONG: - case SerialPacketType::BROADCAST_REQUEST: - - //all rejections - case SerialPacketType::JOIN_REJECTION: - case SerialPacketType::CHARACTER_REJECTION: - case SerialPacketType::ENEMY_REJECTION: - case SerialPacketType::COMBAT_REJECTION: - - //NOTHING - break; - - //character info - case SerialPacketType::CHARACTER_NEW: - case SerialPacketType::CHARACTER_DELETE: - case SerialPacketType::CHARACTER_UPDATE: - case SerialPacketType::CHARACTER_STATS_REQUEST: - case SerialPacketType::CHARACTER_STATS_RESPONSE: - deserializeCharacter(static_cast(packet), buffer); - break; - - //client info - case SerialPacketType::JOIN_REQUEST: - case SerialPacketType::JOIN_RESPONSE: - case SerialPacketType::SYNCHRONIZE: - case SerialPacketType::DISCONNECT: - case SerialPacketType::SHUTDOWN: - deserializeClient(static_cast(packet), buffer); - break; - - //combat info - case SerialPacketType::COMBAT_NEW: - case SerialPacketType::COMBAT_DELETE: - case SerialPacketType::COMBAT_UPDATE: - - case SerialPacketType::COMBAT_ENTER_REQUEST: - case SerialPacketType::COMBAT_ENTER_RESPONSE: - case SerialPacketType::COMBAT_EXIT_REQUEST: - case SerialPacketType::COMBAT_EXIT_RESPONSE: - - serializeCombat(static_cast(packet), buffer); - break; - - //enemy info - case SerialPacketType::ENEMY_NEW: - case SerialPacketType::ENEMY_DELETE: - case SerialPacketType::ENEMY_UPDATE: - case SerialPacketType::ENEMY_STATS_REQUEST: - case SerialPacketType::ENEMY_STATS_RESPONSE: - serializeEnemy(static_cast(packet), buffer); - break; - - //region info - case SerialPacketType::REGION_REQUEST: - deserializeRegionFormat(static_cast(packet), buffer); - break; - - case SerialPacketType::REGION_CONTENT: - deserializeRegionContent(static_cast(packet), buffer); - break; - - //server info - case SerialPacketType::BROADCAST_RESPONSE: - deserializeServer(static_cast(packet), buffer); - break; - } -} \ No newline at end of file diff --git a/common/network/packet_types/serial.hpp b/common/network/packet_types/serial.hpp deleted file mode 100644 index f218a24..0000000 --- a/common/network/packet_types/serial.hpp +++ /dev/null @@ -1,73 +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. -*/ -#ifndef SERIALIZE_HPP_ -#define SERIALIZE_HPP_ - -#include "serial_packet.hpp" - -#include "region.hpp" -#include "statistics.hpp" - -#include - -//Primary interface functions -void serializePacket(SerialPacketBase*, void* dest); -void deserializePacket(SerialPacketBase*, void* src); - -void serializeType(SerialPacketBase*, void*); -void deserializeType(SerialPacketBase*, void*); - -//utility functions, exposed -void serializeCharacter(CharacterPacket*, void*); -void serializeClient(ClientPacket*, void*); -void serializeCombat(CombatPacket*, void*); -void serializeEnemy(EnemyPacket*, void*); -void serializeRegionFormat(RegionPacket*, void*); -void serializeRegionContent(RegionPacket*, void*); -void serializeServer(ServerPacket*, void*); -void serializeStatistics(Statistics*, void*); - -void deserializeCharacter(CharacterPacket*, void*); -void deserializeClient(ClientPacket*, void*); -void deserializeCombat(CombatPacket*, void*); -void deserializeEnemy(EnemyPacket*, void*); -void deserializeRegionFormat(RegionPacket*, void*); -void deserializeRegionContent(RegionPacket*, void*); -void deserializeServer(ServerPacket*, void*); -void deserializeStatistics(Statistics*, void*); - -/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data - * DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type - * Serialized packet structure: - * SerialPacketType - * room index - * X & Y position - * tile data (3 layers) - * solid data (bitset) - * The constants declared here are used for networking ONLY -*/ - -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; - -#endif \ No newline at end of file diff --git a/common/network/packet_types/statistics_packet.cpp b/common/network/packet_types/serial_utility.cpp similarity index 100% rename from common/network/packet_types/statistics_packet.cpp rename to common/network/packet_types/serial_utility.cpp diff --git a/common/network/packet_types/serial_util.hpp b/common/network/packet_types/serial_utility.hpp similarity index 100% rename from common/network/packet_types/serial_util.hpp rename to common/network/packet_types/serial_utility.hpp diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 44198aa..e25a855 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -41,4 +41,19 @@ union MaxPacket { }; constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); +/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data + * DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type + * Serialized packet structure: + * SerialPacketType + * room index + * X & Y position + * tile data (3 layers) + * solid data (bitset) + * The constants declared here are used for networking ONLY +*/ + +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; + #endif