Skip to content

Commit

Permalink
Improved ImageManager class.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenliang committed May 6, 2011
1 parent d4a98a5 commit dbced7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions engine/image_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

#include <util\container.h>

bool ImageManager::LoadImage(const std::string path, const std::string& key)
namespace
{
Image image;
const Image kProxyImage = Image(10, 10);
}

bool ImageManager::LoadImage(const std::string& path, const std::string& key)
{
static Image image;

if (!image.LoadFromFile(path))
{
assert(false);
image = kProxyImage;
}

return util::Insert(images_, std::make_pair(key, image));
}

Expand All @@ -16,6 +26,6 @@ Image& ImageManager::GetImage(const std::string& key)
return images_[key];

assert(false);
static Image nullImage;
return nullImage;
static Image image = kProxyImage;
return image;
}
2 changes: 1 addition & 1 deletion engine/image_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ENGINE_API ImageManager : public util::IGetInstance<ImageManager>
ImageManager() {}
virtual ~ImageManager() {}

bool LoadImage(const std::string path, const std::string& key);
bool LoadImage(const std::string& path, const std::string& key);
Image& GetImage(const std::string& key);

private:
Expand Down

0 comments on commit dbced7e

Please sign in to comment.