ResourcePool.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. require "Polycode/EventDispatcher"
  2. class "ResourcePool" (EventDispatcher)
  3. function ResourcePool:__getvar(name)
  4. if name == "reloadResourcesOnModify" then
  5. return Polycode.ResourcePool_get_reloadResourcesOnModify(self.__ptr)
  6. elseif name == "dispatchChangeEvents" then
  7. return Polycode.ResourcePool_get_dispatchChangeEvents(self.__ptr)
  8. elseif name == "resourceSubscribers" then
  9. return Polycode.ResourcePool_get_resourceSubscribers(self.__ptr)
  10. elseif name == "deleteOnUnsubscribe" then
  11. return Polycode.ResourcePool_get_deleteOnUnsubscribe(self.__ptr)
  12. end
  13. if EventDispatcher["__getvar"] ~= nil then
  14. return EventDispatcher.__getvar(self, name)
  15. end
  16. end
  17. function ResourcePool:__setvar(name,value)
  18. if name == "reloadResourcesOnModify" then
  19. Polycode.ResourcePool_set_reloadResourcesOnModify(self.__ptr, value)
  20. return true
  21. elseif name == "dispatchChangeEvents" then
  22. Polycode.ResourcePool_set_dispatchChangeEvents(self.__ptr, value)
  23. return true
  24. elseif name == "resourceSubscribers" then
  25. Polycode.ResourcePool_set_resourceSubscribers(self.__ptr, value)
  26. return true
  27. elseif name == "deleteOnUnsubscribe" then
  28. Polycode.ResourcePool_set_deleteOnUnsubscribe(self.__ptr, value)
  29. return true
  30. end
  31. if EventDispatcher["__setvar"] ~= nil then
  32. return EventDispatcher.__setvar(self, name, value)
  33. else
  34. return false
  35. end
  36. end
  37. function ResourcePool:ResourcePool(...)
  38. local arg = {...}
  39. if type(arg[1]) == "table" and count(arg) == 1 then
  40. if ""..arg[1].__classname == "EventDispatcher" then
  41. self.__ptr = arg[1].__ptr
  42. return
  43. end
  44. end
  45. for k,v in pairs(arg) do
  46. if type(v) == "table" then
  47. if v.__ptr ~= nil then
  48. arg[k] = v.__ptr
  49. end
  50. end
  51. end
  52. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  53. self.__ptr = Polycode.ResourcePool(unpack(arg))
  54. end
  55. end
  56. function ResourcePool:addResource(resource)
  57. local retVal = Polycode.ResourcePool_addResource(self.__ptr, resource.__ptr)
  58. end
  59. function ResourcePool:removeResource(resource)
  60. local retVal = Polycode.ResourcePool_removeResource(self.__ptr, resource.__ptr)
  61. end
  62. function ResourcePool:hasResource(resource)
  63. local retVal = Polycode.ResourcePool_hasResource(self.__ptr, resource.__ptr)
  64. return retVal
  65. end
  66. function ResourcePool:loadResourcesFromFolder(folder, recursive)
  67. local retVal = Polycode.ResourcePool_loadResourcesFromFolder(self.__ptr, folder, recursive)
  68. end
  69. function ResourcePool:loadResourcesFromMaterialFile(path)
  70. local retVal = Polycode.ResourcePool_loadResourcesFromMaterialFile(self.__ptr, path)
  71. end
  72. function ResourcePool:loadResource(path)
  73. local retVal = Polycode.ResourcePool_loadResource(self.__ptr, path)
  74. if retVal == nil then return nil end
  75. local __c = _G["shared_ptr<Resource>"]("__skip_ptr__")
  76. __c.__ptr = retVal
  77. return __c
  78. end
  79. function ResourcePool:loadResourceWithName(path, name)
  80. local retVal = Polycode.ResourcePool_loadResourceWithName(self.__ptr, path, name)
  81. if retVal == nil then return nil end
  82. local __c = _G["shared_ptr<Resource>"]("__skip_ptr__")
  83. __c.__ptr = retVal
  84. return __c
  85. end
  86. function ResourcePool:getResource(resourceType, resourceName)
  87. local retVal = Polycode.ResourcePool_getResource(self.__ptr, resourceType, resourceName)
  88. if retVal == nil then return nil end
  89. local __c = _G["shared_ptr<Resource>"]("__skip_ptr__")
  90. __c.__ptr = retVal
  91. return __c
  92. end
  93. function ResourcePool:getFont(name)
  94. local retVal = Polycode.ResourcePool_getFont(self.__ptr, name)
  95. if retVal == nil then return nil end
  96. local __c = _G["shared_ptr<Font>"]("__skip_ptr__")
  97. __c.__ptr = retVal
  98. return __c
  99. end
  100. function ResourcePool:getMaterial(name)
  101. local retVal = Polycode.ResourcePool_getMaterial(self.__ptr, name)
  102. if retVal == nil then return nil end
  103. local __c = _G["shared_ptr<Material>"]("__skip_ptr__")
  104. __c.__ptr = retVal
  105. return __c
  106. end
  107. function ResourcePool:getShader(name)
  108. local retVal = Polycode.ResourcePool_getShader(self.__ptr, name)
  109. if retVal == nil then return nil end
  110. local __c = _G["shared_ptr<Shader>"]("__skip_ptr__")
  111. __c.__ptr = retVal
  112. return __c
  113. end
  114. function ResourcePool:loadTexture(name)
  115. local retVal = Polycode.ResourcePool_loadTexture(self.__ptr, name)
  116. if retVal == nil then return nil end
  117. local __c = _G["shared_ptr<Texture>"]("__skip_ptr__")
  118. __c.__ptr = retVal
  119. return __c
  120. end
  121. function ResourcePool:loadMesh(name)
  122. local retVal = Polycode.ResourcePool_loadMesh(self.__ptr, name)
  123. if retVal == nil then return nil end
  124. local __c = _G["shared_ptr<Mesh>"]("__skip_ptr__")
  125. __c.__ptr = retVal
  126. return __c
  127. end
  128. function ResourcePool:getName()
  129. local retVal = Polycode.ResourcePool_getName(self.__ptr)
  130. return retVal
  131. end
  132. function ResourcePool:setName(name)
  133. local retVal = Polycode.ResourcePool_setName(self.__ptr, name)
  134. end
  135. function ResourcePool:loadFont(name, path)
  136. local retVal = Polycode.ResourcePool_loadFont(self.__ptr, name, path)
  137. if retVal == nil then return nil end
  138. local __c = _G["shared_ptr<Font>"]("__skip_ptr__")
  139. __c.__ptr = retVal
  140. return __c
  141. end
  142. function ResourcePool:getResourceByPath(resourcePath)
  143. local retVal = Polycode.ResourcePool_getResourceByPath(self.__ptr, resourcePath)
  144. if retVal == nil then return nil end
  145. local __c = _G["shared_ptr<Resource>"]("__skip_ptr__")
  146. __c.__ptr = retVal
  147. return __c
  148. end
  149. function ResourcePool:Update(elapsed)
  150. local retVal = Polycode.ResourcePool_Update(self.__ptr, elapsed)
  151. end
  152. function ResourcePool:getResources(resourceType)
  153. local retVal = Polycode.ResourcePool_getResources(self.__ptr, resourceType)
  154. if retVal == nil then return nil end
  155. for i=1,count(retVal) do
  156. local __c = _G["shared_ptr<Resource"]("__skip_ptr__")
  157. __c.__ptr = retVal[i]
  158. retVal[i] = __c
  159. end
  160. return retVal
  161. end
  162. function ResourcePool:checkForChangedFiles()
  163. local retVal = Polycode.ResourcePool_checkForChangedFiles(self.__ptr)
  164. end
  165. function ResourcePool:__delete()
  166. if self then Polycode.delete_ResourcePool(self.__ptr) end
  167. end