From 8d4e2c9c4c223c23f17a911a74e08dbb0157b446 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 16 Aug 2010 23:01:16 +0000 Subject: [PATCH] Fix z-sorting of tiles. For now. --- src/debugsprite.cpp | 4 ++-- src/layer.cpp | 7 ++++--- src/layer.h | 4 ++-- src/map.cpp | 5 +++-- src/scene.cpp | 6 +++--- src/scene.h | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/debugsprite.cpp b/src/debugsprite.cpp index 591c5b36..a48fba09 100644 --- a/src/debugsprite.cpp +++ b/src/debugsprite.cpp @@ -52,8 +52,8 @@ void DebugSprite::TickRender(float delta_time) { Asset::TickRender(delta_time); - data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 200); - data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 200); + data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 32, 1); + data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 0, 1); } DebugSprite::~DebugSprite() diff --git a/src/layer.cpp b/src/layer.cpp index 800dc1ee..b082de19 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -11,11 +11,12 @@ #include "layer.h" -Layer::Layer(int w, int h, int z, uint32_t *in_data) +Layer::Layer(int w, int h, int z, int o, uint32_t *in_data) { width = w; height = h; altitude = z; + orientation = o; data = in_data; #if 0 @@ -39,8 +40,8 @@ void Layer::Render(Scene *scene, int x, int y, int z) for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) if (data[j * width + i]) - scene->AddTile(data[j * width + i], - i * 32 - x, j * 32 - y, altitude + z); + scene->AddTile(data[j * width + i], i * 32 - x, j * 32 - y, + altitude + z, orientation); } int Layer::GetZ() diff --git a/src/layer.h b/src/layer.h index 7e24d2bd..3a33660e 100644 --- a/src/layer.h +++ b/src/layer.h @@ -19,7 +19,7 @@ class Layer { public: - Layer(int w, int h, int z, uint32_t *data); + Layer(int w, int h, int z, int o, uint32_t *data); ~Layer(); int GetZ(); @@ -27,7 +27,7 @@ public: void Render(Scene *scene, int x, int y, int z); private: - int width, height, altitude; + int width, height, altitude, orientation; uint32_t *data; }; diff --git a/src/map.cpp b/src/map.cpp index e5d9f08b..bf7e2320 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -103,8 +103,9 @@ Map::Map(char const *path) if (ntiles == data->width * data->height) { - data->layers[data->nlayers] = new Layer(data->width, - data->height, level, tiles); + Layer *l = new Layer(data->width, data->height, + level, orientation, tiles); + data->layers[data->nlayers] = l; data->nlayers++; tiles = NULL; //fprintf(stderr, "new layer %ix%i\n", data->width, data->height); diff --git a/src/scene.cpp b/src/scene.cpp index 50a646a7..48d940fb 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -32,7 +32,7 @@ private: Tile const *t1 = (Tile const *)p1; Tile const *t2 = (Tile const *)p2; - return t1->prio - t2->prio; + return t2->prio - t1->prio; } Tile *tiles; @@ -55,12 +55,12 @@ Scene::~Scene() delete data; } -void Scene::AddTile(uint32_t code, int x, int y, int z) +void Scene::AddTile(uint32_t code, int x, int y, int z, int o) { if ((data->ntiles % 1024) == 0) data->tiles = (Tile *)realloc(data->tiles, (data->ntiles + 1024) * sizeof(Tile)); - data->tiles[data->ntiles].prio = 0; + data->tiles[data->ntiles].prio = y - 2 * 32 * z + (o ? 0 : 32); data->tiles[data->ntiles].code = code; data->tiles[data->ntiles].x = x; data->tiles[data->ntiles].y = y; diff --git a/src/scene.h b/src/scene.h index f187c9c8..e749be20 100644 --- a/src/scene.h +++ b/src/scene.h @@ -21,7 +21,7 @@ public: Scene(); ~Scene(); - void AddTile(uint32_t code, int x, int y, int z); + void AddTile(uint32_t code, int x, int y, int z, int o); void Render(); private: