internal void OnNewPlayerCreated(FrameSyncPlayer player) { if (_inputPlayerCreatedHandler != null) { _inputPlayerCreatedHandler.Invoke(player); } }
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); }
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); }
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); } } }
// 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); } }
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); }
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); }
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); }
public void SetIntForPlayer(string name, int value, FrameSyncPlayer player) { player.SetInt(_inputIndexDictionary[name], value); }
public int GetIntForPlayer(string name, FrameSyncPlayer player) { return(player.GetInt(_inputIndexDictionary[name])); }
public void SetTriggerForPlayer(string name, bool value, FrameSyncPlayer player) { player.SetTrigger(_inputIndexDictionary[name], value); }
public bool GetTriggerForPlayer(string name, FrameSyncPlayer player) { return(player.GetTrigger(_inputIndexDictionary[name])); }
public void SetFloatForPlayer(string name, Fix64 value, FrameSyncPlayer player) { player.SetFloat(_inputIndexDictionary[name], value); }
public Fix64 GetFloatForPlayer(string name, FrameSyncPlayer player) { return(player.GetFloat(_inputIndexDictionary[name])); }