private new MappedSegment Next(int length) { var index = RunningIndex; var segment = new MappedSegment(manager.Cursor, manager.Segment.Next(length)) { RunningIndex = index + manager.Segment.Length, }; base.Next = segment; return(segment); }
public unsafe MappedSegment(MappedSegment <TFrom, TTo> previous, Block <TFrom> underlying) : base(CreateMapped(underlying, out void *origin), previous) { Origin = origin; Underlying = underlying; #if DEBUG _byteCount = underlying.Length * Unsafe.SizeOf <TFrom>(); if (previous != null) { // we can't use "underlying" for this, because of padding etc ByteOffset = previous.ByteOffset + previous._byteCount; } #endif }
private void ProcessRemap(TextureRemap remap) { // Find the original MappedSegment MappedSegment originalSegment = FindSegmentFromTilePosition(remap.OriginalTile, remap.OriginalBounds); // Find the candiate MappedSegment MappedSegment candidateSegment = FindSegmentFromTilePosition(remap.NewTile, remap.NewBounds /*, false*/); // Move it! if (originalSegment != null && candidateSegment != null) { // Move it! ProcessRemap(originalSegment, candidateSegment, remap.AdjustmentPoint); } else { System.Diagnostics.Debug.WriteLine("Could not remap " + remap.OriginalTile + " : " + remap.OriginalIndex); } }
private void ProcessRemap(MappedSegment originalSegment, MappedSegment candidateSegment, Point adjustmentPoint) { Rectangle oldBounds = originalSegment.Segment.Bounds; // We pull all of the sub textures from the original segment into the candidate int oldFirstTextureIndex = originalSegment.Segment.FirstTextureIndex; candidateSegment.Segment.InheritTextures(originalSegment.Segment, adjustmentPoint, candidateSegment.Tile.Index); // Store the removal for later processing in RemoveStaleSegments StoreSegmentRemoval(originalSegment); SegmentRemapped?.Invoke(this, new TRTextureRemapEventArgs { OldFirstTextureIndex = oldFirstTextureIndex, OldArea = originalSegment.Segment.Area, NewSegment = candidateSegment.Segment, OldTile = originalSegment.Tile, NewTile = candidateSegment.Tile, OldBounds = oldBounds, NewBounds = candidateSegment.Segment.Bounds, AdjustmentPoint = adjustmentPoint }); }
private Point?LocateSubSegment(MappedSegment segmentToLocate, MappedSegment containerSegment) { int xEnd = containerSegment.Segment.Bounds.Width - segmentToLocate.Segment.Bounds.Width; int yEnd = containerSegment.Segment.Bounds.Height - segmentToLocate.Segment.Bounds.Height; Rectangle rect = new Rectangle(0, 0, segmentToLocate.Segment.Bounds.Width, segmentToLocate.Segment.Bounds.Height); for (int x = 0; x <= xEnd; x++) { rect.X = x; for (int y = 0; y <= yEnd; y++) { rect.Y = y; using (Bitmap bmp = containerSegment.Segment.Bitmap.Clone(rect, PixelFormat.Format32bppArgb)) { if (CompareBitmaps(segmentToLocate.Segment.Bitmap, bmp)) { return(new Point(x, y)); } } } } return(null); }
private void PrepareSegments() { if(segments != null) { // this is because in case of loading the starting memory snapshot // after deserialization (i.e. resetting after deserialization) // memory segments would have been lost return; } // how many segments we need? var segmentsNo = size / SegmentSize + (size % SegmentSize != 0 ? 1 : 0); this.NoisyLog(string.Format("Preparing {0} segments for {1} bytes of memory, each {2} bytes long.", segmentsNo, size, SegmentSize)); segments = new IntPtr[segmentsNo]; originalPointers = new IntPtr[segmentsNo]; // segments are not allocated until they are used by read, write, load etc (or touched) describedSegments = new IMappedSegment[segmentsNo]; for(var i = 0; i < describedSegments.Length - 1; i++) { describedSegments[i] = new MappedSegment(this, i, (uint)SegmentSize); } var last = describedSegments.Length - 1; var sizeOfLast = size % (uint)SegmentSize; if(sizeOfLast == 0) { sizeOfLast = (uint)SegmentSize; } describedSegments[last] = new MappedSegment(this, last, sizeOfLast); }