diff --git a/src/layer.cpp b/src/layer.cpp index a663f6a0..c870b803 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -40,8 +40,9 @@ Layer::~Layer() free(data); } -void Layer::Render(Scene *scene, int x, int y, int z) +void Layer::Render(int x, int y, int z) { + Scene *scene = Scene::GetDefault(); for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) if (data[j * width + i]) diff --git a/src/layer.h b/src/layer.h index 1be0a428..eb37887c 100644 --- a/src/layer.h +++ b/src/layer.h @@ -19,8 +19,6 @@ #include -#include "scene.h" - class Layer { public: @@ -29,7 +27,7 @@ public: int GetZ(); - void Render(Scene *scene, int x, int y, int z); + void Render(int x, int y, int z); private: int width, height, altitude, orientation; diff --git a/src/map.cpp b/src/map.cpp index dd316092..c01fb4b8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -160,10 +160,10 @@ Map::~Map() delete data; } -void Map::Render(Scene *scene, int x, int y, int z) +void Map::Render(int x, int y, int z) { for (int i = 0; i < data->nlayers; i++) - data->layers[i]->Render(scene, x, y, z); + data->layers[i]->Render(x, y, z); } int Map::GetWidth() diff --git a/src/map.h b/src/map.h index f13f8844..294fa85f 100644 --- a/src/map.h +++ b/src/map.h @@ -18,8 +18,6 @@ #if !defined __DH_MAP_H__ #define __DH_MAP_H__ -#include "scene.h" - class MapData; class Map @@ -28,7 +26,7 @@ public: Map(char const *path); ~Map(); - void Render(Scene *scene, int x, int y, int z); + void Render(int x, int y, int z); int GetWidth(); int GetHeight(); diff --git a/src/scene.cpp b/src/scene.cpp index e2e985e2..688cff4f 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -54,8 +54,12 @@ private: Tile *tiles; int ntiles; float angle; + + static Scene *scene; }; +Scene *SceneData::scene = NULL; + /* * Public Scene class */ @@ -73,6 +77,20 @@ Scene::~Scene() delete data; } +Scene *Scene::GetDefault() +{ + if (!SceneData::scene) + SceneData::scene = new Scene(0.0f); + return SceneData::scene; +} + +void Scene::Reset() +{ + if (SceneData::scene) + delete SceneData::scene; + SceneData::scene = NULL; +} + void Scene::AddTile(uint32_t code, int x, int y, int z, int o) { if ((data->ntiles % 1024) == 0) diff --git a/src/scene.h b/src/scene.h index ca3517c4..97f33c78 100644 --- a/src/scene.h +++ b/src/scene.h @@ -26,6 +26,9 @@ public: Scene(float angle); ~Scene(); + static Scene *GetDefault(); + static void Reset(); + void AddTile(uint32_t code, int x, int y, int z, int o); void Render(); diff --git a/src/ticker.cpp b/src/ticker.cpp index 43905b6c..599c71e7 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -224,12 +224,15 @@ void Ticker::TickDraw() { Profiler::Start(Profiler::STAT_TICK_DRAW); + Scene::GetDefault(); + /* Tick objects for the draw loop */ for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++) { switch (i) { case Entity::DRAWGROUP_HUD: + Scene::GetDefault()->Render(); Video::SetDepth(false); break; default: @@ -254,6 +257,8 @@ void Ticker::TickDraw() } } + Scene::Reset(); + Profiler::Stop(Profiler::STAT_TICK_DRAW); Profiler::Start(Profiler::STAT_TICK_BLIT); }