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) {
|
void RegionPager::DrawTo(SDL_Surface* const dest, TileSheetManager* const sheetMgr, 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (auto& regionIter : regionList) {
|
for (auto& regionIter : regionList) {
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
//draw the region's location
|
//draw the region's location
|
||||||
SDL_Rect box = {
|
SDL_Rect box = {
|
||||||
Sint16(regionIter.GetX() - camX),
|
Sint16(regionIter.GetX() - camX),
|
||||||
@@ -96,27 +90,16 @@ void RegionPager::DrawTo(SDL_Surface* const dest, std::list<TileSheet>* const sh
|
|||||||
Uint16(regionIter.GetHeight())
|
Uint16(regionIter.GetHeight())
|
||||||
};
|
};
|
||||||
SDL_FillRect(dest, &box, SDL_MapRGB(dest->format, 10, 10, 20));
|
SDL_FillRect(dest, &box, SDL_MapRGB(dest->format, 10, 10, 20));
|
||||||
|
#endif
|
||||||
|
|
||||||
//draw each tile
|
//draw each tile
|
||||||
for (auto& tileIter : *regionIter.GetTiles()) {
|
for (auto& tileIter : *regionIter.GetTiles()) {
|
||||||
for (auto& sheetIter : *sheetList) {
|
sheetMgr->DrawTo(
|
||||||
if (sheetIter.InRange(tileIter.tileIndex)) {
|
dest,
|
||||||
sheetIter.DrawTo(
|
tileIter.x + regionIter.GetX() - camX,
|
||||||
dest,
|
tileIter.y + regionIter.GetY() - camY,
|
||||||
tileIter.x + regionIter.GetX() - camX,
|
tileIter.tileIndex
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#define REGIONPAGER_HPP_
|
#define REGIONPAGER_HPP_
|
||||||
|
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet_manager.hpp"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
void DeleteRegion(int x, int y);
|
void DeleteRegion(int x, int y);
|
||||||
|
|
||||||
//call this to draw to the screen
|
//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
|
//callback hooks
|
||||||
void SetOnNew(regionCallback_t f) { onNew = f; }
|
void SetOnNew(regionCallback_t f) { onNew = f; }
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ TestificateScene::TestificateScene() {
|
|||||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\water.bmp", 32, 32);
|
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\water.bmp", 32, 32);
|
||||||
|
|
||||||
cout << "Range End: " << sheetMgr.GetRangeEnd() << endl;
|
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() {
|
TestificateScene::~TestificateScene() {
|
||||||
@@ -61,9 +66,12 @@ void TestificateScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TestificateScene::Render(SDL_Surface* const screen) {
|
void TestificateScene::Render(SDL_Surface* const screen) {
|
||||||
for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
//dump all tile graphics to the screen
|
||||||
sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
// 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 "base_scene.hpp"
|
||||||
|
|
||||||
#include "tile_sheet.hpp"
|
|
||||||
#include "tile_Sheet_manager.hpp"
|
#include "tile_Sheet_manager.hpp"
|
||||||
|
#include "region_pager.hpp"
|
||||||
|
|
||||||
class TestificateScene : public BaseScene {
|
class TestificateScene : public BaseScene {
|
||||||
public:
|
public:
|
||||||
@@ -49,6 +49,7 @@ protected:
|
|||||||
|
|
||||||
//members
|
//members
|
||||||
TileSheetManager sheetMgr;
|
TileSheetManager sheetMgr;
|
||||||
|
RegionPager pager;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user