예제 #1
0
            public void InsertAtFront(ref CachedBatch item, int?previousIndex)
            {
                // No-op
                if (previousIndex == 0)
                {
                    return;
                }
                else if (Count == 0)
                {
                    SetItemAtIndex(0, ref item);
                    Count += 1;
                    return;
                }

                // Move items back to create space for the item at the front
                int writePosition;

                if (Count == Capacity)
                {
                    writePosition = Capacity - 1;
                }
                else
                {
                    writePosition = Count;
                }

                for (int i = writePosition - 1; i >= 0; i--)
                {
                    // If the item is being moved from its position to the front, make sure we don't also move it back
                    if (i == previousIndex)
                    {
                        continue;
                    }

                    CachedBatch temp;
                    GetItemAtIndex(i, out temp);
                    SetItemAtIndex(writePosition, ref temp);
                    writePosition -= 1;
                }

                SetItemAtIndex(0, ref item);

                if (!previousIndex.HasValue)
                {
                    if (Count < Capacity)
                    {
                        Count += 1;
                    }
                }
            }
예제 #2
0
 public bool KeysEqual(ref CachedBatch rhs)
 {
     return(
         (BatchType == rhs.BatchType) &&
         (Container == rhs.Container) &&
         (Layer == rhs.Layer) &&
         (WorldSpace == rhs.WorldSpace) &&
         (BlendState == rhs.BlendState) &&
         (SamplerState == rhs.SamplerState) &&
         (UseZBuffer == rhs.UseZBuffer) &&
         (RasterizerState == rhs.RasterizerState) &&
         (DepthStencilState == rhs.DepthStencilState)
         );
 }
예제 #3
0
            public bool TryGet <T> (
                out CachedBatch result,
                CachedBatchType cbt,
                IBatchContainer container,
                int layer,
                bool worldSpace,
                RasterizerState rasterizerState,
                DepthStencilState depthStencilState,
                BlendState blendState,
                SamplerState samplerState,
                Material customMaterial,
                bool useZBuffer
                )
            {
                CachedBatch itemAtIndex, searchKey;

                searchKey = new CachedBatch(
                    cbt,
                    container,
                    layer,
                    worldSpace,
                    rasterizerState,
                    depthStencilState,
                    blendState,
                    samplerState,
                    customMaterial,
                    useZBuffer
                    );

                for (var i = 0; i < Count; i++)
                {
                    GetItemAtIndex(i, out itemAtIndex);

                    if (itemAtIndex.HashCode != searchKey.HashCode)
                    {
                        continue;
                    }

                    if (itemAtIndex.KeysEqual(ref searchKey))
                    {
                        result = itemAtIndex;
                        InsertAtFront(ref itemAtIndex, i);
                        return(result.Batch != null);
                    }
                }

                result = searchKey;
                return(false);
            }
예제 #4
0
            public bool KeysEqual(ref CachedBatch rhs)
            {
                var result = (
                    (BatchType == rhs.BatchType) &&
                    (Container == rhs.Container) &&
                    (Layer == rhs.Layer) &&
                    (WorldSpace == rhs.WorldSpace) &&
                    (BlendState == rhs.BlendState) &&
                    (UseZBuffer == rhs.UseZBuffer) &&
                    (RasterizerState == rhs.RasterizerState) &&
                    (DepthStencilState == rhs.DepthStencilState) &&
                    (CustomMaterial == rhs.CustomMaterial)
                    );

                return(result);
            }
예제 #5
0
            private void SetItemAtIndex(int index, ref CachedBatch value)
            {
                switch (index)
                {
                case 0:
                    Batch0 = value;
                    break;

                case 1:
                    Batch1 = value;
                    break;

                case 2:
                    Batch2 = value;
                    break;

                case 3:
                    Batch3 = value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("index");
                }
            }
예제 #6
0
            private void GetItemAtIndex(int index, out CachedBatch result)
            {
                switch (index)
                {
                case 0:
                    result = Batch0;
                    break;

                case 1:
                    result = Batch1;
                    break;

                case 2:
                    result = Batch2;
                    break;

                case 3:
                    result = Batch3;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("index");
                }
            }