]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/clientobject.h
refacto: don't use RenderingEngine singleton on CAO
[dragonfireclient.git] / src / client / clientobject.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "activeobject.h"
24 #include <unordered_map>
25 #include <unordered_set>
26
27
28 class ClientEnvironment;
29 class ITextureSource;
30 class Client;
31 class IGameDef;
32 class LocalPlayer;
33 struct ItemStack;
34 class WieldMeshSceneNode;
35
36 namespace irr { namespace scene {
37         class ISceneManager;
38 }}
39
40 class ClientActiveObject : public ActiveObject
41 {
42 public:
43         ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
44         virtual ~ClientActiveObject();
45
46         virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) = 0;
47         virtual void removeFromScene(bool permanent) {}
48
49         virtual void updateLight(u32 day_night_ratio) {}
50
51         virtual bool getCollisionBox(aabb3f *toset) const { return false; }
52         virtual bool getSelectionBox(aabb3f *toset) const { return false; }
53         virtual bool collideWithObjects() const { return false; }
54         virtual const v3f getPosition() const { return v3f(0.0f); }
55         virtual scene::ISceneNode *getSceneNode() const
56         { return NULL; }
57         virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const
58         { return NULL; }
59         virtual bool isLocalPlayer() const { return false; }
60
61         virtual ClientActiveObject *getParent() const { return nullptr; };
62         virtual const std::unordered_set<int> &getAttachmentChildIds() const
63         { static std::unordered_set<int> rv; return rv; }
64         virtual void updateAttachments() {};
65
66         virtual bool doShowSelectionBox() { return true; }
67
68         // Step object in time
69         virtual void step(float dtime, ClientEnvironment *env) {}
70
71         // Process a message sent by the server side object
72         virtual void processMessage(const std::string &data) {}
73
74         virtual std::string infoText() { return ""; }
75         virtual std::string debugInfoText() { return ""; }
76
77         /*
78                 This takes the return value of
79                 ServerActiveObject::getClientInitializationData
80         */
81         virtual void initialize(const std::string &data) {}
82
83         // Create a certain type of ClientActiveObject
84         static ClientActiveObject *create(ActiveObjectType type, Client *client,
85                 ClientEnvironment *env);
86
87         // If returns true, punch will not be sent to the server
88         virtual bool directReportPunch(v3f dir, const ItemStack *punchitem = nullptr,
89                 float time_from_last_punch = 1000000) { return false; }
90
91 protected:
92         // Used for creating objects based on type
93         typedef ClientActiveObject *(*Factory)(Client *client, ClientEnvironment *env);
94         static void registerType(u16 type, Factory f);
95         Client *m_client;
96         ClientEnvironment *m_env;
97 private:
98         // Used for creating objects based on type
99         static std::unordered_map<u16, Factory> m_types;
100 };
101
102 class DistanceSortedActiveObject
103 {
104 public:
105         ClientActiveObject *obj;
106
107         DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
108         {
109                 obj = a_obj;
110                 d = a_d;
111         }
112
113         bool operator < (const DistanceSortedActiveObject &other) const
114         {
115                 return d < other.d;
116         }
117
118 private:
119         f32 d;
120 };