Updating variables on the client
by Paul /*Wedge*/ DElia · in Torque Game Engine · 11/18/2005 (3:15 am) · 9 replies
I thought I'd finally understood this stuff, after working with all the resources, but it's slapping me in the face and not working. I added a variable to shapebase.h called "bool LinearMotion;" right at the bottom before "DECLARE_CONOBJECT(ShapeBase)". I added the initilization and checks in shapebase.cc I wanted for the variable. I added the variable to packUpdate and unpackUpdate as "stream->writeFlag(LinearMotion);" and "LinearMotion = stream->readFlag();" in the proper orders. And then I added a console function at the end as
ConsoleMethod( ShapeBase, setLinearMotion, void, 3, 3, "(bool lmtoggle)"){
object->LinearMotion = dAtob(argv[2]);
}The value forces updateContainer to set mGravityMod to 0 in cases where I want to move without gravity. However no matter what I try, the variable is only getting changed on the server ghost, resulting in choppy motion as the server and client fight over the gravity. I'm totally lost as to why it's doing this, maybe I'm just missing something stupid. I can give anyone the .cc and .h files to check if I screwed up anything there.About the author
#2
11/18/2005 (11:48 am)
Does he need to also add the synchronization stuff to readPacketData and writePacketData?
#3
11/18/2005 (12:06 pm)
Yes, if the object(s) in question would ever be a control object. Good point!
#4
11/18/2005 (2:28 pm)
Okay, yes, I was using a mask earlier with this, but was trying to get it to the most barebones working. What is this synchronization stuff you are talking about though? My code when I uncommented the stuff is likeif (stream->writeFlag(mask & ModifierMask)){
//Con::errorf("writing modifier flags");
stream->writeFlag(FOVLimitBreak);
stream->writeFlag(LinearMotion);
}
...
if (stream->readFlag()){
FOVLimitBreak = stream->readFlag();
LinearMotion = stream->readFlag();
}
...
ConsoleMethod( ShapeBase, setLinearMotion, void, 3, 3, "(bool lmtoggle)"){
if(object->isServerObject()){
object->LinearMotion = dAtob(argv[2]);
object->setMaskBits(object->ModifierMask);
}
}And I'd added that mask to the ShapeBase masks
#5
11/20/2005 (4:25 am)
Really, what is this about synchronization to readPacket and writePacket?
#6
11/20/2005 (7:44 am)
If an object is a control object, it has information sent to the controlling client via read/writePacketData as well as pack/unpackUpdate. For a control object of that client, you don't want to duplicate the information in both of these data feeds, so if it is a control object you should send it in writePacketData for that client, and in packUpdate for all other clients.
#7
11/20/2005 (12:23 pm)
Ah okay cool, it's working now, but I don't exactly understand why? There's no mask settings in the read/write updates, so it's always updating I guess. But these are just values updated in certain situations, so is there anything I should be doing aside from adding them to the read/write without the mask?
#8
Basically, you will be sending that data 10 times a second for each copy of your object class, regardless of if the information has changed (and therefore really needs to be sent) or not!
11/21/2005 (5:25 am)
You may want to take a look at the TDN Article on Torque Networking--it provides a lot of the background and specifics of the Torque networking model--including why you should absolutely not send the data without mask settings as you mention above!Basically, you will be sending that data 10 times a second for each copy of your object class, regardless of if the information has changed (and therefore really needs to be sent) or not!
#9
11/21/2005 (4:53 pm)
No no no, I mean there is no mask value passed into ShapeBase::write/readPacketData, so you can't use them there. I don't understand what those functions are for, they only have a setup for reading and writing the players energy state by default. Everything else is in ShapeBase::pack/unpackUpdate, which is all I thought I needed.
Torque 3D Owner Stephen Zepp
if (mask & XXXMask)
...pack up this data element
for each of the logical groupings of networked data. You need to note which one of the Mask bits you happened to use in your packUpdate(), and call the setMaskBits for your object on that mask within your ConsoleMethod.