Introduction Manual Class Reference Header Reference

ZCom_Replicate_Movement< T, SIZE > Class Template Reference

Inheritance diagram for ZCom_Replicate_Movement< T, SIZE >:

Inheritance graph
[legend]
Collaboration diagram for ZCom_Replicate_Movement< T, SIZE >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename T, int SIZE>
class ZCom_Replicate_Movement< T, SIZE >

Replicator for object positions.

Parameters:
T Type of position vector. Supported are zU32, zS32 and zFloat.
SIZE Size of position, velocity and accel vectors.
This replicator replicates position, velocity and acceleration vectors for an object. The dimension of the vectors is given by the SIZE parameter to the template. ZCom_Replicate_Movement<zFloat, 3> will replicate 3D vectors of floats.

Peeking is not supported for this replicator.

See ex07_movement (in the samples directory) for example usage.

See also:
Replicating Player Movement


Public Member Functions

zU32getLastUpdateTime (ZCom_ConnID _cid)
 Get pointer to time of last update to given connection.
ZCom_NodegetNode () const
 Get the node in which this replicator is registered.
void sendData (eZCom_SendMode _mode, ZCom_BitStream *_stream, zU32 _reference_id=0)
 Sends an event to peer replicators.
void sendDataDirect (eZCom_SendMode _mode, ZCom_ConnID _dest, ZCom_BitStream *_stream, zU32 _reference_id=0)
 Same as sendData(), but with single destination.
void setNode (ZCom_Node *_node)
 Set the node in which this replicator is registered.
ZCOM_TAPI void setTimeScale (zFloat _scale)
 Set timescale of movement.
ZCOM_TAPI void setUpdateListener (ZCom_MoveUpdateListener< TYPE > *_listener)
 Set the mandatory update listener.
ZCOM_TAPI ZCom_Replicate_Movement (zU8 _rbits, zU8 _flags, zU8 _rules, zU8 _intercept_id=0, zS16 _mindelay=-1, zS16 _maxdelay=-1)
 constructor, builds the replicator setup automatically
ZCOM_TAPI ZCom_Replicate_Movement (ZCom_RSetupMovement< TYPE > *_setup)
 constructor, taking a ZCom_ReplicatorSetup pointer
Data fetching.
Use these to get the current state.

ZCOM_TAPI void getAcceleration (zFloat *_data)
 Get the current acceleration used for extrapolation.
ZCOM_TAPI void getExtrapolatedPosition (zS32 _attime, TYPE *_data)
 Get extrapolated position for given time.
ZCOM_TAPI void getExtrapolatedVelocity (zS32 _attime, zFloat *_data)
 Get the current velocity used for extrapolation.
ZCOM_TAPI void getLastReceivedPosition (T *_data)
 Get last received position.
ZCOM_TAPI void getLastReceivedVelocity (zFloat *_data)
 Get last received velocity.
Owner data updates and input API.
Feed owner with input data and retrieve past input data to apply corrections from auth.

ZCOM_TAPI ZCom_BitStreamgetNextInputHistoryEntry (zU32 *_deltatime, void **_iter)
 Get the next inputstream that has to be reapplied after the correction.
ZCOM_TAPI void updateInput (T *_pos, ZCom_BitStream *_inputstream)
 Feed input data to owner.
Debugging
ZCOM_TAPI void getSplineControlPoint (zU32 _idx, TYPE *_data)
 Get a control point from the spline.
ZCOM_TAPI void getSplinePoint (zFloat t, TYPE *_data)
 Get a point on the interpolation spline.
Proxy data overrides.
Temporarily and locally override values on proxy.

ZCOM_TAPI void overrideState (TYPE *_newpos, zFloat *_newvel, zFloat *_newaccel, zS32 _time=0)
 Override position, velocity and acceleration.
Authority data updates
Update data on authority.

ZCOM_TAPI void updateState (TYPE *_newpos, zFloat *_newvel, zFloat *_newaccel, bool _teleport)
 Update position, velocity and acceleration.

Protected Attributes

zU8 m_flags
 Additional replicator flags. ZCom_Replicator() c'tor will set this to 0. (ZCOM_REPLICATOR_*).
