Slight refactoring

This commit is contained in:
Kayne Ruse
2013-10-22 20:19:09 +11:00
parent bc32f2a2f0
commit 77a90f9c0c
6 changed files with 43 additions and 25 deletions
+2 -6
View File
@@ -23,7 +23,7 @@
#include <stdexcept>
SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
void TileSheet::Load(std::string fname, Uint16 w, Uint16 h) {
//setup the image
image.LoadSurface(fname);
image.SetClipW(w);
@@ -39,11 +39,7 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
end = totalCount;
}
SDL_Surface* TileSheet::GetSurface() {
return image.GetSurface();
}
void TileSheet::FreeSurface() {
void TileSheet::Unload() {
image.FreeSurface();
totalCount = xCount = yCount = 0;
begin = end = -1;
+5 -3
View File
@@ -37,9 +37,8 @@ public:
//these load/set functions need to be followed by bookkeeping code
//w & h are the width & height of individual tiles
//TODO: rename these
SDL_Surface* LoadSurface(std::string fname, Uint16 w, Uint16 h);
SDL_Surface* GetSurface();
void FreeSurface();
void Load(std::string fname, Uint16 w, Uint16 h);
void Unload();
void DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex);
@@ -48,6 +47,9 @@ public:
//accessors and mutators
Image* GetImage() { return &image; }
int GetTileW() const { return image.GetClipW(); }
int GetTileH() const { return image.GetClipH(); }
int GetTotalCount() const { return totalCount; }
int GetXCount() const { return xCount; }
int GetYCount() const { return yCount; }
+21 -1
View File
@@ -35,10 +35,30 @@ TileSheet* TileSheetManager::LoadSheet(std::string fname, Uint16 w, Uint16 h) {
}
//load & setup the sheet object
sheetMap[key].LoadSurface(fname, w, h);
sheetMap[key].Load(fname, w, h);
sheetMap[key].SetBegin(rangeEnd);
rangeEnd += sheetMap[key].GetTotalCount();
sheetMap[key].SetEnd(rangeEnd);
//you can modify the object, say, during the save & load routines...
return &sheetMap[key];
}
TileSheet* TileSheetManager::GetSheet(std::string name) {
return &sheetMap.at(name);
}
TileSheet* TileSheetManager::GetSheetByIndex(int tileIndex) {
for (auto& it : sheetMap) {
if (it.second.InRange(tileIndex)) {
return &it.second;
}
}
return nullptr;
}
void TileSheetManager::UnloadSheet(std::string name) {
sheetMap.erase(name);
}
void TileSheetManager::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
+3 -6
View File
@@ -33,12 +33,9 @@ public:
~TileSheetManager() = default;
TileSheet* LoadSheet(std::string fname, Uint16 w, Uint16 h);
TileSheet* GetSheet(std::string name) {
return &sheetMap.at(name);
}
void UnloadSheet(std::string name) {
sheetMap.erase(name);
}
TileSheet* GetSheet(std::string name);
TileSheet* GetSheetByIndex(int tileIndex);
void UnloadSheet(std::string name);
void DrawTo(SDL_Surface* const, int x, int y, int tileIndex);
+10 -9
View File
@@ -63,7 +63,7 @@ EditorScene::EditorScene() {
pager.SetHeight(32*4);
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\grass.bmp", 32, 32);
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\longgrass.bmp", 32, 32);
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\longgrass.bmp", 16, 16);
// loadGameMap("rsc\\maps\\mappy", &pager, &sheetList);
// saveGameMap("rsc\\maps\\foo", &pager, &sheetList);
@@ -145,19 +145,20 @@ void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
menuBar.MouseButtonDown(button);
if (button.button == SDL_BUTTON_LEFT && button.y >= buttonImage.GetClipH()) {
Region* ptr = pager.GetRegion(
Region* regionPtr = pager.GetRegion(
snapToBase(pager.GetWidth(), button.x + camera.x),
snapToBase(pager.GetHeight(), button.y + camera.y)
);
//TODO: find the tileset matching this value, and then use it's width & height for param 4 & 5
ptr->NewTileA({
snapToBase(32, button.x + camera.x), //x
snapToBase(32, button.y + camera.y), //y
TileSheet* sheetPtr = sheetMgr.GetSheetByIndex(tileCounter);
regionPtr->NewTileA({
snapToBase(sheetPtr->GetTileW(), button.x + camera.x), //x
snapToBase(sheetPtr->GetTileH(), button.y + camera.y), //y
0, //depth
32, //width (from tileset)
32, //height (from tileset)
0 //value
sheetPtr->GetTileW(), //width
sheetPtr->GetTileH(), //height
tileCounter++ //value
});
}
}
+2
View File
@@ -71,6 +71,8 @@ protected:
struct {
int x = 0, y = 0;
} camera;
int tileCounter = 0;
};
#endif