diff --git a/src/dawn/asset/AssetLoader.cpp b/src/dawn/asset/AssetLoader.cpp index 69ebb4cc..d289b5e8 100644 --- a/src/dawn/asset/AssetLoader.cpp +++ b/src/dawn/asset/AssetLoader.cpp @@ -8,6 +8,8 @@ using namespace Dawn; +const std::string AssetLoader::ASSET_TYPE = "unknown"; + AssetLoader::AssetLoader( const std::shared_ptr assetManager, const std::string name diff --git a/src/dawn/asset/AssetLoader.hpp b/src/dawn/asset/AssetLoader.hpp index 142ebe9e..a881bf13 100644 --- a/src/dawn/asset/AssetLoader.hpp +++ b/src/dawn/asset/AssetLoader.hpp @@ -14,9 +14,10 @@ namespace Dawn { std::weak_ptr assetManager; public: + const static std::string ASSET_TYPE; + const std::string name; bool_t loaded = false; - /** * Create an abstract Asset object. @@ -42,6 +43,13 @@ namespace Dawn { */ virtual void updateAsync() = 0; + /** + * Returns the asset type. + * + * @return The asset type. + */ + virtual std::string getAssetType() const = 0; + /** * Returns the asset manager. * diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index 184f9a38..e23c7cf4 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -27,38 +27,33 @@ void AssetManager::update() { } } -void AssetManager::removeExisting(const std::string &filename) { - auto existing = std::find_if( - pendingAssetLoaders.begin(), pendingAssetLoaders.end(), - [&](auto &loader) { - return loader->name == filename; - } - ); - if(existing != pendingAssetLoaders.end()) { - pendingAssetLoaders.erase(existing); - } +// Disabled because it does not respect scopes +// void AssetManager::removeExisting(const std::string &filename) { +// auto existing = std::find_if( +// pendingAssetLoaders.begin(), pendingAssetLoaders.end(), +// [&](auto &loader) { +// return loader->name == filename; +// } +// ); +// if(existing != pendingAssetLoaders.end()) { +// pendingAssetLoaders.erase(existing); +// } - existing = std::find_if( - finishedAssetLoaders.begin(), finishedAssetLoaders.end(), - [&](auto &loader) { - return loader->name == filename; - } - ); - if(existing != finishedAssetLoaders.end()) { - finishedAssetLoaders.erase(existing); - } -} +// existing = std::find_if( +// finishedAssetLoaders.begin(), finishedAssetLoaders.end(), +// [&](auto &loader) { +// return loader->name == filename; +// } +// ); +// if(existing != finishedAssetLoaders.end()) { +// finishedAssetLoaders.erase(existing); +// } +// } 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; -} - AssetManager::~AssetManager() { } \ No newline at end of file diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index abf28611..c80ef839 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -25,7 +25,10 @@ namespace Dawn { pendingAssetLoaders.begin(), pendingAssetLoaders.end(), [&](auto &loader) { - return loader->name == filename; + return ( + loader->name == filename && + loader->getAssetType() == T::ASSET_TYPE + ); } ); @@ -33,7 +36,10 @@ namespace Dawn { existing = std::find_if( finishedAssetLoaders.begin(), finishedAssetLoaders.end(), [&](auto &loader) { - return loader->name == filename; + return ( + loader->name == filename && + loader->getAssetType() == T::ASSET_TYPE + ); } ); @@ -69,14 +75,6 @@ namespace Dawn { */ 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/dawn/asset/loader/JSONLoader.cpp b/src/dawn/asset/loader/JSONLoader.cpp index ef109212..5e77a223 100644 --- a/src/dawn/asset/loader/JSONLoader.cpp +++ b/src/dawn/asset/loader/JSONLoader.cpp @@ -7,6 +7,8 @@ using namespace Dawn; +const std::string JSONLoader::ASSET_TYPE = "json"; + JSONLoader::JSONLoader( const std::shared_ptr assetManager, const std::string name @@ -30,6 +32,10 @@ void JSONLoader::updateAsync() { void JSONLoader::updateSync() { } +std::string JSONLoader::getAssetType() const { + return JSONLoader::ASSET_TYPE; +} + JSONLoader::~JSONLoader() { } diff --git a/src/dawn/asset/loader/JSONLoader.hpp b/src/dawn/asset/loader/JSONLoader.hpp index 3441345f..43259a21 100644 --- a/src/dawn/asset/loader/JSONLoader.hpp +++ b/src/dawn/asset/loader/JSONLoader.hpp @@ -23,6 +23,8 @@ namespace Dawn { enum JSONLoaderState state; public: + const static std::string ASSET_TYPE; + json data; JSONLoader( @@ -31,6 +33,7 @@ namespace Dawn { ); void updateSync() override; void updateAsync() override; + std::string getAssetType() const override; ~JSONLoader(); }; } \ No newline at end of file diff --git a/src/dawn/asset/loader/SceneLoader.cpp b/src/dawn/asset/loader/SceneLoader.cpp index dd861a5e..f8c4ce33 100644 --- a/src/dawn/asset/loader/SceneLoader.cpp +++ b/src/dawn/asset/loader/SceneLoader.cpp @@ -7,6 +7,8 @@ using namespace Dawn; +const std::string SceneLoader::ASSET_TYPE = "scene"; + SceneLoader::SceneLoader( const std::shared_ptr assetManager, const std::string name @@ -35,6 +37,10 @@ void SceneLoader::updateSync() { } +std::string SceneLoader::getAssetType() const { + return SceneLoader::ASSET_TYPE; +} + std::shared_ptr SceneLoader::getScene() { return scene; } diff --git a/src/dawn/asset/loader/SceneLoader.hpp b/src/dawn/asset/loader/SceneLoader.hpp index 0f72cd0b..4f1ae682 100644 --- a/src/dawn/asset/loader/SceneLoader.hpp +++ b/src/dawn/asset/loader/SceneLoader.hpp @@ -21,12 +21,15 @@ namespace Dawn { std::shared_ptr scene; public: + const static std::string ASSET_TYPE; + SceneLoader( const std::shared_ptr assetManager, const std::string name ); void updateSync() override; void updateAsync() override; + std::string getAssetType() const override; /** * Returns the Scene that was loaded, or nullptr if not loaded. diff --git a/src/dawn/asset/loader/TextureLoader.cpp b/src/dawn/asset/loader/TextureLoader.cpp index 6f0261e7..fb3b5503 100644 --- a/src/dawn/asset/loader/TextureLoader.cpp +++ b/src/dawn/asset/loader/TextureLoader.cpp @@ -8,6 +8,8 @@ using namespace Dawn; +const std::string TextureLoader::ASSET_TYPE = "texture"; + TextureLoader::TextureLoader( const std::shared_ptr assetManager, const std::string name @@ -137,6 +139,10 @@ void TextureLoader::updateSync() { this->loaded = true; } +std::string TextureLoader::getAssetType() const { + return TextureLoader::ASSET_TYPE; +} + std::shared_ptr TextureLoader::getTexture() { return this->texture; } diff --git a/src/dawn/asset/loader/TextureLoader.hpp b/src/dawn/asset/loader/TextureLoader.hpp index 3fd0b8f4..5d51fd4f 100644 --- a/src/dawn/asset/loader/TextureLoader.hpp +++ b/src/dawn/asset/loader/TextureLoader.hpp @@ -33,6 +33,8 @@ namespace Dawn { std::shared_ptr texture; public: + const static std::string ASSET_TYPE; + TextureLoader( const std::shared_ptr assetManager, const std::string name @@ -40,6 +42,7 @@ namespace Dawn { void updateSync() override; void updateAsync() override; + std::string getAssetType() const override; /** * Get the texture asset. diff --git a/src/dawn/asset/loader/TrueTypeLoader.cpp b/src/dawn/asset/loader/TrueTypeLoader.cpp index 2d6df8d5..60d03f89 100644 --- a/src/dawn/asset/loader/TrueTypeLoader.cpp +++ b/src/dawn/asset/loader/TrueTypeLoader.cpp @@ -8,6 +8,8 @@ using namespace Dawn; +const std::string TrueTypeLoader::ASSET_TYPE = "ttf"; + TrueTypeLoader::TrueTypeLoader( const std::shared_ptr assetManager, const std::string name @@ -65,6 +67,10 @@ void TrueTypeLoader::updateAsync() { state = TrueTypeLoaderState::ASYNC_DONE; } +std::string TrueTypeLoader::getAssetType() const { + return TrueTypeLoader::ASSET_TYPE; +} + std::shared_ptr TrueTypeLoader::getTexture( const uint32_t fontSize ) { diff --git a/src/dawn/asset/loader/TrueTypeLoader.hpp b/src/dawn/asset/loader/TrueTypeLoader.hpp index 14b92b06..2924ea90 100644 --- a/src/dawn/asset/loader/TrueTypeLoader.hpp +++ b/src/dawn/asset/loader/TrueTypeLoader.hpp @@ -27,6 +27,8 @@ namespace Dawn { uint8_t *buffer = nullptr; public: + const static std::string ASSET_TYPE; + TrueTypeLoader( const std::shared_ptr assetManager, const std::string name @@ -34,6 +36,7 @@ namespace Dawn { void updateSync() override; void updateAsync() override; + std::string getAssetType() const override; /** * Returns the texture for the given font size. diff --git a/src/dawn/game/IGame.cpp b/src/dawn/game/IGame.cpp index 8b4bc86e..4e4e2b6d 100644 --- a/src/dawn/game/IGame.cpp +++ b/src/dawn/game/IGame.cpp @@ -38,15 +38,8 @@ void IGame::init() { this->initManagers(); - - auto sceneLoader = this->assetManager->get("test_scene.json"); - while(!sceneLoader->loaded) { - this->assetManager->update(); - } - nextFrameScene = sceneLoader->getScene(); - - // auto initialScene = this->getInitialScene(); - // nextFrameScene = std::make_shared(selfAsGame, initialScene); + auto initialScene = this->getInitialScene(); + nextFrameScene = std::make_shared(selfAsGame, initialScene); } void IGame::deinit() {