AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 #if !defined(_CZ_XOML_RESOURCE_MANAGER_H_) 00015 #define _CZ_XOML_RESOURCE_MANAGER_H_ 00016 00017 #include "CzString.h" 00018 #include "CzUtil.h" 00019 #include "CzXoml.h" 00020 00021 class CzFont; 00022 00023 /** 00024 @addtogroup XOML 00025 @{ 00026 */ 00027 00028 /** 00029 @class CzXomlResourceManager 00030 00031 @brief CzResourceManager manages a collection of resource groups. 00032 00033 The CzXomlResourceManager manages the lifetime of a collection of IzXomlResource derived resources. When the manager is deleted all resources 00034 contained with the resource manager will be destroyed. 00035 00036 Resource management is split into 3 types: 00037 - Global - The global resource manager contains resources that are global to the entire app and will persist until the resources are manually 00038 removed or until the app closes down. 00039 - Scene local - Scenes have their own local resource manager which manage resources that are local to the scene. When the scene is destroyed, 00040 all resources managed by the scene will also be destroyed. This enables you to free up memory by simply managing scenes. 00041 - Actor local - Some types of resource are local to an actor and will be destroyed when the actor is destroyed. These types include actions, 00042 timelines and modifiers. 00043 00044 For optimal searching generally the following types of resources will have their own managers and will not be managed by the resource system: 00045 - Actions (managed by action managers) 00046 - Timelines (managed by timeline managers) 00047 - Actors (managed by scenes) 00048 - Scenes (managed by the main CzApp singleton) 00049 - XOML Variables (managed by variable managers) 00050 - XOML Programs (managed by program managers) 00051 00052 To access a scnes resource manager call CzScene::getResourceManager() 00053 To access the global resource managers resources use the CZ_GLOBAL_RESOURCE_MANAGER macro or call CZ_GLOBAL_RESOURCES->getResourceManager() 00054 00055 For more information on the global resource manager see CzGlobalResources. 00056 00057 */ 00058 class CzXomlResourceManager 00059 { 00060 public: 00061 // Public access to class creator iteration 00062 typedef CzList<IzXomlResource*>::iterator _Iterator; 00063 _Iterator begin() { return Resources.begin(); } 00064 _Iterator end() { return Resources.end(); } 00065 00066 protected: 00067 // Properties 00068 IzXomlResource* Parent; ///< Parent container scene 00069 CzList<IzXomlResource*> Resources; ///< A collection of resources 00070 public: 00071 void setParent(IzXomlResource* scene) { Parent = scene; } 00072 IzXomlResource* getParent() { return Parent; } 00073 // Properties end 00074 00075 public: 00076 CzXomlResourceManager() : Parent(NULL) {} 00077 virtual ~CzXomlResourceManager() { clearResources(); } 00078 00079 bool addResource(IzXomlResource* resource); 00080 void removeResource(IzXomlResource* resource); 00081 void removeResource(unsigned int name_hash, unsigned int type_hash); 00082 void removeTaggedResources(const char* tag); 00083 void removeTaggedResources(unsigned int tag_hash); 00084 #if defined (_DEBUG) 00085 IzXomlResource* findResourceDebug(unsigned int name_hash, unsigned int type_hash, bool global_search = true); 00086 #endif 00087 int findResourcesOfType(unsigned int type_hash, bool global_search, CzVector<IzXomlResource*>& resources); 00088 IzXomlResource* findResource(unsigned int name_hash, unsigned int type_hash, bool global_search = true); 00089 IzXomlResource* findResource(const char* name, unsigned int type_hash, bool global_search = true); 00090 IzXomlResource* findResource(const char* name, const char* type, bool global_search = true); 00091 CzFont* findFontWithFilename(const char* filename, bool global_search = true); 00092 00093 static int FindResourcesOfType(unsigned int type_hash, IzXomlResource* container, CzVector<IzXomlResource*>& resources); 00094 static IzXomlResource* FindResource(unsigned int name_hash, unsigned int type_hash, IzXomlResource* container = NULL); 00095 static IzXomlResource* FindResource(const char* name, unsigned int type_hash, IzXomlResource* container = NULL); 00096 void clearResources(); 00097 }; 00098 00099 /// @} 00100 00101 #endif // _CZ_XOML_RESOURCE_MANAGER_H_