RegionPager now uses a reference to TileSheetManager
This commit is contained in:
@@ -78,16 +78,10 @@ void RegionPager::DeleteRegion(int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
void RegionPager::DrawTo(SDL_Surface* const dest, std::list<TileSheet>* 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<TileSheet>* 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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define REGIONPAGER_HPP_
|
||||
|
||||
#include "region.hpp"
|
||||
#include "tile_sheet.hpp"
|
||||
#include "tile_sheet_manager.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -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<TileSheet>* 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; }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user