Reduced the footprint of the tiles
Also prepping for serializing the regions.
This commit is contained in:
+10
-10
@@ -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];
|
||||
}
|
||||
|
||||
+15
-8
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ..
|
||||
INCLUDES+=. .. ../map
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user