Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Oct 15, 2023
1 parent 5c025a2 commit ad2b8cc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions engine/include/cubos/engine/assets/assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
bool update(Asset<T>& 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);
Expand Down
9 changes: 9 additions & 0 deletions engine/include/cubos/engine/renderer/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<VoxelPalette> asset;
};

/// @brief Plugin entry function.
/// @param cubos @b CUBOS. main class
/// @ingroup renderer-plugin
Expand Down
6 changes: 6 additions & 0 deletions engine/src/cubos/engine/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ 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
12 changes: 12 additions & 0 deletions engine/src/cubos/engine/renderer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ static void frameEnvironment(Write<RendererFrame> frame, Read<RendererEnvironmen
frame->skyGradient(env->skyGradient[0], env->skyGradient[1]);
}

static void checkPaletteUpdateSystem(Write<Assets> assets, Write<Renderer> renderer,
Read<ActiveVoxelPalette> 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.
Expand Down Expand Up @@ -187,6 +197,7 @@ void cubos::engine::rendererPlugin(Cubos& cubos)
cubos.addResource<Renderer>();
cubos.addResource<ActiveCameras>();
cubos.addResource<RendererEnvironment>();
cubos.addResource<ActiveVoxelPalette>();

cubos.addComponent<RenderableGrid>();
cubos.addComponent<Camera>();
Expand All @@ -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");
}

0 comments on commit ad2b8cc

Please sign in to comment.