Revised TileSheet & TileSheetManager
This commit is contained in:
@@ -33,6 +33,10 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
|
||||
xCount = image.GetSurface()->w / w;
|
||||
yCount = image.GetSurface()->h / h;
|
||||
totalCount = xCount * yCount;
|
||||
|
||||
//set begin & end (usually temporary)
|
||||
begin = 0;
|
||||
end = totalCount;
|
||||
}
|
||||
|
||||
SDL_Surface* TileSheet::GetSurface() {
|
||||
|
||||
@@ -36,6 +36,7 @@ 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();
|
||||
|
||||
@@ -29,11 +29,16 @@ TileSheet* TileSheetManager::LoadSheet(std::string fname, Uint16 w, Uint16 h) {
|
||||
//get the key
|
||||
std::string key = truncatePath(fname);
|
||||
|
||||
//override what's already here
|
||||
sheetMap.erase(key);
|
||||
//don't override what's already here
|
||||
if (sheetMap.find(key) != sheetMap.end()) {
|
||||
throw(std::runtime_error("Cannot load duplicate tile sheets"));
|
||||
}
|
||||
|
||||
//load & setup the sheet object
|
||||
sheetMap[key].LoadSurface(fname, w, h);
|
||||
sheetMap[key].SetBegin(rangeEnd);
|
||||
rangeEnd += sheetMap[key].GetTotalCount();
|
||||
sheetMap[key].SetEnd(rangeEnd);
|
||||
}
|
||||
|
||||
void TileSheetManager::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
|
||||
int SetRangeEnd(int i) { return rangeEnd += i; }
|
||||
int GetRangeEnd() const { return rangeEnd; }
|
||||
|
||||
std::map<std::string, TileSheet>* GetSheetMap() { return &sheetMap; }
|
||||
private:
|
||||
std::map<std::string, TileSheet> sheetMap;
|
||||
int rangeEnd = 0;
|
||||
Reference in New Issue
Block a user