3 Copyright (C) 2010 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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 ENVIRONMENT_HEADER
21 #define ENVIRONMENT_HEADER
24 This class is the game's environment.
29 - The current time in the game (actually it only contains the brightness)
34 #include "common_irrlicht.h"
43 // Environment will delete the map passed to the constructor
45 virtual ~Environment();
48 Step everything in environment.
53 virtual void step(f32 dtime) = 0;
55 virtual Map & getMap() = 0;
57 virtual void addPlayer(Player *player);
58 void removePlayer(u16 peer_id);
59 Player * getPlayer(u16 peer_id);
60 Player * getPlayer(const char *name);
61 Player * getRandomConnectedPlayer();
62 Player * getNearestConnectedPlayer(v3f pos);
63 core::list<Player*> getPlayers();
64 core::list<Player*> getPlayers(bool ignore_disconnected);
65 void printPlayers(std::ostream &o);
67 void setDayNightRatio(u32 r);
68 u32 getDayNightRatio();
71 // peer_ids in here should be unique, except that there may be many 0s
72 core::list<Player*> m_players;
78 The server-side environment.
80 This is not thread-safe. Server uses an environment mutex.
83 #include "serverobject.h"
87 class ServerEnvironment : public Environment
90 ServerEnvironment(ServerMap *map, Server *server);
98 ServerMap & getServerMap()
108 void step(f32 dtime);
110 void serializePlayers(const std::string &savedir);
111 void deSerializePlayers(const std::string &savedir);
117 ServerActiveObject* getActiveObject(u16 id);
120 Adds an active object to the environment.
121 Environment handles deletion of object.
122 Object may be deleted by environment immediately.
123 If id of object is 0, assigns a free id to it.
124 Returns the id of the object.
125 Returns 0 if not added and thus deleted.
127 u16 addActiveObject(ServerActiveObject *object);
130 Finds out what new objects have been added to
131 inside a radius around a position
133 void getAddedActiveObjects(v3s16 pos, s16 radius,
134 core::map<u16, bool> ¤t_objects,
135 core::map<u16, bool> &added_objects);
138 Finds out what new objects have been removed from
139 inside a radius around a position
141 void getRemovedActiveObjects(v3s16 pos, s16 radius,
142 core::map<u16, bool> ¤t_objects,
143 core::map<u16, bool> &removed_objects);
146 Gets the next message emitted by some active object.
147 Returns a message with id=0 if no messages are available.
149 ActiveObjectMessage getActiveObjectMessage();
154 core::map<u16, ServerActiveObject*> m_active_objects;
155 Queue<ActiveObjectMessage> m_active_object_messages;
156 float m_random_spawn_timer;
157 float m_send_recommended_timer;
158 IntervalLimiter m_object_management_interval;
163 #include "clientobject.h"
166 The client-side environment.
168 This is not thread-safe.
169 Must be called from main (irrlicht) thread (uses the SceneManager)
170 Client uses an environment mutex.
173 enum ClientEnvEventType
179 struct ClientEnvEvent
181 ClientEnvEventType type;
191 class ClientEnvironment : public Environment
194 ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
195 ~ClientEnvironment();
202 ClientMap & getClientMap()
207 void step(f32 dtime);
209 virtual void addPlayer(Player *player);
210 LocalPlayer * getLocalPlayer();
212 void updateMeshes(v3s16 blockpos);
213 void expireMeshes(bool only_daynight_diffed);
219 ClientActiveObject* getActiveObject(u16 id);
222 Adds an active object to the environment.
223 Environment handles deletion of object.
224 Object may be deleted by environment immediately.
225 If id of object is 0, assigns a free id to it.
226 Returns the id of the object.
227 Returns 0 if not added and thus deleted.
229 u16 addActiveObject(ClientActiveObject *object);
231 void addActiveObject(u16 id, u8 type, const std::string &init_data);
232 void removeActiveObject(u16 id);
234 void processActiveObjectMessage(u16 id, const std::string &data);
237 Callbacks for activeobjects
240 void damageLocalPlayer(u8 damage);
243 Client likes to call these
246 // Get all nearby objects
247 void getActiveObjects(v3f origin, f32 max_d,
248 core::array<DistanceSortedActiveObject> &dest);
250 // Get event from queue. CEE_NONE is returned if queue is empty.
251 ClientEnvEvent getClientEvent();
255 scene::ISceneManager *m_smgr;
256 core::map<u16, ClientActiveObject*> m_active_objects;
257 Queue<ClientEnvEvent> m_client_event_queue;