Пример #1
0
        public override void ApplyPatchTo(INetworkObject target, INetworkObjectSerializerManager serializerManager)
        {
            var componentTypeId = Component.GetComponentId();
            INetworkObjectSerializer componentSerializer = serializerManager.GetSerializer(componentTypeId);

            componentSerializer.Merge(Component as INetworkObject, target, _bitMask);
        }
Пример #2
0
        public override void DeSerialize(BinaryReader reader, INetworkObjectSerializerManager serializerManager)
        {
            var typeId = reader.ReadInt16();

            CreateGameComponent(typeId);
            var componentSerializer = serializerManager.GetSerializer(typeId);

            componentSerializer.DeserializeAll(Component as INetworkObject, DoCompress, reader);
        }
Пример #3
0
        public override void Serialize(MyBinaryWriter writer, INetworkObjectSerializerManager serializerManager)
        {
            writer.Write((byte)ComponentReplicateOperationType.Add);
            var componentId = Component.GetComponentId();

            writer.Write((short)componentId);

            var componentSerializer = serializerManager.GetSerializer(componentId);

            componentSerializer.SerializeAll(Component as INetworkObject, DoCompress, writer);
        }
Пример #4
0
        public override void DeSerialize(BinaryReader reader, INetworkObjectSerializerManager serializerManager)
        {
            int typeId = reader.ReadInt16();

            CreateGameComponent(typeId);
            var componentSerializer = serializerManager.GetSerializer(typeId);

            _bitMask.Deserialize(reader);
            var networkObject = Component as INetworkObject;

            componentSerializer.Deserialize(networkObject, _bitMask, DoCompress, reader);
        }
        /// <summary>
        /// 生成单个Component的Patch
        /// </summary>
        /// <param name="leftEntity"></param>
        /// <param name="leftComponent"></param>
        /// <param name="rightEntity"></param>
        /// <param name="rightComponent"></param>
        public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent, IGameEntity rightEntity, IGameComponent rightComponent)
        {
            var serializer = serializerManager.GetSerializer(leftComponent.GetComponentId());
            var bitMask    = serializer.DiffNetworkObject(leftComponent as INetworkObject, rightComponent as INetworkObject);

            if (bitMask.HasValue())
            {
                var componentPatch = ModifyComponentPatch.Allocate(leftComponent, rightComponent, bitMask);
                currentEntityPatch.AddComponentPatch(componentPatch);
                componentPatch.ReleaseReference();
            }
        }
Пример #6
0
        public override void Serialize(MyBinaryWriter writer, INetworkObjectSerializerManager serializerManager)
        {
            var start = writer.BaseStream.Length;

            writer.Write((byte)ComponentReplicateOperationType.Mod);
            var componentId = Component.GetComponentId();

            AssertUtility.Assert(componentId < 65535);
            writer.Write((short)componentId);
            _bitMask.Serialize(writer);

            var componentSerializer = serializerManager.GetSerializer(componentId);

            componentSerializer.Serialize(LastComponent as INetworkObject, Component as INetworkObject, _bitMask, DoCompress, writer);
            var end    = writer.BaseStream.Length;
            var length = end - start;

            _total[componentId]  += length;
            _current[componentId] = length;
            _count[componentId]  += 1;
            _average[componentId] = _total[componentId] / _count[componentId];
        }