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.
22 #include "irrlichttypes_extrabloated.h"
23 #include "activeobject.h"
24 #include <unordered_map>
25 #include <unordered_set>
28 class ClientEnvironment;
34 class WieldMeshSceneNode;
36 class ClientActiveObject : public ActiveObject
39 ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
40 virtual ~ClientActiveObject();
42 virtual void addToScene(ITextureSource *tsrc) {}
43 virtual void removeFromScene(bool permanent) {}
45 virtual void updateLight(u32 day_night_ratio) {}
46 virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); }
48 virtual bool getCollisionBox(aabb3f *toset) const { return false; }
49 virtual bool getSelectionBox(aabb3f *toset) const { return false; }
50 virtual bool collideWithObjects() const { return false; }
51 virtual const v3f getPosition() const { return v3f(0.0f); }
52 virtual scene::ISceneNode *getSceneNode() const
54 virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const
56 virtual bool isLocalPlayer() const { return false; }
58 virtual ClientActiveObject *getParent() const { return nullptr; };
59 virtual const std::unordered_set<int> &getAttachmentChildIds() const
60 { static std::unordered_set<int> rv; return rv; }
61 virtual void updateAttachments() {};
63 virtual bool doShowSelectionBox() { return true; }
65 // Step object in time
66 virtual void step(float dtime, ClientEnvironment *env) {}
68 // Process a message sent by the server side object
69 virtual void processMessage(const std::string &data) {}
71 virtual std::string infoText() { return ""; }
72 virtual std::string debugInfoText() { return ""; }
75 This takes the return value of
76 ServerActiveObject::getClientInitializationData
78 virtual void initialize(const std::string &data) {}
80 // Create a certain type of ClientActiveObject
81 static ClientActiveObject *create(ActiveObjectType type, Client *client,
82 ClientEnvironment *env);
84 // If returns true, punch will not be sent to the server
85 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem = nullptr,
86 float time_from_last_punch = 1000000) { return false; }
89 // Used for creating objects based on type
90 typedef ClientActiveObject *(*Factory)(Client *client, ClientEnvironment *env);
91 static void registerType(u16 type, Factory f);
93 ClientEnvironment *m_env;
95 // Used for creating objects based on type
96 static std::unordered_map<u16, Factory> m_types;
99 class DistanceSortedActiveObject
102 ClientActiveObject *obj;
104 DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
110 bool operator < (const DistanceSortedActiveObject &other) const