![]() |
VR-Forces Developer's Guide
|
Interface messages use DtSimInterfaceContent objects to store the message data. This example shows how to create a new subclass of DtSimInterfaceContent, MyInterfaceContent, to send a new type of message. The general procedure for creating a new interface message is the following:
Register the new DtSimInterfaceContent with the DtInterfaceContentFactory. If NewType is an integer constant that corresponds to your type() function, and NewContentClass::creator is a pointer to your creator function, you can change the main.cxx of your GUI and sim engine to register the new content as follows:
DtSimInterfaceContent is an abstract class. Any derived class must include a type() member function that returns the type of interface message this content is used for. The type() member function has the following specification:
A class derived from DtSimInterfaceContent needs to provide this type() member function, and should provide mutators and accessors for the information (if any) it will convey. A class derived from DtSimInterfaceContent must also provide a clone() member function. The clone() member function is specified as:
Clone functions are typically implemented by calling the class’s copy constructor, for example,
If your new message has additional parameters, add class member variables to represent the data. Make sure the clone() function that you define handles the copying of any new member data. Any member variables that you add are copied to or from a network representation for transmission over the network.
To make the new message capable of being sent over the network, you must provide a network representation for your class. To do this you must serialize all parameters of your message into a character buffer, and then be able to unserialize them back into the class data members.
You may do this in a number of ways, including making a C-style structure using the MAK "Net" types, such as DtNetInt32 (defined in vlNetTypes.h). These types manage byte order swapping when necessary to ensure platform independence.
VR-Forces also supplies a number of functions in the DtBufferSerialize namespace for serializing data. This is the recommended way of creating the network representation for your new messages, and this is the technique used in this example.
The netRepSize() member function of your class must return the total number of bytes that will be needed to serialize your class in its current state. This may vary depending on the current values of arguments. For example, if you class has a string argument, the size needed to serialize your class will vary depending on the length of the string value.
The setFromNet() function sets class member data from a network buffer. Using the DtBufferSerialize utility member functions, your member function would look something like this:
The setToNet() function fills in the network representation of the interface content class from the content arguments. This function must call netRep() at the start to allocate the network buffer (myNetRep), if it has not already been created. Using the DtBufferSerialize utility functions, your member function would look like this:
Header file: