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]