示例#1
0
        public P2PBackrollSession(BackrollSessionConfig config)
        {
            _next_recommended_sleep = 0;

            _next_spectator_frame = 0;

            _callbacks = config.Callbacks;

            _players    = InitializeConnections(config.Players);
            _spectators = InitializeConnections(config.Spectators);

            SetupConnections(_players);
            SetupConnections(_spectators);

            _localConnectStatus = new BackrollConnectStatus[PlayerCount];
            for (int i = 0; i < _localConnectStatus.Length; i++)
            {
                _localConnectStatus[i].LastFrame = -1;
            }

            // Initialize the synchronziation layer
            _sync = new Sync(_localConnectStatus, new Sync.Config {
                NumPlayers          = config.Players.Length,
                InputSize           = InputSize,
                Callbacks           = _callbacks,
                NumPredictionFrames = BackrollConstants.kMaxPredictionFrames,
            });
        }
        public SyncTestsBackrollSession(BackrollSessionConfig config, int frames)
        {
            _callbacks      = config.Callbacks;
            _num_players    = config.Players.Length;
            _check_distance = frames;
            _last_verified  = 0;
            _rollingback    = false;
            _running        = false;
            _current_input.Clear();

            _sync = new Sync(null, new Sync.Config {
                NumPredictionFrames = BackrollConstants.kMaxPredictionFrames
            });
        }
示例#3
0
        public Sync(BackrollConnectStatus[] connect_status, Config config)
        {
            _localConnectStatus  = connect_status;
            _lastConfirmedFrame  = -1;
            _maxPredictionFrames = config.NumPredictionFrames;

            _savedstate = new SavedState(_maxPredictionFrames);
            _config     = config;
            _callbacks  = config.Callbacks;
            FrameCount  = 0;
            InRollback  = false;


            CreateQueues(config);
        }
        public SpectatorBackrollSession(BackrollSessionConfig config)
        {
            _callbacks          = config.Callbacks;
            _num_players        = config.Players.Length;
            _next_input_to_send = 0;
            _synchronizing      = true;

            _inputs = new GameInput[kFrameBufferSize];
            for (var i = 0; i < _inputs.Length; i++)
            {
                _inputs[i].Frame = -1;
            }

            _host = new BackrollConnection(config.Players[0], 0, null);
            _host.Synchronize();

            _host.OnConnected += () => {
                _callbacks.OnConnected?.Invoke(new ConnectedEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    }
                });
            };

            _host.OnSynchronizing += (count, total) => {
                _callbacks.OnPlayerSynchronizing?.Invoke(new PlayerSynchronizingEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    },
                    Count = count,
                    Total = total
                });
            };

            _host.OnSynchronized += () => {
                if (!_synchronizing)
                {
                    return;
                }
                _callbacks.OnPlayerSynchronized?.Invoke(new PlayerSynchronizedEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    },
                });
                _callbacks.OnReady?.Invoke();
                _synchronizing = false;
            };

            _host.OnNetworkInterrupted += (disconnectTimeout) => {
                _callbacks.OnConnectionInterrupted?.Invoke(new ConnectionInterruptedEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    },
                    DisconnectTimeout = disconnectTimeout
                });
            };

            _host.OnNetworkResumed += () => {
                _callbacks.OnConnectionResumed?.Invoke(new ConnectionResumedEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    },
                });
            };

            _host.OnDisconnected += () => {
                _callbacks.OnDisconnected?.Invoke(new DisconnectedEvent {
                    Player = new BackrollPlayerHandle {
                        Id = 0
                    },
                });
            };

            _host.OnInput += (input) => {
                _host.SetLocalFrameNumber(input.Frame);
                _host.SendInputAck();
                _inputs[input.Frame % _inputs.Length] = input;
            };
        }