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"
31 * Client receives a network packet with information of added objects
33 * Client supplies the information to its ClientEnvironment
34 * The environment adds the specified objects to itself
42 struct SmoothTranslator
47 f32 anim_time_counter;
67 void update(v3f vect_new)
71 if(anim_time < 0.001 || anim_time > 1.0)
72 anim_time = anim_time_counter;
74 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
75 anim_time_counter = 0;
79 void translate(f32 dtime)
81 anim_time_counter = anim_time_counter + dtime;
82 anim_counter = anim_counter + dtime;
83 v3f vect_move = vect_aim - vect_old;
86 moveratio = anim_time_counter / anim_time;
87 // Move a bit less than should, to avoid oscillation
88 moveratio = moveratio * 0.8;
91 vect_show = vect_old + vect_move * moveratio;
95 class ClientEnvironment;
97 class ClientActiveObject : public ActiveObject
100 ClientActiveObject(u16 id);
101 virtual ~ClientActiveObject();
103 virtual void addToScene(scene::ISceneManager *smgr){}
104 virtual void removeFromScene(){}
105 // 0 <= light_at_pos <= LIGHT_SUN
106 virtual void updateLight(u8 light_at_pos){}
107 virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
108 virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
109 virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
110 virtual v3f getPosition(){return v3f(0,0,0);}
112 // Step object in time
113 virtual void step(float dtime, ClientEnvironment *env){}
115 // Process a message sent by the server side object
116 virtual void processMessage(const std::string &data){}
118 virtual std::string infoText() {return "";}
121 This takes the return value of
122 ServerActiveObject::getClientInitializationData
124 virtual void initialize(const std::string &data){}
126 // Create a certain type of ClientActiveObject
127 static ClientActiveObject* create(u8 type);
130 // Used for creating objects based on type
131 typedef ClientActiveObject* (*Factory)();
132 static void registerType(u16 type, Factory f);
134 // Used for creating objects based on type
135 static core::map<u16, Factory> m_types;
138 struct DistanceSortedActiveObject
140 ClientActiveObject *obj;
143 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
149 bool operator < (DistanceSortedActiveObject &other)
159 class TestCAO : public ClientActiveObject
167 return ACTIVEOBJECT_TYPE_TEST;
170 static ClientActiveObject* create();
172 void addToScene(scene::ISceneManager *smgr);
173 void removeFromScene();
174 void updateLight(u8 light_at_pos);
175 v3s16 getLightPosition();
176 void updateNodePos();
178 void step(float dtime, ClientEnvironment *env);
180 void processMessage(const std::string &data);
183 scene::IMeshSceneNode *m_node;
191 class ItemCAO : public ClientActiveObject
199 return ACTIVEOBJECT_TYPE_ITEM;
202 static ClientActiveObject* create();
204 void addToScene(scene::ISceneManager *smgr);
205 void removeFromScene();
206 void updateLight(u8 light_at_pos);
207 v3s16 getLightPosition();
208 void updateNodePos();
210 void step(float dtime, ClientEnvironment *env);
212 void processMessage(const std::string &data);
214 void initialize(const std::string &data);
216 core::aabbox3d<f32>* getSelectionBox()
217 {return &m_selection_box;}
222 core::aabbox3d<f32> m_selection_box;
223 scene::IMeshSceneNode *m_node;
225 std::string m_inventorystring;
232 class RatCAO : public ClientActiveObject
240 return ACTIVEOBJECT_TYPE_RAT;
243 static ClientActiveObject* create();
245 void addToScene(scene::ISceneManager *smgr);
246 void removeFromScene();
247 void updateLight(u8 light_at_pos);
248 v3s16 getLightPosition();
249 void updateNodePos();
251 void step(float dtime, ClientEnvironment *env);
253 void processMessage(const std::string &data);
255 void initialize(const std::string &data);
257 core::aabbox3d<f32>* getSelectionBox()
258 {return &m_selection_box;}
263 core::aabbox3d<f32> m_selection_box;
264 scene::IMeshSceneNode *m_node;
267 SmoothTranslator pos_translator;