Game Development Community

synching variables on client and server

by Jared Hoberock · in Torque Game Engine · 02/25/2002 (11:50 am) · 2 replies

if I have a basic variable defined in shapebase.h and functions in shapebase.cc that modify the value, how do I keep the value synchronized on the server and client? Does it have something to do with mClampF or Con::executef? Those are funcs that I have noticed in the damage control system but I do not use.
This seems like it should be easy, but the var value never changes on the server, although it does on the client.

#1
02/26/2002 (7:29 pm)
You're going to have to mess with the packet-writing stuff in order to send from server to client back to server. I'll try to find you the files needed to look into for an example (read and write and pack and unpack) but I'm at school at the moment.

I haven't really messed with packing and unpacking since all the stuff I've done right now is either server-side but in script, or client side in c++.
#2
03/11/2002 (1:11 pm)
Yeah, as he said, the server object sends updates to the client ghost via packUpdate, and the client interprets them via unpackUpdate. There's an embarrassment of examples in the engine code so it shouldn't be hard to figure this out.

The only somewhat-tricky part is that you need to provide some indication of when an update needs to be sent. As an example, look at the setShapeName member function. When it changes the name, it also calls setMaskBits(NameMask). NameMask is one of the bitflags defined in ShapeBase::ShapeBaseMasks (in shapeBase.h). By calling this function, setShapeName is indicating a) that the client needs to be updated and b) exactly what piece of information needs to be sent. Look at packUpdate to see how NameMask is used, and then look at unpackUpdate to see how the transmitted info is processed. Once you understand what's going on there, you're all set.

If you need to create another mask bit for use with your new member field, edit the ShapeBaseMasks definition accordingly.

If you're wondering when that mask bit ever gets cleared after you set it, the lower-level engine code automatically clears those bits after sending an update.