SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Enumerations
ReadyEvent
Plugins

Peer to peer synchronized ready and unready events. More...

## Classes

class | SLNet::ReadyEvent
| Peer to peer synchronized ready and unready events. More...
struct | SLNet::ReadyEvent::ReadyEventNode
struct | SLNet::ReadyEvent::RemoteSystem

## Enumerations

enum | SLNet::ReadyEventSystemStatus { SLNet::RES_NOT_WAITING, SLNet::RES_WAITING, SLNet::RES_READY, SLNet::RES_ALL_READY, SLNet::RES_UNKNOWN_EVENT }

## Detailed Description

Peer to peer synchronized ready and unready events.

## Class Documentation

class SLNet::ReadyEvent

Peer to peer synchronized ready and unready events.

For peer to peer networks in a fully connected mesh.
Solves the problem of how to tell if all peers, relative to all other peers, are in a certain ready state.
For example, if A is connected to B and C, A may see that B and C are ready, but does not know if B is ready to C, or vice-versa.
This plugin uses two stages to solve that problem, first, everyone I know about is ready. Second, everyone I know about is ready to everyone they know about.
The user will get ID_READY_EVENT_SET and ID_READY_EVENT_UNSET as the signal flag is set or unset
The user will get ID_READY_EVENT_ALL_SET when all systems are done waiting for all other systems, in which case the event is considered complete, and no longer tracked.

See Also
  FullyConnectedMesh2

Definition at line 68 of file ReadyEvent.h.

Inheritance diagram for SLNet::ReadyEvent:

### Public Member Functions

