Esempio n. 1
0
 public void Deserialize(uint tick, DataStreamReader reader, ref DataStreamReader.Context ctx)
 {
     this.tick       = tick;
     horizontal      = reader.ReadInt(ref ctx);
     vertical        = reader.ReadInt(ref ctx);
     spacebarSpecial = reader.ReadInt(ref ctx);
 }
Esempio n. 2
0
        protected override void Deserialize(ref DataStreamReader reader, byte dirtyMask)
        {
            if (IsDirtyAt(dirtyMask, 0))
            {
                int byteCount = reader.ReadInt();
                var bytes     = new NativeArray <byte>(byteCount, Allocator.Temp);
                reader.ReadBytes(bytes);
                _paramBytes = bytes.ToArray();
                bytes.Dispose();
                DeserializeParameters(_paramBytes);
            }

            if (IsDirtyAt(dirtyMask, 1))
            {
                _currentStateHash = reader.ReadInt();
                _currentEnterTime = reader.ReadFloat();
                if (_currentStateHash == _animator.GetCurrentAnimatorStateInfo(0).fullPathHash)
                {
                    _animator.PlayInFixedTime(0, 0, Server.Time - _currentEnterTime);
                }
                else
                {
                    _animator.PlayInFixedTime(_currentStateHash, 0, Server.Time - _currentEnterTime);
                }
            }
        }
Esempio n. 3
0
 public void Deserialize(DataStreamReader reader, ref DataStreamReader.Context ctx)
 {
     width          = reader.ReadInt(ref ctx);
     height         = reader.ReadInt(ref ctx);
     playerForce    = reader.ReadFloat(ref ctx);
     bulletVelocity = reader.ReadFloat(ref ctx);
 }
Esempio n. 4
0
 public void Deserialize(ref DataStreamReader reader)
 {
     Name   = reader.ReadString();
     Size.x = reader.ReadInt();
     Size.y = reader.ReadInt();
     //reader.ReadInt();
 }
Esempio n. 5
0
 public void Deserialize(ref DataStreamReader reader)
 {
     velocity.value = new int2(
         reader.ReadInt(),
         reader.ReadInt()
         );
 }
 public void Deserialize(DataStreamReader reader, ref DataStreamReader.Context ctx)
 {
     nid         = reader.ReadInt(ref ctx);
     simTickRate = reader.ReadInt(ref ctx);
     netTickRate = reader.ReadInt(ref ctx);
     simMaxSteps = reader.ReadInt(ref ctx);
 }
Esempio n. 7
0
 public void Deserialize(ref DataStreamReader reader)
 {
     nid         = reader.ReadInt();
     simTickRate = reader.ReadInt();
     netTickRate = reader.ReadInt();
     simMaxSteps = reader.ReadInt();
 }
    protected override void Read(int connectionId, DataStreamReader stream, ref DataStreamReader.Context c)
    {
        foreach (var reader in Readers)
        {
            var context = default(DataStreamReader.Context);

            if (reader.ConnectionId != null && reader.ConnectionId != connectionId)
            {
                continue;
            }

            var id = stream.ReadInt(ref context);

            if (reader.InstanceId != null)
            {
                var instanceId = stream.ReadInt(ref context);
                if (instanceId != reader.InstanceId)
                {
                    continue;
                }
            }

            if (id == reader.Id)
            {
                reader.Read(connectionId, stream, ref context);
            }
        }
    }
    public override void Read(DataStreamReader stream)
    {
        var readers = new List <NetReader>(Readers);

        foreach (var reader in readers)
        {
            var readerCtx = default(DataStreamReader.Context);

            var id = stream.ReadInt(ref readerCtx);
            if (id == reader.Id)
            {
                if (reader.InstanceId != null)
                {
                    var instanceId = stream.ReadInt(ref readerCtx);

                    if (reader.Log)
                    {
                        Debug.Log($"Instance ID: {instanceId} {reader.transform.name}");
                    }

                    if (instanceId != reader.InstanceId.Value)
                    {
                        continue;
                    }
                }

                reader.Read(0, stream, ref readerCtx);
            }
        }
    }
 public void Deserialize(uint tick, ref DataStreamReader reader)
 {
     this.tick  = tick;
     horizontal = reader.ReadInt();
     vertical   = reader.ReadInt();
     rotation   = reader.ReadInt();
 }
