nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
weather.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_WEATHER_H_
2#define NANOMMO_CLIENT_WEATHER_H_
3
4#include <raylib.h>
5
6#include <cstdint>
7#include <optional>
8#include <vector>
9
10#include "client/atmosphere.h"
11#include "protocol/nanommo.pb.h"
12#include "terrain/terrain.h"
13
14namespace nanommo {
15
16/// Where a bolt of lightning struck, for its thunder to come from.
17struct Bolt {
18 Vector3 at;
19};
20
21/// What the sky lets fall, what glows in the dark, and the lightning, drawn
22/// around the camera from the sky the server sent. Each drop, flake and ember
23/// is worked out from the clock alone, where it is in its fall, so nothing is
24/// kept for any of them between frames.
25class Weather {
26 public:
27 Weather();
28 ~Weather();
29
30 Weather(const Weather&) = delete;
31 Weather& operator=(const Weather&) = delete;
32
33 /// The land's ground, which what falls lands on, and its place in the
34 /// lands, which says what falls there and what glows.
35 void set_land(const Terrain& terrain, int land);
36
37 /// Where the lightning strikes and how often comes from this, so that a
38 /// film's bolts strike where they did the last time.
39 void set_seed(uint32_t seed) { seed_ = seed; }
40
41 /// As soaked as this to start with, rather than as wet as the weather
42 /// would make it: for a film that starts after the rain.
43 void set_wetness(float wetness) { wetness_ = wetness; }
44
45 /// Moves on by the seconds, under the sky, around the camera. Off, nothing
46 /// falls or glows, and the ground dries.
47 void Update(float seconds, const protocol::Sky& sky, bool on,
48 const Camera3D& camera);
49
50 /// Inside BeginMode3D, after what's solid and the sea, as it's all
51 /// see-through.
52 void Draw(const Camera3D& camera, const Atmosphere& atmosphere) const;
53
54 /// From dry to soaked, which rain makes it, and the sun dries.
55 float wetness() const { return wetness_.value_or(0.0f); }
56
57 /// How bright the sky is from a bolt that's just struck, from 0 to 1.
58 float flash() const;
59
60 /// The bolts that struck since the last time, once each.
61 std::vector<Bolt> TakeBolts();
62
63 private:
64 struct Strike {
65 std::vector<Vector3> points;
66 std::vector<Vector3> branch;
67 float at = -10.0f;
68 float near = 1.0f;
69 };
70
71 void DrawFalling(const Camera3D& camera, const Atmosphere& atmosphere,
72 const Terrain& terrain, Vector3 middle) const;
73 void DrawGlows(const Camera3D& camera, const Terrain& terrain,
74 Vector3 middle) const;
75 void DrawStrike(const Camera3D& camera) const;
76 float StrikeLight() const;
77
78 Shader shader_;
79 std::optional<Terrain> terrain_;
80 int land_ = 0;
81 uint32_t seed_ = 1;
82 protocol::Sky sky_;
83 bool on_ = true;
84 /// The seconds the weather's moved on by, which everything falls by.
85 float clock_ = 0.0f;
86 /// Unset until the first sky, so that rain we come into is already wet.
87 std::optional<float> wetness_;
88 /// Until the next bolt, in seconds.
89 float next_bolt_ = 3.0f;
90 uint32_t bolts_struck_ = 0;
91 Strike strike_;
92 std::vector<Bolt> bolts_;
93};
94
95} // namespace nanommo
96
97#endif // NANOMMO_CLIENT_WEATHER_H_
void Update(float seconds, const protocol::Sky &sky, bool on, const Camera3D &camera)
Definition weather.cc:319
void set_seed(uint32_t seed)
Definition weather.h:39
float flash() const
How bright the sky is from a bolt that's just struck, from 0 to 1.
Definition weather.cc:400
Weather(const Weather &)=delete
float wetness() const
From dry to soaked, which rain makes it, and the sun dries.
Definition weather.h:55
Weather & operator=(const Weather &)=delete
void set_land(const Terrain &terrain, int land)
Definition weather.cc:314
void set_wetness(float wetness)
Definition weather.h:43
void Draw(const Camera3D &camera, const Atmosphere &atmosphere) const
Definition weather.cc:404
std::vector< Bolt > TakeBolts()
The bolts that struck since the last time, once each.
Definition weather.cc:402
Definition chat.cc:9
The sky and the light, which the shaders read each frame.
Definition atmosphere.h:13
Where a bolt of lightning struck, for its thunder to come from.
Definition weather.h:17
Vector3 at
Definition weather.h:18