Hi foosh!
I took a look at your code. There are several things you should probably change or at least reconsider:
- Do not send messages updating coordinates every time they change, send them a couple of times a second instead... a quick change on you main loop in order to send /receive positions only 5 times a second keeps your famerate higher.
- While receiving data from the network you are getting loads of intermediate positions from the remote objects... and you are probably only interested in the "latest one" and can easily calculate the intermediate points to make remote objects move smoother on the local display. Some sample code to ilustrate it (it probably breaks the function purpose but try it out to see what I mean):
Also, going thru the objects list several times, for each and every single one of those intermediate changes, was killing your your framerate. You would probably do much better if you got a notification from the game server on "when" and "what" objects changed, so you would request the latest (not the history) info on the ones that "interest" you.
- A echo server may be used for game room handling... but it is NOT your best option for keeping track of remote objects in real time... use must use UDP for that.
PLS
PS: "I'm working an a massively multiplayer online game client"... you will fail (sorry!). Code a few smaller networks games (real time or turn based), have fun, and give yourself a chance of finishing a game.
I took a look at your code. There are several things you should probably change or at least reconsider:
- Do not send messages updating coordinates every time they change, send them a couple of times a second instead... a quick change on you main loop in order to send /receive positions only 5 times a second keeps your famerate higher.
Local elapsed:Int=MilliSecs() While Not KeyDown(Key_ESCAPE) Or AppTerminate() Cls time_passed_secs = stop-start time_passed_secs = time_passed_secs/1000 start = MilliSecs() DrawText "fps: " + (time_passed_secs*1000),200,465 main_player.UpdateState() For Local o:TGameObject=EachIn GameObjectList o.DrawSelf() Next DrawText "alias: " + player_name,0,465 DrawText "x,y: " + main_player.X+","+main_player.Y,400,465 Flip stop = MilliSecs() If(elapsed+200<MilliSecs()) If Not (main_player.X=main_player.pX And main_player.Y=main_player.pY) Then game_network.sendCoords(main_player.X,main_player.Y) game_network.updateMap() elapsed=MilliSecs() End If Wend
- While receiving data from the network you are getting loads of intermediate positions from the remote objects... and you are probably only interested in the "latest one" and can easily calculate the intermediate points to make remote objects move smoother on the local display. Some sample code to ilustrate it (it probably breaks the function purpose but try it out to see what I mean):
Also, going thru the objects list several times, for each and every single one of those intermediate changes, was killing your your framerate. You would probably do much better if you got a notification from the game server on "when" and "what" objects changed, so you would request the latest (not the history) info on the ones that "interest" you.
Method updateMap() Local other_player:TOtherPlayer Local mapState:String Local parseCoords:String[] Local x,y,id:Int Local name:String Local last:Int[][] Local unfinished:Int=1 Local updated:Int=0 While(unfinished=1) If SocketReadAvail(socket) > 0 Then mapState = ReadLine(stream) If mapState Then parseCoords = mapState.split(":") id = parseCoords[0].toint() parseCoords = parseCoords[1].split(",") x = Trim(parseCoords[0]).toint() y = Trim(parseCoords[1]).toint() name = Trim(parseCoords[2]) Print x+"*"+y+"*"+name+"*"+id+"*" updated =+ 1 End If Else If(updated) For Local o:TGameObject=EachIn GameObjectList If o.ID = id Then o.X = x o.Y = y Else other_player = TOtherPlayer.Create(name,file_server+"playerorange.png",x,y,id) End If Next End If unfinished=0 End If Wend End Method
- A echo server may be used for game room handling... but it is NOT your best option for keeping track of remote objects in real time... use must use UDP for that.
PLS
PS: "I'm working an a massively multiplayer online game client"... you will fail (sorry!). Code a few smaller networks games (real time or turn based), have fun, and give yourself a chance of finishing a game.