コード例 #1
0
    private List <Commands> DeserializeCommands(BitBuffer buffer)
    {
        var commandsList = new List <Commands>();

        try
        {
            var playerId           = buffer.GetInt();
            var storedCommandLists = buffer.GetInt();
            var clientData         = clients[playerId];
            for (var i = 0; i < storedCommandLists; i++)
            {
                var seq = buffer.GetInt();

                var commands = new Commands(
                    seq,
                    buffer.GetByte() > 0,
                    buffer.GetByte() > 0,
                    buffer.GetByte() > 0,
                    buffer.GetByte() > 0,
                    buffer.GetFloat());

                if (clientData.RecvCommandSeq < seq)
                {
                    commandsList.Add(commands);
                    clientData.RecvCommandSeq = seq;
                }
            }
        }
        catch (Exception ex)
        {
            Debug.Log("ERROR " + ex.StackTrace);
        }

        return(commandsList);
    }
コード例 #2
0
 private static void DeserializeShotBroadcast(BitBuffer buffer, ShotBroadcast shotBroadcast)
 {
     shotBroadcast.ShotId       = buffer.GetInt();
     shotBroadcast.UserID       = buffer.GetInt();
     shotBroadcast.PlayerShotID = buffer.GetInt();
     shotBroadcast.PlayerDied   = buffer.GetInt() > 0;
 }
コード例 #3
0
        private void ManageJoinEvent(NetworkEvent nEvent)
        {
            BitBuffer buffer = nEvent.Packet.buffer;

            _clientId = buffer.GetInt();
            var playersLength = buffer.GetInt();

            for (var i = 0; i < playersLength; i++)
            {
                var    clientId = buffer.GetInt();
                Player player;
                if (clientId == _clientId)
                {
                    GameObject go = Instantiate(playerClientPrefab, new Vector3(0f, -25f, 0f), Quaternion.identity);
                    player            = new Player(clientId, go);
                    camera            = go.transform.Find("Camera").gameObject.GetComponent <Camera>();
                    _uiManager        = new UiManager(player, go.transform.Find("Ui").gameObject);
                    _actions          = go.GetComponent <Actions>();
                    _playerController = go.GetComponent <PlayerController>();
                    _playerController.SetArsenal("Rifle");
                    _actions.Aiming();
                }
                else
                {
                    GameObject go = Instantiate(otherPlayerClientPrefab, new Vector3(0f, -25f, 0f), Quaternion.identity);
                    go.GetComponent <DummyScript>().id = clientId;
                    player = new Player(clientId, go);
                }
                _players.Add(player.id, player);
                player.Deserialize(buffer);
            }
            dummy     = Instantiate(dummyPrefab, Vector3.zero, Quaternion.identity);
            dummyHead = dummy.FindInChildren("RigSpine1");
        }
コード例 #4
0
ファイル: ClientEntity.cs プロジェクト: marcoslund/tavj
    private void DeserializePlayerRespawn(BitBuffer buffer)
    {
        var playerId           = buffer.GetInt();
        var respawnSnapshotSeq = buffer.GetInt();
        var respawnPosition    = new Vector3(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());

        if (playerId == clientId)
        {
            RespawnSelf(respawnPosition);
        }
        else
        {
            if (!otherPlayers.ContainsKey(playerId))
            {
                return;
            }

            var respawnPlayer = otherPlayers[playerId];
            if (displaySeq >= respawnSnapshotSeq)
            {
                RespawnOther(respawnPlayer, respawnPosition);
            }
            else
            {
                // To avoid wrong interpolation, save data until correct snapshot is being used
                respawnPlayer.RespawnSnapshotSeq = respawnSnapshotSeq;
                respawnPlayer.RespawnPosition    = respawnPosition;
                playersToRespawn.Add(playerId);
            }
        }
    }
コード例 #5
0
 public static void PlayerJoinedDeserialize(PlayerJoined playerJoined, BitBuffer buffer)
 {
     playerJoined.UserID                  = buffer.GetInt();
     playerJoined.PlayerCount             = buffer.GetInt();
     playerJoined.Seq                     = buffer.GetInt();
     playerJoined.Time                    = buffer.GetFloat();
     playerJoined.InstantiateCubesPending = true;
 }
コード例 #6
0
    private void DeserializePlayerJoinedAck(BitBuffer buffer)
    {
        var clientId          = buffer.GetInt();
        var connectedPlayerId = buffer.GetInt(); // New player
        var clientData        = clients[connectedPlayerId];

        clientData.PlayerJoinedTimeouts.Remove(clientId);
    }
