]> git.lizzy.rs Git - minetest-m13.git/blob - src/clientobject.h
Update to 4.6 base
[minetest-m13.git] / src / clientobject.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 "common_irrlicht.h"
24 #include "activeobject.h"
25
26 /*
27
28 Some planning
29 -------------
30
31 * Client receives a network packet with information of added objects
32   in it
33 * Client supplies the information to its ClientEnvironment
34 * The environment adds the specified objects to itself
35
36 */
37
38 class ClientEnvironment;
39 class ITextureSource;
40 class IGameDef;
41
42 class ClientActiveObject : public ActiveObject
43 {
44 public:
45         ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
46         virtual ~ClientActiveObject();
47
48         virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
49                         IrrlichtDevice *irr){}
50         virtual void removeFromScene(){}
51         // 0 <= light_at_pos <= LIGHT_SUN
52         virtual void updateLight(u8 light_at_pos){}
53         virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
54         virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
55         virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
56         virtual v3f getPosition(){return v3f(0,0,0);}
57         virtual bool doShowSelectionBox(){return true;}
58         
59         // Step object in time
60         virtual void step(float dtime, ClientEnvironment *env){}
61         
62         // Process a message sent by the server side object
63         virtual void processMessage(const std::string &data){}
64
65         virtual std::string infoText() {return "";}
66         
67         /*
68                 This takes the return value of
69                 ServerActiveObject::getClientInitializationData
70         */
71         virtual void initialize(const std::string &data){}
72         
73         // Create a certain type of ClientActiveObject
74         static ClientActiveObject* create(u8 type, IGameDef *gamedef,
75                         ClientEnvironment *env);
76
77         // If returns true, punch will not be sent to the server
78         virtual bool directReportPunch(const std::string &toolname, v3f dir)
79         { return false; }
80
81 protected:
82         // Used for creating objects based on type
83         typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
84         static void registerType(u16 type, Factory f);
85         IGameDef *m_gamedef;
86         ClientEnvironment *m_env;
87 private:
88         // Used for creating objects based on type
89         static core::map<u16, Factory> m_types;
90 };
91
92 struct DistanceSortedActiveObject
93 {
94         ClientActiveObject *obj;
95         f32 d;
96
97         DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
98         {
99                 obj = a_obj;
100                 d = a_d;
101         }
102
103         bool operator < (DistanceSortedActiveObject &other)
104         {
105                 return d < other.d;
106         }
107 };
108
109 #endif
110