Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
clientobject.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
8#include "activeobject.h"
9#include <memory>
10#include <unordered_map>
11#include <unordered_set>
12
13
15class ITextureSource;
16class Client;
17struct ItemStack;
18
19namespace scene
20{
21 class AnimatedMeshSceneNode;
22 class ISceneNode;
23 class ISceneManager;
24}
25
27{
28public:
30 virtual ~ClientActiveObject();
31
32 virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) = 0;
33 virtual void removeFromScene(bool permanent) {}
34
35 virtual void updateLight(u32 day_night_ratio) {}
36
37 virtual bool getCollisionBox(aabb3f *toset) const { return false; }
38 virtual bool getSelectionBox(aabb3f *toset) const { return false; }
39 virtual bool collideWithObjects() const { return false; }
40 virtual const v3f getPosition() const { return v3f(0.0f); } // in BS-space
41 virtual const v3f getVelocity() const { return v3f(0.0f); } // in BS-space
42 virtual scene::ISceneNode *getSceneNode() const
43 { return NULL; }
44 virtual scene::AnimatedMeshSceneNode *getAnimatedMeshSceneNode() const
45 { return NULL; }
46 virtual bool isLocalPlayer() const { return false; }
47
48 virtual ClientActiveObject *getParent() const { return nullptr; };
49 virtual const std::unordered_set<object_t> &getAttachmentChildIds() const
50 { static std::unordered_set<object_t> rv; return rv; }
51 virtual void updateAttachments() {};
52
53 virtual bool doShowSelectionBox() { return true; }
54
55 // Step object in time
56 virtual void step(float dtime, ClientEnvironment *env) {}
57
58 // Process a message sent by the server side object
59 virtual void processMessage(const std::string &data) {}
60
61 virtual std::string infoText() { return ""; }
62 virtual std::string debugInfoText() { return ""; }
63
64 /*
65 This takes the return value of
66 ServerActiveObject::getClientInitializationData
67 */
68 virtual void initialize(const std::string &data) {}
69
70 // Create a certain type of ClientActiveObject
71 static std::unique_ptr<ClientActiveObject> create(ActiveObjectType type,
73
74 // If returns true, punch will not be sent to the server
75 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem,
76 const ItemStack *hand_item, float time_from_last_punch = 1000000) { return false; }
77
78protected:
79 // Used for creating objects based on type
80 typedef std::unique_ptr<ClientActiveObject> (*Factory)(Client *client, ClientEnvironment *env);
81 static void registerType(u16 type, Factory f);
84private:
85 // Used for creating objects based on type
86 static std::unordered_map<u16, Factory> m_types;
87};
88
90{
91public:
93
95 {
96 obj = a_obj;
97 d = a_d;
98 }
99
101 {
102 return d < other.d;
103 }
104
105private:
106 f32 d;
107};
ActiveObjectType
Definition activeobject.h:14
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:207
Definition activeobject.h:149
Definition clientobject.h:27
virtual const v3f getPosition() const
Definition clientobject.h:40
virtual scene::AnimatedMeshSceneNode * getAnimatedMeshSceneNode() const
Definition clientobject.h:44
virtual bool directReportPunch(v3f dir, const ItemStack *punchitem, const ItemStack *hand_item, float time_from_last_punch=1000000)
Definition clientobject.h:75
virtual std::string infoText()
Definition clientobject.h:61
std::unique_ptr< ClientActiveObject >(* Factory)(Client *client, ClientEnvironment *env)
Definition clientobject.h:80
virtual bool getCollisionBox(aabb3f *toset) const
Definition clientobject.h:37
virtual bool collideWithObjects() const
Definition clientobject.h:39
virtual void initialize(const std::string &data)
Definition clientobject.h:68
virtual void updateAttachments()
Definition clientobject.h:51
virtual scene::ISceneNode * getSceneNode() const
Definition clientobject.h:42
virtual bool isLocalPlayer() const
Definition clientobject.h:46
virtual std::string debugInfoText()
Definition clientobject.h:62
static void registerType(u16 type, Factory f)
Definition clientobject.cpp:42
virtual void processMessage(const std::string &data)
Definition clientobject.h:59
virtual ClientActiveObject * getParent() const
Definition clientobject.h:48
virtual void step(float dtime, ClientEnvironment *env)
Definition clientobject.h:56
virtual bool doShowSelectionBox()
Definition clientobject.h:53
virtual void updateLight(u32 day_night_ratio)
Definition clientobject.h:35
virtual const v3f getVelocity() const
Definition clientobject.h:41
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env)
Definition clientobject.cpp:12
virtual bool getSelectionBox(aabb3f *toset) const
Definition clientobject.h:38
Client * m_client
Definition clientobject.h:82
virtual const std::unordered_set< object_t > & getAttachmentChildIds() const
Definition clientobject.h:49
static std::unique_ptr< ClientActiveObject > create(ActiveObjectType type, Client *client, ClientEnvironment *env)
Definition clientobject.cpp:25
static std::unordered_map< u16, Factory > m_types
Definition clientobject.h:86
virtual void removeFromScene(bool permanent)
Definition clientobject.h:33
virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)=0
virtual ~ClientActiveObject()
Definition clientobject.cpp:20
ClientEnvironment * m_env
Definition clientobject.h:83
Definition clientenvironment.h:54
Definition client.h:106
Definition clientobject.h:90
ClientActiveObject * obj
Definition clientobject.h:92
DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
Definition clientobject.h:94
f32 d
Definition clientobject.h:106
bool operator<(const DistanceSortedActiveObject &other) const
Definition clientobject.h:100
Definition texturesource.h:45
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition camera.h:24
Definition inventory.h:21