1 #ifndef CORE_MAPS_LIGHTINGSYSTEM_HPP
2 #define CORE_MAPS_LIGHTINGSYSTEM_HPP
4 #include <BLIB/Containers/Grid.hpp>
5 #include <BLIB/Containers/ObjectPool.hpp>
6 #include <BLIB/Events.hpp>
7 #include <BLIB/Render/Lighting/Scene2DLighting.hpp>
8 #include <BLIB/Serialization/Binary.hpp>
12 #include <SFML/Graphics.hpp>
13 #include <unordered_map>
27 :
public bl::event::Listener<event::TimeChange, event::WeatherStarted, event::WeatherStopped,
97 void setAmbientLevel(std::uint8_t lowLightLevel, std::uint8_t highLightLevel);
133 void activate(bl::rc::lgt::Scene2DLighting& sceneLighting);
194 std::vector<Light> rawLights;
195 std::uint8_t minLevel;
196 std::uint8_t maxLevel;
197 std::uint8_t sunlight;
200 bl::rc::lgt::Scene2DLighting* sceneLighting;
201 std::vector<bl::rc::lgt::Light2D> activeLights;
205 float sunlightFactor;
207 int targetWeatherModifier;
208 float weatherResidual;
211 std::uint8_t computeAmbient()
const;
212 void addLightToScene(
const Light& light);
213 void updateAmbientLighting();
226 struct SerializableObject<
core::map::LightingSystem> :
public SerializableObjectBase {
229 SerializableField<1, LS, std::vector<core::map::Light>>
lights;
230 SerializableField<2, LS, std::uint8_t>
low;
231 SerializableField<3, LS, std::uint8_t>
high;
232 SerializableField<4, LS, std::uint8_t>
sun;
235 : SerializableObjectBase(
"LightingSystem")
236 , lights(
"lights", *this, &
LS::rawLights, SerializableFieldBase::Required{})
237 , low(
"low", *this, &
LS::minLevel, SerializableFieldBase::Required{})
238 , high(
"high", *this, &
LS::maxLevel, SerializableFieldBase::Required{})
239 , sun(
"sun", *this, &
LS::sunlight, SerializableFieldBase::Required{}) {}
Core classes and functionality for both the editor and game.
Basic event for when the game time changes.
Fired when weather starts.
Fired when weather stops.
Fired when thunder happens.
Represents a renderable light in a Map.
System for handling lighting in Maps. Manages all the lights and performs rendering....
virtual ~LightingSystem()=default
Destroys the lighting system.
std::uint16_t Handle
Handle representing a light in the map.
std::uint8_t getMaxLightLevel() const
Returns the maximum ambient light level of this map.
void setColorTint(const glm::vec3 &tint)
Sets a color tint to apply to the ambient lighting.
std::uint8_t getMinLightLevel() const
Returns the minimum ambient light level of this map.
LightingSystem()
Initializes the lighting system with no lights.
const Light & getLight(Handle handle) const
Returns the value of the light with the given handle. Invalid handles return a default value (a light...
void addLight(const Light &light)
Adds a light to the map and to the persistent map file.
void update(float dt)
Updates the lighting system.
void adjustForSunlight(bool adjust)
Set whether or not the light level is adjusted based on time of day. If not adjusting for sunlight th...
void unsubscribe()
Unsubscribes the lighting system from the event dispatcher.
void setAmbientLevel(std::uint8_t lowLightLevel, std::uint8_t highLightLevel)
The ambient light band. 0 is full darkness and 255 is full brightness.
void updateLight(Handle handle, const Light &value)
Updates the light with the given handle to the new information.
bool lightsAreOn() const
Returns whether lights are being shown or not based on how dark it is.
Handle getClosestLight(const sf::Vector2i &position)
Returns a handle to the light closest to the given position.
static constexpr Handle None
Special handle indicating that no light is referenced.
void removeLight(Handle light)
Remove the given light from the system and optionally persist the removal.
void activate(bl::rc::lgt::Scene2DLighting &sceneLighting)
Adds all lights into the scene.
void subscribe()
Subscribes the lighting system to time events for ambient light level.
virtual void observe(const event::TimeChange &timeChange) override
Updates the light level based on the new current time.
bool adjustsForSunlight() const
Returns whether or not this map is adjusted for time of day.
void clear()
Clears all lights from the map, including the persisted light data.
SerializableField< 1, LS, std::vector< core::map::Light > > lights
SerializableField< 3, LS, std::uint8_t > high
SerializableField< 4, LS, std::uint8_t > sun
SerializableField< 2, LS, std::uint8_t > low