blitz 3d multiplayer

Miscellaneous Forums/General Discussion/blitz 3d multiplayer

Wait a second ... what's complex about packing and unpacking the data. You can use some compression if need be to minimize the number of bytes sent and that can be done in numerous ways but essentially it's this simple ... and probably could be simpler with some optimization.

Dim incoming$( 100 )

If JoinNetGame( GetWord( gns\server$, 1 ), gns\ip$ )
   localNetPlayer = CreateNetPlayer( localPlayerName$ )
   Setup( "Game" )
   hosting = False
Else
   If HostNetGame( localPlayerName$ ) = 2
      localPlayerName$ = Replace( localPlayerName$, " ", "" )
      If GNET_AddServer( "YourGame", localPlayerName$ )
         localNetPlayer = CreateNetPlayer( localPlayerName$ )
	 Setup( "Game" )
	 hosting = True
      Else
         RuntimeError( "Failed to Add Server!" )
      EndIf
   Else
      RuntimeError( "Failed to Create Net Game!" )	
   EndIf
Endif

Sending Player ...
packet$ = X + " " + Y + " " + Z
SendNetMsg(4, packet$, localNetPlayer, 0, False )

Receiving Player ...
While RecvNetMsg()

   Select NetMsgType()
      case 4
         PositionEntity( otherPlayer, GetWord$( NetMsgData$(), 1 ), GetWord$( NetMsgData$, 2 ), GetWord$( NetMsgData$, 3 ) )

   End Select

Wend

;====== GET WORD ==========================================================

Function GetWord$( message$, wordNum )

	For i = 1 To 100
		incoming$(i) = ""
	Next

	i = 1
	part = 1
	incoming$( part ) = Mid( message$, i, 1 )
	i = i + 1
	While i <= Len( message$ )
		While ( Mid( message$, i, 1) <> " " )
			incoming$( part ) = incoming$( part ) + Mid( message$, i, 1 )
			i = i + 1
			If i > Len( message$ )
				Exit
			EndIf
		Wend
		If Mid( message$, i, 1 ) = " "
			i = i + 1
			part = part + 1
			incoming$( part ) = Mid( message$, i, 1 )
			i = i + 1
		EndIf
	Wend
	
	Return incoming$( wordNum )

End Function

;==========================================================================



Everyone probably uses some different compression techniques. Personally, I've seen NAN's come about because of some associated with BlitzPlay so I've written my own optimization routines especially for floats. Overall though sending the data back and forth isn't difficult. I suppose TCP really isn't much worse except you're dealing with a stream. Perhaps let me see how you handle it.