Пример #1
0
    public void ProcessStateUpdatePacket(byte[] packetData, int fromClientIndex)
    {
        int readNumAvatarStates = 0;
        int readNumStateUpdates = 0;

        Context.ConnectionData connectionData = context.GetServerConnectionData(fromClientIndex);

        Network.PacketHeader readPacketHeader;

        if (ReadStateUpdatePacket(packetData, out readPacketHeader, out readNumAvatarStates, ref readAvatarStateQuantized, out readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineSequence, ref readCubeState, ref readCubeDelta, ref readPredictionDelta))
        {
            // unquantize avatar states

            for (int i = 0; i < readNumAvatarStates; ++i)
            {
                AvatarState.Unquantize(ref readAvatarStateQuantized[i], out readAvatarState[i]);
            }

            // ignore any updates from a client with a different reset sequence #

            if (context.GetResetSequence() != readPacketHeader.resetSequence)
            {
                return;
            }

            // decode the predicted cube states from baselines

            DecodePrediction(connectionData.receiveDeltaBuffer, readPacketHeader.sequence, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineSequence, ref readCubeState, ref readPredictionDelta);

            // decode the not changed and delta cube states from baselines

            DecodeNotChangedAndDeltas(connectionData.receiveDeltaBuffer, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readBaselineSequence, ref readCubeState, ref readCubeDelta);

            // add the cube states to the receive delta buffer

            AddPacketToDeltaBuffer(ref connectionData.receiveDeltaBuffer, readPacketHeader.sequence, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readCubeState);

            // apply the state updates to cubes

            context.ApplyCubeStateUpdates(readNumStateUpdates, ref readCubeIds, ref readCubeState, fromClientIndex, 0, enableJitterBuffer);

            // apply avatar state updates

            context.ApplyAvatarStateUpdates(readNumAvatarStates, ref readAvatarState, fromClientIndex, 0);

            // process the packet header

            connectionData.connection.ProcessPacketHeader(ref readPacketHeader);
        }
    }
    public bool AddStateUpdatePacket(byte[] packetData, DeltaBuffer receiveDeltaBuffer, ushort resetSequence, out long packetFrameNumber)
    {
        Network.PacketHeader packetHeader;
        ReadStateUpdatePacketHeader(packetData, out packetHeader);

        packetFrameNumber = packetHeader.frameNumber;

        int entryIndex = sequenceBuffer.Insert(packetHeader.frameNumber);

        if (entryIndex < 0)
        {
            return(false);
        }

        bool result = true;

        Profiler.BeginSample("ProcessStateUpdatePacket");

        JitterBufferEntry entry = sequenceBuffer.Entries[entryIndex];

        if (ReadStateUpdatePacket(packetData, out entry.packetHeader, out entry.numAvatarStates, ref entry.avatarStateQuantized, out entry.numStateUpdates, ref entry.cubeIds, ref entry.notChanged, ref entry.hasDelta, ref entry.perfectPrediction, ref entry.hasPredictionDelta, ref entry.baselineSequence, ref entry.cubeState, ref entry.cubeDelta, ref entry.predictionDelta))
        {
            for (int i = 0; i < entry.numAvatarStates; ++i)
            {
                AvatarState.Unquantize(ref entry.avatarStateQuantized[i], out entry.avatarState[i]);
            }

            DecodePrediction(receiveDeltaBuffer, resetSequence, entry.packetHeader.sequence, entry.numStateUpdates, ref entry.cubeIds, ref entry.perfectPrediction, ref entry.hasPredictionDelta, ref entry.baselineSequence, ref entry.cubeState, ref entry.predictionDelta);

            DecodeNotChangedAndDeltas(receiveDeltaBuffer, resetSequence, entry.numStateUpdates, ref entry.cubeIds, ref entry.notChanged, ref entry.hasDelta, ref entry.baselineSequence, ref entry.cubeState, ref entry.cubeDelta);
        }
        else
        {
            sequenceBuffer.Remove(packetHeader.frameNumber);

            result = false;
        }

        Profiler.EndSample();

        return(result);
    }
    public bool AddUpdatePacket(byte[] packet, DeltaBuffer receiveBuffer, ushort resetId, out long frame)
    {
        PacketHeader header;

        ReadUpdateHeader(packet, out header);
        frame = header.frame;
        int entryId = buffer.Insert(header.frame);

        if (entryId < 0)
        {
            return(false);
        }

        var result = true;

        Profiler.BeginSample("ProcessStateUpdatePacket");
        var e = buffer.entries[entryId];

        if (ReadUpdatePacket(packet, out e.header, out e.avatarCount, ref e.avatarsQuantized, out e.cubeCount, ref e.cubeIds, ref e.notChanged, ref e.hasDelta, ref e.hasPerfectPrediction, ref e.hasPrediction, ref e.baselineIds, ref e.cubes, ref e.deltas, ref e.predictions)
            )
        {
            for (int i = 0; i < e.avatarCount; ++i)
            {
                AvatarState.Unquantize(ref e.avatarsQuantized[i], out e.avatars[i]);
            }

            DecodePrediction(receiveBuffer, resetId, e.header.id, e.cubeCount, ref e.cubeIds, ref e.hasPerfectPrediction, ref e.hasPrediction, ref e.baselineIds, ref e.cubes, ref e.predictions);
            DecodeNotChangedAndDeltas(receiveBuffer, resetId, e.cubeCount, ref e.cubeIds, ref e.notChanged, ref e.hasDelta, ref e.baselineIds, ref e.cubes, ref e.deltas);
        }
        else
        {
            buffer.Remove(header.frame);
            result = false;
        }
        Profiler.EndSample();

        return(result);
    }