Esempio n. 11
0
        public void ReadWritePackedUIntWithDeferred()
        {
            using (var compressionModel = new NetworkCompressionModel(Allocator.Persistent))
            {
                var  dataStream = new DataStreamWriter(300 * 4, Allocator.Temp);
                uint base_val   = 2000;
                uint count      = 277;
                var  def        = dataStream;
                dataStream.WriteInt((int)0);
                for (uint i = 0; i < count; ++i)
                {
                    dataStream.WritePackedUInt(base_val + i, compressionModel);
                }

                dataStream.Flush();
                def.WriteInt(1979);
                def = dataStream;
                dataStream.WriteInt((int)0);
                def.WriteInt(1979);
                dataStream.Flush();
                var reader = new DataStreamReader(dataStream.AsNativeArray());
                Assert.AreEqual(1979, reader.ReadInt());
                for (uint i = 0; i < count; ++i)
                {
                    var val = reader.ReadPackedUInt(compressionModel);
                    Assert.AreEqual(base_val + i, val);
                }
                Assert.AreEqual(1979, reader.ReadInt());
            }
        }
Esempio n. 12
0
        public void ReadWritePackedUIntWithDeferred()
        {
            using (var dataStream = new DataStreamWriter(300 * 4, Allocator.Persistent))
                using (var compressionModel = new NetworkCompressionModel(Allocator.Persistent))
                {
                    uint base_val = 2000;
                    uint count    = 277;
                    var  def      = dataStream.Write((int)0);
                    for (uint i = 0; i < count; ++i)
                    {
                        dataStream.WritePackedUInt(base_val + i, compressionModel);
                    }

                    dataStream.Flush();
                    def.Update(1979);
                    def = dataStream.Write((int)0);
                    def.Update(1979);
                    dataStream.Flush();
                    var reader = new DataStreamReader(dataStream, 0, dataStream.Length);
                    var ctx    = default(DataStreamReader.Context);
                    Assert.AreEqual(1979, reader.ReadInt(ref ctx));
                    for (uint i = 0; i < count; ++i)
                    {
                        var val = reader.ReadPackedUInt(ref ctx, compressionModel);
                        Assert.AreEqual(base_val + i, val);
                    }
                    Assert.AreEqual(1979, reader.ReadInt(ref ctx));
                }
        }
Esempio n. 13
0
 public void Deserialize(ref DataStreamReader reader)
 {
     width          = reader.ReadInt();
     height         = reader.ReadInt();
     playerForce    = reader.ReadFloat();
     bulletVelocity = reader.ReadFloat();
 }
Esempio n. 14
0
        public override void Read(DataStreamReader reader, ref DataStreamReader.Context context)
        {
            if (Data == null)
            {
                Data = new SpawnRPCData();
            }

            Data.InstanceId = reader.ReadInt(ref context);
            Data.PrefabId   = reader.ReadInt(ref context);
            Data.Ownership  = (EOwnershipType)reader.ReadInt(ref context);

            byte[]  buff     = reader.ReadBytesAsArray(ref context, sizeof(float) * 7);
            Vector3 position = Vector3.zero;

            position.x = BitConverter.ToSingle(buff, 0 * sizeof(float));
            position.y = BitConverter.ToSingle(buff, 1 * sizeof(float));
            position.z = BitConverter.ToSingle(buff, 2 * sizeof(float));

            var rotation = Quaternion.identity;

            rotation.x = BitConverter.ToSingle(buff, 3 * sizeof(float));
            rotation.y = BitConverter.ToSingle(buff, 4 * sizeof(float));
            rotation.z = BitConverter.ToSingle(buff, 5 * sizeof(float));
            rotation.w = BitConverter.ToSingle(buff, 6 * sizeof(float));

            Data.Position = position;
            Data.Rotation = rotation;
        }
Esempio n. 15
0
        public static void Read(DataStreamReader stream, ClientBehaviour reader)
        {
            ServerMessage serverMessageType = (ServerMessage)stream.ReadByte();

            Debug.Log(reader.name + " got message of type " + serverMessageType.ToString());
            switch (serverMessageType)
            {
            case ServerMessage.ConnectionID:
                reader.SaveConnectionID(stream.ReadInt());
                break;

            case ServerMessage.Ping:
                SendPing(reader.m_Driver, reader.m_Connection);
                break;

            //case ServerMessage.Disconnection:
            //    reader.Disconnect((DisconnectionReason)stream.ReadByte());
            //break;
            case ServerMessage.GameStart:
                reader.GameStart(stream.ReadInt());
                break;

            case ServerMessage.GameOver:
                reader.GameOver(ref stream);
                break;

            case ServerMessage.TurnStart:
                reader.TurnStart();
                break;

            case ServerMessage.TurnEnd:
                reader.TurnEnd();
                break;

            case ServerMessage.ScoreUpdate:
                int score = (int)stream.ReadFloat();
                reader.ScoreUpdate(score);
                break;

            case ServerMessage.PlayerPositions:
                reader.UpdatePlayerPositions(ExtractVector3List(ref stream));
                break;

            case ServerMessage.PlayerRotations:
                reader.UpdatePlayerRotations(ExtractVector3List(ref stream));
                break;

            case ServerMessage.ProjectilePositions:
                reader.UpdateProjectilePositions(ExtractVector3List(ref stream));
                break;

            case ServerMessage.PlayerTakesDamage:
                reader.PlayerTakesDamage(ref stream);
                break;

            default:
                break;
            }
        }
