Line data Source code
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 : video::SColor m_nametag_color;
74 : scene::ITextSceneNode* m_textnode;
75 : v3f m_position;
76 : v3f m_velocity;
77 : v3f m_acceleration;
78 : float m_yaw;
79 : s16 m_hp;
80 : SmoothTranslator pos_translator;
81 : // Spritesheet/animation stuff
82 : v2f m_tx_size;
83 : v2s16 m_tx_basepos;
84 : bool m_initial_tx_basepos_set;
85 : bool m_tx_select_horiz_by_yawpitch;
86 : v2s32 m_animation_range;
87 : int m_animation_speed;
88 : int m_animation_blend;
89 : bool m_animation_loop;
90 : std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
91 : std::string m_attachment_bone;
92 : v3f m_attachment_position;
93 : v3f m_attachment_rotation;
94 : bool m_attached_to_local;
95 : int m_anim_frame;
96 : int m_anim_num_frames;
97 : float m_anim_framelength;
98 : float m_anim_timer;
99 : ItemGroupList m_armor_groups;
100 : float m_reset_textures_timer;
101 : bool m_visuals_expired;
102 : float m_step_distance_counter;
103 : u8 m_last_light;
104 : bool m_is_visible;
105 :
106 : std::vector<u16> m_children;
107 :
108 : public:
109 : GenericCAO(IGameDef *gamedef, ClientEnvironment *env);
110 :
111 : ~GenericCAO();
112 :
113 44 : static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
114 : {
115 44 : return new GenericCAO(gamedef, env);
116 : }
117 :
118 1 : inline ActiveObjectType getType() const
119 : {
120 1 : return ACTIVEOBJECT_TYPE_GENERIC;
121 : }
122 :
123 : void initialize(const std::string &data);
124 :
125 : ClientActiveObject *getParent();
126 :
127 : bool getCollisionBox(aabb3f *toset);
128 :
129 : bool collideWithObjects();
130 :
131 : core::aabbox3d<f32>* getSelectionBox();
132 :
133 : v3f getPosition();
134 :
135 : scene::ISceneNode *getSceneNode();
136 :
137 : scene::IMeshSceneNode *getMeshSceneNode();
138 :
139 : scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
140 :
141 : WieldMeshSceneNode *getWieldMeshSceneNode();
142 :
143 : scene::IBillboardSceneNode *getSpriteSceneNode();
144 :
145 0 : inline bool isPlayer() const
146 : {
147 0 : return m_is_player;
148 : }
149 :
150 0 : inline bool isLocalPlayer() const
151 : {
152 0 : return m_is_local_player;
153 : }
154 :
155 : inline bool isVisible() const
156 : {
157 : return m_is_visible;
158 : }
159 :
160 0 : inline void setVisible(bool toset)
161 : {
162 0 : m_is_visible = toset;
163 0 : }
164 :
165 : void setChildrenVisible(bool toset);
166 :
167 : void setAttachments();
168 :
169 : void removeFromScene(bool permanent);
170 :
171 : void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
172 : IrrlichtDevice *irr);
173 :
174 118 : inline void expireVisuals()
175 : {
176 118 : m_visuals_expired = true;
177 118 : }
178 :
179 : void updateLight(u8 light_at_pos);
180 :
181 : v3s16 getLightPosition();
182 :
183 : void updateNodePos();
184 :
185 : void step(float dtime, ClientEnvironment *env);
186 :
187 : void updateTexturePos();
188 :
189 : void updateTextures(const std::string &mod);
190 :
191 : void updateAnimation();
192 :
193 : void updateBonePosition();
194 :
195 : void updateAttachments();
196 :
197 : void processMessage(const std::string &data);
198 :
199 : bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
200 : float time_from_last_punch=1000000);
201 :
202 : std::string debugInfoText();
203 : };
204 :
205 :
206 : #endif
|