ResourceCache.pkg 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 char* type, unsigned budget);
  8. void SetAutoReloadResources(bool enable);
  9. // template <class T> T* GetResource(const String& name);
  10. Resource* GetResource(const char* type, const String& name);
  11. // template <class T> T* GetResource(const char* name);
  12. Resource* GetResource(const char* type, const char* name);
  13. bool Exists(const String& name) const;
  14. bool Exists(StringHash nameHash) const;
  15. unsigned GetMemoryBudget(ShortStringHash type) const;
  16. unsigned GetMemoryUse(ShortStringHash type) const;
  17. unsigned GetTotalMemoryUse() const;
  18. const String& GetResourceName(StringHash nameHash) const;
  19. String GetResourceFileName(const String& name) const;
  20. bool GetAutoReloadResources() const;
  21. tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
  22. tolua_readonly tolua_property__get_set bool autoReloadResources;
  23. };
  24. ${
  25. // Disable generated GetResource funciton.
  26. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
  27. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource01
  28. static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
  29. {
  30. #ifndef TOLUA_RELEASE
  31. tolua_Error tolua_err;
  32. if (
  33. !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
  34. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  35. (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const String",0,&tolua_err)) ||
  36. !tolua_isnoobj(tolua_S,4,&tolua_err)
  37. )
  38. goto tolua_lerror;
  39. else
  40. #endif
  41. {
  42. ResourceCache* self = (ResourceCache*) tolua_tousertype(tolua_S,1,0);
  43. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  44. const String* name = ((const String*) tolua_tousertype(tolua_S,3,0));
  45. #ifndef TOLUA_RELEASE
  46. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
  47. #endif
  48. {
  49. Resource* tolua_ret = (Resource*) self->GetResource(type,*name);
  50. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  51. }
  52. }
  53. return 1;
  54. #ifndef TOLUA_RELEASE
  55. tolua_lerror:
  56. tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
  57. return 0;
  58. #endif
  59. }
  60. static int tolua_ResourceLuaAPI_ResourceCache_GetResource01(lua_State* tolua_S)
  61. {
  62. tolua_Error tolua_err;
  63. if (
  64. !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
  65. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  66. !tolua_isstring(tolua_S,3,0,&tolua_err) ||
  67. !tolua_isnoobj(tolua_S,4,&tolua_err)
  68. )
  69. goto tolua_lerror;
  70. else
  71. {
  72. ResourceCache* self = (ResourceCache*) tolua_tousertype(tolua_S,1,0);
  73. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  74. const char* name = ((const char*) tolua_tostring(tolua_S,3,0));
  75. #ifndef TOLUA_RELEASE
  76. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
  77. #endif
  78. {
  79. Resource* tolua_ret = (Resource*) self->GetResource(type,name);
  80. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  81. }
  82. }
  83. return 1;
  84. tolua_lerror:
  85. return tolua_ResourceLuaAPI_ResourceCache_GetResource00(tolua_S);
  86. }
  87. $}