TNet Multiplayer Release Update

BlitzMax Forums/BlitzMax Programming/TNet Multiplayer Release Update

Tibit(Posted 2005) [#1]
My Network Module is taking it's next step. The first real version is online. The site has been updated with various stuff.

TNet is now using BlitzMax sockets from scratch and should work on Mac and Linux aswell as PC. Overall the structure of TNet have been made more effective and modular so the next updates should take less time to complete (TCP, Reliable UDP, SyncObjects).

Hope this version is more stable than the last and not the opposite. TCP and reliabel UDP is the next step. They are both 70% done.

See the command section for an update list of all command with descriptions and examples.

Examples Updated to support TNet Pre-Release.


RepeatUntil(Posted 2005) [#2]
Congratulation!! Very promising!!


BlitzSupport(Posted 2005) [#3]
Oops, meant to try this last night! I'll try later on.


Najdorf(Posted 2005) [#4]
I'll check it out, looks great.


_Skully(Posted 2005) [#5]
Im curious how you are implementing sync objects.

Excuse my ignorance of how Max works but is there a way of interating through a type's structure or would the programmer have to create a function or method for this to occur?


Najdorf(Posted 2005) [#6]
will this be competing with the "official" network modules (when/if they come out)?


Jeroen(Posted 2005) [#7]
Awesome Wave. Keep it up.
Good documentation too!


Tibit(Posted 2005) [#8]
Thanks,
I was away last week so that's why I haven't replied.


will this be competing with the "official" network modules (when/if they come out)?


The official network module called GNet is already out, as well as the sockets code, see the official documentation. It could need a little more work, but it's done. I would say TNet-BASIC is competing to GNet. TNet-Advanced will be aimed for more serious developers, it will not be harder to use it will only contain more features. And will be out of league with GNet.


Excuse my ignorance of how Max works but is there a way of interating through a type's structure or would the programmer have to create a function or method for this to occur?


Direct answer would be: Programmer have to use functions and import a "unreal_network_module.bmk" file, which you can modifiy if you want to.

Syncobjects will be implemented into your game with the help of some functions.

Here is an example:
'This is your create method for an object you want to sync.
	Function Create()
	
			Local P:Probe = New Probe
			P.Control = AI 'On this computer
			P.Local_ID = CreateSyncObject()'<--- NETWORK CREATE SYNC OBJECT
			UpdateSyncObject( [ Int(P.X), Int(P.Y) ,P.Dir, P.Armor, P.Energy], P.Local_ID )	
	
	EndFunction


This is for sending actions, could be keypresses.
If KeyDown(Key_Up) SetActionOn( 0,Local_ID ) Else SetActionOff( 0,Local_ID )
If KeyDown(Key_Down)  SetActionOn( 1,Local_ID ) Else SetActionOff( 1,Local_ID )
If KeyDown(Key_Left) SetActionOn( 2,Local_ID ) Else SetActionOff( 2,Local_ID )
If KeyDown(Key_Right) SetActionOn( 3,Local_ID ) Else SetActionOff( 3,Local_ID )


In your objects update method you would have this, decide which fields you want to send. These fields will be sent to the other clients and applied to their remote sync-objects. You can control the sending interval at which these updates are sent.
UpdateSyncObject( [ Int(X), Int(Y) ,Dir, Armor, Energy] ,Local_ID )


This is how you receive the data from others. This should be run in objects that are remote controlled. Means If SyncUpdate Recieved then
If SyncUpdate( Net_ID, Local_ID )	TNetApplyUpdate( X, Y, Dir, Armor, Energy )	

If TNetKeySync( Net_ID, Local_ID )	SetActions( Up, Down, TLeft, TRight)		



Takuan(Posted 2005) [#9]
May i ask something about sync.?

Does this SyncUpdate gets true if somewhere else a
UpdateSyncObject has been called or gets it true if all clients have received the (UpdateSyncObject) Fields?
Is there a command to check out if all clients have got the new data and are ready to update it?


Tibit(Posted 2005) [#10]
SyncUpdate return true is the sync object from Net_ID which you are given when you join. Every connected Client have a unique Net_ID. Each Client may have any number of sync objects. To get a specific sync-object you check the Net_ID and then the Local_ID. A sync objects could be anything. A Ped, a Car, A Door, A Tree. If it moves it's data is packed into a "send this next update list". At the next update all syncobjects which have new and relevant data are sent, as one big packet. It's probably hard to get it without an real example. But all in all it is easier than building your own system. As everyone will need to modyfy small stuff of the imported module file so it's fits into their game, such as ApplyUpdate( X, Y ,Z , Pitch, Yaw, Roll ...) if your doing it in 3D.

The idea is that each object in your game have to know if it is remote or local. A remote object is updated with received packets at SyncUpdate( NetID , LocalID ), local objects are sent in updates at UpdateSyncObject( X,Y,Z.. ). This is controlled when you create the object. So check NewSyncObject() to get a remote object from another client or CreateSyncObject() to create a local one. Each sync object has a local ID and a Client_ID.

Did I answer your question?


Jeroen(Posted 2005) [#11]
Hi Wave,

I don't understand your syncobjects example, but I'll wait until there are some live examples :)


Tibit(Posted 2005) [#12]
I guess that's the best =)


Takuan(Posted 2005) [#13]
Thank you, downloaded the pre release.
Please cry out loud if you got prediction in.
Looking forward to the release version:)


Takuan(Posted 2005) [#14]
Mhh...strange.

'host
Graphics(1024,768,0,75)
HostUDP(8080)
While Not KeyDown(Key_Escape)
UpdateTNet()
Flip
Cls
Delay 20
FlushMem
Wend

'------------------------------

'Client
Graphics(1024,768,0,75)
JoinUDP("82.135.71.240",8080)
While Not KeyDown(Key_Escape)
DrawText "Testest",50,50
Flip
Cls
Delay 20
FlushMem
Wend


I am running 1 client and 1 host at one PC.

Sometimes the client gets ID 2 which is okay.
Sometimes host debug message says something like player joined..ID2, player joined...ID3, player joined..ID4 etc.

Why that?


Tibit(Posted 2005) [#15]
Do you got Pre Release 2?

I fixed some bugs which resulted it that behavior in the latest version. (or I'll try to figure it out)

Here is another simple example, yours should work fine. There is some new debugging too, more info under commands at the TNet site.

Host
HostUDP(8080)
While Not KeyHit(KEY_ESCAPE)
   UpdateTNet()
Wend 


Client
 
Graphics 640,480,0
JoinUDP( 82.135.71.240", 8080 )
While Not KeyHit(KEY_ESCAPE)
 UpdateTNet()
 DrawListOfAllClients(0,0)
 Flip;Cls
Wend 



Takuan(Posted 2005) [#16]
Just tried your Pre Release 2.
Works fine now, nice job.
DrawListOfAllClients(0,0) behaves different if put in Hosts Code (message only several seconds visible).
If i am allowed to, i will write in your forum;-)


Tibit(Posted 2005) [#17]
DrawListOfAllClients() only works in graphics mode but I guess that's not the problem. Explain more, perhaps post some code. It works for my host =)

Please use the TNet Forum for any Multiplayer Programming Questions, it's not for TNet-Only.
TNet Forum

( You do not have to create an accout to post but it's recommended )


Takuan(Posted 2005) [#18]
Will do.


Filax(Posted 2005) [#19]
Hi Wave

I have tested a little bit you TNet library :) great job ! but i'm a little
bit lost with your command .... It's not very easy to see what
command is a TNet command. I think that you must rename them.

Example :

TNet_JoinUDP
TNet_NewClient()

etc...

Else , keep up good job :) and continue this lib for free :)

Last question : the command
TNetPack.WriteFlagsToByte%( Key1, Key2, Key3, Key4 )

How many value can be used ? example :
TNetPack.WriteFlagsToByte%( Key1, Key2, Key3, Key4,KeyJump,KeyShoot, etc etc) possible ?


Red Ocktober(Posted 2005) [#20]
that's a good idea... i second that...

--Mike


Tibit(Posted 2005) [#21]
Thanks for the feedback. Ok that would be an easy fix to rename them, I'll see to that in the next release.

WriteFlagsToByte is the same as write bits to byte. You can write at max 8 bits or flags or keys to a byte. If you need more keys simply do the process two times for a total of 16 flags.

A little more on the packing commands can be found at:
Packing Commands


Filax(Posted 2005) [#22]
Thanks Wave :) keep up good job :)