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