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; } } }
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) ); }
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); }
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); }
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"); } }
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"); } }