Exemple #1
0
        public BufferFrame Clone()
        {
            BufferFrame newBufferFrame = new BufferFrame(bufferArray.Length, this.mode);

            for (int j = 0; j < bufferArray.Length; j++)
            {
                newBufferFrame.bufferArray[j] = bufferArray[j];
            }

            newBufferFrame.stackedFrames = stackedFrames;

            newBufferFrame.time = time;

            newBufferFrame.transitionTime = transitionTime;

            return(newBufferFrame);
        }
Exemple #2
0
        public void LoadData(BinaryReader reader, bool accrue = false)
        {
            if (!accrue)
            {
                transitions = reader.ReadUInt32();

                long bufferFramesArrayLength = reader.ReadUInt32();

                if (bufferFramesArrayLength > 0)
                {
                    long bufferFramesLength = reader.ReadUInt32();

                    for (int i = 0; i < bufferFramesArrayLength; i++)
                    {
                        bufferFramesArray.Add(new BufferFrame(bufferFramesLength, BinDataMode.Indeterminate));
                        bufferFramesArray[bufferFramesArray.Count - 1].LoadData(reader);
                    }

                    currentBufferIndex = bufferFramesArray.Count - 1;
                    startBufferIndex   = 0;
                }


                long currentBufferFramesArrayLength = reader.ReadUInt32();

                if (currentBufferFramesArrayLength > 0)
                {
                    long currentBufferFramesLength = reader.ReadUInt32();

                    for (int i = 0; i < currentBufferFramesArrayLength; i++)
                    {
                        currentTransitionBufferFramesArray.Add(new BufferFrame(currentBufferFramesLength, BinDataMode.Indeterminate));
                        currentTransitionBufferFramesArray[currentTransitionBufferFramesArray.Count - 1].LoadData(reader);
                    }
                }

                long gradientArrayLength = reader.ReadUInt32();

                if (gradientArrayLength > 0)
                {
                    long gradientsLength = reader.ReadUInt32();

                    for (int i = 0; i < gradientArrayLength; i++)
                    {
                        gradients.Add(new GradientArray(gradientsLength));
                        gradients[gradients.Count - 1].LoadData(reader);
                    }
                }
            }
            else
            {
                uint newTransitions = reader.ReadUInt32();

                long bufferFramesArrayLength = reader.ReadUInt32();

                if (bufferFramesArrayLength > 0)
                {
                    long bufferFramesLength = reader.ReadUInt32();

                    BufferFrame bufferFrame;

                    for (int i = 0; i < bufferFramesArrayLength; i++)
                    {
                        ////bufferFramesArray.Add(new BufferFrame(bufferFramesLength, BinDataMode.Indeterminate));
                        ////bufferFramesArray[bufferFramesArray.Count - 1].LoadData(reader);

                        bufferFrame = new BufferFrame(bufferFramesLength, BinDataMode.Indeterminate);

                        bufferFrame.LoadData(reader);

                        AddTransitionBufferFrame(bufferFrame, bufferFrame.transitionTime, i);
                    }

                    currentBufferIndex = bufferFramesArray.Count - 1;
                    startBufferIndex   = 0;
                }

                transitions += newTransitions;


                currentTransitionBufferFramesArray.Clear();

                long currentBufferFramesArrayLength = reader.ReadUInt32();

                if (currentBufferFramesArrayLength > 0)
                {
                    long currentBufferFramesLength = reader.ReadUInt32();

                    for (int i = 0; i < currentBufferFramesArrayLength; i++)
                    {
                        currentTransitionBufferFramesArray.Add(new BufferFrame(currentBufferFramesLength, BinDataMode.Indeterminate));
                        currentTransitionBufferFramesArray[currentTransitionBufferFramesArray.Count - 1].LoadData(reader);
                    }
                }

                long gradientArrayLength = reader.ReadUInt32();

                if (gradientArrayLength > 0)
                {
                    long gradientsLength = reader.ReadUInt32();

                    for (int i = 0; i < gradientArrayLength; i++)
                    {
                        gradients.Add(new GradientArray(gradientsLength));
                        gradients[gradients.Count - 1].LoadData(reader);
                    }
                }
            }
        }
Exemple #3
0
        public void AddTransitionBufferFrame(BufferFrame bufferFrame, long transitionTime, long index)
        {
            bufferFrame.transitionTime = transitionTime;

            if (bufferFrame.mode == BinDataMode.Indeterminate || bufferFrame.mode == BinDataMode.NotUsed)
            {
                return;
            }

            if (index >= currentTransitionBufferFramesArray.Count)
            {
                currentTransitionBufferFramesArray.Add(bufferFrame.Clone());
            }
            else
            {
                for (int i = 0; i < currentTransitionBufferFramesArray[(int)index].bufferArray.Length; i++)
                {
                    currentTransitionBufferFramesArray[(int)index].bufferArray[i] = bufferFrame.bufferArray[i];
                }
            }

            if (transitions == 0)
            {
                bufferFramesArray.Add(bufferFrame.Clone());

                minFrameIndex = bufferFramesArray.Count;

                currentBufferIndex = (int)minFrameIndex - 1;
            }
            else
            {
                long startTransitionTime = bufferFramesArray[0].time;

                long minTimeDifference = -1, dif, minIndex = -1;

                for (int i = 0; i < bufferFramesArray.Count; i++)
                {
                    dif = Math.Abs(transitionTime - (bufferFramesArray[i].time - startTransitionTime));

                    if (minTimeDifference == -1 || dif < minTimeDifference)
                    {
                        minTimeDifference = dif;

                        minIndex = i;
                    }
                }

                if (minIndex < 0 || (minIndex == bufferFramesArray.Count - 1 && bufferFramesArray[(int)minIndex].stackedFrames >= bufferFramesArray[(int)minIndex - 1].stackedFrames))
                {
                    bufferFramesArray.Add(bufferFrame.Clone());
                }
                else
                {
                    bufferFramesArray[(int)minIndex].stackedFrames++;

                    for (int i = 0; i < bufferFramesArray[(int)minIndex].bufferArray.Length; i++)
                    {
                        bufferFramesArray[(int)minIndex].bufferArray[i] += bufferFrame.bufferArray[i];
                    }
                }
            }
        }