| ReadyEvent ()
virtual | ~ReadyEvent ()
bool | SetEvent (int eventId, bool isReady)
void | ForceCompletion (int eventId)
bool | DeleteEvent (int eventId)
bool | IsEventSet (int eventId)
bool | IsEventCompletionProcessing (int eventId) const
bool | IsEventCompleted (int eventId) const
bool | HasEvent (int eventId)
unsigned | GetEventListSize (void) const
int | GetEventAtIndex (unsigned index) const
bool | AddToWaitList (int eventId, RakNetGUID guid)
bool | RemoveFromWaitList (int eventId, RakNetGUID guid)
bool | IsInWaitList (int eventId, RakNetGUID guid)
unsigned | GetRemoteWaitListSize (int eventId) const
RakNetGUID | GetFromWaitListAtIndex (int eventId, unsigned index) const
ReadyEventSystemStatus | GetReadyStatus (int eventId, RakNetGUID guid)
void | SetSendChannel (unsigned char newChannel)
Public Member Functions inherited from SLNet::PluginInterface2
| PluginInterface2 ()
virtual | ~PluginInterface2 ()
virtual void | OnAttach (void)
| Called when the interface is attached.
virtual void | OnDetach (void)
| Called when the interface is detached.
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual void | OnRakPeerStartup (void)
| Called when RakPeer is initialized.
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
virtual bool | UsesReliabilityLayer (void) const
virtual void | OnDirectSocketSend (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnDirectSocketReceive (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnReliabilityLayerNotification (const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress, bool isError)
virtual void | OnInternalPacket (InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time, int isSend)
virtual void | OnAck (unsigned int messageNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time)
virtual void | OnPushBackPacket (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
RakPeerInterface * | GetRakPeerInterface (void) const
RakNetGUID | GetMyGUIDUnified (void) const
void | SetRakPeerInterface (RakPeerInterface *ptr)
void | SetTCPInterface (TCPInterface *ptr)

### Static Public Member Functions

static int | RemoteSystemCompByGuid (const RakNetGUID &key, const RemoteSystem &data)
static int | ReadyEventNodeComp (const int &key, ReadyEvent::ReadyEventNode *const &data)

### Protected Member Functions

virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
virtual void | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
void | Clear (void)
void | SendReadyStateQuery (unsigned eventId, RakNetGUID guid)
void | SendReadyUpdate (unsigned eventIndex, unsigned systemIndex, bool forceIfNotDefault)
void | BroadcastReadyUpdate (unsigned eventIndex, bool forceIfNotDefault)
void | RemoveFromAllLists (RakNetGUID guid)
void | OnReadyEventQuery (Packet *packet)
void | PushCompletionPacket (unsigned eventId)
bool | AddToWaitListInternal (unsigned eventIndex, RakNetGUID guid)
void | OnReadyEventForceAllSet (Packet *packet)
void | OnReadyEventPacketUpdate (Packet *packet)
void | UpdateReadyStatus (unsigned eventIndex)
bool | IsEventCompletedByIndex (unsigned eventIndex) const
unsigned | CreateNewEvent (int eventId, bool isReady)
bool | SetEventByIndex (int eventIndex, bool isReady)
Protected Member Functions inherited from SLNet::PluginInterface2
void | SendUnified (const SLNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
void | SendUnified (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
bool | SendListUnified (const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
Packet * | AllocatePacketUnified (unsigned dataSize)
void | PushBackPacketUnified (Packet *packet, bool pushAtHead)
void | DeallocPacketUnified (Packet *packet)

### Protected Attributes

DataStructures::OrderedList < int, ReadyEventNode *, ReadyEvent::ReadyEventNodeComp > | readyEventNodeList
unsigned char | channel
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Constructor & Destructor Documentation

SLNet::ReadyEvent::ReadyEvent | ( |  | ) |

virtual SLNet::ReadyEvent::~ReadyEvent | ( |  | ) |

virtual

#### Member Function Documentation

bool SLNet::ReadyEvent::AddToWaitList | ( | int | eventId,
|  | RakNetGUID | guid
| ) |  |

Adds a system to wait for to signal an event before considering the event complete and returning ID_READY_EVENT_ALL_SET. As we add systems, if this event was previously set to true with SetEvent, these systems will get ID_READY_EVENT_SET. As these systems disconnect (directly or indirectly through the router) they are removed.

Note
  If the event completion process has already started, you cannot add more systems, as this would cause the completion process to fail

Parameters

  [in] | eventId | A user-defined number previously passed to SetEvent that has not yet completed
  [in] | guid | An address to wait for event replies from. Pass UNASSIGNED_SYSTEM_ADDRESS for all currently connected systems. Until all systems in this list have called SetEvent with this ID and true, and have this system in the list, we won't get ID_READY_EVENT_COMPLETE

Returns
  True on success, false on unknown eventId (this should be considered an error)

bool SLNet::ReadyEvent::AddToWaitListInternal | ( | unsigned | eventIndex,
|  | RakNetGUID | guid
| ) |  |

protected

void SLNet::ReadyEvent::BroadcastReadyUpdate | ( | unsigned | eventIndex,
|  | bool | forceIfNotDefault
| ) |  |

protected

void SLNet::ReadyEvent::Clear | ( | void |  | ) |

protected

unsigned SLNet::ReadyEvent::CreateNewEvent | ( | int | eventId,
|  | bool | isReady
| ) |  |

protected

bool SLNet::ReadyEvent::DeleteEvent | ( | int | eventId | ) |

Deletes an event. We will no longer wait for this event, and any systems that we know have set the event will be forgotten. Call this to clear memory when events are completed and you know you will never need them again.

Parameters

  [in] | eventId | A user-defined identifier

Returns
  True on success. False (failure) on unknown eventId

void SLNet::ReadyEvent::ForceCompletion | ( | int | eventId | ) |

When systems can call SetEvent() with isReady==false, it is possible for one system to return true from IsEventCompleted() while the other systems return false This can occur if a system SetEvent() with isReady==false while the completion message is still being transmitted. If your game has the situation where some action should be taken on all systems when IsEventCompleted() is true for any system, then call ForceCompletion() when the action begins. This will force all systems to return true from IsEventCompleted().

Parameters

  [in] | eventId | A user-defined identifier to immediately set as completed

int SLNet::ReadyEvent::GetEventAtIndex | ( | unsigned | index | ) | const

Returns the event ID stored at a particular index. EventIDs are stored sorted from least to greatest.

Parameters

  [in] | index | Index into the array, from 0 to GetEventListSize()

Returns
  The event ID stored at a particular index

unsigned SLNet::ReadyEvent::GetEventListSize | ( | void |  | ) | const

Returns the total number of events stored in the system.

Returns
  The total number of events stored in the system.

RakNetGUID SLNet::ReadyEvent::GetFromWaitListAtIndex | ( | int | eventId,
|  | unsigned | index
| ) |  | const

Returns the system address of a system at a particular index, for this event.

Parameters

  [in] | eventId | A user-defined identifier
  [in] | index | Index into the array, from 0 to GetWaitListSize()

Returns
  The system address of a system at a particular index, for this event.

ReadyEventSystemStatus SLNet::ReadyEvent::GetReadyStatus | ( | int | eventId,
|  | RakNetGUID | guid
| ) |  |

For a remote system, find out what their ready status is (waiting, signaled, complete).

Parameters

  [in] | eventId | A user-defined identifier
  [in] | guid | Which system we are checking up on

Returns
  The status of this system, for this particular event.

See Also
  ReadyEventSystemStatus

unsigned SLNet::ReadyEvent::GetRemoteWaitListSize | ( | int | eventId | ) | const

Returns the total number of systems we are waiting on for this event. Does not include yourself

Parameters

  [in] | eventId | A user-defined identifier

Returns
  The total number of systems we are waiting on for this event.

bool SLNet::ReadyEvent::HasEvent | ( | int | eventId | ) |

Returns if this is a known event. Events may be known even if we never ourselves referenced them with SetEvent, because other systems created them via ID_READY_EVENT_SET.

Parameters

  [in] | eventId | A user-defined identifier

Returns
  true if we have this event, false otherwise

bool SLNet::ReadyEvent::IsEventCompleted | ( | int | eventId | ) | const

Returns if the wait list is a subset of the completion list. Call this after all systems you want to wait for have been added with AddToWaitList If you are waiting for a specific number of systems (such as players later connecting), also check GetRemoteWaitListSize(eventId) to be equal to 1 less than the total number of participants.

Parameters

  [in] | eventId | A user-defined identifier

Returns
  True on completion. False (failure) on unknown eventId, or the set is not completed.

bool SLNet::ReadyEvent::IsEventCompletedByIndex | ( | unsigned | eventIndex | ) | const

protected

bool SLNet::ReadyEvent::IsEventCompletionProcessing | ( | int | eventId | ) | const

Returns if the event is about to be ready and we are negotiating the final packets. This will usually only be true for a very short time, after which IsEventCompleted should return true. While this is true you cannot add to the wait list, or SetEvent() isReady to false anymore.

Parameters

  [in] | eventId | A user-defined identifier

Returns
  True if any other system has completed processing. Will always be true if IsEventCompleted() is true

bool SLNet::ReadyEvent::IsEventSet | ( | int | eventId | ) |

Returns what was passed to SetEvent()

Returns
  The value of isReady passed to SetEvent(). Also returns false on unknown event.

bool SLNet::ReadyEvent::IsInWaitList | ( | int | eventId,
|  | RakNetGUID | guid
| ) |  |

Returns if a particular system is waiting on a particular event.

Parameters

  [in] | eventId | A user-defined identifier
  [in] | guid | The system we are checking up on

Returns
  True if this system is waiting on this event, false otherwise.

virtual void SLNet::ReadyEvent::OnClosedConnection | ( | const SystemAddress & | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason
| ) |  |

protectedvirtual

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters

  [in] | systemAddress | The system whose connection was closed
  [in] | rakNetGuid | The guid of the specified system
  [in] | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from SLNet::PluginInterface2.

virtual void SLNet::ReadyEvent::OnRakPeerShutdown | ( | void |  | ) |

protectedvirtual

Called when RakPeer is shutdown.

Reimplemented from SLNet::PluginInterface2.

void SLNet::ReadyEvent::OnReadyEventForceAllSet | ( | Packet * | packet | ) |

protected

void SLNet::ReadyEvent::OnReadyEventPacketUpdate | ( | Packet * | packet | ) |

protected

void SLNet::ReadyEvent::OnReadyEventQuery | ( | Packet * | packet | ) |

protected

virtual PluginReceiveResult SLNet::ReadyEvent::OnReceive | ( | Packet * | packet | ) |

protectedvirtual

OnReceive is called for every packet.

Parameters

  [in] | packet | the packet that is being returned to the user

Returns
  True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from SLNet::PluginInterface2.

void SLNet::ReadyEvent::PushCompletionPacket | ( | unsigned | eventId | ) |

protected

static int SLNet::ReadyEvent::ReadyEventNodeComp | ( | const int & | key,
|  | ReadyEvent::ReadyEventNode *const & | data
| ) |  |

static

static int SLNet::ReadyEvent::RemoteSystemCompByGuid | ( | const RakNetGUID & | key,
|  | const RemoteSystem & | data
| ) |  |

static

void SLNet::ReadyEvent::RemoveFromAllLists | ( | RakNetGUID | guid | ) |

protected

bool SLNet::ReadyEvent::RemoveFromWaitList | ( | int | eventId,
|  | RakNetGUID | guid
| ) |  |

Removes systems from the wait list, which should have been previously added with AddToWaitList

Note
  Systems that directly or indirectly disconnect from us are automatically removed from the wait list

Parameters

  [in] | guid | The system to remove from the wait list. Pass UNASSIGNED_RAKNET_GUID for all currently connected systems.

Returns
  True on success, false on unknown eventId (this should be considered an error)

void SLNet::ReadyEvent::SendReadyStateQuery | ( | unsigned | eventId,
|  | RakNetGUID | guid
| ) |  |

protected

void SLNet::ReadyEvent::SendReadyUpdate | ( | unsigned | eventIndex,
|  | unsigned | systemIndex,
|  | bool | forceIfNotDefault
| ) |  |

protected

bool SLNet::ReadyEvent::SetEvent | ( | int | eventId,
|  | bool | isReady
| ) |  |

Sets or updates the initial ready state for our local system. If eventId is an unknown event the event is created. If eventId was previously used and you want to reuse it, call DeleteEvent first, or else you will keep the same event signals from before Systems previously or later added through AddToWaitList() with the same eventId when isReady=true will get ID_READY_EVENT_SET Systems previously added through AddToWaitList with the same eventId will get ID_READY_EVENT_UNSET For both ID_READY_EVENT_SET and ID_READY_EVENT_UNSET, eventId is encoded in bytes 1 through 1+sizeof(int)

Parameters

  [in] | eventId | A user-defined identifier to wait on. This can be a sequence counter, an event identifier, or anything else you want.
  [in] | isReady | True to signal we are ready to proceed with this event, false to unsignal

Returns
  False if event status is ID_READY_EVENT_FORCE_ALL_SET, or if we are setting to a status we are already in (no change). Otherwise true

bool SLNet::ReadyEvent::SetEventByIndex | ( | int | eventIndex,
|  | bool | isReady
| ) |  |

protected

void SLNet::ReadyEvent::SetSendChannel | ( | unsigned char | newChannel | ) |

This channel will be used for all RakPeer::Send calls

Parameters

  [in] | newChannel | The channel to use for internal RakPeer::Send calls from this system. Defaults to 0.

void SLNet::ReadyEvent::UpdateReadyStatus | ( | unsigned | eventIndex | ) |

protected

#### Member Data Documentation

unsigned char SLNet::ReadyEvent::channel

protected

Definition at line 240 of file ReadyEvent.h.

DataStructures::OrderedList<int, ReadyEventNode*, ReadyEvent::ReadyEventNodeComp> SLNet::ReadyEvent::readyEventNodeList

protected

Definition at line 239 of file ReadyEvent.h.

struct SLNet::ReadyEvent::ReadyEventNode

Definition at line 194 of file ReadyEvent.h.

Class Members
int | eventId |
MessageID | eventStatus |
OrderedList< RakNetGUID, RemoteSystem, RemoteSystemCompByGuid > | systemList |

struct SLNet::ReadyEvent::RemoteSystem

Definition at line 186 of file ReadyEvent.h.

Class Members
MessageID | lastReceivedStatus |
MessageID | lastSentStatus |
RakNetGUID | rakNetGuid |

## Enumeration Type Documentation

enum SLNet::ReadyEventSystemStatus

Returns the status of a remote system when querying with ReadyEvent::GetReadyStatus

Enumerator:

  RES_NOT_WAITING | --------— Normal states ------------— The remote system is not in the wait list, and we have never gotten a ready or complete message from it. This is the default state for valid events
  RES_WAITING | We are waiting for this remote system to call SetEvent(thisEvent,true).
  RES_READY | The remote system called SetEvent(thisEvent,true), but it still waiting for other systems before completing the ReadyEvent.
  RES_ALL_READY | The remote system called SetEvent(thisEvent,true), and is no longer waiting for any other systems. This remote system has completed the ReadyEvent
  RES_UNKNOWN_EVENT | Error code, we couldn't look up the system because the event was unknown.

Definition at line 41 of file ReadyEvent.h.