Esempio n. 16
0
    PackageMetadata ReadPackageMetadata(DataStreamReader reader)
    {
        DataStreamReader.Context readerCtx = default(DataStreamReader.Context);
        int command = reader.ReadInt(ref readerCtx);
        int id      = reader.ReadInt(ref readerCtx);

        return(new PackageMetadata(command, id));
    }
Esempio n. 17
0
 public void Deserialize(ref DataStreamReader reader)
 {
     skillId     = reader.ReadShort();
     skill2Id    = reader.ReadShort();
     skill3Id    = reader.ReadShort();
     skill4Id    = reader.ReadShort();
     characterId = (uint)reader.ReadInt();
     skinId      = (uint)reader.ReadInt();
     userId      = reader.ReadString();
 }
Esempio n. 18
0
 public void Deserialize(uint tick, DataStreamReader reader, ref DataStreamReader.Context ctx)
 {
     this.tick     = tick;
     checkTick     = reader.ReadInt(ref ctx);
     renderTick    = reader.ReadInt(ref ctx);
     moveYaw       = 0.1f * reader.ReadInt(ref ctx);
     moveMagnitude = 0.01f * reader.ReadInt(ref ctx);
     buttons.flags = reader.ReadUInt(ref ctx);
     lookYaw       = reader.ReadFloat(ref ctx);
     lookPitch     = reader.ReadFloat(ref ctx);
 }
Esempio n. 19
0
    public override void Read(int connectionId, DataStreamReader stream, ref DataStreamReader.Context context)
    {
        var prefabId    = stream.ReadInt(ref context);
        var ownershipId = stream.ReadInt(ref context);
        var instanceId  = stream.ReadInt(ref context);

        Debug.Log($"Spawn: {prefabId} Instance ID: {instanceId}");

        var client = GetComponentInParent <ClientBehaviour>();

        Spawner.SpawnInClient(prefabId, instanceId, ownershipId, client);
    }
Esempio n. 20
0
    public void Deserialize(uint tick, ref DataStreamReader reader)
    {
        this.tick = tick;

        movement.x = reader.ReadInt() / 100f;
        movement.y = reader.ReadInt() / 100f;
        jumping    = (reader.ReadInt() > 0);

        head.Deserialize(ref reader, 10000);
        leftHand.Deserialize(ref reader, 1000);
        rightHand.Deserialize(ref reader, 1000);
    }
    public override void Read(int connectionId, DataStreamReader stream, ref DataStreamReader.Context context)
    {
        var client = GetComponentInParent <ClientBehaviour>();
        var length = stream.ReadInt(ref context);

        for (int i = 0; i < length; i++)
        {
            var prefabId   = stream.ReadInt(ref context);
            var instanceId = stream.ReadInt(ref context);

            GhostCollection.NewInClient(prefabId, instanceId, (int)EOwnershipType.Server, client);
        }
    }
    public override void ReadPacket(DataStreamReader stream)
    {
        int attackingPlayerID = stream.ReadInt();

        if (attackingPlayerID == whoseTurn.Value)
        {
            int actionCount = stream.ReadInt();
            for (int i = 0; i < actionCount; i++)
            {
                int actionIndex = stream.ReadInt();
                queuedActions.Add(allActions.Items[actionIndex]);
            }
            takeAction.Value = true;
        }
    }
    public override void ReadPacket(DataStreamReader stream)
    {
        int selectorPlayerID  = stream.ReadInt();
        int selectedCharacter = stream.ReadInt();

        if (selectorPlayerID == 0)
        {
            p0PlayerCharacterID.Value = selectedCharacter;
        }
        else if (selectorPlayerID == 1)
        {
            p1PlayerCharacterID.Value = selectedCharacter;
        }
        serverToClientQueue.Add(reactionEvent);
    }
    public override void ReadPacket(DataStreamReader stream)
    {
        int playerID = stream.ReadInt();
        int userID   = stream.ReadInt();

        if (playerID == 0)
        {
            p0UserID.Value = userID;
        }
        else if (playerID == 1)
        {
            p1UserID.Value = userID;
        }
        serverToClientQueue.Add(updateUserIDEvent);
    }
