Peoplemon  0.1.0
Peoplemon 3 game source documentation
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
core::map::LightingSystem Class Reference

System for handling lighting in Maps. Manages all the lights and performs rendering. Also handles the loading and saving of lights to map files. More...

#include <LightingSystem.hpp>

+ Inheritance diagram for core::map::LightingSystem:

Public Types

using Handle = std::uint16_t
 Handle representing a light in the map. More...
 

Public Member Functions

 LightingSystem ()
 Initializes the lighting system with no lights. More...
 
virtual ~LightingSystem ()=default
 Destroys the lighting system. More...
 
void addLight (const Light &light)
 Adds a light to the map and to the persistent map file. More...
 
void updateLight (Handle handle, const Light &value)
 Updates the light with the given handle to the new information. More...
 
Handle getClosestLight (const sf::Vector2i &position)
 Returns a handle to the light closest to the given position. More...
 
const LightgetLight (Handle handle) const
 Returns the value of the light with the given handle. Invalid handles return a default value (a light with a negative position and 0 radius) More...
 
void removeLight (Handle light)
 Remove the given light from the system and optionally persist the removal. More...
 
bool lightsAreOn () const
 Returns whether lights are being shown or not based on how dark it is. More...
 
void setAmbientLevel (std::uint8_t lowLightLevel, std::uint8_t highLightLevel)
 The ambient light band. 0 is full darkness and 255 is full brightness. More...
 
std::uint8_t getMinLightLevel () const
 Returns the minimum ambient light level of this map. More...
 
std::uint8_t getMaxLightLevel () const
 Returns the maximum ambient light level of this map. More...
 
void adjustForSunlight (bool adjust)
 Set whether or not the light level is adjusted based on time of day. If not adjusting for sunlight the higher light level is used for a constant ambient. More...
 
bool adjustsForSunlight () const
 Returns whether or not this map is adjusted for time of day. More...
 
void activate (bl::rc::lgt::Scene2DLighting &sceneLighting)
 Adds all lights into the scene. More...
 
void subscribe ()
 Subscribes the lighting system to time events for ambient light level. More...
 
void unsubscribe ()
 Unsubscribes the lighting system from the event dispatcher. More...
 
void clear ()
 Clears all lights from the map, including the persisted light data. More...
 
void update (float dt)
 Updates the lighting system. More...
 
void setColorTint (const glm::vec3 &tint)
 Sets a color tint to apply to the ambient lighting. More...
 
virtual void observe (const event::TimeChange &timeChange) override
 Updates the light level based on the new current time. More...
 
virtual void observe (const event::WeatherStarted &event) override
 Adjusts the ambient lighting based on the current weather. More...
 
virtual void observe (const event::WeatherStopped &event) override
 Resets the ambient lighting when weather stops. More...
 
virtual void observe (const event::Thundered &) override
 Triggers the lighting cycle for thunder. More...
 

Static Public Attributes

static constexpr Handle None = 0
 Special handle indicating that no light is referenced. More...
 

Friends

struct bl::serial::SerializableObject< LightingSystem >
 

Detailed Description

System for handling lighting in Maps. Manages all the lights and performs rendering. Also handles the loading and saving of lights to map files.

Definition at line 26 of file LightingSystem.hpp.

Member Typedef Documentation

◆ Handle

using core::map::LightingSystem::Handle = std::uint16_t

Handle representing a light in the map.

Definition at line 31 of file LightingSystem.hpp.

Constructor & Destructor Documentation

◆ LightingSystem()

core::map::LightingSystem::LightingSystem ( )

Initializes the lighting system with no lights.

Definition at line 22 of file LightingSystem.cpp.

◆ ~LightingSystem()

virtual core::map::LightingSystem::~LightingSystem ( )
virtualdefault

Destroys the lighting system.

Member Function Documentation

◆ activate()

void core::map::LightingSystem::activate ( bl::rc::lgt::Scene2DLighting &  sceneLighting)

Adds all lights into the scene.

Parameters
sceneLightingThe lighting manager for the map scene

Definition at line 107 of file LightingSystem.cpp.

◆ addLight()

void core::map::LightingSystem::addLight ( const Light light)

Adds a light to the map and to the persistent map file.

Parameters
lightThe light to add

Definition at line 34 of file LightingSystem.cpp.

◆ adjustForSunlight()

void core::map::LightingSystem::adjustForSunlight ( bool  adjust)

Set whether or not the light level is adjusted based on time of day. If not adjusting for sunlight the higher light level is used for a constant ambient.

Parameters
adjustTrue to adjust based on time of day, false to always use ambient level

Definition at line 103 of file LightingSystem.cpp.

◆ adjustsForSunlight()

bool core::map::LightingSystem::adjustsForSunlight ( ) const

Returns whether or not this map is adjusted for time of day.

Returns
True is adjusting light level based on time, false if constant light level

Definition at line 105 of file LightingSystem.cpp.

◆ clear()

void core::map::LightingSystem::clear ( )

Clears all lights from the map, including the persisted light data.

Definition at line 124 of file LightingSystem.cpp.

◆ getClosestLight()

LightingSystem::Handle core::map::LightingSystem::getClosestLight ( const sf::Vector2i &  position)

Returns a handle to the light closest to the given position.

Parameters
positionThe position to search near
Returns
Handle A handle to the closest light. Do not store as handles may be invalidated

Definition at line 64 of file LightingSystem.cpp.

◆ getLight()

const Light & core::map::LightingSystem::getLight ( Handle  handle) const

Returns the value of the light with the given handle. Invalid handles return a default value (a light with a negative position and 0 radius)

Parameters
handleThe handle to get the light for
Returns
const Light& The value of the light with the given handle

Definition at line 80 of file LightingSystem.cpp.

◆ getMaxLightLevel()

std::uint8_t core::map::LightingSystem::getMaxLightLevel ( ) const

Returns the maximum ambient light level of this map.

Returns
std::uint8_t The maximum ambient light level

Definition at line 101 of file LightingSystem.cpp.

◆ getMinLightLevel()

std::uint8_t core::map::LightingSystem::getMinLightLevel ( ) const

Returns the minimum ambient light level of this map.

Returns
std::uint8_t The minimum ambient light level

Definition at line 99 of file LightingSystem.cpp.

◆ lightsAreOn()

bool core::map::LightingSystem::lightsAreOn ( ) const

Returns whether lights are being shown or not based on how dark it is.

Definition at line 91 of file LightingSystem.cpp.

◆ observe() [1/4]

void core::map::LightingSystem::observe ( const event::Thundered )
overridevirtual

Triggers the lighting cycle for thunder.

Definition at line 265 of file LightingSystem.cpp.

◆ observe() [2/4]

void core::map::LightingSystem::observe ( const event::TimeChange timeChange)
overridevirtual

Updates the light level based on the new current time.

Parameters
timeChangeThe new current time

Definition at line 209 of file LightingSystem.cpp.

◆ observe() [3/4]

void core::map::LightingSystem::observe ( const event::WeatherStarted event)
overridevirtual

Adjusts the ambient lighting based on the current weather.

Parameters
eventThe new weather that has started

Definition at line 219 of file LightingSystem.cpp.

◆ observe() [4/4]

void core::map::LightingSystem::observe ( const event::WeatherStopped event)
overridevirtual

Resets the ambient lighting when weather stops.

Parameters
eventThe weather that just stopped

Definition at line 263 of file LightingSystem.cpp.

◆ removeLight()

void core::map::LightingSystem::removeLight ( Handle  light)

Remove the given light from the system and optionally persist the removal.

Parameters
lightA handle to the light to remove
updateSaveTrue to update the data saved to the map file (editor only)

Definition at line 82 of file LightingSystem.cpp.

◆ setAmbientLevel()

void core::map::LightingSystem::setAmbientLevel ( std::uint8_t  lowLightLevel,
std::uint8_t  highLightLevel 
)

The ambient light band. 0 is full darkness and 255 is full brightness.

Parameters
lowLightLevelThe min light level. This is reached at midnight
highLightLevelThe max light level. This is reached at noon

Definition at line 93 of file LightingSystem.cpp.

◆ setColorTint()

void core::map::LightingSystem::setColorTint ( const glm::vec3 &  tint)

Sets a color tint to apply to the ambient lighting.

Parameters
tintThe tint to apply to the ambient light color

Definition at line 267 of file LightingSystem.cpp.

◆ subscribe()

void core::map::LightingSystem::subscribe ( )

Subscribes the lighting system to time events for ambient light level.

Definition at line 120 of file LightingSystem.cpp.

◆ unsubscribe()

void core::map::LightingSystem::unsubscribe ( )

Unsubscribes the lighting system from the event dispatcher.

Definition at line 122 of file LightingSystem.cpp.

◆ update()

void core::map::LightingSystem::update ( float  dt)

Updates the lighting system.

Parameters
dtTime elapsed in seconds

Definition at line 134 of file LightingSystem.cpp.

◆ updateLight()

void core::map::LightingSystem::updateLight ( Handle  handle,
const Light value 
)

Updates the light with the given handle to the new information.

Parameters
handleThe handle referencing the light to update
valueThe new light information

Definition at line 50 of file LightingSystem.cpp.

Friends And Related Function Documentation

◆ bl::serial::SerializableObject< LightingSystem >

friend struct bl::serial::SerializableObject< LightingSystem >
friend

Definition at line 213 of file LightingSystem.hpp.

Member Data Documentation

◆ None

constexpr Handle core::map::LightingSystem::None = 0
staticconstexpr

Special handle indicating that no light is referenced.

Definition at line 34 of file LightingSystem.hpp.


The documentation for this class was generated from the following files: