2
0

ResourceCache.pkg 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 SetReturnFailedResources(bool enable);
  10. void SetSearchPackagesFirst(bool value);
  11. tolua_outside File* ResourceCacheGetFile @ GetFile(const String name);
  12. Resource* GetResource(const String type, const String name, bool SendEventOnFailure = true);
  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 GetReturnFailedResources() const;
  20. bool GetSearchPackagesFirst() const;
  21. String GetPreferredResourceDir(const String path) const;
  22. String SanitateResourceName(const String name) const;
  23. String SanitateResourceDirName(const String name) const;
  24. tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
  25. tolua_readonly tolua_property__get_set bool autoReloadResources;
  26. tolua_readonly tolua_property__get_set bool returnFailedResources;
  27. tolua_readonly tolua_property__get_set bool searchPackagesFirst;
  28. };
  29. ResourceCache* GetCache();
  30. tolua_readonly tolua_property__get_set ResourceCache* cache;
  31. ${
  32. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_GetCache00
  33. static int tolua_ResourceLuaAPI_GetCache00(lua_State* tolua_S)
  34. {
  35. return ToluaGetSubsystem<ResourceCache>(tolua_S);
  36. }
  37. #define TOLUA_DISABLE_tolua_get_cache_ptr
  38. #define tolua_get_cache_ptr tolua_ResourceLuaAPI_GetCache00
  39. static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
  40. {
  41. SharedPtr<File> filePtr = cache->GetFile(fileName);
  42. if (!filePtr)
  43. return 0;
  44. File* file = filePtr.Get();
  45. filePtr.Detach();
  46. return file;
  47. }
  48. // Disable generated GetResource function.
  49. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
  50. static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
  51. {
  52. #ifndef TOLUA_RELEASE
  53. tolua_Error tolua_err;
  54. if (
  55. !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
  56. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  57. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  58. !tolua_isboolean(tolua_S,4,1,&tolua_err) ||
  59. !tolua_isnoobj(tolua_S,5,&tolua_err)
  60. )
  61. goto tolua_lerror;
  62. else
  63. #endif
  64. {
  65. ResourceCache* self = (ResourceCache*) tolua_tousertype(tolua_S,1,0);
  66. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  67. const String name = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  68. bool SendEventOnFailure = ((bool) tolua_toboolean(tolua_S,4,true));
  69. #ifndef TOLUA_RELEASE
  70. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
  71. #endif
  72. {
  73. Resource* tolua_ret = (Resource*) self->GetResource(type,name,SendEventOnFailure);
  74. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  75. }
  76. }
  77. return 1;
  78. #ifndef TOLUA_RELEASE
  79. tolua_lerror:
  80. tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
  81. return 0;
  82. #endif
  83. }
  84. $}