Imported graphics updates from Codebase

This commit is contained in:
Kayne Ruse
2013-06-04 05:05:40 +10:00
parent 6a16e341ec
commit 783e8928d6
9 changed files with 98 additions and 116 deletions
+7 -11
View File
@@ -23,16 +23,12 @@
#include <stdexcept>
SurfaceManager::SurfaceManager() {
//
}
SurfaceManager::~SurfaceManager() {
SurfaceManager::~SurfaceManager() noexcept {
FreeAll();
}
SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) {
mapType::iterator it = surfaceMap.find(key);
MapType::iterator it = surfaceMap.find(key);
if (it != surfaceMap.end()) {
throw(std::runtime_error(std::string("Surface already loaded: ") + key + std::string(", ") + fname));
}
@@ -40,7 +36,7 @@ SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) {
}
SDL_Surface* SurfaceManager::Reload(std::string key, std::string fname) {
mapType::iterator it = surfaceMap.find(key);
MapType::iterator it = surfaceMap.find(key);
if (it != surfaceMap.end()) {
SDL_FreeSurface(it->second);
surfaceMap.erase(it);
@@ -49,7 +45,7 @@ SDL_Surface* SurfaceManager::Reload(std::string key, std::string fname) {
}
SDL_Surface* SurfaceManager::Get(std::string key) {
mapType::iterator it = surfaceMap.find(key);
MapType::iterator it = surfaceMap.find(key);
if (it == surfaceMap.end()) {
throw(std::runtime_error(std::string("Could not find key: ") + key));
}
@@ -57,7 +53,7 @@ SDL_Surface* SurfaceManager::Get(std::string key) {
}
SDL_Surface* SurfaceManager::Set(std::string key, SDL_Surface* ptr) {
mapType::iterator it = surfaceMap.find(key);
MapType::iterator it = surfaceMap.find(key);
if (it != surfaceMap.end()) {
throw(std::runtime_error(std::string("Key already exists: ") + key));
}
@@ -65,7 +61,7 @@ SDL_Surface* SurfaceManager::Set(std::string key, SDL_Surface* ptr) {
}
void SurfaceManager::Free(std::string key) {
mapType::iterator it = surfaceMap.find(key);
MapType::iterator it = surfaceMap.find(key);
if (it != surfaceMap.end()) {
SDL_FreeSurface(it->second);
surfaceMap.erase(it);
@@ -81,7 +77,7 @@ void SurfaceManager::FreeAll() {
SDL_Surface* SurfaceManager::LoadSurface(std::string key, std::string fname) {
SDL_Surface* ptr = SDL_LoadBMP(fname.c_str());
if (ptr == nullptr) {
if (!ptr) {
throw(std::runtime_error(std::string("Failed to load file: ") + fname));
}
SDL_SetColorKey(ptr, SDL_SRCCOLORKEY, SDL_MapRGB(ptr->format, 255, 0, 255)); //default