UGDK
|
00001 #ifndef UGDK_BASE_RESOURCEMANAGER_H_ 00002 #define UGDK_BASE_RESOURCEMANAGER_H_ 00003 00004 #include <typeinfo> 00005 #include <map> 00006 #include <ugdk/action.h> 00007 #include <ugdk/base/resourcecontainer.h> 00008 #include <ugdk/graphic.h> 00009 #include <ugdk/util.h> 00010 00011 #define RESOURCE_MANAGER() (ugdk::Engine::reference()->resource_manager()) 00012 00013 namespace ugdk { 00014 namespace base { 00015 00016 class ResourceManager { 00017 public: 00018 ResourceManager(); 00019 ~ResourceManager(); 00020 00021 static graphic::Texture* GetTextureFromTag (const std::string& tag); 00022 static graphic::Texture* GetTextureFromFile (const std::string& file); 00023 static graphic::Spritesheet* GetSpritesheetFromTag (const std::string& tag); 00024 static action::AnimationSet* GetAnimationSetFromFile (const std::string& file); 00025 static graphic::Text* CreateTextFromLanguageTag(const std::string& tag); 00026 00027 // Generic Methods 00028 template <class T> 00029 void add_container(ResourceContainer<T>* container) { 00030 containers_[&typeid(T)] = container; 00031 } 00032 00033 template <class T> 00034 ResourceContainer<T>& get_container() { 00035 ResourceContainerBase* base = containers_[&typeid(T)]; 00036 ResourceContainer<T>* container = static_cast<ResourceContainer<T>*>(base); 00037 return *container; 00038 } 00039 00040 // Retro-compatibility 00041 ResourceContainer<graphic::Texture*>& texture_container() { return get_container<graphic::Texture*>(); } 00042 ResourceContainer<graphic::Spritesheet*>& spritesheet_container() { return get_container<graphic::Spritesheet*>(); } 00043 ResourceContainer<action::AnimationSet*>& animation_loader() { return get_container<action::AnimationSet*>(); } 00044 ResourceContainer<LanguageWord*>& word_container() { return get_container<LanguageWord*>(); } 00045 00046 private: 00047 typedef std::map<const std::type_info*, ResourceContainerBase*, 00048 bool (*)(const std::type_info*, const std::type_info*) > ResourceMap; 00049 ResourceMap containers_; 00050 }; 00051 00052 } // namespace base 00053 } // namespace ugdk 00054 00055 #endif // UGDK_BASE_RESOURCEMANAGER_H_ 00056