Esempio n. 1
0
    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);
            }
        }
    }
Esempio n. 2
0
 public ClientInput(BitBuffer buffer)
 {
     _number     = buffer.GetInt();
     _horizontal = buffer.GetFloat();
     _vertical   = buffer.GetFloat();
     _mouseX     = buffer.GetFloat();
     _mouseY     = buffer.GetFloat();
 }
Esempio n. 3
0
    public void Load(BitBuffer bitBuffer)
    {
        playerId = bitBuffer.GetInt();
        float x = bitBuffer.GetFloat();
        float y = bitBuffer.GetFloat();

        position.Set(x, y);
    }
Esempio n. 4
0
    public static PositionInfo FromBytes(BitBuffer bitBuffer)
    {
        float x = bitBuffer.GetFloat();
        float y = bitBuffer.GetFloat();
        float z = bitBuffer.GetFloat();

        return(new PositionInfo(new Vector3(x, y, z)));
    }
Esempio n. 5
0
 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();
 }
Esempio n. 6
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);
        }
    }
Esempio n. 7
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);
    }
Esempio n. 8
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);
    }
Esempio n. 9
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;
 }
Esempio n. 10
0
    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);
        }
    }
Esempio n. 11
0
    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();
    }
Esempio n. 12
0
    public void Load(BitBuffer bitBuffer)
    {
        Time = bitBuffer.GetFloat();
        var playerCount = bitBuffer.GetInt();

        for (var i = 0; i < playerCount; i++)
        {
            var playerData = new PlayerData();
            playerData.Load(bitBuffer);
            PlayersData.Add(playerData);
        }
    }
Esempio n. 13
0
    public void Load(BitBuffer bitBuffer)
    {
        time = bitBuffer.GetFloat();
        int playerCount = bitBuffer.GetInt();

        for (int i = 0; i < playerCount; i++)
        {
            PlayerData playerData = new PlayerData();
            playerData.Load(bitBuffer);
            playersData.Add(playerData);
        }
    }
Esempio n. 14
0
    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);
        }
    }
Esempio n. 15
0
    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);
    }
Esempio n. 16
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);
    }
Esempio n. 17
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();
 }
Esempio n. 18
0
    /**
     * Mueve un jugador en alguna dirección.
     */
    public Packet Move(Packet request)
    {
        int       id         = request.Reset(6).GetInteger();
        BitBuffer bb         = request.GetBitBuffer();
        float     Δt         = bb.GetFloat(0, 1, 0.0001f);
        int       directions = bb.GetInt(0, 10);
        float     delta      = Δt * config.playerSpeed;

        LoadGhostFor(id);
        for (int k = 0; k < directions; ++k)
        {
            switch (bb.GetDirection())
            {
            case Direction.FORWARD: {
                ghostTransform.Translate(0, 0, delta);
                break;
            }

            case Direction.STRAFING_LEFT: {
                ghostTransform.Translate(-delta, 0, 0);
                break;
            }

            case Direction.BACKWARD: {
                ghostTransform.Translate(0, 0, -delta);
                break;
            }

            case Direction.STRAFING_RIGHT: {
                ghostTransform.Translate(delta, 0, 0);
                break;
            }

            case Direction.ROTATE_RIGHT: {
                ghostTransform.Rotate(0, 10 * delta, 0);
                break;
            }

            case Direction.ROTATE_LEFT: {
                ghostTransform.Rotate(0, -10 * delta, 0);
                break;
            }
            }
        }
        SaveGhostFor(id);
        return(GetResponseHeader(request.Reset(), 0).Build());
    }
Esempio n. 19
0
 public void Deserialize(BitBuffer buffer)
 {
     position   = new Vector3();
     rotation   = new Quaternion();
     id         = buffer.GetString();
     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();
     //Debug.Log(position);
     //Debug.Log(rotation);
 }
Esempio n. 20
0
    public void Deserialize(BitBuffer buffer)
    {
        position   = new Vector3();
        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();
        health     = buffer.GetFloat();
        points     = buffer.GetInt();

        if (uiManager != null)
        {
            uiManager.UpdateHealthUI(health);
        }
    }
Esempio n. 21
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;
        }
Esempio n. 22
0
    private void DeserializePlayerJoined(BitBuffer buffer)
    {
        var newPlayerId   = buffer.GetInt();
        var newPlayerName = 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();

        InitializeConnectedPlayer(newPlayerId, newPlayerName, position, rotation);

        SendPlayerJoinedAck(newPlayerId);
    }
Esempio n. 23
0
    private static void DeserializeCommands(List <Commands> totalCommands, BitBuffer buffer)
    {
        var count = buffer.GetInt();

        while (count > 0)
        {
            var seq = buffer.GetInt();

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

            totalCommands.Add(commands);
            count--;
        }
    }
Esempio n. 24
0
 public void Load(BitBuffer buffer)
 {
     x     = buffer.GetFloat();
     y     = buffer.GetFloat();
     shoot = buffer.GetBit();
 }
Esempio n. 25
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();
 }
Esempio n. 26
0
 public void Deserialize(BitBuffer buffer)
 {
     hitName = buffer.GetString();
     damage  = buffer.GetFloat();
 }
Esempio n. 27
0
        public void Deserialize(BitBuffer buffer)
        {
            var position     = new Vector3();
            var rotation     = new Quaternion();
            var headRotation = 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();
            _entity.transform.position = position;
            _entity.transform.rotation = rotation;
            _head.transform.rotation   = headRotation;
        }