X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fenvironment.h;h=03c21b08ccff55aad7963da7e003876ddf4f8d59;hb=63867b1a372a4d1a4a4ffdec9d0862b094211a89;hp=a62173a11f51a4481fd8fa86399a9d21ce51c82c;hpb=ab433775777c4f5055bcf4d2a1cffc506c4f9961;p=minetest.git diff --git a/src/environment.h b/src/environment.h index a62173a11..03c21b08c 100644 --- a/src/environment.h +++ b/src/environment.h @@ -32,25 +32,24 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#include "irrlichttypes_extrabloated.h" -#include "player.h" -#include +#include +#include "irr_v3d.h" #include "activeobject.h" -#include "util/container.h" #include "util/numeric.h" #include "mapnode.h" #include "mapblock.h" +#include "jthread/jmutex.h" class ServerEnvironment; class ActiveBlockModifier; class ServerActiveObject; -typedef struct lua_State lua_State; class ITextureSource; class IGameDef; class Map; class ServerMap; class ClientMap; -class ScriptApi; +class GameScripting; +class Player; class Environment { @@ -71,16 +70,16 @@ class Environment virtual void addPlayer(Player *player); void removePlayer(u16 peer_id); + void removePlayer(const char *name); Player * getPlayer(u16 peer_id); Player * getPlayer(const char *name); Player * getRandomConnectedPlayer(); Player * getNearestConnectedPlayer(v3f pos); std::list getPlayers(); std::list getPlayers(bool ignore_disconnected); - void printPlayers(std::ostream &o); u32 getDayNightRatio(); - + // 0-23999 virtual void setTimeOfDay(u32 time) { @@ -96,11 +95,18 @@ class Environment void stepTimeOfDay(float dtime); - void setTimeOfDaySpeed(float speed) - { m_time_of_day_speed = speed; } + void setTimeOfDaySpeed(float speed); - float getTimeOfDaySpeed() - { return m_time_of_day_speed; } + float getTimeOfDaySpeed(); + + void setDayNightRatioOverride(bool enable, u32 value) + { + m_enable_day_night_ratio_override = enable; + m_day_night_ratio_override = value; + } + + // counter used internally when triggering ABMs + u32 m_added_objects; protected: // peer_ids in here should be unique, except that there may be many 0s @@ -112,6 +118,24 @@ class Environment float m_time_of_day_speed; // Used to buffer dtime for adding to m_time_of_day float m_time_counter; + // Overriding the day-night ratio is useful for custom sky visuals + bool m_enable_day_night_ratio_override; + u32 m_day_night_ratio_override; + + /* 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; + +private: + JMutex m_lock; + }; /* @@ -172,16 +196,11 @@ class ActiveBlockList } std::set m_list; + std::set m_forceloaded_list; private: }; -class IBackgroundBlockEmerger -{ -public: - virtual void queueBlockEmerge(v3s16 blockpos, bool allow_generate)=0; -}; - /* The server-side environment. @@ -191,8 +210,8 @@ class IBackgroundBlockEmerger class ServerEnvironment : public Environment { public: - ServerEnvironment(ServerMap *map, ScriptApi *iface, IGameDef *gamedef, - IBackgroundBlockEmerger *emerger); + ServerEnvironment(ServerMap *map, GameScripting *scriptIface, + IGameDef *gamedef, const std::string &path_world); ~ServerEnvironment(); Map & getMap(); @@ -200,7 +219,7 @@ class ServerEnvironment : public Environment ServerMap & getServerMap(); //TODO find way to remove this fct! - ScriptApi* getScriptIface() + GameScripting* getScriptIface() { return m_script; } IGameDef *getGameDef() @@ -209,17 +228,16 @@ class ServerEnvironment : public Environment float getSendRecommendedInterval() { return m_recommended_send_interval; } - /* - Save players - */ - void serializePlayers(const std::string &savedir); - void deSerializePlayers(const std::string &savedir); + // Save players + void saveLoadedPlayers(); + void savePlayer(const std::string &playername); + Player *loadPlayer(const std::string &playername); /* Save and load time of day and game timer */ - void saveMeta(const std::string &savedir); - void loadMeta(const std::string &savedir); + void saveMeta(); + void loadMeta(); /* External ActiveObject interface @@ -252,6 +270,7 @@ class ServerEnvironment : public Environment inside a radius around a position */ void getAddedActiveObjects(v3s16 pos, s16 radius, + s16 player_radius, std::set ¤t_objects, std::set &added_objects); @@ -260,6 +279,7 @@ class ServerEnvironment : public Environment inside a radius around a position */ void getRemovedActiveObjects(v3s16 pos, s16 radius, + s16 player_radius, std::set ¤t_objects, std::set &removed_objects); @@ -290,6 +310,7 @@ class ServerEnvironment : public Environment // Script-aware node setters bool setNode(v3s16 p, const MapNode &n); bool removeNode(v3s16 p); + bool swapNode(v3s16 p, const MapNode &n); // Find all active objects inside a radius around a point std::set getObjectsInsideRadius(v3f pos, float radius); @@ -301,8 +322,15 @@ class ServerEnvironment : public Environment void step(f32 dtime); //check if there's a line of sight between two positions - bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0); + bool line_of_sight(v3f pos1, v3f pos2, float stepsize=1.0, v3s16 *p=NULL); + u32 getGameTime() { return m_game_time; } + + void reportMaxLagEstimate(float f) { m_max_lag_estimate = f; } + float getMaxLagEstimate() { return m_max_lag_estimate; } + + std::set* getForceloadedBlocks() { return &m_active_blocks.m_forceloaded_list; }; + private: /* @@ -350,17 +378,16 @@ class ServerEnvironment : public Environment // The map ServerMap *m_map; // Lua state - ScriptApi* m_script; + GameScripting* m_script; // Game definition IGameDef *m_gamedef; - // Background block emerger (the server, in practice) - IBackgroundBlockEmerger *m_emerger; + // World path + const std::string m_path_world; // Active object list std::map m_active_objects; // Outgoing network message buffer for active objects - Queue m_active_object_messages; + std::list m_active_object_messages; // Some timers - float m_random_spawn_timer; // used for experimental code float m_send_recommended_timer; IntervalLimiter m_object_management_interval; // List of active blocks @@ -377,6 +404,9 @@ class ServerEnvironment : public Environment std::list m_abms; // An interval for generally sending object positions and stuff float m_recommended_send_interval; + // Estimate for general maximum lag as determined by server. + // Can raise to high values like 15s with eg. map generation mods. + float m_max_lag_estimate; }; #ifndef SERVER @@ -395,7 +425,8 @@ class ClientSimpleObject; enum ClientEnvEventType { CEE_NONE, - CEE_PLAYER_DAMAGE + CEE_PLAYER_DAMAGE, + CEE_PLAYER_BREATH }; struct ClientEnvEvent @@ -408,6 +439,9 @@ struct ClientEnvEvent u8 amount; bool send_to_server; } player_damage; + struct{ + u16 amount; + } player_breath; }; }; @@ -462,6 +496,7 @@ class ClientEnvironment : public Environment */ void damageLocalPlayer(u8 damage, bool handle_hp=true); + void updateLocalPlayerBreath(u16 breath); /* Client likes to call these @@ -474,7 +509,7 @@ class ClientEnvironment : public Environment // Get event from queue. CEE_NONE is returned if queue is empty. ClientEnvEvent getClientEvent(); - std::vector > attachment_list; // X is child ID, Y is parent ID + u16 m_attachements[USHRT_MAX]; std::list getPlayerNames() { return m_player_names; } @@ -482,6 +517,10 @@ class ClientEnvironment : public Environment { m_player_names.push_back(name); } void removePlayerName(std::string name) { m_player_names.remove(name); } + void updateCameraOffset(v3s16 camera_offset) + { m_camera_offset = camera_offset; } + v3s16 getCameraOffset() + { return m_camera_offset; } private: ClientMap *m_map; @@ -491,10 +530,13 @@ class ClientEnvironment : public Environment IrrlichtDevice *m_irr; std::map m_active_objects; std::list m_simple_objects; - Queue m_client_event_queue; + std::list m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_lava_hurt_interval; + IntervalLimiter m_drowning_interval; + IntervalLimiter m_breathing_interval; std::list m_player_names; + v3s16 m_camera_offset; }; #endif