diff --git a/engine/include/cubos/engine/assets/assets.hpp b/engine/include/cubos/engine/assets/assets.hpp index 8b1d7be5d..5dc627659 100644 --- a/engine/include/cubos/engine/assets/assets.hpp +++ b/engine/include/cubos/engine/assets/assets.hpp @@ -183,7 +183,10 @@ namespace cubos::engine /// @param handle Handle to update. /// @return Whether the version was updated. template - bool update(Asset& handle) const; + bool update(Asset& handle) const + { + return update(static_cast(handle)); + } /// @brief Unloads the given asset. Can be used to force assets to be reloaded. /// @param handle Handle to unload. diff --git a/engine/include/cubos/engine/renderer/plugin.hpp b/engine/include/cubos/engine/renderer/plugin.hpp index f123ff147..f34fd7b8f 100644 --- a/engine/include/cubos/engine/renderer/plugin.hpp +++ b/engine/include/cubos/engine/renderer/plugin.hpp @@ -93,6 +93,10 @@ namespace cubos::engine { /// @brief Asset handle to the currently active palette. Asset asset; + + /// @brief Previous asset handle save in order to check if asset changed later. + /// TODO: ECS should have a .changed function to make this process easier (#273). + Asset prev; }; /// @brief Plugin entry function. diff --git a/engine/src/cubos/engine/assets/assets.cpp b/engine/src/cubos/engine/assets/assets.cpp index 869d417ac..35581a989 100644 --- a/engine/src/cubos/engine/assets/assets.cpp +++ b/engine/src/cubos/engine/assets/assets.cpp @@ -285,12 +285,6 @@ bool Assets::update(AnyAsset& handle) const return false; } -template -bool Assets::update(Asset& handle) const -{ - return update(static_cast(handle)); -} - void Assets::invalidate(const AnyAsset& handle) { this->invalidate(handle, true); diff --git a/engine/src/cubos/engine/renderer/plugin.cpp b/engine/src/cubos/engine/renderer/plugin.cpp index 11b2a5e8e..2b1a621bc 100644 --- a/engine/src/cubos/engine/renderer/plugin.cpp +++ b/engine/src/cubos/engine/renderer/plugin.cpp @@ -102,12 +102,18 @@ static void frameEnvironment(Write frame, Read assets, Write renderer, - Read activePalette) + Write activePalette) { - if (assets->update(activePalette->asset)) + if (activePalette->asset.isNull()) + { + return; + } + + if (assets->update(activePalette->asset) || activePalette->prev.toAny() != activePalette->asset.toAny()) { auto palette = assets->read(activePalette->asset).get(); (*renderer)->setPalette(palette); + activePalette->prev = activePalette->asset; } }