ZCom_ReplicatorSetupm_setup
 pointing to an instance of the setup class - all replication parameters are stored here


Constructor & Destructor Documentation

template<typename T, int SIZE>
ZCOM_TAPI ZCom_Replicate_Movement< T, SIZE >::ZCom_Replicate_Movement ZCom_RSetupMovement< TYPE > *  _setup  ) 
 

constructor, taking a ZCom_ReplicatorSetup pointer

template<typename T, int SIZE>
ZCOM_TAPI ZCom_Replicate_Movement< T, SIZE >::ZCom_Replicate_Movement zU8  _rbits,
zU8  _flags,
zU8  _rules,
zU8  _intercept_id = 0,
zS16  _mindelay = -1,
zS16  _maxdelay = -1
 

constructor, builds the replicator setup automatically


Member Function Documentation

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::setTimeScale zFloat  _scale  ) 
 

Set timescale of movement.

Parameters:
_scale The time scale.
Inform replicator about application's timescale. If this is not set, a scale of 1 is applied, i.e. Zoidcom assumes a physics update frequency of 1000 hz (a velocity of 5 then equals to 5 units per millisecond = 5000 units per second).

Set the scale to your_physics_rate/1000. For a 50hz update frequency, scale should be 0.05.

If your update frequency is fixed at a constant rate, you can leave this value at 1, and call ZCom_Control::processReplicators(1) instead of the actually passed simulation time.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::setUpdateListener ZCom_MoveUpdateListener< TYPE > *  _listener  ) 
 

Set the mandatory update listener.

Parameters:
_listener Pointer to initialized ZCom_MoveUpdateListener instance.
The ZCom_MoveUpdateListener interface informs authority and owner nodes about incoming player input updates and correction feedback. It is necessary for the data flow of this replicator.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::updateInput T *  _pos,
ZCom_BitStream _inputstream
 

Feed input data to owner.

Parameters:
_pos *Current* position of owner's object. May be NULL.
_inputstream Bitstream containing application's input data. Like 4 bools for (up/down/left/right).
The _pos parameter is sent to the authority along with the _inputstream. _pos is not used to update the authority in any way, the authority only needs this data to check if the owner has the correct values. If the sent data differs from the authority's data by more than the allowed error threshold, the authority will issue a correction on the owner.

Calling this method results in the ZCom_MoveUpdateListener::inputUpdated() callback to be called on the authority. In case of correction, ZCom_MoveUpdateListener::correctionReceived() will be called later on the owner.

Attention:
Zoidcom takes ownership over the _inputstream bitstream, it may not be deleted or altered after it has been passed to this method.

template<typename T, int SIZE>
ZCOM_TAPI ZCom_BitStream* ZCom_Replicate_Movement< T, SIZE >::getNextInputHistoryEntry zU32 _deltatime,
void **  _iter
 

Get the next inputstream that has to be reapplied after the correction.

Parameters:
_deltatime Pass a pointer to a zU32 here and the method will store the passed simulation time between the returned and the previous input stream.
Returns:
Pointer to bitstream originally given to updateInput(). Don't modify or delete it. If NULL is returned, there is nothing to reapply.
When a correction arrives on the owner, the corrected data is data of the past. In fact, the age of the data equals the ping between owner and authority. Therefore, the correction has to be applied in the past. After the correction has been applied, all movement updates that happened after the corrected one, have to be reapplied.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::updateState TYPE *  _newpos,
zFloat _newvel,
zFloat _newaccel,
bool  _teleport
 

Update position, velocity and acceleration.

Parameters:
_newpos Pointer to array of TYPE[SIZE] containing the new position. May be NULL.
_newvel Pointer to array of zFloat[SIZE] containing the new velocity. May be NULL.
_newacc Pointer to array of zFloat[SIZE] containing the new acceleration. May be NULL.
_teleport If true, tells proxies to apply the new pos directly, instead of interpolating to it.
Call this method on authority and the update will get sent to proxies and owners.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::overrideState TYPE *  _newpos,
zFloat _newvel,
zFloat _newaccel,
zS32  _time = 0
 

