3 Copyright (C) 2010-2013 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 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.
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.
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.
20 #ifndef CLIENTOBJECT_HEADER
21 #define CLIENTOBJECT_HEADER
23 #include "irrlichttypes_extrabloated.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
39 class ClientEnvironment;
45 class ClientActiveObject : public ActiveObject
48 ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
49 virtual ~ClientActiveObject();
51 virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
52 IrrlichtDevice *irr){}
53 virtual void removeFromScene(bool permanent){}
54 // 0 <= light_at_pos <= LIGHT_SUN
55 virtual void updateLight(u8 light_at_pos){}
56 virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
57 virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
58 virtual bool getCollisionBox(aabb3f *toset){return false;}
59 virtual bool collideWithObjects(){return false;}
60 virtual v3f getPosition(){return v3f(0,0,0);}
61 virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
62 virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
63 virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
64 virtual bool isPlayer(){return false;}
65 virtual bool isLocalPlayer(){return false;}
66 virtual void setAttachments(){}
67 virtual bool doShowSelectionBox(){return true;}
68 virtual void updateCameraOffset(v3s16 camera_offset){};
70 // Step object in time
71 virtual void step(float dtime, ClientEnvironment *env){}
73 // Process a message sent by the server side object
74 virtual void processMessage(const std::string &data){}
76 virtual std::string infoText() {return "";}
77 virtual std::string debugInfoText() {return "";}
80 This takes the return value of
81 ServerActiveObject::getClientInitializationData
83 virtual void initialize(const std::string &data){}
85 // Create a certain type of ClientActiveObject
86 static ClientActiveObject* create(u8 type, IGameDef *gamedef,
87 ClientEnvironment *env);
89 // If returns true, punch will not be sent to the server
90 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
91 float time_from_last_punch=1000000)
95 // Used for creating objects based on type
96 typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
97 static void registerType(u16 type, Factory f);
99 ClientEnvironment *m_env;
101 // Used for creating objects based on type
102 static std::map<u16, Factory> m_types;
105 struct DistanceSortedActiveObject
107 ClientActiveObject *obj;
110 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
116 bool operator < (const DistanceSortedActiveObject &other) const