From 76bfecd4665ad30b24c4fc4393e91e6aeb832c14 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 22 Oct 2013 19:35:24 +1100 Subject: [PATCH] RegionPager now uses a reference to TileSheetManager --- common/mapsystem/region_pager.cpp | 37 +++++++++---------------------- common/mapsystem/region_pager.hpp | 4 ++-- editor/testificate_scene.cpp | 14 +++++++++--- editor/testificate_scene.hpp | 3 ++- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/common/mapsystem/region_pager.cpp b/common/mapsystem/region_pager.cpp index 3394d0f..7e6ed7b 100644 --- a/common/mapsystem/region_pager.cpp +++ b/common/mapsystem/region_pager.cpp @@ -78,16 +78,10 @@ void RegionPager::DeleteRegion(int x, int y) { } } -void RegionPager::DrawTo(SDL_Surface* const dest, std::list* const sheetList, int camX, int camY) { - /* for each region: - * for each tile within that reagon - * if you have the correct tile sheet - * draw to the screen - * else - * error - */ - +void RegionPager::DrawTo(SDL_Surface* const dest, TileSheetManager* const sheetMgr, int camX, int camY) { for (auto& regionIter : regionList) { + +#ifdef DEBUG //draw the region's location SDL_Rect box = { Sint16(regionIter.GetX() - camX), @@ -96,27 +90,16 @@ void RegionPager::DrawTo(SDL_Surface* const dest, std::list* const sh Uint16(regionIter.GetHeight()) }; SDL_FillRect(dest, &box, SDL_MapRGB(dest->format, 10, 10, 20)); +#endif //draw each tile for (auto& tileIter : *regionIter.GetTiles()) { - for (auto& sheetIter : *sheetList) { - if (sheetIter.InRange(tileIter.tileIndex)) { - sheetIter.DrawTo( - dest, - tileIter.x + regionIter.GetX() - camX, - tileIter.y + regionIter.GetY() - camY, - tileIter.tileIndex - ); - //skip to the next tile - goto continueTile; - } - } - - //reaching this point without rendering means that the tile is invalid - throw(std::runtime_error(std::string("Undrawable tile encountered: ") + to_string_custom(tileIter.tileIndex))); - - continueTile: ; - //continue with the next tile + sheetMgr->DrawTo( + dest, + tileIter.x + regionIter.GetX() - camX, + tileIter.y + regionIter.GetY() - camY, + tileIter.tileIndex + ); } } } diff --git a/common/mapsystem/region_pager.hpp b/common/mapsystem/region_pager.hpp index c75f58b..54cba33 100644 --- a/common/mapsystem/region_pager.hpp +++ b/common/mapsystem/region_pager.hpp @@ -23,7 +23,7 @@ #define REGIONPAGER_HPP_ #include "region.hpp" -#include "tile_sheet.hpp" +#include "tile_sheet_manager.hpp" #include @@ -41,7 +41,7 @@ public: void DeleteRegion(int x, int y); //call this to draw to the screen - void DrawTo(SDL_Surface* const, std::list* const, int camX, int camY); + void DrawTo(SDL_Surface* const, TileSheetManager* const, int camX, int camY); //callback hooks void SetOnNew(regionCallback_t f) { onNew = f; } diff --git a/editor/testificate_scene.cpp b/editor/testificate_scene.cpp index 34b84a8..6ab4653 100644 --- a/editor/testificate_scene.cpp +++ b/editor/testificate_scene.cpp @@ -38,6 +38,11 @@ TestificateScene::TestificateScene() { sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\water.bmp", 32, 32); cout << "Range End: " << sheetMgr.GetRangeEnd() << endl; + + pager.SetWidth(128); + pager.SetHeight(128); + + pager.GetRegion(0, 0)->NewTileR({0, 0, 0, 32, 32, 0}); } TestificateScene::~TestificateScene() { @@ -61,9 +66,12 @@ void TestificateScene::FrameEnd() { } void TestificateScene::Render(SDL_Surface* const screen) { - for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) { - sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i); - } + //dump all tile graphics to the screen +// for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) { +// sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i); +// } + + pager.DrawTo(screen, &sheetMgr, 0, 0); } //------------------------- diff --git a/editor/testificate_scene.hpp b/editor/testificate_scene.hpp index e8f22d4..416b470 100644 --- a/editor/testificate_scene.hpp +++ b/editor/testificate_scene.hpp @@ -24,8 +24,8 @@ #include "base_scene.hpp" -#include "tile_sheet.hpp" #include "tile_Sheet_manager.hpp" +#include "region_pager.hpp" class TestificateScene : public BaseScene { public: @@ -49,6 +49,7 @@ protected: //members TileSheetManager sheetMgr; + RegionPager pager; }; #endif