Skip to content

Commit

Permalink
- Re-link color layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Dacquay committed Mar 25, 2024
1 parent 004e992 commit c2ac476
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 272 deletions.
17 changes: 15 additions & 2 deletions lib/app/include/app/application/ecs/registry_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,22 @@ namespace VTX::App::Application::ECS
}

template<Core::ECS::ECS_Component Type, Core::ECS::ECS_Component... Other>
Core::ECS::View<Type, Other...> getComponents() const
Type & findComponent()
{
return _registry.getComponents<Type, Other...>();
Core::ECS::View<Type, Other...> view = _registry.findComponents<Type, Other...>();
return getComponent<Type>( *( view.begin() ) );
}
template<Core::ECS::ECS_Component Type, Core::ECS::ECS_Component... Other>
const Type & findComponent() const
{
Core::ECS::View<Type, Other...> view = _registry.findComponents<Type, Other...>();
return getComponent<Type>( *( view.begin() ) );
}

template<Core::ECS::ECS_Component Type, Core::ECS::ECS_Component... Other>
Core::ECS::View<Type, Other...> findComponents() const
{
return _registry.findComponents<Type, Other...>();
}

template<Core::ECS::ECS_Component C>
Expand Down
3 changes: 2 additions & 1 deletion lib/app/include/app/application/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace VTX::App::Application
template<SceneItem T>
Core::ECS::View<Component::Scene::SceneItemComponent, T> getAllSceneItemsOfType() const
{
return MAIN_REGISTRY().getComponents<Component::Scene::SceneItemComponent, T>();
return MAIN_REGISTRY().findComponents<Component::Scene::SceneItemComponent, T>();
}

void referenceItem( Component::Scene::SceneItemComponent & p_item );
Expand Down Expand Up @@ -131,6 +131,7 @@ namespace VTX::App::Application

void _computeAABB();
void _createDefaultPath();
void _createDefaultColorLayout();

private:
Component::Render::Camera * _camera = nullptr;
Expand Down
29 changes: 29 additions & 0 deletions lib/app/include/app/component/render/proxy_color_layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __VTX_APP_COMPONENT_RENDER_PROXY_COLOR_LAYOUT__
#define __VTX_APP_COMPONENT_RENDER_PROXY_COLOR_LAYOUT__

#include "app/application/renderer/proxy_wrapper.hpp"
#include <core/chemdb/color.hpp>
#include <renderer/facade.hpp>
#include <util/types.hpp>
#include <vector>

namespace VTX::App::Component::Render
{
class ProxyColorLayout
{
public:
ProxyColorLayout();
~ProxyColorLayout();

void setup( Renderer::Facade & p_renderer );
Application::Renderer::ProxyWrapper<VTX::Renderer::Proxy::ColorLayout> & getProxy() { return _proxyWrapper; };

private:
void _addInRenderer( Renderer::Facade & p_renderer );
void _setupCallbacks();

Application::Renderer::ProxyWrapper<VTX::Renderer::Proxy::ColorLayout> _proxyWrapper;
};

} // namespace VTX::App::Component::Render
#endif
29 changes: 29 additions & 0 deletions lib/app/include/app/component/representation/color_layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __VTX_APP_COMPONENT_REPRESENTATION_COLOR_LAYOUT__
#define __VTX_APP_COMPONENT_REPRESENTATION_COLOR_LAYOUT__

#include "app/core/ecs/base_component.hpp"
#include <core/chemdb/color.hpp>
#include <util/callback.hpp>

namespace VTX::App::Component::Representation
{

class ColorLayout : public Core::ECS::BaseComponent
{
public:
ColorLayout() = default;

const VTX::Core::ChemDB::Color::ColorLayout & getLayout() const { return _layout; }

void setColor( const size_t p_index, const Util::Color::Rgba & p_color );
void setColors( const std::vector<Util::Color::Rgba> & p_colors );

Util::Callback<> onColorChange;

private:
VTX::Core::ChemDB::Color::ColorLayout _layout;
};

} // namespace VTX::App::Component::Representation

#endif
2 changes: 1 addition & 1 deletion lib/app/include/app/core/ecs/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace VTX::App::Core::ECS
}

template<ECS_Component Type, ECS_Component... Other>
View<Type, Other...> getComponents() const
View<Type, Other...> findComponents() const
{
return View<Type, Other...>( _enttRegistry );
}
Expand Down
18 changes: 15 additions & 3 deletions lib/app/src/app/application/scene.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "app/application/scene.hpp"
#include "app/application/ecs/entity_director.hpp"
#include "app/component/render/camera.hpp"
#include "app/component/render/proxy_color_layout.hpp"
#include "app/component/representation/color_layout.hpp"
#include "app/component/scene/aabb_component.hpp"
#include "app/component/scene/updatable.hpp"
#include "app/core/ecs/base_entity.hpp"
Expand All @@ -11,7 +13,7 @@ namespace VTX::App::Application
{
Core::ECS::View<Component::Scene::SceneItemComponent> Scene::getAllSceneItems() const
{
return MAIN_REGISTRY().getComponents<Component::Scene::SceneItemComponent>();
return MAIN_REGISTRY().findComponents<Component::Scene::SceneItemComponent>();
}

Scene::Scene()
Expand All @@ -20,6 +22,7 @@ namespace VTX::App::Application
_camera = &( MAIN_REGISTRY().getComponent<Component::Render::Camera>( cameraEntity ) );

_createDefaultPath();
_createDefaultColorLayout();
}

