Solid data is moving from the server to the client, read more
The APIs have access to the solid data, and I fixed a bug: Basically, the template parameter for std::bitset expects an integer representing the number of bits to hold, but I initially misread it as the number of bytes. This has been corrected. I've also added a sandy beach to the generated island. I'm tempted to start working on some simple generators soon.
This commit is contained in:
@@ -35,6 +35,7 @@ Region::Region(int argX, int argY): x(argX), y(argY) {
|
||||
|
||||
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
||||
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
|
||||
solid = rhs.solid;
|
||||
}
|
||||
|
||||
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
#include <cmath>
|
||||
|
||||
//the region's storage format
|
||||
constexpr int REGION_WIDTH = 21;
|
||||
constexpr int REGION_HEIGHT = 21;
|
||||
constexpr int REGION_WIDTH = 20;
|
||||
constexpr int REGION_HEIGHT = 20;
|
||||
constexpr int REGION_DEPTH = 3;
|
||||
|
||||
//the size of the solid map
|
||||
constexpr int REGION_SOLID = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||
|
||||
class Region {
|
||||
public:
|
||||
@@ -51,15 +51,17 @@ public:
|
||||
//accessors
|
||||
int GetX() const { return x; }
|
||||
int GetY() const { return y; }
|
||||
|
||||
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; }
|
||||
private:
|
||||
const int x;
|
||||
const int y;
|
||||
|
||||
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
||||
std::bitset<REGION_SOLID> solid;
|
||||
std::bitset<REGION_WIDTH*REGION_HEIGHT> solid;
|
||||
};
|
||||
|
||||
//the memory footprint of the tile and solid data; not including any metadata
|
||||
constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID;
|
||||
constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID_FOOTPRINT;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,6 +37,20 @@ static int getTile(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setSolid(lua_State* L) {
|
||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||
bool ret = region->SetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_toboolean(L, 4));
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getSolid(lua_State* L) {
|
||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||
bool ret = region->GetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1);
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getX(lua_State* L) {
|
||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, region->GetX());
|
||||
@@ -89,6 +103,8 @@ static int onUnload(lua_State* L) {
|
||||
static const luaL_Reg regionLib[] = {
|
||||
{"SetTile",setTile},
|
||||
{"GetTile",getTile},
|
||||
{"SetSolid",setSolid},
|
||||
{"GetSolid",getSolid},
|
||||
{"GetX",getX},
|
||||
{"GetY",getY},
|
||||
{"GetWidth",getWidth},
|
||||
|
||||
@@ -43,6 +43,20 @@ static int getTile(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setSolid(lua_State* L) {
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
bool ret = pager->SetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_toboolean(L, 4));
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getSolid(lua_State* L) {
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
bool ret = pager->GetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getRegion(lua_State* L) {
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
@@ -94,6 +108,8 @@ static int unloadRegion(lua_State* L) {
|
||||
static const luaL_Reg pagerlib[] = {
|
||||
{"SetTile", setTile},
|
||||
{"GetTile", getTile},
|
||||
{"SetSolid", setSolid},
|
||||
{"GetSolid", getSolid},
|
||||
{"GetRegion", getRegion},
|
||||
{"SetDirectory", setDirectory},
|
||||
{"GetDirectory", getDirectory},
|
||||
|
||||
@@ -40,7 +40,7 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
||||
|
||||
//content
|
||||
//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++) {
|
||||
@@ -50,7 +50,8 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: serialize collision map
|
||||
//solids
|
||||
SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
}
|
||||
|
||||
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
||||
@@ -73,7 +74,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
//an object to work on
|
||||
packet->region = new Region(packet->x, packet->y);
|
||||
|
||||
//content
|
||||
//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++) {
|
||||
@@ -83,5 +84,6 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: deserialize collision map
|
||||
//solids
|
||||
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||
}
|
||||
Reference in New Issue
Block a user