ResourceCache.pkg 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. $#include "ResourceCache.h"
  2. class ResourceCache
  3. {
  4. void ReleaseAllResources(bool force = false);
  5. bool ReloadResource(Resource* resource);
  6. void SetMemoryBudget(ShortStringHash type, unsigned budget);
  7. void SetMemoryBudget(const String type, unsigned budget);
  8. void SetAutoReloadResources(bool enable);
  9. void SetSearchPackagesFirst(bool value);
  10. // SharedPtr<File> GetFile(const String& name);
  11. tolua_outside File* ResourceCacheGetFile @ GetFile(const String name);
  12. Resource* GetResource(const String type, const String name);
  13. bool Exists(const String name) const;
  14. unsigned GetMemoryBudget(ShortStringHash type) const;
  15. unsigned GetMemoryUse(ShortStringHash type) const;
  16. unsigned GetTotalMemoryUse() const;
  17. String GetResourceFileName(const String name) const;
  18. bool GetAutoReloadResources() const;
  19. bool GetSearchPackagesFirst() const;
  20. String GetPreferredResourceDir(const String path) const;
  21. String SanitateResourceName(const String name) const;
  22. String SanitateResourceDirName(const String name) const;
  23. tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
  24. tolua_readonly tolua_property__get_set bool autoReloadResources;
  25. tolua_readonly tolua_property__get_set bool searchPackagesFirst;
  26. };
  27. ResourceCache* GetCache();
  28. tolua_readonly tolua_property__get_set ResourceCache* cache;
  29. ${
  30. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_GetCache00
  31. static int tolua_ResourceLuaAPI_GetCache00(lua_State* tolua_S)
  32. {
  33. return ToluaGetSubsystem<ResourceCache>(tolua_S);
  34. }
  35. #define TOLUA_DISABLE_tolua_get_cache_ptr
  36. #define tolua_get_cache_ptr tolua_ResourceLuaAPI_GetCache00
  37. static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
  38. {
  39. SharedPtr<File> filePtr = cache->GetFile(fileName);
  40. if (!filePtr)
  41. return 0;
  42. File* file = filePtr.Get();
  43. filePtr.Detach();
  44. return file;
  45. }
  46. // Disable generated GetResource function.
  47. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
  48. static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
  49. {
  50. #ifndef TOLUA_RELEASE
  51. tolua_Error tolua_err;
  52. if (
  53. !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
  54. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  55. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  56. !tolua_isnoobj(tolua_S,4,&tolua_err)
  57. )
  58. goto tolua_lerror;
  59. else
  60. #endif
  61. {
  62. ResourceCache* self = (ResourceCache*) tolua_tousertype(tolua_S,1,0);
  63. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  64. const String name = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  65. #ifndef TOLUA_RELEASE
  66. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
  67. #endif
  68. {
  69. Resource* tolua_ret = (Resource*) self->GetResource(type,name);
  70. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  71. }
  72. }
  73. return 1;
  74. #ifndef TOLUA_RELEASE
  75. tolua_lerror:
  76. tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
  77. return 0;
  78. #endif
  79. }
  80. $}