Luanti 5.10.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;
17class IGameDef;
18class LocalPlayer;
19struct ItemStack;
21
22namespace irr::scene
23{
24 class IAnimatedMeshSceneNode;
25 class ISceneNode;
26 class ISceneManager;
27}
28
30{
31public:
33 virtual ~ClientActiveObject();
34
35 virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) = 0;
36 virtual void removeFromScene(bool permanent) {}
37
38 virtual void updateLight(u32 day_night_ratio) {}
39
40 virtual bool getCollisionBox(aabb3f *toset) const { return false; }
41 virtual bool getSelectionBox(aabb3f *toset) const { return false; }
42 virtual bool collideWithObjects() const { return false; }
43 virtual const v3f getPosition() const { return v3f(0.0f); } // in BS-space
44 virtual const v3f getVelocity() const { return v3f(0.0f); } // in BS-space
45 virtual scene::ISceneNode *getSceneNode() const
46 { return NULL; }
47 virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() const
48 { return NULL; }
49 virtual bool isLocalPlayer() const { return false; }
50
51 virtual ClientActiveObject *getParent() const { return nullptr; };
52 virtual const std::unordered_set<object_t> &getAttachmentChildIds() const
53 { static std::unordered_set<object_t> rv; return rv; }
54 virtual void updateAttachments() {};
55
56 virtual bool doShowSelectionBox() { return true; }
57
58 // Step object in time
59 virtual void step(float dtime, ClientEnvironment *env) {}
60
61 // Process a message sent by the server side object
62 virtual void processMessage(const std::string &data) {}
63
64 virtual std::string infoText() { return ""; }
65 virtual std::string debugInfoText() { 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 std::unique_ptr<ClientActiveObject> create(ActiveObjectType type,
76
77 // If returns true, punch will not be sent to the server
78 virtual bool directReportPunch(v3f dir, const ItemStack *punchitem = nullptr,
79 float time_from_last_punch = 1000000) { return false; }
80
81protected:
82 // Used for creating objects based on type
83 typedef std::unique_ptr<ClientActiveObject> (*Factory)(Client *client, ClientEnvironment *env);
84 static void registerType(u16 type, Factory f);
87private:
88 // Used for creating objects based on type
89 static std::unordered_map<u16, Factory> m_types;
90};
91
93{
94public:
96
98 {
99 obj = a_obj;
100 d = a_d;
101 }
102
104 {
105 return d < other.d;
106 }
107
108private:
109 f32 d;
110};
ActiveObjectType
Definition activeobject.h:14
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:191
Definition activeobject.h:141
Definition clientobject.h:30
virtual const v3f getPosition() const
Definition clientobject.h:43
virtual std::string infoText()
Definition clientobject.h:64
std::unique_ptr< ClientActiveObject >(* Factory)(Client *client, ClientEnvironment *env)
Definition clientobject.h:83
virtual bool getCollisionBox(aabb3f *toset) const
Definition clientobject.h:40
virtual bool collideWithObjects() const
Definition clientobject.h:42
virtual void initialize(const std::string &data)
Definition clientobject.h:71
virtual void updateAttachments()
Definition clientobject.h:54
virtual scene::ISceneNode * getSceneNode() const
Definition clientobject.h:45
virtual bool isLocalPlayer() const
Definition clientobject.h:49
virtual std::string debugInfoText()
Definition clientobject.h:65
static void registerType(u16 type, Factory f)
Definition clientobject.cpp:43
virtual void processMessage(const std::string &data)
Definition clientobject.h:62
virtual ClientActiveObject * getParent() const
Definition clientobject.h:51
virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=nullptr, float time_from_last_punch=1000000)
Definition clientobject.h:78
virtual void step(float dtime, ClientEnvironment *env)
Definition clientobject.h:59
virtual bool doShowSelectionBox()
Definition clientobject.h:56
virtual void updateLight(u32 day_night_ratio)
Definition clientobject.h:38
virtual const v3f getVelocity() const
Definition clientobject.h:44
ClientActiveObject(u16 id, Client *client, ClientEnvironment *env)
Definition clientobject.cpp:13
virtual bool getSelectionBox(aabb3f *toset) const
Definition clientobject.h:41
Client * m_client
Definition clientobject.h:85
virtual const std::unordered_set< object_t > & getAttachmentChildIds() const
Definition clientobject.h:52
static std::unique_ptr< ClientActiveObject > create(ActiveObjectType type, Client *client, ClientEnvironment *env)
Definition clientobject.cpp:26
static std::unordered_map< u16, Factory > m_types
Definition clientobject.h:89
virtual void removeFromScene(bool permanent)
Definition clientobject.h:36
virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)=0
virtual scene::IAnimatedMeshSceneNode * getAnimatedMeshSceneNode() const
Definition clientobject.h:47
virtual ~ClientActiveObject()
Definition clientobject.cpp:21
ClientEnvironment * m_env
Definition clientobject.h:86
Definition clientenvironment.h:54
Definition client.h:105
Definition clientobject.h:93
ClientActiveObject * obj
Definition clientobject.h:95
DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
Definition clientobject.h:97
f32 d
Definition clientobject.h:109
bool operator<(const DistanceSortedActiveObject &other) const
Definition clientobject.h:103
Definition gamedef.h:36
Definition texturesource.h:36
Definition localplayer.h:49
Definition wieldmesh.h:90
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition inventory.h:19