Menu
Lumberyard
Developer Guide (Version 1.11)

Reacting to Session Events

Much of the session functionality is asynchronous because functions can be called, but the response is often not immediately available. For example, messages may be slowed by network transfer time, server processing, or the required response time.

The Event Bus (EBus) in Lumberyard is an event bus system that can send out events when asynchronous session functions are complete. This topic shows you how to set up your application to use the event bus and to connect and disconnect from it.

Setup

Your application must derive a class from GridMate::SessionEventBus::Handler. This class must contain certain overridden session events. However, not all events need to be implemented. An example follows.

Copy
class MyClass : public GridMate::SessionEventBus::Handler { public: void OnSessionJoined(GridMate::GridSession* session) override; void OnMemberJoined(GridMate::GridSession* session, GridMate::GridMember* member) override; void OnMemberLeaving(GridMate::GridSession* session, GridMate::GridMember* member) override; };

Connect

The following example shows how to connect to the session event bus and start receiving session events.

Copy
void MyClass::Init() { GridMate::IGridMate* gridMate = gEnv->pNetwork->GetGridMate(); if(gridMate) { GridMate::SessionEventBus::Handler::BusConnect(gridMate); } }

Disconnect

The following example shows how to disconnect from the session event bus and stop receiving session events.

Copy
void MyClass::Term() { GridMate::IGridMate* gridMate = gEnv->pNetwork->GetGridMate(); if(gridMate) { GridMate::SessionEventBus::Handler::BusDisconnect(gridMate); } }

On this page: