Peoplemon  0.1.0
Peoplemon 3 game source documentation
Sunny.cpp
Go to the documentation of this file.
1 #include "Sunny.hpp"
2 
3 #include <cmath>
4 
5 namespace core
6 {
7 namespace map
8 {
9 namespace weather
10 {
11 namespace
12 {
13 constexpr float Variance = 35.f / 256.f;
14 constexpr float BaseLine = 165.f / 256.f;
15 constexpr float FadeRate = 1.f / 2.5f;
16 constexpr float Wrap = 2.f * 3.141592653f / 3.f;
17 constexpr glm::vec3 Color(2.0f, 1.58f, 0.f);
18 
19 float computeScale(float t) { return (std::sin(3.f * t)) / 1.6f; }
20 
21 float computeLevel(float t) { return BaseLine + computeScale(t) * Variance; }
22 
23 glm::vec3 computeColor(float t) {
24  const float a = computeLevel(t);
25  return {Color.x * a, Color.y * a, 0.f};
26 }
27 
28 } // namespace
29 
31 : t(0.f)
32 , stopping(false)
33 , map(nullptr) {}
34 
36 
37 void Sunny::start(bl::engine::Engine&, bl::rc::RenderTarget&, Map& m) {
38  t = 0.f;
39  factor = 0.f;
40  stopping = false;
41  map = &m;
42 }
43 
44 void Sunny::stop() { stopping = true; }
45 
46 bool Sunny::stopped() const { return stopping && t <= 0.f; }
47 
48 void Sunny::update(float dt) {
49  t += dt;
50  if (t >= Wrap) t = 0.f;
51 
52  if (stopping) { factor = std::max(0.f, factor - FadeRate * dt); }
53  else { factor = std::min(1.f, factor + FadeRate * dt); }
54 
55  if (map) {
56  const glm::vec3 color = computeColor(t) - glm::vec3(1.f);
57  map->lightingSystem().setColorTint(glm::vec3(1.f) + color * factor);
58  }
59 }
60 
61 } // namespace weather
62 } // namespace map
63 } // namespace core
Core classes and functionality for both the editor and game.
void setColorTint(const glm::vec3 &tint)
Sets a color tint to apply to the ambient lighting.
The primary map class that represents a usable map in the game.
Definition: Map.hpp:49
LightingSystem & lightingSystem()
Returns a reference to the lighting system in this map.
Definition: Map.cpp:184
Type
The type of weather.
Definition: Weather.hpp:38
@ Sunny
A very sunny day with pulsating light.
Definition: Weather.hpp:76
virtual void update(float dt) override
Updates the sunny weather.
Definition: Sunny.cpp:48
virtual bool stopped() const override
Returns true when the sun is finished fading.
Definition: Sunny.cpp:46
virtual void start(bl::engine::Engine &engine, bl::rc::RenderTarget &renderTarget, Map &map) override
Starts the sunny weather.
Definition: Sunny.cpp:37
Sunny()
Construct a new Sunny object.
Definition: Sunny.cpp:30
virtual Weather::Type type() const override
Returns Sunny.
Definition: Sunny.cpp:35
virtual void stop() override
Stops the sunny weather.
Definition: Sunny.cpp:44