Luanti 5.10.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 // Settings
120 bool m_enable_shaders = false;
121
122 bool visualExpiryRequired(const ObjectProperties &newprops) const;
123
124public:
126
127 ~GenericCAO();
128
129 static std::unique_ptr<ClientActiveObject> create(Client *client, ClientEnvironment *env)
130 {
131 return std::make_unique<GenericCAO>(client, env);
132 }
133
134 inline ActiveObjectType getType() const override
135 {
137 }
138 inline const ItemGroupList &getGroups() const
139 {
140 return m_armor_groups;
141 }
142 void initialize(const std::string &data) override;
143
144 void processInitData(const std::string &data);
145
146 bool getCollisionBox(aabb3f *toset) const override;
147
148 bool collideWithObjects() const override;
149
150 virtual bool getSelectionBox(aabb3f *toset) const override;
151
152 const v3f getPosition() const override final;
153
154 const v3f getVelocity() const override final { return m_velocity; }
155
156 inline const v3f &getRotation() const { return m_rotation; }
157
158 bool isImmortal() const;
159
160 inline const ObjectProperties &getProperties() const { return m_prop; }
161
162 inline const std::string &getName() const { return m_name; }
163
164 scene::ISceneNode *getSceneNode() const override;
165
166 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const override;
167
168 // m_matrixnode controls the position and rotation of the child node
169 // for all scene nodes, as a workaround for an Irrlicht problem with
170 // rotations. The child node's position can't be used because it's
171 // rotated, and must remain as 0.
172 // Note that m_matrixnode.setPosition() shouldn't be called. Use
173 // m_matrixnode->getRelativeTransformationMatrix().setTranslation()
174 // instead (aka getPosRotMatrix().setTranslation()).
175 inline core::matrix4 &getPosRotMatrix()
176 {
177 assert(m_matrixnode);
178 return m_matrixnode->getRelativeTransformationMatrix();
179 }
180
181 inline const core::matrix4 *getAbsolutePosRotMatrix() const
182 {
183 if (!m_matrixnode)
184 return nullptr;
185 return &m_matrixnode->getAbsoluteTransformation();
186 }
187
188 inline f32 getStepHeight() const
189 {
190 return m_prop.stepheight;
191 }
192
193 inline bool isLocalPlayer() const override
194 {
195 return m_is_local_player;
196 }
197
198 inline bool isPlayer() const
199 {
200 return m_is_player;
201 }
202
203 inline bool isVisible() const
204 {
205 return m_is_visible;
206 }
207
208 inline void setVisible(bool toset)
209 {
210 m_is_visible = toset;
211 }
212
213 void setChildrenVisible(bool toset);
214 void setAttachment(object_t parent_id, const std::string &bone, v3f position,
215 v3f rotation, bool force_visible) override;
216 void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
217 v3f *rotation, bool *force_visible) const override;
218 void clearChildAttachments() override;
219 void addAttachmentChild(object_t child_id) override;
220 void removeAttachmentChild(object_t child_id) override;
221 ClientActiveObject *getParent() const override;
222 const std::unordered_set<object_t> &getAttachmentChildIds() const override
223 { return m_attachment_child_ids; }
224 void updateAttachments() override;
225
226 void removeFromScene(bool permanent) override;
227
228 void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override;
229
230 inline void expireVisuals()
231 {
232 m_visuals_expired = true;
233 }
234
235 void updateLight(u32 day_night_ratio) override;
236
237 void setNodeLight(const video::SColor &light);
238
239 /* Get light position(s).
240 * returns number of positions written into pos[], which must have space
241 * for at least 3 vectors. */
242 u16 getLightPosition(v3s16 *pos);
243
244 void updateNametag();
245
246 void updateMarker();
247
248 void updateNodePos();
249
250 void step(float dtime, ClientEnvironment *env) override;
251
252 void updateTexturePos();
253
254 // ffs this HAS TO BE a string copy! See #5739 if you think otherwise
255 // Reason: updateTextures(m_previous_texture_modifier);
256 void updateTextures(std::string mod);
257
258 void updateAnimation();
259
261
262 void updateBones(f32 dtime);
263
264 void processMessage(const std::string &data) override;
265
266 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
267 float time_from_last_punch=1000000) override;
268
269 std::string debugInfoText() override;
270
271 std::string infoText() override
272 {
273 return m_prop.infotext;
274 }
275
276 void updateMeshCulling();
277};
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:356
void updateBones(f32 dtime)
Definition content_cao.cpp:1479
int m_anim_frame
Definition content_cao.h:102
aabb3f m_selection_box
Definition content_cao.h:67
void updateAnimationSpeed()
Definition content_cao.cpp:1471
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:963
void processMessage(const std::string &data) override
Definition content_cao.cpp:1621
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:589
void clearChildAttachments() override
Definition content_cao.cpp:512
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:525
void setNodeLight(const video::SColor &light)
Definition content_cao.cpp:906
scene::IDummyTransformationSceneNode * m_matrixnode
Definition content_cao.h:72
bool isVisible() const
Definition content_cao.h:203
bool isImmortal() const
Definition content_cao.cpp:426
u16 m_hp
Definition content_cao.h:79
void expireVisuals()
Definition content_cao.h:230
const v3f getPosition() const override final
Definition content_cao.cpp:411
void updateLight(u32 day_night_ratio) override
Definition content_cao.cpp:862
const ObjectProperties & getProperties() const
Definition content_cao.h:160
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:208
void updateMeshCulling()
Definition content_cao.cpp:1991
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:193
float m_step_distance_counter
Definition content_cao.h:113
void removeAttachmentChild(object_t child_id) override
Definition content_cao.cpp:530
const std::string & getName() const
Definition content_cao.h:162
const core::matrix4 * getAbsolutePosRotMatrix() const
Definition content_cao.h:181
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:502
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:154
const std::unordered_set< object_t > & getAttachmentChildIds() const override
Definition content_cao.h:222
std::string debugInfoText() override
Definition content_cao.cpp:1977
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:456
void removeFromScene(bool permanent) override
Definition content_cao.cpp:541
const ItemGroupList & getGroups() const
Definition content_cao.h:138
void updateTexturePos()
Definition content_cao.cpp:1255
SmoothTranslatorWrappedv3f rot_translator
Definition content_cao.h:81
u16 getLightPosition(v3s16 *pos)
Definition content_cao.cpp:930
static std::unique_ptr< ClientActiveObject > create(Client *client, ClientEnvironment *env)
Definition content_cao.h:129
bool m_tx_select_horiz_by_yawpitch
Definition content_cao.h:86
void updateTextures(std::string mod)
Definition content_cao.cpp:1325
std::string infoText() override
Definition content_cao.h:271
bool m_initial_tx_basepos_set
Definition content_cao.h:85
bool m_enable_shaders
Definition content_cao.h:120
void updateAttachments() override
Definition content_cao.cpp:1545
SmoothTranslator< v3f > pos_translator
Definition content_cao.h:80
scene::ISceneNode * getSceneNode() const override
Definition content_cao.cpp:431
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:467
bool m_force_visible
Definition content_cao.h:100
void step(float dtime, ClientEnvironment *env) override
Definition content_cao.cpp:1016
v3f m_velocity
Definition content_cao.h:76
ClientActiveObject * getParent() const override
Definition content_cao.cpp:535
bool visualExpiryRequired(const ObjectProperties &newprops) const
Definition content_cao.cpp:1595
WieldMeshSceneNode * m_wield_meshnode
Definition content_cao.h:70
~GenericCAO()
Definition content_cao.cpp:397
void updateAnimation()
Definition content_cao.cpp:1457
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:402
scene::IBillboardSceneNode * m_spritenode
Definition content_cao.h:71
bool m_visuals_expired
Definition content_cao.h:112
void updateNodePos()
Definition content_cao.cpp:997
Nametag * m_nametag
Definition content_cao.h:73
const v3f & getRotation() const
Definition content_cao.h:156
core::matrix4 & getPosRotMatrix()
Definition content_cao.h:175
int m_anim_num_frames
Definition content_cao.h:103
ActiveObjectType getType() const override
Definition content_cao.h:134
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:943
f32 getStepHeight() const
Definition content_cao.h:188
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:451
bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL, float time_from_last_punch=1000000) override
Definition content_cao.cpp:1937
bool m_is_visible
Definition content_cao.h:115
bool isPlayer() const
Definition content_cao.h:198
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