![]() |
||||||||
|
|
||||||||
Each ZCom_Node represents one object in the network. There are several types of them:
Once nodes are linked up with their counterparts, they can send events back and forth as much as have their data synchronized and interpolated.
ZCom_Nodes appear in three roles (eZCom_NodeRole):
Event replication and file transfers | |
| void | acceptFile (ZCom_ConnID _src_id, ZCom_FileTransID _ftrans_id, const char *_path, bool _accept) |
| Accept or deny an incoming file. | |
| bool | checkEventWaiting () const |
| Check for new events. | |
| const ZCom_FileTransInfo & | getFileInfo (ZCom_ConnID _conn_id, ZCom_FileTransID _ftrans_id) const |
| Get data for a file transfer. | |
| ZCom_BitStream * | getNextEvent (eZCom_Event *_type, eZCom_NodeRole *_remote_role, ZCom_ConnID *_connid, zU32 *_estimated_time_sent=NULL) |
| Get the next event. | |
| bool | sendEvent (eZCom_SendMode _mode, zU8 _rules, ZCom_BitStream *_data) |
| Send an event to the peers selected with _rules: Replication Rules. | |
| bool | sendEventDirect (eZCom_SendMode _mode, ZCom_BitStream *_data, ZCom_ConnID _destconn) |
| Send an event to a connected node on a specific connection only (needed for initializing and syncing, see eZCom_Event). | |
| bool | sendEventToGroup (eZCom_SendMode _mode, ZCom_BitStream *_data, ZCom_GroupID _destgroup) |
| Send an event to connected nodes on a group of connections. | |
| ZCom_FileTransID | sendFile (const char *_path, const char *_pathtosend, ZCom_ConnID _destconn, ZCom_BitStream *_data, zFloat _aggressivenes) |
| Send a file to a specific connection. | |
| void | setEventInterceptor (ZCom_NodeEventInterceptor *_interceptor) |
| Set event interceptor for this node. | |
| void | setEventNotification (bool _oninit, bool _onremove) |
| Toggle connect/remove notification. | |
Data replication setup | |
| Setup the data replication rules. They have to be exactly the same for all nodes of the same class on all systems. | |
| void | addInterpolationFloat (zFloat *_ptr, zU8 _mantissa_bits, zU8 _flags, zU8 _rules, zFloat _treshold, zFloat *_dst=NULL, zS16 _mindelay=-1, zS16 _maxdelay=-1, zFloat _ipolfac=0.4f) |
| Add a float to the data replication and ask Zoidcom to interpolate it. | |
| void | addInterpolationInt (zS32 *_ptr, zU8 _bits, bool _sign, zU8 _flags, zU8 _rules, zS32 _treshold, zS32 *_dst=NULL, zS16 _mindelay=-1, zS16 _maxdelay=-1, zFloat _ipolfac=0.4f) |
| Add an int to the data replication and ask Zoidcom to interpolate it. | |
| void | addReplicationBool (bool *_ptr, zU8 _flags, zU8 _rules, zS16 _mindelay=-1, zS16 _maxdelay=-1) |
| Add a bool to the data replication. | |
| void | addReplicationFloat (zFloat *_ptr, zU8 _mantissa_bits, zU8 _flags, zU8 _rules, zS16 _mindelay=-1, zS16 _maxdelay=-1) |
| Add a float to the data replication. | |
| void | addReplicationInt (zS32 *_ptr, zU8 _bits, bool _sign, zU8 _flags, zU8 _rules, zS16 _mindelay=-1, zS16 _maxdelay=-1) |
| Add an int to the data replication. | |
| void | addReplicationString (char *_str, zU16 _maxlen, zU8 _flags, zU8 _rules, zS16 _mindelay=-1, zS16 _maxdelay=-1) |
| Add a string to the data replication. | |
| void | addReplicationStringW (wchar_t *_str, zU16 _maxlen, zU8 _flags, zU8 _rules, zS16 _mindelay=-1, zS16 _maxdelay=-1) |
| Add a string to the data replication. | |
| void | addReplicator (ZCom_Replicator *_rep, bool _autodelete) |
| Add replicator object. | |
| bool | beginReplicationSetup (zU16 _replicators_max) |
| Enclose all data replication setup functions with this and endReplicationSetup(). | |
| bool | endReplicationSetup (void) |
| End replication setup. | |
| void | setInterceptID (ZCom_InterceptID _id) |
| Set intercept ID for all forthcoming replication registrations which have ZCOM_REPFLAG_INTERCEPT set. | |
| void | setReplicationInterceptor (ZCom_NodeReplicationInterceptor *_interceptor) |
| Set replication interceptor for this node. | |
Node parameters | |
| void | applyForZoidLevel (zU8 _level) |
| Add node to Zoidlevel. (Allowed on: Authority). | |
| void | dependsOn (ZCom_Node *_othernode, eZCom_DependencyOpt _opt=eZCom_AddDependency) |
| Force replication order of nodes by making this dependent on _othernode. _othernode is replicated first. (Allowed on: Authority). | |
| zU32 | getRelevantConnectionCount () const |
| Find out how many connections are relevant for this node. (Allowed on: Authority, Owner, Proxy). | |
| zS32 | getRelevantConnections (ZCom_ConnID *_conns, zU32 _max, zU32 *_count) const |
| Find out which connections are relevant for this node. (Allowed on: Authority, Owner, Proxy). | |
| zU8 | getZoidLevel (zU32 _index) const |
| Get one of the nodes Zoidlevels. | |
| zU32 | getZoidLevelCount () const |
| Get amount of Zoidlevels this node is registered in. | |
| void | removeFromZoidLevel (zU8 _level) |
| Remove node from Zoidlevel. (Allowed on: Authority). | |
| void | setAnnounceData (ZCom_BitStream *_data) |
| void | setConnectionSpecificRelevance (ZCom_ConnID _conn, zFloat _rel) |
| Set current relevance of this node to a specific connection. (Allowed on: Authority). | |
| void | setDefaultRelevance (zFloat _default_relevance) |
| Set default relevance of this node to all connections. (Allowed on: Authority). | |
| void | setMustSync (bool _enabled, zU16 _order) |
| Force this node to successfully sync during Zoidlevel transition. (Allowed on: Authority). | |
| void | setOwner (ZCom_ConnID _id, bool _enabled) |
| Give owner-status to proxy nodes on clients. (Allowed on: Authority). | |
| void | setPrivate (bool _enabled) |
| Make node private. (Allowed on: Authority). | |
| void | setSyncResult (ZCom_ConnID _conn, bool _success, ZCom_BitStream *_errormsg) |
| Report sync result to Zoidcom. (Allowed on: Authority). | |
| void | setSyncResultAutoSuccess (bool _enabled) |
| Tell node to automatically report all sync requests as successful. (Allowed on: Authority). | |
| void | setUpdatePriority (zU16 _prio) |
| Set relative object priority. (Allowed on: Authority, Owner, Proxy). | |
Node registration | |
| Register your node with the system, the needed ZCom_ClassID is the result of a call to ZCom_Control::ZCom_registerClass().
| |
| void | disconnectAll () |
| Unlink nodes from all peers. | |
| bool | registerNodeByTag (ZCom_ClassID _classid, zU32 _tag, eZCom_NodeRole _role, ZCom_Control *_control) |
| Register a tagnode, initially or on request. | |
| bool | registerNodeDynamic (ZCom_ClassID _classid, ZCom_Control *_control) |
| Register an authoritative dynamic node. | |
| bool | registerNodeUnique (ZCom_ClassID _classid, eZCom_NodeRole _role, ZCom_Control *_control) |
| Register a unique node. | |
| bool | registerRequestedNode (ZCom_ClassID _classid, ZCom_Control *_control) |
| Register a requested dynamic node. | |
| bool | unregisterNode () |
| Unregister the node from ZCom_Control. | |
Misc. | |
| ZCom_ClassID | getClassID () const |
| Get node's class ID. | |
| ZCom_Control * | getControl () const |
| Get the ZCom_Control this node is registered with. | |
| zU32 | getCurrentUpdateRate () const |
| Get packet rate of source connection. | |
| zS32 | getEstimatedTimeUntilPossibleUpdate () const |
| Get estimated time in msecs until next possible update arrives. | |
| ZCom_NodeID | getNetworkID () const |
| Retrieve the node's network ID. | |
| eZCom_NodeRole | getRole () const |
| Get role of this node. | |
| zS32 | getUpdateDelta () const |
| Get time in msecs since last received update packet. | |
| bool | isPrivate () const |
| Find out if node is in private mode. | |
User data | |
| void * | getUserData () const |
| Retrieve global user data pointer. | |
| void * | getUserData (ZCom_ConnID _conn) const |
| Retrieve user data. | |
| void | setUserData (void *_data) |
| Set global user data pointer. | |
| bool | setUserData (ZCom_ConnID _conn, void *_data) |
| Set user data pointer per relevant connection. | |
|
||||||||||||||||
|
Register a unique node.
|
|
||||||||||||||||||||
|
Register a tagnode, initially or on request.
|
|
||||||||||||
|
Register an authoritative dynamic node.
|
|
||||||||||||
|
Register a requested dynamic node.
The node's role will be eZCom_RoleProxy if the node is created inside ZCom_Control::ZCom_cbNodeRequest_Dynamic(), eZCom_RoleAuthority otherwise.
|
|
|
Unregister the node from ZCom_Control.
All node options, setups, replicators etc are lost. Actually, you can just as well delete the node and create a new one. Using unregisterNode() will just spare you one memory allocation. Calls disconnectAll(). |
|
|
Unlink nodes from all peers. Use this if the node is going to be deleted soon, the earlier this is called, the earlier peers will get notified about the removal and can react accordingly. You can also just delete this instead, if you don't need it any longer. |
|
|
Set relative object priority. (Allowed on: Authority, Owner, Proxy).
|
|
|
Set default relevance of this node to all connections. (Allowed on: Authority).
|
|
||||||||||||
|
Set current relevance of this node to a specific connection. (Allowed on: Authority).
See also: getRelevantConnectionCount(), getRelevantConnections() |
|
|
Find out how many connections are relevant for this node. (Allowed on: Authority, Owner, Proxy).
|
|
||||||||||||||||
|
Find out which connections are relevant for this node. (Allowed on: Authority, Owner, Proxy).
|
|
||||||||||||
|
Force replication order of nodes by making this dependent on _othernode. _othernode is replicated first. (Allowed on: Authority).
This will force _othernode to be replicated before this node whenever both nodes need to be replicated to a connection. It will show no effect if one of the nodes can't be replicated (because it is private or the relevance is 0) or if one of the nodes is replicated while the other is not. Don't make cyclic dependencies. Don't add the same dependency multiple times. (The debug version of Zoidcom will check for latter case). |
|
|
Add node to Zoidlevel. (Allowed on: Authority).
You can manually switch connections to different Zoidlevels, only nodes which have applied for a specific level will be synced while the connection is in this level. All nodes are in ZoidLevel 1 by default. |
|
|
Remove node from Zoidlevel. (Allowed on: Authority).
See also: applyForZoidlevel(). |
|
|
Get amount of Zoidlevels this node is registered in.
|
|
|
Get one of the nodes Zoidlevels.
|
|
||||||||||||
|
Force this node to successfully sync during Zoidlevel transition. (Allowed on: Authority).
If any of the mustsync nodes reports failure, the whole Zoidlevel transition fails for the connection in question. This is only relevant for nodes in existence _before_ the connection changes to the node's Zoidlevel. Nodes created when a connection is already in the respective Zoidlevel will be handled like normal, mustsync=false nodes. All other nodes ( which don't have MustSync=true ) are synced after all MustSync-nodes have synced.
UseCase:
See also: setSyncResult(), setSyncResultAutoSuccess() |
|
||||||||||||||||
|
Report sync result to Zoidcom. (Allowed on: Authority).
|
|
|
Tell node to automatically report all sync requests as successful. (Allowed on: Authority).
This method should be called on authority nodes only. See also: setSyncResult(), setMustSync() |
|
||||||||||||
|
Give owner-status to proxy nodes on clients. (Allowed on: Authority).
Example scenario: A spaceship. The server of course has the authority over it, and there are 10 proxies (which replicate what the server object is doing). Now you declare one proxy to become the owner of that ship (in fact, one object may have several owners, and one client can own several objects, it totally depends on the application what it means to be an owner). This owner (which is a client) now can send events to the server node which are not dropped because it accepts these specific events from an owner. In our scenario, these events are control commands to steer the ship and fire. In turn, the server would replicate some additional data (as set by the application), like the current ammo left for each weapon and other special infos no other players need to or should know about. You can also use the owner status to delegate AI calculations to clients, for example. |
|
|
Make node private. (Allowed on: Authority).
|
|
|
Set data that will be attached to each announcement of this node to a client. The data needs to be set only on server side. It will be used only if the node's classname (registered with ZCom_Control::ZCom_registerClass()) has been registered with the ZCOM_CLASSFLAG_ANNOUNCEDATA flag. When the flag is set, such data MUST be available. The client needs to be able to read exactly the amount of data which has been set here, as no size information will be transmitted. The bitstream goes into ownership of Zoidcom, it may not be deleted or used otherwise after giving it to the node. More information about this topic can be found in the documentation to the flag. |
|
|
Enclose all data replication setup functions with this and endReplicationSetup().
|
|
|
Set intercept ID for all forthcoming replication registrations which have ZCOM_REPFLAG_INTERCEPT set.
|
|
||||||||||||||||||||||||||||||||
|
Add an int to the data replication.
|
|
||||||||||||||||||||||||
|
Add a bool to the data replication.
|
|
||||||||||||||||||||||||||||
|
Add a float to the data replication.
_mantissa_bits states how big your mantissa should be. Default for floats in C++ is 23. Additional 9 bits will be replicated for exponent and sign bit. The smaller the mantissa and the bigger the value of the float, the lower the precision will be. Example: original value(mantissa size) => replicated value
In some cases, it may be better to make your own conversion. Take your float, create an approximation value for it and store it in an int, and register the int instead. Every time the float changes, the approx. value in the int has to be recomputed, or at least every time before you tell Zoidcom to process the updates. On the other side, you register that int, too. And every time after Zoidcom has processed the incoming updates, convert it back. |
|
||||||||||||||||||||||||||||
|
Add a string to the data replication.
|
|
||||||||||||||||||||||||||||
|
Add a string to the data replication.
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Add an int to the data replication and ask Zoidcom to interpolate it.
Setting the _dst parameter orders Zoidcom to store incoming updates in application provided memory. Now it is possible to provide custom interpolation by setting the _ipolfac to 0 and interpolate manually between _dst and _ptr. Or let Zoidcom handle interpolation with _ipolfac > 0, but the application can also write to _dst itself thus forcing Zoidcom to interpolate against clientside generated values. (E.g. You could process your physics locally as means of dead reckoning and store the current status is _dst. Zoidcom will then interpolate against the locally computed value, and also against incoming values from the server, which overwrite _dst). See also: addReplicationInt() |
|
||||||||||||||||||||||||||||||||||||||||
|
Add a float to the data replication and ask Zoidcom to interpolate it.
Setting the _dst parameter orders Zoidcom to store incoming updates in application provided memory. Now it is possible to provide custom interpolation by setting the _ipolfac to 0 and interpolate manually between _dst and _ptr. Or let Zoidcom handle interpolation with _ipolfac > 0, but the application can also write to _dst itself thus forcing Zoidcom to interpolate against clientside generated values. (E.g. You could process your physics locally as means of dead reckoning and store the current status is _dst. Zoidcom will then interpolate against the locally computed value, and also against incoming values from the server, which overwrite _dst). See also: addReplicationFloat() for more details on float replication. |
|
||||||||||||
|
Add replicator object.
The replicator setups however, won't get deleted. (Replicator setups are the configuration object passed to the replicator's constructor. If you want to save memory, you'd better use this method for all your replication needs. Only this method allows you to use one (static) ZCom_ReplicatorSetup for several replicator objects, while the other replication methods allocate one ZCom_ReplicatorSetup object for each replication item. Read the manual for more in depth information on this. |
|
|
End replication setup. This finalizes the replication setup. Make sure that nodes of the same ZCom_ClassID have the same replication setup. Important for that are especially:
|
|
|
Set replication interceptor for this node.
|
|
||||||||||||||||
|
Send an event to the peers selected with _rules: Replication Rules.
|