Skip to content

Commit

Permalink
feat(renderer): add ActiveVoxelPalette resource to rendererPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Oct 15, 2023
1 parent b04cfd5 commit d0f93ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion engine/include/cubos/engine/assets/assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ namespace cubos::engine
/// @param handle Handle to update.
/// @return Whether the version was updated.
template <typename T>
bool update(Asset<T>& handle) const;
bool update(Asset<T>& handle) const
{
return update(static_cast<AnyAsset&>(handle));
}

/// @brief Unloads the given asset. Can be used to force assets to be reloaded.
/// @param handle Handle to unload.
Expand Down
4 changes: 4 additions & 0 deletions engine/include/cubos/engine/renderer/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ namespace cubos::engine
{
/// @brief Asset handle to the currently active palette.
Asset<VoxelPalette> 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<VoxelPalette> prev;
};

/// @brief Plugin entry function.
Expand Down
6 changes: 0 additions & 6 deletions engine/src/cubos/engine/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,6 @@ bool Assets::update(AnyAsset& handle) const
return false;
}

template <typename T>
bool Assets::update(Asset<T>& handle) const
{
return update(static_cast<AnyAsset&>(handle));
}

void Assets::invalidate(const AnyAsset& handle)
{
this->invalidate(handle, true);
Expand Down
10 changes: 8 additions & 2 deletions engine/src/cubos/engine/renderer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ static void frameEnvironment(Write<RendererFrame> frame, Read<RendererEnvironmen
}

static void checkPaletteUpdateSystem(Write<Assets> assets, Write<Renderer> renderer,
Read<ActiveVoxelPalette> activePalette)
Write<ActiveVoxelPalette> 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;
}
}

Expand Down

0 comments on commit d0f93ff

Please sign in to comment.