3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "irrlichttypes_extrabloated.h"
24 #include "clientobject.h"
25 #include "object_properties.h"
26 #include "itemgroup.h"
27 #include "constants.h"
38 struct SmoothTranslator
44 f32 anim_time_counter = 0;
45 bool aim_is_end = true;
47 SmoothTranslator() = default;
51 void update(T new_target, bool is_end_position = false,
52 float update_interval = -1);
54 void translate(f32 dtime);
57 struct SmoothTranslatorWrapped : SmoothTranslator<f32>
59 void translate(f32 dtime);
62 struct SmoothTranslatorWrappedv3f : SmoothTranslator<v3f>
64 void translate(f32 dtime);
67 class GenericCAO : public ClientActiveObject
70 // Only set at initialization
71 std::string m_name = "";
72 bool m_is_player = false;
73 bool m_is_local_player = false;
74 // Property-ish things
75 ObjectProperties m_prop;
77 scene::ISceneManager *m_smgr = nullptr;
78 Client *m_client = nullptr;
79 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
80 scene::IMeshSceneNode *m_meshnode = nullptr;
81 scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
82 WieldMeshSceneNode *m_wield_meshnode = nullptr;
83 scene::IBillboardSceneNode *m_spritenode = nullptr;
84 Nametag *m_nametag = nullptr;
85 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
90 SmoothTranslator<v3f> pos_translator;
91 SmoothTranslatorWrappedv3f rot_translator;
92 // Spritesheet/animation stuff
93 v2f m_tx_size = v2f(1,1);
95 bool m_initial_tx_basepos_set = false;
96 bool m_tx_select_horiz_by_yawpitch = false;
97 v2s32 m_animation_range;
98 float m_animation_speed = 15.0f;
99 float m_animation_blend = 0.0f;
100 bool m_animation_loop = true;
101 // stores position and rotation for each bone name
102 std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
103 std::string m_attachment_bone = "";
104 v3f m_attachment_position;
105 v3f m_attachment_rotation;
106 bool m_attached_to_local = false;
107 int m_anim_frame = 0;
108 int m_anim_num_frames = 1;
109 float m_anim_framelength = 0.2f;
110 float m_anim_timer = 0.0f;
111 ItemGroupList m_armor_groups;
112 float m_reset_textures_timer = -1.0f;
113 // stores texture modifier before punch update
114 std::string m_previous_texture_modifier = "";
115 // last applied texture modifier
116 std::string m_current_texture_modifier = "";
117 bool m_visuals_expired = false;
118 float m_step_distance_counter = 0.0f;
119 u8 m_last_light = 255;
120 bool m_is_visible = false;
123 std::vector<u16> m_children;
126 GenericCAO(Client *client, ClientEnvironment *env);
130 static ClientActiveObject* create(Client *client, ClientEnvironment *env)
132 return new GenericCAO(client, env);
135 inline ActiveObjectType getType() const
137 return ACTIVEOBJECT_TYPE_GENERIC;
139 inline const ItemGroupList &getGroups() const
141 return m_armor_groups;
143 void initialize(const std::string &data);
145 void processInitData(const std::string &data);
147 bool getCollisionBox(aabb3f *toset) const;
149 bool collideWithObjects() const;
151 virtual bool getSelectionBox(aabb3f *toset) const;
155 inline const v3f &getRotation()
160 const bool isImmortal();
162 scene::ISceneNode *getSceneNode();
164 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
166 inline f32 getStepHeight() const
168 return m_prop.stepheight;
171 inline bool isLocalPlayer() const
173 return m_is_local_player;
176 inline bool isVisible() const
181 inline void setVisible(bool toset)
183 m_is_visible = toset;
186 void setChildrenVisible(bool toset);
188 ClientActiveObject *getParent() const;
190 void setAttachments();
192 void removeFromScene(bool permanent);
194 void addToScene(ITextureSource *tsrc);
196 inline void expireVisuals()
198 m_visuals_expired = true;
201 void updateLight(u8 light_at_pos);
203 void updateLightNoCheck(u8 light_at_pos);
205 v3s16 getLightPosition();
207 void updateNodePos();
209 void step(float dtime, ClientEnvironment *env);
211 void updateTexturePos();
213 // std::string copy is mandatory as mod can be a class member and there is a swap
214 // on those class members... do NOT pass by reference
215 void updateTextures(std::string mod);
217 void updateAnimation();
219 void updateAnimationSpeed();
221 void updateBonePosition();
223 void updateAttachments();
225 void processMessage(const std::string &data);
227 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
228 float time_from_last_punch=1000000);
230 std::string debugInfoText();
232 std::string infoText()
234 return m_prop.infotext;