コード例 #7
0
 public static int[] PlayerConnectResponseDeserialize(BitBuffer buffer)
 {
     int[] resp = new int[2];
     buffer.GetByte();          // PlayerConnect
     resp[0] = buffer.GetInt(); // userID
     resp[1] = buffer.GetInt(); // srvPort
     return(resp);
 }
コード例 #8
0
        public void BitBufferAllInt()
        {
            var b = new BitBuffer(new byte[104857600]);

            b.Position = 0;
            Bench("PutInt aligned full", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.Put(i);
                }
            });

            b.Position = 0;
            Bench("PutInt aligned incomplete", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.Put(i, 31);
                    b.Position++;
                }
            });

            b.Position += 4;
            Bench("PutInt misaligned", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.Put(i);
                }
            });

            b.Position = 0;
            Bench("GetInt aligned full", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.GetInt();
                }
            });

            b.Position = 0;
            Bench("GetInt aligned incomplete", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.GetInt(31);
                    b.Position++;
                }
            });

            b.Position += 4;
            Bench("GetInt misaligned", 1000000, (iterations) => {
                for (int i = 0; i < iterations; i++)
                {
                    b.GetInt();
                }
            });
        }
コード例 #9
0
    public void Deserialize(BitBuffer buffer)
    {
        packetNumber = buffer.GetInt();
        var quatity = buffer.GetInt();

        for (int i = 0; i < quatity; i++)
        {
            var cubeEntity = new CubeEntity();
            cubeEntity.Deserialize(buffer);
            cubeEntities.Add(cubeEntity.id, cubeEntity);
        }
    }
コード例 #10
0
 public void AddFromBuffer(BitBuffer buffer)
 {
     for (var inputsToRead = buffer.GetInt(); inputsToRead > 0; inputsToRead--)
     {
         var inputId = buffer.GetInt();
         var input   = new Input(buffer);
         if (inputId > _lastInputIdProcessed && !_inputsToProcess.ContainsKey(inputId))
         {
             _inputsToProcess[inputId] = input;
         }
     }
 }
コード例 #11
0
    public Snapshot(BitBuffer buffer)
    {
        _playersData = new Dictionary <int, PlayerNetworkData>();
        var playersLengths = buffer.GetInt();

        for (var i = 0; i < playersLengths; i++)
        {
            var playerId    = buffer.GetInt();
            var networkData = new PlayerNetworkData(buffer);
            _playersData.Add(playerId, networkData);
        }
    }
コード例 #12
0
    private void SaveMessage(Message message)
    {
        if (message == null || message.message == null)
        {
            return;
        }

        var bitBuffer = new BitBuffer(message.message);

        if (message.messageType == MessageType.JoinACK)
        {
            var playerId = bitBuffer.GetInt(0, 10);
            _engine.playerId      = playerId;
            ClientPlayer.playerId = playerId;
            return;
        }


        var score = bitBuffer.GetInt(0, 10000);
        var level = bitBuffer.GetInt(0, 10);

        if (level > this.level)
        {
            ClientLevelManager.LevelUp(level);
            this.level = level;
        }

        var playerCount = bitBuffer.GetInt(0, 10);

        var playerStates = new List <PlayerState>();
        var enemyStates  = new List <EnemyState>();

        for (var i = 0; i < playerCount; i++)
        {
            playerStates.Add(new PlayerState(bitBuffer));
        }

        var enemyCount = bitBuffer.GetInt(0, 1000);

        for (var i = 0; i < enemyCount; i++)
        {
            enemyStates.Add(new EnemyState(bitBuffer));
        }

        _snapshot       = new Snapshot(playerStates, enemyStates, message.sequence);
        _snapshot.score = score;

        _interpolation.AddSnapshot(_snapshot);

        _prediction.checkState(_snapshot);
    }
コード例 #13
0
ファイル: ClientEntity.cs プロジェクト: marcoslund/tavj
    private void DeserializeShotBroadcast(BitBuffer buffer)
    {
        var shooterId        = buffer.GetInt();
        var shotPlayerId     = buffer.GetInt();
        var shotPlayerHealth = buffer.GetInt();

        var shooterExists = otherPlayers.ContainsKey(shooterId);
        var victimExists  = otherPlayers.ContainsKey(shotPlayerId);

        if (shotPlayerId == clientId)
        {
            health = shotPlayerHealth;
            playerHealthManager.SetPlayerHealth(health);
            if (health <= 0)
            {
                uiEventManagerventManager.ShowKillEvent(
                    shooterId,
                    shooterExists ? otherPlayers[shooterId].PlayerName : "PLAYER",
                    shotPlayerId,
                    clientName);
                ShowOwnDeathAnimation();
            }
            if (shooterExists)
            {
                otherPlayers[shooterId].PlayShot();
            }
        }
        else if (shotPlayerHealth <= 0)
        {
            if (!victimExists)
            {
                return;
            }

            var shotPlayer = otherPlayers[shotPlayerId];
            shotPlayer.IsDead = true;
            uiEventManagerventManager.ShowKillEvent(shooterId, shooterId == clientId? clientName :
                                                    (shooterExists ? otherPlayers[shooterId].PlayerName : "PLAYER"), shotPlayerId, shotPlayer.PlayerName);
            shotPlayer.TriggerDeathAnimation();
            if (shooterExists)
            {
                otherPlayers[shooterId].PlayShot();
            }
            otherPlayers[shotPlayerId].PlayDeath();
        }

        if (shooterId != clientId && shooterExists)
        {
            otherPlayers[shooterId].ShowMuzzelFlash();
        }
    }
