From fba183fa27ffeb9da765b7e9b514bbbfdab9862f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 20 Apr 2014 03:55:52 +1000 Subject: [PATCH] Brought the common/ directory up to date with the region's preprocessors I really hope the serialization code still works. --- common/graphics/tile_sheet.cpp | 6 ++-- common/network/network_packet.hpp | 2 +- common/network/serial.cpp | 53 +++++++++---------------------- common/network/serial.hpp | 9 +++--- common/script/region_api.cpp | 9 ++---- todo.txt | 2 +- 6 files changed, 28 insertions(+), 53 deletions(-) diff --git a/common/graphics/tile_sheet.cpp b/common/graphics/tile_sheet.cpp index cc96ec5..e1b9ea2 100644 --- a/common/graphics/tile_sheet.cpp +++ b/common/graphics/tile_sheet.cpp @@ -44,9 +44,9 @@ void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t til void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) { Region::type_t tile = 0; - for (register int i = 0; i < region->GetWidth(); ++i) { - for (register int j = 0; j < region->GetHeight(); ++j) { - for (register int k = 0; k < region->GetDepth(); ++k) { + 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) { tile = region->GetTile(i, j, k); //0 is invisible if (tile == 0) continue; diff --git a/common/network/network_packet.hpp b/common/network/network_packet.hpp index 68b91ee..79c9af2 100644 --- a/common/network/network_packet.hpp +++ b/common/network/network_packet.hpp @@ -107,7 +107,7 @@ union NetworkPacket { //map data struct RegionInformation { Metadata meta; - int width, height, depth, x, y; + int x, y; Region* region; }regionInfo; diff --git a/common/network/serial.cpp b/common/network/serial.cpp index 2aa88cb..5130841 100644 --- a/common/network/serial.cpp +++ b/common/network/serial.cpp @@ -21,7 +21,7 @@ */ #include "serial.hpp" -#include "map_generator.hpp" +#include "map_allocator.hpp" #include @@ -75,14 +75,6 @@ void serializeRegionFormat(NetworkPacket* packet, char* buffer) { memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type)); buffer += sizeof(NetworkPacket::Type); - //size - memcpy(buffer, &packet->regionInfo.width, sizeof(int)); - buffer += sizeof(int); - memcpy(buffer, &packet->regionInfo.height, sizeof(int)); - buffer += sizeof(int); - memcpy(buffer, &packet->regionInfo.depth, sizeof(int)); - buffer += sizeof(int); - //x & y memcpy(buffer, &packet->regionInfo.x, sizeof(int)); buffer += sizeof(int); @@ -94,14 +86,6 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) { memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type)); buffer += sizeof(NetworkPacket::Type); - //size - *reinterpret_cast(buffer) = packet->regionInfo.region->GetWidth(); - buffer += sizeof(int); - *reinterpret_cast(buffer) = packet->regionInfo.region->GetHeight(); - buffer += sizeof(int); - *reinterpret_cast(buffer) = packet->regionInfo.region->GetDepth(); - buffer += sizeof(int); - //x & y *reinterpret_cast(buffer) = packet->regionInfo.region->GetX(); buffer += sizeof(int); @@ -109,9 +93,9 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) { buffer += sizeof(int); //content - for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) { - for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) { - for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) { + 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++) { *reinterpret_cast(buffer) = packet->regionInfo.region->GetTile(i, j, k); buffer += sizeof(Region::type_t); } @@ -169,14 +153,6 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) { memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type)); buffer += sizeof(NetworkPacket::Type); - //size - memcpy(&packet->regionInfo.width, buffer, sizeof(int)); - buffer += sizeof(int); - memcpy(&packet->regionInfo.height, buffer, sizeof(int)); - buffer += sizeof(int); - memcpy(&packet->regionInfo.depth, buffer, sizeof(int)); - buffer += sizeof(int); - //x & y memcpy(&packet->regionInfo.x, buffer, sizeof(int)); buffer += sizeof(int); @@ -184,23 +160,24 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) { } void deserializeRegionContent(NetworkPacket* packet, char* buffer) { - //format - deserializeRegionFormat(packet, buffer); - buffer += sizeof(int) * 5 + sizeof(NetworkPacket::Type); + memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type)); + buffer += sizeof(NetworkPacket::Type); + + //x & y + memcpy(&packet->regionInfo.x, buffer, sizeof(int)); + buffer += sizeof(int); + memcpy(&packet->regionInfo.y, buffer, sizeof(int)); //content - BlankGenerator().Create( + BlankAllocator().Create( &packet->regionInfo.region, - packet->regionInfo.width, - packet->regionInfo.height, - packet->regionInfo.depth, packet->regionInfo.x, packet->regionInfo.y ); - for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) { - for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) { - for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) { + 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++) { packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast(buffer)); buffer += sizeof(Region::type_t); } diff --git a/common/network/serial.hpp b/common/network/serial.hpp index 8680c8a..f2534dc 100644 --- a/common/network/serial.hpp +++ b/common/network/serial.hpp @@ -24,12 +24,13 @@ #include "network_packet.hpp" -/* Sending regions are the largest type of packet - * content: width * height * depth * sizoeof(type) - * map format: sizeof(int) * 5 +/* TODO: Keep the PACKET_BUFFER_SIZE up to date + * NOTE: REGION_CONTENT is currently the largest type of packet + * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t) + * map format: sizeof(int) * 2 * metadata: sizeof(metadata) */ -#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 5 + sizeof(NetworkPacket::Metadata) +#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 2 + sizeof(NetworkPacket::Metadata) void serialize(NetworkPacket* const, void*); void deserialize(NetworkPacket* const, void*); diff --git a/common/script/region_api.cpp b/common/script/region_api.cpp index 48380d3..e71831f 100644 --- a/common/script/region_api.cpp +++ b/common/script/region_api.cpp @@ -37,20 +37,17 @@ static int getTile(lua_State* L) { } static int getWidth(lua_State* L) { - Region* ptr = (Region*)lua_touserdata(L, 1); - lua_pushinteger(L, ptr->GetWidth()); + lua_pushinteger(L, REGION_WIDTH); return 1; } static int getHeight(lua_State* L) { - Region* ptr = (Region*)lua_touserdata(L, 1); - lua_pushinteger(L, ptr->GetHeight()); + lua_pushinteger(L, REGION_HEIGHT); return 1; } static int getDepth(lua_State* L) { - Region* ptr = (Region*)lua_touserdata(L, 1); - lua_pushinteger(L, ptr->GetDepth()); + lua_pushinteger(L, REGION_DEPTH); return 1; } diff --git a/todo.txt b/todo.txt index f60a8bc..7e60edd 100644 --- a/todo.txt +++ b/todo.txt @@ -4,7 +4,7 @@ *. Rename MapGenerator to MapAllocator -. Does the format need to be a functor too? -. Can the format functor go inside the allocator? -5. lua API +*. lua API 4. in_world.cpp:487 make the region units official 5. region_pager.hpp:50 delete?