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