Default server step to 0.1s and sync object/player update intervals to it
authorPerttu Ahola <celeron55@gmail.com>
Mon, 26 Nov 2012 20:31:21 +0000 (22:31 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 26 Nov 2012 20:34:59 +0000 (22:34 +0200)
minetest.conf.example
src/client.cpp
src/client.h
src/clientserver.h
src/defaultsettings.cpp
src/environment.cpp
src/environment.h
src/server.cpp

index 3f292c01e58ec9dfe525c8b9a37b50b799d4f901..aebab825c71a4e3212f5d0cac648efa4ae223391 100644 (file)
 # To reduce lag, block transfers are slowed down when a player is building something.
 # This determines how long they are slowed down after placing or removing a node.
 #full_block_send_enable_min_time_from_building = 2.0
-# Length of a server tick in dedicated server
-#dedicated_server_step = 0.05
+# Length of a server tick and the interval at which objects are generally updated over network
+#dedicated_server_step = 0.1
 # Can be set to true to disable shutting down on invalid world data
 #ignore_world_load_errors = false
index 1936c2ce9aba6025fcd2132981fb9985f2df7335..4117a91306a655f923d01703266c9e912f160784 100644 (file)
@@ -267,6 +267,7 @@ Client::Client(
        m_time_of_day_set(false),
        m_last_time_of_day_f(-1),
        m_time_of_day_update_timer(0),
+       m_recommended_send_interval(0.1),
        m_removed_sounds_check_timer(0)
 {
        m_packetcounter_timer = 0.0;
@@ -658,7 +659,7 @@ void Client::step(float dtime)
        {
                float &counter = m_playerpos_send_timer;
                counter += dtime;
-               if(counter >= 0.2)
+               if(counter >= m_recommended_send_interval)
                {
                        counter = 0.0;
                        sendPlayerPos();
@@ -1022,6 +1023,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
                        m_map_seed = readU64(&data[2+1+6]);
                        infostream<<"Client: received map seed: "<<m_map_seed<<std::endl;
                }
+
+               if(datasize >= 2+1+6+8+4)
+               {
+                       // Get map seed
+                       m_recommended_send_interval = readF1000(&data[2+1+6+8]);
+                       infostream<<"Client: received recommended send interval "
+                                       <<m_recommended_send_interval<<std::endl;
+               }
                
                // Reply to server
                u32 replysize = 2;
index 154c8bb003646bd580e563ee3a0841dfeda548ad..b4b7af7c3347d74ad95e16481e711ba1b6983870 100644 (file)
@@ -382,6 +382,9 @@ private:
        float m_last_time_of_day_f;
        float m_time_of_day_update_timer;
 
+       // An interval for generally sending object positions and stuff
+       float m_recommended_send_interval;
+
        // Sounds
        float m_removed_sounds_check_timer;
        // Mapping from server sound ids to our sound ids
index 65a14ab386b40c1ecc42b6a67f166e82bbebdc2a..6d4998550b683066015d2b947bf1e153ca9a337a 100644 (file)
@@ -103,6 +103,7 @@ enum ToClientCommand
                [2] u8 deployed version
                [3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd 
                [12] u64 map seed (new as of 2011-02-27)
+               [20] f1000 recommended send interval (in seconds) (new as of 14)
 
                NOTE: The position in here is deprecated; position is
                      explicitly sent afterwards
index 6eaa284101f37b176410379145cc4292f2751d68..e9c2ba3b8ce2ee780d99cefa07401fc4edf1bfcf 100644 (file)
@@ -140,7 +140,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("server_unload_unused_data_timeout", "29");
        settings->setDefault("server_map_save_interval", "5.3");
        settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
-       settings->setDefault("dedicated_server_step", "0.05");
+       settings->setDefault("dedicated_server_step", "0.1");
        settings->setDefault("ignore_world_load_errors", "false");
        settings->setDefault("mip_map", "false");
        settings->setDefault("anisotropic_filter", "false");
index b8e0373766a12f541d20b4742a55efa363d3f6fc..e70cb39b784d42a38a6e93f118e408a9e3c3e5f9 100644 (file)
@@ -329,7 +329,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
        m_send_recommended_timer(0),
        m_active_block_interval_overload_skip(0),
        m_game_time(0),
-       m_game_time_fraction_counter(0)
+       m_game_time_fraction_counter(0),
+       m_recommended_send_interval(0.1)
 {
 }
 
@@ -940,6 +941,11 @@ void ServerEnvironment::step(float dtime)
        /* Step time of day */
        stepTimeOfDay(dtime);
 
+       // Update this one
+       // NOTE: This is kind of funny on a singleplayer game, but doesn't
+       // really matter that much.
+       m_recommended_send_interval = g_settings->getFloat("dedicated_server_step");
+
        /*
                Increment game time
        */
index e2028d614e1f87fe1493fc27e0a0a4e65e2e6c15..0cc53f9a6dccea2dc8f215f720def5f275a2288e 100644 (file)
@@ -205,9 +205,7 @@ public:
                { return m_gamedef; }
 
        float getSendRecommendedInterval()
-       {
-               return 0.10;
-       }
+               { return m_recommended_send_interval; }
 
        /*
                Save players
@@ -367,6 +365,8 @@ private:
        // A helper variable for incrementing the latter
        float m_game_time_fraction_counter;
        core::list<ABMWithState> m_abms;
+       // An interval for generally sending object positions and stuff
+       float m_recommended_send_interval;
 };
 
 #ifndef SERVER
index 6f80c82f7b5e371f42f59e3934a7b3f7390d64ac..cb54476058799d1304db2daaa7b0291a240136e7 100644 (file)
@@ -2224,11 +2224,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        Answer with a TOCLIENT_INIT
                */
                {
-                       SharedBuffer<u8> reply(2+1+6+8);
+                       SharedBuffer<u8> reply(2+1+6+8+4);
                        writeU16(&reply[0], TOCLIENT_INIT);
                        writeU8(&reply[2], deployed);
                        writeV3S16(&reply[2+1], floatToInt(playersao->getPlayer()->getPosition()+v3f(0,BS/2,0), BS));
                        writeU64(&reply[2+1+6], m_env->getServerMap().getSeed());
+                       writeF1000(&reply[2+1+6+8], g_settings->getFloat("dedicated_server_step"));
                        
                        // Send as reliable
                        m_con.Send(peer_id, 0, reply, true);