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 ClientActiveObject;
35 The client-side environment.
37 This is not thread-safe.
38 Must be called from main (irrlicht) thread (uses the SceneManager)
39 Client uses an environment mutex.
42 enum ClientEnvEventType
51 ClientEnvEventType type;
65 class ClientEnvironment : public Environment
68 ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
69 ITextureSource *texturesource, IGameDef *gamedef,
70 IrrlichtDevice *device);
74 ClientMap & getClientMap();
76 IGameDef *getGameDef()
81 virtual void setLocalPlayer(LocalPlayer *player);
82 LocalPlayer *getLocalPlayer() { return m_local_player; }
88 void addSimpleObject(ClientSimpleObject *simple);
94 GenericCAO* getGenericCAO(u16 id);
95 ClientActiveObject* getActiveObject(u16 id);
98 Adds an active object to the environment.
99 Environment handles deletion of object.
100 Object may be deleted by environment immediately.
101 If id of object is 0, assigns a free id to it.
102 Returns the id of the object.
103 Returns 0 if not added and thus deleted.
105 u16 addActiveObject(ClientActiveObject *object);
107 void addActiveObject(u16 id, u8 type, const std::string &init_data);
108 void removeActiveObject(u16 id);
110 void processActiveObjectMessage(u16 id, const std::string &data);
113 Callbacks for activeobjects
116 void damageLocalPlayer(u8 damage, bool handle_hp=true);
117 void updateLocalPlayerBreath(u16 breath);
120 Client likes to call these
123 // Get all nearby objects
124 void getActiveObjects(v3f origin, f32 max_d,
125 std::vector<DistanceSortedActiveObject> &dest);
127 // Get event from queue. CEE_NONE is returned if queue is empty.
128 ClientEnvEvent getClientEvent();
131 * Gets closest object pointed by the shootline.
132 * Returns NULL if not found.
134 * \param[in] shootline_on_map the shootline for
135 * the test in world coordinates
136 * \param[out] intersection_point the first point where
137 * the shootline meets the object. Valid only if
138 * not NULL is returned.
139 * \param[out] intersection_normal the normal vector of
140 * the intersection, pointing outwards. Zero vector if
141 * the shootline starts in an active object.
142 * Valid only if not NULL is returned.
144 ClientActiveObject * getSelectedActiveObject(
145 const core::line3d<f32> &shootline_on_map,
146 v3f *intersection_point,
147 v3s16 *intersection_normal
151 * Performs a raycast on the world.
152 * Returns the first thing the shootline meets.
154 * @param[in] shootline the shootline, starting from
155 * the camera position. This also gives the maximal distance
157 * @param[in] liquids_pointable if false, liquids are ignored
158 * @param[in] look_for_object if false, objects are ignored
160 PointedThing getPointedThing(
161 core::line3d<f32> shootline,
162 bool liquids_pointable,
163 bool look_for_object);
165 u16 attachement_parent_ids[USHRT_MAX + 1];
167 const std::list<std::string> &getPlayerNames() { return m_player_names; }
168 void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
169 void removePlayerName(const std::string &name) { m_player_names.remove(name); }
170 void updateCameraOffset(v3s16 camera_offset)
171 { m_camera_offset = camera_offset; }
172 v3s16 getCameraOffset() const { return m_camera_offset; }
175 LocalPlayer *m_local_player;
176 scene::ISceneManager *m_smgr;
177 ITextureSource *m_texturesource;
179 IrrlichtDevice *m_irr;
180 UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
181 std::vector<ClientSimpleObject*> m_simple_objects;
182 std::queue<ClientEnvEvent> m_client_event_queue;
183 IntervalLimiter m_active_object_light_update_interval;
184 IntervalLimiter m_lava_hurt_interval;
185 IntervalLimiter m_drowning_interval;
186 IntervalLimiter m_breathing_interval;
187 std::list<std::string> m_player_names;
188 v3s16 m_camera_offset;