Brought the common/ directory up to date with the region's preprocessors

I really hope the serialization code still works.
This commit is contained in:
Kayne Ruse
2014-04-20 03:55:52 +10:00
parent c5a627004a
commit fba183fa27
6 changed files with 28 additions and 53 deletions
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -107,7 +107,7 @@ union NetworkPacket {
//map data
struct RegionInformation {
Metadata meta;
int width, height, depth, x, y;
int x, y;
Region* region;
}regionInfo;
+15 -38
View File
@@ -21,7 +21,7 @@
*/
#include "serial.hpp"
#include "map_generator.hpp"
#include "map_allocator.hpp"
#include <cstring>
@@ -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<int*>(buffer) = packet->regionInfo.region->GetWidth();
buffer += sizeof(int);
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetHeight();
buffer += sizeof(int);
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetDepth();
buffer += sizeof(int);
//x & y
*reinterpret_cast<int*>(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<Region::type_t*>(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<Region::type_t*>(buffer));
buffer += sizeof(Region::type_t);
}
+5 -4
View File
@@ -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*);
+3 -6
View File
@@ -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;
}