Fixed Region's internals

This commit is contained in:
Kayne Ruse
2014-02-28 23:14:22 +11:00
parent 02d83d1f16
commit 4629b7302b
4 changed files with 32 additions and 14 deletions
-1
View File
@@ -49,4 +49,3 @@ private:
};
#endif
+19 -4
View File
@@ -30,17 +30,32 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY):
x(argX),
y(argY)
{
tiles = static_cast<int*>(calloc(width * height * depth, sizeof(int)));
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[i][j][k] = 0;
}
}
}
}
Region::~Region() {
free(tiles);
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; j++) {
delete tiles[i][j];
}
delete tiles[i];
}
delete tiles;
}
int Region::SetTile(int x, int y, int z, int v) {
return *(tiles + x*width + y*height + z*depth) = v;
return tiles[x][y][z] = v;
}
int Region::GetTile(int x, int y, int z) {
return *(tiles + x*width + y*height + z*depth);
return tiles[x][y][z];
}
+1 -1
View File
@@ -44,7 +44,7 @@ private:
const int x;
const int y;
int* tiles = nullptr;
int*** tiles = nullptr;
};
#endif
+12 -8
View File
@@ -35,7 +35,7 @@ using namespace std;
EditorScene::EditorScene(ConfigUtility* const arg1):
config(*arg1),
region(20, 20, 1, 0, 0)
region(20, 20, 3, 0, 0)
{
//create the debugging "window"
debugInfo.CreateSurface(256, 256);
@@ -51,8 +51,8 @@ EditorScene::EditorScene(ConfigUtility* const arg1):
menuBar.SetImage(&buttonImage);
menuBar.SetEntries({
{"File", "-New", "-Open", "-Save", "-Save As...", "-Close", "Exit"},
{"Edit", "-Set Tile", "-Load Sheet", "-Delete Sheet", "-Metadata", "-Run Script"},
{"File", "New", "Open", "Save", "Save As...", "Close", "Exit"},
{"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"},
{"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"}
});
@@ -87,10 +87,14 @@ void EditorScene::Render(SDL_Surface* const screen) {
//debug
for (int i = 0; i < region.GetWidth(); i++) {
for (int j = 0; j < region.GetHeight(); j++) {
// for (int k = 0; k < region.GetDepth(); k++) {
cout << region.GetTile(i,j,0) << endl;
tsheet.DrawTo(screen, i*tsheet.GetTileW(), j*tsheet.GetTileH(), region.GetTile(i,j,0));
// }
for (int k = 0; k < region.GetDepth(); k++) {
tsheet.DrawTo(
screen,
i*tsheet.GetTileW()+region.GetX()-camera.x,
j*tsheet.GetTileH()+region.GetY()-camera.y,
region.GetTile(i,j,k)
);
}
}
}
@@ -168,7 +172,7 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
break;
case 5: {
//Quit
//EXIT
SDL_Event e;
e.type = SDL_QUIT;
SDL_PushEvent(&e);