diff --git a/common/map/region.cpp b/common/map/region.cpp index 8de957b..7fbe38c 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -30,11 +30,11 @@ Region::Region(int argX, int argY): x(argX), y(argY) { if (x != snapToBase(REGION_WIDTH, x) || y != snapToBase(REGION_HEIGHT, y)) { throw(std::invalid_argument("Region location is off grid")); } - memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); + memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*(REGION_DEPTH+1)*sizeof(type_t)); } 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+1)*sizeof(type_t)); } Region::type_t Region::SetTile(int x, int y, int z, type_t v) { diff --git a/common/map/region.hpp b/common/map/region.hpp index 74fc013..7b578fa 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -22,8 +22,8 @@ #ifndef REGION_HPP_ #define REGION_HPP_ -constexpr int REGION_WIDTH = 20; -constexpr int REGION_HEIGHT = 20; +constexpr int REGION_WIDTH = 21; +constexpr int REGION_HEIGHT = 21; constexpr int REGION_DEPTH = 3; class Region { @@ -45,7 +45,7 @@ private: const int x; const int y; - type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH]; + type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH+1]; }; #endif diff --git a/common/map/region_api.cpp b/common/map/region_api.cpp index fdff4f7..ead6ef2 100644 --- a/common/map/region_api.cpp +++ b/common/map/region_api.cpp @@ -85,6 +85,7 @@ static int onUnload(lua_State* L) { return 0; } +//TODO: wrappers for the collision map static const luaL_Reg regionLib[] = { {"SetTile",setTile}, {"GetTile",getTile}, diff --git a/common/network/packet/serial_packet_base.hpp b/common/network/packet/serial_packet_base.hpp index 156d1e5..2f82092 100644 --- a/common/network/packet/serial_packet_base.hpp +++ b/common/network/packet/serial_packet_base.hpp @@ -30,7 +30,7 @@ #include "SDL/SDL_net.h" -constexpr int NETWORK_VERSION = 20140607; +constexpr int NETWORK_VERSION = 20140701; constexpr int PACKET_STRING_SIZE = 100; struct SerialPacketBase { diff --git a/common/network/serial/serial.hpp b/common/network/serial/serial.hpp index 02d5dba..f69743a 100644 --- a/common/network/serial/serial.hpp +++ b/common/network/serial/serial.hpp @@ -27,6 +27,8 @@ #include "region.hpp" #include "statistics.hpp" +#include + //Primary interface functions void serializePacket(SerialPacketBase*, void* dest); void deserializePacket(SerialPacketBase*, void* src); @@ -53,13 +55,22 @@ void deserializeRegionContent(RegionPacket*, void*); void deserializeServer(ServerPacket*, void*); void deserializeStatistics(Statistics*, void*); -/* DOCS: Keep the PACKET_BUFFER_SIZE up to date +/* DOCS: Keep these macros, including PACKET_BUFFER_SIZE up to date * DOCS: REGION_CONTENT is currently the largest type of packet, read more - * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t) - * map format: sizeof(int) * 3 - * metadata: sizeof(SerialPacket::Type) + * REGION_FORMAT + * This is the space for the region's metadata; the X and Y position, the map index and the SerialPacketType + * REGION_FOOTPRINT + * This is the theoretical size of the map's tile data in memory, but it doesn't take the collision map into account + * COLLISION_FOOTPRINT + * This is the space in the packet for the collision map, stored as a bit array + * PACKET_BUFFER_SIZE + * This is the tital size of the packet being sent between the server and the clients */ -constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType); +constexpr int REGION_FORMAT = sizeof(int) * 3 + sizeof(SerialPacketType); +constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t); +constexpr int COLLISION_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); + +constexpr int PACKET_BUFFER_SIZE = REGION_FORMAT + REGION_FOOTPRINT + COLLISION_FOOTPRINT; #endif \ No newline at end of file diff --git a/common/network/serial/serial_region.cpp b/common/network/serial/serial_region.cpp index 31145bd..d4dc563 100644 --- a/common/network/serial/serial_region.cpp +++ b/common/network/serial/serial_region.cpp @@ -49,6 +49,8 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) { } } } + + //TODO: serialize collision map } void deserializeRegionFormat(RegionPacket* packet, void* buffer) { @@ -80,4 +82,6 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) { } } } + + //TODO: deserialize collision map } \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 6bc65f0..e589a18 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -1,4 +1,4 @@ -print("Lua script check (./rsc)") +print("Lua script check") --uber lazy declarations function square(x) return x*x end @@ -33,10 +33,10 @@ end newRoom = RoomMgr.CreateRoom("overworld") pager = Room.GetPager(newRoom) regionTable = { - RegionPager.GetRegion(pager, 0, 0), - RegionPager.GetRegion(pager, 0, -20), - RegionPager.GetRegion(pager, -20, 0), - RegionPager.GetRegion(pager, -20, -20) + RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() * 0), + RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() * 0), + RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() *-1), + RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1) } print("Finished the lua script") \ No newline at end of file diff --git a/server/server_application.cpp b/server/server_application.cpp index 901706f..16bb8e4 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -113,12 +113,20 @@ void ServerApplication::Init(int argc, char** argv) { //debug output //------------------------- + //TODO: put these outputs into the client too +#define OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; + std::cout << "Internal sizes:" << std::endl; - std::cout << "\tTile Size: " << sizeof(Region::type_t) << std::endl; - std::cout << "\tRegion Format: " << REGION_WIDTH << ", " << REGION_HEIGHT << ", " << REGION_DEPTH << std::endl; - std::cout << "\tRegion Content Footprint: " << REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) << std::endl; - std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl; - std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl; + + OUTPUT_VAR(sizeof(Region::type_t)); + OUTPUT_VAR(sizeof(Region)); + OUTPUT_VAR(REGION_FORMAT); + OUTPUT_VAR(REGION_FOOTPRINT); + OUTPUT_VAR(COLLISION_FOOTPRINT); + OUTPUT_VAR(PACKET_BUFFER_SIZE); + OUTPUT_VAR(MAX_PACKET_SIZE); + +#undef OUTPUT_VAR //------------------------- //finalize the startup