v2d & aabbox3d<f32> & sky cleanups
[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 class WieldMeshSceneNode;
45
46 class ClientActiveObject : public ActiveObject
47 {
48 public:
49         ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
50         virtual ~ClientActiveObject();
51
52         virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
53                         IrrlichtDevice *irr){}
54         virtual void removeFromScene(bool permanent){}
55         // 0 <= light_at_pos <= LIGHT_SUN
56         virtual void updateLight(u8 light_at_pos){}
57         virtual void updateLightNoCheck(u8 light_at_pos){}
58         virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
59         virtual aabb3f *getSelectionBox() { return NULL; }
60         virtual bool getCollisionBox(aabb3f *toset){return false;}
61         virtual bool collideWithObjects(){return false;}
62         virtual v3f getPosition(){return v3f(0,0,0);}
63         virtual scene::ISceneNode *getSceneNode(){return NULL;}
64         virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
65         virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
66         virtual WieldMeshSceneNode *getWieldMeshSceneNode(){return NULL;}
67         virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
68         virtual bool isPlayer() const {return false;}
69         virtual bool isLocalPlayer() const {return false;}
70         virtual void setAttachments(){}
71         virtual bool doShowSelectionBox(){return true;}
72         virtual void updateCameraOffset(v3s16 camera_offset){};
73
74         // Step object in time
75         virtual void step(float dtime, ClientEnvironment *env){}
76
77         // Process a message sent by the server side object
78         virtual void processMessage(const std::string &data){}
79
80         virtual std::string infoText() {return "";}
81         virtual std::string debugInfoText() {return "";}
82
83         /*
84                 This takes the return value of
85                 ServerActiveObject::getClientInitializationData
86         */
87         virtual void initialize(const std::string &data){}
88
89         // Create a certain type of ClientActiveObject
90         static ClientActiveObject* create(ActiveObjectType type, IGameDef *gamedef,
91                         ClientEnvironment *env);
92
93         // If returns true, punch will not be sent to the server
94         virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
95                         float time_from_last_punch=1000000)
96         { return false; }
97
98 protected:
99         // Used for creating objects based on type
100         typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
101         static void registerType(u16 type, Factory f);
102         IGameDef *m_gamedef;
103         ClientEnvironment *m_env;
104 private:
105         // Used for creating objects based on type
106         static std::map<u16, Factory> m_types;
107 };
108
109 struct DistanceSortedActiveObject
110 {
111         ClientActiveObject *obj;
112         f32 d;
113
114         DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
115         {
116                 obj = a_obj;
117                 d = a_d;
118         }
119
120         bool operator < (const DistanceSortedActiveObject &other) const
121         {
122                 return d < other.d;
123         }
124 };
125
126 #endif