|
|
@@ -6,6 +6,10 @@
|
|
|
#include <anki/resource/ResourceManager.h>
|
|
|
#include <anki/resource/AsyncLoader.h>
|
|
|
#include <anki/resource/AnimationResource.h>
|
|
|
+#include <anki/util/Logger.h>
|
|
|
+#include <anki/core/ConfigSet.h>
|
|
|
+#include <anki/gr/ShaderCompiler.h>
|
|
|
+
|
|
|
#include <anki/resource/MaterialResource.h>
|
|
|
#include <anki/resource/MeshResource.h>
|
|
|
#include <anki/resource/ModelResource.h>
|
|
|
@@ -16,9 +20,7 @@
|
|
|
#include <anki/resource/GenericResource.h>
|
|
|
#include <anki/resource/TextureAtlasResource.h>
|
|
|
#include <anki/resource/ShaderProgramResource.h>
|
|
|
-#include <anki/util/Logger.h>
|
|
|
-#include <anki/core/ConfigSet.h>
|
|
|
-#include <anki/gr/ShaderCompiler.h>
|
|
|
+#include <anki/resource/CollisionResource.h>
|
|
|
|
|
|
namespace anki
|
|
|
{
|
|
|
@@ -52,9 +54,7 @@ Error ResourceManager::init(ResourceManagerInitInfo& init)
|
|
|
|
|
|
// Init type resource managers
|
|
|
#define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) TypeResourceManager<rsrc_>::init(m_alloc);
|
|
|
-
|
|
|
#define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
|
|
|
-
|
|
|
#include <anki/resource/InstantiationMacros.h>
|
|
|
#undef ANKI_INSTANTIATE_RESOURCE
|
|
|
#undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
|
|
|
@@ -76,4 +76,69 @@ U64 ResourceManager::getAsyncTaskCompletedCount() const
|
|
|
return m_asyncLoader->getCompletedTaskCount();
|
|
|
}
|
|
|
|
|
|
+template<typename T>
|
|
|
+Error ResourceManager::loadResource(const CString& filename, ResourcePtr<T>& out, Bool async)
|
|
|
+{
|
|
|
+ ANKI_ASSERT(!out.isCreated() && "Already loaded");
|
|
|
+
|
|
|
+ Error err = Error::NONE;
|
|
|
+ ++m_loadRequestCount;
|
|
|
+
|
|
|
+ T* const other = findLoadedResource<T>(filename);
|
|
|
+
|
|
|
+ if(other)
|
|
|
+ {
|
|
|
+ // Found
|
|
|
+ out.reset(other);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Allocate ptr
|
|
|
+ T* ptr = m_alloc.newInstance<T>(this);
|
|
|
+ ANKI_ASSERT(ptr->getRefcount().load() == 0);
|
|
|
+
|
|
|
+ // Populate the ptr. Use a block to cleanup temp_pool allocations
|
|
|
+ auto& pool = m_tmpAlloc.getMemoryPool();
|
|
|
+
|
|
|
+ {
|
|
|
+ U allocsCountBefore = pool.getAllocationsCount();
|
|
|
+ (void)allocsCountBefore;
|
|
|
+
|
|
|
+ err = ptr->load(filename, async);
|
|
|
+ if(err)
|
|
|
+ {
|
|
|
+ ANKI_RESOURCE_LOGE("Failed to load resource: %s", &filename[0]);
|
|
|
+ m_alloc.deleteInstance(ptr);
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+
|
|
|
+ ANKI_ASSERT(pool.getAllocationsCount() == allocsCountBefore && "Forgot to deallocate");
|
|
|
+ }
|
|
|
+
|
|
|
+ ptr->setFilename(filename);
|
|
|
+ ptr->setUuid(++m_uuid);
|
|
|
+
|
|
|
+ // Reset the memory pool if no-one is using it.
|
|
|
+ // NOTE: Check because resources load other resources
|
|
|
+ if(pool.getAllocationsCount() == 0)
|
|
|
+ {
|
|
|
+ pool.reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Register resource
|
|
|
+ registerResource(ptr);
|
|
|
+ out.reset(ptr);
|
|
|
+ }
|
|
|
+
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+// Instansiate the ResourceManager::loadResource()
|
|
|
+#define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) \
|
|
|
+ template Error ResourceManager::loadResource<rsrc_>(const CString& filename, ResourcePtr<rsrc_>& out, Bool async);
|
|
|
+#define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
|
|
|
+#include <anki/resource/InstantiationMacros.h>
|
|
|
+#undef ANKI_INSTANTIATE_RESOURCE
|
|
|
+#undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
|
|
|
+
|
|
|
} // end namespace anki
|