Manic Digger

It is currently Tue May 21, 2013 10:19 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Why should you make a delay?
PostPosted: Thu Apr 05, 2012 10:42 pm 
Was just browsing the code, stumble onto this snippet:

Code:
if (!playerdrawinfo.ContainsKey(k.Key))
                {
                    playerdrawinfo[k.Key] = new PlayerDrawInfo();
                    NetworkInterpolation n = new NetworkInterpolation();
                    n.req = new PlayerInterpolate();
                    n.DELAY = 0.5f;
                    n.EXTRAPOLATE = true;
                    n.EXTRAPOLATION_TIME = 0.3f;
                    playerdrawinfo[k.Key].interpolation = n;
                }

(From ManicDiggerGameWindow.cs, DrawPlayers() )

Why would you set a delay for letting the players move. I tested it in multiplayer with and without delay, and I have to say, if you get rid of that delay it looks so much better.

Grtz Diho


Top
  
 
 Post subject: Re: Why should you make a delay?
PostPosted: Fri Apr 06, 2012 6:00 am 
Offline
Site Admin

Joined: Mon Jun 21, 2010 12:02 pm
Posts: 384
Delay is like buffering of video. If you open youtube on very slow internet, but let it buffer for a minute, you will still be able to watch without any lag.

It's important. Try with laggy server - if server ping is greater than delay (500 miliseconds) then players just freeze.

After that time, the extrapolation deals with this emergency situation for another 300 miliseconds by pretending that everyone moves straight foward. But if extrapolation is too long then players will move very jerkily and will randomly teleport.

But it's true that this delay time should be dynamically adjusted based on connection speed. For example on LAN it should be 10 miliseconds, not 500.


Top
 Profile  
 
 Post subject: Re: Why should you make a delay?
PostPosted: Fri Apr 06, 2012 12:49 pm 
And what if you do it this way? It's dynamic, but I dunno if it's good enough. Maybe you should add some extra ms so you're sure there will be no lag. And maybe the client shouldn't just check it after connecting but more frequently. But besides that, can you tell me if this would work:

Code:
Server.cs:
       
      static class PingTest
      {
         public static int ping1;
         public static int SetPingMS(string hostNameOrAddress)
         {
            System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
            ping1 = Convert.ToInt32(ping.Send(hostNameOrAddress).RoundtripTime);
            return Convert.ToInt32(ping.Send(hostNameOrAddress).RoundtripTime);
         }
         public static int GetPingMS
         {
            get { return ping1; }
         }

      }
      
      private void SendPingReady(int clientid)
        {
            PacketServer p = new PacketServer() { };
            SendPacket(clientid, Serialize(new PacketServer() { PacketId = ServerPacketId.PingTest }));
        }
ManicDiggerGameWindow.cs:
            
                case ServerPacketId.PingTest:
                    {
                        ManicDiggerServer.PingTest.SetPingMS(connectdata.Ip);
                    }
                    return true;
               
            n.DELAY = ManicDiggerServer.PingTest.GetPingMS * 0.001f;
            
Packets.cs
            PingTest = 27, ( @ public enum ServerPacketId)
            [ProtoMember(22, IsRequired = false)]
            public PacketServer PingTest;            (@ public class PacketServer)

I tested it at localhost. Worked great.

Grtz Diho


Top
  
 
 Post subject: Re: Why should you make a delay?
PostPosted: Fri Apr 06, 2012 3:46 pm 
Maybe this would be better, Now it's checks the ping ( in ms ) every minute, right?.
Code:
                case ServerPacketId.PingTest:
                    {
                        //ManicDiggerServer.PingTest.SetPingMS(connectdata.Ip);
                        new Thread((a) => { for (; ; ) { ManicDiggerServer.PingTest.SetPingMS(connectdata.Ip); Thread.Sleep(TimeSpan.FromMinutes(1)); } }).Start();
                    }
                    return true;

Tested it at localhost, and over internet. No problems at all. Fine quick movement, no teleport because of lag.

grtz Diho


Top
  
 
 Post subject: Re: Why should you make a delay?
PostPosted: Sun Apr 08, 2012 6:16 am 
Offline
Site Admin

Joined: Mon Jun 21, 2010 12:02 pm
Posts: 384
Diho wrote:
Code:
System.Net.NetworkInformation.Ping();

Ping has to be a packet inside game, because real network ping is often blocked, and it doesn't take into account the server lag.


Top
 Profile  
 
 Post subject: Re: Why should you make a delay?
PostPosted: Sun Apr 08, 2012 1:40 pm 
Okay, now I measure the ping by sending a packet from the client to the server, the server response directly by sending a packet back. Then the client checks the time that has been used from sending a packet to the server till he receives one back from the server, in milliseconds.

Thanks for your explaination ;)

Grtz Diho


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group