Override position, velocity and acceleration.

Parameters:
_newpos Pointer to array of TYPE[SIZE] containing the new position.
_newvel Pointer to array of TYPE[SIZE] containing the new velocity.
_newacc Pointer to array of TYPE[SIZE] containing the new acceleration.
_time Relative time. 0 == current simulation time.
The physics state will be locally overridden. All consecutive queries to getPosition() etc will return values based on the overridden state, until the next update from the authority arrives.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getExtrapolatedPosition zS32  _attime,
TYPE *  _data
 

Get extrapolated position for given time.

Parameters:
_attime Time for which the extrapolation is needed. 0 = current simulation time.
_data Pointer to array where the result will get stored.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getExtrapolatedVelocity zS32  _attime,
zFloat _data
 

Get the current velocity used for extrapolation.

Parameters:
_attime Time for which the extrapolation is needed. 0 = current simulation time.
_data Pointer to array where the result will get stored.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getAcceleration zFloat _data  ) 
 

Get the current acceleration used for extrapolation.

Parameters:
_data Pointer to array where the result will get stored.
Acceleration is constant during extrapolation.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getLastReceivedPosition T *  _data  ) 
 

Get last received position.

Parameters:
_data Pointer to array where the result will get stored.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getLastReceivedVelocity zFloat _data  ) 
 

Get last received velocity.

Parameters:
_data Pointer to array where the result will get stored.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getSplinePoint zFloat  t,
TYPE *  _data
 

Get a point on the interpolation spline.

Parameters:
_t Must be between 0 <= t <= 1. 0 gives the start point of the interpolation, 1 the endpoint.
_data Pointer to an array of TYPE with SIZE elements.

template<typename T, int SIZE>
ZCOM_TAPI void ZCom_Replicate_Movement< T, SIZE >::getSplineControlPoint zU32  _idx,
TYPE *  _data
 

Get a control point from the spline.

Parameters:
_idx Must be 0 <= _idx <= 3.
_data Pointer to an array of TYPE with SIZE elements.

ZCom_Node* ZCom_ReplicatorAdvanced::getNode  )  const [inherited]
 

Get the node in which this replicator is registered.

Returns:
A pointer to the node.

zU32* ZCom_ReplicatorAdvanced::getLastUpdateTime ZCom_ConnID  _cid  )  [inherited]
 

Get pointer to time of last update to given connection.

Parameters:
_cid Id of connection.
Returns:
Pointer(!!) to time in msecs.
This method should be used for implementing min- and maxdelay enforcement.

If the result is non-NULL, writing to this pointer is encouraged, as advanced replicators have to manage timing on their own.

Attention:
This is only available (i.e. non-NULL) if at least one replicator in the node has a mindelay or maxdelay activated. If this is not the case, the method returns NULL.
Code example:
 zU32* lastupdate = getLastUpdateTime(id_of_connection_which_is_currently_processed);
 if (lastupdate) {
   if (ZoidCom::getTime() - *lastupdate < m_setup->getMinDelay())
     // don't send data if last update to this happened too recent
     return;
   else
     // store the current time because an update gets sent now
     *lastupdate = ZoidCom::getTime();
 }

void ZCom_ReplicatorAdvanced::sendData eZCom_SendMode  _mode,
ZCom_BitStream _stream,
zU32  _reference_id = 0
[inherited]
 

Sends an event to peer replicators.

Parameters:
_mode eZCom_SendMode. eZCom_ReliableOrdered is not supported in this context.
_stream The event data.
_reference_id If send mode is eZCom_UnreliableNotify, this id will be given back to the application through onDataLost() or onDataAcked().
This event will be received by all replicators which normally receive data from this replicator, too. If this replicator is owned by an authority node and the replicator is flagged ZCOM_REPFLAG_AUTH_2_PROXY, all replicators owned by a proxy of this replicators node will receive this event.

In order to handle the event, overload ZCom_ReplicatorAdvanced::onDataReceived().

Replicator events are sent reliable unordered or unreliable.

