RsrcPtr.cpp 9.7 KB

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