My idea for a network library

BlitzMax Forums/BlitzMax Programming/My idea for a network library

AngelDaniel, if I get you right that would work for a game with max one player on each computer and no AI players. As Ai-players don't have input directly from the keyboard. And two players on one computer has different keys for the same actions.

And Jeroen thats how it works right now =)
SendUDP( MsgType , DataString$ , OnlyToID=0 , NotToID=0 )
if OnlytoID = 0 (or not specified) send to all. NotToID is specified if you want to send to all but that ID.

I'm thinking about allowing for "local" clients. So that you can have several players on one computer. In that way you could match the client number with the AIplayers and RealPlayers on your computer and in that way specify the keysync of each. But I can't think af an easier way to do it. I actually want to make it even more simple but I don't know how (got any ideas?).

And even though you send keypresses (when changed) you need to send fullupdates once in a while because of latency.

This is how I'm thinking the interface will look when it's done:
--- THIS IS NOT A WORKING EXAMPLE ---


'In main loop
For C = eachin localClient
    C.UpdateSend( 5 , [X,Y,Dir,Energy,Armor])
    ' 5 = Five times per sec - or once every 200ms

    C.UpdateKeysOnly( 0 ) 
    ' 0 =Always send keys if they have changed
Next


'In player input method (do this for each key)
C = GetClientID( player.ID ) 'Match with your type

 If Keydown( ~~~ )  

      'SetKeyToSend( KeyNR - From 0 to 7 , True or False )
      C.SetKeyToSend( 0 , True )  'Pressed

 Else

      C.SetKeyToSend( 0 , False ) 'Not down

 Endif



'in mainloop
If UpdateReceived() 'Check if you got any msg sent by UpdateSend()

    For C = Eachin RemoteClient 

       If C.ID = Player.ID ' match with your type

           'In the same order you sent them..
           Player.X = C.GetUpdate( 0 )
           Player.Y = C.GetUpdate( 1 )
           Player.Dir = C.GetUpdate( 2 )
           Player.Energy = C.GetUpdate( 3 )
           Player.Armor = C.GetUpdate( 4 )

       Endif
    Next

endif
So when you create a player you need to create an client equalent.

'In the New() method of your player type
AddLocalClient( Name$ = "" , Info$ = "")

'And in Delete()
RemoveLocalClientwithID( Self.ID )

When the Client connects to host (or when he himself host a game) the local clients will be given IDs by the Host. If you AddLocalClient() After host() or Join() it will announce itself to all others. Same goes if you change the name/info of any client by using yourClient.SetName( newName$ )

I'll probably notice that this doesn't work after trying to code it for X weeks, but it's the guideline I'm working after. Ideas are welcome =)