Beispiel #1
0
        private void SendPackage(DatagramPayload payload, NetPeer peer)
        {
            NetDataWriter package = new NetDataWriter();

            package.Put(SerializeDatagramPayload(payload));
            peer.Send(package, SendOptions.ReliableOrdered);
        }
Beispiel #2
0
        public void SendSessionStartedPackage(SimulatorDataSet simulatorDataSet)
        {
            _lastPackedStopWatch.Restart();
            DatagramPayload payload = _datagramPayloadPacker.CreateSessionStartedPayload(simulatorDataSet);

            SendPackage(payload);
        }
Beispiel #3
0
        public DatagramPayload CreateSessionStartedPayload(SimulatorDataSet simulatorData)
        {
            _lastDataSet = simulatorData;
            DatagramPayload datagramPayload = CreatePayload(simulatorData, DatagramPayloadKind.SessionStart);

            return(datagramPayload);
        }
        private void ExtractLastData(DatagramPayload datagramPayload)
        {
            if (datagramPayload.ContainsOtherDriversTiming)
            {
                _lastDriversInfo = datagramPayload.DriversInfo;
                _lastLeaderInfo  = datagramPayload.LeaderInfo;
                _lastPlayerInfo  = datagramPayload.DriversInfo.Any(x => x.IsPlayer) ? datagramPayload.DriversInfo.FirstOrDefault(x => x.IsPlayer) : _lastPlayerInfo;
            }

            if (datagramPayload.ContainsPlayersTiming)
            {
                _lastPlayerInfo = datagramPayload.PlayerInfo;
                if (_lastDriversInfo != null)
                {
                    int index = Array.IndexOf(_lastDriversInfo, _lastDriversInfo.FirstOrDefault(x => x.IsPlayer));
                    if (index != -1)
                    {
                        _lastDriversInfo[index] = _lastPlayerInfo;
                    }
                }
            }

            if (datagramPayload.ContainsSimulatorSourceInfo)
            {
                _lastSimulatorSourceInfo = datagramPayload.SimulatorSourceInfo;
            }
        }
Beispiel #5
0
        private void SendPackage(DatagramPayload payload)
        {
            UpdateViewModelInputs(payload.InputInfo, payload.Source);
            NetDataWriter package = new NetDataWriter();

            package.Put(SerializeDatagramPayload(payload));
            _server.SendToAll(package, SendOptions.ReliableOrdered);
        }
Beispiel #6
0
        public DatagramPayload CreateRegularDatagramPayload(SimulatorDataSet simulatorData)
        {
            _lastDataSet = simulatorData;
            DatagramPayload datagramPayload = CreatePayload(simulatorData, DatagramPayloadKind.Normal);

            RemoveUnnecessaryData(datagramPayload);
            return(datagramPayload);
        }
Beispiel #7
0
        private byte[] SerializeDatagramPayload(DatagramPayload payload)
        {
            byte[] payloadBytes;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                _formatter.Serialize(memoryStream, payload);
                payloadBytes = memoryStream.ToArray();
            }

            return(payloadBytes);
        }
        private SimulatorDataSet CreateSimulatorDataSet(DatagramPayload datagramPayload)
        {
            SimulatorDataSet newSet = new SimulatorDataSet(datagramPayload.Source)
            {
                DriversInfo         = datagramPayload.DriversInfo,
                InputInfo           = datagramPayload.InputInfo,
                LeaderInfo          = datagramPayload.LeaderInfo,
                PlayerInfo          = datagramPayload.PlayerInfo,
                SessionInfo         = datagramPayload.SessionInfo,
                SimulatorSourceInfo = datagramPayload.SimulatorSourceInfo,
            };

            FillMissingInformation(newSet);
            return(newSet);
        }
Beispiel #9
0
        private void RemoveUnnecessaryData(DatagramPayload datagramPayload)
        {
            if (!_isNetworkConservationEnabled)
            {
                return;
            }

            if (_packageTimer.Elapsed > _packedDelay)
            {
                _packageTimer.Restart();
            }

            if (_playerInfoDelayTimer.Elapsed > _playerInfoDelay)
            {
                _playerInfoDelayTimer.Restart();
            }
            else
            {
                datagramPayload.PlayerInfo            = null;
                datagramPayload.ContainsPlayersTiming = false;
            }

            if (_driversInfoDelayTimer.Elapsed > _driversInfoDelay)
            {
                _driversInfoDelayTimer.Restart();
            }
            else
            {
                datagramPayload.ContainsOtherDriversTiming = false;
                datagramPayload.DriversInfo = null;
                datagramPayload.LeaderInfo  = null;
            }

            if (_lastSimulatorSourceName != datagramPayload.Source || !_simulatorSourceInfoComparator.AreEqual(datagramPayload.SimulatorSourceInfo, _lastSimulatorSourceInfo))
            {
                _lastSimulatorSourceName = datagramPayload.Source;
                _lastSimulatorSourceInfo = datagramPayload.SimulatorSourceInfo;
            }
            else
            {
                datagramPayload.ContainsSimulatorSourceInfo = false;
                datagramPayload.SimulatorSourceInfo         = null;
            }
        }
Beispiel #10
0
        public void SendRegularDataPackage(SimulatorDataSet simulatorDataSet)
        {
            if (!_datagramPayloadPacker.IsMinimalPackageDelayPassed())
            {
                return;
            }

            lock (_queueLock)
            {
                if (_newPeers.Any())
                {
                    DatagramPayload initialPayload = _datagramPayloadPacker.CreateHandshakeDatagramPayload();
                    while (_newPeers.Count > 0)
                    {
                        SendPackage(initialPayload, _newPeers.Dequeue());
                    }
                }
            }

            _lastPackedStopWatch.Restart();
            DatagramPayload payload = _datagramPayloadPacker.CreateRegularDatagramPayload(simulatorDataSet);

            SendPackage(payload);
        }
Beispiel #11
0
        private void SendKeepAlivePacket()
        {
            DatagramPayload payload = _datagramPayloadPacker.CreateHearthBeatDatagramPayload();

            SendPackage(payload);
        }
 public SimulatorDataSet UnpackDatagramPayload(DatagramPayload datagramPayload)
 {
     ExtractLastData(datagramPayload);
     return(CreateSimulatorDataSet(datagramPayload));
 }