nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
characters.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_CHARACTERS_H_
2#define NANOMMO_CLIENT_CHARACTERS_H_
3
4#include <raylib.h>
5
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <map>
10#include <optional>
11#include <string>
12#include <utility>
13#include <vector>
14
15#include "client/animator.h"
16#include "client/moves.h"
17#include "client/outline.h"
18#include "client/soundscape.h"
19#include "content/figures.pb.h"
20#include "content/items.pb.h"
21#include "content/rig.pb.h"
22#include "content/skills.pb.h"
23
24namespace nanommo {
25
26std::string MonstersFolder();
27
28std::string WeaponsFolder();
29
30std::string ContentFolder();
31
32class Characters {
33 public:
34 /// People: one for each of the rig's builds, with its motions, in the
35 /// figures' body, and each player in their own skin and hair.
36 Characters(const rig::Rig& rig, Shader shader,
37 const figures::Figures& figures);
38
39 /// Monsters: each model in the folder's files, with the clips in it, as
40 /// tall as the height.
41 Characters(const std::string& folder, const std::vector<std::string>& files,
42 float height, Shader shader);
44
45 Characters(const Characters&) = delete;
46 Characters& operator=(const Characters&) = delete;
47
48 std::size_t size() const { return characters_.size(); }
49
50 /// Loads the item's model, to draw in the hand of each figure that holds
51 /// the item.
52 void Hold(uint32_t id, const items::Look& look, Shader shader);
53
54 /// Makes the item's parts, for each character to draw on the players who
55 /// wear it.
56 void Wear(uint32_t id, const items::Look& look);
57
58 /// Keeps the skill's move, for the players who use it.
59 void Learn(uint32_t skill, const skills::Look& look);
60
61 /// Draws the figure, posed, with what it wears and its weapon, and with an
62 /// outline, when it's given one: a model in the colour, and a player's
63 /// figure in their skin, with their hair, and what's dyed in the colour.
64 void Draw(const Figure& figure, Color color, const Outline* outline) const;
65
66 /// The figure as it was, see-through and lit in the colour, without an
67 /// outline: one of the copies a fast move leaves behind it. Drawn after
68 /// what's solid, as it doesn't hide what's behind it.
69 void DrawGhost(const Figure& figure, Color color) const;
70
71 /// Where the figure's blade is, in the world, from the hilt to the tip, as
72 /// it's posed: none, if it holds nothing.
73 std::optional<std::pair<Vector3, Vector3>> Blade(const Figure& figure) const;
74
75 /// Where the figure is in its walk or run: none, if it's doing neither.
76 std::optional<Gait> GaitOf(const Figure& figure) const;
77
78 private:
79 /// Something over the figure, such as the hair or what it wears, as a model
80 /// and its hull, which share the character's bones.
81 struct Garment {
82 Model model;
83 Model hull;
84 /// Drawn in the player's colour, rather than its own.
85 bool dyed = false;
86 };
87
88 struct Character {
89 Model model;
90 /// What the outline draws: the model, or a figure's hull, on the
91 /// model's bones.
92 Model hull;
93 bool dressed = false;
94 /// Each way to wear the hair, by its place in the figures' list, but
95 /// bald.
96 std::map<int, Garment> hairs;
97 /// What it can wear, by the item's id.
98 std::map<uint32_t, Garment> garments;
99 ModelAnimation* clips = nullptr;
100 int clip_count = 0;
101 std::array<int, 5> clip_for{};
102 std::array<float, 5> speed{1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
103 /// Where each foot comes down in each motion's clip.
104 std::array<std::array<float, 2>, 5> footfalls{};
105 float scale = 1.0f;
106 int hand = -1;
107 /// The bones the moves turn.
108 Joints joints{};
109 };
110
111 struct Pose {
112 const ModelAnimation* clip;
113 float frame;
114 };
115
116 /// Finds the character's hand, its feet and its joints, and where its feet
117 /// come down, and draws it with the shader.
118 static void Ready(Character& character, Shader shader);
119
120 /// Puts the figures' body on the character, its hull, and each way to wear
121 /// the hair.
122 static void Dress(Character& character, const figures::Figures& figures);
123
124 /// Frees what the character's model, clips and garments hold.
125 static void Unload(Character& character);
126
127 static Pose PoseFor(const Character& character, protocol::Motion motion,
128 float time);
129
130 /// Poses the character's bones as the figure is: its clips, blended, and
131 /// the move of the skill it's using.
132 void PoseAs(const Character& character, const Figure& figure) const;
133
134 /// Where the figure stands, turned and at its scale.
135 static Matrix Placed(const Character& character, const Figure& figure);
136
137 /// Where the held item goes, as the hand's bone is now.
138 static Matrix InHand(const Character& character, const Matrix& grip);
139
140 struct Weapon {
141 Model model;
142 Matrix grip;
143 /// Along the blade, in the model's own units.
144 Vector3 hilt;
145 Vector3 tip;
146 };
147
148 const Character& For(const Figure& figure) const;
149
150 figures::Figures figures_;
151 std::vector<Character> characters_;
152 std::map<uint32_t, Weapon> weapons_;
153 /// Each skill's move, by the skill's id.
154 std::map<uint32_t, skills::Move> moves_;
155 Shader shader_;
156 /// The light the figure gives off, in the shader, to light it up.
157 int emission_ = -1;
158};
159
160} // namespace nanommo
161
162#endif // NANOMMO_CLIENT_CHARACTERS_H_
std::size_t size() const
Definition characters.h:48
void Learn(uint32_t skill, const skills::Look &look)
Keeps the skill's move, for the players who use it.
std::optional< Gait > GaitOf(const Figure &figure) const
Where the figure is in its walk or run: none, if it's doing neither.
void DrawGhost(const Figure &figure, Color color) const
void Wear(uint32_t id, const items::Look &look)
Characters(const Characters &)=delete
std::optional< std::pair< Vector3, Vector3 > > Blade(const Figure &figure) const
Characters & operator=(const Characters &)=delete
void Hold(uint32_t id, const items::Look &look, Shader shader)
Characters(Database &database)
Definition characters.h:24
void Draw(const Figure &figure, Color color, const Outline *outline) const
Definition chat.cc:9
std::string ContentFolder()
std::string WeaponsFolder()
std::string MonstersFolder()
std::array< int, kJointBones.size()> Joints
Where a model's bones are, by joint, or -1 for one it doesn't have.
Definition moves.h:19