Added a draw function to the pager

I'm also committing some simple debugging code in the scene.
This commit is contained in:
Kayne Ruse
2013-10-04 02:18:10 +10:00
parent a88a1f7cf7
commit 29928c0b92
3 changed files with 48 additions and 14 deletions
+2 -10
View File
@@ -85,15 +85,7 @@ void EditorScene::FrameEnd() {
}
void EditorScene::Render(SDL_Surface* const screen) {
for (auto& regionIter : *pager.GetRegions()) {
for (auto& tileIter : *regionIter.GetTiles()) {
for (auto& sheetIter : sheetList) {
if (sheetIter.InRange(tileIter.tileIndex)) {
sheetIter.DrawTo(screen, tileIter.x + regionIter.GetX(), tileIter.y + regionIter.GetY(), tileIter.tileIndex);
}
}
}
}
pager.DrawTo(screen, &sheetList, 0, 0);
}
//-------------------------
@@ -124,7 +116,7 @@ void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
<< endl;
;
if (++incrementer >= 180) {
if (++incrementer >= TileSheet::GetRangeEnd()) {
incrementer = 0;
}
}
+33
View File
@@ -74,3 +74,36 @@ 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
*/
for (auto& regionIter : regionList) {
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("Undrawable tile encountered"));
continueTile: ;
//continue with the next tile
}
}
}
+13 -4
View File
@@ -23,11 +23,15 @@
#define REGIONPAGER_HPP_
#include "region.hpp"
#include "tile_sheet.hpp"
#include <list>
class RegionPager {
public:
//for simplicity and consistency
typedef void (*regionCallback_t)(Region* const);
RegionPager();
~RegionPager();
@@ -36,8 +40,12 @@ public:
Region* GetRegion(int x, int y);
void DeleteRegion(int x, int y);
void SetOnDelete(void(*f)(Region* const)) { onDelete = f; }
void SetOnNew(void(*f)(Region* const)) { onNew = f; }
//call this to draw to the screen
void DrawTo(SDL_Surface* const, std::list<TileSheet>* const, int camX, int camY);
//callback hooks
void SetOnNew(regionCallback_t f) { onNew = f; }
void SetOnDelete(regionCallback_t f) { onDelete = f; }
//accessors and mutators
int SetWidth(int i) { return regionWidth = i; }
@@ -50,8 +58,9 @@ public:
private:
std::list<Region> regionList;
int regionWidth = 0, regionHeight = 0;
void (*onDelete)(Region* const) = nullptr;
void (*onNew)(Region* const) = nullptr;
regionCallback_t onNew = nullptr;
regionCallback_t onDelete = nullptr;
};
#endif