コード例 #14
0
        public void DeserializeFromBuffer(BitBuffer buffer)
        {
            var transform = _gameObject.transform;
            var _         = buffer.GetInt(); // Last input id processed, ignored!

            _health = buffer.GetInt();
            var position = new Vector3(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());
            var rotation = new Quaternion(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());

            transform.position = position;
            transform.rotation = rotation;
            _lastSnapshotTransform.position = position;
            _lastSnapshotTransform.rotation = rotation;
        }
コード例 #15
0
    public static void DeserializeShot(List <Shot> shots, BitBuffer buffer)
    {
        int count = buffer.GetInt();

        while (count > 0)
        {
            shots.Add(new Shot(
                          buffer.GetInt(),
                          buffer.GetInt(),
                          buffer.GetInt()
                          )
                      );
            count--;
        }
    }
コード例 #16
0
    public void Deserialize(BitBuffer buffer)
    {
        inputNumber = buffer.GetInt();
        forwards    = buffer.GetFloat();
        rotate      = buffer.GetFloat();
        shoot       = buffer.GetBit();
        var hitCount = buffer.GetInt();

        for (int i = 0; i < hitCount; i++)
        {
            var newHitPackage = new HitPackage();
            newHitPackage.Deserialize(buffer);
            hitPackages.Add(newHitPackage);
        }
    }
コード例 #17
0
    private static void ClientDeserializeUpdate(List <Snapshot> interpolationBuffer, BitBuffer buffer,
                                                int displaySeq, CommandsList clientCommands, out int commandSnapshotAck)
    {
        commandSnapshotAck = -1;
        var seq         = buffer.GetInt();
        var time        = buffer.GetFloat();
        var cmdSeq      = buffer.GetInt();
        var playerCount = buffer.GetInt();

        Dictionary <int, UserState> userStates = new Dictionary <int, UserState>();
        int i;

        for (i = 0; i < playerCount; i++)
        {
            var position = new Vector3();
            var rotation = new Quaternion();

            var userID = buffer.GetInt();
            position.x = buffer.GetFloat();
            position.y = buffer.GetFloat();
            position.z = buffer.GetFloat();
            rotation.w = buffer.GetFloat();
            rotation.x = buffer.GetFloat();
            rotation.y = buffer.GetFloat();
            rotation.z = buffer.GetFloat();

            userStates.Add(userID, new UserState(position, rotation));
        }

        if (seq < displaySeq)
        {
            return;
        }

        clientCommands.SnapshotAck(cmdSeq);
        commandSnapshotAck = cmdSeq;

        Snapshot snapshot = new Snapshot(seq, time, cmdSeq, userStates);

        for (i = 0; i < interpolationBuffer.Count; i++)
        {
            if (interpolationBuffer[i].Seq > seq)
            {
                break;
            }
        }
        interpolationBuffer.Insert(i, snapshot);
    }
コード例 #18
0
ファイル: ClientEntity.cs プロジェクト: marcoslund/tavj
    private void DeserializePlayerDisconnectBroadcast(BitBuffer buffer)
    {
        var disconnectedPlayerId = buffer.GetInt();

        Destroy(otherPlayers[disconnectedPlayerId].gameObject);
        otherPlayers.Remove(disconnectedPlayerId);
    }
コード例 #19
0
 public void Deserialize(BitBuffer buffer)
 {
     commandNumber = buffer.GetInt();
     up            = buffer.GetBit();
     down          = buffer.GetBit();
     space         = buffer.GetBit();
 }
