[KEEP IN SYNC WITH SYNCHEDJSOBJECT.H]

Author: Simon Brenner <simon.brenner@…>

Description

A helper class for CJSObject that enables a callback to be called whenever an attribute of the class changes and enables all (synched) properties to be set and retrieved as strings for network sync. All string conversions are performed by specific functions that use a strictly (hrm) defined format - or at least a format that is specific for the type in question (which is why JSParseString can't be used - the JS interface's ToString function is also not usable since it often produces a human-readable format that doesn't parse well and might change outside the control of the network protocol).

This replaces CAttributeMap for both player and game attributes.

Usage

First you must create your subclass, make it inherit from CSynchedJSObject and implement the pure virtual method Update (see prototype below).

Then you may use it just like CJSObject - with one exception: Any property you want to be synchronized (i.e. have the new property functionality including the update callback) is added using the AddSynchedProperty method instead: AddSynchedProperty(name, &m_Property).

The extra arguments that exist in the AddProperty method haven't been implemented. (if you by any chance would need to, just do it ;-)

CSynchedJSObject Methods

Update

  • Overview:
    • Called every time a property changes.
  • Syntax:
    • void Update(CStrW name, ISynchedJSProperty* property)
  • Parameters:
    • name [CStrW], property [ISynchedJSProperty*]
  • Returns:
  • Notes:
    • This is where the individual callbacks are dispatched from.

AddSynchedProperty

  • Overview:
    • Add a property to the object; if desired, a callback is called every time it changes.
  • Example:
    • AddSynchedProperty(L"numSlots", &m_NumSlots, &CGameAttributes::OnNumSlotsUpdate);
  • Parameters:
    • name [CStrW], native [templated], update callback [UpdateFn] (optional)
  • Returns:
  • Notes:
    • Replaces CJSObject's AddProperty.
Last modified 16 years ago Last modified on Feb 23, 2008, 4:18:59 AM
Note: See TracWiki for help on using the wiki.