]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clientobject.h
Add missing keyname_to_keycode function (needed on Android)
[dragonfireclient.git] / src / 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 #ifndef CLIENTOBJECT_HEADER
21 #define CLIENTOBJECT_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "activeobject.h"
25 #include <map>
26 #include "util/cpp11_container.h"
27
28 /*
29
30 Some planning
31 -------------
32
33 * Client receives a network packet with information of added objects
34   in it
35 * Client supplies the information to its ClientEnvironment
36 * The environment adds the specified objects to itself
37
38 */
39
40 class ClientEnvironment;
41 class ITextureSource;
42 class IGameDef;
43 class LocalPlayer;
44 struct ItemStack;
45 class WieldMeshSceneNode;
46
47 class ClientActiveObject : public ActiveObject
48 {
49 public:
50         ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
51         virtual ~ClientActiveObject();
52
53         virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
54                         IrrlichtDevice *irr){}
55         virtual void removeFromScene(bool permanent){}
56         // 0 <= light_at_pos <= LIGHT_SUN
57         virtual void updateLight(u8 light_at_pos){}
58         virtual void updateLightNoCheck(u8 light_at_pos){}
59         virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
60         virtual aabb3f *getSelectionBox() { return NULL; }
61         virtual bool getCollisionBox(aabb3f *toset){return false;}
62         virtual bool collideWithObjects(){return false;}
63         virtual v3f getPosition(){return v3f(0,0,0);}
64         virtual scene::ISceneNode *getSceneNode(){return NULL;}
65         virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
66         virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
67         virtual WieldMeshSceneNode *getWieldMeshSceneNode(){return NULL;}
68         virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
69         virtual bool isPlayer() const {return false;}
70         virtual bool isLocalPlayer() const {return false;}
71         virtual void setAttachments(){}
72         virtual bool doShowSelectionBox(){return true;}
73         virtual void updateCameraOffset(v3s16 camera_offset){};
74
75         // Step object in time
76         virtual void step(float dtime, ClientEnvironment *env){}
77
78         // Process a message sent by the server side object
79         virtual void processMessage(const std::string &data){}
80
81         virtual std::string infoText() {return "";}
82         virtual std::string debugInfoText() {return "";}
83
84         /*
85                 This takes the return value of
86                 ServerActiveObject::getClientInitializationData
87         */
88         virtual void initialize(const std::string &data){}
89
90         // Create a certain type of ClientActiveObject
91         static ClientActiveObject* create(ActiveObjectType type, IGameDef *gamedef,
92                         ClientEnvironment *env);
93
94         // If returns true, punch will not be sent to the server
95         virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
96                         float time_from_last_punch=1000000)
97         { return false; }
98
99 protected:
100         // Used for creating objects based on type
101         typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
102         static void registerType(u16 type, Factory f);
103         IGameDef *m_gamedef;
104         ClientEnvironment *m_env;
105 private:
106         // Used for creating objects based on type
107         static UNORDERED_MAP<u16, Factory> m_types;
108 };
109
110 struct DistanceSortedActiveObject
111 {
112         ClientActiveObject *obj;
113         f32 d;
114
115         DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
116         {
117                 obj = a_obj;
118                 d = a_d;
119         }
120
121         bool operator < (const DistanceSortedActiveObject &other) const
122         {
123                 return d < other.d;
124         }
125 };
126
127 #endif