Luanti 5.15.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 "EMaterialTypes.h"
8#include "IDummyTransformationSceneNode.h"
9#include "irrlichttypes.h"
10
11#include "object_properties.h"
12#include "clientobject.h"
13#include "constants.h"
14#include "itemgroup.h"
15#include "client/tile.h"
16#include <cassert>
17#include <memory>
18
19namespace scene {
20 class IMeshSceneNode;
21 class IBillboardSceneNode;
22 class AnimatedMeshSceneNode;
23}
24
25class Client;
26struct Nametag;
27struct MinimapMarker;
29
30/*
31 SmoothTranslator and other helpers
32*/
33
34template<typename T>
36{
40 f32 anim_time = 0;
42 bool aim_is_end = true;
43
44 SmoothTranslator() = default;
45
46 void init(T current);
47
48 void update(T new_target, bool is_end_position = false,
49 float update_interval = -1);
50
51 void translate(f32 dtime);
52};
53
55{
56 void translate(f32 dtime);
57};
58
60{
61 void translate(f32 dtime);
62};
63
69
70/*
71 GenericCAO
72*/
73
75{
76private:
77
78 // Only set at initialization
79 std::string m_name = "";
80 bool m_is_player = false;
81 bool m_is_local_player = false;
82 // Property-ish things
84 //
85 scene::ISceneManager *m_smgr = nullptr;
86 Client *m_client = nullptr;
87 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
88
89 // Visuals
90 scene::IMeshSceneNode *m_meshnode = nullptr;
91 scene::AnimatedMeshSceneNode *m_animated_meshnode = nullptr;
93 scene::IBillboardSceneNode *m_spritenode = nullptr;
94 scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
95 Nametag *m_nametag = nullptr;
97 bool m_visuals_expired = false;
98 video::SColor m_last_light = video::SColor(0xFFFFFFFF);
99 bool m_is_visible = false;
100 std::vector<MeshAnimationInfo> m_meshnode_animation;
101
102 // Material
103 video::E_MATERIAL_TYPE m_material_type = video::EMT_INVALID;
104
105 // Movement
106 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
110 u16 m_hp = 1;
113
114 // Spritesheet stuff
119 bool m_animation_loop = true;
121 float m_animation_speed = 15.0f;
122 float m_animation_blend = 0.0f;
125 float m_anim_framelength = 0.2f;
126 float m_anim_timer = 0.0f;
127
128 // stores position and rotation for each bone name
130
131 // Attachments
133 std::unordered_set<object_t> m_attachment_child_ids;
134 std::string m_attachment_bone = "";
138 bool m_force_visible = false;
139
142 // stores texture modifier before punch update
144 // last applied texture modifier
147
148 bool visualExpiryRequired(const ObjectProperties &newprops) const;
149
150public:
151
153
154 ~GenericCAO();
155
156 static std::unique_ptr<ClientActiveObject> create(Client *client, ClientEnvironment *env)
157 {
158 return std::make_unique<GenericCAO>(client, env);
159 }
160
161 inline ActiveObjectType getType() const override
162 {
164 }
165 inline const ItemGroupList &getGroups() const
166 {
167 return m_armor_groups;
168 }
169 void initialize(const std::string &data) override;
170
171 void processInitData(const std::string &data);
172
173 bool getCollisionBox(aabb3f *toset) const override;
174
175 bool collideWithObjects() const override;
176
177 virtual bool getSelectionBox(aabb3f *toset) const override;
178
179 const v3f getPosition() const override final;
180
181 const v3f getVelocity() const override final { return m_velocity; }
182
183 inline const v3f &getRotation() const { return m_rotation; }
184
185 bool isImmortal() const;
186
187 inline const ObjectProperties &getProperties() const { return m_prop; }
188
189 inline const std::string &getName() const { return m_name; }
190
191 scene::ISceneNode *getSceneNode() const override;
192
193 scene::AnimatedMeshSceneNode *getAnimatedMeshSceneNode() const override;
194
195 // m_matrixnode controls the position and rotation of the child node
196 // for all scene nodes, as a workaround for an Irrlicht problem with
197 // rotations. The child node's position can't be used because it's
198 // rotated, and must remain as 0.
199 // Note that m_matrixnode.setPosition() shouldn't be called. Use
200 // m_matrixnode->getRelativeTransformationMatrix().setTranslation()
201 // instead (aka getPosRotMatrix().setTranslation()).
202 inline core::matrix4 &getPosRotMatrix()
203 {
204 assert(m_matrixnode);
205 return m_matrixnode->getRelativeTransformationMatrix();
206 }
207
208 inline const core::matrix4 *getAbsolutePosRotMatrix() const
209 {
210 if (!m_matrixnode)
211 return nullptr;
212 return &m_matrixnode->getAbsoluteTransformation();
213 }
214
215 inline f32 getStepHeight() const
216 {
217 return m_prop.stepheight;
218 }
219
220 inline bool isLocalPlayer() const override
221 {
222 return m_is_local_player;
223 }
224
225 inline bool isPlayer() const
226 {
227 return m_is_player;
228 }
229
230 inline bool isVisible() const
231 {
232 return m_is_visible;
233 }
234
235 inline void setVisible(bool toset)
236 {
237 m_is_visible = toset;
238 }
239
240 void setChildrenVisible(bool toset);
241 void setAttachment(object_t parent_id, const std::string &bone, v3f position,
242 v3f rotation, bool force_visible) override;
243 void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
244 v3f *rotation, bool *force_visible) const override;
245 void clearChildAttachments() override;
246 void addAttachmentChild(object_t child_id) override;
247 void removeAttachmentChild(object_t child_id) override;
248 ClientActiveObject *getParent() const override;
249 const std::unordered_set<object_t> &getAttachmentChildIds() const override
250 { return m_attachment_child_ids; }
251 void updateAttachments() override;
252
253 void removeFromScene(bool permanent) override;
254
255 void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override;
256
257 inline void expireVisuals()
258 {
259 m_visuals_expired = true;
260 }
261
262 void updateLight(u32 day_night_ratio) override;
263
264 void setNodeLight(const video::SColor &light);
265
266 /* Get light position(s).
267 * returns number of positions written into pos[], which must have space
268 * for at least 3 vectors. */
269 u16 getLightPosition(v3s16 *pos);
270
271 void updateNametag();
272
273 void updateMarker();
274
275 void updateNodePos();
276
277 void step(float dtime, ClientEnvironment *env) override;
278
279 void updateTextureAnim();
280
281 // ffs this HAS TO BE a string copy! See #5739 if you think otherwise
282 // Reason: updateTextures(m_previous_texture_modifier);
283 void updateTextures(std::string mod);
284
285 void updateAnimation();
286
288
289 void processMessage(const std::string &data) override;
290
291 bool directReportPunch(v3f dir, const ItemStack *punchitem,
292 const ItemStack *hand_item, float time_from_last_punch=1000000) override;
293
294 std::string debugInfoText() override;
295
296 std::string infoText() override
297 {
298 return m_prop.infotext;
299 }
300
301 void updateMeshCulling();
302
303private:
304
306 void updateParentChain() const;
307
308};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:142
ActiveObjectType
Definition activeobject.h:14
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:28
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:207
Definition clientobject.h:27
Definition clientenvironment.h:54
Definition client.h:106
Definition content_cao.h:75
v2f m_tx_size
Definition content_cao.h:115
scene::IMeshSceneNode * m_meshnode
Definition content_cao.h:90
v3f m_attachment_rotation
Definition content_cao.h:136
void processInitData(const std::string &data)
Definition content_cao.cpp:290
void updateParentChain() const
Update the parent chain so getPosition() returns an up to date position.
Definition content_cao.cpp:345
int m_anim_frame
Definition content_cao.h:123
aabb3f m_selection_box
Definition content_cao.h:87
void updateAnimationSpeed()
Definition content_cao.cpp:1399
v3f m_acceleration
Definition content_cao.h:108
std::string m_current_texture_modifier
Definition content_cao.h:145
void updateNametag()
Definition content_cao.cpp:933
void processMessage(const std::string &data) override
Definition content_cao.cpp:1484
void initialize(const std::string &data) override
Definition content_cao.cpp:285
object_t m_attachment_parent_id
Definition content_cao.h:132
MinimapMarker * m_marker
Definition content_cao.h:96
void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override
Definition content_cao.cpp:568
void clearChildAttachments() override
Definition content_cao.cpp:489
BoneOverrideMap m_bone_override
Definition content_cao.h:129
bool m_is_local_player
Definition content_cao.h:81
bool m_is_player
Definition content_cao.h:80
void addAttachmentChild(object_t child_id) override
Definition content_cao.cpp:502
void setNodeLight(const video::SColor &light)
Definition content_cao.cpp:883
scene::IDummyTransformationSceneNode * m_matrixnode
Definition content_cao.h:94
bool isVisible() const
Definition content_cao.h:230
bool isImmortal() const
Definition content_cao.cpp:377
scene::AnimatedMeshSceneNode * getAnimatedMeshSceneNode() const override
Definition content_cao.cpp:402
u16 m_hp
Definition content_cao.h:110
void expireVisuals()
Definition content_cao.h:257
const v3f getPosition() const override final
Definition content_cao.cpp:357
void updateLight(u32 day_night_ratio) override
Definition content_cao.cpp:843
const ObjectProperties & getProperties() const
Definition content_cao.h:187
std::string m_attachment_bone
Definition content_cao.h:134
v3f m_position
Definition content_cao.h:106
bool m_animation_loop
Definition content_cao.h:119
void setVisible(bool toset)
Definition content_cao.h:235
void updateMeshCulling()
Definition content_cao.cpp:1844
std::unordered_set< object_t > m_attachment_child_ids
Definition content_cao.h:133
v2s16 m_tx_basepos
Definition content_cao.h:116
v3f m_attachment_position
Definition content_cao.h:135
bool isLocalPlayer() const override
Definition content_cao.h:220
float m_step_distance_counter
Definition content_cao.h:146
void removeAttachmentChild(object_t child_id) override
Definition content_cao.cpp:507
const std::string & getName() const
Definition content_cao.h:189
const core::matrix4 * getAbsolutePosRotMatrix() const
Definition content_cao.h:208
float m_anim_framelength
Definition content_cao.h:125
video::SColor m_last_light
Definition content_cao.h:98
void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const override
Definition content_cao.cpp:479
float m_reset_textures_timer
Definition content_cao.h:141
video::E_MATERIAL_TYPE m_material_type
Definition content_cao.h:103
const v3f getVelocity() const override final
Definition content_cao.h:181
const std::unordered_set< object_t > & getAttachmentChildIds() const override
Definition content_cao.h:249
bool directReportPunch(v3f dir, const ItemStack *punchitem, const ItemStack *hand_item, float time_from_last_punch=1000000) override
Definition content_cao.cpp:1790
std::string debugInfoText() override
Definition content_cao.cpp:1830
v2f m_animation_range
Definition content_cao.h:120
scene::ISceneManager * m_smgr
Definition content_cao.h:85
v3f m_rotation
Definition content_cao.h:109
void setChildrenVisible(bool toset)
Definition content_cao.cpp:407
void removeFromScene(bool permanent) override
Definition content_cao.cpp:518
const ItemGroupList & getGroups() const
Definition content_cao.h:165
SmoothTranslatorWrappedv3f rot_translator
Definition content_cao.h:112
u16 getLightPosition(v3s16 *pos)
Definition content_cao.cpp:900
static std::unique_ptr< ClientActiveObject > create(Client *client, ClientEnvironment *env)
Definition content_cao.h:156
bool m_tx_select_horiz_by_yawpitch
Definition content_cao.h:118
void updateTextures(std::string mod)
Definition content_cao.cpp:1298
std::string infoText() override
Definition content_cao.h:296
bool m_initial_tx_basepos_set
Definition content_cao.h:117
void updateAttachments() override
Definition content_cao.cpp:1407
SmoothTranslator< v3f > pos_translator
Definition content_cao.h:111
scene::ISceneNode * getSceneNode() const override
Definition content_cao.cpp:382
std::string m_previous_texture_modifier
Definition content_cao.h:143
bool getCollisionBox(aabb3f *toset) const override
Definition content_cao.cpp:263
ItemGroupList m_armor_groups
Definition content_cao.h:140
void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible) override
Definition content_cao.cpp:418
bool m_force_visible
Definition content_cao.h:138
void step(float dtime, ClientEnvironment *env) override
Definition content_cao.cpp:985
v3f m_velocity
Definition content_cao.h:107
ClientActiveObject * getParent() const override
Definition content_cao.cpp:512
bool visualExpiryRequired(const ObjectProperties &newprops) const
Definition content_cao.cpp:1457
WieldMeshSceneNode * m_wield_meshnode
Definition content_cao.h:92
~GenericCAO()
Definition content_cao.cpp:331
void updateAnimation()
Definition content_cao.cpp:1385
float m_animation_speed
Definition content_cao.h:121
float m_anim_timer
Definition content_cao.h:126
virtual bool getSelectionBox(aabb3f *toset) const override
Definition content_cao.cpp:336
scene::IBillboardSceneNode * m_spritenode
Definition content_cao.h:93
bool m_visuals_expired
Definition content_cao.h:97
void updateNodePos()
Definition content_cao.cpp:965
Nametag * m_nametag
Definition content_cao.h:95
const v3f & getRotation() const
Definition content_cao.h:183
core::matrix4 & getPosRotMatrix()
Definition content_cao.h:202
int m_anim_num_frames
Definition content_cao.h:124
ActiveObjectType getType() const override
Definition content_cao.h:161
Client * m_client
Definition content_cao.h:86
void updateTextureAnim()
Definition content_cao.cpp:1211
bool m_attached_to_local
Definition content_cao.h:137
float m_animation_blend
Definition content_cao.h:122
bool collideWithObjects() const override
Definition content_cao.cpp:280
void updateMarker()
Definition content_cao.cpp:913
std::vector< MeshAnimationInfo > m_meshnode_animation
Definition content_cao.h:100
f32 getStepHeight() const
Definition content_cao.h:215
std::string m_name
Definition content_cao.h:79
ObjectProperties m_prop
Definition content_cao.h:83
GenericCAO(Client *client, ClientEnvironment *env)
Definition content_cao.cpp:253
scene::AnimatedMeshSceneNode * m_animated_meshnode
Definition content_cao.h:91
bool m_is_visible
Definition content_cao.h:99
bool isPlayer() const
Definition content_cao.h:225
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:28
Definition activeobjectmgr.cpp:11
Definition camera.h:24
Definition inventory.h:21
Definition content_cao.h:64
int frame
index of mesh buffer
Definition content_cao.h:66
TileLayer tile
last animation frame
Definition content_cao.h:67
u32 i
Definition content_cao.h:65
Definition minimap.h:53
Definition camera.h:31
Definition object_properties.h:32
std::string infotext
Definition object_properties.h:45
f32 stepheight
Definition object_properties.h:53
Definition content_cao.h:55
void translate(f32 dtime)
Definition content_cao.cpp:90
Definition content_cao.h:60
void translate(f32 dtime)
Definition content_cao.cpp:108
Definition content_cao.h:36
void translate(f32 dtime)
Definition content_cao.cpp:76
void update(T new_target, bool is_end_position=false, float update_interval=-1)
Definition content_cao.cpp:59
T val_target
Definition content_cao.h:39
T val_current
Definition content_cao.h:38
f32 anim_time_counter
Definition content_cao.h:41
T val_old
Definition content_cao.h:37
f32 anim_time
Definition content_cao.h:40
bool aim_is_end
Definition content_cao.h:42
SmoothTranslator()=default
void init(T current)
Definition content_cao.cpp:48
Defines a layer of a tile.
Definition tile.h:75