3 Copyright (C) 2010-2017 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef CLIENT_ENVIRONMENT_HEADER
21 #define CLIENT_ENVIRONMENT_HEADER
23 #include <IrrlichtDevice.h>
24 #include <ISceneManager.h>
25 #include "environment.h"
26 #include "clientobject.h"
28 class ClientSimpleObject;
30 class ClientScripting;
31 class ClientActiveObject;
37 The client-side environment.
39 This is not thread-safe.
40 Must be called from main (irrlicht) thread (uses the SceneManager)
41 Client uses an environment mutex.
44 enum ClientEnvEventType
53 ClientEnvEventType type;
67 typedef std::unordered_map<u16, ClientActiveObject*> ClientActiveObjectMap;
68 class ClientEnvironment : public Environment
71 ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
72 ITextureSource *texturesource, Client *client,
73 IrrlichtDevice *device);
77 ClientMap & getClientMap();
79 Client *getGameDef() { return m_client; }
80 void setScript(ClientScripting *script) { m_script = script; }
84 virtual void setLocalPlayer(LocalPlayer *player);
85 LocalPlayer *getLocalPlayer() { return m_local_player; }
91 void addSimpleObject(ClientSimpleObject *simple);
97 GenericCAO* getGenericCAO(u16 id);
98 ClientActiveObject* getActiveObject(u16 id);
101 Adds an active object to the environment.
102 Environment handles deletion of object.
103 Object may be deleted by environment immediately.
104 If id of object is 0, assigns a free id to it.
105 Returns the id of the object.
106 Returns 0 if not added and thus deleted.
108 u16 addActiveObject(ClientActiveObject *object);
110 void addActiveObject(u16 id, u8 type, const std::string &init_data);
111 void removeActiveObject(u16 id);
113 void processActiveObjectMessage(u16 id, const std::string &data);
116 Callbacks for activeobjects
119 void damageLocalPlayer(u8 damage, bool handle_hp=true);
120 void updateLocalPlayerBreath(u16 breath);
123 Client likes to call these
126 // Get all nearby objects
127 void getActiveObjects(v3f origin, f32 max_d,
128 std::vector<DistanceSortedActiveObject> &dest);
130 bool hasClientEnvEvents() const { return !m_client_event_queue.empty(); }
131 // Get event from queue. If queue is empty, it triggers an assertion failure.
132 ClientEnvEvent getClientEnvEvent();
135 * Gets closest object pointed by the shootline.
136 * Returns NULL if not found.
138 * \param[in] shootline_on_map the shootline for
139 * the test in world coordinates
140 * \param[out] intersection_point the first point where
141 * the shootline meets the object. Valid only if
142 * not NULL is returned.
143 * \param[out] intersection_normal the normal vector of
144 * the intersection, pointing outwards. Zero vector if
145 * the shootline starts in an active object.
146 * Valid only if not NULL is returned.
148 ClientActiveObject * getSelectedActiveObject(
149 const core::line3d<f32> &shootline_on_map,
150 v3f *intersection_point,
151 v3s16 *intersection_normal
155 * Performs a raycast on the world.
156 * Returns the first thing the shootline meets.
158 * @param[in] shootline the shootline, starting from
159 * the camera position. This also gives the maximal distance
161 * @param[in] liquids_pointable if false, liquids are ignored
162 * @param[in] look_for_object if false, objects are ignored
164 PointedThing getPointedThing(
165 core::line3d<f32> shootline,
166 bool liquids_pointable,
167 bool look_for_object);
169 u16 attachement_parent_ids[USHRT_MAX + 1];
171 const std::list<std::string> &getPlayerNames() { return m_player_names; }
172 void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
173 void removePlayerName(const std::string &name) { m_player_names.remove(name); }
174 void updateCameraOffset(v3s16 camera_offset)
175 { m_camera_offset = camera_offset; }
176 v3s16 getCameraOffset() const { return m_camera_offset; }
179 LocalPlayer *m_local_player = nullptr;
180 scene::ISceneManager *m_smgr;
181 ITextureSource *m_texturesource;
183 ClientScripting *m_script = nullptr;
184 IrrlichtDevice *m_irr;
185 ClientActiveObjectMap m_active_objects;
186 std::vector<ClientSimpleObject*> m_simple_objects;
187 std::queue<ClientEnvEvent> m_client_event_queue;
188 IntervalLimiter m_active_object_light_update_interval;
189 IntervalLimiter m_lava_hurt_interval;
190 IntervalLimiter m_drowning_interval;
191 IntervalLimiter m_breathing_interval;
192 std::list<std::string> m_player_names;
193 v3s16 m_camera_offset;