1 #include <Core/Asset/FileData.hpp>
2 #include <Core/Tasks/Task.hpp>
3 #include <Core/Tasks/TaskQueue.hpp>
4 #include <Engine/FrameInfo.hpp>
5 #include <Engine/RadiumEngine.hpp>
6 #include <Engine/Scene/ComponentMessenger.hpp>
7 #include <Engine/Scene/DirLight.hpp>
8 #include <Engine/Scene/Entity.hpp>
9 #include <Engine/Scene/LightManager.hpp>
10 #include <Engine/Scene/PointLight.hpp>
11 #include <Engine/Scene/SpotLight.hpp>
12 #include <Engine/Scene/SystemDisplay.hpp>
19 using namespace Core::Utils;
20 using namespace Core::Asset;
29 return m_data->size();
42 std::vector<LightData*> lightData = filedata->getLightData();
49 for (
size_t i = 0; i < m_data->size(); ) {
50 auto l = ( *m_data )[i];
51 if ( l->getEntity() == SystemEntity::getInstance() ) { m_data->remove( l ); }
55 for (
const auto& data : lightData ) {
56 std::string componentName =
57 "LIGHT_" + data->getName() +
" (" + std::to_string(
id++ ) +
")";
60 switch ( data->getType() ) {
61 case LightData::DIRECTIONAL_LIGHT: {
64 thelight->setColor( data->m_color );
65 thelight->setDirection( data->m_dirlight.direction );
69 case LightData::POINT_LIGHT: {
70 auto thelight =
new PointLight( entity, componentName );
71 thelight->setColor( data->m_color );
72 thelight->setPosition( data->m_pointlight.position );
73 thelight->setAttenuation( data->m_pointlight.attenuation.constant,
74 data->m_pointlight.attenuation.linear,
75 data->m_pointlight.attenuation.quadratic );
79 case LightData::SPOT_LIGHT: {
80 auto thelight =
new SpotLight( entity, componentName );
81 thelight->setColor( data->m_color );
82 thelight->setPosition( data->m_spotlight.position );
83 thelight->setDirection( data->m_spotlight.direction );
84 thelight->setAttenuation( data->m_spotlight.attenuation.constant,
85 data->m_spotlight.attenuation.linear,
86 data->m_spotlight.attenuation.quadratic );
87 thelight->setInnerAngleInRadians( data->m_spotlight.innerAngle );
88 thelight->setOuterAngleInRadians( data->m_spotlight.outerAngle );
92 case LightData::AREA_LIGHT: {
95 auto thelight =
new PointLight( entity, componentName );
96 thelight->setColor( data->m_color );
97 thelight->setPosition( data->m_arealight.position );
98 thelight->setAttenuation( data->m_arealight.attenuation.constant,
99 data->m_arealight.attenuation.linear,
100 data->m_arealight.attenuation.quadratic );
109 if ( !comp )
continue;
111 registerComponent( entity, comp );
113 LOG( logINFO ) <<
"LightManager : loaded " << count() <<
" lights.";
118 m_data->add(
reinterpret_cast<Scene::Light*
>( component ) );
123 m_data->remove(
reinterpret_cast<Scene::Light*
>( component ) );
127 for (
const auto& comp : this->m_components ) {
128 if ( comp.first == entity ) {
129 m_data->remove(
reinterpret_cast<Scene::Light*
>( comp.second ) );
A component is an element that can be updated by a system. It is also linked to some other components...
An entity is an scene element. It ties together components with a transform.
void generateTasks(Core::TaskQueue *taskQueue, const Engine::FrameInfo &frameInfo) override
Do nothing as this system only manage light related asset loading.
virtual size_t count() const
Number of lights. This is still a work in progress. The idea is to make it possible for a LightManage...
void handleAssetLoading(Entity *entity, const Core::Asset::FileData *data) override
Transform loaded file data to usable entities and component in the engine.
~LightManager() override
Virtual destructor.
void unregisterAllComponents(const Entity *entity) final
void registerComponent(const Entity *entity, Component *component) final
void unregisterComponent(const Entity *entity, Component *component) final
virtual void unregisterAllComponents(const Entity *entity)
virtual void registerComponent(const Entity *entity, Component *component)
virtual void unregisterComponent(const Entity *entity, Component *component)
Structure passed to each system before they fill the task queue.