Luanti 5.11.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 <map>
9#include "clientobject.h"
10#include "object_properties.h"
11#include "itemgroup.h"
12#include "constants.h"
13#include <cassert>
14#include <memory>
15
16class Camera;
17class Client;
18struct Nametag;
19struct MinimapMarker;
20
21/*
22 SmoothTranslator
23*/
24
25template<typename T>
27{
31 f32 anim_time = 0;
33 bool aim_is_end = true;
34
35 SmoothTranslator() = default;
36
37 void init(T current);
38
39 void update(T new_target, bool is_end_position = false,
40 float update_interval = -1);
41
42 void translate(f32 dtime);
43};
44
46{
47 void translate(f32 dtime);
48};
49
51{
52 void translate(f32 dtime);
53};
54
56{
57private:
58 // Only set at initialization
59 std::string m_name = "";
60 bool m_is_player = false;
61 bool m_is_local_player = false;
62 // Property-ish things
64 //
65 scene::ISceneManager *m_smgr = nullptr;
66 Client *m_client = nullptr;
67 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
68 scene::IMeshSceneNode *m_meshnode = nullptr;
69 scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
71 scene::IBillboardSceneNode *m_spritenode = nullptr;
72 scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
73 Nametag *m_nametag = nullptr;
75 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
79 u16 m_hp = 1;
82 // Spritesheet/animation stuff
88 float m_animation_speed = 15.0f;
89 float m_animation_blend = 0.0f;
90 bool m_animation_loop = true;
91 // stores position and rotation for each bone name
93
95 std::unordered_set<object_t> m_attachment_child_ids;
96 std::string m_attachment_bone = "";
99 bool m_attached_to_local = false;
100 bool m_force_visible = false;
101
104 float m_anim_framelength = 0.2f;
105 float m_anim_timer = 0.0f;
108 // stores texture modifier before punch update
110 // last applied texture modifier
112 bool m_visuals_expired = false;
114 video::SColor m_last_light = video::SColor(0xFFFFFFFF);
115 bool m_is_visible = false;
116 // Material
117 video::E_MATERIAL_TYPE m_material_type;
119
120 bool visualExpiryRequired(const ObjectProperties &newprops) const;
121
122public:
124
125 ~GenericCAO();
126
127 static std::unique_ptr<ClientActiveObject> create(Client *client, ClientEnvironment *env)
128 {
129 return std::make_unique<GenericCAO>(client, env);
130 }
131
132 inline ActiveObjectType getType() const override
133 {
135 }
136 inline const ItemGroupList &getGroups() const
137 {
138 return m_armor_groups;
139 }
140 void initialize(const std::string &data) override;
141
142 void processInitData(const std::string &data);
143
144 bool getCollisionBox(aabb3f *toset) const override;
145
146 bool collideWithObjects() const override;
147
148 virtual bool getSelectionBox(aabb3f *toset) const override;
149
150 const v3f getPosition() const override final;
151
152 const v3f getVelocity() const override final { return m_velocity; }
153
154 inline const v3f &getRotation() const { return m_rotation; }
155
156 bool isImmortal() const;
157
158 inline const ObjectProperties &getProperties() const { return m_prop; }
159
160 inline const std::string &getName() const { return m_name; }
161
162 scene::ISceneNode *getSceneNode() const override;
163
164 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const override;
165
166 // m_matrixnode controls the position and rotation of the child node
167 // for all scene nodes, as a workaround for an Irrlicht problem with
168 // rotations. The child node's position can't be used because it's
169 // rotated, and must remain as 0.
170 // Note that m_matrixnode.setPosition() shouldn't be called. Use
171 // m_matrixnode->getRelativeTransformationMatrix().setTranslation()
172 // instead (aka getPosRotMatrix().setTranslation()).
173 inline core::matrix4 &getPosRotMatrix()
174 {
175 assert(m_matrixnode);
176 return m_matrixnode->getRelativeTransformationMatrix();
177 }
178
179 inline const core::matrix4 *getAbsolutePosRotMatrix() const
180 {
181 if (!m_matrixnode)
182 return nullptr;
183 return &m_matrixnode->getAbsoluteTransformation();
184 }
185
186 inline f32 getStepHeight() const
187 {
188 return m_prop.stepheight;
189 }
190
191 inline bool isLocalPlayer() const override
192 {
193 return m_is_local_player;
194 }
195
196 inline bool isPlayer() const
197 {
198 return m_is_player;
199 }
200
201 inline bool isVisible() const
202 {
203 return m_is_visible;
204 }
205
206 inline void setVisible(bool toset)
207 {
208 m_is_visible = toset;
209 }
210
211 void setChildrenVisible(bool toset);
212 void setAttachment(object_t parent_id, const std::string &bone, v3f position,
213 v3f rotation, bool force_visible) override;
214 void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
215 v3f *rotation, bool *force_visible) const override;
216 void clearChildAttachments() override;
217 void addAttachmentChild(object_t child_id) override;
218 void removeAttachmentChild(object_t child_id) override;
219 ClientActiveObject *getParent() const override;
220 const std::unordered_set<object_t> &getAttachmentChildIds() const override
221 { return m_attachment_child_ids; }
222 void updateAttachments() override;
223
224 void removeFromScene(bool permanent) override;
225
226 void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override;
227
228 inline void expireVisuals()
229 {
230 m_visuals_expired = true;
231 }
232
233 void updateLight(u32 day_night_ratio) override;
234
235 void setNodeLight(const video::SColor &light);
236
237 /* Get light position(s).
238 * returns number of positions written into pos[], which must have space
239 * for at least 3 vectors. */
240 u16 getLightPosition(v3s16 *pos);
241
242 void updateNametag();
243
244 void updateMarker();
245
246 void updateNodePos();
247
248 void step(float dtime, ClientEnvironment *env) override;
249
250 void updateTexturePos();
251
252 // ffs this HAS TO BE a string copy! See #5739 if you think otherwise
253 // Reason: updateTextures(m_previous_texture_modifier);
254 void updateTextures(std::string mod);
255
256 void updateAnimation();
257
259
260 void updateBones(f32 dtime);
261
262 void processMessage(const std::string &data) override;
263
264 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
265 float time_from_last_punch=1000000) override;
266
267 std::string debugInfoText() override;
268
269 std::string infoText() override
270 {
271 return m_prop.infotext;
272 }
273
274 void updateMeshCulling();
275};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:134
ActiveObjectType
Definition activeobject.h:14
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:28
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:191
u16 object_t
Definition activeobject.h:143
Definition camera.h:68
Definition clientobject.h:30
Definition clientenvironment.h:54
Definition client.h:105
Definition content_cao.h:56
v2f m_tx_size
Definition content_cao.h:83
scene::IMeshSceneNode * m_meshnode
Definition content_cao.h:68
v3f m_attachment_rotation
Definition content_cao.h:98
f32 m_material_type_param
Definition content_cao.h:118
void processInitData(const std::string &data)
Definition content_cao.cpp:354
void updateBones(f32 dtime)
Definition content_cao.cpp:1454
int m_anim_frame
Definition content_cao.h:102
aabb3f m_selection_box
Definition content_cao.h:67
void updateAnimationSpeed()
Definition content_cao.cpp:1446
v3f m_acceleration
Definition content_cao.h:77
std::string m_current_texture_modifier
Definition content_cao.h:111
void updateNametag()
Definition content_cao.cpp:939
void processMessage(const std::string &data) override
Definition content_cao.cpp:1596
void initialize(const std::string &data) override
Definition content_cao.cpp:349
object_t m_attachment_parent_id
Definition content_cao.h:94
MinimapMarker * m_marker
Definition content_cao.h:74
void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override
Definition content_cao.cpp:587
void clearChildAttachments() override
Definition content_cao.cpp:510
BoneOverrideMap m_bone_override
Definition content_cao.h:92
bool m_is_local_player
Definition content_cao.h:61
bool m_is_player
Definition content_cao.h:60
void addAttachmentChild(object_t child_id) override
Definition content_cao.cpp:523
void setNodeLight(const video::SColor &light)
Definition content_cao.cpp:890
scene::IDummyTransformationSceneNode * m_matrixnode
Definition content_cao.h:72
bool isVisible() const
Definition content_cao.h:201
bool isImmortal() const
Definition content_cao.cpp:424
u16 m_hp
Definition content_cao.h:79
void expireVisuals()
Definition content_cao.h:228
const v3f getPosition() const override final
Definition content_cao.cpp:409
void updateLight(u32 day_night_ratio) override
Definition content_cao.cpp:849
const ObjectProperties & getProperties() const
Definition content_cao.h:158
std::string m_attachment_bone
Definition content_cao.h:96
v3f m_position
Definition content_cao.h:75
bool m_animation_loop
Definition content_cao.h:90
void setVisible(bool toset)
Definition content_cao.h:206
void updateMeshCulling()
Definition content_cao.cpp:1966
std::unordered_set< object_t > m_attachment_child_ids
Definition content_cao.h:95
v2s16 m_tx_basepos
Definition content_cao.h:84
v3f m_attachment_position
Definition content_cao.h:97
bool isLocalPlayer() const override
Definition content_cao.h:191
float m_step_distance_counter
Definition content_cao.h:113
void removeAttachmentChild(object_t child_id) override
Definition content_cao.cpp:528
const std::string & getName() const
Definition content_cao.h:160
const core::matrix4 * getAbsolutePosRotMatrix() const
Definition content_cao.h:179
float m_anim_framelength
Definition content_cao.h:104
video::SColor m_last_light
Definition content_cao.h:114
void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const override
Definition content_cao.cpp:500
float m_reset_textures_timer
Definition content_cao.h:107
video::E_MATERIAL_TYPE m_material_type
Definition content_cao.h:117
const v3f getVelocity() const override final
Definition content_cao.h:152
const std::unordered_set< object_t > & getAttachmentChildIds() const override
Definition content_cao.h:220
std::string debugInfoText() override
Definition content_cao.cpp:1952
v2f m_animation_range
Definition content_cao.h:87
scene::ISceneManager * m_smgr
Definition content_cao.h:65
v3f m_rotation
Definition content_cao.h:78
void setChildrenVisible(bool toset)
Definition content_cao.cpp:454
void removeFromScene(bool permanent) override
Definition content_cao.cpp:539
const ItemGroupList & getGroups() const
Definition content_cao.h:136
void updateTexturePos()
Definition content_cao.cpp:1230
SmoothTranslatorWrappedv3f rot_translator
Definition content_cao.h:81
u16 getLightPosition(v3s16 *pos)
Definition content_cao.cpp:906
static std::unique_ptr< ClientActiveObject > create(Client *client, ClientEnvironment *env)
Definition content_cao.h:127
bool m_tx_select_horiz_by_yawpitch
Definition content_cao.h:86
void updateTextures(std::string mod)
Definition content_cao.cpp:1300
std::string infoText() override
Definition content_cao.h:269
bool m_initial_tx_basepos_set
Definition content_cao.h:85
void updateAttachments() override
Definition content_cao.cpp:1520
SmoothTranslator< v3f > pos_translator
Definition content_cao.h:80
scene::ISceneNode * getSceneNode() const override
Definition content_cao.cpp:429
std::string m_previous_texture_modifier
Definition content_cao.h:109
bool getCollisionBox(aabb3f *toset) const override
Definition content_cao.cpp:327
ItemGroupList m_armor_groups
Definition content_cao.h:106
void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible) override
Definition content_cao.cpp:465
bool m_force_visible
Definition content_cao.h:100
void step(float dtime, ClientEnvironment *env) override
Definition content_cao.cpp:992
v3f m_velocity
Definition content_cao.h:76
ClientActiveObject * getParent() const override
Definition content_cao.cpp:533
bool visualExpiryRequired(const ObjectProperties &newprops) const
Definition content_cao.cpp:1570
WieldMeshSceneNode * m_wield_meshnode
Definition content_cao.h:70
~GenericCAO()
Definition content_cao.cpp:395
void updateAnimation()
Definition content_cao.cpp:1432
float m_animation_speed
Definition content_cao.h:88
float m_anim_timer
Definition content_cao.h:105
virtual bool getSelectionBox(aabb3f *toset) const override
Definition content_cao.cpp:400
scene::IBillboardSceneNode * m_spritenode
Definition content_cao.h:71
bool m_visuals_expired
Definition content_cao.h:112
void updateNodePos()
Definition content_cao.cpp:973
Nametag * m_nametag
Definition content_cao.h:73
const v3f & getRotation() const
Definition content_cao.h:154
core::matrix4 & getPosRotMatrix()
Definition content_cao.h:173
int m_anim_num_frames
Definition content_cao.h:103
ActiveObjectType getType() const override
Definition content_cao.h:132
Client * m_client
Definition content_cao.h:66
bool m_attached_to_local
Definition content_cao.h:99
float m_animation_blend
Definition content_cao.h:89
scene::IAnimatedMeshSceneNode * m_animated_meshnode
Definition content_cao.h:69
bool collideWithObjects() const override
Definition content_cao.cpp:344
void updateMarker()
Definition content_cao.cpp:919
f32 getStepHeight() const
Definition content_cao.h:186
std::string m_name
Definition content_cao.h:59
ObjectProperties m_prop
Definition content_cao.h:63
GenericCAO(Client *client, ClientEnvironment *env)
Definition content_cao.cpp:317
scene::IAnimatedMeshSceneNode * getAnimatedMeshSceneNode() const override
Definition content_cao.cpp:449
bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL, float time_from_last_punch=1000000) override
Definition content_cao.cpp:1912
bool m_is_visible
Definition content_cao.h:115
bool isPlayer() const
Definition content_cao.h:196
Definition texturesource.h:36
Definition wieldmesh.h:90
#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 inventory.h:19
Definition minimap.h:37
Definition camera.h:25
Definition object_properties.h:15
std::string infotext
Definition object_properties.h:28
f32 stepheight
Definition object_properties.h:36
Definition content_cao.h:46
void translate(f32 dtime)
Definition content_cao.cpp:85
Definition content_cao.h:51
void translate(f32 dtime)
Definition content_cao.cpp:103
Definition content_cao.h:27
void translate(f32 dtime)
Definition content_cao.cpp:71
void update(T new_target, bool is_end_position=false, float update_interval=-1)
Definition content_cao.cpp:54
T val_target
Definition content_cao.h:30
T val_current
Definition content_cao.h:29
f32 anim_time_counter
Definition content_cao.h:32
T val_old
Definition content_cao.h:28
f32 anim_time
Definition content_cao.h:31
bool aim_is_end
Definition content_cao.h:33
SmoothTranslator()=default
void init(T current)
Definition content_cao.cpp:43