C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)
[oweals/minetest.git] / src / content_cao.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef CONTENT_CAO_HEADER
21 #define CONTENT_CAO_HEADER
22
23 #include <map>
24 #include "irrlichttypes_extrabloated.h"
25 #include "clientobject.h"
26 #include "object_properties.h"
27 #include "itemgroup.h"
28
29 class Camera;
30 class Client;
31 struct Nametag;
32
33 /*
34         SmoothTranslator
35 */
36
37 struct SmoothTranslator
38 {
39         v3f vect_old;
40         v3f vect_show;
41         v3f vect_aim;
42         f32 anim_counter;
43         f32 anim_time;
44         f32 anim_time_counter;
45         bool aim_is_end;
46
47         SmoothTranslator();
48
49         void init(v3f vect);
50
51         void sharpen();
52
53         void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
54
55         void translate(f32 dtime);
56
57         bool is_moving();
58 };
59
60 class GenericCAO : public ClientActiveObject
61 {
62 private:
63         // Only set at initialization
64         std::string m_name;
65         bool m_is_player;
66         bool m_is_local_player;
67         // Property-ish things
68         ObjectProperties m_prop;
69         //
70         scene::ISceneManager *m_smgr;
71         IrrlichtDevice *m_irr;
72         Client *m_client;
73         aabb3f m_selection_box;
74         scene::IMeshSceneNode *m_meshnode;
75         scene::IAnimatedMeshSceneNode *m_animated_meshnode;
76         WieldMeshSceneNode *m_wield_meshnode;
77         scene::IBillboardSceneNode *m_spritenode;
78         Nametag* m_nametag;
79         v3f m_position;
80         v3f m_velocity;
81         v3f m_acceleration;
82         float m_yaw;
83         s16 m_hp;
84         SmoothTranslator pos_translator;
85         // Spritesheet/animation stuff
86         v2f m_tx_size;
87         v2s16 m_tx_basepos;
88         bool m_initial_tx_basepos_set;
89         bool m_tx_select_horiz_by_yawpitch;
90         v2s32 m_animation_range;
91         int m_animation_speed;
92         int m_animation_blend;
93         bool m_animation_loop;
94         // stores position and rotation for each bone name
95         std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
96         std::string m_attachment_bone;
97         v3f m_attachment_position;
98         v3f m_attachment_rotation;
99         bool m_attached_to_local;
100         int m_anim_frame;
101         int m_anim_num_frames;
102         float m_anim_framelength;
103         float m_anim_timer;
104         ItemGroupList m_armor_groups;
105         float m_reset_textures_timer;
106         std::string m_previous_texture_modifier; // stores texture modifier before punch update
107         std::string m_current_texture_modifier;  // last applied texture modifier
108         bool m_visuals_expired;
109         float m_step_distance_counter;
110         u8 m_last_light;
111         bool m_is_visible;
112
113         std::vector<u16> m_children;
114
115 public:
116         GenericCAO(Client *client, ClientEnvironment *env);
117
118         ~GenericCAO();
119
120         static ClientActiveObject* create(Client *client, ClientEnvironment *env)
121         {
122                 return new GenericCAO(client, env);
123         }
124
125         inline ActiveObjectType getType() const
126         {
127                 return ACTIVEOBJECT_TYPE_GENERIC;
128         }
129
130         void initialize(const std::string &data);
131
132         void processInitData(const std::string &data);
133
134         ClientActiveObject *getParent();
135
136         bool getCollisionBox(aabb3f *toset) const;
137
138         bool collideWithObjects() const;
139
140         aabb3f *getSelectionBox();
141
142         v3f getPosition();
143         inline float getYaw() const
144         {
145                 return m_yaw;
146         }
147
148         scene::ISceneNode *getSceneNode();
149
150         scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
151
152         inline bool isLocalPlayer() const
153         {
154                 return m_is_local_player;
155         }
156
157         inline bool isVisible() const
158         {
159                 return m_is_visible;
160         }
161
162         inline void setVisible(bool toset)
163         {
164                 m_is_visible = toset;
165         }
166
167         void setChildrenVisible(bool toset);
168
169         void setAttachments();
170
171         void removeFromScene(bool permanent);
172
173         void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
174                         IrrlichtDevice *irr);
175
176         inline void expireVisuals()
177         {
178                 m_visuals_expired = true;
179         }
180
181         void updateLight(u8 light_at_pos);
182
183         void updateLightNoCheck(u8 light_at_pos);
184
185         v3s16 getLightPosition();
186
187         void updateNodePos();
188
189         void step(float dtime, ClientEnvironment *env);
190
191         void updateTexturePos();
192
193         // std::string copy is mandatory as mod can be a class member and there is a swap
194         // on those class members
195         void updateTextures(std::string mod);
196
197         void updateAnimation();
198
199         void updateBonePosition();
200
201         void updateAttachments();
202
203         void processMessage(const std::string &data);
204
205         bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
206                         float time_from_last_punch=1000000);
207
208         std::string debugInfoText();
209
210         std::string infoText()
211         {
212                 return m_prop.infotext;
213         }
214 };
215
216
217 #endif