Moved serialization globals

This commit is contained in:
Kayne Ruse
2014-08-25 00:07:17 +10:00
parent 4ed512e0e2
commit 6f4334f84d
9 changed files with 25 additions and 25 deletions
+12 -6
View File
@@ -27,6 +27,8 @@
#include "region.hpp"
#include "statistics.hpp"
#include <cmath>
//Primary interface functions
void serializePacket(SerialPacketBase*, void* dest);
void deserializePacket(SerialPacketBase*, void* src);
@@ -53,15 +55,19 @@ void deserializeRegionContent(RegionPacket*, void*);
void deserializeServer(ServerPacket*, void*);
void deserializeStatistics(Statistics*, void*);
/* DOCS: Keep PACKET_BUFFER_SIZE up to date
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more
* The metadata used are:
/* 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 positon
* The rest is taken up by the Regions's content.
* X & Y position
* tile data (3 layers)
* solid data (bitset)
* The constants declared here are used for networking ONLY
*/
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT;
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
+6 -6
View File
@@ -41,9 +41,9 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->y, sizeof(int));
//tiles
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
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);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
}
@@ -75,9 +75,9 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
packet->region = new Region(packet->x, packet->y);
//tiles
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
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));
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
}