Esempio n. 25
0
        protected override FileTransporter RecieveStart(int hash, DataStreamReader stream, ref DataStreamReader.Context ctx)
        {
            if (string.IsNullOrEmpty(SaveDirectory))
            {
                SaveDirectory = Application.persistentDataPath + "/RecieveFile";
                System.IO.Directory.CreateDirectory(SaveDirectory);
            }

            string fileName = stream.ReadString(ref ctx);
            int    fileSize = stream.ReadInt(ref ctx);
            ushort dataSize = stream.ReadUShort(ref ctx);

            string     path = SaveDirectory + "/" + hash + "_" + fileName;
            FileStream fs   = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);

            var transporter = new FileTransporter(hash, fileName, fs, 8092, 8092);

            unsafe
            {
                fixed(byte *data = transporter.buffer)
                {
                    stream.ReadBytes(ref ctx, data, dataSize);
                    transporter.bufferPos += dataSize;
                }
            }
            return(transporter);
        }
Esempio n. 26
0
        public override void DeserializeObject(ref DataStreamReader reader)
        {
            base.DeserializeObject(ref reader);

            PlayerID     = reader.ReadInt();
            PlayerColour = reader.ReadUInt();
        }
Esempio n. 27
0
        public static void Read(ServerBehaviour reader, int connectionID, DataStreamReader stream)
        {
            ClientMessage clientMessageType = (ClientMessage)stream.ReadByte();

            //Debug.Log(reader.name + " got message of type " + clientMessageType.ToString());

            switch (clientMessageType)
            {
            case ClientMessage.Pong:
                reader.ReadPong(connectionID);
                break;

            case ClientMessage.PlayerReady:
                reader.PlayerReady(connectionID);
                break;

            case ClientMessage.MovementInput:
                reader.ReadMovementInput(ExtractVector2(ref stream), connectionID);
                break;

            //case ClientMessage.ShootInput:
            //    reader.ShootInput(connectionID, Convert.ToBoolean(stream.ReadByte()));
            //    break;
            case ClientMessage.PlayerID:
                int val = stream.ReadInt();
                reader.AssignPlayerIDToConnection(connectionID, val);
                break;

            default:
                break;
            }
        }
Esempio n. 28
0
        public void ReadRow(DataStreamReader dataR, int[] filedIndex)
        {
          //var schemeNames = dataR.GetSchemeName();
          int col = 0;
          while(true)
          {
            col = dataR.MoreFieldOnRow();
            if (col == -1)
            {
              break;
            }
            switch (filedIndex[col])
            { 
            
                case 0:
                    m_Id = dataR.ReadInt();
                    break;
                case 1:
                    m_Process = dataR.ReadString();
                    break;
                default:
                    //TableHelper.CacheNewField(dataR, schemeNames[col], m_DataCacheNoGenerate);
                    break;
            }
          }

        }
Esempio n. 29
0
        public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var entities     = chunk.GetNativeArray(entityType);
            var bufferAccess = chunk.GetBufferAccessor(bufferType);

            for (int i = 0; i < bufferAccess.Length; ++i)
            {
                var dynArray            = bufferAccess[i];
                DataStreamReader reader = DataStreamUnsafeUtility.CreateReaderFromExistingData((byte *)dynArray.GetUnsafePtr(), dynArray.Length);
                var ctx = default(DataStreamReader.Context);
                while (reader.GetBytesRead(ref ctx) < reader.Length)
                {
                    int type = reader.ReadInt(ref ctx);
                    if (type < internalRpcCollectionLength)
                    {
                        internalRpcCollection.ExecuteRpc(type, reader, ref ctx, entities[i], commandBuffer, chunkIndex);
                    }
                    else
                    {
                        rpcCollection.ExecuteRpc(type - internalRpcCollectionLength, reader, ref ctx, entities[i], commandBuffer, chunkIndex);
                    }
                }

                dynArray.Clear();
            }
        }
    public override void DeserializeObject(ref DataStreamReader reader)
    {
        base.DeserializeObject(ref reader);

        PlayerID = reader.ReadInt();
        newHP    = reader.ReadUShort();
    }