nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
fx.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_FX_H_
2#define NANOMMO_CLIENT_FX_H_
3
4#include <raylib.h>
5
6#include <cstddef>
7#include <cstdint>
8#include <deque>
9#include <map>
10#include <optional>
11#include <set>
12#include <utility>
13#include <vector>
14
15#include "client/animator.h"
16#include "client/atmosphere.h"
17#include "client/characters.h"
18#include "content/items.h"
19#include "content/skills.h"
20#include "terrain/terrain.h"
21
22namespace nanommo {
23
24/// What the skills show besides the players' moves: their fx. Each is worked
25/// out from how long ago the skill started, so it looks the same at any frame
26/// rate.
27class Fx {
28 public:
29 /// While a blow that's landed holds things still, they go at this share of
30 /// their speed, and then catch up, faster, over this many times as long.
31 static constexpr float kStill = 0.05f;
32 static constexpr float kCatchUp = 1.5f;
33 /// How far apart the copies a fast move leaves are, in seconds.
34 static constexpr float kGhostGap = 0.05f;
35
36 /// The shards and the spikes are solid, lit by the world's shader. A swing
37 /// lands when the weapon in the hand says, from the items.
38 Fx(const SkillTable& skills, Shader lit, const ItemTable& items = {});
39 ~Fx();
40
41 Fx(const Fx&) = delete;
42 Fx& operator=(const Fx&) = delete;
43
44 /// Follows the skills the players are using, and keeps each going until
45 /// its fx are over, as a ring spreads on after the move's done.
46 void Update(const std::vector<Figure>& figures, float seconds);
47
48 /// Holds the players back where a blow of theirs has just landed, and what
49 /// it landed on with them, for the weight of the hit.
50 void Hold(std::vector<Figure>& figures) const;
51
52 /// The shards and the spikes.
53 void DrawSolid(const Terrain& terrain) const;
54
55 /// The copies fast moves leave behind them, which go over what's solid.
56 void DrawGhosts(const Characters& characters) const;
57
58 /// The light, which goes over what's behind it, and blooms.
59 void DrawLight(const Camera3D& camera, const Terrain& terrain,
60 const Atmosphere& atmosphere,
61 const Characters& characters) const;
62
63 /// How far the camera's shaken, at this moment, by the skills near it.
64 Vector3 Shake(Vector3 camera) const;
65
66 /// How far in our own camera goes, in metres, for a skill we're using.
67 float Zoom() const;
68
69 /// How many skills' fx are going.
70 std::size_t casts() const { return casts_.size(); }
71
72 private:
73 struct Cast {
74 /// The player as we last saw them using it.
75 Figure figure;
76 /// Seconds since it started, and how far its move and fx have got, which
77 /// the blows that land hold back.
78 float clock = 0.0f;
79 float time = 0.0f;
80 /// Where the monster they picked is, if they picked one.
81 std::optional<Vector3> target;
82 /// Each cast has sparks of its own.
83 uint32_t seed = 0;
84 /// Whether each blow it's got to so far landed, in order.
85 std::vector<bool> landed;
86 /// What its blows landed on, by id, held still with the player.
87 std::set<uint32_t> struck;
88 /// Where the player's been, by the time of the cast's move.
89 std::deque<std::pair<float, Vector3>> path;
90 };
91
92 /// When each of the skill's blows lands, in seconds, for the player, and
93 /// how much longer than the skill's stop it holds things still.
94 struct Beat {
95 float at = 0.0f;
96 float weight = 1.0f;
97 };
98 std::vector<Beat> BlowsOf(const skills::Skill& skill,
99 const Figure& figure) const;
100 /// How far the cast's held back now, in seconds.
101 float Lag(const Cast& cast) const;
102 /// Whether the blow lands, as we see it: what it goes for is alive and
103 /// within its reach. What it lands on goes into the cast's struck.
104 bool Lands(Cast& cast, const skills::Skill& skill,
105 const std::vector<Figure>& figures) const;
106
107 std::map<uint32_t, skills::Skill> skills_;
108 /// Each weapon's swing, by its item's id.
109 std::map<uint32_t, items::Weapon> weapons_;
110 /// When each skill's fx are over, in seconds, by its id.
111 std::map<uint32_t, float> ends_;
112 /// By the player's id.
113 std::map<uint32_t, Cast> casts_;
114 uint32_t seeds_ = 0;
115 Shader light_;
116 Model shard_;
117};
118
119} // namespace nanommo
120
121#endif // NANOMMO_CLIENT_FX_H_
void DrawGhosts(const Characters &characters) const
The copies fast moves leave behind them, which go over what's solid.
Definition fx.cc:685
void DrawLight(const Camera3D &camera, const Terrain &terrain, const Atmosphere &atmosphere, const Characters &characters) const
The light, which goes over what's behind it, and blooms.
Definition fx.cc:825
std::size_t casts() const
How many skills' fx are going.
Definition fx.h:70
static constexpr float kStill
Definition fx.h:31
Vector3 Shake(Vector3 camera) const
How far the camera's shaken, at this moment, by the skills near it.
Definition fx.cc:936
Fx(const Fx &)=delete
void Hold(std::vector< Figure > &figures) const
Definition fx.cc:341
Fx(const SkillTable &skills, Shader lit, const ItemTable &items={})
Definition fx.cc:172
Fx & operator=(const Fx &)=delete
float Zoom() const
How far in our own camera goes, in metres, for a skill we're using.
Definition fx.cc:960
void DrawSolid(const Terrain &terrain) const
The shards and the spikes.
Definition fx.cc:739
static constexpr float kCatchUp
Definition fx.h:32
static constexpr float kGhostGap
How far apart the copies a fast move leaves are, in seconds.
Definition fx.h:34
void Update(const std::vector< Figure > &figures, float seconds)
Definition fx.cc:199
Definition chat.cc:9
The sky and the light, which the shaders read each frame.
Definition atmosphere.h:13
The items in the items file, by id.
Definition items.h:18