/*
-Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef ENVIRONMENT_HEADER
-#define ENVIRONMENT_HEADER
+#pragma once
/*
This class is the game's environment.
- The map
- Players
- Other objects
- - The current time in the game (actually it only contains the brightness)
+ - The current time in the game
- etc.
*/
#include <list>
-#include "common_irrlicht.h"
-#include "player.h"
-#include "map.h"
-#include <ostream>
+#include <queue>
+#include <map>
+#include <atomic>
+#include <mutex>
+#include "irr_v3d.h"
+#include "network/networkprotocol.h" // for AccessDeniedCode
+#include "util/basic_macros.h"
+
+class IGameDef;
+class Map;
+struct PointedThing;
+class RaycastState;
class Environment
{
public:
// Environment will delete the map passed to the constructor
- Environment();
- virtual ~Environment();
+ Environment(IGameDef *gamedef);
+ virtual ~Environment() = default;
+ DISABLE_CLASS_COPY(Environment);
/*
Step everything in environment.
*/
virtual void step(f32 dtime) = 0;
- virtual Map & getMap() = 0;
-
- virtual void addPlayer(Player *player);
- void removePlayer(u16 peer_id);
- Player * getPlayer(u16 peer_id);
- Player * getPlayer(const char *name);
- core::list<Player*> getPlayers();
- core::list<Player*> getPlayers(bool ignore_disconnected);
- void printPlayers(std::ostream &o);
-
- void setDayNightRatio(u32 r);
- u32 getDayNightRatio();
-
-protected:
- // peer_ids in here should be unique, except that there may be many 0s
- core::list<Player*> m_players;
- // Brightness
- u32 m_daynight_ratio;
-};
-
-/*
- The server-side environment.
-
- This is not thread-safe. Server uses an environment mutex.
-*/
-
-#include "serverobject.h"
-
-class ServerEnvironment : public Environment
-{
-public:
- ServerEnvironment(ServerMap *map);
- ~ServerEnvironment();
+ virtual Map &getMap() = 0;
- Map & getMap()
- {
- return *m_map;
- }
-
- ServerMap & getServerMap()
- {
- return *m_map;
- }
-
- void step(f32 dtime);
-
- void serializePlayers(const std::string &savedir);
- void deSerializePlayers(const std::string &savedir);
-
- /*
- ActiveObjects
- */
-
- ServerActiveObject* getActiveObject(u16 id);
-
- /*
- Adds an active object to the environment.
- Environment handles deletion of object.
- Object may be deleted by environment immediately.
- If id of object is 0, assigns a free id to it.
- Returns the id of the object.
- Returns 0 if not added and thus deleted.
- */
- u16 addActiveObject(ServerActiveObject *object);
-
- /*
- Finds out what new objects have been added to
- inside a radius around a position
- */
- void getAddedActiveObjects(v3s16 pos, s16 radius,
- core::map<u16, bool> ¤t_objects,
- core::map<u16, bool> &added_objects);
-
- /*
- Finds out what new objects have been removed from
- inside a radius around a position
- */
- void getRemovedActiveObjects(v3s16 pos, s16 radius,
- core::map<u16, bool> ¤t_objects,
- core::map<u16, bool> &removed_objects);
-
- /*
- Gets the next message emitted by some active object.
- Returns a message with id=0 if no messages are available.
- */
- ActiveObjectMessage getActiveObjectMessage();
-
-private:
- ServerMap *m_map;
- core::map<u16, ServerActiveObject*> m_active_objects;
- Queue<ActiveObjectMessage> m_active_object_messages;
- float m_random_spawn_timer;
-};
+ u32 getDayNightRatio();
-#ifndef SERVER
+ // 0-23999
+ virtual void setTimeOfDay(u32 time);
+ u32 getTimeOfDay();
+ float getTimeOfDayF();
-#include "clientobject.h"
+ void stepTimeOfDay(float dtime);
-/*
- The client-side environment.
+ void setTimeOfDaySpeed(float speed);
- This is not thread-safe.
- Must be called from main (irrlicht) thread (uses the SceneManager)
- Client uses an environment mutex.
-*/
+ void setDayNightRatioOverride(bool enable, u32 value);
-class ClientEnvironment : public Environment
-{
-public:
- ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr);
- ~ClientEnvironment();
+ u32 getDayCount();
- Map & getMap()
- {
- return *m_map;
- }
+ /*!
+ * Gets the objects pointed by the shootline as
+ * pointed things.
+ * If this is a client environment, the local player
+ * won't be returned.
+ * @param[in] shootline_on_map the shootline for
+ * the test in world coordinates
+ *
+ * @param[out] objects found objects
+ */
+ virtual void getSelectedActiveObjects(const core::line3d<f32> &shootline_on_map,
+ std::vector<PointedThing> &objects) = 0;
- ClientMap & getClientMap()
- {
- return *m_map;
- }
+ /*!
+ * Returns the next node or object the shootline meets.
+ * @param state current state of the raycast
+ * @result output, will contain the next pointed thing
+ */
+ void continueRaycast(RaycastState *state, PointedThing *result);
- void step(f32 dtime);
+ // counter used internally when triggering ABMs
+ u32 m_added_objects;
- virtual void addPlayer(Player *player);
- LocalPlayer * getLocalPlayer();
+ IGameDef *getGameDef() { return m_gamedef; }
- void updateMeshes(v3s16 blockpos);
- void expireMeshes(bool only_daynight_diffed);
+protected:
+ std::atomic<float> m_time_of_day_speed;
/*
- ActiveObjects
- */
-
- ClientActiveObject* getActiveObject(u16 id);
-
+ * Below: values managed by m_time_lock
+ */
+ // Time of day in milli-hours (0-23999), determines day and night
+ u32 m_time_of_day;
+ // Time of day in 0...1
+ float m_time_of_day_f;
+ // Stores the skew created by the float -> u32 conversion
+ // to be applied at next conversion, so that there is no real skew.
+ float m_time_conversion_skew = 0.0f;
+ // Overriding the day-night ratio is useful for custom sky visuals
+ bool m_enable_day_night_ratio_override = false;
+ u32 m_day_night_ratio_override = 0.0f;
+ // Days from the server start, accounts for time shift
+ // in game (e.g. /time or bed usage)
+ std::atomic<u32> m_day_count;
/*
- Adds an active object to the environment.
- Environment handles deletion of object.
- Object may be deleted by environment immediately.
- If id of object is 0, assigns a free id to it.
- Returns the id of the object.
- Returns 0 if not added and thus deleted.
- */
- u16 addActiveObject(ClientActiveObject *object);
-
- void addActiveObject(u16 id, u8 type, const std::string &init_data);
- void removeActiveObject(u16 id);
-
- void processActiveObjectMessage(u16 id, const std::string &data);
+ * Above: values managed by m_time_lock
+ */
+
+ /* TODO: Add a callback function so these can be updated when a setting
+ * changes. At this point in time it doesn't matter (e.g. /set
+ * is documented to change server settings only)
+ *
+ * TODO: Local caching of settings is not optimal and should at some stage
+ * be updated to use a global settings object for getting thse values
+ * (as opposed to the this local caching). This can be addressed in
+ * a later release.
+ */
+ bool m_cache_enable_shaders;
+ float m_cache_active_block_mgmt_interval;
+ float m_cache_abm_interval;
+ float m_cache_nodetimer_interval;
+
+ IGameDef *m_gamedef;
private:
- ClientMap *m_map;
- scene::ISceneManager *m_smgr;
- core::map<u16, ClientActiveObject*> m_active_objects;
+ std::mutex m_time_lock;
};
-
-#endif
-
-#endif
-