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:
@@ -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) {
|
void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) {
|
||||||
Region::type_t tile = 0;
|
Region::type_t tile = 0;
|
||||||
for (register int i = 0; i < region->GetWidth(); ++i) {
|
for (register int i = 0; i < REGION_WIDTH; ++i) {
|
||||||
for (register int j = 0; j < region->GetHeight(); ++j) {
|
for (register int j = 0; j < REGION_HEIGHT; ++j) {
|
||||||
for (register int k = 0; k < region->GetDepth(); ++k) {
|
for (register int k = 0; k < REGION_DEPTH; ++k) {
|
||||||
tile = region->GetTile(i, j, k);
|
tile = region->GetTile(i, j, k);
|
||||||
//0 is invisible
|
//0 is invisible
|
||||||
if (tile == 0) continue;
|
if (tile == 0) continue;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ union NetworkPacket {
|
|||||||
//map data
|
//map data
|
||||||
struct RegionInformation {
|
struct RegionInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int width, height, depth, x, y;
|
int x, y;
|
||||||
Region* region;
|
Region* region;
|
||||||
}regionInfo;
|
}regionInfo;
|
||||||
|
|
||||||
|
|||||||
+15
-38
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
|
||||||
#include "map_generator.hpp"
|
#include "map_allocator.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -75,14 +75,6 @@ void serializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
|||||||
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
||||||
buffer += 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
|
//x & y
|
||||||
memcpy(buffer, &packet->regionInfo.x, sizeof(int));
|
memcpy(buffer, &packet->regionInfo.x, sizeof(int));
|
||||||
buffer += sizeof(int);
|
buffer += sizeof(int);
|
||||||
@@ -94,14 +86,6 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
|
|||||||
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
||||||
buffer += 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
|
//x & y
|
||||||
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetX();
|
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetX();
|
||||||
buffer += sizeof(int);
|
buffer += sizeof(int);
|
||||||
@@ -109,9 +93,9 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
|
|||||||
buffer += sizeof(int);
|
buffer += sizeof(int);
|
||||||
|
|
||||||
//content
|
//content
|
||||||
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) {
|
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||||
*reinterpret_cast<Region::type_t*>(buffer) = packet->regionInfo.region->GetTile(i, j, k);
|
*reinterpret_cast<Region::type_t*>(buffer) = packet->regionInfo.region->GetTile(i, j, k);
|
||||||
buffer += sizeof(Region::type_t);
|
buffer += sizeof(Region::type_t);
|
||||||
}
|
}
|
||||||
@@ -169,14 +153,6 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
|||||||
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type));
|
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::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
|
//x & y
|
||||||
memcpy(&packet->regionInfo.x, buffer, sizeof(int));
|
memcpy(&packet->regionInfo.x, buffer, sizeof(int));
|
||||||
buffer += sizeof(int);
|
buffer += sizeof(int);
|
||||||
@@ -184,23 +160,24 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deserializeRegionContent(NetworkPacket* packet, char* buffer) {
|
void deserializeRegionContent(NetworkPacket* packet, char* buffer) {
|
||||||
//format
|
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type));
|
||||||
deserializeRegionFormat(packet, buffer);
|
buffer += sizeof(NetworkPacket::Type);
|
||||||
buffer += sizeof(int) * 5 + sizeof(NetworkPacket::Type);
|
|
||||||
|
//x & y
|
||||||
|
memcpy(&packet->regionInfo.x, buffer, sizeof(int));
|
||||||
|
buffer += sizeof(int);
|
||||||
|
memcpy(&packet->regionInfo.y, buffer, sizeof(int));
|
||||||
|
|
||||||
//content
|
//content
|
||||||
BlankGenerator().Create(
|
BlankAllocator().Create(
|
||||||
&packet->regionInfo.region,
|
&packet->regionInfo.region,
|
||||||
packet->regionInfo.width,
|
|
||||||
packet->regionInfo.height,
|
|
||||||
packet->regionInfo.depth,
|
|
||||||
packet->regionInfo.x,
|
packet->regionInfo.x,
|
||||||
packet->regionInfo.y
|
packet->regionInfo.y
|
||||||
);
|
);
|
||||||
|
|
||||||
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) {
|
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||||
packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||||
buffer += sizeof(Region::type_t);
|
buffer += sizeof(Region::type_t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,13 @@
|
|||||||
|
|
||||||
#include "network_packet.hpp"
|
#include "network_packet.hpp"
|
||||||
|
|
||||||
/* Sending regions are the largest type of packet
|
/* TODO: Keep the PACKET_BUFFER_SIZE up to date
|
||||||
* content: width * height * depth * sizoeof(type)
|
* NOTE: REGION_CONTENT is currently the largest type of packet
|
||||||
* map format: sizeof(int) * 5
|
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
|
||||||
|
* map format: sizeof(int) * 2
|
||||||
* metadata: sizeof(metadata)
|
* 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 serialize(NetworkPacket* const, void*);
|
||||||
void deserialize(NetworkPacket* const, void*);
|
void deserialize(NetworkPacket* const, void*);
|
||||||
|
|||||||
@@ -37,20 +37,17 @@ static int getTile(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int getWidth(lua_State* L) {
|
static int getWidth(lua_State* L) {
|
||||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
lua_pushinteger(L, REGION_WIDTH);
|
||||||
lua_pushinteger(L, ptr->GetWidth());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getHeight(lua_State* L) {
|
static int getHeight(lua_State* L) {
|
||||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
lua_pushinteger(L, REGION_HEIGHT);
|
||||||
lua_pushinteger(L, ptr->GetHeight());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getDepth(lua_State* L) {
|
static int getDepth(lua_State* L) {
|
||||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
lua_pushinteger(L, REGION_DEPTH);
|
||||||
lua_pushinteger(L, ptr->GetDepth());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*. Rename MapGenerator to MapAllocator
|
*. Rename MapGenerator to MapAllocator
|
||||||
-. Does the format need to be a functor too?
|
-. Does the format need to be a functor too?
|
||||||
-. Can the format functor go inside the allocator?
|
-. Can the format functor go inside the allocator?
|
||||||
5. lua API
|
*. lua API
|
||||||
|
|
||||||
4. in_world.cpp:487 make the region units official
|
4. in_world.cpp:487 make the region units official
|
||||||
5. region_pager.hpp:50 delete?
|
5. region_pager.hpp:50 delete?
|
||||||
|
|||||||
Reference in New Issue
Block a user