Game Development Community

Packet read/writes?

by Markus Nuebel · in Torque Game Engine · 01/22/2004 (11:11 pm) · 3 replies

Hi guys.

I have a question regarding the packet read/write functions:
writePacketData/readPacketData and packUpdate/unpackUpdate.

Here is what the docs say:
void  writePacketData (GameConnection *conn, BitStream *stream) 
  Write state information necessary to perform client side prediction of an object. 
 
void  readPacketData (GameConnection *conn, BitStream *stream) 
  Read data written with writePacketData() and update the object state. 
 
U32  packUpdate (NetConnection *conn, U32 mask, BitStream *stream) 
  Instructs this object to pack its state for transfer over the network. 
 
void  unpackUpdate (NetConnection *conn, BitStream *stream) 
  Instructs this object to read state data previously packed with packUpdate.


It is not clear to me at which points in program execution each function is called. Are they called every frame or just when there are changes to data?

I have added a new member flag to the player class and want to update the client, whenever the server changes it. I placed my code in packUpdate, but the function is not called when the member flag is changed. (Although I am setting a mask bit on every changes.)
So I guess packUpdate and unpackUpdate is not called every frame??

Can someone give me more detailed explanation of the four functions?

Best regards
Markus

#1
01/23/2004 (10:02 am)
Have you read the docs for NetObject?

Basically, write/readPacket are there to do high precision updates to the player controlling the object (if any).

pack/unpackUpdate are there to do incremental updates. You need to call setMaskBits() to set bits for it to update. The object must also be ghosted across the network - ie, it must be in scope for at least one connection or else it shan't be written to a packet.

You may need to tweak mNetFlags ( perhaps bitwise OR Ghostable into it?) to get the object to ghost properly.
#2
01/26/2004 (11:45 pm)
Hi Ben.

Yes I have read the doc, but I am still not comfortable with the network programming paradigm. But it's getting better day by day ;)

Thanks for your tip.
As always you were right. Tweaking the flags, did the job.

Thanks.
-- Markus
#3
01/27/2004 (10:05 am)
Good luck figuring the networking out. It's quite an interesting thing - well worth matsering, IMHO. ;)

Glad you solved your problem!