Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
clientenvironment.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2017 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "environment.h"
8#include "util/numeric.h" // IntervalLimiter
9#include "activeobjectmgr.h" // client::ActiveObjectMgr
10#include "irr_ptr.h"
11#include "config.h"
12#include <set>
13
14#if !IS_CLIENT_BUILD
15#error Do not include in server builds
16#endif
17
19class ClientMap;
20class ClientScripting;
22class GenericCAO;
23class LocalPlayer;
24
25/*
26 The client-side environment.
27
28 This is not thread-safe.
29 Must be called from main (irrlicht) thread (uses the SceneManager)
30 Client uses an environment mutex.
31*/
32
38
40{
42 union {
43 //struct{
44 //} none;
45 struct{
46 u16 amount;
49 };
50};
51
52typedef std::unordered_map<u16, ClientActiveObject*> ClientActiveObjectMap;
54{
55public:
56 ClientEnvironment(irr_ptr<ClientMap> map, ITextureSource *texturesource, Client *client);
58
59 Map & getMap();
61
62 Client *getGameDef() { return m_client; }
63 void setScript(ClientScripting *script) { m_script = script; }
64
65 void step(f32 dtime);
66
67 virtual void setLocalPlayer(LocalPlayer *player);
69
70 /*
71 ClientSimpleObjects
72 */
73
75
76 /*
77 ActiveObjects
78 */
79
85
86 /*
87 Adds an active object to the environment.
88 Environment handles deletion of object.
89 Object may be deleted by environment immediately.
90 If id of object is 0, assigns a free id to it.
91 Returns the id of the object.
92 Returns 0 if not added and thus deleted.
93 */
94 u16 addActiveObject(std::unique_ptr<ClientActiveObject> object);
95
96 void addActiveObject(u16 id, u8 type, const std::string &init_data);
97 void removeActiveObject(u16 id);
98
99 void processActiveObjectMessage(u16 id, const std::string &data);
100
101 /*
102 Callbacks for activeobjects
103 */
104
105 void damageLocalPlayer(u16 damage, bool handle_hp=true);
106
107 /*
108 Client likes to call these
109 */
110
111 // Get all nearby objects
112 void getActiveObjects(const v3f &origin, f32 max_d,
113 std::vector<DistanceSortedActiveObject> &dest)
114 {
115 return m_ao_manager.getActiveObjects(origin, max_d, dest);
116 }
117
118 bool hasClientEnvEvents() const { return !m_client_event_queue.empty(); }
119
120 // Get event from queue. If queue is empty, it triggers an assertion failure.
122
123 virtual void getSelectedActiveObjects(
124 const core::line3d<f32> &shootline_on_map,
125 std::vector<PointedThing> &objects,
126 const std::optional<Pointabilities> &pointabilities
127 );
128
129 const std::set<std::string> &getPlayerNames() { return m_player_names; }
130 void addPlayerName(const std::string &name) { m_player_names.insert(name); }
131 void removePlayerName(const std::string &name) { m_player_names.erase(name); }
132 void updateCameraOffset(const v3s16 &camera_offset)
133 { m_camera_offset = camera_offset; }
135
136 void updateFrameTime(bool is_paused);
137 u64 getFrameTime() const { return m_frame_time; }
138 u64 getFrameTimeDelta() const { return m_frame_dtime; }
139
140private:
141 irr_ptr<ClientMap> m_map;
147 std::vector<ClientSimpleObject*> m_simple_objects;
148 std::queue<ClientEnvEvent> m_client_event_queue;
150 std::set<std::string> m_player_names;
155};
T * getActiveObject(u16 id)
Definition activeobjectmgr.h:48
Definition clientobject.h:30
Definition clientenvironment.h:54
irr_ptr< ClientMap > m_map
Definition clientenvironment.h:141
u64 getFrameTimeDelta() const
Definition clientenvironment.h:138
ClientScripting * m_script
Definition clientenvironment.h:145
bool hasClientEnvEvents() const
Definition clientenvironment.h:118
client::ActiveObjectMgr m_ao_manager
Definition clientenvironment.h:146
virtual void getSelectedActiveObjects(const core::line3d< f32 > &shootline_on_map, std::vector< PointedThing > &objects, const std::optional< Pointabilities > &pointabilities)
Definition clientenvironment.cpp:425
IntervalLimiter m_active_object_light_update_interval
Definition clientenvironment.h:149
void removePlayerName(const std::string &name)
Definition clientenvironment.h:131
u64 m_frame_time_pause_accumulator
Definition clientenvironment.h:154
GenericCAO * getGenericCAO(u16 id)
Definition clientenvironment.cpp:290
void addSimpleObject(ClientSimpleObject *simple)
Definition clientenvironment.cpp:285
void step(f32 dtime)
Definition clientenvironment.cpp:74
ClientMap & getClientMap()
Definition clientenvironment.cpp:58
void processActiveObjectMessage(u16 id, const std::string &data)
Definition clientenvironment.cpp:368
void updateCameraOffset(const v3s16 &camera_offset)
Definition clientenvironment.h:132
ClientEnvironment(irr_ptr< ClientMap > map, ITextureSource *texturesource, Client *client)
Definition clientenvironment.cpp:31
void removeActiveObject(u16 id)
Definition clientenvironment.cpp:352
std::set< std::string > m_player_names
Definition clientenvironment.h:150
u64 m_frame_time
Definition clientenvironment.h:152
const std::set< std::string > & getPlayerNames()
Definition clientenvironment.h:129
Client * m_client
Definition clientenvironment.h:144
void damageLocalPlayer(u16 damage, bool handle_hp=true)
Definition clientenvironment.cpp:392
void getActiveObjects(const v3f &origin, f32 max_d, std::vector< DistanceSortedActiveObject > &dest)
Definition clientenvironment.h:112
LocalPlayer * m_local_player
Definition clientenvironment.h:142
ClientActiveObject * getActiveObject(u16 id)
Definition clientenvironment.h:81
v3s16 m_camera_offset
Definition clientenvironment.h:151
ClientEnvEvent getClientEnvEvent()
Definition clientenvironment.cpp:415
LocalPlayer * getLocalPlayer() const
Definition clientenvironment.h:68
std::vector< ClientSimpleObject * > m_simple_objects
Definition clientenvironment.h:147
Client * getGameDef()
Definition clientenvironment.h:62
u64 getFrameTime() const
Definition clientenvironment.h:137
void updateFrameTime(bool is_paused)
Definition clientenvironment.cpp:476
void addPlayerName(const std::string &name)
Definition clientenvironment.h:130
u64 m_frame_dtime
Definition clientenvironment.h:153
~ClientEnvironment()
Definition clientenvironment.cpp:40
std::queue< ClientEnvEvent > m_client_event_queue
Definition clientenvironment.h:148
ITextureSource * m_texturesource
Definition clientenvironment.h:143
virtual void setLocalPlayer(LocalPlayer *player)
Definition clientenvironment.cpp:63
u16 addActiveObject(std::unique_ptr< ClientActiveObject > object)
Definition clientenvironment.cpp:299
v3s16 getCameraOffset() const
Definition clientenvironment.h:134
void setScript(ClientScripting *script)
Definition clientenvironment.h:63
Map & getMap()
Definition clientenvironment.cpp:53
Definition clientmap.h:46
Definition scripting_client.h:23
Definition clientsimpleobject.h:11
Definition client.h:105
Definition environment.h:34
Definition content_cao.h:56
Definition texturesource.h:36
Definition numeric.h:347
Definition localplayer.h:49
Definition map.h:101
Definition activeobjectmgr.h:15
void getActiveObjects(const v3f &origin, f32 max_d, std::vector< DistanceSortedActiveObject > &dest)
Definition activeobjectmgr.cpp:75
ClientEnvEventType
Definition clientenvironment.h:34
@ CEE_PLAYER_DAMAGE
Definition clientenvironment.h:36
@ CEE_NONE
Definition clientenvironment.h:35
std::unordered_map< u16, ClientActiveObject * > ClientActiveObjectMap
Definition clientenvironment.h:52
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition clientenvironment.h:40
ClientEnvEventType type
Definition clientenvironment.h:41
struct ClientEnvEvent::@0::@2 player_damage
u16 amount
Definition clientenvironment.h:46
bool send_to_server
Definition clientenvironment.h:47