vbGore Free Online RPG Engine

Revolutionizing Visual Basic ORPG Development
It is currently Sun May 19, 2013 1:49 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Pixel movement and packets
PostPosted: Mon Mar 24, 2008 4:30 pm 
Wizard of Xor

Joined: Sat Jun 09, 2007 8:30 pm
Posts: 236
Location: Mexico
I ran into some trouble with movement packets using Tcp.
I used to send a packet every time the client player requested to move, but this rendered inefficiently and created a whole crap load of problems once a tiny bit of lag was present.
After searching VBGore I thought making some sort of buffer to store movement packets before sending them would solve this problem, then I came up with this (code isn't real, it's just to show my point):

Code:
string sendData = "";
int limit = 100;
int count = 0;

if(pressKeyRight)
{
        sendData = sendData + "r,";
}
// and ect. for all direction movements

gameProcessLoop()
{
        if(sendData != "")
        {
                if(counter > limit)
                {
                        socket.send(sendData);
                        counter = 0;
                }

                counter += 1;
        }
}


So basically the server receives a packet like "r,r,r,r,d,d,l,l,r,r,r,r," (r = right and so on with all directions).
Here I brake down the packet by ',' to get individual directions, and loop the array of directions checking which is which and actually moving the player.
Everything with this works fine, except everything happening IN the loop isn't being rendered, so it creates a kind of "skipping" effect which isn't very nice at all haha.
Is there a more efficient way of transferring packets via Tcp without this lag problem?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 11:47 am 
Wizard of Xor

Joined: Sat Jun 09, 2007 8:30 pm
Posts: 236
Location: Mexico
Fine :( I'll use Udp for movement then *sniff*.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 12:10 pm 
Site Admin

Joined: Fri Jul 14, 2006 4:00 pm
Posts: 11230
Location: Washington
The problem is your implementation. Its hard to say what is wrong with it without seeing it, but locally TCP should be near instant. UDP isn't going to help in the slightest bit unless the problem is a lot of dropped packets, which isn't going to be the case locally where nothing gets dropped. Without knowing what you're doing, UDP will just make things much worse for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 12:34 pm 
Cubic Root of 1

Joined: Sat Sep 16, 2006 4:00 pm
Posts: 290
you'll have to let the rendering take place after each iteration of the loop, so the player moves smoothly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 12:51 pm 
Site Admin

Joined: Fri Jul 14, 2006 4:00 pm
Posts: 11230
Location: Washington
I just noticed that counter variable - what the heck is the point of that? If you want to prevent spam, do it on a per-command basis. What you are doing is waiting limit loops before sending anything, and the waiting starts AFTER the first packet is queued. First off, TCP implements the Nagle Algorithm which combines packets together for you so you are just making a queue before the queue. Secondly, if you do want to queue the data, you might as well just do it on a timer not dependant on the send time. It'd be like sending every frame or so. But again, this is pretty useless.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 4:35 pm 
Wizard of Xor

Joined: Sat Jun 09, 2007 8:30 pm
Posts: 236
Location: Mexico
Sorry, and thanks.

Forgot to mention this wasn't tested localy lol, so the problem was indeed lag. I now use Udp for movement only, works good :).


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

All times are UTC - 8 hours


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

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group