Minetest  5.4.0
clientobject.h
Go to the documentation of this file.
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 
23 #include "activeobject.h"
24 #include <unordered_map>
25 #include <unordered_set>
26 
27 
28 class ClientEnvironment;
29 class ITextureSource;
30 class Client;
31 class IGameDef;
32 class LocalPlayer;
33 struct ItemStack;
34 class WieldMeshSceneNode;
35 
37 {
38 public:
40  virtual ~ClientActiveObject();
41 
42  virtual void addToScene(ITextureSource *tsrc) {}
43  virtual void removeFromScene(bool permanent) {}
44 
45  virtual void updateLight(u32 day_night_ratio) {}
46 
47  virtual bool getCollisionBox(aabb3f *toset) const { return false; }
48  virtual bool getSelectionBox(aabb3f *toset) const { return false; }
49  virtual bool collideWithObjects() const { return false; }
50  virtual const v3f getPosition() const { return v3f(0.0f); }
51  virtual scene::ISceneNode *getSceneNode() const
52  { return NULL; }
53  virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const
54  { return NULL; }
55  virtual bool isLocalPlayer() const { return false; }
56 
57  virtual ClientActiveObject *getParent() const { return nullptr; };
58  virtual const std::unordered_set<int> &getAttachmentChildIds() const
59  { static std::unordered_set<int> rv; return rv; }
60  virtual void updateAttachments() {};
61 
62  virtual bool doShowSelectionBox() { return true; }
63 
64  // Step object in time
65  virtual void step(float dtime, ClientEnvironment *env) {}
66 
67  // Process a message sent by the server side object
68  virtual void processMessage(const std::string &data) {}
69 
70  virtual std::string infoText() { return ""; }
71  virtual std::string debugInfoText() { return ""; }
72 
73  /*
74  This takes the return value of
75  ServerActiveObject::getClientInitializationData
76  */
77  virtual void initialize(const std::string &data) {}
78 
79  // Create a certain type of ClientActiveObject
81  ClientEnvironment *env);
82 
83  // If returns true, punch will not be sent to the server
84  virtual bool directReportPunch(v3f dir, const ItemStack *punchitem = nullptr,
85  float time_from_last_punch = 1000000) { return false; }
86 
87 protected:
88  // Used for creating objects based on type
89  typedef ClientActiveObject *(*Factory)(Client *client, ClientEnvironment *env);
90  static void registerType(u16 type, Factory f);
93 private:
94  // Used for creating objects based on type
95  static std::unordered_map<u16, Factory> m_types;
96 };
97 
99 {
100 public:
102 
104  {
105  obj = a_obj;
106  d = a_d;
107  }
108 
109  bool operator < (const DistanceSortedActiveObject &other) const
110  {
111  return d < other.d;
112  }
113 
114 private:
115  f32 d;
116 };
ActiveObjectType
Definition: activeobject.h:27
static v2f dir(const v2f &pos_dist)
Definition: camera.cpp:240
Definition: activeobject.h:79
Definition: clientobject.h:37
virtual const v3f getPosition() const
Definition: clientobject.h:50
virtual scene::ISceneNode * getSceneNode() const
Definition: clientobject.h:51
virtual std::string infoText()
Definition: clientobject.h:70
virtual bool getCollisionBox(aabb3f *toset) const
Definition: clientobject.h:47
virtual bool collideWithObjects() const
Definition: clientobject.h:49
virtual void initialize(const std::string &data)
Definition: clientobject.h:77
virtual void updateAttachments()
Definition: clientobject.h:60
virtual scene::IAnimatedMeshSceneNode * getAnimatedMeshSceneNode() const
Definition: clientobject.h:53
virtual bool isLocalPlayer() const
Definition: clientobject.h:55
ClientActiveObject *(* Factory)(Client *client, ClientEnvironment *env)
Definition: clientobject.h:89
virtual std::string debugInfoText()
Definition: clientobject.h:71
static void registerType(u16 type, Factory f)
Definition: clientobject.cpp:58
virtual void processMessage(const std::string &data)
Definition: clientobject.h:68
virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=nullptr, float time_from_last_punch=1000000)
Definition: clientobject.h:84
virtual void step(float dtime, ClientEnvironment *env)
Definition: clientobject.h:65
virtual bool doShowSelectionBox()
Definition: clientobject.h:62
virtual void updateLight(u32 day_night_ratio)
Definition: clientobject.h:45
virtual const std::unordered_set< int > & getAttachmentChildIds() const
Definition: clientobject.h:58
static ClientActiveObject * create(ActiveObjectType type, Client *client, ClientEnvironment *env)
Definition: clientobject.cpp:41
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env)
Definition: clientobject.cpp:28
virtual bool getSelectionBox(aabb3f *toset) const
Definition: clientobject.h:48
Client * m_client
Definition: clientobject.h:91
virtual void addToScene(ITextureSource *tsrc)
Definition: clientobject.h:42
static std::unordered_map< u16, Factory > m_types
Definition: clientobject.h:95
virtual void removeFromScene(bool permanent)
Definition: clientobject.h:43
virtual ClientActiveObject * getParent() const
Definition: clientobject.h:57
virtual ~ClientActiveObject()
Definition: clientobject.cpp:36
ClientEnvironment * m_env
Definition: clientobject.h:92
Definition: clientenvironment.h:64
Definition: client.h:109
Definition: clientobject.h:99
ClientActiveObject * obj
Definition: clientobject.h:101
DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
Definition: clientobject.h:103
f32 d
Definition: clientobject.h:115
bool operator<(const DistanceSortedActiveObject &other) const
Definition: clientobject.h:109
Definition: gamedef.h:49
Definition: tile.h:86
Definition: localplayer.h:45
Definition: wieldmesh.h:75
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: activeobjectmgr.cpp:25
Definition: inventory.h:34