ResourceCache.pkg 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. $#include "ResourceCache.h"
  2. class ResourceCache
  3. {
  4. void ReleaseAllResources(bool force = false);
  5. bool ReloadResource(Resource* resource);
  6. void SetMemoryBudget(StringHash type, unsigned budget);
  7. void SetMemoryBudget(const String type, unsigned budget);
  8. void SetAutoReloadResources(bool enable);
  9. void SetReturnFailedResources(bool enable);
  10. void SetSearchPackagesFirst(bool value);
  11. void SetFinishBackgroundResourcesMs(int ms);
  12. tolua_outside File* ResourceCacheGetFile @ GetFile(const String name);
  13. Resource* GetResource(const String type, const String name, bool sendEventOnFailure = true);
  14. tolua_outside bool ResourceCacheBackgroundLoadResource @ BackgroundLoadResource(const String type, const String name, bool sendEventOnFailure = true);
  15. unsigned GetNumBackgroundLoadResources() const;
  16. bool Exists(const String name) const;
  17. unsigned GetMemoryBudget(StringHash type) const;
  18. unsigned GetMemoryUse(StringHash type) const;
  19. unsigned GetTotalMemoryUse() const;
  20. String GetResourceFileName(const String name) const;
  21. bool GetAutoReloadResources() const;
  22. bool GetReturnFailedResources() const;
  23. bool GetSearchPackagesFirst() const;
  24. int GetFinishBackgroundResourcesMs() const;
  25. String GetPreferredResourceDir(const String path) const;
  26. String SanitateResourceName(const String name) const;
  27. String SanitateResourceDirName(const String name) const;
  28. tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
  29. tolua_property__get_set bool autoReloadResources;
  30. tolua_property__get_set bool returnFailedResources;
  31. tolua_property__get_set bool searchPackagesFirst;
  32. tolua_readonly tolua_property__get_set unsigned numBackgroundLoadResources;
  33. tolua_property__get_set int finishBackgroundResourcesMs;
  34. };
  35. ResourceCache* GetCache();
  36. tolua_readonly tolua_property__get_set ResourceCache* cache;
  37. ${
  38. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_GetCache00
  39. static int tolua_ResourceLuaAPI_GetCache00(lua_State* tolua_S)
  40. {
  41. return ToluaGetSubsystem<ResourceCache>(tolua_S);
  42. }
  43. #define TOLUA_DISABLE_tolua_get_cache_ptr
  44. #define tolua_get_cache_ptr tolua_ResourceLuaAPI_GetCache00
  45. static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
  46. {
  47. SharedPtr<File> filePtr = cache->GetFile(fileName);
  48. if (!filePtr)
  49. return 0;
  50. File* file = filePtr.Get();
  51. filePtr.Detach();
  52. return file;
  53. }
  54. static bool ResourceCacheBackgroundLoadResource(ResourceCache* cache, StringHash type, const String& fileName, bool sendEventOnFailure)
  55. {
  56. return cache->BackgroundLoadResource(type, fileName, sendEventOnFailure);
  57. }
  58. $}