]> git.lizzy.rs Git - minetest.git/blob - src/clientobject.h
Move files to subdirectories (#6599)
[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 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "activeobject.h"
24 #include <unordered_map>
25
26 class ClientEnvironment;
27 class ITextureSource;
28 class Client;
29 class IGameDef;
30 class LocalPlayer;
31 struct ItemStack;
32 class WieldMeshSceneNode;
33
34 class ClientActiveObject : public ActiveObject
35 {
36 public:
37         ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
38         virtual ~ClientActiveObject();
39
40         virtual void addToScene(ITextureSource *tsrc) {};
41         virtual void removeFromScene(bool permanent) {}
42         // 0 <= light_at_pos <= LIGHT_SUN
43         virtual void updateLight(u8 light_at_pos){}
44         virtual void updateLightNoCheck(u8 light_at_pos){}
45         virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
46         virtual bool getCollisionBox(aabb3f *toset) const { return false; }
47         virtual bool getSelectionBox(aabb3f *toset) const { return false; }
48         virtual bool collideWithObjects() const { return false; }
49         virtual v3f getPosition(){ return v3f(0,0,0); }
50         virtual float getYaw() const { return 0; }
51         virtual scene::ISceneNode *getSceneNode() { return NULL; }
52         virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() { return NULL; }
53         virtual bool isLocalPlayer() const {return false;}
54         virtual void setAttachments() {}
55         virtual bool doShowSelectionBox(){return true;}
56
57         // Step object in time
58         virtual void step(float dtime, ClientEnvironment *env){}
59
60         // Process a message sent by the server side object
61         virtual void processMessage(const std::string &data){}
62
63         virtual std::string infoText() {return "";}
64         virtual std::string debugInfoText() {return "";}
65
66         /*
67                 This takes the return value of
68                 ServerActiveObject::getClientInitializationData
69         */
70         virtual void initialize(const std::string &data){}
71
72         // Create a certain type of ClientActiveObject
73         static ClientActiveObject* create(ActiveObjectType type, Client *client,
74                         ClientEnvironment *env);
75
76         // If returns true, punch will not be sent to the server
77         virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
78                         float time_from_last_punch=1000000)
79         { return false; }
80
81 protected:
82         // Used for creating objects based on type
83         typedef ClientActiveObject* (*Factory)(Client *client, ClientEnvironment *env);
84         static void registerType(u16 type, Factory f);
85         Client *m_client;
86         ClientEnvironment *m_env;
87 private:
88         // Used for creating objects based on type
89         static std::unordered_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 < (const DistanceSortedActiveObject &other) const
104         {
105                 return d < other.d;
106         }
107 };