Predict param2 of facedir nodes and attachment of attached_node nodes
[oweals/minetest.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
27 /*
28
29 Some planning
30 -------------
31
32 * Client receives a network packet with information of added objects
33   in it
34 * Client supplies the information to its ClientEnvironment
35 * The environment adds the specified objects to itself
36
37 */
38
39 class ClientEnvironment;
40 class ITextureSource;
41 class IGameDef;
42 class LocalPlayer;
43 struct ItemStack;
44
45 class ClientActiveObject : public ActiveObject
46 {
47 public:
48         ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
49         virtual ~ClientActiveObject();
50
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 core::aabbox3d<f32>* getCollisionBox(){return NULL;}
59         virtual v3f getPosition(){return v3f(0,0,0);}
60         virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
61         virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
62         virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
63         virtual bool isPlayer(){return false;}
64         virtual bool isLocalPlayer(){return false;}
65         virtual void setAttachments(){}
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(u8 type, IGameDef *gamedef,
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=NULL,
89                         float time_from_last_punch=1000000)
90         { return false; }
91
92 protected:
93         // Used for creating objects based on type
94         typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
95         static void registerType(u16 type, Factory f);
96         IGameDef *m_gamedef;
97         ClientEnvironment *m_env;
98 private:
99         // Used for creating objects based on type
100         static std::map<u16, Factory> m_types;
101 };
102
103 struct DistanceSortedActiveObject
104 {
105         ClientActiveObject *obj;
106         f32 d;
107
108         DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
109         {
110                 obj = a_obj;
111                 d = a_d;
112         }
113
114         bool operator < (const DistanceSortedActiveObject &other) const
115         {
116                 return d < other.d;
117         }
118 };
119
120 #endif
121