RsrcPtr.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #include "RsrcPtr.h"
  2. #include "RsrcContainer.h"
  3. #include "Texture.h"
  4. #include "ShaderProg.h"
  5. #include "Material.h"
  6. #include "Mesh.h"
  7. #include "Skeleton.h"
  8. #include "SkelAnim.h"
  9. #include "LightData.h"
  10. #include "ParticleEmitterProps.h"
  11. #include "Script.h"
  12. #include "Model.h"
  13. #include "Skin.h"
  14. namespace RsrcContainers {
  15. extern RsrcContainer<Texture> textures;
  16. extern RsrcContainer<ShaderProg> shaderProgs;
  17. extern RsrcContainer<Material> materials;
  18. extern RsrcContainer<Mesh> meshes;
  19. extern RsrcContainer<Skeleton> skeletons;
  20. extern RsrcContainer<SkelAnim> skelAnims;
  21. extern RsrcContainer<LightData> lightProps;
  22. extern RsrcContainer<ParticleEmitterProps> particleEmitterProps;
  23. extern RsrcContainer<Script> scripts;
  24. extern RsrcContainer<Model> models;
  25. extern RsrcContainer<Skin> skins;
  26. }
  27. #define LOAD_RSRC(container) \
  28. p = RsrcContainers::container.load(filename); \
  29. return p != NULL;
  30. #define UNLOAD_RSRC(container) \
  31. if(p) \
  32. { \
  33. RsrcContainers::container.unload(p); \
  34. p = NULL; \
  35. }
  36. //======================================================================================================================
  37. // loadRsrc <Texture> =
  38. //======================================================================================================================
  39. template<>
  40. bool RsrcPtr<Texture>::loadRsrc(const char* filename)
  41. {
  42. LOAD_RSRC(textures);
  43. }
  44. //======================================================================================================================
  45. // loadRsrc <ShaderProg> =
  46. //======================================================================================================================
  47. template<>
  48. bool RsrcPtr<ShaderProg>::loadRsrc(const char* filename)
  49. {
  50. LOAD_RSRC(shaderProgs);
  51. }
  52. //======================================================================================================================
  53. // loadRsrc <Material> =
  54. //======================================================================================================================
  55. template<>
  56. bool RsrcPtr<Material>::loadRsrc(const char* filename)
  57. {
  58. LOAD_RSRC(materials);
  59. }
  60. //======================================================================================================================
  61. // loadRsrc <Mesh> =
  62. //======================================================================================================================
  63. template<>
  64. bool RsrcPtr<Mesh>::loadRsrc(const char* filename)
  65. {
  66. LOAD_RSRC(meshes);
  67. }
  68. //======================================================================================================================
  69. // loadRsrc <Skeleton> =
  70. //======================================================================================================================
  71. template<>
  72. bool RsrcPtr<Skeleton>::loadRsrc(const char* filename)
  73. {
  74. LOAD_RSRC(skeletons);
  75. }
  76. //======================================================================================================================
  77. // loadRsrc <SkelAnim> =
  78. //======================================================================================================================
  79. template<>
  80. bool RsrcPtr<SkelAnim>::loadRsrc(const char* filename)
  81. {
  82. LOAD_RSRC(skelAnims);
  83. }
  84. //======================================================================================================================
  85. // loadRsrc <LightProp> =
  86. //======================================================================================================================
  87. template<>
  88. bool RsrcPtr<LightData>::loadRsrc(const char* filename)
  89. {
  90. LOAD_RSRC(lightProps);
  91. }
  92. //======================================================================================================================
  93. // loadRsrc <ParticleEmitterProps> =
  94. //======================================================================================================================
  95. template<>
  96. bool RsrcPtr<ParticleEmitterProps>::loadRsrc(const char* filename)
  97. {
  98. LOAD_RSRC(particleEmitterProps);
  99. }
  100. //======================================================================================================================
  101. // loadRsrc <Script> =
  102. //======================================================================================================================
  103. template<>
  104. bool RsrcPtr<Script>::loadRsrc(const char* filename)
  105. {
  106. LOAD_RSRC(scripts);
  107. }
  108. //======================================================================================================================
  109. // loadRsrc <Model> =
  110. //======================================================================================================================
  111. template<>
  112. bool RsrcPtr<Model>::loadRsrc(const char* filename)
  113. {
  114. LOAD_RSRC(models);
  115. }
  116. //======================================================================================================================
  117. // loadRsrc <Skin> =
  118. //======================================================================================================================
  119. template<>
  120. bool RsrcPtr<Skin>::loadRsrc(const char* filename)
  121. {
  122. LOAD_RSRC(skins);
  123. }
  124. //----------------------------------------------------------------------------------------------------------------------
  125. //======================================================================================================================
  126. // unload <Texture> =
  127. //======================================================================================================================
  128. template<>
  129. void RsrcPtr<Texture>::unload()
  130. {
  131. UNLOAD_RSRC(textures);
  132. }
  133. //======================================================================================================================
  134. // unload <ShaderProg> =
  135. //======================================================================================================================
  136. template<>
  137. void RsrcPtr<ShaderProg>::unload()
  138. {
  139. UNLOAD_RSRC(shaderProgs);
  140. }
  141. //======================================================================================================================
  142. // unload <Material> =
  143. //======================================================================================================================
  144. template<>
  145. void RsrcPtr<Material>::unload()
  146. {
  147. UNLOAD_RSRC(materials);
  148. }
  149. //======================================================================================================================
  150. // unload <Mesh> =
  151. //======================================================================================================================
  152. template<>
  153. void RsrcPtr<Mesh>::unload()
  154. {
  155. UNLOAD_RSRC(meshes);
  156. }
  157. //======================================================================================================================
  158. // unload <Skeleton> =
  159. //======================================================================================================================
  160. template<>
  161. void RsrcPtr<Skeleton>::unload()
  162. {
  163. UNLOAD_RSRC(skeletons);
  164. }
  165. //======================================================================================================================
  166. // unload <SkelAnim> =
  167. //======================================================================================================================
  168. template<>
  169. void RsrcPtr<SkelAnim>::unload()
  170. {
  171. UNLOAD_RSRC(skelAnims);
  172. }
  173. //======================================================================================================================
  174. // unload <LightProps> =
  175. //======================================================================================================================
  176. template<>
  177. void RsrcPtr<LightData>::unload()
  178. {
  179. UNLOAD_RSRC(lightProps);
  180. }
  181. //======================================================================================================================
  182. // unload <ParticleEmitterProps> =
  183. //======================================================================================================================
  184. template<>
  185. void RsrcPtr<ParticleEmitterProps>::unload()
  186. {
  187. UNLOAD_RSRC(particleEmitterProps);
  188. }
  189. //======================================================================================================================
  190. // unload <Script> =
  191. //======================================================================================================================
  192. template<>
  193. void RsrcPtr<Script>::unload()
  194. {
  195. UNLOAD_RSRC(scripts);
  196. }
  197. //======================================================================================================================
  198. // unload <Model> =
  199. //======================================================================================================================
  200. template<>
  201. void RsrcPtr<Model>::unload()
  202. {
  203. UNLOAD_RSRC(models);
  204. }
  205. //======================================================================================================================
  206. // unload <Skin> =
  207. //======================================================================================================================
  208. template<>
  209. void RsrcPtr<Skin>::unload()
  210. {
  211. UNLOAD_RSRC(skins);
  212. }