]> git.lizzy.rs Git - minetest.git/blobdiff - src/serverenvironment.h
Optimize headers (part 2) (#6272)
[minetest.git] / src / serverenvironment.h
index 7c370fd5495cedc725e6433d45b3a3ba7998a669..36f3e20673bba32b6502438078ed75b4c24f5bf8 100644 (file)
@@ -17,17 +17,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef SERVER_ENVIRONMENT_HEADER
-#define SERVER_ENVIRONMENT_HEADER
+#pragma once
 
+#include "activeobject.h"
 #include "environment.h"
 #include "mapnode.h"
-#include "mapblock.h"
+#include "settings.h"
+#include "util/numeric.h"
 #include <set>
 
 class IGameDef;
 class ServerMap;
 struct GameParams;
+class MapBlock;
 class RemotePlayer;
 class PlayerDatabase;
 class PlayerSAO;
@@ -70,7 +72,7 @@ class ActiveBlockModifier
 struct ABMWithState
 {
        ActiveBlockModifier *abm;
-       float timer;
+       float timer = 0.0f;
 
        ABMWithState(ActiveBlockModifier *abm_);
 };
@@ -80,7 +82,7 @@ struct LoadingBlockModifierDef
        // Set of contents to trigger on
        std::set<std::string> trigger_contents;
        std::string name;
-       bool run_at_every_load;
+       bool run_at_every_load = false;
 
        virtual ~LoadingBlockModifierDef() {}
        virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
@@ -88,8 +90,8 @@ struct LoadingBlockModifierDef
 
 struct LBMContentMapping
 {
-       typedef std::map<content_t, std::vector<LoadingBlockModifierDef *> > container_map;
-       container_map map;
+       typedef std::unordered_map<content_t, std::vector<LoadingBlockModifierDef *>> lbm_map;
+       lbm_map map;
 
        std::vector<LoadingBlockModifierDef *> lbm_list;
 
@@ -104,10 +106,7 @@ struct LBMContentMapping
 class LBMManager
 {
 public:
-       LBMManager():
-               m_query_mode(false)
-       {}
-
+       LBMManager() {}
        ~LBMManager();
 
        // Don't call this after loadIntroductionTimes() ran.
@@ -128,7 +127,7 @@ class LBMManager
 private:
        // Once we set this to true, we can only query,
        // not modify
-       bool m_query_mode;
+       bool m_query_mode = false;
 
        // For m_query_mode == false:
        // The key of the map is the LBM def's name.
@@ -190,7 +189,7 @@ enum ClearObjectsMode {
        This is not thread-safe. Server uses an environment mutex.
 */
 
-typedef UNORDERED_MAP<u16, ServerActiveObject *> ActiveObjectMap;
+typedef std::unordered_map<u16, ServerActiveObject *> ServerActiveObjectMap;
 
 class ServerEnvironment : public Environment
 {
@@ -287,6 +286,11 @@ class ServerEnvironment : public Environment
        */
        ActiveObjectMessage getActiveObjectMessage();
 
+       virtual void getSelectedActiveObjects(
+               const core::line3d<f32> &shootline_on_map,
+               std::vector<PointedThing> &objects
+       );
+
        /*
                Activate objects and dynamically modify for the dtime determined
                from timestamp and additional_dtime
@@ -395,44 +399,42 @@ class ServerEnvironment : public Environment
        // World path
        const std::string m_path_world;
        // Active object list
-       ActiveObjectMap m_active_objects;
+       ServerActiveObjectMap m_active_objects;
        // Outgoing network message buffer for active objects
        std::queue<ActiveObjectMessage> m_active_object_messages;
        // Some timers
-       float m_send_recommended_timer;
+       float m_send_recommended_timer = 0.0f;
        IntervalLimiter m_object_management_interval;
        // List of active blocks
        ActiveBlockList m_active_blocks;
        IntervalLimiter m_active_blocks_management_interval;
        IntervalLimiter m_active_block_modifier_interval;
        IntervalLimiter m_active_blocks_nodemetadata_interval;
-       int m_active_block_interval_overload_skip;
+       int m_active_block_interval_overload_skip = 0;
        // Time from the beginning of the game in seconds.
        // Incremented in step().
-       u32 m_game_time;
+       u32 m_game_time = 0;
        // A helper variable for incrementing the latter
-       float m_game_time_fraction_counter;
+       float m_game_time_fraction_counter = 0.0f;
        // Time of last clearObjects call (game time).
        // When a mapblock older than this is loaded, its objects are cleared.
-       u32 m_last_clear_objects_time;
+       u32 m_last_clear_objects_time = 0;
        // Active block modifiers
        std::vector<ABMWithState> m_abms;
        LBMManager m_lbm_mgr;
        // An interval for generally sending object positions and stuff
-       float m_recommended_send_interval;
+       float m_recommended_send_interval = 0.1f;
        // 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;
+       float m_max_lag_estimate = 0.1f;
 
        // peer_ids in here should be unique, except that there may be many 0s
        std::vector<RemotePlayer*> m_players;
 
-       PlayerDatabase *m_player_database;
+       PlayerDatabase *m_player_database = nullptr;
 
        // Particles
        IntervalLimiter m_particle_management_interval;
-       UNORDERED_MAP<u32, float> m_particle_spawners;
-       UNORDERED_MAP<u32, u16> m_particle_spawner_attachments;
+       std::unordered_map<u32, float> m_particle_spawners;
+       std::unordered_map<u32, u16> m_particle_spawner_attachments;
 };
-
-#endif