|
| NetObject () |
|
| ~NetObject () |
|
void | setMaskBits (U32 orMask) |
|
void | clearMaskBits (U32 orMask) |
|
void | setScopeAlways () |
|
void | clearScopeAlways () |
|
virtual F32 | getUpdatePriority (CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips) |
|
virtual U32 | packUpdate (NetConnection *conn, U32 mask, BitStream *stream) |
|
virtual void | unpackUpdate (NetConnection *conn, BitStream *stream) |
|
virtual void | onCameraScopeQuery (NetConnection *cr, CameraScopeQuery *camInfo) |
|
U32 | getNetIndex () |
| Get the ghost index of this object. More...
|
|
bool | isServerObject () const |
| Is this a server object? More...
|
|
bool | isClientObject () const |
| Is this a client object? More...
|
|
bool | isGhost () const |
| Is this is a ghost? More...
|
|
bool | isScopeLocal () const |
| Should this object only be visible to the client which created it? More...
|
|
bool | isScopeable () const |
| Is this object subject to scoping? More...
|
|
bool | isGhostable () const |
| Is this object ghostable? More...
|
|
bool | isGhostAlways () const |
| Should this object always be ghosted? More...
|
|
StringTableEntry | getClassNamespace () const |
|
StringTableEntry | getSuperClassNamespace () const |
|
void | setClassNamespace (const char *classNamespace) |
|
void | setSuperClassNamespace (const char *superClassNamespace) |
|
void | pushScriptCallbackGuard (void) |
|
void | popScriptCallbackGuard (void) |
|
S32 | getScriptCallbackGuard (void) |
|
virtual SimObject * | findObject (const char *name) |
|
Namespace * | getNamespace () |
| Return the object's namespace. More...
|
|
const char * | tabComplete (const char *prevText, S32 baseLen, bool) |
|
virtual void | dump () |
|
virtual void | dumpClassHierarchy () |
|
SimObject * | clone (const bool copyDynamicFields) |
|
virtual void | copyTo (SimObject *object) |
|
template<typename T > |
bool | isType (void) |
|
virtual bool | handlesConsoleMethod (const char *fname, S32 *routingId) |
|
| DECLARE_CONOBJECT (SimObject) |
|
Notify * | removeNotify (void *ptr, Notify::Type) |
| Remove a notification from the list. More...
|
|
void | deleteNotify (SimObject *obj) |
| Notify an object when we are deleted. More...
|
|
void | clearNotify (SimObject *obj) |
| Notify an object when we are cleared. More...
|
|
void | clearAllNotifications () |
| Remove all notifications for this object. More...
|
|
void | processDeleteNotifies () |
| Send out deletion notifications. More...
|
|
void | registerReference (SimObject **obj) |
|
void | unregisterReference (SimObject **obj) |
|
const char * | getDataField (StringTableEntry slotName, const char *array) |
|
void | setDataField (StringTableEntry slotName, const char *array, const char *value) |
|
const char * | getPrefixedDataField (StringTableEntry fieldName, const char *array) |
|
void | setPrefixedDataField (StringTableEntry fieldName, const char *array, const char *value) |
|
const char * | getPrefixedDynamicDataField (StringTableEntry fieldName, const char *array, const S32 fieldType=-1) |
|
void | setPrefixedDynamicDataField (StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType=-1) |
|
StringTableEntry | getDataFieldPrefix (StringTableEntry fieldName) |
|
U32 | getDataFieldType (StringTableEntry slotName, const char *array) |
|
SimFieldDictionary * | getFieldDictionary () |
|
void | clearDynamicFields (void) |
| Clear all dynamic fields. More...
|
|
void | setCanSaveDynamicFields (bool bCanSave) |
| Set whether fields created at runtime should be saved. Default is true. More...
|
|
bool | getCanSaveDynamicFields (void) const |
| Get whether fields created at runtime should be saved. Default is true. More...
|
|
void | setInternalName (const char *newname) |
|
StringTableEntry | getInternalName () |
| Get the internal of of this control. More...
|
|
virtual bool | save (const char *pcFilePath, bool bOnlySelected=false) |
| Save object as a TorqueScript File. More...
|
|
virtual bool | isMethod (const char *methodName) |
| Check if a method exists in the objects current namespace. More...
|
|
SimObjectId | getId (void) const |
|
StringTableEntry | getIdString (void) const |
|
U32 | getType () const |
|
const StringTableEntry | getName (void) const |
|
void | setId (SimObjectId id) |
|
void | assignName (const char *name) |
|
SimGroup * | getGroup () const |
|
bool | isChildOfGroup (SimGroup *pGroup) |
|
bool | isProperlyAdded () const |
|
bool | isDeleted () const |
|
bool | isRemoved () const |
|
bool | isLocked () |
|
void | setLocked (bool b) |
|
bool | isHidden () |
|
void | setHidden (bool b) |
|
void | setProgenitorFile (const char *pFile) |
|
StringTableEntry | getProgenitorFile (void) const |
|
void | setPeriodicTimerID (const S32 timerID) |
|
S32 | getPeriodicTimerID (void) const |
|
bool | isPeriodicTimerActive (void) const |
|
bool | isSelected () const |
|
bool | isExpanded () const |
|
void | setSelected (bool sel) |
|
void | setExpanded (bool exp) |
|
void | setModDynamicFields (bool dyn) |
|
void | setModStaticFields (bool sta) |
|
| SimObject (const U8 namespaceLinkMask=LinkSuperClassName|LinkClassName) |
|
virtual | ~SimObject () |
|
virtual bool | processArguments (S32 argc, const char **argv) |
| Process constructor options. (ie, new SimObject(1,2,3)) More...
|
|
virtual void | onGroupAdd () |
| Called when the object is added to a SimGroup. More...
|
|
virtual void | onGroupRemove () |
| Called when the object is removed from a SimGroup. More...
|
|
virtual void | onNameChange (const char *name) |
| Called when the object's name is changed. More...
|
|
virtual void | onStaticModified (const char *slotName, const char *newValue=NULL) |
|
virtual void | inspectPreApply () |
|
virtual void | inspectPostApply () |
|
virtual void | onDeleteNotify (SimObject *object) |
|
virtual void | onEditorEnable () |
| Called when the editor is activated. More...
|
|
virtual void | onEditorDisable () |
| Called when the editor is deactivated. More...
|
|
bool | registerObject () |
|
bool | registerObject (U32 id) |
|
bool | registerObject (const char *name) |
|
bool | registerObject (const char *name, U32 id) |
|
void | unregisterObject () |
|
void | deleteObject () |
|
bool | addToSet (SimObjectId) |
|
bool | addToSet (const char *) |
|
bool | removeFromSet (SimObjectId) |
|
bool | removeFromSet (const char *) |
|
virtual bool | writeField (StringTableEntry fieldname, const char *value) |
|
virtual void | write (Stream &stream, U32 tabStop, U32 flags=0) |
|
virtual void | writeFields (Stream &stream, U32 tabStop) |
|
virtual bool | writeObject (Stream *stream) |
|
virtual bool | readObject (Stream *stream) |
|
virtual void | buildFilterList () |
|
void | addFieldFilter (const char *fieldName) |
|
void | removeFieldFilter (const char *fieldName) |
|
void | clearFieldFilters () |
|
bool | isFiltered (const char *fieldName) |
|
void | assignFieldsFrom (SimObject *obj) |
|
void | assignDynamicFieldsFrom (SimObject *obj) |
|
const AbstractClassRep::Field * | findField (StringTableEntry fieldName) const |
| Get a reference to a field by name. More...
|
|
virtual AbstractClassRep * | getClassRep () const |
| Gets the ClassRep. More...
|
|
bool | setField (const char *fieldName, const char *value) |
| Set the value of a field. More...
|
|
virtual | ~ConsoleObject () |
|
const AbstractClassRep::FieldList & | getFieldList () const |
| Get a list of all the fields. This information cannot be modified. More...
|
|
AbstractClassRep::FieldList & | getModifiableFieldList () |
|
bool & | getDynamicGroupExpand () |
|
S32 | getClassId (U32 netClassGroup) const |
|
const char * | getClassName () const |
|
Superclass for ghostable networked objects.
Introduction To NetObject And Ghosting
One of the most powerful aspects of Torque's networking code is its support for ghosting and prioritized, most-recent-state network updates. The way this works is a bit complex, but it is immensely efficient. Let's run through the steps that the server goes through for each client in this part of Torque's networking:
- First, the server determines what objects are in-scope for the client. This is done by calling onCameraScopeQuery() on the object which is considered the "scope" object. This is usually the player object, but it can be something else. (For instance, the current vehicle, or a object we're remote controlling.)
- Second, it ghosts them to the client; this is implemented in netGhost.cc.
- Finally, it sends updates as needed, by checking the dirty list and packing updates.
There several significant advantages to using this networking system:
- Efficient network usage, since we only send data that has changed. In addition, since we only care about most-recent data, if a packet is dropped, we don't waste effort trying to deliver stale data.
- Cheating protection; since we don't deliver information about game objects which aren't in scope, we dramatically reduce the ability of clients to hack the game and gain a meaningful advantage. (For instance, they can't find out about things behind them, since objects behind them don't fall in scope.) In addition, since ghost IDs are assigned per-client, it's difficult for any sort of co-ordination between cheaters to occur.
NetConnection contains the Ghost Manager implementation, which deals with transferring data to the appropriate clients and keeping state in synch.
An Example Implementation
The basis of the ghost implementation in Torque is NetObject. It tracks the dirty flags for the various states that the object trackers, and does some other book-keeping to allow more efficient operation of the networking layer.
Using a NetObject is very simple; let's go through a simple example implementation:
Above is the standard boilerplate code for a Torque class. You can find out more about this in SimObject.
char message1[256];
char message2[256];
enum States {
Message1Mask = BIT(0),
Message2Mask = BIT(1),
};
For our example, we're having two "states" that we keep track of, message1 and message2. In a real object, we might map our states to health and position, or some other set of fields. You have 32 bits to work with, so it's possible to be very specific when defining states. In general, you should try to use as few states as possible (you never know when you'll need to expand your object's functionality!), and in fact, most of your fields will end up changing all at once, so it's not worth it to be too fine-grained. (As an example, position and velocity on Player are controlled by the same bit, as one rarely changes without the other changing, too.)
{
dStrcpy(message1, "Hello World 1!");
dStrcpy(message2, "Hello World 2!");
}
Here is the constructor. Here, you see that we initialize our net flags to show that we should always be scoped, and that we're to be taken into consideration for ghosting. We also provide some initial values for the message fields.
Here's half of the meat of the networking code, the packUpdate() function. (The other half, unpackUpdate(), we'll get to in a second.) The comments in the code pretty much explain everything, however, notice that the code follows a pattern of if(writeFlag(mask & StateMask)) { ... write data ... }. The packUpdate()/unpackUpdate() functions are responsible for reading and writing the dirty bits to the bitstream by themselves.
The other half of the networking code in any NetObject, unpackUpdate(). In our simple example, all that the code does is print the new messages to the console; however, in a more advanced object, you might trigger animations, update complex object properties, or even spawn new objects, based on what packet data you unpack.
void setMessage1(const char *msg)
{
dStrcpy(message1, msg);
}
void setMessage2(const char *msg)
{
dStrcpy(message2, msg);
}
Here are the accessors for the two properties. It is good to encapsulate your state variables, so that you don't have to remember to make a call to setMaskBits every time you change anything; the accessors can do it for you. In a more complex object, you might need to set multiple mask bits when you change something; this can be done using the | operator, for instance, setMaskBits( Message1Mask | Message2Mask ); if you changed both messages.
ConsoleMethod(
SimpleNetObject, setMessage1,
void, 3, 3,
"(string msg) Set message 1.")
{
object->setMessage1(argv[2]);
}
ConsoleMethod(
SimpleNetObject, setMessage2,
void, 3, 3,
"(string msg) Set message 2.")
{
object->setMessage2(argv[2]);
}
Finally, we use the NetObject implementation macro, IMPLEMENT_CO_NETOBJECT_V1(), to implement our NetObject. It is important that we use this, as it makes Torque perform certain initialization tasks that allow us to send the object over the network. IMPLEMENT_CONOBJECT() doesn't perform these tasks, see the documentation on AbstractClassRep for more details.