Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
content_cao.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <map>
24#include "clientobject.h"
25#include "object_properties.h"
26#include "itemgroup.h"
27#include "constants.h"
28#include <cassert>
29#include <memory>
30
31class Camera;
32class Client;
33struct Nametag;
34struct MinimapMarker;
35
36/*
37 SmoothTranslator
38*/
39
40template<typename T>
42{
46 f32 anim_time = 0;
48 bool aim_is_end = true;
49
50 SmoothTranslator() = default;
51
52 void init(T current);
53
54 void update(T new_target, bool is_end_position = false,
55 float update_interval = -1);
56
57 void translate(f32 dtime);
58};
59
61{
62 void translate(f32 dtime);
63};
64
66{
67 void translate(f32 dtime);
68};
69
71{
72private:
73 // Only set at initialization
74 std::string m_name = "";
75 bool m_is_player = false;
76 bool m_is_local_player = false;
77 // Property-ish things
79 //
80 scene::ISceneManager *m_smgr = nullptr;
81 Client *m_client = nullptr;
82 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
83 scene::IMeshSceneNode *m_meshnode = nullptr;
84 scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
86 scene::IBillboardSceneNode *m_spritenode = nullptr;
87 scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
88 Nametag *m_nametag = nullptr;
90 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
94 u16 m_hp = 1;
97 // Spritesheet/animation stuff
103 float m_animation_speed = 15.0f;
104 float m_animation_blend = 0.0f;
105 bool m_animation_loop = true;
106 // stores position and rotation for each bone name
108
110 std::unordered_set<int> m_attachment_child_ids;
111 std::string m_attachment_bone = "";
115 bool m_force_visible = false;
116
119 float m_anim_framelength = 0.2f;
120 float m_anim_timer = 0.0f;
123 // stores texture modifier before punch update
125 // last applied texture modifier
127 bool m_visuals_expired = false;
129 video::SColor m_last_light = video::SColor(0xFFFFFFFF);
130 bool m_is_visible = false;
131 // Material
132 video::E_MATERIAL_TYPE m_material_type;
134 // Settings
135 bool m_enable_shaders = false;
136
137 bool visualExpiryRequired(const ObjectProperties &newprops) const;
138
139public:
141
142 ~GenericCAO();
143
144 static std::unique_ptr<ClientActiveObject> create(Client *client, ClientEnvironment *env)
145 {
146 return std::make_unique<GenericCAO>(client, env);
147 }
148
149 inline ActiveObjectType getType() const override
150 {
152 }
153 inline const ItemGroupList &getGroups() const
154 {
155 return m_armor_groups;
156 }
157 void initialize(const std::string &data) override;
158
159 void processInitData(const std::string &data);
160
161 bool getCollisionBox(aabb3f *toset) const override;
162
163 bool collideWithObjects() const override;
164
165 virtual bool getSelectionBox(aabb3f *toset) const override;
166
167 const v3f getPosition() const override final;
168
169 const v3f getVelocity() const override final { return m_velocity; }
170
171 inline const v3f &getRotation() const { return m_rotation; }
172
173 bool isImmortal() const;
174
175 inline const ObjectProperties &getProperties() const { return m_prop; }
176
177 inline const std::string &getName() const { return m_name; }
178
179 scene::ISceneNode *getSceneNode() const override;
180
181 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const override;
182
183 // m_matrixnode controls the position and rotation of the child node
184 // for all scene nodes, as a workaround for an Irrlicht problem with
185 // rotations. The child node's position can't be used because it's
186 // rotated, and must remain as 0.
187 // Note that m_matrixnode.setPosition() shouldn't be called. Use
188 // m_matrixnode->getRelativeTransformationMatrix().setTranslation()
189 // instead (aka getPosRotMatrix().setTranslation()).
190 inline core::matrix4 &getPosRotMatrix()
191 {
192 assert(m_matrixnode);
193 return m_matrixnode->getRelativeTransformationMatrix();
194 }
195
196 inline const core::matrix4 *getAbsolutePosRotMatrix() const
197 {
198 if (!m_matrixnode)
199 return nullptr;
200 return &m_matrixnode->getAbsoluteTransformation();
201 }
202
203 inline f32 getStepHeight() const
204 {
205 return m_prop.stepheight;
206 }
207
208 inline bool isLocalPlayer() const override
209 {
210 return m_is_local_player;
211 }
212
213 inline bool isPlayer() const
214 {
215 return m_is_player;
216 }
217
218 inline bool isVisible() const
219 {
220 return m_is_visible;
221 }
222
223 inline void setVisible(bool toset)
224 {
225 m_is_visible = toset;
226 }
227
228 void setChildrenVisible(bool toset);
229 void setAttachment(int parent_id, const std::string &bone, v3f position,
230 v3f rotation, bool force_visible) override;
231 void getAttachment(int *parent_id, std::string *bone, v3f *position,
232 v3f *rotation, bool *force_visible) const override;
233 void clearChildAttachments() override;
234 void clearParentAttachment() override;
235 void addAttachmentChild(int child_id) override;
236 void removeAttachmentChild(int child_id) override;
237 ClientActiveObject *getParent() const override;
238 const std::unordered_set<int> &getAttachmentChildIds() const override
239 { return m_attachment_child_ids; }
240 void updateAttachments() override;
241
242 void removeFromScene(bool permanent) override;
243
244 void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override;
245
246 inline void expireVisuals()
247 {
248 m_visuals_expired = true;
249 }
250
251 void updateLight(u32 day_night_ratio) override;
252
253 void setNodeLight(const video::SColor &light);
254
255 /* Get light position(s).
256 * returns number of positions written into pos[], which must have space
257 * for at least 3 vectors. */
258 u16 getLightPosition(v3s16 *pos);
259
260 void updateNametag();
261
262 void updateMarker();
263
264 void updateNodePos();
265
266 void step(float dtime, ClientEnvironment *env) override;
267
268 void updateTexturePos();
269
270 // ffs this HAS TO BE a string copy! See #5739 if you think otherwise
271 // Reason: updateTextures(m_previous_texture_modifier);
272 void updateTextures(std::string mod);
273
274 void updateAnimation();
275
277
278 void updateBones(f32 dtime);
279
280 void processMessage(const std::string &data) override;
281
282 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
283 float time_from_last_punch=1000000) override;
284
285 std::string debugInfoText() override;
286
287 std::string infoText() override
288 {
289 return m_prop.infotext;
290 }
291
292 void updateMeshCulling();
293};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition: activeobject.h:146
ActiveObjectType
Definition: activeobject.h:29
@ ACTIVEOBJECT_TYPE_GENERIC
Definition: activeobject.h:43
static v2f dir(const v2f &pos_dist)
Definition: camera.cpp:204
Definition: camera.h:83
Definition: clientobject.h:38
Definition: clientenvironment.h:67
Definition: client.h:119
Definition: content_cao.h:71
v2f m_tx_size
Definition: content_cao.h:98
scene::IMeshSceneNode * m_meshnode
Definition: content_cao.h:83
v3f m_attachment_rotation
Definition: content_cao.h:113
f32 m_material_type_param
Definition: content_cao.h:133
void processInitData(const std::string &data)
Definition: content_cao.cpp:366
void updateBones(f32 dtime)
Definition: content_cao.cpp:1547
int m_anim_frame
Definition: content_cao.h:117
aabb3f m_selection_box
Definition: content_cao.h:82
v2s32 m_animation_range
Definition: content_cao.h:102
void updateAnimationSpeed()
Definition: content_cao.cpp:1539
v3f m_acceleration
Definition: content_cao.h:92
std::string m_current_texture_modifier
Definition: content_cao.h:126
void updateNametag()
Definition: content_cao.cpp:988
void processMessage(const std::string &data) override
Definition: content_cao.cpp:1689
void initialize(const std::string &data) override
Definition: content_cao.cpp:359
void clearParentAttachment() override
Definition: content_cao.cpp:535
MinimapMarker * m_marker
Definition: content_cao.h:89
void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override
Definition: content_cao.cpp:607
void clearChildAttachments() override
Definition: content_cao.cpp:522
BoneOverrideMap m_bone_override
Definition: content_cao.h:107
bool m_is_local_player
Definition: content_cao.h:76
bool m_is_player
Definition: content_cao.h:75
void setNodeLight(const video::SColor &light)
Definition: content_cao.cpp:920
scene::IDummyTransformationSceneNode * m_matrixnode
Definition: content_cao.h:87
bool isVisible() const
Definition: content_cao.h:218
bool isImmortal() const
Definition: content_cao.cpp:436
u16 m_hp
Definition: content_cao.h:94
void expireVisuals()
Definition: content_cao.h:246
const v3f getPosition() const override final
Definition: content_cao.cpp:421
void updateLight(u32 day_night_ratio) override
Definition: content_cao.cpp:876
const ObjectProperties & getProperties() const
Definition: content_cao.h:175
std::string m_attachment_bone
Definition: content_cao.h:111
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const override
Definition: content_cao.cpp:512
void addAttachmentChild(int child_id) override
Definition: content_cao.cpp:543
v3f m_position
Definition: content_cao.h:90
bool m_animation_loop
Definition: content_cao.h:105
void setVisible(bool toset)
Definition: content_cao.h:223
void updateMeshCulling()
Definition: content_cao.cpp:2060
v2s16 m_tx_basepos
Definition: content_cao.h:99
v3f m_attachment_position
Definition: content_cao.h:112
bool isLocalPlayer() const override
Definition: content_cao.h:208
float m_step_distance_counter
Definition: content_cao.h:128
const std::string & getName() const
Definition: content_cao.h:177
const core::matrix4 * getAbsolutePosRotMatrix() const
Definition: content_cao.h:196
float m_anim_framelength
Definition: content_cao.h:119
video::SColor m_last_light
Definition: content_cao.h:129
int m_attachment_parent_id
Definition: content_cao.h:109
float m_reset_textures_timer
Definition: content_cao.h:122
video::E_MATERIAL_TYPE m_material_type
Definition: content_cao.h:132
const v3f getVelocity() const override final
Definition: content_cao.h:169
const std::unordered_set< int > & getAttachmentChildIds() const override
Definition: content_cao.h:238
std::string debugInfoText() override
Definition: content_cao.cpp:2046
scene::ISceneManager * m_smgr
Definition: content_cao.h:80
v3f m_rotation
Definition: content_cao.h:93
void setChildrenVisible(bool toset)
Definition: content_cao.cpp:466
void removeFromScene(bool permanent) override
Definition: content_cao.cpp:559
const ItemGroupList & getGroups() const
Definition: content_cao.h:153
void updateTexturePos()
Definition: content_cao.cpp:1270
SmoothTranslatorWrappedv3f rot_translator
Definition: content_cao.h:96
u16 getLightPosition(v3s16 *pos)
Definition: content_cao.cpp:955
static std::unique_ptr< ClientActiveObject > create(Client *client, ClientEnvironment *env)
Definition: content_cao.h:144
bool m_tx_select_horiz_by_yawpitch
Definition: content_cao.h:101
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible) override
Definition: content_cao.cpp:477
void updateTextures(std::string mod)
Definition: content_cao.cpp:1340
std::string infoText() override
Definition: content_cao.h:287
bool m_initial_tx_basepos_set
Definition: content_cao.h:100
bool m_enable_shaders
Definition: content_cao.h:135
void updateAttachments() override
Definition: content_cao.cpp:1613
SmoothTranslator< v3f > pos_translator
Definition: content_cao.h:95
scene::ISceneNode * getSceneNode() const override
Definition: content_cao.cpp:441
std::string m_previous_texture_modifier
Definition: content_cao.h:124
void removeAttachmentChild(int child_id) override
Definition: content_cao.cpp:548
bool getCollisionBox(aabb3f *toset) const override
Definition: content_cao.cpp:337
ItemGroupList m_armor_groups
Definition: content_cao.h:121
bool m_force_visible
Definition: content_cao.h:115
void step(float dtime, ClientEnvironment *env) override
Definition: content_cao.cpp:1041
v3f m_velocity
Definition: content_cao.h:91
ClientActiveObject * getParent() const override
Definition: content_cao.cpp:553
bool visualExpiryRequired(const ObjectProperties &newprops) const
Definition: content_cao.cpp:1663
WieldMeshSceneNode * m_wield_meshnode
Definition: content_cao.h:85
~GenericCAO()
Definition: content_cao.cpp:407
void updateAnimation()
Definition: content_cao.cpp:1524
float m_animation_speed
Definition: content_cao.h:103
float m_anim_timer
Definition: content_cao.h:120
virtual bool getSelectionBox(aabb3f *toset) const override
Definition: content_cao.cpp:412
scene::IBillboardSceneNode * m_spritenode
Definition: content_cao.h:86
bool m_visuals_expired
Definition: content_cao.h:127
void updateNodePos()
Definition: content_cao.cpp:1022
Nametag * m_nametag
Definition: content_cao.h:88
const v3f & getRotation() const
Definition: content_cao.h:171
core::matrix4 & getPosRotMatrix()
Definition: content_cao.h:190
int m_anim_num_frames
Definition: content_cao.h:118
ActiveObjectType getType() const override
Definition: content_cao.h:149
Client * m_client
Definition: content_cao.h:81
bool m_attached_to_local
Definition: content_cao.h:114
float m_animation_blend
Definition: content_cao.h:104
scene::IAnimatedMeshSceneNode * m_animated_meshnode
Definition: content_cao.h:84
bool collideWithObjects() const override
Definition: content_cao.cpp:354
void updateMarker()
Definition: content_cao.cpp:968
f32 getStepHeight() const
Definition: content_cao.h:203
std::string m_name
Definition: content_cao.h:74
ObjectProperties m_prop
Definition: content_cao.h:78
std::unordered_set< int > m_attachment_child_ids
Definition: content_cao.h:110
scene::IAnimatedMeshSceneNode * getAnimatedMeshSceneNode() const override
Definition: content_cao.cpp:461
bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL, float time_from_last_punch=1000000) override
Definition: content_cao.cpp:2006
bool m_is_visible
Definition: content_cao.h:130
bool isPlayer() const
Definition: content_cao.h:213
Definition: texturesource.h:45
Definition: wieldmesh.h:92
#define BS
Definition: constants.h:76
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector2d< s32 > v2s32
Definition: irr_v2d.h:28
core::vector2d< s16 > v2s16
Definition: irr_v2d.h:27
core::vector2d< f32 > v2f
Definition: irr_v2d.h:26
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
std::unordered_map< std::string, int > ItemGroupList
Definition: itemgroup.h:25
Definition: activeobjectmgr.cpp:26
Definition: inventory.h:34
Definition: minimap.h:51
Definition: camera.h:40
Definition: object_properties.h:32
std::string infotext
Definition: object_properties.h:45
f32 stepheight
Definition: object_properties.h:53
Definition: content_cao.h:61
void translate(f32 dtime)
Definition: content_cao.cpp:100
Definition: content_cao.h:66
void translate(f32 dtime)
Definition: content_cao.cpp:118
Definition: content_cao.h:42
void translate(f32 dtime)
Definition: content_cao.cpp:86
void update(T new_target, bool is_end_position=false, float update_interval=-1)
Definition: content_cao.cpp:69
T val_target
Definition: content_cao.h:45
T val_current
Definition: content_cao.h:44
f32 anim_time_counter
Definition: content_cao.h:47
T val_old
Definition: content_cao.h:43
f32 anim_time
Definition: content_cao.h:46
bool aim_is_end
Definition: content_cao.h:48
SmoothTranslator()=default
void init(T current)
Definition: content_cao.cpp:58