diff --git a/engine/include/cubos/engine/assets/assets.hpp b/engine/include/cubos/engine/assets/assets.hpp index ec4b899f55..8b1d7be5d7 100644 --- a/engine/include/cubos/engine/assets/assets.hpp +++ b/engine/include/cubos/engine/assets/assets.hpp @@ -176,6 +176,15 @@ namespace cubos::engine /// @return Whether the version was updated. bool update(AnyAsset& handle) const; + /// @brief Updates the given handle to the latest version of the asset. + /// + /// Can be used to implement hot-reloading. + /// + /// @param handle Handle to update. + /// @return Whether the version was updated. + template + bool update(Asset& handle) const; + /// @brief Unloads the given asset. Can be used to force assets to be reloaded. /// @param handle Handle to unload. void invalidate(const AnyAsset& handle); diff --git a/engine/include/cubos/engine/renderer/plugin.hpp b/engine/include/cubos/engine/renderer/plugin.hpp index a786b07aab..f123ff1477 100644 --- a/engine/include/cubos/engine/renderer/plugin.hpp +++ b/engine/include/cubos/engine/renderer/plugin.hpp @@ -43,6 +43,7 @@ namespace cubos::engine /// - @ref RendererFrame - holds the current frame information. /// - @ref RendererEnvironment - holds the environment information (ambient light, sky gradient). /// - @ref ActiveCameras - holds the entities which represents the active cameras. + /// - @ref ActiveVoxelPalette - holds an asset handle to the currently active palette. /// /// ## Components /// - @ref RenderableGrid - a grid to be rendered. @@ -86,6 +87,14 @@ namespace cubos::engine core::ecs::Entity entities[4]; }; + /// @brief Resource which holds an asset handle to the currently active palette. + /// @ingroup renderer-plugin + struct ActiveVoxelPalette + { + /// @brief Asset handle to the currently active palette. + Asset asset; + }; + /// @brief Plugin entry function. /// @param cubos @b CUBOS. main class /// @ingroup renderer-plugin diff --git a/engine/src/cubos/engine/assets/assets.cpp b/engine/src/cubos/engine/assets/assets.cpp index 35581a989a..869d417ac5 100644 --- a/engine/src/cubos/engine/assets/assets.cpp +++ b/engine/src/cubos/engine/assets/assets.cpp @@ -285,6 +285,12 @@ 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 ba8f573bf1..11b2a5e8e9 100644 --- a/engine/src/cubos/engine/renderer/plugin.cpp +++ b/engine/src/cubos/engine/renderer/plugin.cpp @@ -101,6 +101,16 @@ static void frameEnvironment(Write frame, ReadskyGradient(env->skyGradient[0], env->skyGradient[1]); } +static void checkPaletteUpdateSystem(Write assets, Write renderer, + Read activePalette) +{ + if (assets->update(activePalette->asset)) + { + auto palette = assets->read(activePalette->asset).get(); + (*renderer)->setPalette(palette); + } +} + /// @brief Splits the viewport recursively for the given cameras. /// @param position Viewport position. /// @param size Viewport size. @@ -187,6 +197,7 @@ void cubos::engine::rendererPlugin(Cubos& cubos) cubos.addResource(); cubos.addResource(); cubos.addResource(); + cubos.addResource(); cubos.addComponent(); cubos.addComponent(); @@ -204,6 +215,7 @@ void cubos::engine::rendererPlugin(Cubos& cubos) cubos.system(frameDirectionalLights).tagged("cubos.renderer.frame"); cubos.system(framePointLights).tagged("cubos.renderer.frame"); cubos.system(frameEnvironment).tagged("cubos.renderer.frame"); + cubos.system(checkPaletteUpdateSystem).tagged("cubos.renderer.frame"); cubos.system(draw).tagged("cubos.renderer.draw"); cubos.system(resize).after("cubos.window.poll").before("cubos.renderer.draw"); }