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 core::list<Player*> getPlayers();
61 core::list<Player*> getPlayers(bool ignore_disconnected);
62 void printPlayers(std::ostream &o);
64 void setDayNightRatio(u32 r);
65 u32 getDayNightRatio();
68 // peer_ids in here should be unique, except that there may be many 0s
69 core::list<Player*> m_players;
75 The server-side environment.
77 This is not thread-safe. Server uses an environment mutex.
80 #include "serverobject.h"
82 class ServerEnvironment : public Environment
85 ServerEnvironment(ServerMap *map);
93 ServerMap & getServerMap()
100 void serializePlayers(const std::string &savedir);
101 void deSerializePlayers(const std::string &savedir);
107 ServerActiveObject* getActiveObject(u16 id);
110 Adds an active object to the environment.
111 Environment handles deletion of object.
112 Object may be deleted by environment immediately.
113 If id of object is 0, assigns a free id to it.
114 Returns the id of the object.
115 Returns 0 if not added and thus deleted.
117 u16 addActiveObject(ServerActiveObject *object);
120 Finds out what new objects have been added to
121 inside a radius around a position
123 void getAddedActiveObjects(v3s16 pos, s16 radius,
124 core::map<u16, bool> ¤t_objects,
125 core::map<u16, bool> &added_objects);
128 Finds out what new objects have been removed from
129 inside a radius around a position
131 void getRemovedActiveObjects(v3s16 pos, s16 radius,
132 core::map<u16, bool> ¤t_objects,
133 core::map<u16, bool> &removed_objects);
136 Gets the next message emitted by some active object.
137 Returns a message with id=0 if no messages are available.
139 ActiveObjectMessage getActiveObjectMessage();
143 core::map<u16, ServerActiveObject*> m_active_objects;
144 Queue<ActiveObjectMessage> m_active_object_messages;
145 float m_random_spawn_timer;
150 #include "clientobject.h"
153 The client-side environment.
155 This is not thread-safe.
156 Must be called from main (irrlicht) thread (uses the SceneManager)
157 Client uses an environment mutex.
160 class ClientEnvironment : public Environment
163 ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
164 ~ClientEnvironment();
171 ClientMap & getClientMap()
176 void step(f32 dtime);
178 virtual void addPlayer(Player *player);
179 LocalPlayer * getLocalPlayer();
181 void updateMeshes(v3s16 blockpos);
182 void expireMeshes(bool only_daynight_diffed);
188 ClientActiveObject* getActiveObject(u16 id);
191 Adds an active object to the environment.
192 Environment handles deletion of object.
193 Object may be deleted by environment immediately.
194 If id of object is 0, assigns a free id to it.
195 Returns the id of the object.
196 Returns 0 if not added and thus deleted.
198 u16 addActiveObject(ClientActiveObject *object);
200 void addActiveObject(u16 id, u8 type, const std::string &init_data);
201 void removeActiveObject(u16 id);
203 void processActiveObjectMessage(u16 id, const std::string &data);
207 scene::ISceneManager *m_smgr;
208 core::map<u16, ClientActiveObject*> m_active_objects;