From d5b551cec3d17f4be65b2db5524ab0c9a62443a7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 15 Mar 2014 22:59:57 +1100 Subject: [PATCH] Reduced the footprint of the tiles Also prepping for serializing the regions. --- common/map/region.cpp | 20 ++++++++++---------- common/map/region.hpp | 23 +++++++++++++++-------- common/map/region_pager.cpp | 4 ++-- common/map/region_pager.hpp | 4 ++-- common/network/makefile | 2 +- common/network/network_packet.hpp | 14 +++++++++++--- editor/editor_scene.cpp | 8 ++++---- server/server_application.cpp | 7 ++++--- 8 files changed, 49 insertions(+), 33 deletions(-) diff --git a/common/map/region.cpp b/common/map/region.cpp index 9f4f68e..8dd701b 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -28,12 +28,12 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): x(argX), y(argY) { - tiles = new int**[width]; - for (int i = 0; i < width; ++i) { - tiles[i] = new int*[height]; - for (int j = 0; j < height; ++j) { - tiles[i][j] = new int[depth]; - for (int k = 0; k < depth; ++k) { + tiles = new type_t**[width]; + for (register int i = 0; i < width; ++i) { + tiles[i] = new type_t*[height]; + for (register int j = 0; j < height; ++j) { + tiles[i][j] = new type_t[depth]; + for (register int k = 0; k < depth; ++k) { tiles[i][j][k] = 0; } } @@ -41,8 +41,8 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): } Region::~Region() { - for (int i = 0; i < width; ++i) { - for (int j = 0; j < height; j++) { + for (register int i = 0; i < width; ++i) { + for (register int j = 0; j < height; j++) { delete tiles[i][j]; } delete tiles[i]; @@ -50,10 +50,10 @@ Region::~Region() { delete tiles; } -int Region::SetTile(int x, int y, int z, int v) { +Region::type_t Region::SetTile(int x, int y, int z, type_t v) { return tiles[x][y][z] = v; } -int Region::GetTile(int x, int y, int z) { +Region::type_t Region::GetTile(int x, int y, int z) { return tiles[x][y][z]; } diff --git a/common/map/region.hpp b/common/map/region.hpp index 4d083ad..382c3dd 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -22,21 +22,28 @@ #ifndef REGION_HPP_ #define REGION_HPP_ +//temporary? +#define REGION_WIDTH 20 +#define REGION_HEIGHT 20 +#define REGION_DEPTH 3 + class Region { public: + typedef unsigned short type_t; + Region() = delete; Region(int width, int height, int depth, int x, int y); ~Region(); - int SetTile(int x, int y, int z, int v); - int GetTile(int x, int y, int z); + type_t SetTile(int x, int y, int z, type_t v); + type_t GetTile(int x, int y, int z); //accessors - int GetWidth() { return width; } - int GetHeight() { return height; } - int GetDepth() { return depth; } - int GetX() { return x; } - int GetY() { return y; } + int GetWidth() const { return width; } + int GetHeight() const { return height; } + int GetDepth() const { return depth; } + int GetX() const { return x; } + int GetY() const { return y; } private: const int width; const int height; @@ -44,7 +51,7 @@ private: const int x; const int y; - int*** tiles = nullptr; + type_t*** tiles = nullptr; }; #endif diff --git a/common/map/region_pager.cpp b/common/map/region_pager.cpp index 11baea9..bbef22d 100644 --- a/common/map/region_pager.cpp +++ b/common/map/region_pager.cpp @@ -35,12 +35,12 @@ RegionPagerBase::~RegionPagerBase() { //EMPTY } -int RegionPagerBase::SetTile(int x, int y, int z, int v) { +Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) { Region* ptr = GetRegion(x, y); return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); } -int RegionPagerBase::GetTile(int x, int y, int z) { +Region::type_t RegionPagerBase::GetTile(int x, int y, int z) { Region* ptr = GetRegion(x, y); return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z); } diff --git a/common/map/region_pager.hpp b/common/map/region_pager.hpp index 9759a69..46fc612 100644 --- a/common/map/region_pager.hpp +++ b/common/map/region_pager.hpp @@ -33,8 +33,8 @@ public: RegionPagerBase(int regionWidth, int regionHeight, int regionDepth); virtual ~RegionPagerBase(); - int SetTile(int x, int y, int z, int v); - int GetTile(int x, int y, int z); + Region::type_t SetTile(int x, int y, int z, Region::type_t v); + Region::type_t GetTile(int x, int y, int z); Region* GetRegion(int x, int y); diff --git a/common/network/makefile b/common/network/makefile index fb50dee..c1b2927 100644 --- a/common/network/makefile +++ b/common/network/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. +INCLUDES+=. .. ../map LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) diff --git a/common/network/network_packet.hpp b/common/network/network_packet.hpp index a031f00..35801d5 100644 --- a/common/network/network_packet.hpp +++ b/common/network/network_packet.hpp @@ -22,9 +22,10 @@ #ifndef NETWORKPACKET_HPP_ #define NETWORKPACKET_HPP_ -#include "SDL/SDL_net.h" - #include "vector2.hpp" +#include "region.hpp" + +#include "SDL/SDL_net.h" #define PACKET_STRING_SIZE 100 @@ -61,6 +62,9 @@ union NetworkPacket { PLAYER_NEW = 10, PLAYER_DELETE = 11, PLAYER_UPDATE = 12, + + //map data + REGION_CONTENT = 13, }; //metadata on the packet itself @@ -75,6 +79,7 @@ union NetworkPacket { //TODO: version info char name[PACKET_STRING_SIZE]; //TODO: player count + //TODO: map format }serverInfo; //information about the client @@ -95,7 +100,10 @@ union NetworkPacket { }playerInfo; //map data - //... + struct MapInformation { + Metadata meta; + Region* region; + }mapInfo; //defaults NetworkPacket() { diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index 816c304..19d414b 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -56,12 +56,12 @@ EditorScene::EditorScene(ConfigUtility* const arg1): }); //setup the map - pager.SetRegionWidth(config.Int("map.pager.width")); - pager.SetRegionHeight(config.Int("map.pager.height")); - pager.SetRegionDepth(config.Int("map.pager.depth")); + pager.SetRegionWidth(REGION_WIDTH); + pager.SetRegionHeight(REGION_HEIGHT); + pager.SetRegionDepth(REGION_DEPTH); //debug - tsheet.Load("rsc\\graphics\\tilesets\\sand.bmp", 12, 3); + tsheet.Load(config["dir.tilesets"] + "sand.bmp", 12, 3); } EditorScene::~EditorScene() { diff --git a/server/server_application.cpp b/server/server_application.cpp index 6c11873..84ff4ea 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -97,13 +97,14 @@ void ServerApplication::Init(int argc, char** argv) { cout << "Initialized lua's setup script" << endl; //setup the map object - mapPager.SetRegionWidth(config.Int("map.pager.width")); - mapPager.SetRegionHeight(config.Int("map.pager.height")); - mapPager.SetRegionDepth(config.Int("map.pager.depth")); + mapPager.SetRegionWidth(REGION_WIDTH); + mapPager.SetRegionHeight(REGION_HEIGHT); + mapPager.SetRegionDepth(REGION_DEPTH); //TODO: pass args to the generator & format as needed //NOTE: I might need to rearrange the init process so that lua & SQL can interact // with the map system as needed. cout << "Initialized the map system" << endl; + cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl; //finalize the startup cout << "Startup completed successfully" << endl;