Exemplo n.º 1
0
        public override void Update()
        {
            //Constantly adjust the interpolation play speed,
            //so there is always one sample in the buffer
            float playSpeed = stateBuffer.Count * 0.5f;

            //Increment the interpolation timeline
            interpolationTime += Time.unscaledDeltaTime * playSpeed;
            interpolationTime  = Mathf.Clamp(interpolationTime, 0f, sampleInterval * 3f);

            //Read from the state buffer until the interpolation timeline is caught up with real time
            while ((stateBuffer.Count > 0) && (interpolationTime > sampleInterval))
            {
                prevState.fillEncoding(currentState.data);
                currentState.fillEncoding(stateBuffer.Dequeue());
                interpolationTime -= sampleInterval;
            }

            //Interpolate the real samples according to the interpolation timeline
            lerpState.lerp(prevState, currentState, interpolationTime / sampleInterval);

            //if (RealtimeGraph.Instance != null) { RealtimeGraph.Instance.AddSample("InterpolationAlpha", RealtimeGraph.GraphUnits.Miliseconds, (prevState.RPos == currentState.RPos) ? 10f : 0f); }

            //Decode the interpolated state and send it off
            fillCurrentFrame(lerpState);
            DispatchUpdateFrameEvent(CurrentFrame);
        }
Exemplo n.º 2
0
        void Play()
        {
            //If we have reached the end of our playBackBuffer or the file...
            if (currentBufferTime >= (float)((playBackBuffer.Length / frameSize) - 1) / fps || currentFileTime >= (float)(((fileLength - headerLength) / frameSize) - 1) / fps)
            {
                readNextChunk();
            }
            int startFrame; float alpha;

            bufferTimeToFramesandAlpha(currentBufferTime, out startFrame, out alpha);

            Array.Copy(playBackBuffer, startFrame * frameSize, beginInterpolate.data, 0, frameSize);
            beginInterpolate.fillEncoding(beginInterpolate.data);
            Array.Copy(playBackBuffer, (startFrame + 1) * frameSize, endInterpolate.data, 0, frameSize);
            endInterpolate.fillEncoding(endInterpolate.data);

            playerState.lerp(beginInterpolate, endInterpolate, alpha);

            currentBufferTime += Time.deltaTime / 100f;
            currentFileTime   += Time.deltaTime / 100f;
            AddFrameState(playerState);
        }