![]() |
||||||||
|
|
||||||||


As opposed to basic replicators (ZCom_ReplicatorBasic) which are aided by Zoidcom a lot, the advanced replicator interface allows replicators to fully control when data has to be sent, to whom, in which manner and how often. This results in extremely high flexibility and on the other hand requires more work to get it working.
One restriction remains, though. The replicator cannot surpass the owning node's priority. It is only able to send when the owning node is allowed to send.
Interceptor peek support. | |
The methods getPeekData() and clearPeekData() need to be implemented when the replicator is supposed to be intercepted. Using these methods, the interceptor callback can ask the replicator to peek into the stream, without altering it's read position. Inspecting the data provided by the peekData() method, the callback can then decide if the update should be let through or not. A interceptor trying to see what is in the stream only needs to call the peekData() method. Everything else is handled by the replicator itself. A replicator that should support peeking has to implement peekData(), using getPeekStream() to get the currently processed bitstream. If it needs to allocate memory to hold the data, it has to make use of peekDataStore() in peekData(), and peekDataRetrieve() in clearPeekData().
class MyReplicator : public ZCom_Replicator { void * peekData() { int size = getPeekStream()->getStringSize(); char *string = new char[size]; getPeekStream()->getString(string, size); // store it so it can be deleted later peekDataStore(buf); return (void*) buf; } void clearPeekData() { char *str = peekDataRetrieve(); if (str) delete []str; } Zoidcom automatically notices if data has been stored and calls clearPeekData() after the interceptor has completed. If the stream contains very simple data for which no memory allocation is needed, this will do: void *MyReplicator::peekData() { return (void*) getPeekStream()->getInt(32); } void MyReplicator::clearPeekData() {}
More information can be found in the documentation of each peek method. | |
| virtual void | clearPeekData ()=0 |
| If peekData() has allocated memory, clear it here. | |
| virtual void * | peekData ()=0 |
| Unpack data from the stream, but don't update the local data. | |
| ZCom_BitStream * | getPeekStream () const |
| Get stream currently processed for peeking the data. | |
| void * | peekDataRetrieve () |
| Retrieve the peekbuffer pointer currently stored. | |
| void | peekDataStore (void *_ptr) |
| Store pointer to allocated peekbuffer, so it can be deleted again. | |
Public Member Functions | |
| zU32 * | getLastUpdateTime (ZCom_ConnID _cid) |
| Get pointer to time of last update to given connection. | |
| ZCom_Node * | getNode () const |
| Get the node in which this replicator is registered. | |
| virtual void | onConnectionAdded (ZCom_ConnID _cid, eZCom_NodeRole _remoterole)=0 |
| A node has become relevant on the specified connection and thus to this replicator, too. | |
| virtual void | onConnectionRemoved (ZCom_ConnID _cid, eZCom_NodeRole _remoterole)=0 |
| The node on this connection is no longer relevant. | |
| virtual void | onDataReceived (ZCom_ConnID _cid, eZCom_NodeRole _remoterole, ZCom_BitStream &_stream, bool _store, zU32 _estimated_time_sent)=0 |
| Data has been received from the replicator of a remote node. | |
| virtual void | onLocalRoleChanged (eZCom_NodeRole _oldrole, eZCom_NodeRole _newrole)=0 |
| The role of the local node which owns this replicator has changed. | |
| virtual void | onPacketReceived (ZCom_ConnID _cid)=0 |
| The given connection has received a packet. | |
| virtual void | onPreSendData (ZCom_ConnID _cid, eZCom_NodeRole _remoterole, zU32 *_lastupdate)=0 |
| Zoidcom is about to transmit data to the given client. | |
| virtual void | onRemoteRoleChanged (ZCom_ConnID _cid, eZCom_NodeRole _oldrole, eZCom_NodeRole _newrole)=0 |
| The role of a node on a remote connection has changed it's role. | |
| virtual void | Process (eZCom_NodeRole _localrole, zU32 _simulation_time_passed)=0 |
| Do any kind of processing. | |
| 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. | |
Protected Attributes | |
| zU8 | m_flags |
| Additional replicator flags. ZCom_Replicator() c'tor will set this to 0. (ZCOM_REPLICATOR_*). | |
| ZCom_ReplicatorSetup * | m_setup |
| pointing to an instance of the setup class - all replication parameters are stored here | |
|
|
Get the node in which this replicator is registered.
|
|
|
Get pointer to time of last update to given connection.
If the result is non-NULL, writing to this pointer is encouraged, as advanced replicators have to manage timing on their own.
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(); } |
|
||||||||||||||||
|
Sends an event to peer replicators.
In order to handle the event, overload ZCom_ReplicatorAdvanced::onDataReceived(). Replicator events are sent reliable unordered or unreliable.
|
|
||||||||||||||||||||
|
Same as sendData(), but with single destination.
Replicator events are sent reliable unordered or unreliable.
|
|
||||||||||||||||
|
Zoidcom is about to transmit data to the given client.
Example code for _lastupdate usage: if (_lastupdate) { // don't update if (ZoidCom::getTime() - *_lastupdate < m_setup->getMinDelay()) return; // after update was sent, store the current time *_lastupdate = ZoidCom::getTime(); } |
|
||||||||||||||||||||||||
|
Data has been received from the replicator of a remote node.
|
|
|
The given connection has received a packet.
|
|
||||||||||||
|
A node has become relevant on the specified connection and thus to this replicator, too.
|
|
||||||||||||
|
The node on this connection is no longer relevant.
|
|
||||||||||||
|
The role of the local node which owns this replicator has changed.
|
|
||||||||||||||||
|
The role of a node on a remote connection has changed it's role.
|
|
|
Set the node in which this replicator is registered.
|
|
|
Overloaded memory operator ensuring that always Zoidcom's new gets called.
|
|
|
Overloaded memory operator ensuring that always Zoidcom's delete gets called.
|
|
|
Unpack data from the stream, but don't update the local data.
The bitstream to peek from must be acquired with getPeekStream(). It will be restored to it's previous read position after peekData() has returned.
Implemented in ZCom_Interpolate< T, SIZE >, and ZCom_Replicate_Numeric< T, SIZE >. |
|
|
If peekData() has allocated memory, clear it here. This has to be implemented in order to clear up any memory allocated by peekData(). Use peekDataRetrieve() to acquire the pointer stored by peekDataStore() earlier. It is not necessary to call peekDataStore(NULL) to clear the pointer as Zoidcom will do this automatically. This method will get called right after ZCom_NodeReplicationInterceptor::inPreUpdateItem() returned but only if peekDataStore() has been used inside the interceptor. This method will also get called from inside peekDataStore() if it holds a pointer from a previous call to peekDataStore(). |
|
|
Get stream currently processed for peeking the data.
This will only return a valid result when called from inside the above mentioned interceptor callback. |
|
|
Store pointer to allocated peekbuffer, so it can be deleted 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. |
|
|
Retrieve the peekbuffer pointer currently stored.
|
|
||||||||||||
|
Do any kind of processing.
This method will only get called when the replicator has the ZCOM_REPLICATOR_CALLPROCESS flag set. |
|
|
Additional replicator flags. ZCom_Replicator() c'tor will set this to 0. (ZCOM_REPLICATOR_*).
|
|
|
pointing to an instance of the setup class - all replication parameters are stored here
|
1.4.6-NO