Пример #1
0
 internal void OnNewPlayerCreated(FrameSyncPlayer player)
 {
     if (_inputPlayerCreatedHandler != null)
     {
         _inputPlayerCreatedHandler.Invoke(player);
     }
 }
Пример #2
0
        internal void ApplyPrediction(FrameSyncInput input, InputFrame i1, InputFrame i2)
        {
            //copy i1 to i2
            SWBytes.CopyFull(i1.bytes, i2.bytes);

            //let input reset
            //important to reset triggers
            input.InputJustCopied(i2.bytes);

            byte inputSize = input.Size;

            if (bytes.DataLength > 0)
            {
                byte playerCount = bytes.PopByte();

                for (int i = 0; i < playerCount; i++)
                {
                    byte            playerID = bytes.PopByte();
                    FrameSyncPlayer player   = input.GetPlayer(playerID);
                    byte            offset   = player.InputOffset;
                    SWBytes.Copy(bytes, i2.bytes, bytes.ReadIndex, offset, inputSize);
                    bytes.SkipRead(inputSize);
                }
            }

            //reset read index
            bytes.SetReadIndex(0);

            //prepare bitarray
            input.InputDeltaJustApplied(i2.bytes);
        }
Пример #3
0
        internal void Apply(FrameSyncInput input, InputFrame i1, InputFrame i2)
        {
            //copy i1 to i2
            SWBytes.CopyFull(i1.bytes, i2.bytes);

            //let input reset
            //important to reset triggers
            input.InputJustCopied(i2.bytes);

            //apply delta for each player
            byte inputSize = input.Size;

            SWConsole.Crit($"ApplyDelta delta frameNumber={frameNumber} {bytes.FullString()}");

            while (bytes.DataLength > 0)
            {
                byte            playerID = bytes.PopByte();
                FrameSyncPlayer player   = input.GetPlayer(playerID);
                if (player == null)
                {
                    SWConsole.Error($"InputFrameDelta Apply: player not found {playerID}");
                }
                byte offset = player.InputOffset;
                SWBytes.Copy(bytes, i2.bytes, bytes.ReadIndex, offset, inputSize);
                bytes.SkipRead(inputSize);
            }

            //reset read index
            bytes.SetReadIndex(0);

            //prepare bitarray
            input.InputDeltaJustApplied(i2.bytes);
        }
Пример #4
0
        public void ExportInput(SWBytes bytes)
        {
            byte playerCount = 0;

            foreach (KeyValuePair <byte, FrameSyncPlayer> pair in _playerDictionary)
            {
                FrameSyncPlayer player = pair.Value;
                if (player.Type == FrameSyncPlayerType.Local || player.Type == FrameSyncPlayerType.LocalBot)
                {
                    playerCount++;
                    pair.Value.ExportInput(bytes);
                }
            }
        }
Пример #5
0
        // predition
        internal void ApplyPredictionModifier(SWBytes bytes)
        {
            foreach (KeyValuePair <byte, FrameSyncPlayer> pair in _playerDictionary)
            {
                FrameSyncPlayer player = pair.Value;
                if (player.Type == FrameSyncPlayerType.Local || player.Type == FrameSyncPlayerType.LocalBot)
                {
                    // only apply modifier to remote player's input
                    continue;
                }

                player.ApplyPredictionModifier(bytes);
            }
        }
Пример #6
0
        internal FrameSyncPlayer CreateOnlineGamePlayer(byte playerID, byte localPlayerID)
        {
            FrameSyncPlayer player = _input.CreatePlayer(playerID);

            if (playerID == localPlayerID)
            {
                player.Type = FrameSyncPlayerType.Local;
            }
            else
            {
                player.Type = FrameSyncPlayerType.Remote;
            }

            OnNewPlayerCreated(player);
            return(player);
        }
Пример #7
0
        public FrameSyncPlayer CreateOfflineGamePlayer()
        {
            if (_gameState != FrameSyncGameState.Default)
            {
                SWConsole.Error("SWFrameSyncGame: not allow to add players after starting the game");
                return(null);
            }

            FrameSyncPlayer player = _input.CreatePlayer(_offlineGamePlayerID);

            _offlineGamePlayerID++;

            OnNewPlayerCreated(player);

            return(player);
        }
Пример #8
0
        internal FrameSyncPlayer CreatePlayer(byte playerID)
        {
            if (_inputConfig == null)
            {
                throw new InvalidOperationException("SWFrameSyncInputConfig not set");
            }

            if (_playerDictionary.ContainsKey(playerID))
            {
                return(_playerDictionary[playerID]);
            }

            FrameSyncPlayer player = new FrameSyncPlayer(playerID, _inputConfig);

            _playerDictionary[playerID] = player;
            return(player);
        }
Пример #9
0
 public void SetIntForPlayer(string name, int value, FrameSyncPlayer player)
 {
     player.SetInt(_inputIndexDictionary[name], value);
 }
Пример #10
0
 public int GetIntForPlayer(string name, FrameSyncPlayer player)
 {
     return(player.GetInt(_inputIndexDictionary[name]));
 }
Пример #11
0
 public void SetTriggerForPlayer(string name, bool value, FrameSyncPlayer player)
 {
     player.SetTrigger(_inputIndexDictionary[name], value);
 }
Пример #12
0
 public bool GetTriggerForPlayer(string name, FrameSyncPlayer player)
 {
     return(player.GetTrigger(_inputIndexDictionary[name]));
 }
Пример #13
0
 public void SetFloatForPlayer(string name, Fix64 value, FrameSyncPlayer player)
 {
     player.SetFloat(_inputIndexDictionary[name], value);
 }
Пример #14
0
 public Fix64 GetFloatForPlayer(string name, FrameSyncPlayer player)
 {
     return(player.GetFloat(_inputIndexDictionary[name]));
 }