コード例 #1
0
        private AbstractComponentPatch CreateEmptyComponentPatch(ComponentReplicateOperationType opType)
        {
            switch (opType)
            {
            case ComponentReplicateOperationType.Add:
                return(AddComponentPatch.Allocate());

            case ComponentReplicateOperationType.Del:
                return(DeleteComponentPatch.Allocate());

            case ComponentReplicateOperationType.Mod:
                return(ModifyComponentPatch.Allocate());

            default:
                throw new Exception(string.Format("invalid ComponentReplicateOperationType {0}", opType));
            }
        }
コード例 #2
0
        private long SerializeComponents(MyBinaryWriter binaryWriter, List <IUpdateComponent> oldComponents,
                                         List <IUpdateComponent> currentComponents, out int count)
        {
            int c            = 0;
            var startPostion = binaryWriter.Position;

            foreach (var currentComponent in currentComponents)
            {
                var  serializer = _componentSerializerManager.GetSerializer(currentComponent.GetComponentId());
                bool isModife   = false;
                foreach (var oldComponent in oldComponents)
                {
                    if (currentComponent.GetComponentId() == oldComponent.GetComponentId())
                    {
                        var bitMask = serializer.DiffNetworkObject(oldComponent,
                                                                   currentComponent);
                        if (bitMask.HasValue())
                        {
                            var modifyPatch = ModifyComponentPatch.Allocate(oldComponent, currentComponent, bitMask);

                            modifyPatch.Serialize(binaryWriter, _componentSerializerManager);
                            modifyPatch.ReleaseReference();
                            c++;
                        }
                        isModife = true;
                        break;
                    }
                }

                if (!isModife)
                {
                    var addPatch = AddComponentPatch.Allocate(currentComponent);
                    addPatch.Serialize(binaryWriter, _componentSerializerManager);
                    addPatch.ReleaseReference();
                    c++;
                }
            }

            var endPosition = binaryWriter.Position;

            count = c;
            return(endPosition - startPostion);
        }