ResourceManager.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. class "ResourceManager"
  2. function ResourceManager:ResourceManager(...)
  3. for k,v in pairs(arg) do
  4. if type(v) == "table" then
  5. if v.__ptr ~= nil then
  6. arg[k] = v.__ptr
  7. end
  8. end
  9. end
  10. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  11. self.__ptr = Polycore.ResourceManager(unpack(arg))
  12. Polycore.__ptr_lookup[self.__ptr] = self
  13. end
  14. end
  15. function ResourceManager:addResource(resource)
  16. local retVal = Polycore.ResourceManager_addResource(self.__ptr, resource.__ptr)
  17. end
  18. function ResourceManager:addDirResource(dirPath, recursive)
  19. local retVal = Polycore.ResourceManager_addDirResource(self.__ptr, dirPath.__ptr, recursive)
  20. end
  21. function ResourceManager:addArchive(zipPath)
  22. local retVal = Polycore.ResourceManager_addArchive(self.__ptr, zipPath.__ptr)
  23. end
  24. function ResourceManager:readFile(fileName)
  25. local retVal = Polycore.ResourceManager_readFile(self.__ptr, fileName.__ptr)
  26. return retVal
  27. end
  28. function ResourceManager:parseTextures(dirPath, recursive)
  29. local retVal = Polycore.ResourceManager_parseTextures(self.__ptr, dirPath.__ptr, recursive)
  30. end
  31. function ResourceManager:parseMaterials(dirPath, recursive)
  32. local retVal = Polycore.ResourceManager_parseMaterials(self.__ptr, dirPath.__ptr, recursive)
  33. end
  34. function ResourceManager:parseShaders(dirPath, recursive)
  35. local retVal = Polycore.ResourceManager_parseShaders(self.__ptr, dirPath.__ptr, recursive)
  36. end
  37. function ResourceManager:parsePrograms(dirPath, recursive)
  38. local retVal = Polycore.ResourceManager_parsePrograms(self.__ptr, dirPath.__ptr, recursive)
  39. end
  40. function ResourceManager:parseCubemaps(dirPath, recursive)
  41. local retVal = Polycore.ResourceManager_parseCubemaps(self.__ptr, dirPath.__ptr, recursive)
  42. end
  43. function ResourceManager:parseOthers(dirPath, recursive)
  44. local retVal = Polycore.ResourceManager_parseOthers(self.__ptr, dirPath.__ptr, recursive)
  45. end
  46. function ResourceManager:getResource(resourceType, resourceName)
  47. local retVal = Polycore.ResourceManager_getResource(self.__ptr, resourceType, resourceName.__ptr)
  48. if retVal == nil then return nil end
  49. if Polycore.__ptr_lookup[retVal] ~= nil then
  50. return Polycore.__ptr_lookup[retVal]
  51. else
  52. Polycore.__ptr_lookup[retVal] = Resource("__skip_ptr__")
  53. Polycore.__ptr_lookup[retVal].__ptr = retVal
  54. return Polycore.__ptr_lookup[retVal]
  55. end
  56. end
  57. function ResourceManager:addShaderModule(module)
  58. local retVal = Polycore.ResourceManager_addShaderModule(self.__ptr, module.__ptr)
  59. end
  60. function ResourceManager:__delete()
  61. Polycore.__ptr_lookup[self.__ptr] = nil
  62. Polycore.delete_ResourceManager(self.__ptr)
  63. end