Urho3D
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Urho3D::Connection Class Reference

Connection to a remote network host. More...

#include <Connection.h>

Inheritance diagram for Urho3D::Connection:
Urho3D::Object Urho3D::RefCounted

List of all members.

Public Member Functions

 Connection (Context *context, bool isClient, kNet::SharedPtr< kNet::MessageConnection > connection)
 Construct with context and kNet message connection pointers.
 ~Connection ()
 Destruct.
void SendMessage (int msgID, bool reliable, bool inOrder, const VectorBuffer &msg, unsigned contentID=0)
 Send a message.
void SendMessage (int msgID, bool reliable, bool inOrder, const unsigned char *data, unsigned numBytes, unsigned contentID=0)
 Send a message.
void SendRemoteEvent (StringHash eventType, bool inOrder, const VariantMap &eventData=VariantMap())
 Send a remote event.
void SendRemoteEvent (Node *node, StringHash eventType, bool inOrder, const VariantMap &eventData=VariantMap())
 Send a remote event with the specified node as sender.
void SetScene (Scene *newScene)
 Assign scene. On the server, this will cause the client to load it.
void SetIdentity (const VariantMap &identity)
 Assign identity. Called by Network.
void SetControls (const Controls &newControls)
 Set new controls.
void SetPosition (const Vector3 &position)
 Set the observer position for interest management.
void SetConnectPending (bool connectPending)
 Set the connection pending status. Called by Network.
void SetLogStatistics (bool enable)
 Set whether to log data in/out statistics.
void Disconnect (int waitMSec=0)
 Disconnect. If wait time is non-zero, will block while waiting for disconnect to finish.
void SendServerUpdate ()
 Send scene update messages. Called by Network.
void SendClientUpdate ()
 Send latest controls from the client. Called by Network.
void SendRemoteEvents ()
 Send queued remote events. Called by Network.
void SendPackages ()
 Send package files to client. Called by network.
void ProcessPendingLatestData ()
 Process pending latest data for nodes and components.
bool ProcessMessage (int msgID, MemoryBuffer &msg)
 Process a message from the server or client. Called by Network.
kNet::MessageConnection * GetMessageConnection () const
 Return the kNet message connection.
const VariantMapGetIdentity () const
 Return client identity.
SceneGetScene () const
 Return the scene used by this connection.
const ControlsGetControls () const
 Return the client controls of this connection.
const Vector3GetPosition () const
 Return the observer position for interest management.
bool IsClient () const
 Return whether is a client connection.
bool IsConnected () const
 Return whether is fully connected.
bool IsConnectPending () const
 Return whether connection is pending.
bool IsSceneLoaded () const
 Return whether the scene is loaded and ready to receive server updates.
bool GetLogStatistics () const
 Return whether to log data in/out statistics.
String GetAddress () const
 Return remote address.
unsigned short GetPort () const
 Return remote port.
String ToString () const
 Return an address:port string.
unsigned GetNumDownloads () const
 Return number of package downloads remaining.
const StringGetDownloadName () const
 Return name of current package download, or empty if no downloads.
float GetDownloadProgress () const
 Return progress of current package download, or 1.0 if no downloads.
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
virtual ShortStringHash GetType () const =0
 Return type hash.
virtual const StringGetTypeName () const =0
 Return type name.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
ContextGetContext () const
 Return execution context.
ObjectGetSubsystem (ShortStringHash type) const
 Return subsystem by type.
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
int Refs () const
 Return reference count.
int WeakRefs () const
 Return weak reference count.
RefCountRefCountPtr ()
 Return pointer to the reference count structure.

Public Attributes

Vector3 position_
 Observer position for interest management.
Controls controls_
 Current controls.
VariantMap identity_
 Identity map.

Private Member Functions

 OBJECT (Connection)
void HandleAsyncLoadFinished (StringHash eventType, VariantMap &eventData)
 Handle scene loaded event.
void ProcessLoadScene (int msgID, MemoryBuffer &msg)
 Process a LoadScene message from the server. Called by Network.
void ProcessSceneChecksumError (int msgID, MemoryBuffer &msg)
 Process a SceneChecksumError message from the server. Called by Network.
void ProcessSceneUpdate (int msgID, MemoryBuffer &msg)
 Process a scene update message from the server. Called by Network.
void ProcessPackageDownload (int msgID, MemoryBuffer &msg)
 Process package download related messages. Called by Network.
void ProcessIdentity (int msgID, MemoryBuffer &msg)
 Process an Identity message from the client. Called by Network.
void ProcessControls (int msgID, MemoryBuffer &msg)
 Process a Controls message from the client. Called by Network.
void ProcessSceneLoaded (int msgID, MemoryBuffer &msg)
 Process a SceneLoaded message from the client. Called by Network.
void ProcessRemoteEvent (int msgID, MemoryBuffer &msg)
 Process a remote event message from the client or server. Called by Network.
void ProcessNode (unsigned nodeID)
 Process a node for sending a network update. Recurses to process depended on node(s) first.
void ProcessNewNode (Node *node)
 Process a node that the client has not yet received.
void ProcessExistingNode (Node *node, NodeReplicationState &nodeState)
 Process a node that the client has already received.
void RequestPackage (const String &name, unsigned fileSize, unsigned checksum)
 Initiate a package download.
void SendPackageError (const String &name)
 Send an error reply for a package download.
void OnSceneLoadFailed ()
 Handle scene load failure on the server or client.
void OnPackageDownloadFailed (const String &name)
 Handle a package download failure on the client.
void OnPackagesReady ()
 Handle all packages loaded successfully. Also called directly on MSG_LOADSCENE if there are none.

Private Attributes

kNet::SharedPtr
< kNet::MessageConnection > 
connection_
 kNet message connection.
WeakPtr< Scenescene_
 Scene.
SceneReplicationState sceneState_
 Network replication state of the scene.
HashMap< StringHash,
PackageDownload
downloads_
 Waiting or ongoing package file receive transfers.
HashMap< StringHash,
PackageUpload
uploads_
 Ongoing package send transfers.
HashMap< unsigned, PODVector
< unsigned char > > 
nodeLatestData_
 Pending latest data for not yet received nodes.
HashMap< unsigned, PODVector
< unsigned char > > 
componentLatestData_
 Pending latest data for not yet received components.
HashSet< unsigned > nodesToProcess_
 Node ID's to process during a replication update.
VectorBuffer msg_
 Reusable message buffer.
Vector< RemoteEventremoteEvents_
 Queued remote events.
String sceneFileName_
 Scene file to load once all packages (if any) have been downloaded.
Timer statsTimer_
 Statistics timer.
bool isClient_
 Client connection flag.
bool connectPending_
 Connection pending flag.
bool sceneLoaded_
 Scene loaded flag.
bool logStatistics_
 Show statistics flag.

Additional Inherited Members

- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.

Detailed Description

Connection to a remote network host.


Member Function Documentation

void Urho3D::Connection::ProcessExistingNode ( Node node,
NodeReplicationState nodeState 
)
private

Process a node that the client has already received.

Todo:
Searching for the component is a potential CPU hotspot. It should be cached
void Urho3D::Connection::ProcessSceneUpdate ( int  msgID,
MemoryBuffer msg 
)
private

Process a scene update message from the server. Called by Network.

Todo:
On mobile devices processing this message may potentially cause a crash if it attempts to load new GPU resources while the application is minimized

The documentation for this class was generated from the following files: