ResourceCache.pkg 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $#include "Animation.h"
  2. $#include "Font.h"
  3. $#include "Image.h"
  4. $#include "Material.h"
  5. $#include "Model.h"
  6. $#include "ResourceCache.h"
  7. $#include "Sound.h"
  8. $#include "Technique.h"
  9. $#include "Texture2D.h"
  10. $#include "TextureCube.h"
  11. $#include "XMLFile.h"
  12. /// %Resource cache subsystem. Loads resources on demand and stores them for later access.
  13. class ResourceCache
  14. {
  15. public:
  16. /// Release all resources.
  17. void ReleaseAllResources(bool force = false);
  18. /// Reload a resource. Return false and release it if fails.
  19. bool ReloadResource(Resource* resource);
  20. /// Set memory budget for a specific resource type, default 0 is unlimited.
  21. void SetMemoryBudget(ShortStringHash type, unsigned budget);
  22. /// Enable or disable automatic reloading of resources as files are modified.
  23. void SetAutoReloadResources(bool enable);
  24. /// Template version of returning a resource by name.
  25. // template <class T> T* GetResource(const char* name);
  26. Animation* GetResource<Animation> @ GetAnimation(const char* name);
  27. Font* GetResource<Font> @ GetFont(const char* name);
  28. Image* GetResource<Image> @ GetImage(const char* name);
  29. Material* GetResource<Material> @ GetMaterial(const char* name);
  30. Model* GetResource<Model> @ GetModel(const char* name);
  31. Sound* GetResource<Sound> @ GetSound(const char* name);
  32. Technique* GetResource<Technique> @ GetTechnique(const char* name);
  33. Texture2D* GetResource<Texture2D> @ GetTexture2D(const char* name);
  34. TextureCube* GetResource<TextureCube> @ GetTextureCube(const char* name);
  35. XMLFile* GetResource<XMLFile> @ GetXMLFile(const char* name);
  36. /// Return whether a file exists by name.
  37. bool Exists(const String& name) const;
  38. /// Return whether a file exists by name hash.
  39. bool Exists(StringHash nameHash) const;
  40. /// Return memory budget for a resource type.
  41. unsigned GetMemoryBudget(ShortStringHash type) const;
  42. /// Return total memory use for a resource type.
  43. unsigned GetMemoryUse(ShortStringHash type) const;
  44. /// Return total memory use for all resources.
  45. unsigned GetTotalMemoryUse() const;
  46. /// Return resource name from hash, or empty if not found.
  47. const String& GetResourceName(StringHash nameHash) const;
  48. /// Return full absolute file name of resource if possible.
  49. String GetResourceFileName(const String& name) const;
  50. /// Return whether automatic resource reloading is enabled.
  51. bool GetAutoReloadResources() const;
  52. };