Reduced the footprint of the tiles

Also prepping for serializing the regions.
This commit is contained in:
Kayne Ruse
2014-03-15 22:59:57 +11:00
parent 7e500027e3
commit d5b551cec3
8 changed files with 49 additions and 33 deletions
+10 -10
View File
@@ -28,12 +28,12 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY):
x(argX), x(argX),
y(argY) y(argY)
{ {
tiles = new int**[width]; tiles = new type_t**[width];
for (int i = 0; i < width; ++i) { for (register int i = 0; i < width; ++i) {
tiles[i] = new int*[height]; tiles[i] = new type_t*[height];
for (int j = 0; j < height; ++j) { for (register int j = 0; j < height; ++j) {
tiles[i][j] = new int[depth]; tiles[i][j] = new type_t[depth];
for (int k = 0; k < depth; ++k) { for (register int k = 0; k < depth; ++k) {
tiles[i][j][k] = 0; tiles[i][j][k] = 0;
} }
} }
@@ -41,8 +41,8 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY):
} }
Region::~Region() { Region::~Region() {
for (int i = 0; i < width; ++i) { for (register int i = 0; i < width; ++i) {
for (int j = 0; j < height; j++) { for (register int j = 0; j < height; j++) {
delete tiles[i][j]; delete tiles[i][j];
} }
delete tiles[i]; delete tiles[i];
@@ -50,10 +50,10 @@ Region::~Region() {
delete tiles; 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; 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]; return tiles[x][y][z];
} }
+15 -8
View File
@@ -22,21 +22,28 @@
#ifndef REGION_HPP_ #ifndef REGION_HPP_
#define REGION_HPP_ #define REGION_HPP_
//temporary?
#define REGION_WIDTH 20
#define REGION_HEIGHT 20
#define REGION_DEPTH 3
class Region { class Region {
public: public:
typedef unsigned short type_t;
Region() = delete; Region() = delete;
Region(int width, int height, int depth, int x, int y); Region(int width, int height, int depth, int x, int y);
~Region(); ~Region();
int SetTile(int x, int y, int z, int v); type_t SetTile(int x, int y, int z, type_t v);
int GetTile(int x, int y, int z); type_t GetTile(int x, int y, int z);
//accessors //accessors
int GetWidth() { return width; } int GetWidth() const { return width; }
int GetHeight() { return height; } int GetHeight() const { return height; }
int GetDepth() { return depth; } int GetDepth() const { return depth; }
int GetX() { return x; } int GetX() const { return x; }
int GetY() { return y; } int GetY() const { return y; }
private: private:
const int width; const int width;
const int height; const int height;
@@ -44,7 +51,7 @@ private:
const int x; const int x;
const int y; const int y;
int*** tiles = nullptr; type_t*** tiles = nullptr;
}; };
#endif #endif
+2 -2
View File
@@ -35,12 +35,12 @@ RegionPagerBase::~RegionPagerBase() {
//EMPTY //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); Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); 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); Region* ptr = GetRegion(x, y);
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z); return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
} }
+2 -2
View File
@@ -33,8 +33,8 @@ public:
RegionPagerBase(int regionWidth, int regionHeight, int regionDepth); RegionPagerBase(int regionWidth, int regionHeight, int regionDepth);
virtual ~RegionPagerBase(); virtual ~RegionPagerBase();
int SetTile(int x, int y, int z, int v); Region::type_t SetTile(int x, int y, int z, Region::type_t v);
int GetTile(int x, int y, int z); Region::type_t GetTile(int x, int y, int z);
Region* GetRegion(int x, int y); Region* GetRegion(int x, int y);
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. .. INCLUDES+=. .. ../map
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
+11 -3
View File
@@ -22,9 +22,10 @@
#ifndef NETWORKPACKET_HPP_ #ifndef NETWORKPACKET_HPP_
#define NETWORKPACKET_HPP_ #define NETWORKPACKET_HPP_
#include "SDL/SDL_net.h"
#include "vector2.hpp" #include "vector2.hpp"
#include "region.hpp"
#include "SDL/SDL_net.h"
#define PACKET_STRING_SIZE 100 #define PACKET_STRING_SIZE 100
@@ -61,6 +62,9 @@ union NetworkPacket {
PLAYER_NEW = 10, PLAYER_NEW = 10,
PLAYER_DELETE = 11, PLAYER_DELETE = 11,
PLAYER_UPDATE = 12, PLAYER_UPDATE = 12,
//map data
REGION_CONTENT = 13,
}; };
//metadata on the packet itself //metadata on the packet itself
@@ -75,6 +79,7 @@ union NetworkPacket {
//TODO: version info //TODO: version info
char name[PACKET_STRING_SIZE]; char name[PACKET_STRING_SIZE];
//TODO: player count //TODO: player count
//TODO: map format
}serverInfo; }serverInfo;
//information about the client //information about the client
@@ -95,7 +100,10 @@ union NetworkPacket {
}playerInfo; }playerInfo;
//map data //map data
//... struct MapInformation {
Metadata meta;
Region* region;
}mapInfo;
//defaults //defaults
NetworkPacket() { NetworkPacket() {
+4 -4
View File
@@ -56,12 +56,12 @@ EditorScene::EditorScene(ConfigUtility* const arg1):
}); });
//setup the map //setup the map
pager.SetRegionWidth(config.Int("map.pager.width")); pager.SetRegionWidth(REGION_WIDTH);
pager.SetRegionHeight(config.Int("map.pager.height")); pager.SetRegionHeight(REGION_HEIGHT);
pager.SetRegionDepth(config.Int("map.pager.depth")); pager.SetRegionDepth(REGION_DEPTH);
//debug //debug
tsheet.Load("rsc\\graphics\\tilesets\\sand.bmp", 12, 3); tsheet.Load(config["dir.tilesets"] + "sand.bmp", 12, 3);
} }
EditorScene::~EditorScene() { EditorScene::~EditorScene() {
+4 -3
View File
@@ -97,13 +97,14 @@ void ServerApplication::Init(int argc, char** argv) {
cout << "Initialized lua's setup script" << endl; cout << "Initialized lua's setup script" << endl;
//setup the map object //setup the map object
mapPager.SetRegionWidth(config.Int("map.pager.width")); mapPager.SetRegionWidth(REGION_WIDTH);
mapPager.SetRegionHeight(config.Int("map.pager.height")); mapPager.SetRegionHeight(REGION_HEIGHT);
mapPager.SetRegionDepth(config.Int("map.pager.depth")); mapPager.SetRegionDepth(REGION_DEPTH);
//TODO: pass args to the generator & format as needed //TODO: pass args to the generator & format as needed
//NOTE: I might need to rearrange the init process so that lua & SQL can interact //NOTE: I might need to rearrange the init process so that lua & SQL can interact
// with the map system as needed. // with the map system as needed.
cout << "Initialized the map system" << endl; cout << "Initialized the map system" << endl;
cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl;
//finalize the startup //finalize the startup
cout << "Startup completed successfully" << endl; cout << "Startup completed successfully" << endl;