Jump to content

  • Log In with Google      Sign In   
  • Create Account


TheDirectShift

Member Since 27 Jan 2013
Offline Last Active Jan 29 2013 07:20 PM
-----

Topics I've Started

Lag in TCP/IP lockstep model RTS game

27 January 2013 - 08:50 PM

Hi to everyone!

I have been dealing with this problem for weeks and I can't find the root of it.

I'm working on a RTS game, it uses lockstep to communicate.

At the moment it's just 2 players.

 

I'm going to show you the code of sending/receiving.

Information is an object containing a matrix of 5x6 integers.

settcpnodelay is done outside.

 

there is only one Thread

 

            SleepABit();
            ReceiveData();           
            ScheduleDutys();
            UpdateAllUnits();
            SendData();      
            DrawGraphics();
            step = StepLookAhead(step,1);
 

 

 

private void ReceiveData()
    {

        try{
                if(whoisthis == 1) //for server
               {
                    indata1 = new ObjectInputStream(sk.getInputStream());
                   
                    info_other1 = (Information) indata1.readObject();
                    ProcessInformation(info_other1); //process client info
                   
                    ProcessInformation(info); //process own info
                   
                   
                }
                else //for client
               {
                    indata1 = new ObjectInputStream(sk.getInputStream());
                    indata2 = new ObjectInputStream(sk.getInputStream());
                   
                    info_other1 = (Information) indata1.readObject();
                    info_other2 = (Information) indata2.readObject();
                   
                    ProcessInformation(info_other1);
                    ProcessInformation(info_other2);
                   
                   
                }
               }catch(IOException ioe){} catch(ClassNotFoundException css){System.out.println("nothing to do here");}
   
    }
 

 

 

private void SendData()
    {
       
         
        try{

              if(whoisthis == 2) //this is client
             {
                outdata1 = new ObjectOutputStream(sk.getOutputStream());
               
                outdata1.writeObject(info);
                info.CleanInformation();
                   
                info_other1.CleanInformation();
                info_other2.CleanInformation();
               
               
              }
              else //this is server
             {
                  outdata1 = new ObjectOutputStream(sk.getOutputStream());
                  outdata2 = new ObjectOutputStream(sk.getOutputStream());
                 
                  outdata1.writeObject(info); //send server info
               
                  info.CleanInformation();
                   
                   outdata2.writeObject(info_other1); //send client info
                 info_other1.CleanInformation();
                 
              }

             
            }catch(IOException ioe){}
    }
 

 

I know the problem is there, in one of those codes, because when I try it in localhost mode, it works excellent, but when it comes to playing with another player through LAN...it lags, and I really don't know why.

 

 

So, I hope you can help me here, thanks ! bye!

 


PARTNERS