3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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.
20 #ifndef CLIENTOBJECT_HEADER
21 #define CLIENTOBJECT_HEADER
23 #include "common_irrlicht.h"
24 #include "activeobject.h"
32 * Client receives a network packet with information of added objects
34 * Client supplies the information to its ClientEnvironment
35 * The environment adds the specified objects to itself
43 struct SmoothTranslator
48 f32 anim_time_counter;
68 void update(v3f vect_new)
72 if(anim_time < 0.001 || anim_time > 1.0)
73 anim_time = anim_time_counter;
75 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
76 anim_time_counter = 0;
80 void translate(f32 dtime)
82 anim_time_counter = anim_time_counter + dtime;
83 anim_counter = anim_counter + dtime;
84 v3f vect_move = vect_aim - vect_old;
87 moveratio = anim_time_counter / anim_time;
88 // Move a bit less than should, to avoid oscillation
89 moveratio = moveratio * 0.8;
92 vect_show = vect_old + vect_move * moveratio;
96 class ClientEnvironment;
98 class ClientActiveObject : public ActiveObject
101 ClientActiveObject(u16 id);
102 virtual ~ClientActiveObject();
104 virtual void addToScene(scene::ISceneManager *smgr){}
105 virtual void removeFromScene(){}
106 // 0 <= light_at_pos <= LIGHT_SUN
107 virtual void updateLight(u8 light_at_pos){}
108 virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
109 virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
110 virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
111 virtual v3f getPosition(){return v3f(0,0,0);}
113 // Step object in time
114 virtual void step(float dtime, ClientEnvironment *env){}
116 // Process a message sent by the server side object
117 virtual void processMessage(const std::string &data){}
119 virtual std::string infoText() {return "";}
122 This takes the return value of
123 ServerActiveObject::getClientInitializationData
125 virtual void initialize(const std::string &data){}
127 // Create a certain type of ClientActiveObject
128 static ClientActiveObject* create(u8 type);
131 // Used for creating objects based on type
132 typedef ClientActiveObject* (*Factory)();
133 static void registerType(u16 type, Factory f);
135 // Used for creating objects based on type
136 static core::map<u16, Factory> m_types;
139 struct DistanceSortedActiveObject
141 ClientActiveObject *obj;
144 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
150 bool operator < (DistanceSortedActiveObject &other)
160 class TestCAO : public ClientActiveObject
168 return ACTIVEOBJECT_TYPE_TEST;
171 static ClientActiveObject* create();
173 void addToScene(scene::ISceneManager *smgr);
174 void removeFromScene();
175 void updateLight(u8 light_at_pos);
176 v3s16 getLightPosition();
177 void updateNodePos();
179 void step(float dtime, ClientEnvironment *env);
181 void processMessage(const std::string &data);
184 scene::IMeshSceneNode *m_node;
192 class ItemCAO : public ClientActiveObject
200 return ACTIVEOBJECT_TYPE_ITEM;
203 static ClientActiveObject* create();
205 void addToScene(scene::ISceneManager *smgr);
206 void removeFromScene();
207 void updateLight(u8 light_at_pos);
208 v3s16 getLightPosition();
209 void updateNodePos();
211 void step(float dtime, ClientEnvironment *env);
213 void processMessage(const std::string &data);
215 void initialize(const std::string &data);
217 core::aabbox3d<f32>* getSelectionBox()
218 {return &m_selection_box;}
223 core::aabbox3d<f32> m_selection_box;
224 scene::IMeshSceneNode *m_node;
226 std::string m_inventorystring;
233 class RatCAO : public ClientActiveObject
241 return ACTIVEOBJECT_TYPE_RAT;
244 static ClientActiveObject* create();
246 void addToScene(scene::ISceneManager *smgr);
247 void removeFromScene();
248 void updateLight(u8 light_at_pos);
249 v3s16 getLightPosition();
250 void updateNodePos();
252 void step(float dtime, ClientEnvironment *env);
254 void processMessage(const std::string &data);
256 void initialize(const std::string &data);
258 core::aabbox3d<f32>* getSelectionBox()
259 {return &m_selection_box;}
264 core::aabbox3d<f32> m_selection_box;
265 scene::IMeshSceneNode *m_node;
268 SmoothTranslator pos_translator;
275 class Oerkki1CAO : public ClientActiveObject
279 virtual ~Oerkki1CAO();
283 return ACTIVEOBJECT_TYPE_OERKKI1;
286 static ClientActiveObject* create();
288 void addToScene(scene::ISceneManager *smgr);
289 void removeFromScene();
290 void updateLight(u8 light_at_pos);
291 v3s16 getLightPosition();
292 void updateNodePos();
294 void step(float dtime, ClientEnvironment *env);
296 void processMessage(const std::string &data);
298 void initialize(const std::string &data);
300 core::aabbox3d<f32>* getSelectionBox()
301 {return &m_selection_box;}
303 {return pos_translator.vect_show;}
304 //{return m_position;}
307 IntervalLimiter m_attack_interval;
308 core::aabbox3d<f32> m_selection_box;
309 scene::IMeshSceneNode *m_node;
312 SmoothTranslator pos_translator;