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) {
|
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
||||||
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
|
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) {
|
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
||||||
|
|||||||
@@ -26,12 +26,12 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
//the region's storage format
|
//the region's storage format
|
||||||
constexpr int REGION_WIDTH = 21;
|
constexpr int REGION_WIDTH = 20;
|
||||||
constexpr int REGION_HEIGHT = 21;
|
constexpr int REGION_HEIGHT = 20;
|
||||||
constexpr int REGION_DEPTH = 3;
|
constexpr int REGION_DEPTH = 3;
|
||||||
|
|
||||||
//the size of the solid map
|
//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 {
|
class Region {
|
||||||
public:
|
public:
|
||||||
@@ -51,15 +51,17 @@ public:
|
|||||||
//accessors
|
//accessors
|
||||||
int GetX() const { return x; }
|
int GetX() const { return x; }
|
||||||
int GetY() const { return y; }
|
int GetY() const { return y; }
|
||||||
|
|
||||||
|
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; }
|
||||||
private:
|
private:
|
||||||
const int x;
|
const int x;
|
||||||
const int y;
|
const int y;
|
||||||
|
|
||||||
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
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
|
//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
|
#endif
|
||||||
|
|||||||
@@ -37,6 +37,20 @@ static int getTile(lua_State* L) {
|
|||||||
return 1;
|
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) {
|
static int getX(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
lua_pushinteger(L, region->GetX());
|
lua_pushinteger(L, region->GetX());
|
||||||
@@ -89,6 +103,8 @@ static int onUnload(lua_State* L) {
|
|||||||
static const luaL_Reg regionLib[] = {
|
static const luaL_Reg regionLib[] = {
|
||||||
{"SetTile",setTile},
|
{"SetTile",setTile},
|
||||||
{"GetTile",getTile},
|
{"GetTile",getTile},
|
||||||
|
{"SetSolid",setSolid},
|
||||||
|
{"GetSolid",getSolid},
|
||||||
{"GetX",getX},
|
{"GetX",getX},
|
||||||
{"GetY",getY},
|
{"GetY",getY},
|
||||||
{"GetWidth",getWidth},
|
{"GetWidth",getWidth},
|
||||||
|
|||||||
@@ -43,6 +43,20 @@ static int getTile(lua_State* L) {
|
|||||||
return 1;
|
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) {
|
static int getRegion(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
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[] = {
|
static const luaL_Reg pagerlib[] = {
|
||||||
{"SetTile", setTile},
|
{"SetTile", setTile},
|
||||||
{"GetTile", getTile},
|
{"GetTile", getTile},
|
||||||
|
{"SetSolid", setSolid},
|
||||||
|
{"GetSolid", getSolid},
|
||||||
{"GetRegion", getRegion},
|
{"GetRegion", getRegion},
|
||||||
{"SetDirectory", setDirectory},
|
{"SetDirectory", setDirectory},
|
||||||
{"GetDirectory", getDirectory},
|
{"GetDirectory", getDirectory},
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
SERIALIZE(buffer, &packet->x, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
SERIALIZE(buffer, &packet->y, sizeof(int));
|
||||||
|
|
||||||
//content
|
//tiles
|
||||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
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) {
|
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
||||||
@@ -73,7 +74,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
//an object to work on
|
//an object to work on
|
||||||
packet->region = new Region(packet->x, packet->y);
|
packet->region = new Region(packet->x, packet->y);
|
||||||
|
|
||||||
//content
|
//tiles
|
||||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
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);
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,13 @@ Region.OnCreate = function(region)
|
|||||||
local ret = Region.hcOnCreate(region) --best practices
|
local ret = Region.hcOnCreate(region) --best practices
|
||||||
for i = 1, Region.GetWidth() do
|
for i = 1, Region.GetWidth() do
|
||||||
for j = 1, Region.GetHeight() do
|
for j = 1, Region.GetHeight() do
|
||||||
if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then
|
local dist = distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
||||||
Region.SetTile(region, i, j, 1, water)
|
if dist < 10 then
|
||||||
else
|
|
||||||
Region.SetTile(region, i, j, 1, plains)
|
Region.SetTile(region, i, j, 1, plains)
|
||||||
|
elseif dist < 12 then
|
||||||
|
Region.SetTile(region, i, j, 1, sand)
|
||||||
|
else
|
||||||
|
Region.SetTile(region, i, j, 1, water)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
DEBUG_OUTPUT_VAR(REGION_WIDTH);
|
DEBUG_OUTPUT_VAR(REGION_WIDTH);
|
||||||
DEBUG_OUTPUT_VAR(REGION_HEIGHT);
|
DEBUG_OUTPUT_VAR(REGION_HEIGHT);
|
||||||
DEBUG_OUTPUT_VAR(REGION_DEPTH);
|
DEBUG_OUTPUT_VAR(REGION_DEPTH);
|
||||||
DEBUG_OUTPUT_VAR(REGION_SOLID);
|
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
|
||||||
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
|
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
|
||||||
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
|
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
|
||||||
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
|
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user