![]() |
||||||||
|
|
||||||||
class GameObject { protected: ZCom_Node* m_node; // this is new bool m_deleteme; public: GameObject(); virtual ~GameObject(); // this is new void processNodeEvents(); }; void GameObject::processNodeEvents() { // checkEventWaiting() returns true whenever there is a waiting event in the node while (m_node->checkEventWaiting()) { eZCom_Event type; // event type eZCom_NodeRole remote_role; // role of remote sender ZCom_ConnID conn_id; // connection id of sender // get next waiting event ZCom_BitStream *data = m_node->getNextEvent(&type, &remote_role, &conn_id); // the server object has been deleted on the server, we should delete it here, too if (remote_role == eZCom_RoleAuthority && type == eZCom_EventRemoved) m_deleteme = true; } }
checkEventWaiting() returns true whenever there is a waiting event in the node. The waiting event is then fetched with a call to getNextEvent(). This method returns the event data as bitstream pointer, and the event meta information (event id, role of event sender, connection id of event sender) through pointer-parameters. If getNextEvent(NULL, NULL, NULL) is called, the only thing you get is the event data itself. The contents of the data stream depends on the event type though, so it is always necessary to get at least the event type (i.e. the first parameter to getNextEvent() should not be NULL)).
ZCom_Node::getRole() allows you to find out on which side of the fence the code is executed. When it returns eZCom_RoleAuthority then the node is on the server, while eZCom_RoleProxy and eZCom_RoleOwner implicate that the current node is on the client. So if you want to avoid having two different event handlers for server and client just do something like this:
// pseudocode void processNodeEvents() { while (node->checkEventWaiting()) { data, type = node->getNextEvent(); if (type == something that appears on both client and server) { // check if we are server if (node->getRole() == eZCom_RoleAuthority) { // do server stuff with the event } else { // do client stuff with the event } } } }
1.4.6-NO