Пример #4
0
    public void ProcessStateUpdatePacket(Context.NetworkData data, byte[] packet)
    {
        Profiler.BeginSample("ProcessStateUpdatePacket");
        int          avatarCount = 0;
        int          cubeCount   = 0;
        PacketHeader header;

        if (ReadUpdatePacket(packet, out header, out avatarCount, ref readAvatarsQuantized, out cubeCount, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineIds, ref readCubes, ref readCubeDeltas, ref readPredictionDeltas)
            )
        {
            for (int i = 0; i < avatarCount; ++i) //unquantize avatar states
            {
                AvatarState.Unquantize(ref readAvatarsQuantized[i], out readAvatars[i]);
            }

            if (Util.IdGreaterThan(context.resetId, header.resetId))
            {
                return;                                              //ignore updates from before the last server reset
            }
            if (Util.IdGreaterThan(header.resetId, context.resetId)) //reset if the server reset sequence is more recent than ours
            {
                context.Reset();
                context.resetId = header.resetId;
            }

            DecodePrediction(data.receiveBuffer, header.id, context.resetId, cubeCount, ref readCubeIds, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineIds, ref readCubes, ref readPredictionDeltas); //decode the predicted cube states from baselines
            DecodeNotChangedAndDeltas(data.receiveBuffer, context.resetId, cubeCount, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readBaselineIds, ref readCubes, ref readCubeDeltas);                          //decode the not changed and delta cube states from baselines
            AddPacketToDeltaBuffer(ref data.receiveBuffer, header.id, context.resetId, cubeCount, ref readCubeIds, ref readCubes);                                                                                             //add the cube states to the receive delta buffer

            int fromClientId = 0;                                                                                                                                                                                              //apply the state updates to cubes
            int toClientId   = clientId;
            context.ApplyCubeUpdates(cubeCount, ref readCubeIds, ref readCubes, fromClientId, toClientId, isJitterBufferEnabled && renderTime > timeConnected + 0.25);
            context.ApplyAvatarUpdates(avatarCount, ref readAvatars, fromClientId, toClientId); //apply avatar state updates
            data.acking.AckPackets(ref header);                                                 //process the packet header
        }
        Profiler.EndSample();
    }
    public void ProcessStateUpdatePacket(Context context, Context.NetworkData connectionData, byte[] packetData, int fromClientIndex, int toClientIndex)
    {
        Profiler.BeginSample("ProcessStateUpdatePacket");

        int readNumAvatarStates = 0;
        int readNumStateUpdates = 0;

        Network.PacketHeader readPacketHeader;

        if (ReadUpdatePacket(packetData, out readPacketHeader, out readNumAvatarStates, ref readAvatarsQuantized, out readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineIds, ref readCubes, ref readCubeDeltas, ref readPredictionDeltas))
        {
            // unquantize avatar states

            for (int i = 0; i < readNumAvatarStates; ++i)
            {
                AvatarState.Unquantize(ref readAvatarsQuantized[i], out readAvatars[i]);
            }

            // reset sequence handling

            if (fromClientIndex == 0)
            {
                // server -> client

                // Ignore updates from before the last reset.
                if (Network.Util.IdGreaterThan(context.resetId, readPacketHeader.resetId))
                {
                    return;
                }

                // Reset if the server reset sequence is more recent than ours.
                if (Network.Util.IdGreaterThan(readPacketHeader.resetId, context.resetId))
                {
                    context.Reset();
                    context.resetId = readPacketHeader.resetId;
                }
            }
            else
            {
                // server -> client

                // Ignore any updates from the client with a different reset sequence #
                if (context.resetId != readPacketHeader.resetId)
                {
                    return;
                }
            }

            // decode the predicted cube states from baselines

            DecodePrediction(connectionData.receiveBuffer, context.resetId, readPacketHeader.id, readNumStateUpdates, ref readCubeIds, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineIds, ref readCubes, ref readPredictionDeltas);

            // decode the not changed and delta cube states from baselines

            DecodeNotChangedAndDeltas(connectionData.receiveBuffer, context.resetId, readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readBaselineIds, ref readCubes, ref readCubeDeltas);

            // add the cube states to the receive delta buffer

            AddPacketToDeltaBuffer(ref connectionData.receiveBuffer, readPacketHeader.id, context.resetId, readNumStateUpdates, ref readCubeIds, ref readCubes);

            // apply the state updates to cubes

            context.ApplyCubeUpdates(readNumStateUpdates, ref readCubeIds, ref readCubes, fromClientIndex, toClientIndex, isJitterBufferEnabled);

            // apply avatar state updates

            context.ApplyAvatarUpdates(readNumAvatarStates, ref readAvatars, fromClientIndex, toClientIndex);

            // process the packet header

            connectionData.acking.AckPackets(ref readPacketHeader);
        }

        Profiler.EndSample();
    }
