1 SynchedJSObject
trac edited this page 2008-02-23 03:18:59 +00:00

[IN SYNC WITH SYNCHEDJSOBJECT.H]KEEP

Author: Simon Brenner simon.brenner@home.se

Description

A helper class for [CJSObject]wiki:ScriptableObject 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]wiki:ScriptableObject - 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.