Imported graphics updates from Codebase
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user