Network serialization in the CryEngine happens at the entity level. Entities that should be synchronized have to be bound to network by calling GetNetEntity()->BindToNetwork().
To serialize the data of an entity on a regular basis, do either of the following:
In either case, also provide a GetNetSerializeAspectMask() implementation in the respective class to let CryNetwork know the bitmask of active aspects for this component/extension.
The serialization follow different aspects and profiles to distinguish the types of stream.
Serialized data for a given aspect and profile must remain fixed. In example, if you serialized four floats, you must always serialize four floats.
CryNetwork doesn't keep track of the serializable data that is changed during the game, so you need to tell CryNetwork explicitly when to synchronize an aspect by calling either IEntityComponent::NetMarkAspectsDirty or CGameObject::MarkAspectsDirty.
Aspects should be used to group data that logically belongs together, especially important given the constraints of compression.
Information about GameObjects is being propagated through the network by the function RequestRemoteUpdate() which takes EEntityAspects flags as a parameter to determine how the update should be performed.
The aspects are defined as follows:
Profiles allow particular aspects fixed format data to be different. There are potentially 8 profiles per aspect. Usually they are only used for physics aspects (i.e. switching between ragdoll and living entity). Profiles requires the aspect to be setup using the eAF_ServerManagedProfile flag.
The network layer takes care of compression and quantization based on the usage of Tserialize::Value. The quantization and/or compression can be controlled via a compression policy.
The different quantization and compression types are defined inside the XML file: Game/Scripts/Network/CompressionPolicy.xml
. A 4 character code will be assigned to the type.
Here is an entry example:
<policy name="team" impl="RangedInt">
<params min="0" max="7" />
</policy>
The policy implementation are written in C++ and can be found within the CryNetwork project.
Here is the list of policies currently implemented:
It's possible to implement a new policy inside CryNetwork by deriving the ICompressionPolicy interface and calling the REGISTER_COMPRESSION_POLICY(class, name) macro.