From 4ed512e0e214cd4238ac495729a60e05f84c6cff Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 24 Aug 2014 13:23:50 +1000 Subject: [PATCH 1/2] Moved the snapToBase() utility function to region.*pp I've also adjusted the TODO file, which really shouldn't be committed. Still, it's there now, so it stays. I don't think the logger is going to be possible any time soon, so I'll probably look into the disconnection handler. --- common/map/region.cpp | 6 ++++-- common/map/region.hpp | 3 +++ common/map/region_pager_api.cpp | 2 -- common/map/region_pager_base.cpp | 2 -- common/map/region_pager_lua.cpp | 2 -- common/utilities/utility.cpp | 13 ------------- common/utilities/utility.hpp | 3 --- makefile | 7 +------ todo.txt | 2 +- 9 files changed, 9 insertions(+), 31 deletions(-) diff --git a/common/map/region.cpp b/common/map/region.cpp index c4fb712..13b2c66 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -21,11 +21,13 @@ */ #include "region.hpp" -#include "utility.hpp" - #include #include +int snapToBase(int base, int x) { + return floor((double)x / base) * base; +} + 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")); diff --git a/common/map/region.hpp b/common/map/region.hpp index 0571c09..8e3c208 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -33,6 +33,9 @@ constexpr int REGION_DEPTH = 3; //the size of the solid map constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); +//utility function +int snapToBase(int base, int x); + class Region { public: typedef unsigned char type_t; diff --git a/common/map/region_pager_api.cpp b/common/map/region_pager_api.cpp index b08ce6c..73019d1 100644 --- a/common/map/region_pager_api.cpp +++ b/common/map/region_pager_api.cpp @@ -24,8 +24,6 @@ #include "region_pager_lua.hpp" #include "region.hpp" -#include - //DOCS: These glue functions simply wrap RegionPagerLua's methods static int setTile(lua_State* L) { diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index f288ef0..3310cb8 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -21,8 +21,6 @@ */ #include "region_pager_base.hpp" -#include "utility.hpp" - #include #include diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index 278bdb4..4682b68 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -21,8 +21,6 @@ */ #include "region_pager_lua.hpp" -#include "utility.hpp" - #include //TODO: Could I push the pager to the API functions too? diff --git a/common/utilities/utility.cpp b/common/utilities/utility.cpp index bbba99c..5e2c439 100644 --- a/common/utilities/utility.cpp +++ b/common/utilities/utility.cpp @@ -23,19 +23,6 @@ #include -int snapToBase(int base, int x) { - //snap to a grid - if (x < 0) { - ++x; - return x / base * base - base; - } - return x / base * base; -} - -double snapToBase(double base, double x) { - return floor(x / base) * base; -} - std::string truncatePath(std::string pathname) { return std::string( std::find_if( diff --git a/common/utilities/utility.hpp b/common/utilities/utility.hpp index 3346136..2cec21f 100644 --- a/common/utilities/utility.hpp +++ b/common/utilities/utility.hpp @@ -24,9 +24,6 @@ #include -int snapToBase(int base, int x); -double snapToBase(double base, double x); - std::string truncatePath(std::string pathname); //fixing known bugs in g++ diff --git a/makefile b/makefile index 8ae66e9..7b66127 100644 --- a/makefile +++ b/makefile @@ -3,11 +3,6 @@ #MKDIR=mkdir #RM=del /y -#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall -#CXXFLAGS+=-static-libgcc -static-libstdc++ - -#export - OUTDIR=out all: $(OUTDIR) @@ -23,7 +18,7 @@ release: clean all package #For use on my machine ONLY package: - rar a -r -ep Tortuga.rar out/*.exe out/*.dll + rar a -r -ep Tortuga.rar $(OUTDIR)/*.exe $(OUTDIR)/*.dll rar a -r Tortuga.rar rsc/* copyright.txt $(OUTDIR): diff --git a/todo.txt b/todo.txt index 284be85..685269a 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,4 @@ TODO: encapsulate the data structures -TODO: A proper logging system TODO: Ping-pong and keep alive system TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times TODO: Get the rooms working, even if only via hotkeys @@ -12,3 +11,4 @@ TODO: server is slaved to the client TODO: Time delay for requesting region packets TODO: command line parameters overriding config.cfg settings +TODO: A proper logging system From 6f4334f84d747f63a21de3d0b6c6b52e52134949 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 25 Aug 2014 00:07:17 +1000 Subject: [PATCH 2/2] Moved serialization globals --- client/client_application.cpp | 2 +- common/map/region.cpp | 1 + common/map/region.hpp | 7 ------- common/map/region_pager_base.cpp | 4 ++-- common/map/region_pager_lua.cpp | 2 -- common/network/serial/serial.hpp | 18 ++++++++++++------ common/network/serial/serial_region.cpp | 12 ++++++------ server/server_logic.cpp | 2 +- todo.txt | 2 ++ 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index 75a9d9b..a5426be 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -94,8 +94,8 @@ void ClientApplication::Init(int argc, char** argv) { DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_HEIGHT); DEBUG_OUTPUT_VAR(REGION_DEPTH); + DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); - DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); diff --git a/common/map/region.cpp b/common/map/region.cpp index 13b2c66..ea1f402 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -22,6 +22,7 @@ #include "region.hpp" #include +#include #include int snapToBase(int base, int x) { diff --git a/common/map/region.hpp b/common/map/region.hpp index 8e3c208..55e7e9f 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -23,16 +23,12 @@ #define REGION_HPP_ #include -#include //the region's storage format 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_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); - //utility function int snapToBase(int base, int x); @@ -64,7 +60,4 @@ private: std::bitset 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_FOOTPRINT; - #endif diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index 3310cb8..c046bdc 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -71,12 +71,12 @@ Region* RegionPagerBase::PushRegion(Region* const ptr) { } Region* RegionPagerBase::LoadRegion(int x, int y) { - //TODO: load the region if possible + //EMPTY, intended for override return nullptr; } Region* RegionPagerBase::SaveRegion(int x, int y) { - //TODO: find & save the region + //EMPTY, intended for override return nullptr; } diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index 4682b68..d8fb538 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -23,8 +23,6 @@ #include -//TODO: Could I push the pager to the API functions too? - Region* RegionPagerLua::LoadRegion(int x, int y) { //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); diff --git a/common/network/serial/serial.hpp b/common/network/serial/serial.hpp index 2a948bd..f218a24 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,15 +55,19 @@ void deserializeRegionContent(RegionPacket*, void*); void deserializeServer(ServerPacket*, void*); void deserializeStatistics(Statistics*, void*); -/* DOCS: Keep PACKET_BUFFER_SIZE up to date - * DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more - * The metadata used are: +/* DOCS: PACKET_BUFFER_SIZE is the memory required to store serialized data + * DOCS: SerialPacketType::REGION_CONTENT is currently the largest packet type + * Serialized packet structure: * SerialPacketType * room index - * X & Y positon - * The rest is taken up by the Regions's content. + * X & Y position + * tile data (3 layers) + * solid data (bitset) + * The constants declared here are used for networking ONLY */ -constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT; +constexpr int REGION_TILE_FOOTPRINT = sizeof(Region::type_t) * REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH; +constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); +constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_TILE_FOOTPRINT + REGION_SOLID_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 5aec454..54c4b6b 100644 --- a/common/network/serial/serial_region.cpp +++ b/common/network/serial/serial_region.cpp @@ -41,9 +41,9 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) { SERIALIZE(buffer, &packet->y, sizeof(int)); //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++) { + for (int i = 0; i < REGION_WIDTH; i++) { + for (int j = 0; j < REGION_HEIGHT; j++) { + for (int k = 0; k < REGION_DEPTH; k++) { *reinterpret_cast(buffer) = packet->region->GetTile(i, j, k); buffer = reinterpret_cast(buffer) + sizeof(Region::type_t); } @@ -75,9 +75,9 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) { packet->region = new Region(packet->x, packet->y); //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++) { + for (int i = 0; i < REGION_WIDTH; i++) { + for (int j = 0; j < REGION_HEIGHT; j++) { + for (int k = 0; k < REGION_DEPTH; k++) { packet->region->SetTile(i, j, k, *reinterpret_cast(buffer)); buffer = reinterpret_cast(buffer) + sizeof(Region::type_t); } diff --git a/server/server_logic.cpp b/server/server_logic.cpp index e4e1f5f..114c7ff 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -117,8 +117,8 @@ void ServerApplication::Init(int argc, char** argv) { DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_HEIGHT); DEBUG_OUTPUT_VAR(REGION_DEPTH); + DEBUG_OUTPUT_VAR(REGION_TILE_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); - DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); diff --git a/todo.txt b/todo.txt index 685269a..0e86d2c 100644 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,8 @@ TODO: Ping-pong and keep alive system TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times TODO: Get the rooms working, even if only via hotkeys TODO: Rejection messages +TODO: Move the map system into it's own namespace +TODO: The TileSheet class should implement the surface itself TODO: Fix shoddy movement TODO: make the whole thing more fault tolerant