ResourceManager.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "anki/resource/ResourceManager.h"
  6. #include "anki/resource/AsyncLoader.h"
  7. #include "anki/resource/Animation.h"
  8. #include "anki/resource/Material.h"
  9. #include "anki/resource/Mesh.h"
  10. #include "anki/resource/Model.h"
  11. #include "anki/resource/Script.h"
  12. #include "anki/resource/DummyRsrc.h"
  13. #include "anki/resource/ShaderResource.h"
  14. #include "anki/resource/ParticleEmitterResource.h"
  15. #include "anki/resource/TextureResource.h"
  16. #include "anki/resource/GenericResource.h"
  17. #include "anki/util/Logger.h"
  18. #include "anki/misc/ConfigSet.h"
  19. namespace anki {
  20. //==============================================================================
  21. ResourceManager::ResourceManager()
  22. {}
  23. //==============================================================================
  24. ResourceManager::~ResourceManager()
  25. {
  26. m_cacheDir.destroy(m_alloc);
  27. m_shadersPrependedSource.destroy(m_alloc);
  28. m_alloc.deleteInstance(m_asyncLoader);
  29. }
  30. //==============================================================================
  31. Error ResourceManager::create(Initializer& init)
  32. {
  33. Error err = ErrorCode::NONE;
  34. m_gr = init.m_gr;
  35. m_physics = init.m_physics;
  36. m_fs = init.m_resourceFs;
  37. m_alloc = ResourceAllocator<U8>(
  38. init.m_allocCallback, init.m_allocCallbackData);
  39. m_tmpAlloc = TempResourceAllocator<U8>(
  40. init.m_allocCallback, init.m_allocCallbackData,
  41. init.m_tempAllocatorMemorySize);
  42. m_cacheDir.create(m_alloc, init.m_cacheDir);
  43. // Init some constants
  44. //
  45. m_maxTextureSize = init.m_config->getNumber("maxTextureSize");
  46. m_textureAnisotropy = init.m_config->getNumber("textureAnisotropy");
  47. // Init type resource managers
  48. //
  49. #define ANKI_RESOURCE(type_) \
  50. TypeResourceManager<type_>::init(m_alloc);
  51. ANKI_RESOURCE(Animation)
  52. ANKI_RESOURCE(TextureResource)
  53. ANKI_RESOURCE(ShaderResource)
  54. ANKI_RESOURCE(Material)
  55. ANKI_RESOURCE(Mesh)
  56. ANKI_RESOURCE(Skeleton)
  57. ANKI_RESOURCE(ParticleEmitterResource)
  58. ANKI_RESOURCE(Model)
  59. ANKI_RESOURCE(Script)
  60. ANKI_RESOURCE(DummyRsrc)
  61. ANKI_RESOURCE(CollisionResource)
  62. ANKI_RESOURCE(GenericResource)
  63. #undef ANKI_RESOURCE
  64. // Init the thread
  65. m_asyncLoader = m_alloc.newInstance<AsyncLoader>();
  66. err = m_asyncLoader->create(m_alloc);
  67. return err;
  68. }
  69. } // end namespace anki