Ejemplo n.º 1
0
        public static NetworkedGameState DeserializeNetworkedGameState(
            BinaryReader reader, uint sequenceNumber, NetworkedGameState networkedGameStateRelativeTo
            )
        {
            var networkedComponentTypeInfos = networkedGameStateRelativeTo.NetworkedComponentTypeInfos;
            var networkedComponentInfoLists = networkedComponentTypeInfos
                                              .Select((networkedComponentTypeInfo, networkedComponentTypeInfosIndex) =>
            {
                var oldComponentInfos = networkedGameStateRelativeTo
                                        .NetworkedComponentInfoLists[networkedComponentTypeInfosIndex];
                var componentInfos = new List <NetworkedComponentInfo>();

                Deserialize(reader, componentInfos, (binaryReader, componentInfoIndex) =>
                {
                    var componentStateId = reader.ReadUInt32();

                    var oldComponentInfoIndex = oldComponentInfos
                                                .FindIndex(oci =>
                                                           NetLib.GetIdFromState(networkedComponentTypeInfo, oci.ComponentState) == componentStateId
                                                           );
                    NetworkedComponentInfo oldComponentInfo;

                    if (oldComponentInfoIndex < 0)
                    {
                        var stateType    = networkedComponentTypeInfo.StateType;
                        oldComponentInfo = new NetworkedComponentInfo
                        {
                            ComponentState = Activator.CreateInstance(stateType)
                        };
                    }
                    else
                    {
                        oldComponentInfo = oldComponentInfos[oldComponentInfoIndex];
                        oldComponentInfo = new NetworkedComponentInfo
                        {
                            ComponentState = ObjectExtensions.DeepCopy(oldComponentInfo.ComponentState)
                        };
                    }

                    DeserializeDelta(
                        binaryReader, networkedComponentTypeInfo, ref oldComponentInfo
                        );
                    return(oldComponentInfo);
                });

                return(componentInfos);
            })
                                              .ToList();

            return(new NetworkedGameState
            {
                SequenceNumber = sequenceNumber,
                NetworkedComponentTypeInfos = networkedComponentTypeInfos,
                NetworkedComponentInfoLists = networkedComponentInfoLists
            });
        }
Ejemplo n.º 2
0
 public static void DeserializeDelta(
     BinaryReader reader, NetworkedComponentTypeInfo networkedComponentTypeInfo, ref NetworkedComponentInfo oldComponentInfo
     )
 {
     oldComponentInfo.ChangeMask = reader.ReadUInt32();
     DeserializeGivenChangeMask(reader, networkedComponentTypeInfo, oldComponentInfo.ComponentState, oldComponentInfo.ChangeMask);
 }