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"
42 // Environment will delete the map passed to the constructor
44 virtual ~Environment();
47 Step everything in environment.
52 virtual void step(f32 dtime) = 0;
54 virtual Map & getMap() = 0;
56 virtual void addPlayer(Player *player);
57 void removePlayer(u16 peer_id);
58 Player * getPlayer(u16 peer_id);
59 Player * getPlayer(const char *name);
60 Player * getRandomConnectedPlayer();
61 Player * getNearestConnectedPlayer(v3f pos);
62 core::list<Player*> getPlayers();
63 core::list<Player*> getPlayers(bool ignore_disconnected);
64 void printPlayers(std::ostream &o);
66 void setDayNightRatio(u32 r);
67 u32 getDayNightRatio();
70 // peer_ids in here should be unique, except that there may be many 0s
71 core::list<Player*> m_players;
77 The server-side environment.
79 This is not thread-safe. Server uses an environment mutex.
82 #include "serverobject.h"
86 class ServerEnvironment : public Environment
89 ServerEnvironment(ServerMap *map, Server *server);
97 ServerMap & getServerMap()
107 void step(f32 dtime);
109 void serializePlayers(const std::string &savedir);
110 void deSerializePlayers(const std::string &savedir);
116 ServerActiveObject* getActiveObject(u16 id);
119 Adds an active object to the environment.
120 Environment handles deletion of object.
121 Object may be deleted by environment immediately.
122 If id of object is 0, assigns a free id to it.
123 Returns the id of the object.
124 Returns 0 if not added and thus deleted.
126 u16 addActiveObject(ServerActiveObject *object);
129 Finds out what new objects have been added to
130 inside a radius around a position
132 void getAddedActiveObjects(v3s16 pos, s16 radius,
133 core::map<u16, bool> ¤t_objects,
134 core::map<u16, bool> &added_objects);
137 Finds out what new objects have been removed from
138 inside a radius around a position
140 void getRemovedActiveObjects(v3s16 pos, s16 radius,
141 core::map<u16, bool> ¤t_objects,
142 core::map<u16, bool> &removed_objects);
145 Gets the next message emitted by some active object.
146 Returns a message with id=0 if no messages are available.
148 ActiveObjectMessage getActiveObjectMessage();
153 core::map<u16, ServerActiveObject*> m_active_objects;
154 Queue<ActiveObjectMessage> m_active_object_messages;
155 float m_random_spawn_timer;
160 #include "clientobject.h"
163 The client-side environment.
165 This is not thread-safe.
166 Must be called from main (irrlicht) thread (uses the SceneManager)
167 Client uses an environment mutex.
170 class ClientEnvironment : public Environment
173 ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
174 ~ClientEnvironment();
181 ClientMap & getClientMap()
186 void step(f32 dtime);
188 virtual void addPlayer(Player *player);
189 LocalPlayer * getLocalPlayer();
191 void updateMeshes(v3s16 blockpos);
192 void expireMeshes(bool only_daynight_diffed);
198 ClientActiveObject* getActiveObject(u16 id);
201 Adds an active object to the environment.
202 Environment handles deletion of object.
203 Object may be deleted by environment immediately.
204 If id of object is 0, assigns a free id to it.
205 Returns the id of the object.
206 Returns 0 if not added and thus deleted.
208 u16 addActiveObject(ClientActiveObject *object);
210 void addActiveObject(u16 id, u8 type, const std::string &init_data);
211 void removeActiveObject(u16 id);
213 void processActiveObjectMessage(u16 id, const std::string &data);
217 scene::ISceneManager *m_smgr;
218 core::map<u16, ClientActiveObject*> m_active_objects;