Attention:
Make sure that onDataReceived() reads the same amount of bits sendEvent() has written, otherwise the stream can't be extracted any further.

Please note that calling sendData() won't ensure the data is sent immediately. The data will be sent as soon as the owning node's priority allows the node to send. If you want to generate data which is sent immediately, wait for the onPreSendData() callback.

void ZCom_ReplicatorAdvanced::sendDataDirect eZCom_SendMode  _mode,
ZCom_ConnID  _dest,
ZCom_BitStream _stream,
zU32  _reference_id = 0
[inherited]
 

Same as sendData(), but with single destination.

Parameters:
_mode eZCom_SendMode. eZCom_ReliableOrdered is not supported in this context.
_dest Connection ID of destination.
_stream The event data.
_reference_id If send mode is eZCom_UnreliableNotify, this id will be given back to the application through onDataLost() or onDataAcked().
In order to handle the event, overload ZCom_ReplicatorAdvanced::onDataReceived().

Replicator events are sent reliable unordered or unreliable.

Attention:
Make sure that onDataReceived() reads the same amount of bits sendEvent() has written, otherwise the stream can't be extracted any further.

Please note that calling sendData() won't ensure the data is sent immediately. The data will be sent as soon as the owning node's priority allows the node to send. If you want to generate data which is sent immediately, wait for the onPreSendData() callback.

void ZCom_ReplicatorAdvanced::setNode ZCom_Node _node  )  [inherited]
 

Set the node in which this replicator is registered.

Parameters:
_node The node pointer.
This will get called automatically by ZCom_Node::addReplicator(). There is normally no reason to call this method.

void* ZCom_Replicator::operator new size_t  _size  )  [inherited]
 

Overloaded memory operator ensuring that always Zoidcom's new gets called.

Attention:
Don't overload this unless you are 100% sure what you are doing.

void ZCom_Replicator::operator delete void *  _p  )  [inherited]
 

Overloaded memory operator ensuring that always Zoidcom's delete gets called.

Attention:
Don't overload this unless you are 100% sure what you are doing.

ZCom_BitStream* ZCom_Replicator::getPeekStream  )  const [protected, inherited]
 

Get stream currently processed for peeking the data.

Returns:
Pointer to current ZCom_BitStream.
As you might have noticed, peekData() does not have a ZCom_BitStream parameter. That's the case because peekData() must be called from inside ZCom_NodeReplicationInterceptor::inPreUpdateItem(), and this interceptor callback has no access to the currently processed stream. Use this method to get a pointer to the currently processed stream instead.

This will only return a valid result when called from inside the above mentioned interceptor callback.

void ZCom_Replicator::peekDataStore void *  _ptr  )  [protected, inherited]
 

Store pointer to allocated peekbuffer, so it can be deleted again.

Parameters:
_ptr Pointer to the allocated memory.
The pointer will get stored in a global Thread Local Storage, so that multiple ZCom_Controls can safely operate simultaneously in different threads. When a replicator's peekData() makes use of this method, expect to get a call to clearPeekData() sometime soon, which is supposed to free the allocated memory again.

When you call peekDataStore() more than once with a pointer != NULL, clearPeekData() will get called automatically.

Thread Local Storage means, there is one variable for each thread of the program. Replicators could as well declare a member variable used for that purpose instead, but that would waste a lot of memory when peeking interceptors are not used.

void* ZCom_Replicator::peekDataRetrieve  )  [protected, inherited]
 

Retrieve the peekbuffer pointer currently stored.

Returns:
Pointer previously stored with peekDataStore().


Member Data Documentation

zU8 ZCom_Replicator::m_flags [protected, inherited]
 

Additional replicator flags. ZCom_Replicator() c'tor will set this to 0. (ZCOM_REPLICATOR_*).

ZCom_ReplicatorSetup* ZCom_Replicator::m_setup [protected, inherited]
 

pointing to an instance of the setup class - all replication parameters are stored here


This file is part of the documentation for Zoidcom. Documentation copyright © 2004-2008 by Jörg Rüppel. Generated on Sat Aug 16 15:26:50 2008 for Zoidcom by doxygen 1.4.6-NO