From d0f93ff2f9712f7e04909712199d837acbd6db35 Mon Sep 17 00:00:00 2001 From: roby2014 Date: Sun, 15 Oct 2023 23:03:57 +0100 Subject: [PATCH] feat(renderer): add ActiveVoxelPalette resource to rendererPlugin --- engine/include/cubos/engine/assets/assets.hpp | 5 ++++- engine/include/cubos/engine/renderer/plugin.hpp | 4 ++++ engine/src/cubos/engine/assets/assets.cpp | 6 ------ engine/src/cubos/engine/renderer/plugin.cpp | 10 ++++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/engine/include/cubos/engine/assets/assets.hpp b/engine/include/cubos/engine/assets/assets.hpp index 8b1d7be5d7..5dc627659d 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 f123ff1477..f34fd7b8f5 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 869d417ac5..35581a989a 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 11b2a5e8e9..2b1a621bcb 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; } }