diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index 83150512..a2ab456f 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -16,11 +16,7 @@ void AssetManager::update() { } void AssetManager::queueLoad(const std::vector> assets) { - std::merge( - this->assetsToLoad.begin(), this->assetsToLoad.end(), - assets.begin(), assets.end(), - this->assetsToLoad.begin() - ); + assetsToLoad.insert(this->assetsToLoad.end(), assets.begin(), assets.end()); } void AssetManager::queueLoad(const std::shared_ptr &asset) { @@ -33,11 +29,7 @@ void AssetManager::queueUnload( std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl; - std::merge( - this->assetsToUnload.begin(), this->assetsToUnload.end(), - assets.begin(), assets.end(), - this->assetsToUnload.begin() - ); + assetsToUnload.insert(assetsToUnload.end(), assets.begin(), assets.end()); } void AssetManager::queueUnload(const std::shared_ptr &asset) { @@ -51,17 +43,17 @@ void AssetManager::queueSwap( const std::vector> &newAssets, const std::vector> &oldAssets ) { - std::vector unload; - std::vector load; + std::vector> unload; + std::vector> load; // Determine assets to unload. - std::for_each(oldAssets.begin(), oldAssets.end(), [&](Asset *asset){ + std::for_each(oldAssets.begin(), oldAssets.end(), [&](const auto &asset){ auto it = std::find(newAssets.begin(), newAssets.end(), asset); if(it == newAssets.end()) unload.push_back(asset); }); // Determine assets to load - std::for_each(newAssets.begin(), newAssets.end(), [&](Asset *asset){ + std::for_each(newAssets.begin(), newAssets.end(), [&](const auto &asset){ auto it = std::find(oldAssets.begin(), oldAssets.end(), asset); if(it == oldAssets.end()) load.push_back(asset); }); diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index 0961cb51..14bc30f7 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -90,9 +90,9 @@ namespace Dawn { auto existing = this->assets.find(name); if(existing != this->assets.end()) { - return (T*)existing->second; + return dynamic_pointer_cast(existing->second); } - auto asset = new T(name); + auto asset = std::make_shared(name); this->assets[name] = asset; return asset; } diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 7f33a1c2..8e32af96 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -115,7 +115,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { auto renderables = scene->findComponents(); auto itRenderables = renderables.begin(); while(itRenderables != renderables.end()) { - vectorAppend(&shaderPassItems, (*itRenderables)->getRenderPasses(context)); + vectorAppend(shaderPassItems, (*itRenderables)->getRenderPasses(context)); ++itRenderables; } diff --git a/src/dawn/locale/LocaleManager.hpp b/src/dawn/locale/LocaleManager.hpp index 75a97f1c..a4b06014 100644 --- a/src/dawn/locale/LocaleManager.hpp +++ b/src/dawn/locale/LocaleManager.hpp @@ -20,8 +20,8 @@ namespace Dawn { DawnGame *game; LanguageAsset *asset; struct Locale locale; - LanguageAsset *currentlyLoadedAsset = nullptr; - LanguageAsset *loadingAsset = nullptr; + std::shared_ptr currentlyLoadedAsset; + std::shared_ptr loadingAsset; std::function eventTeardownLanguageLoaded; /** Listens for when the pending language loads. */ diff --git a/src/dawn/prefab/Prefab.hpp b/src/dawn/prefab/Prefab.hpp index 6c7d8c9a..d442fcf0 100644 --- a/src/dawn/prefab/Prefab.hpp +++ b/src/dawn/prefab/Prefab.hpp @@ -18,7 +18,9 @@ namespace Dawn { * @param man Asset Manasger for getting required assets from. * @return List of required assets this prefab. */ - static std::vector getRequiredAssets(AssetManager *man) { + static std::vector> + getRequiredAssets(AssetManager *man) + { return P::prefabAssets(man); } diff --git a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp index cfb41cb3..4092eeb9 100644 --- a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp +++ b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp @@ -19,8 +19,8 @@ namespace Dawn { public: SimpleTexturedMaterial *material; - static std::vector prefabAssets(AssetManager *man) { - return std::vector(); + static std::vector> prefabAssets(AssetManager *man) { + return std::vector>(); } SimpleSpinningCubePrefab(Scene *s, sceneitemid_t i) : diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index 8e49c150..5f73a37a 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -78,7 +78,7 @@ namespace Dawn { * * @return List of assets required by this scene. */ - virtual std::vector getRequiredAssets() = 0; + virtual std::vector> getRequiredAssets() = 0; /** * Method to begin the actual staging of the scene, typically called after diff --git a/src/dawn/scene/SceneItem.hpp b/src/dawn/scene/SceneItem.hpp index 0d07dc11..c3067661 100644 --- a/src/dawn/scene/SceneItem.hpp +++ b/src/dawn/scene/SceneItem.hpp @@ -149,7 +149,7 @@ namespace Dawn { while(transformsToCheck.size() > 0) { Transform *tras = *transformsToCheck.begin(); - vectorAppend(&transformsToCheck, tras->children); + vectorAppend(transformsToCheck, tras->children); auto component = tras->item->getComponent(); if(component != nullptr) itemsFound.push_back(component); transformsToCheck.erase(transformsToCheck.begin()); diff --git a/src/dawn/scene/components/ui/text/UILabel.hpp b/src/dawn/scene/components/ui/text/UILabel.hpp index ee09b619..aad652fc 100644 --- a/src/dawn/scene/components/ui/text/UILabel.hpp +++ b/src/dawn/scene/components/ui/text/UILabel.hpp @@ -17,7 +17,7 @@ namespace Dawn { flag_t style = 0; flag_t decorations = 0; uint32_t size = 16; - TrueTypeAsset *font = nullptr; + std::shared_ptr font; }; struct UILabelText { diff --git a/src/dawn/scene/components/ui/text/UISimpleLabel.hpp b/src/dawn/scene/components/ui/text/UISimpleLabel.hpp index e7ea18c6..5baed970 100644 --- a/src/dawn/scene/components/ui/text/UISimpleLabel.hpp +++ b/src/dawn/scene/components/ui/text/UISimpleLabel.hpp @@ -12,7 +12,7 @@ namespace Dawn { // @optional StateProperty text; // @optional - StateProperty font; + StateProperty> font; // @optional StateProperty size; // @optional diff --git a/src/dawn/scenes/TestScene.hpp b/src/dawn/scenes/TestScene.hpp index adc552d0..6353f574 100644 --- a/src/dawn/scenes/TestScene.hpp +++ b/src/dawn/scenes/TestScene.hpp @@ -20,10 +20,10 @@ namespace Dawn { cube = SimpleSpinningCubePrefab::prefabCreate(this); } - std::vector getRequiredAssets() override { + std::vector> getRequiredAssets() override { auto assMan = &this->game->assetManager; - std::vector assets; - vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); + std::vector> assets; + vectorAppend(assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); return assets; } diff --git a/src/dawn/util/array.hpp b/src/dawn/util/array.hpp index 55b71f9e..1fa94ee0 100644 --- a/src/dawn/util/array.hpp +++ b/src/dawn/util/array.hpp @@ -15,31 +15,7 @@ namespace Dawn { * @param append Pointer to list that will be appended. */ template - void vectorAppend(std::vector *list, std::vector *append) { - assertNotNull(list, "vectorAppend: list cannot be null"); - assertNotNull(append, "vectorAppend: append cannot be null"); - - auto it = append->begin(); - while(it != append->end()) { - list->push_back(*it); - ++it; - } - } - - /** - * Append a list on to another list. - * - * @param list Pointer to list that is being appended to. - * @param append List that will be appended. - */ - template - void vectorAppend(std::vector *list, std::vector append) { - assertNotNull(list, "vectorAppend: list cannot be null"); - - auto it = append.begin(); - while(it != append.end()) { - list->push_back(*it); - ++it; - } + void vectorAppend(std::vector &list, const std::vector &append) { + list.insert(list.end(), append.begin(), append.end()); } } diff --git a/src/dawnhelloworld/scenes/HelloWorldScene.hpp b/src/dawnhelloworld/scenes/HelloWorldScene.hpp index 39f32189..1f2f68f1 100644 --- a/src/dawnhelloworld/scenes/HelloWorldScene.hpp +++ b/src/dawnhelloworld/scenes/HelloWorldScene.hpp @@ -24,10 +24,10 @@ namespace Dawn { canvas = UICanvas::create(this); } - std::vector getRequiredAssets() override { + std::vector> getRequiredAssets() override { auto assMan = &this->game->assetManager; - std::vector assets; - vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); + std::vector> assets; + vectorAppend(assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); return assets; } diff --git a/src/dawnliminal/scenes/HelloWorldScene.hpp b/src/dawnliminal/scenes/HelloWorldScene.hpp index 12797a3e..c288fe10 100644 --- a/src/dawnliminal/scenes/HelloWorldScene.hpp +++ b/src/dawnliminal/scenes/HelloWorldScene.hpp @@ -26,9 +26,9 @@ namespace Dawn { canvas->camera = camera; } - std::vector getRequiredAssets() override { + std::vector> getRequiredAssets() override { auto assMan = &this->game->assetManager; - std::vector assets; + std::vector> assets; vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan)); return assets; } diff --git a/src/dawnliminal/vnscenes/ScenePrologue8.cpp b/src/dawnliminal/vnscenes/ScenePrologue8.cpp index c25df7ce..fa992638 100644 --- a/src/dawnliminal/vnscenes/ScenePrologue8.cpp +++ b/src/dawnliminal/vnscenes/ScenePrologue8.cpp @@ -46,9 +46,9 @@ void ScenePrologue8CustomEventForAfterCharacterFollowup::onStart() { ScenePrologue8::ScenePrologue8(DawnGame *game) : SceneMonologue(game) { } -std::vector ScenePrologue8::getRequiredAssets() { +std::vector> ScenePrologue8::getRequiredAssets() { auto man = &this->game->assetManager; - std::vector assets = SceneMonologue::getRequiredAssets(); + auto assets = SceneMonologue::getRequiredAssets(); return assets; } diff --git a/src/dawnliminal/vnscenes/ScenePrologue8.hpp b/src/dawnliminal/vnscenes/ScenePrologue8.hpp index b1d3cb9a..6c1cfc43 100644 --- a/src/dawnliminal/vnscenes/ScenePrologue8.hpp +++ b/src/dawnliminal/vnscenes/ScenePrologue8.hpp @@ -36,7 +36,7 @@ namespace Dawn { ScenePrologue8(DawnGame *game); - std::vector getRequiredAssets() override; + std::vector> getRequiredAssets() override; void stage() override; }; diff --git a/src/dawnrose/scenes/HelloWorldScene.hpp b/src/dawnrose/scenes/HelloWorldScene.hpp index fc4ae20f..068d05ac 100644 --- a/src/dawnrose/scenes/HelloWorldScene.hpp +++ b/src/dawnrose/scenes/HelloWorldScene.hpp @@ -47,11 +47,11 @@ namespace Dawn { gameCamera->player = player->player; } - std::vector getRequiredAssets() override { + std::vector> getRequiredAssets() override { auto assMan = &this->game->assetManager; - std::vector assets; - vectorAppend(&assets, Urchin::getRequiredAssets(assMan)); - vectorAppend(&assets, Player::getRequiredAssets(assMan)); + std::vector> assets; + vectorAppend(assets, Urchin::getRequiredAssets(assMan)); + vectorAppend(assets, Player::getRequiredAssets(assMan)); return assets; }