Game Development Community

Pack/Unpack SimObjectPtr

by Johnathan Moore · in Torque Game Engine · 04/10/2006 (12:33 pm) · 3 replies

Hey,
Could some one tell me how to read and write a SimObjectPtr datatype in the pack and unpack functions because the simple read and write commands do not work,would I have to change the datatype to pack

#1
04/10/2006 (12:56 pm)
Since SimObjectPtr is a pointer to a memory location,
it's probably a very bad idea to transmit it across the network.

- The server's memory address for the object is going to be different than the client's.

You probably want to use the object's ID (from getId()),
converted to a ghost index in packUpdate via NetConnection's getGhostIndex(),
and unconverted in unpackUpdate via NetConnection's resolveGhost().
#2
04/10/2006 (1:49 pm)
As Orion states, pass object ID's. Have a look at projectile.cc specifically how mSourceObject is passed from server to client. In short in packupdate the object ghost index is transmit, then in unpack data the id is resolved.

Another example would be the packdata method of the playerdata datablock which transmits datablock id's for particles/sounds etc This takes a bit of a shortcut by storing the received ID in the same variable and then later replacing it with a pointer to the correct object in the preload function.

Both methods however pass the ID, just take care to transmit the ghost index and not just the getID().
#3
04/10/2006 (1:54 pm)
Sorry, I missunderstood the use of the function, I was just adding all the variables in the class to it there is no point of the handles being on the client side