Luanti 5.17.0-dev
Loading...
Searching...
No Matches
content_cao.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irrlichttypes.h"
8
9#include <EMaterialTypes.h>
10#include <IDummyTransformationSceneNode.h>
11#include <AnimSpec.h>
12
13#include "object_properties.h"
14#include "clientobject.h"
15#include "constants.h"
16#include "itemgroup.h"
17#include "client/tile.h"
18#include <cassert>
19#include <memory>
20
21namespace scene {
22 class IMeshSceneNode;
23 class IBillboardSceneNode;
24 class AnimatedMeshSceneNode;
25}
26
27class Client;
28struct Nametag;
29struct MinimapMarker;
31
32enum class LocalPlayerAnimation : u8;
33
34/*
35 SmoothTranslator and other helpers
36*/
37
38template<typename T>
40{
44 f32 anim_time = 0;
46 bool aim_is_end = true;
47
48 SmoothTranslator() = default;
49
50 void init(T current);
51
52 void update(T new_target, bool is_end_position = false,
53 float update_interval = -1);
54
55 void translate(f32 dtime);
56};
57
59{
60 void translate(f32 dtime);
61};
62
64{
65 void translate(f32 dtime);
66};
67
73
74/*
75 GenericCAO
76*/
77
79{
80private:
81
82 // Only set at initialization
83 std::string m_name = "";
84 bool m_is_player = false;
85 bool m_is_local_player = false;
86 // Property-ish things
88 //
89 scene::ISceneManager *m_smgr = nullptr;
90 Client *m_client = nullptr;
91 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
92
93 // Visuals
94 scene::IMeshSceneNode *m_meshnode = nullptr;
95 scene::AnimatedMeshSceneNode *m_animated_meshnode = nullptr;
97 scene::IBillboardSceneNode *m_spritenode = nullptr;
98 scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
99 Nametag *m_nametag = nullptr;
101 bool m_visuals_expired = false;
102 video::SColor m_last_light = video::SColor(0xFFFFFFFF);
103 bool m_is_visible = false;
104 std::vector<MeshAnimationInfo> m_meshnode_animation;
105
106 // Material
107 video::E_MATERIAL_TYPE m_material_type = video::EMT_INVALID;
108
109 // Movement
110 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
114 u16 m_hp = 1;
117
118 // Spritesheet stuff
119 // TODO move into own struct
126 float m_anim_framelength = 0.2f;
127 float m_anim_timer = 0.0f;
128
131 scene::AnimSpec m_animation;
137 std::vector<std::pair<std::string, scene::TrackAnimSpec>> deferred_set_animation_cmds;
138
139 void applyTrackAnimation(scene::TrackId &&track_id, scene::TrackAnimSpec anim);
140
141 // stores position and rotation for each bone name
143
144 // Attachments
146 std::unordered_set<object_t> m_attachment_child_ids;
147 std::string m_attachment_bone = "";
151 bool m_force_visible = false;
152
155 // stores texture modifier before punch update
157 // last applied texture modifier
160
161 bool visualExpiryRequired(const ObjectProperties &newprops) const;
162
163public:
164
166
167 ~GenericCAO();
168
169 static std::unique_ptr<ClientActiveObject> create(Client *client, ClientEnvironment *env)
170 {
171 return std::make_unique<GenericCAO>(client, env);
172 }
173
174 inline ActiveObjectType getType() const override
175 {
177 }
178 inline const ItemGroupList &getGroups() const
179 {
180 return m_armor_groups;
181 }
182 void initialize(const std::string &data) override;
183
184 void processInitData(const std::string &data);
185
186 bool getCollisionBox(aabb3f *toset) const override;
187
188 bool collideWithObjects() const override;
189
190 virtual bool getSelectionBox(aabb3f *toset) const override;
191
192 const v3f getPosition() const override final;
193
194 const v3f getVelocity() const override final { return m_velocity; }
195
196 inline const v3f &getRotation() const { return m_rotation; }
197
198 bool isImmortal() const;
199
200 inline const ObjectProperties &getProperties() const { return m_prop; }
201
202 inline const std::string &getName() const { return m_name; }
203
204 scene::ISceneNode *getSceneNode() const override;
205
206 scene::AnimatedMeshSceneNode *getAnimatedMeshSceneNode() const override;
207
208 // m_matrixnode controls the position and rotation of the child node
209 // for all scene nodes, as a workaround for an Irrlicht problem with
210 // rotations. The child node's position can't be used because it's
211 // rotated, and must remain as 0.
212 // Note that m_matrixnode.setPosition() shouldn't be called. Use
213 // m_matrixnode->getRelativeTransformationMatrix().setTranslation()
214 // instead (aka getPosRotMatrix().setTranslation()).
215 inline core::matrix4 &getPosRotMatrix()
216 {
217 assert(m_matrixnode);
218 return m_matrixnode->getRelativeTransformationMatrix();
219 }
220
221 inline const core::matrix4 *getAbsolutePosRotMatrix() const
222 {
223 if (!m_matrixnode)
224 return nullptr;
225 return &m_matrixnode->getAbsoluteTransformation();
226 }
227
228 inline f32 getStepHeight() const
229 {
230 return m_prop.stepheight;
231 }
232
233 inline bool isLocalPlayer() const override
234 {
235 return m_is_local_player;
236 }
237
238 inline bool isPlayer() const
239 {
240 return m_is_player;
241 }
242
243 inline bool isVisible() const
244 {
245 return m_is_visible;
246 }
247
248 inline void setVisible(bool toset)
249 {
250 m_is_visible = toset;
251 }
252
253 void setChildrenVisible(bool toset);
254 void setAttachment(object_t parent_id, const std::string &bone, v3f position,
255 v3f rotation, bool force_visible) override;
256 void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
257 v3f *rotation, bool *force_visible) const override;
258 void clearChildAttachments() override;
259 void addAttachmentChild(object_t child_id) override;
260 void removeAttachmentChild(object_t child_id) override;
261 ClientActiveObject *getParent() const override;
262 const std::unordered_set<object_t> &getAttachmentChildIds() const override
263 { return m_attachment_child_ids; }
264 void updateAttachments() override;
265
266 void removeFromScene(bool permanent) override;
267
268 void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override;
269
270 inline void expireVisuals()
271 {
272 m_visuals_expired = true;
273 }
274
275 void updateLight(u32 day_night_ratio) override;
276
277 void setNodeLight(const video::SColor &light);
278
279 /* Get light position(s).
280 * returns number of positions written into pos[], which must have space
281 * for at least 3 vectors. */
282 u16 getLightPosition(v3s16 *pos);
283
284 void updateNametag();
285
286 void updateMarker();
287
288 void updateNodePos();
289
290 void step(float dtime, ClientEnvironment *env) override;
291
292 void updateTextureAnim();
293
294 // ffs this HAS TO BE a string copy! See #5739 if you think otherwise
295 // Reason: updateTextures(m_previous_texture_modifier);
296 void updateTextures(std::string mod);
297
298 void updateAnimation(u16 track_nr);
299 void setLocalPlayerAnimation(LocalPlayerAnimation local_anim, float speed);
300
302 std::optional<u16> resolveTrackId(const scene::TrackId &id);
303
304 void processMessage(const std::string &data) override;
305
306 bool directReportPunch(v3f dir, const ItemStack *punchitem,
307 const ItemStack *hand_item, float time_from_last_punch=1000000) override;
308
309 std::string debugInfoText() override;
310
311 std::string infoText() override
312 {
313 return m_prop.infotext;
314 }
315
316 void updateMeshCulling();
317
318private:
319
321 void updateParentChain() const;
322
323};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:149
ActiveObjectType
Definition activeobject.h:15
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:29
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:205
u16 object_t
Definition activeobject.h:158
Definition clientobject.h:27
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env)
Definition clientobject.cpp:12
Definition clientenvironment.h:54
Definition client.h:107
v2f m_tx_size
Definition content_cao.h:120
scene::IMeshSceneNode * m_meshnode
Definition content_cao.h:94
v3f m_attachment_rotation
Definition content_cao.h:149
void processInitData(const std::string &data)
Definition content_cao.cpp:295
void updateParentChain() const
Update the parent chain so getPosition() returns an up to date position.
Definition content_cao.cpp:350
int m_anim_frame
Definition content_cao.h:124
aabb3f m_selection_box
Definition content_cao.h:91
v3f m_acceleration
Definition content_cao.h:112
std::string m_current_texture_modifier
Definition content_cao.h:158
void updateNametag()
Definition content_cao.cpp:932
void processMessage(const std::string &data) override
Definition content_cao.cpp:1578
void initialize(const std::string &data) override
Definition content_cao.cpp:290
object_t m_attachment_parent_id
Definition content_cao.h:145
MinimapMarker * m_marker
Definition content_cao.h:100
void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override
Definition content_cao.cpp:573
void clearChildAttachments() override
Definition content_cao.cpp:494
scene::AnimSpec m_animation
The animation for all tracks as specified by the server.
Definition content_cao.h:131
BoneOverrideMap m_bone_override
Definition content_cao.h:142
bool m_is_local_player
Definition content_cao.h:85
bool m_is_player
Definition content_cao.h:84
void addAttachmentChild(object_t child_id) override
Definition content_cao.cpp:507
void setNodeLight(const video::SColor &light)
Definition content_cao.cpp:882
scene::IDummyTransformationSceneNode * m_matrixnode
Definition content_cao.h:98
bool isVisible() const
Definition content_cao.h:243
bool isImmortal() const
Definition content_cao.cpp:382
scene::AnimatedMeshSceneNode * getAnimatedMeshSceneNode() const override
Definition content_cao.cpp:407
u16 m_hp
Definition content_cao.h:114
void expireVisuals()
Definition content_cao.h:270
const v3f getPosition() const override final
Definition content_cao.cpp:362
void updateLight(u32 day_night_ratio) override
Definition content_cao.cpp:842
const ObjectProperties & getProperties() const
Definition content_cao.h:200
std::string m_attachment_bone
Definition content_cao.h:147
v3f m_position
Definition content_cao.h:110
void setVisible(bool toset)
Definition content_cao.h:248
void updateMeshCulling()
Definition content_cao.cpp:1934
std::unordered_set< object_t > m_attachment_child_ids
Definition content_cao.h:146
v2s16 m_tx_basepos
Definition content_cao.h:121
v3f m_attachment_position
Definition content_cao.h:148
bool isLocalPlayer() const override
Definition content_cao.h:233
float m_step_distance_counter
Definition content_cao.h:159
void removeAttachmentChild(object_t child_id) override
Definition content_cao.cpp:512
const std::string & getName() const
Definition content_cao.h:202
const core::matrix4 * getAbsolutePosRotMatrix() const
Definition content_cao.h:221
float m_anim_framelength
Definition content_cao.h:126
video::SColor m_last_light
Definition content_cao.h:102
void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const override
Definition content_cao.cpp:484
float m_reset_textures_timer
Definition content_cao.h:154
void setLocalPlayerAnimation(LocalPlayerAnimation local_anim, float speed)
Definition content_cao.cpp:1395
video::E_MATERIAL_TYPE m_material_type
Definition content_cao.h:107
const v3f getVelocity() const override final
Definition content_cao.h:194
const std::unordered_set< object_t > & getAttachmentChildIds() const override
Definition content_cao.h:262
bool directReportPunch(v3f dir, const ItemStack *punchitem, const ItemStack *hand_item, float time_from_last_punch=1000000) override
Definition content_cao.cpp:1880
std::string debugInfoText() override
Definition content_cao.cpp:1920
scene::ISceneManager * m_smgr
Definition content_cao.h:89
v3f m_rotation
Definition content_cao.h:113
void setChildrenVisible(bool toset)
Definition content_cao.cpp:412
void removeFromScene(bool permanent) override
Definition content_cao.cpp:523
const ItemGroupList & getGroups() const
Definition content_cao.h:178
void applyTrackAnimation(scene::TrackId &&track_id, scene::TrackAnimSpec anim)
Definition content_cao.cpp:1536
SmoothTranslatorWrappedv3f rot_translator
Definition content_cao.h:116
u16 getLightPosition(v3s16 *pos)
Definition content_cao.cpp:899
static std::unique_ptr< ClientActiveObject > create(Client *client, ClientEnvironment *env)
Definition content_cao.h:169
bool m_tx_select_horiz_by_yawpitch
Definition content_cao.h:123
void updateTextures(std::string mod)
Definition content_cao.cpp:1293
std::string infoText() override
Definition content_cao.h:311
bool m_initial_tx_basepos_set
Definition content_cao.h:122
void updateAttachments() override
Definition content_cao.cpp:1423
SmoothTranslator< v3f > pos_translator
Definition content_cao.h:115
scene::ISceneNode * getSceneNode() const override
Definition content_cao.cpp:387
std::string m_previous_texture_modifier
Definition content_cao.h:156
bool getCollisionBox(aabb3f *toset) const override
Definition content_cao.cpp:268
ItemGroupList m_armor_groups
Definition content_cao.h:153
void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible) override
Definition content_cao.cpp:423
bool m_force_visible
Definition content_cao.h:151
void step(float dtime, ClientEnvironment *env) override
Definition content_cao.cpp:984
bool m_local_player_animation
For the local player CAO, animations may be overridden by the client based on the in-game state of th...
Definition content_cao.h:135
v3f m_velocity
Definition content_cao.h:111
ClientActiveObject * getParent() const override
Definition content_cao.cpp:517
bool visualExpiryRequired(const ObjectProperties &newprops) const
Definition content_cao.cpp:1473
WieldMeshSceneNode * m_wield_meshnode
Definition content_cao.h:96
~GenericCAO()
Definition content_cao.cpp:336
std::vector< std::pair< std::string, scene::TrackAnimSpec > > deferred_set_animation_cmds
Deferred set animation commands, to be run once the scene node exists.
Definition content_cao.h:137
float m_anim_timer
Definition content_cao.h:127
virtual bool getSelectionBox(aabb3f *toset) const override
Definition content_cao.cpp:341
scene::IBillboardSceneNode * m_spritenode
Definition content_cao.h:97
bool m_visuals_expired
Definition content_cao.h:101
void updateNodePos()
Definition content_cao.cpp:964
Nametag * m_nametag
Definition content_cao.h:99
const v3f & getRotation() const
Definition content_cao.h:196
void updateAnimation(u16 track_nr)
Definition content_cao.cpp:1380
core::matrix4 & getPosRotMatrix()
Definition content_cao.h:215
int m_anim_num_frames
Definition content_cao.h:125
ActiveObjectType getType() const override
Definition content_cao.h:174
Client * m_client
Definition content_cao.h:90
void updateTextureAnim()
Definition content_cao.cpp:1206
bool m_attached_to_local
Definition content_cao.h:150
bool collideWithObjects() const override
Definition content_cao.cpp:285
void updateMarker()
Definition content_cao.cpp:912
std::vector< MeshAnimationInfo > m_meshnode_animation
Definition content_cao.h:104
std::optional< u16 > resolveTrackId(const scene::TrackId &id)
Definition content_cao.cpp:1511
f32 getStepHeight() const
Definition content_cao.h:228
std::string m_name
Definition content_cao.h:83
ObjectProperties m_prop
Definition content_cao.h:87
GenericCAO(Client *client, ClientEnvironment *env)
Definition content_cao.cpp:258
scene::AnimatedMeshSceneNode * m_animated_meshnode
Definition content_cao.h:95
bool m_is_visible
Definition content_cao.h:103
bool isPlayer() const
Definition content_cao.h:238
Definition texturesource.h:45
Definition wieldmesh.h:113
#define BS
Definition constants.h:61
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
std::unordered_map< std::string, int > ItemGroupList
Definition itemgroup.h:10
ServerActiveObject::object_t object_t
Definition l_object.cpp:32
LocalPlayerAnimation
Definition localplayer.h:22
Definition activeobjectmgr.cpp:11
Definition camera.h:24
Definition inventory.h:21
Definition content_cao.h:68
int frame
index of mesh buffer
Definition content_cao.h:70
TileLayer tile
last animation frame
Definition content_cao.h:71
u32 i
Definition content_cao.h:69
Definition minimap.h:53
Definition camera.h:31
Definition object_properties.h:39
Definition content_cao.h:59
void translate(f32 dtime)
Definition content_cao.cpp:95
Definition content_cao.h:64
void translate(f32 dtime)
Definition content_cao.cpp:113
Definition content_cao.h:40
void translate(f32 dtime)
Definition content_cao.cpp:81
void update(T new_target, bool is_end_position=false, float update_interval=-1)
Definition content_cao.cpp:64
T val_target
Definition content_cao.h:43
T val_current
Definition content_cao.h:42
f32 anim_time_counter
Definition content_cao.h:45
T val_old
Definition content_cao.h:41
f32 anim_time
Definition content_cao.h:44
bool aim_is_end
Definition content_cao.h:46
SmoothTranslator()=default
void init(T current)
Definition content_cao.cpp:53
Defines a layer of a tile.
Definition tile.h:75