ResourceCache.pkg 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. tolua_outside File* ResourceCacheGetFile @ GetFile(const String name);
  11. Resource* GetResource(const String type, const String name);
  12. bool Exists(const String name) const;
  13. unsigned GetMemoryBudget(ShortStringHash type) const;
  14. unsigned GetMemoryUse(ShortStringHash type) const;
  15. unsigned GetTotalMemoryUse() const;
  16. String GetResourceFileName(const String name) const;
  17. bool GetAutoReloadResources() const;
  18. bool GetSearchPackagesFirst() const;
  19. String GetPreferredResourceDir(const String path) const;
  20. String SanitateResourceName(const String name) const;
  21. String SanitateResourceDirName(const String name) const;
  22. tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
  23. tolua_readonly tolua_property__get_set bool autoReloadResources;
  24. tolua_readonly tolua_property__get_set bool searchPackagesFirst;
  25. };
  26. ${
  27. static File* ResourceCacheGetFile(ResourceCache* cache, const String& fileName)
  28. {
  29. SharedPtr<File> file = cache->GetFile(fileName);
  30. if (!file)
  31. return 0;
  32. else
  33. {
  34. // Need to safely detach the object from the shared pointer so that the Lua script can manually
  35. // delete the object once done. The refcount needs to be set zero or else the destructor will assert
  36. File* fileRaw = file.Get();
  37. fileRaw->AddRef();
  38. file.Reset();
  39. RefCount* refCount = fileRaw->RefCountPtr();
  40. refCount->refs_ = 0;
  41. return fileRaw;
  42. }
  43. }
  44. // Disable generated GetResource function.
  45. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
  46. static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
  47. {
  48. #ifndef TOLUA_RELEASE
  49. tolua_Error tolua_err;
  50. if (
  51. !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
  52. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  53. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  54. !tolua_isnoobj(tolua_S,4,&tolua_err)
  55. )
  56. goto tolua_lerror;
  57. else
  58. #endif
  59. {
  60. ResourceCache* self = (ResourceCache*) tolua_tousertype(tolua_S,1,0);
  61. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  62. const String name = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  63. #ifndef TOLUA_RELEASE
  64. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
  65. #endif
  66. {
  67. Resource* tolua_ret = (Resource*) self->GetResource(type,name);
  68. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  69. }
  70. }
  71. return 1;
  72. #ifndef TOLUA_RELEASE
  73. tolua_lerror:
  74. tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
  75. return 0;
  76. #endif
  77. }
  78. $}