Network - the X and Y position (fastest way)

Blitz3D Forums/Blitz3D Beginners Area/Network - the X and Y position (fastest way)

GC-Martijn(Posted 2005) [#1]
H!

I testing things with tcp and udp and everything is working fine but slow.

Now I use this:
If KeyDown(200) then
   send("2|"+y%) ;send it with udp
endif


Then I extract the msg.
the letter 2 is the header so I know the player is going up.
and the player is moving up.
But 1 second later.

What to do ?
Must I use Cubic Spline Interpolation ?
http://www.blitzbasic.com/codearcs/codearcs.php?code=345

But I don't understand how.
Or is there a faster/other way ?

Thanks very Much,
GC-Martijn


Matty(Posted 2005) [#2]
You really don't want to use 'if keydown() then send a network message' every frame - check for changes in state, so when the key is first pressed and when it is released otherwise, if your game runs at 60 frames per second you will be sending network messages at that rate as well.


ziggy(Posted 2005) [#3]
I would suggest you not to use a number as a identifier. If you get a broken package, the client application can interpret a cifre of Y as a header of a packet.
It's a good idea to send player status every X millisecs (for example every 400 millisecs) better than sending packets non-stop all the time.


WolRon(Posted 2005) [#4]
a cifre of Y
? Please explain what you mean.



I would send several updates in each packet because sending each packet takes time but sending a few extra characters with every packet takes almost no time.


GC-Martijn(Posted 2005) [#5]
hmm I will try the 400 millisecs but I really want to know what other 2d games do.

@WolRon

Do you mean
If KeyDown(200) then
recordMovementforsomeMillisecs(y%)
endif

function recordMovementforsomeMillisecs(y%)
makethestring = makethestring+"|"+y%

if timeisup then
send("2|"+makethestring) ;send it with tcp
endif
end function

Thanks for all the info


ImaginaryHuman(Posted 2005) [#6]
You could also try sending the KEY PRESSES.

You see, what you're doing is waiting for user input. On the local end of things, you would normally interpret that user input and then use it in some way. But if you do that, the interpreted version of the action usually takes up more room and time than the uninterpreted raw input. If you just send the input, ie a code that a given key is pressed instead of trying to EXPLAIN to the other computer what to do, then let the other computer interpret the raw user input and decide what it means. Let the remote computer turn the keypress into a movement, let it be the interpreter. Apparently this will drastically cut down on how much data you need to send. You don't want to have to send a whole heap of data describing some event in intricate detail with several variables and all the rest of it. Just send the raw keypresses or joystick movements or mouse movements, this data is much smaller and can be interpreted by the recipient.


GC-Martijn(Posted 2005) [#7]
Thanks AngelDaniel thats a other great idea, i will use them all for one good fast player movement :)