From 5547c7c236a53a8014bda34ab11f08f10ba40cc8 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 2 Nov 2023 17:56:18 -0500 Subject: [PATCH] Push --- src/dawn/asset/AssetManager.cpp | 18 +++++++++--------- src/dawn/asset/AssetManager.hpp | 26 +++++++++++++------------- src/dawn/time/ITimeManager.cpp | 30 +++++++----------------------- src/dawn/time/ITimeManager.hpp | 8 +------- 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index fbdab5da..83150512 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -15,7 +15,7 @@ void AssetManager::update() { this->syncTick(); } -void AssetManager::queueLoad(const std::vector assets) { +void AssetManager::queueLoad(const std::vector> assets) { std::merge( this->assetsToLoad.begin(), this->assetsToLoad.end(), assets.begin(), assets.end(), @@ -23,11 +23,13 @@ void AssetManager::queueLoad(const std::vector assets) { ); } -void AssetManager::queueLoad(Asset *asset) { +void AssetManager::queueLoad(const std::shared_ptr &asset) { this->assetsToLoad.push_back(asset); } -void AssetManager::queueUnload(const std::vector assets) { +void AssetManager::queueUnload( + const std::vector> &assets +) { std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl; @@ -38,7 +40,7 @@ void AssetManager::queueUnload(const std::vector assets) { ); } -void AssetManager::queueUnload(Asset *asset) { +void AssetManager::queueUnload(const std::shared_ptr &asset) { std::cout << "Asset was queued to unload, but is not yet implemented" << std::endl; @@ -46,8 +48,8 @@ void AssetManager::queueUnload(Asset *asset) { } void AssetManager::queueSwap( - const std::vector newAssets, - const std::vector oldAssets + const std::vector> &newAssets, + const std::vector> &oldAssets ) { std::vector unload; std::vector load; @@ -94,7 +96,5 @@ void AssetManager::syncLoad() { } AssetManager::~AssetManager() { - std::for_each(this->assets.begin(), this->assets.end(), [&](auto &item){ - delete item.second; - }); + this->assets.clear(); } \ No newline at end of file diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index dacd2520..0961cb51 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -10,9 +10,9 @@ namespace Dawn { class AssetManager { private: /** List of pointers to assets, mapped by their asset key. */ - std::map assets; - std::vector assetsToLoad; - std::vector assetsToUnload; + std::map> assets; + std::vector> assetsToLoad; + std::vector> assetsToUnload; public: /** @@ -30,28 +30,28 @@ namespace Dawn { * * @param assets Assets to load. */ - void queueLoad(const std::vector assets); + void queueLoad(const std::vector> assets); /** * Queue a loading of a single asset. Does not actually begin loading. * - * @param assets Assets to load. + * @param asset Asset to load. */ - void queueLoad(Asset *assets); + void queueLoad(const std::shared_ptr &asset); /** * Takes a list of lists to queue to unload. Does not immediately unload. * * @param assets Assets to unload. */ - void queueUnload(const std::vector assets); + void queueUnload(const std::vector> &assets); /** * Takes a single asset to queue to unload. Does not immediately unload. * * @param assets Assets to unload. */ - void queueUnload(Asset* assets); + void queueUnload(const std::shared_ptr &assets); /** * Queues load and unload based on the difference between two sets of @@ -61,8 +61,8 @@ namespace Dawn { * @param oldAssets Old list of assets to no longer maintain. */ void queueSwap( - const std::vector newAssets, - const std::vector oldAssets + const std::vector> &newAssets, + const std::vector> &oldAssets ); /** @@ -83,7 +83,7 @@ namespace Dawn { * @return The asset element to be loaded. */ template - T * get(std::string name) { + std::shared_ptr get(std::string name) { assertTrue( name.size() > 0, "AssetManager::get: name must be greater than 0" ); @@ -104,14 +104,14 @@ namespace Dawn { * @return The asset element to be loaded. */ template - T * getAndLoad(std::string name) { + std::shared_ptr getAndLoad(std::string name) { auto asset = this->get(name); this->queueLoad(asset); return asset; } template - void unload(T *asset) { + void unload(std::shared_ptr asset) { assertUnreachable("AssetManager::unload: NOT IMPLEMENTED"); } diff --git a/src/dawn/time/ITimeManager.cpp b/src/dawn/time/ITimeManager.cpp index 2eb45069..b72d6be9 100644 --- a/src/dawn/time/ITimeManager.cpp +++ b/src/dawn/time/ITimeManager.cpp @@ -11,7 +11,7 @@ ITimeManager::ITimeManager() { } -void ITimeManager::update(float_t delta) { +void ITimeManager::update(const float_t delta) { this->delta = delta; this->time += delta; @@ -19,28 +19,12 @@ void ITimeManager::update(float_t delta) { this->unpausedTime += delta; // Timeout effect provider - auto itEffect = this->timeoutProvider.listeners.begin(); - while(itEffect != this->timeoutProvider.listeners.end()) { - itEffect->data -= delta; - if(itEffect->data <= 0) { - itEffect->callback(); - itEffect = this->timeoutProvider.listeners.erase(itEffect); - continue; - } - ++itEffect; - } - - - // Interval provider - auto itInterval = this->intervalProvider.listeners.begin(); - while(itInterval != this->intervalProvider.listeners.end()) { - itInterval->data.time += delta; - if(itInterval->data.time >= itInterval->data.interval) { - itInterval->callback(); - itInterval->data.time = 0; - } - ++itInterval; - } + std::erase_if(this->timeoutProvider.listeners, [&](auto &listener) { + listener.data -= delta; + if(listener.data > 0) return false; + listener.callback(); + return true; + }); } } diff --git a/src/dawn/time/ITimeManager.hpp b/src/dawn/time/ITimeManager.hpp index 18ac4303..90e0c3a0 100644 --- a/src/dawn/time/ITimeManager.hpp +++ b/src/dawn/time/ITimeManager.hpp @@ -9,11 +9,6 @@ #include "state/StateEvent.hpp" namespace Dawn { - struct IntervalProviderData { - float_t interval; - float_t time; - }; - class ITimeManager { public: float_t time = 0.0f; @@ -22,7 +17,6 @@ namespace Dawn { bool_t isPaused = false; StateProviderSet timeoutProvider; - StateProviderSet intervalProvider; StateEvent<> eventTimePaused; StateEvent<> eventTimeResumed; @@ -36,7 +30,7 @@ namespace Dawn { * * @param delta Time in seconds to tick the instance by. */ - void update(float_t delta); + void update(const float_t delta); /** * Pauses the game.