2D - Network tweening (slow pc / fast pc)

Blitz3D Forums/Blitz3D Programming/2D - Network tweening (slow pc / fast pc)

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

I have one fast pc and a slow pc with a terrible slow videocard ;)

And what do I get when I'm testing my game with that : wrong results.

When the player moves it sending the code of direction.
For example Right -> 1
----

1.
Fast pc [host]
idle

Slow pc [client]
player is going right {player moves very slow}

2.
Fast pc
the client is much much more to the right then at the slow pc

---------------
When I use 2 fast pc's everything is oke.

But now my question.

What to do ?
- block slow computers with a frame test ?
- what frame tweening can I use ?
- how to get it 1:1 ? [or is that a bad idea]

I found this in the 3D code archives, i don't know if its working for 2D like it must.

period=1000 / 30
tweentime = MilliSecs()-period
While 1
;====== CALCULATE TWEEN ==============
	Repeat
		elapsed = MilliSecs() - tweentime
	Until elapsed
	ticks = elapsed/period
	tween# = Float(elapsed Mod period) / Float(period)
;=======================================

	;Game LOOP
	For k=1 To ticks
		tweentime = tweentime+period
		If KeyDown(1)
			End
		EndIf
	
		;TCP network stuff
	
	Next

	Cls
	 ; Draw everything on the screen
	Flip
Wend




DJWoodgate(Posted 2005) [#2]
That 3d code may work in 2d if you linear interpolate the 2d movement vectors using the tween value like tweening does for 3d. It will I suspect look very jerky otherwise. So you will need to store the position of the objects at the same place as the captureworld statement in the 3d version and then interpolate between their current positions and the position they were captured at using the value of tween#. Or something like that, I have never actually tried it myself.

The tweened draw positin will then, at a guess, be something like TX=CapturedX+(CurrentX-CapturedX)*tween, TY=CapturedY+(CurrentY-CapturedY)*tween. As I say I have not tested it though, so I am sure someone here will put me right if I am wrong.

I have no idea about the networking side of it though ! I get the impression more sophisticated interpolation is generally used to cope with lag, but maybe that is not as necessary on a local network.


morduun(Posted 2005) [#3]
http://www.gamasutra.com/features/19970919/aronson_01.htm


GC-Martijn(Posted 2005) [#4]
mmm,

My project fails if I don't get a 1:1 network game.
Its only 2d.

What is the best way to split drawing things and calculate things.
slow/fast videocards use only the drawing section but not on the calculate section, so the tcp/ip will be 1:1

while not keyhit(1)

;drawing section 
cls
;draws everything
flip

;calculate section

;tcp stuff and has nothing to do with flip,framerate,slower videocard.

wend


Will it help if I put the movement
when keyup sendtoOthers(up)
in below the flip command ?

-------------

Maybe I must ask some people how have done this before.


Matty(Posted 2005) [#5]
There is a lot more to stable and synchronised network code than simply sending player inputs to each PC when they change.

You most likely will find that even if you have a LAN and are using identical PCs that your game diverges on both machines. Once the game becomes unsynchronised the simulation will usually become completely different on both machines in a short space of time. This is a bad thing (in 99% of cases - if you don't care that both players will have a different experience then I guess not always).

Assuming you are creating a real time game not a turn based one then this will be a big problem.

There are many articles on the internet about coding multiplayer games which you may be able to find, a few on gamasutra and on gamedev.net.

If you are doing an action game which has only a small number of 'characters' (such as in a game like Quake 3) then it is far easier to write network code. Usually this will involve having one PC acting as the 'server' which basically tells all the other PCs (clients) what the correct state of the world is on a regular basis.

If you are doing an RTS or other game with multitudes of units then a different approach is needed. There is an article on gamasutra about this using the example of Age of Empires.


GC-Martijn(Posted 2005) [#6]
Well I'm going back to gamasutra then ;)