XII Release 0.1.0
Loading...
Searching...
No Matches
xiiMessage Class Reference

Base class for all message types. Each message type has it's own id which is used to dispatch messages efficiently. More...

#include <Message.h>

Inheritance diagram for xiiMessage:
[legend]

Public Member Functions

virtual xiiInt32 GetSortingKey () const
 Derived message types can override this method to influence sorting order. Smaller keys are processed first.
 
XII_ALWAYS_INLINE xiiMessageId GetId () const
 Returns the id for this message type.
 
XII_ALWAYS_INLINE xiiUInt16 GetSize () const
 Returns the size in byte of this message.
 
XII_ALWAYS_INLINE xiiUInt64 GetHash () const
 Calculates a hash of the message.
 
virtual void Serialize (xiiStreamWriter &ref_stream) const
 Implement this for efficient transmission across process boundaries (e.g. network transfer etc.)
 
virtual void Deserialize (xiiStreamReader &ref_stream, xiiUInt8 uiTypeVersion)
 
- Public Member Functions inherited from xiiReflectedClass
virtual const xiiRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const xiiRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T>
XII_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Static Public Member Functions

static void PackageForTransfer (const xiiMessage &msg, xiiStreamWriter &ref_stream)
 Writes msg to stream in such a way that ReplicatePackedMessage() can restore it even in another process.
 
static xiiUniquePtr< xiiMessageReplicatePackedMessage (xiiStreamReader &ref_stream)
 Restores a message that was written by PackageForTransfer()
 
- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 

Protected Member Functions

 xiiMessage (size_t messageSize)
 

Static Protected Member Functions

static XII_ALWAYS_INLINE xiiMessageId GetNextMsgId ()
 

Protected Attributes

xiiMessageId m_Id
 
xiiUInt16 m_uiSize
 

Static Protected Attributes

static xiiMessageId s_NextMsgId = 0
 

Detailed Description

Base class for all message types. Each message type has it's own id which is used to dispatch messages efficiently.

To implement a custom message type derive from xiiMessage and add XII_DECLARE_MESSAGE_TYPE to the type declaration. XII_IMPLEMENT_MESSAGE_TYPE needs to be added to a cpp.

See also
xiiRTTI

For the automatic cloning to work and for efficiency the messages must only contain simple data members. For instance, everything that allocates internally (strings, arrays) should be avoided. Instead, such objects should be located somewhere else and the message should only contain pointers to the data.

Member Function Documentation

◆ Deserialize()

virtual void xiiMessage::Deserialize ( xiiStreamReader & ref_stream,
xiiUInt8 uiTypeVersion )
inlinevirtual
See also
Serialize()

Reimplemented in xiiMsgSetColor, and xiiMsgSetMeshMaterial.

◆ PackageForTransfer()

void xiiMessage::PackageForTransfer ( const xiiMessage & msg,
xiiStreamWriter & ref_stream )
static

Writes msg to stream in such a way that ReplicatePackedMessage() can restore it even in another process.

For this to work the message type has to have the Serialize and Deserialize functions implemented.

Note
This is NOT used by xiiWorld. Within the same process messages can be dispatched more efficiently.

◆ ReplicatePackedMessage()

xiiUniquePtr< xiiMessage > xiiMessage::ReplicatePackedMessage ( xiiStreamReader & ref_stream)
static

Restores a message that was written by PackageForTransfer()

If the message type is unknown, nullptr is returned.

See also
PackageForTransfer()

◆ Serialize()

virtual void xiiMessage::Serialize ( xiiStreamWriter & ref_stream) const
inlinevirtual

Implement this for efficient transmission across process boundaries (e.g. network transfer etc.)

If the message is only ever sent within the same process between nodes of the same xiiWorld, this does not need to be implemented.

Note that PackageForTransfer() will automatically include the xiiRTTI type version into the stream and ReplicatePackedMessage() will pass this into Deserialize(). Use this if the serialization changes.

Reimplemented in xiiMsgSetColor, and xiiMsgSetMeshMaterial.


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