FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_lightSystem.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_LIGHTSYSTEM_HPP_INCLUDED
18#define _FGE_C_LIGHTSYSTEM_HPP_INCLUDED
19
20#include "FastEngine/C_concavePolygon.hpp"
21#include "FastEngine/C_scene.hpp"
22#include "FastEngine/C_tunnel.hpp"
23
24#define FGE_LIGHT_PROPERTY_DEFAULT_LS "_fge_def_ls"
25
26namespace fge
27{
28
29class LightComponent;
30
37
46{
47 return scene._properties.getProperty(FGE_LIGHT_PROPERTY_DEFAULT_LS).get<fge::LightSystem*>().value_or(nullptr);
48}
49
56{
57public:
58 inline LightComponent() :
59 _g_lightSystemGate(this)
60 {}
61 inline LightComponent(fge::LightComponent const& r) :
62 _g_lightSystemGate(r._g_lightSystemGate)
63 {
64 this->_g_lightSystemGate.setData(this);
65 }
66 inline LightComponent(fge::LightComponent&& r) noexcept :
67 _g_lightSystemGate(std::move(r._g_lightSystemGate))
68 {
69 this->_g_lightSystemGate.setData(this);
70 }
71 virtual ~LightComponent() = default;
72
73 inline LightComponent& operator=(fge::LightComponent const& r)
74 {
75 this->_g_lightSystemGate = r._g_lightSystemGate;
76 this->_g_lightSystemGate.setData(this);
77 return *this;
78 }
79 inline LightComponent& operator=(fge::LightComponent&& r) noexcept
80 {
81 this->_g_lightSystemGate = std::move(r._g_lightSystemGate);
82 this->_g_lightSystemGate.setData(this);
83 return *this;
84 }
85
91 inline void setLightSystem(fge::LightSystem& lightSystem)
92 {
93 this->_g_lightSystemGate.openTo(lightSystem, !this->isObstacle());
94 }
95
96 [[nodiscard]] inline virtual bool isObstacle() const { return false; }
97 inline virtual void updateObstacleShape() {}
98
105 {
106 auto* ls = fge::GetDefaultLightSystem(scene);
107 if (ls != nullptr)
108 {
109 this->setLightSystem(*ls);
110 }
111 }
112
113protected:
114 fge::LightSystemGate _g_lightSystemGate;
115};
116
125{
126public:
127 inline explicit LightObstacle(fge::Transformable const* transformableParent) :
128 g_transformableParent(transformableParent)
129 {}
130 inline LightObstacle(fge::LightObstacle const& r, fge::Transformable const* transformableParent) :
132 g_transformableParent(transformableParent)
133 {}
134 inline LightObstacle(fge::LightObstacle&& r, fge::Transformable const* transformableParent) noexcept :
135 fge::LightComponent(std::move(static_cast<fge::LightComponent&&>(r))),
136 g_transformableParent(transformableParent)
137 {}
138 inline LightObstacle(fge::LightObstacle const& r) = delete;
139 inline LightObstacle(fge::LightObstacle&& r) noexcept = delete;
140 inline ~LightObstacle() override = default;
141
142 inline fge::LightObstacle& operator=(fge::LightObstacle const& r)
143 {
144 LightComponent::operator=(static_cast<fge::LightComponent const&>(r));
145 return *this;
146 }
147 inline fge::LightObstacle& operator=(fge::LightObstacle&& r) noexcept
148 {
149 LightComponent::operator=(std::move(static_cast<fge::LightComponent&&>(r)));
150 return *this;
151 }
152
153 [[nodiscard]] inline bool isObstacle() const final { return true; }
154
155 [[nodiscard]] inline fge::Transformable const& getTransformableParent() const
156 {
157 return *this->g_transformableParent;
158 }
159
160 [[nodiscard]] inline fge::ConcavePolygon const& getShape() const { return this->_g_shape; }
161
162protected:
163 fge::ConcavePolygon _g_shape;
164
165private:
166 fge::Transformable const* g_transformableParent;
167};
168
169} // namespace fge
170
171#endif // _FGE_C_LIGHTSYSTEM_HPP_INCLUDED
Definition C_concavePolygon.hpp:40
A base class that define a light component.
Definition C_lightSystem.hpp:56
void setDefaultLightSystem(fge::Scene &scene)
Retrieve the default light system from a scene.
Definition C_lightSystem.hpp:104
void setLightSystem(fge::LightSystem &lightSystem)
Set the light system to be used by this light.
Definition C_lightSystem.hpp:91
A base class to define an obstacle for the light system.
Definition C_lightSystem.hpp:125
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
fge::PropertyList _properties
Definition C_scene.hpp:1437
Definition C_transformable.hpp:34
fge::LightSystem * GetDefaultLightSystem(fge::Scene &scene)
Get the default light system from a scene property.
Definition C_lightSystem.hpp:45