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"
25 #include <unordered_map>
27 class ClientEnvironment;
33 class WieldMeshSceneNode;
35 class ClientActiveObject : public ActiveObject
38 ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
39 virtual ~ClientActiveObject();
41 virtual void addToScene(ITextureSource *tsrc) {};
42 virtual void removeFromScene(bool permanent) {}
43 // 0 <= light_at_pos <= LIGHT_SUN
44 virtual void updateLight(u8 light_at_pos){}
45 virtual void updateLightNoCheck(u8 light_at_pos){}
46 virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
47 virtual bool getCollisionBox(aabb3f *toset) const { return false; }
48 virtual bool getSelectionBox(aabb3f *toset) const { return false; }
49 virtual bool collideWithObjects() const { return false; }
50 virtual v3f getPosition(){ return v3f(0,0,0); }
51 virtual float getYaw() const { return 0; }
52 virtual scene::ISceneNode *getSceneNode() { return NULL; }
53 virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() { return NULL; }
54 virtual bool isLocalPlayer() const {return false;}
55 virtual void setAttachments() {}
56 virtual bool doShowSelectionBox(){return true;}
58 // Step object in time
59 virtual void step(float dtime, ClientEnvironment *env){}
61 // Process a message sent by the server side object
62 virtual void processMessage(const std::string &data){}
64 virtual std::string infoText() {return "";}
65 virtual std::string debugInfoText() {return "";}
68 This takes the return value of
69 ServerActiveObject::getClientInitializationData
71 virtual void initialize(const std::string &data){}
73 // Create a certain type of ClientActiveObject
74 static ClientActiveObject* create(ActiveObjectType type, Client *client,
75 ClientEnvironment *env);
77 // If returns true, punch will not be sent to the server
78 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
79 float time_from_last_punch=1000000)
83 // Used for creating objects based on type
84 typedef ClientActiveObject* (*Factory)(Client *client, ClientEnvironment *env);
85 static void registerType(u16 type, Factory f);
87 ClientEnvironment *m_env;
89 // Used for creating objects based on type
90 static std::unordered_map<u16, Factory> m_types;
93 struct DistanceSortedActiveObject
95 ClientActiveObject *obj;
98 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
104 bool operator < (const DistanceSortedActiveObject &other) const