コード例 #20
0
ファイル: ConnectionManager.cs プロジェクト: marcoslund/tavj
    private void SaveConnectedPlayersAttributes(BitBuffer buffer)
    {
        var connectedPlayerCount = buffer.GetByte();

        PlayerPrefs.SetInt("ConnectedPlayerCount", connectedPlayerCount);

        for (var i = 1; i <= connectedPlayerCount; i++)
        {
            var otherClientId   = buffer.GetInt();
            var otherClientName = buffer.GetString();
            var position        = new Vector3();
            var rotation        = new Quaternion();

            position.x = buffer.GetFloat();
            position.y = buffer.GetFloat();
            position.z = buffer.GetFloat();
            rotation.w = buffer.GetFloat();
            rotation.x = buffer.GetFloat();
            rotation.y = buffer.GetFloat();
            rotation.z = buffer.GetFloat();

            PlayerPrefs.SetInt($"ConnectedPlayer{i}Id", otherClientId);
            PlayerPrefs.SetString($"ConnectedPlayer{i}Name", otherClientName);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}PosX", position.x);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}PosY", position.y);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}PosZ", position.z);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}RotW", rotation.w);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}RotX", rotation.x);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}RotY", rotation.y);
            PlayerPrefs.SetFloat($"ConnectedPlayer{i}RotZ", rotation.z);
        }
    }
コード例 #21
0
    public void Load(BitBuffer bitBuffer)
    {
        playerId = bitBuffer.GetInt();
        float x = bitBuffer.GetFloat();
        float y = bitBuffer.GetFloat();

        position.Set(x, y);
    }
コード例 #22
0
    public EnemyState(BitBuffer bitBuffer)
    {
        id = bitBuffer.GetInt(0, 1000);

        type = (EnemyType)bitBuffer.GetInt(0, 3);

        x = bitBuffer.GetFloat(-200, 200, (float)0.1);
        z = bitBuffer.GetFloat(-200, 200, (float)0.1);

        yA = bitBuffer.GetInt(0, 360);

        xH = bitBuffer.GetFloat(-200, 200, (float)0.1);
        yH = bitBuffer.GetFloat(-200, 200, (float)0.1);
        zH = bitBuffer.GetFloat(-200, 200, (float)0.1);

        health = bitBuffer.GetInt(0, 200);
    }
コード例 #23
0
ファイル: ClientInput.cs プロジェクト: JoaquinBattilana/TAVJ
 public ClientInput(BitBuffer buffer)
 {
     _number     = buffer.GetInt();
     _horizontal = buffer.GetFloat();
     _vertical   = buffer.GetFloat();
     _mouseX     = buffer.GetFloat();
     _mouseY     = buffer.GetFloat();
 }
コード例 #24
0
        void manageJoinBroadcastEvent(NetworkEvent nEvent)
        {
            BitBuffer buffer      = nEvent.Packet.buffer;
            var       newClientId = buffer.GetInt();
            var       newPlayer   = new Player(newClientId, Instantiate(otherPlayerClientPrefab, Vector3.zero, Quaternion.identity));

            _players.Add(newPlayer.id, newPlayer);
            newPlayer.Deserialize(buffer);
        }
コード例 #25
0
 public void Deserialize(BitBuffer buffer)
 {
     aux_position             = new Vector3();
     aux_rotation             = new Quaternion();
     aux_id                   = buffer.GetInt();
     aux_kills                = buffer.GetInt();
     aux_health               = buffer.GetFloat();
     health                   = aux_health;
     kills                    = aux_kills;
     aux_position.x           = buffer.GetFloat();
     aux_position.y           = buffer.GetFloat();
     aux_position.z           = buffer.GetFloat();
     aux_rotation.w           = buffer.GetFloat();
     aux_rotation.x           = buffer.GetFloat();
     aux_rotation.y           = buffer.GetFloat();
     aux_rotation.z           = buffer.GetFloat();
     aux_lastCommandProcessed = buffer.GetInt();
 }
コード例 #26
0
ファイル: Snapshot.cs プロジェクト: sebasfavaron/tav
    public void Deserialize(BitBuffer buffer)
    {
        var bulletCount = buffer.GetInt();

        for (int i = 0; i < bulletCount; i++)
        {
            var pos = new Vector3(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());
            var fwd = new Vector3(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());
            var rot = new Quaternion(buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat(), buffer.GetFloat());
            bullets.Add(new Bullet(pos, fwd, rot));
        }

        packetNumber = buffer.GetInt();
        while (buffer.HasRemaining())
        {
            var key = buffer.GetInt();
            cubeEntities[key].Deserialize(buffer);
        }
    }
コード例 #27
0
ファイル: Commands.cs プロジェクト: mgrabina/tav1
 public void Deserialize(BitBuffer buffer)
 {
     number     = buffer.GetInt();
     x          = buffer.GetFloat();
     y          = buffer.GetFloat();
     rotation_x = buffer.GetFloat();
     rotation_y = buffer.GetFloat();
     rotation_z = buffer.GetFloat();
     space      = buffer.GetBit();
 }
