From 3c31c2872d11b27e7814c3bbf15d96136b72c23a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 6 Dec 2023 08:59:19 -0600 Subject: [PATCH] Added some extra functions for managing assets. --- src/dawn/asset/AssetManager.cpp | 10 ++++++++++ src/dawn/asset/AssetManager.hpp | 16 ++++++++++++++++ src/dawnhelloworld/scene/HelloWorldScene.cpp | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index ca45a8e9..ce40768f 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -50,6 +50,16 @@ void AssetManager::removeExisting(const std::string filename) { } } +bool_t AssetManager::isEverythingLoaded() { + return pendingAssetLoaders.size() == 0; +} + +bool_t AssetManager::isLoaded(const std::string filename) { + auto existing = this->getExisting(filename); + if(existing) return existing->loaded; + return false; +} + template<> std::shared_ptr AssetManager::get( const std::string filename diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index cd6f07eb..d9ec5034 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -60,6 +60,22 @@ namespace Dawn { */ void update(); + /** + * Returns whether the asset manager has loaded all of the currently + * managed assets. + * + * @return True if all assets have been loaded. + */ + bool_t isEverythingLoaded(); + + /** + * Returns whether the asset manager has loaded the given asset. + * + * @param filename The filename of the asset to check. + * @return True if the asset has been loaded. + */ + bool_t isLoaded(const std::string filename); + /** * Returns the asset loader for the given asset. * diff --git a/src/dawnhelloworld/scene/HelloWorldScene.cpp b/src/dawnhelloworld/scene/HelloWorldScene.cpp index 4fc69b6a..18e1e414 100644 --- a/src/dawnhelloworld/scene/HelloWorldScene.cpp +++ b/src/dawnhelloworld/scene/HelloWorldScene.cpp @@ -20,6 +20,10 @@ std::shared_ptr texture; void Dawn::helloWorldScene(Scene &s) { texture = s.getGame()->assetManager.get("ysabeau_regular", 12); + while(!s.getGame()->assetManager.isLoaded("ysabeau_regular")) { + s.getGame()->assetManager.update(); + } + auto cameraItem = s.createSceneItem(); auto camera = cameraItem->addComponent(); cameraItem->lookAt({ 5, 5, 5 }, { 0, 0, 0 }, { 0, 1, 0 });