ezEngine  Milestone 9
ezMessage 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 ezMessage:

Public Member Functions

virtual ezInt32 GetSortingKey () const
 Derived message types can override this method to influence sorting order. Smaller keys are processed first.
 
EZ_ALWAYS_INLINE ezMessageId GetId () const
 Returns the id for this message type.
 
EZ_ALWAYS_INLINE ezUInt16 GetSize () const
 Returns the size in byte of this message.
 
EZ_ALWAYS_INLINE ezUInt32 GetHash () const
 Calculates a hash of the message.
 
virtual void Serialize (ezStreamWriter &stream) const
 Implement this for efficient transmission across process boundaries (e.g. network transfer etc.) More...
 
virtual void Deserialize (ezStreamReader &stream, ezUInt8 uiTypeVersion)
 
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
EZ_ALWAYS_INLINE bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_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 ezMessage &msg, ezStreamWriter &stream)
 Writes msg to stream in such a way that ReplicatePackedMessage() can restore it even in another process. More...
 
static ezUniquePtr< ezMessageReplicatePackedMessage (ezStreamReader &stream)
 Restores a message that was written by PackageForTransfer() More...
 
- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 

Static Protected Member Functions

static EZ_ALWAYS_INLINE ezMessageId GetNextMsgId ()
 

Protected Attributes

ezMessageId m_Id
 
ezUInt16 m_uiSize
 

Static Protected Attributes

static ezMessageId s_uiNextMsgId = 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 ezMessage and add EZ_DECLARE_MESSAGE_TYPE to the type declaration. EZ_IMPLEMENT_MESSAGE_TYPE needs to be added to a cpp.

See also
ezRTTI

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 ezMessage::Deserialize ( ezStreamReader stream,
ezUInt8  uiTypeVersion 
)
inlinevirtual
See also
Serialize()

Reimplemented in ezMsgSetMeshMaterial, and ezMsgSetColor.

◆ PackageForTransfer()

void ezMessage::PackageForTransfer ( const ezMessage msg,
ezStreamWriter 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 ezWorld. Within the same process messages can be dispatched more efficiently.

◆ ReplicatePackedMessage()

ezUniquePtr< ezMessage > ezMessage::ReplicatePackedMessage ( ezStreamReader 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 ezMessage::Serialize ( ezStreamWriter 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 ezWorld, this does not need to be implemented.

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

Reimplemented in ezMsgSetMeshMaterial, and ezMsgSetColor.


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