nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
soundscape.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_SOUNDSCAPE_H_
2#define NANOMMO_CLIENT_SOUNDSCAPE_H_
3
4#include <raylib.h>
5
6#include <array>
7#include <cstdint>
8#include <map>
9#include <utility>
10#include <vector>
11
12#include "client/animator.h"
13#include "client/synth.h"
14
15// When the game's sounds play, and how, kept apart from raylib's audio.
16namespace nanommo {
17
18/// How a sound is heard: how loud, from 0 to 1, and from which side, from -1
19/// for the left to 1 for the right.
20struct Heard {
21 float volume = 1.0f;
22 float pan = 0.0f;
23};
24
25/// In metres: full volume this near, and nothing past far.
26constexpr float kNear = 4.0f;
27constexpr float kFar = 40.0f;
28
29/// A sound at the source, heard by the player, at the ears, with the camera's
30/// right to their right. Past near, it falls as one over the distance, and it
31/// fades out to nothing at far.
32Heard Hear(Vector3 source, Vector3 ears, Vector3 right);
33
34/// Which take of a sound plays next, and how, so that a sound heard again and
35/// again doesn't sound like a machine: not the take that played last, a little
36/// higher or lower, and at most a little quieter.
37class Variety {
38 public:
39 struct Take {
40 int take = 0;
41 /// Where 1 is as it was made, and 2 an octave up.
42 float pitch = 1.0f;
43 float volume = 1.0f;
44 };
45
46 /// The pitch can be off by its spread either way, and the volume down by
47 /// its spread.
48 Variety(uint32_t seed, float pitch_spread, float volume_spread);
49
50 /// One of that many takes.
51 Take Next(int takes);
52
53 private:
54 Noise noise_;
55 float pitch_spread_;
56 float volume_spread_;
57 int last_ = -1;
58};
59
60/// Where a figure is in its walk or run: how many times its clip has looped,
61/// and how far into a loop each foot comes down, from 0 to 1.
62struct Gait {
63 float loops = 0.0f;
64 std::array<float, 2> footfalls{0.0f, 0.5f};
65};
66
67/// How far into the clip each foot comes down, from 0 to 1: where each foot's
68/// bone, left and right, drops to near its lowest. A clip without them steps
69/// at its start and halfway.
70std::array<float, 2> Footfalls(const ModelAnimation& clip, int left, int right);
71
72/// Which figures put a foot down, from how far each has got through its walk
73/// or run since the last update.
74class Footsteps {
75 public:
76 /// Those, by Who, from each walking or running figure's gait. A figure
77 /// that's left out has stopped, and starts afresh.
78 std::vector<uint64_t> Update(const std::map<uint64_t, Gait>& gaits);
79
80 private:
81 std::map<uint64_t, float> loops_;
82};
83
84/// Which players started a skill since the last update: another skill, or the
85/// one before again, as their time in it starts over.
86class Casts {
87 public:
88 std::vector<Figure> Update(const std::vector<Figure>& figures);
89
90 private:
91 /// Each player's skill, and their time in it, by their id.
92 std::map<uint32_t, std::pair<uint32_t, float>> skills_;
93};
94
95/// When a gate's sounds play, from the loading screen: the departure, as its
96/// cover goes up over the world we were in, and the arrival, as it lifts off
97/// the land we came to, which is also how we enter the world.
98class Passage {
99 public:
100 enum class Cue { kNothing, kDeparture, kArrival };
101
102 Cue Update(bool covering, bool in_world);
103
104 private:
105 bool covering_ = false;
106 bool in_world_ = false;
107};
108
109} // namespace nanommo
110
111#endif // NANOMMO_CLIENT_SOUNDSCAPE_H_
std::vector< Figure > Update(const std::vector< Figure > &figures)
std::vector< uint64_t > Update(const std::map< uint64_t, Gait > &gaits)
Definition soundscape.cc:92
Cue Update(bool covering, bool in_world)
Variety(uint32_t seed, float pitch_spread, float volume_spread)
Definition soundscape.cc:38
Take Next(int takes)
One of that many takes.
Definition soundscape.cc:43
Definition chat.cc:9
constexpr float kNear
In metres: full volume this near, and nothing past far.
Definition soundscape.h:26
constexpr float kArrival
Past the edge of a gate, so that players don't arrive inside it.
Definition lands.h:84
std::array< float, 2 > Footfalls(const ModelAnimation &clip, int left, int right)
Definition soundscape.cc:57
Heard Hear(Vector3 source, Vector3 ears, Vector3 right)
Definition soundscape.cc:21
constexpr float kFar
Definition soundscape.h:27
std::array< float, 2 > footfalls
Definition soundscape.h:64
float pitch
Where 1 is as it was made, and 2 an octave up.
Definition soundscape.h:42