コード例 #28
0
ファイル: ClientEntity.cs プロジェクト: marcoslund/tavj
    private void DeserializeSnapshot(BitBuffer buffer)
    {
        var recvFrameSeq = buffer.GetInt();

        if (recvFrameSeq < displaySeq)
        {
            return;                            // Check if received snapshot is old
        }
        var time        = buffer.GetFloat();
        var recvCmdSeq  = buffer.GetInt();
        var recvVelY    = buffer.GetFloat();
        var playerCount = buffer.GetByte();

        var positions = new Dictionary <int, Vector3>();
        var rotations = new Dictionary <int, Quaternion>();

        for (int i = 0; i < playerCount; i++)
        {
            var position = new Vector3();
            var rotation = new Quaternion();

            var playerId = buffer.GetInt();
            position.x = buffer.GetFloat();
            position.y = buffer.GetFloat();
            position.z = buffer.GetFloat();
            rotation.w = buffer.GetFloat();
            rotation.x = buffer.GetFloat();
            rotation.y = buffer.GetFloat();
            rotation.z = buffer.GetFloat();

            positions.Add(playerId, position);
            rotations.Add(playerId, rotation);

            if (playerId == clientId)
            {
                Conciliate(recvCmdSeq, position, recvVelY);
            }
        }

        var snapshot = new Snapshot(recvFrameSeq, time, positions, rotations);

        StoreSnapshot(snapshot, recvFrameSeq);
    }
コード例 #29
0
 public PlayerNetworkData(BitBuffer buffer)
 {
     _position       = new Vector3();
     _rotation       = new Quaternion();
     _mostBigInput   = buffer.GetInt();
     _health         = buffer.GetInt();
     _points         = buffer.GetInt();
     _position.x     = buffer.GetFloat();
     _position.y     = buffer.GetFloat();
     _position.z     = buffer.GetFloat();
     _rotation.x     = buffer.GetFloat();
     _rotation.y     = buffer.GetFloat();
     _rotation.z     = buffer.GetFloat();
     _rotation.w     = buffer.GetFloat();
     _headRotation.x = buffer.GetFloat();
     _headRotation.y = buffer.GetFloat();
     _headRotation.z = buffer.GetFloat();
     _headRotation.w = buffer.GetFloat();
 }
コード例 #30
0
ファイル: ConnectionManager.cs プロジェクト: marcoslund/tavj
    private void SavePlayerAttributes(BitBuffer buffer)
    {
        var clientPort     = buffer.GetInt();
        var serverPort     = buffer.GetInt();
        var clientTime     = buffer.GetFloat();
        var displaySeq     = buffer.GetInt();
        var minBufferElems = buffer.GetByte();
        var position       = new Vector3();
        var rotation       = new Quaternion();

        position.x = buffer.GetFloat();
        position.y = buffer.GetFloat();
        position.z = buffer.GetFloat();
        rotation.w = buffer.GetFloat();
        rotation.x = buffer.GetFloat();
        rotation.y = buffer.GetFloat();
        rotation.z = buffer.GetFloat();

        var health  = buffer.GetInt();
        var speed   = buffer.GetFloat();
        var gravity = buffer.GetFloat();

        PlayerPrefs.SetInt("ClientId", clientId);
        PlayerPrefs.SetInt("ClientPort", clientPort);
        PlayerPrefs.SetInt("ServerPort", serverPort);
        PlayerPrefs.SetFloat("ClientTime", clientTime);
        PlayerPrefs.SetInt("DisplaySequence", displaySeq);
        PlayerPrefs.SetInt("MinInterpolationBufferElements", minBufferElems);
        PlayerPrefs.SetFloat("ClientPosX", position.x);
        PlayerPrefs.SetFloat("ClientPosY", position.y);
        PlayerPrefs.SetFloat("ClientPosZ", position.z);
        PlayerPrefs.SetFloat("ClientRotW", rotation.w);
        PlayerPrefs.SetFloat("ClientRotX", rotation.x);
        PlayerPrefs.SetFloat("ClientRotY", rotation.y);
        PlayerPrefs.SetFloat("ClientRotZ", rotation.z);
        PlayerPrefs.SetInt("ClientHealth", health);
        PlayerPrefs.SetFloat("PlayerSpeed", speed);
        PlayerPrefs.SetFloat("Gravity", gravity);

        SaveConnectedPlayersAttributes(buffer);

        PlayerPrefs.Save();
    }