Пример #6
0
    public void ProcessStateUpdatePacket(Context.ConnectionData connectionData, byte[] packetData)
    {
        Profiler.BeginSample("ProcessStateUpdatePacket");

        int readNumAvatarStates = 0;
        int readNumStateUpdates = 0;

        Network.PacketHeader readPacketHeader;

        if (ReadStateUpdatePacket(packetData, out readPacketHeader, out readNumAvatarStates, ref readAvatarStateQuantized, out readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineSequence, ref readCubeState, ref readCubeDelta, ref readPredictionDelta))
        {
            // unquantize avatar states

            for (int i = 0; i < readNumAvatarStates; ++i)
            {
                AvatarState.Unquantize(ref readAvatarStateQuantized[i], out readAvatarState[i]);
            }

            // ignore updates from before the last server reset

            if (Network.Util.SequenceGreaterThan(context.GetResetSequence(), readPacketHeader.resetSequence))
            {
                return;
            }

            // reset if the server reset sequence is more recent than ours

            if (Network.Util.SequenceGreaterThan(readPacketHeader.resetSequence, context.GetResetSequence()))
            {
                context.Reset();
                context.SetResetSequence(readPacketHeader.resetSequence);
            }

            // decode the predicted cube states from baselines

            DecodePrediction(connectionData.receiveDeltaBuffer, readPacketHeader.sequence, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readPerfectPrediction, ref readHasPredictionDelta, ref readBaselineSequence, ref readCubeState, ref readPredictionDelta);

            // decode the not changed and delta cube states from baselines

            DecodeNotChangedAndDeltas(connectionData.receiveDeltaBuffer, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readNotChanged, ref readHasDelta, ref readBaselineSequence, ref readCubeState, ref readCubeDelta);

            // add the cube states to the receive delta buffer

            AddPacketToDeltaBuffer(ref connectionData.receiveDeltaBuffer, readPacketHeader.sequence, context.GetResetSequence(), readNumStateUpdates, ref readCubeIds, ref readCubeState);

            // apply the state updates to cubes

            int fromClientIndex = 0;
            int toClientIndex   = clientIndex;

            context.ApplyCubeStateUpdates(readNumStateUpdates, ref readCubeIds, ref readCubeState, fromClientIndex, toClientIndex, enableJitterBuffer && renderTime > timeConnected + 0.25);

            // apply avatar state updates

            context.ApplyAvatarStateUpdates(readNumAvatarStates, ref readAvatarState, fromClientIndex, toClientIndex);

            // process the packet header

            connectionData.connection.ProcessPacketHeader(ref readPacketHeader);
        }

        Profiler.EndSample();
    }