ResourceManager.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "ResourceManager.h"
  2. #include "Texture.h"
  3. #include "Material.h"
  4. #include "ShaderProg.h"
  5. #include "Mesh.h"
  6. #include "Skeleton.h"
  7. #include "SkelAnim.h"
  8. #include "LightRsrc.h"
  9. #include "ParticleEmitterProps.h"
  10. #include "Script.h"
  11. #include "Model.h"
  12. #include "Skin.h"
  13. #include "DummyRsrc.h"
  14. #include "Image.h"
  15. #include "Logger.h"
  16. // Because we are bored to write the same
  17. #define SPECIALIZE_TEMPLATE_STUFF(type__, container__) \
  18. template<> \
  19. ResourceManager::Types<type__>::Container& ResourceManager::choseContainer<type__>() \
  20. { \
  21. return container__; \
  22. } \
  23. \
  24. template<> \
  25. void ResourceManager::deallocRsrc<type__>(type__* rsrc) \
  26. { \
  27. delete rsrc; \
  28. }
  29. //SPECIALIZE_TEMPLATE_STUFF(Texture, textures)
  30. SPECIALIZE_TEMPLATE_STUFF(ShaderProg, shaderProgs)
  31. SPECIALIZE_TEMPLATE_STUFF(Material, materials)
  32. SPECIALIZE_TEMPLATE_STUFF(Mesh, meshes)
  33. SPECIALIZE_TEMPLATE_STUFF(Skeleton, skeletons)
  34. SPECIALIZE_TEMPLATE_STUFF(SkelAnim, skelAnims)
  35. SPECIALIZE_TEMPLATE_STUFF(LightRsrc, lightProps)
  36. SPECIALIZE_TEMPLATE_STUFF(ParticleEmitterProps, particleEmitterProps)
  37. SPECIALIZE_TEMPLATE_STUFF(Script, scripts)
  38. SPECIALIZE_TEMPLATE_STUFF(Model, models)
  39. SPECIALIZE_TEMPLATE_STUFF(Skin, skins)
  40. SPECIALIZE_TEMPLATE_STUFF(DummyRsrc, dummies)
  41. //======================================================================================================================
  42. // Texture Specializations =
  43. //======================================================================================================================
  44. template<>
  45. ResourceManager::Types<Texture>::Container& ResourceManager::choseContainer<Texture>()
  46. {
  47. return textures;
  48. }
  49. template<>
  50. void ResourceManager::deallocRsrc<Texture>(Texture* rsrc)
  51. {
  52. if(rsrc != dummyTex.get() && rsrc != dummyNormTex.get())
  53. {
  54. delete rsrc;
  55. }
  56. }
  57. template<>
  58. void ResourceManager::allocAndLoadRsrc(const char* filename, Texture*& ptr)
  59. {
  60. // Load the dummys
  61. if(dummyTex.get() == NULL)
  62. {
  63. dummyTex.reset(new Texture);
  64. dummyTex->load("gfx/dummy.png");
  65. }
  66. if(dummyNormTex.get() == NULL)
  67. {
  68. dummyNormTex.reset(new Texture);
  69. dummyNormTex->load("gfx/dummy.norm.png");
  70. }
  71. // Send a loading request
  72. rsrcAsyncLoadingReqsHandler.sendNewLoadingRequest(filename, &ptr);
  73. // Point to the dummy for now
  74. std::string fname(filename);
  75. size_t found = fname.find("norm.");
  76. if(found != std::string::npos)
  77. {
  78. ptr = dummyNormTex.get();
  79. }
  80. else
  81. {
  82. ptr = dummyTex.get();
  83. }
  84. }