Scene::~Scene() {}
Expand Down Expand Up @@ -82,6 +85,7 @@ namespace VTX::App::Application
{
clear();
_createDefaultPath();
_createDefaultColorLayout();
}

size_t Scene::getItemIndex( const Core::ECS::BaseEntity & p_entity ) const
Expand Down Expand Up @@ -229,7 +233,7 @@ namespace VTX::App::Application
void Scene::_computeAABB()
{
const Core::ECS::View view
= MAIN_REGISTRY().getComponents<Component::Scene::SceneItemComponent, Component::Scene::AABB>();
= MAIN_REGISTRY().findComponents<Component::Scene::SceneItemComponent, Component::Scene::AABB>();

_aabb.invalidate();

Expand All @@ -246,7 +250,7 @@ namespace VTX::App::Application
// (let that here instead of doing the exact same things in all states for the moment)

Core::ECS::View updatables
= MAIN_REGISTRY().getComponents<Component::Scene::SceneItemComponent, Component::Scene::Updatable>();
= MAIN_REGISTRY().findComponents<Component::Scene::SceneItemComponent, Component::Scene::Updatable>();

for ( const Core::ECS::BaseEntity entity : updatables )
{
Expand Down Expand Up @@ -300,4 +304,12 @@ namespace VTX::App::Application
// addPath( path );
}

void Scene::_createDefaultColorLayout()
{
Core::ECS::BaseEntity colorLayoutEntity = MAIN_REGISTRY().createEntity();
MAIN_REGISTRY().addComponent<Component::Representation::ColorLayout>( colorLayoutEntity );
Component::Render::ProxyColorLayout & proxy
= MAIN_REGISTRY().addComponent<Component::Render::ProxyColorLayout>( colorLayoutEntity );
}

} // namespace VTX::App::Application
30 changes: 30 additions & 0 deletions lib/app/src/app/component/render/proxy_color_layout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "app/component/render/proxy_color_layout.hpp"
#include "app/application/system/ecs_system.hpp"
#include "app/component/representation/color_layout.hpp"

namespace VTX::App::Component::Render
{
ProxyColorLayout::ProxyColorLayout() {}
ProxyColorLayout::~ProxyColorLayout() {}
void ProxyColorLayout::setup( Renderer::Facade & p_renderer )
{
_addInRenderer( p_renderer );
_setupCallbacks();
}

void ProxyColorLayout::_addInRenderer( Renderer::Facade & p_renderer )
{
Component::Representation::ColorLayout & colorLayoutComp
= MAIN_REGISTRY().getComponent<Component::Representation::ColorLayout>( *this );

colorLayoutComp.setColors( VTX::Core::ChemDB::Color::COLOR_LAYOUT_JMOL.layout );

std::unique_ptr<VTX::Renderer::Proxy::ColorLayout> proxyPtr
= std::make_unique<VTX::Renderer::Proxy::ColorLayout>( VTX::Renderer::Proxy::ColorLayout {
&colorLayoutComp.getLayout().layout } );

_proxyWrapper.setProxy( proxyPtr );
}
void ProxyColorLayout::_setupCallbacks() {}

} // namespace VTX::App::Component::Render
20 changes: 20 additions & 0 deletions lib/app/src/app/component/representation/color_layout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "app/component/representation/color_layout.hpp"

namespace VTX::App::Component::Representation
{
void ColorLayout::setColor( const size_t p_index, const Util::Color::Rgba & p_color )
{
assert( p_index < VTX::Core::ChemDB::Color::ColorLayout::LAYOUT_SIZE );

_layout.layout[ p_index ] = p_color;
onColorChange();
}
void ColorLayout::setColors( const std::vector<Util::Color::Rgba> & p_colors )
{
assert( p_colors.size() == VTX::Core::ChemDB::Color::ColorLayout::LAYOUT_SIZE );

_layout.layout = p_colors;
onColorChange();
}

} // namespace VTX::App::Component::Representation
5 changes: 3 additions & 2 deletions lib/app/test/src/util/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ namespace VTX::App::Test::Util
renderer.setProxyRepresentations( representations );

// Default color layout.
static auto JMOL = VTX::Core::ChemDB::Color::COLOR_LAYOUT_JMOL;
renderer.setProxyColorLayout( JMOL );
static auto JMOL = VTX::Core::ChemDB::Color::COLOR_LAYOUT_JMOL;
static Renderer::Proxy::ColorLayout jmolColorLayout = { &JMOL.layout };
renderer.setProxyColorLayout( jmolColorLayout );

isInit = true;
}
Expand Down
Loading

0 comments on commit c2ac476

Please sign in to comment.