コード例 #1
0
 internal SpriteDefinition(SpriteSheet spriteSheet, string name, RectangleInt rectangle, Vector? origin)
 {
     this.SpriteSheet = spriteSheet;
     this.Name = name;
     this.Rectangle = rectangle;
     this.Origin = origin.HasValue ? origin.Value : Vector.Zero;
 }
コード例 #2
0
		public override void CopyBackBufferToScreen(Graphics displayGraphics)
		{
			WidgetForWindowsFormsBitmap aggBitmapAppWidget = ((WidgetForWindowsFormsBitmap)aggAppWidget);

			RectangleInt intRect = new RectangleInt(0, 0, (int)aggAppWidget.Width, (int)aggAppWidget.Height);
			aggBitmapAppWidget.bitmapBackBuffer.UpdateHardwareSurface(intRect);

			if (OsInformation.OperatingSystem != OSType.Windows)
			{
				//displayGraphics.DrawImage(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap, windowsRect, windowsRect, GraphicsUnit.Pixel);  // around 250 ms for full screen
				displayGraphics.DrawImageUnscaled(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap, 0, 0); // around 200 ms for full screnn
			}
			else
			{
				// or the code below which calls BitBlt directly running at 17 ms for full screnn.
				const int SRCCOPY = 0xcc0020;

				using (Graphics bitmapGraphics = Graphics.FromImage(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap))
				{
					IntPtr displayHDC = displayGraphics.GetHdc();
					IntPtr bitmapHDC = bitmapGraphics.GetHdc();

					IntPtr hBitmap = aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.GetHbitmap();
					IntPtr hOldObject = SelectObject(bitmapHDC, hBitmap);

					int result = BitBlt(displayHDC, 0, 0, aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.Width, aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.Height, bitmapHDC, 0, 0, SRCCOPY);

					SelectObject(bitmapHDC, hOldObject);
					DeleteObject(hBitmap);

					bitmapGraphics.ReleaseHdc(bitmapHDC);
					displayGraphics.ReleaseHdc(displayHDC);
				}
			}
		}
コード例 #3
0
 //----------------------------------------------------------clipping_flags
 // Determine the clipping code of the vertex according to the 
 // Cyrus-Beck line clipping algorithm
 //
 //        |        |
 //  0110  |  0010  | 0011
 //        |        |
 // -------+--------+-------- clip_box.y2
 //        |        |
 //  0100  |  0000  | 0001
 //        |        |
 // -------+--------+-------- clip_box.y1
 //        |        |
 //  1100  |  1000  | 1001
 //        |        |
 //  clip_box.x1  clip_box.x2
 //
 // 
 //template<class T>
 public static int clipping_flags(int x, int y, RectangleInt clip_box)
 {
     return ((x > clip_box.Right) ? 1 : 0) 
         | ((y > clip_box.Top) ? 1 << 1 : 0)
         | ((x < clip_box.Left) ? 1 << 2 : 0)
         | ((y < clip_box.Bottom) ? 1 << 3 : 0);
 }
コード例 #4
0
ファイル: HexSheet.cs プロジェクト: plaurin/MonoGameEngine2D
        public HexDefinition CreateHexDefinition(string hexName, Point hexPosition)
        {
            var rectangle = new RectangleInt(hexPosition.X, hexPosition.Y, this.HexSize.Width, this.HexSize.Height);
            var hexDefinition = new HexDefinition(this, hexName, rectangle);

            this.Definitions.Add(hexName, hexDefinition);
            return hexDefinition;
        }
コード例 #5
0
ファイル: TileSheet.cs プロジェクト: plaurin/MonoGameEngine2D
        public TileDefinition CreateTileDefinition(string tileName, Point tilePosition)
        {
            var rectangle = new RectangleInt(tilePosition.X, tilePosition.Y, this.TilesSize.Width, this.TilesSize.Height);
            var tileDefinition = new TileDefinition(this, tileName, rectangle);
            this.definitions.Add(tileName, tileDefinition);

            return tileDefinition;
        }
コード例 #6
0
ファイル: ClippingProxy.cs プロジェクト: glocklueng/agg-sharp
		public bool SetClippingBox(int x1, int y1, int x2, int y2)
		{
			RectangleInt cb = new RectangleInt(x1, y1, x2, y2);
			cb.normalize();
			if (cb.clip(new RectangleInt(0, 0, (int)Width - 1, (int)Height - 1)))
			{
				m_ClippingRect = cb;
				return true;
			}
			m_ClippingRect.Left = 1;
			m_ClippingRect.Bottom = 1;
			m_ClippingRect.Right = 0;
			m_ClippingRect.Top = 0;
			return false;
		}
コード例 #7
0
ファイル: HexGrid.cs プロジェクト: plaurin/MonoGameEngine2D
        public static IEnumerable<HexGridElement> CreateHexMap(Vector startingCenter, float edgeLength, RectangleInt areaRectangle)
        {
            var hexRadius = MathUtil.CalcHypotenuseSide(edgeLength * 2, edgeLength);
            var angles = new[] { -30, 30, 90 };
            var hexCenters = new HashSet<HexGridElement>();
            var toExplore = new HashSet<HexGridElement> { new HexGridElement(startingCenter, edgeLength, areaRectangle.Location) };

            while (toExplore.Any())
            {
                var currentHex = toExplore.First();
                toExplore.Remove(currentHex);

                foreach (var angle in angles)
                {
                    var position = Point.Zero;
                    switch (angle)
                    {
                        case -30:
                            position = currentHex.Position.Translate(new Point(1, currentHex.Position.X % 2 == 0 ? -1 : 0));
                            break;
                        case 30:
                            position = currentHex.Position.Translate(new Point(1, currentHex.Position.X % 2 == 0 ? 0 : 1));
                            break;
                        case 90:
                            position = currentHex.Position.Translate(new Point(0, 1));
                            break;
                    }

                    var adjacent = currentHex.Center
                        .TranslatePolar(MathUtil.ToRadians(angle), hexRadius)
                        .RoundTo(1);

                    var adjacentHex = new HexGridElement(adjacent, edgeLength, position);
                    if (areaRectangle.Contains(adjacentHex.Position))
                    {
                        if (!toExplore.Contains(adjacentHex) && !hexCenters.Contains(adjacentHex))
                            toExplore.Add(adjacentHex);
                    }
                }

                hexCenters.Add(currentHex);
            }

            return hexCenters;
        }
コード例 #8
0
ファイル: RayTracer.cs プロジェクト: philsylvester/agg-sharp
        public void RayTraceScene(RectangleInt viewport, Scene scene)
        {
            int maxsamples = (int)AntiAliasing;

            //graphics2D.FillRectangle(viewport, RGBA_Floats.Black);

            if (ColorBuffer == null || ColorBuffer.Length < viewport.Width || ColorBuffer[0].Length < viewport.Height)
            {
                ColorBuffer = new RGBA_Floats[viewport.Width][];
                for (int i = 0; i < viewport.Width; i++)
                {
                    ColorBuffer[i] = new RGBA_Floats[viewport.Height];
                }
                NormalBuffer = new Vector3[viewport.Width][];
                for (int i = 0; i < viewport.Width; i++)
                {
                    NormalBuffer[i] = new Vector3[viewport.Height];
                }
                DepthBuffer = new double[viewport.Width][];
                for (int i = 0; i < viewport.Width; i++)
                {
                    DepthBuffer[i] = new double[viewport.Height];
                }
            }

            if (TraceWithRayBundles)
            {
                int yStep = 8;
                int xStep = 8;
                for (int y = viewport.Bottom; y < viewport.Height; y += yStep)
                {
                    for (int x = viewport.Left; x < viewport.Right; x += xStep)
                    {
                        try {
                            int bundleWidth            = Math.Min(xStep, viewport.Right - x);
                            int bundleHeight           = Math.Min(yStep, viewport.Top - y);
                            FrustumRayBundle rayBundle = new FrustumRayBundle(bundleWidth * bundleHeight);
                            IntersectInfo[]  intersectionsForBundle = new IntersectInfo[bundleWidth * bundleHeight];

                            // Calculate all the initial rays
                            for (int rayY = 0; rayY < bundleHeight; rayY++)
                            {
                                for (int rayX = 0; rayX < bundleWidth; rayX++)
                                {
                                    rayBundle.rayArray[rayX + rayY * bundleWidth]     = scene.camera.GetRay(x + rayX, y + rayY);
                                    intersectionsForBundle[rayX + rayY * bundleWidth] = new IntersectInfo();
                                }
                            }

                            // get a ray to find the origin (every ray comes from the camera and should have the same origin)
                            rayBundle.CalculateFrustum(bundleWidth, bundleHeight, rayBundle.rayArray[0].origin);

                            FullyTraceRayBundle(rayBundle, intersectionsForBundle, scene);

                            // get the color data out of the traced rays
                            for (int rayY = 0; rayY < bundleHeight; rayY++)
                            {
                                for (int rayX = 0; rayX < bundleWidth; rayX++)
                                {
                                    ColorBuffer[x + rayX][y + rayY] = intersectionsForBundle[rayX + rayY * bundleWidth].totalColor;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else
            {
                if (MultiThreaded)
                {
                    System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y =>
                    {
                        TraceXSpan(viewport, scene, y);
                    });
                }
                else
                {
                    for (int y = viewport.Bottom; y < viewport.Height; y++)
                    {
                        TraceXSpan(viewport, scene, y);
                    }
                }
            }

            if (AntiAliasing != AntiAliasing.None)
            {
                AntiAliasScene(viewport, scene, ColorBuffer, (int)AntiAliasing);
            }
        }
コード例 #9
0
        private List <PortalPath> GeneratePairs(Portal startPortal, List <Portal> allPortals)
        {
            RectangleInt bounds = new RectangleInt(Vector2Int.Zero, new Vector2Int(inputGrid[0].Count - 1, inputGrid.Count - 1));
            //Vector2Int startLocation = startPortal.PositionA;

            //List<PortalPair> output = new List<PortalPair>();
            List <PortalPath>    output           = new List <PortalPath>();
            HashSet <Vector2Int> visitedLocations = new HashSet <Vector2Int>();

            Queue <Vector2Int> locationsLeft = new Queue <Vector2Int>();
            Queue <int>        distances     = new Queue <int>();

            locationsLeft.Enqueue(startPortal.Position);
            //locationsLeft.Enqueue(startPortal.PositionB);
            distances.Enqueue(0);
            //distances.Enqueue(0);

            while (locationsLeft.Count > 0)
            {
                // get current position from queue
                Vector2Int currentPos = locationsLeft.Dequeue();
                int        distance   = distances.Dequeue();

                // skip over an already visited location
                if (visitedLocations.Contains(currentPos))
                {
                    continue;
                }

                visitedLocations.Add(currentPos);

                char currentTile = inputGrid[currentPos.Y][currentPos.X];

                // teleporter
                if (char.IsUpper(currentTile))
                {
                    Portal            otherPortal = null;// = allPortals.FirstOrDefault(p => p.Position.Equals(currentPos));
                    List <Vector2Int> around      = Around(currentPos);
                    foreach (var pos in around)
                    {
                        //if (allPortals.FirstOrDefault(p => p.Position.Equals(pos)) != null)
                        if (inputGrid[pos.Y][pos.X] == '.')
                        {
                            otherPortal = allPortals.FirstOrDefault(p => p.Position.Equals(pos));

                            if (otherPortal != null && !otherPortal.Equals(startPortal) && otherPortal.Name != "AA")
                            {
                                output.Add(new PortalPath()
                                {
                                    OtherPortal = otherPortal,
                                    Distance    = distance - 1
                                });

                                break;
                            }
                        }
                    }

                    //Portal otherPortal = allPortals.FirstOrDefault(p => p.PositionA.Equals(currentPos) || p.PositionB.Equals(currentPos));
                }
                // open space
                else if (currentTile == '.')
                {
                    List <Vector2Int> around = Around(currentPos);
                    foreach (Vector2Int aroundPos in around)
                    {
                        if (bounds.IsInRectangle(aroundPos))
                        {
                            locationsLeft.Enqueue(aroundPos);
                            distances.Enqueue(distance + 1);
                        }
                    }
                }
            }

            return(output);
        }
コード例 #10
0
		internal void UpdateHardwareSurface(RectangleInt rect)
		{
			numInFunction++;
			if (backingImageBufferByte != null)
			{
				if (!externallyLocked && !currentlyLocked)
				{
					currentlyLocked = true;
					bitmapData = windowsBitmap.LockBits(new Rectangle(0, 0, windowsBitmap.Width, windowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, windowsBitmap.PixelFormat);
				}
				int backBufferStrideInBytes = backingImageBufferByte.StrideInBytes();
				int backBufferStrideInInts = backBufferStrideInBytes / 4;
				int backBufferHeight = backingImageBufferByte.Height;
				int backBufferHeightMinusOne = backBufferHeight - 1;
				int bitmapDataStride = bitmapData.Stride;
				int offset;
				byte[] buffer = backingImageBufferByte.GetBuffer(out offset);
				switch (backingImageBufferByte.BitDepth)
				{
					case 24:
						{
							unsafe
							{
								byte* bitmapDataScan0 = (byte*)bitmapData.Scan0;
								fixed (byte* pSourceFixed = &buffer[offset])
								{
									byte* pSource = pSourceFixed;
									byte* pDestBuffer = bitmapDataScan0 + bitmapDataStride * backBufferHeightMinusOne;
									for (int y = 0; y < backBufferHeight; y++)
									{
										int* pSourceInt = (int*)pSource;
										int* pDestBufferInt = (int*)pDestBuffer;
										for (int x = 0; x < backBufferStrideInInts; x++)
										{
											pDestBufferInt[x] = pSourceInt[x];
										}
										for (int x = backBufferStrideInInts * 4; x < backBufferStrideInBytes; x++)
										{
											pDestBuffer[x] = pSource[x];
										}
										pDestBuffer -= bitmapDataStride;
										pSource += backBufferStrideInBytes;
									}
								}
							}
						}
						break;

					case 32:
						{
							unsafe
							{
								byte* bitmapDataScan0 = (byte*)bitmapData.Scan0;
								fixed (byte* pSourceFixed = &buffer[offset])
								{
									byte* pSource = pSourceFixed;
									byte* pDestBuffer = bitmapDataScan0 + bitmapDataStride * backBufferHeightMinusOne;
									for (int y = rect.Bottom; y < rect.Top; y++)
									{
										int* pSourceInt = (int*)pSource;
										pSourceInt += (backBufferStrideInBytes * y / 4);

										int* pDestBufferInt = (int*)pDestBuffer;
										pDestBufferInt -= (bitmapDataStride * y / 4);

										for (int x = rect.Left; x < rect.Right; x++)
										{
											pDestBufferInt[x] = pSourceInt[x];
										}
									}
								}
							}
						}
						break;

					default:
						throw new NotImplementedException();
				}
				if (!externallyLocked)
				{
					windowsBitmap.UnlockBits(bitmapData);
					currentlyLocked = false;
				}
			}
			else
			{
				switch (backingImageBufferFloat.BitDepth)
				{
					case 128:
						{
							BitmapData bitmapData = windowsBitmap.LockBits(new Rectangle(0, 0, windowsBitmap.Width, windowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, windowsBitmap.PixelFormat);
							int index = 0;
							unsafe
							{
								unchecked
								{
									int offset;
									float[] buffer = backingImageBufferFloat.GetBuffer(out offset);
									fixed (float* pSource = &buffer[offset])
									{
										for (int y = 0; y < backingImageBufferFloat.Height; y++)
										{
											byte* pDestBuffer = (byte*)bitmapData.Scan0 + (bitmapData.Stride * (backingImageBufferFloat.Height - 1 - y));
											for (int x = 0; x < backingImageBufferFloat.Width; x++)
											{
#if true
												pDestBuffer[x * 4 + 0] = (byte)(pSource[index * 4 + 0] * 255);
												pDestBuffer[x * 4 + 1] = (byte)(pSource[index * 4 + 1] * 255);
												pDestBuffer[x * 4 + 2] = (byte)(pSource[index * 4 + 2] * 255);
												pDestBuffer[x * 4 + 3] = (byte)(pSource[index * 4 + 3] * 255);
												index++;
#else
                                                pDestBuffer[x * 4 + 0] = (byte)255;
                                                pDestBuffer[x * 4 + 1] = (byte)0;
                                                pDestBuffer[x * 4 + 2] = (byte)128;
                                                pDestBuffer[x * 4 + 3] = (byte)255;
#endif
											}
										}
									}
								}
							}

							windowsBitmap.UnlockBits(bitmapData);
						}
						break;

					default:
						throw new NotImplementedException();
				}
			}

			numInFunction--;
		}
コード例 #11
0
        private void ServerExplode(IItem item)
        {
            Server.Items.DestroyItem(item);

            // explode a primitive bomb in player position
            var character = item.Container.OwnerAsCharacter;

            if (character is null)
            {
                return;
            }

            var characterPublicState = character.GetPublicState <PlayerCharacterPublicState>();

            if (!characterPublicState.IsDead)
            {
                // ensure the wearer is killed by the explosion
                characterPublicState.CurrentStats.ServerSetHealthCurrent(0);
            }

            var targetPosition = character.Position;

            var protoBomb = ProtoObjectBomb;

            SharedExplosionHelper.ServerExplode(
                character: character,
                protoExplosive: protoBomb,
                protoWeapon: null,
                explosionPreset: protoBomb.ExplosionPreset,
                epicenterPosition: targetPosition,
                damageDescriptionCharacters: protoBomb.DamageDescriptionCharacters,
                physicsSpace: Server.World.GetPhysicsSpace(),
                executeExplosionCallback: protoBomb.ServerExecuteExplosion);

            // notify all characters about the explosion
            using var charactersObserving = Api.Shared.GetTempList <ICharacter>();
            const byte explosionEventRadius = 40;

            Server.World.GetCharactersInRadius(targetPosition.ToVector2Ushort(),
                                               charactersObserving,
                                               radius: explosionEventRadius,
                                               onlyPlayers: true);

            this.CallClient(charactersObserving.AsList(),
                            _ => _.ClientRemote_OnExplosion(targetPosition));

            // activate the raidblock if possible (the code is similar to ProtoObjectEplosive)
            var explosionRadius = (int)Math.Ceiling(protoBomb.DamageRadius);
            var bounds          = new RectangleInt(x: (int)Math.Round(character.Position.X - explosionRadius),
                                                   y: (int)Math.Round(character.Position.Y - explosionRadius),
                                                   width: 2 * explosionRadius,
                                                   height: 2 * explosionRadius);

            if (RaidingProtectionSystem.SharedCanRaid(bounds,
                                                      showClientNotification: false))
            {
                // try activate the raidblock
                LandClaimSystem.ServerOnRaid(bounds, character, isStructureDestroyed: false);
            }
            else
            {
                // Raiding is not possible now due to raiding window
                // Find if there is any land claim and in that case notify nearby players
                // that the damage to objects there was not applied.
                if (LandClaimSystem.SharedIsLandClaimedByAnyone(bounds))
                {
                    using var tempPlayers = Api.Shared.GetTempList <ICharacter>();
                    Server.World.GetScopedByPlayers(character, tempPlayers);
                    RaidingProtectionSystem.ServerNotifyShowNotificationRaidingNotAvailableNow(
                        tempPlayers.AsList());
                }
            }
        }
コード例 #12
0
        protected void CopyFromNoClipping(IImageByte sourceImage, RectangleInt clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (GetBytesBetweenPixelsInclusive() != BitDepth / 8 ||
                sourceImage.GetBytesBetweenPixelsInclusive() != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * GetBytesBetweenPixelsInclusive();

                int    sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);
                byte[] sourceBuffer = sourceImage.GetBuffer();
                int    destOffset;
                byte[] destBuffer = GetPixelPointerXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset, out destOffset);

                for (int i = 0; i < clippedSourceImageRect.Height; i++)
                {
                    agg_basics.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                    sourceOffset += sourceImage.StrideInBytes();
                    destOffset   += StrideInBytes();
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                case 24:
                    switch (BitDepth)
                    {
                    case 32:
                    {
                        int numPixelsToCopy = clippedSourceImageRect.Width;
                        for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                        {
                            int    sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);
                            byte[] sourceBuffer = sourceImage.GetBuffer();
                            int    destOffset;
                            byte[] destBuffer = GetPixelPointerXY(
                                clippedSourceImageRect.Left + destXOffset,
                                clippedSourceImageRect.Bottom + i + destYOffset,
                                out destOffset);
                            for (int x = 0; x < numPixelsToCopy; x++)
                            {
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = 255;
                            }
                        }
                    }
                    break;

                    default:
                        haveConversion = false;
                        break;
                    }
                    break;

                default:
                    haveConversion = false;
                    break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }
コード例 #13
0
 public ImageClippingProxyFloat(IImageFloat ren)
     : base(ren)
 {
     m_ClippingRect = new RectangleInt(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
 }
コード例 #14
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		public void GetVisibleBounds(out RectangleInt visibleBounds)
		{
			visibleBounds = new RectangleInt(0, 0, Width, Height);

			// trim the bottom
			bool aPixelsIsVisible = false;
			for (int y = 0; y < height; y++)
			{
				for (int x = 0; x < width; x++)
				{
					if (IsPixelVisible(x, y))
					{
						visibleBounds.Bottom = y;
						y = height;
						x = width;
						aPixelsIsVisible = true;
					}
				}
			}

			// if we don't run into any pixels set for the top trim than there are no pixels set at all
			if (!aPixelsIsVisible)
			{
				visibleBounds.SetRect(0, 0, 0, 0);
				return;
			}

			// trim the bottom
			for (int y = height - 1; y >= 0; y--)
			{
				for (int x = 0; x < width; x++)
				{
					if (IsPixelVisible(x, y))
					{
						visibleBounds.Top = y + 1;
						y = -1;
						x = width;
					}
				}
			}

			// trim the left
			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					if (IsPixelVisible(x, y))
					{
						visibleBounds.Left = x;
						y = height;
						x = width;
					}
				}
			}

			// trim the right
			for (int x = width - 1; x >= 0; x--)
			{
				for (int y = 0; y < height; y++)
				{
					if (IsPixelVisible(x, y))
					{
						visibleBounds.Right = x + 1;
						y = height;
						x = -1;
					}
				}
			}
		}
コード例 #15
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		private void Initialize(ImageBuffer sourceImage, RectangleInt boundsToCopyFrom)
		{
			if (sourceImage == this)
			{
				throw new Exception("We do not create a temp buffer for this to work.  You must have a source distinct from the dest.");
			}
			Deallocate();
			Allocate(boundsToCopyFrom.Width, boundsToCopyFrom.Height, boundsToCopyFrom.Width * sourceImage.BitDepth / 8, sourceImage.BitDepth);
			SetRecieveBlender(sourceImage.GetRecieveBlender());

			if (width != 0 && height != 0)
			{
				RectangleInt DestRect = new RectangleInt(0, 0, boundsToCopyFrom.Width, boundsToCopyFrom.Height);
				RectangleInt AbsoluteSourceRect = boundsToCopyFrom;
				// The first thing we need to do is make sure the frame is cleared. LBB [3/15/2004]
				MatterHackers.Agg.Graphics2D graphics2D = NewGraphics2D();
				graphics2D.Clear(new RGBA_Bytes(0, 0, 0, 0));

				int x = -boundsToCopyFrom.Left - (int)sourceImage.OriginOffset.x;
				int y = -boundsToCopyFrom.Bottom - (int)sourceImage.OriginOffset.y;

				graphics2D.Render(sourceImage, x, y, 0, 1, 1);
			}
		}
コード例 #16
0
 public static int clipping_flags_x(int x, RectangleInt clip_box)
 {
     return((x > clip_box.Right ? 1 : 0) | ((x < clip_box.Left ? 1 : 0) << 2));
 }
コード例 #17
0
        internal void UpdateHardwareSurface(RectangleInt rect)
        {
            numInFunction++;
            if (backingImageBufferByte != null)
            {
                if (!externallyLocked && !currentlyLocked)
                {
                    currentlyLocked = true;
                    bitmapData      = windowsBitmap.LockBits(new Rectangle(0, 0, windowsBitmap.Width, windowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, windowsBitmap.PixelFormat);
                }
                int    backBufferStrideInBytes  = backingImageBufferByte.StrideInBytes();
                int    backBufferStrideInInts   = backBufferStrideInBytes / 4;
                int    backBufferHeight         = backingImageBufferByte.Height;
                int    backBufferHeightMinusOne = backBufferHeight - 1;
                int    bitmapDataStride         = bitmapData.Stride;
                int    offset;
                byte[] buffer = backingImageBufferByte.GetBuffer(out offset);
                switch (backingImageBufferByte.BitDepth)
                {
                case 24:
                {
                    unsafe
                    {
                        byte *bitmapDataScan0 = (byte *)bitmapData.Scan0;
                        fixed(byte *pSourceFixed = &buffer[offset])
                        {
                            byte *pSource     = pSourceFixed;
                            byte *pDestBuffer = bitmapDataScan0 + bitmapDataStride * backBufferHeightMinusOne;

                            for (int y = 0; y < backBufferHeight; y++)
                            {
                                int *pSourceInt     = (int *)pSource;
                                int *pDestBufferInt = (int *)pDestBuffer;
                                for (int x = 0; x < backBufferStrideInInts; x++)
                                {
                                    pDestBufferInt[x] = pSourceInt[x];
                                }
                                for (int x = backBufferStrideInInts * 4; x < backBufferStrideInBytes; x++)
                                {
                                    pDestBuffer[x] = pSource[x];
                                }
                                pDestBuffer -= bitmapDataStride;
                                pSource     += backBufferStrideInBytes;
                            }
                        }
                    }
                }
                break;

                case 32:
                {
                    unsafe
                    {
                        byte *bitmapDataScan0 = (byte *)bitmapData.Scan0;
                        fixed(byte *pSourceFixed = &buffer[offset])
                        {
                            byte *pSource     = pSourceFixed;
                            byte *pDestBuffer = bitmapDataScan0 + bitmapDataStride * backBufferHeightMinusOne;

                            for (int y = rect.Bottom; y < rect.Top; y++)
                            {
                                int *pSourceInt = (int *)pSource;
                                pSourceInt += (backBufferStrideInBytes * y / 4);

                                int *pDestBufferInt = (int *)pDestBuffer;
                                pDestBufferInt -= (bitmapDataStride * y / 4);

                                for (int x = rect.Left; x < rect.Right; x++)
                                {
                                    pDestBufferInt[x] = pSourceInt[x];
                                }
                            }
                        }
                    }
                }
                break;

                default:
                    throw new NotImplementedException();
                }
                if (!externallyLocked)
                {
                    windowsBitmap.UnlockBits(bitmapData);
                    currentlyLocked = false;
                }
            }
            else
            {
                switch (backingImageBufferFloat.BitDepth)
                {
                case 128:
                {
                    BitmapData bitmapData = windowsBitmap.LockBits(new Rectangle(0, 0, windowsBitmap.Width, windowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, windowsBitmap.PixelFormat);
                    int        index      = 0;
                    unsafe
                    {
                        unchecked
                        {
                            int     offset;
                            float[] buffer = backingImageBufferFloat.GetBuffer(out offset);
                            fixed(float *pSource = &buffer[offset])
                            {
                                for (int y = 0; y < backingImageBufferFloat.Height; y++)
                                {
                                    byte *pDestBuffer = (byte *)bitmapData.Scan0 + (bitmapData.Stride * (backingImageBufferFloat.Height - 1 - y));
                                    for (int x = 0; x < backingImageBufferFloat.Width; x++)
                                    {
#if true
                                        pDestBuffer[x * 4 + 0] = (byte)(pSource[index * 4 + 0] * 255);
                                        pDestBuffer[x * 4 + 1] = (byte)(pSource[index * 4 + 1] * 255);
                                        pDestBuffer[x * 4 + 2] = (byte)(pSource[index * 4 + 2] * 255);
                                        pDestBuffer[x * 4 + 3] = (byte)(pSource[index * 4 + 3] * 255);
                                        index++;
#else
                                        pDestBuffer[x * 4 + 0] = (byte)255;
                                        pDestBuffer[x * 4 + 1] = (byte)0;
                                        pDestBuffer[x * 4 + 2] = (byte)128;
                                        pDestBuffer[x * 4 + 3] = (byte)255;
#endif
                                    }
                                }
                            }
                        }
                    }

                    windowsBitmap.UnlockBits(bitmapData);
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }

            numInFunction--;
        }
コード例 #18
0
    public static TileMap <T> Convert <U, T>(this TileMap <U> map, Func <U, T> conversionFunction)
    {
        TileMap <T> result       = new TileMap <T>();
        Layout      resultLayout = new Layout();

        result.Layout = resultLayout;

        // Add zones & tiles

        Graph <Zone> mapGraph = map.Layout.Zones;
        Zone         zone;

        for (int i = 0; i < mapGraph.Count; i++)
        {
            zone = mapGraph.Nodes[i].Value;
            RectangleInt bounds  = zone.bounds;
            Zone         newZone = new Zone(bounds.x, bounds.y, bounds.width, bounds.height);

            var  enumerator = zone.GetEnumerator();
            int2 tile;

            while (enumerator.MoveNext())
            {
                tile = enumerator.Current;
                newZone.tiles.Add(tile);
                result.Add(tile, conversionFunction(map[tile.x, tile.y]));
            }

            resultLayout.Add(newZone);
        }

        // Link layout Zones

        Zone resultZone;

        for (int i = 0; i < mapGraph.Count; i++)
        {
            zone = mapGraph.Nodes[i].Value;
            GraphNode <Zone> mapZoneNode = mapGraph.Nodes.FindByValue(zone) as GraphNode <Zone>;
            resultZone = resultLayout.FindZoneByPosition(zone.bounds.Position);

            var linkEnumerator = mapZoneNode.Neighbors.GetEnumerator();

            while (linkEnumerator.MoveNext())
            {
                Zone mapConnectionZone    = linkEnumerator.Current.Value;
                Zone resultConnectionZone = resultLayout.FindZoneByPosition(mapConnectionZone.bounds.Position);

                GraphNode <Zone> resultZoneNode = resultLayout.Zones.Nodes.FindByValue(resultZone) as GraphNode <Zone>;

                if (CountOccurrences(resultZoneNode.Neighbors, resultConnectionZone) < CountOccurrences(mapZoneNode.Neighbors, mapConnectionZone))
                {
                    resultLayout.ConnectZones(resultZone, resultConnectionZone);
                }
            }
        }

        // Connect zones

        for (int i = 0; i < mapGraph.Count; i++)
        {
            zone       = mapGraph.Nodes[i].Value;
            resultZone = resultLayout.FindZoneByPosition(zone.bounds.Position);

            int2 connectionPoint;
            Zone connectionZone;
            var  connectionsEnumerator = zone.connections.GetEnumerator();

            while (connectionsEnumerator.MoveNext())
            {
                int2 currentMapPoint          = connectionsEnumerator.Current.Key;
                Zone currentMapZoneConnection = connectionsEnumerator.Current.Value;

                connectionPoint = new int2(currentMapPoint.x, currentMapPoint.y);
                connectionZone  = resultLayout.FindZoneByPosition(currentMapZoneConnection.bounds.Position);

                resultZone.AddConnectionPoint(connectionPoint, connectionZone);
            }
        }

        // Set Initial & Final zones

        resultLayout.InitialZone = resultLayout.FindZoneByPosition(map.Layout.InitialZone.bounds.Position);
        resultLayout.FinalZone   = resultLayout.FindZoneByPosition(map.Layout.FinalZone.bounds.Position);

        // Set Spawn & Exit zones

        result.SpawnPoint = map.SpawnPoint;
        result.ExitPoint  = map.ExitPoint;

        return(result);
    }
コード例 #19
0
        public static int clip_liang_barsky(int x1, int y1, int x2, int y2,
                                            RectangleInt clip_box,
                                            int[] x, int[] y)
        {
            int    XIndex   = 0;
            int    YIndex   = 0;
            double nearzero = 1e-30;

            double deltax = x2 - x1;
            double deltay = y2 - y1;
            double xin;
            double xout;
            double yin;
            double yout;
            double tinx;
            double tiny;
            double toutx;
            double touty;
            double tin1;
            double tin2;
            double tout1;
            int    np = 0;

            if (deltax == 0.0)
            {
                // bump off of the vertical
                deltax = (x1 > clip_box.Left) ? -nearzero : nearzero;
            }

            if (deltay == 0.0)
            {
                // bump off of the horizontal
                deltay = (y1 > clip_box.Bottom) ? -nearzero : nearzero;
            }

            if (deltax > 0.0)
            {
                // points to right
                xin  = clip_box.Left;
                xout = clip_box.Right;
            }
            else
            {
                xin  = clip_box.Right;
                xout = clip_box.Left;
            }

            if (deltay > 0.0)
            {
                // points up
                yin  = clip_box.Bottom;
                yout = clip_box.Top;
            }
            else
            {
                yin  = clip_box.Top;
                yout = clip_box.Bottom;
            }

            tinx = (xin - x1) / deltax;
            tiny = (yin - y1) / deltay;

            if (tinx < tiny)
            {
                // hits x first
                tin1 = tinx;
                tin2 = tiny;
            }
            else
            {
                // hits y first
                tin1 = tiny;
                tin2 = tinx;
            }

            if (tin1 <= 1.0)
            {
                if (0.0 < tin1)
                {
                    x[XIndex++] = (int)xin;
                    y[YIndex++] = (int)yin;
                    ++np;
                }

                if (tin2 <= 1.0)
                {
                    toutx = (xout - x1) / deltax;
                    touty = (yout - y1) / deltay;

                    tout1 = (toutx < touty) ? toutx : touty;

                    if (tin2 > 0.0 || tout1 > 0.0)
                    {
                        if (tin2 <= tout1)
                        {
                            if (tin2 > 0.0)
                            {
                                if (tinx > tiny)
                                {
                                    x[XIndex++] = (int)xin;
                                    y[YIndex++] = (int)(y1 + tinx * deltay);
                                }
                                else
                                {
                                    x[XIndex++] = (int)(x1 + tiny * deltax);
                                    y[YIndex++] = (int)yin;
                                }
                                ++np;
                            }

                            if (tout1 < 1.0)
                            {
                                if (toutx < touty)
                                {
                                    x[XIndex++] = (int)xout;
                                    y[YIndex++] = (int)(y1 + toutx * deltay);
                                }
                                else
                                {
                                    x[XIndex++] = (int)(x1 + touty * deltax);
                                    y[YIndex++] = (int)yout;
                                }
                            }
                            else
                            {
                                x[XIndex++] = x2;
                                y[YIndex++] = y2;
                            }
                            ++np;
                        }
                        else
                        {
                            if (tinx > tiny)
                            {
                                x[XIndex++] = (int)xin;
                                y[YIndex++] = (int)yout;
                            }
                            else
                            {
                                x[XIndex++] = (int)xout;
                                y[YIndex++] = (int)yin;
                            }
                            ++np;
                        }
                    }
                }
            }
            return(np);
        }
コード例 #20
0
ファイル: ClippingProxy.cs プロジェクト: glocklueng/agg-sharp
		public ImageClippingProxyFloat(IImageFloat ren)
			: base(ren)
		{
			m_ClippingRect = new RectangleInt(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
		}
コード例 #21
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		protected void CopyFromNoClipping(IImageByte sourceImage, RectangleInt clippedSourceImageRect, int destXOffset, int destYOffset)
		{
			if (GetBytesBetweenPixelsInclusive() != BitDepth / 8
				|| sourceImage.GetBytesBetweenPixelsInclusive() != sourceImage.BitDepth / 8)
			{
				throw new Exception("WIP we only support packed pixel formats at this time.");
			}

			if (BitDepth == sourceImage.BitDepth)
			{
				int lengthInBytes = clippedSourceImageRect.Width * GetBytesBetweenPixelsInclusive();

				int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);
				byte[] sourceBuffer = sourceImage.GetBuffer();
				int destOffset;
				byte[] destBuffer = GetPixelPointerXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset, out destOffset);

				for (int i = 0; i < clippedSourceImageRect.Height; i++)
				{
					agg_basics.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
					sourceOffset += sourceImage.StrideInBytes();
					destOffset += StrideInBytes();
				}
			}
			else
			{
				bool haveConversion = true;
				switch (sourceImage.BitDepth)
				{
					case 24:
						switch (BitDepth)
						{
							case 32:
								{
									int numPixelsToCopy = clippedSourceImageRect.Width;
									for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
									{
										int sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);
										byte[] sourceBuffer = sourceImage.GetBuffer();
										int destOffset;
										byte[] destBuffer = GetPixelPointerXY(
											clippedSourceImageRect.Left + destXOffset,
											clippedSourceImageRect.Bottom + i + destYOffset,
											out destOffset);
										for (int x = 0; x < numPixelsToCopy; x++)
										{
											destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
											destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
											destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
											destBuffer[destOffset++] = 255;
										}
									}
								}
								break;

							default:
								haveConversion = false;
								break;
						}
						break;

					default:
						haveConversion = false;
						break;
				}

				if (!haveConversion)
				{
					throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
				}
			}
		}
コード例 #22
0
ファイル: ClippingProxy.cs プロジェクト: glocklueng/agg-sharp
		public override void LinkToImage(IImageFloat ren)
		{
			base.LinkToImage(ren);
			m_ClippingRect = new RectangleInt(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
		}
コード例 #23
0
ファイル: SimpleTests.cs プロジェクト: CNCBrasil/agg-sharp
		public void TestGetHashCode()
		{
			{
				RGBA_Bytes a = new RGBA_Bytes(10, 11, 12);
				RGBA_Bytes b = new RGBA_Bytes(10, 11, 12);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RGBA_Floats a = new RGBA_Floats(10, 11, 12);
				RGBA_Floats b = new RGBA_Floats(10, 11, 12);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				BorderDouble a = new BorderDouble(10, 11, 12, 13);
				BorderDouble b = new BorderDouble(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				Point2D a = new Point2D(10, 11);
				Point2D b = new Point2D(10, 11);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RectangleDouble a = new RectangleDouble(10, 11, 12, 13);
				RectangleDouble b = new RectangleDouble(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
			{
				RectangleInt a = new RectangleInt(10, 11, 12, 13);
				RectangleInt b = new RectangleInt(10, 11, 12, 13);
				Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
			}
		}
コード例 #24
0
ファイル: ClippingProxy.cs プロジェクト: glocklueng/agg-sharp
		public override void CopyFrom(IImageFloat sourceImage,
					   RectangleInt sourceImageRect,
					   int destXOffset,
					   int destYOffset)
		{
			RectangleInt destRect = sourceImageRect;
			destRect.Offset(destXOffset, destYOffset);

			RectangleInt clippedSourceRect = new RectangleInt();
			if (clippedSourceRect.IntersectRectangles(destRect, m_ClippingRect))
			{
				// move it back relative to the source
				clippedSourceRect.Offset(-destXOffset, -destYOffset);

				base.CopyFrom(sourceImage, clippedSourceRect, destXOffset, destYOffset);
			}
		}
コード例 #25
0
        public void GetVisibleBounds(out RectangleInt visibleBounds)
        {
            visibleBounds = new RectangleInt(0, 0, Width, Height);

            // trim the bottom
            bool aPixelsIsVisible = false;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (IsPixelVisible(x, y))
                    {
                        visibleBounds.Bottom = y;
                        y = height;
                        x = width;
                        aPixelsIsVisible = true;
                    }
                }
            }

            // if we don't run into any pixels set for the top trim than there are no pixels set at all
            if (!aPixelsIsVisible)
            {
                visibleBounds.SetRect(0, 0, 0, 0);
                return;
            }

            // trim the bottom
            for (int y = height - 1; y >= 0; y--)
            {
                for (int x = 0; x < width; x++)
                {
                    if (IsPixelVisible(x, y))
                    {
                        visibleBounds.Top = y + 1;
                        y = -1;
                        x = width;
                    }
                }
            }

            // trim the left
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (IsPixelVisible(x, y))
                    {
                        visibleBounds.Left = x;
                        y = height;
                        x = width;
                    }
                }
            }

            // trim the right
            for (int x = width - 1; x >= 0; x--)
            {
                for (int y = 0; y < height; y++)
                {
                    if (IsPixelVisible(x, y))
                    {
                        visibleBounds.Right = x + 1;
                        y = height;
                        x = -1;
                    }
                }
            }
        }
コード例 #26
0
ファイル: ClippingProxy.cs プロジェクト: glocklueng/agg-sharp
		public RectangleInt clip_rect_area(ref RectangleInt destRect, ref RectangleInt sourceRect, int sourceWidth, int sourceHeight)
		{
			RectangleInt rc = new RectangleInt(0, 0, 0, 0);
			RectangleInt cb = clip_box();
			++cb.Right;
			++cb.Top;

			if (sourceRect.Left < 0)
			{
				destRect.Left -= sourceRect.Left;
				sourceRect.Left = 0;
			}
			if (sourceRect.Bottom < 0)
			{
				destRect.Bottom -= sourceRect.Bottom;
				sourceRect.Bottom = 0;
			}

			if (sourceRect.Right > sourceWidth) sourceRect.Right = sourceWidth;
			if (sourceRect.Top > sourceHeight) sourceRect.Top = sourceHeight;

			if (destRect.Left < cb.Left)
			{
				sourceRect.Left += cb.Left - destRect.Left;
				destRect.Left = cb.Left;
			}
			if (destRect.Bottom < cb.Bottom)
			{
				sourceRect.Bottom += cb.Bottom - destRect.Bottom;
				destRect.Bottom = cb.Bottom;
			}

			if (destRect.Right > cb.Right) destRect.Right = cb.Right;
			if (destRect.Top > cb.Top) destRect.Top = cb.Top;

			rc.Right = destRect.Right - destRect.Left;
			rc.Top = destRect.Top - destRect.Bottom;

			if (rc.Right > sourceRect.Right - sourceRect.Left) rc.Right = sourceRect.Right - sourceRect.Left;
			if (rc.Top > sourceRect.Top - sourceRect.Bottom) rc.Top = sourceRect.Top - sourceRect.Bottom;
			return rc;
		}
コード例 #27
0
    /// <summary>
    /// Returns the tiles inside this rectangle that are touched by other rectangle.
    /// </summary>
    /// <param name="other">A rectangle potentially adjacent to this rectangle.</param>
    /// <param name="discardEdges">Set true to discard tiles on any edges of this Rectangle or the other.</param>
    /// <returns>A list of points from this rectangle that are touched by other. The list will be empty if both rectangles are not adjacent.</returns>
    public List <int2> ContactArea(RectangleInt other, bool discardEdges = false)
    {
        List <int2> result = new List <int2>();

        if (IsAdjacent(other))
        {
            int xMin = 0, xMax = 0, yMin = 0, yMax = 0;
            int xThis = x, yThis = y, widthThis = width, heightThis = height;
            int xOther = other.x, yOther = other.y, widthOther = other.width, heightOther = other.height;

            if (yOther >= yThis + heightThis)
            { // other is on top
                if (discardEdges)
                {
                    xThis++;
                    xOther++;
                    widthThis  -= 2;
                    widthOther -= 2;
                }

                yMin = yMax = yThis + heightThis - 1;
                xMin = Mathf.Max(xThis, xOther);
                xMax = Mathf.Min(xThis + widthThis - 1, xOther + widthOther - 1);
            }
            else if (xOther >= xThis + widthThis)
            { // other is right
                if (discardEdges)
                {
                    yThis++;
                    yOther++;
                    heightThis  -= 2;
                    heightOther -= 2;
                }

                xMin = xMax = xThis + widthThis - 1;
                yMin = Mathf.Max(y, yOther);
                yMax = Mathf.Min(yThis + heightThis - 1, yOther + heightOther - 1);
            }
            else if (yOther + heightOther <= y)
            { // other is down
                if (discardEdges)
                {
                    xThis++;
                    xOther++;
                    widthThis  -= 2;
                    widthOther -= 2;
                }

                yMin = yMax = yThis;
                xMin = Mathf.Max(x, xOther);
                xMax = Mathf.Min(xThis + widthThis - 1, xOther + widthOther - 1);
            }
            else if (xOther + widthOther <= x)
            { // other is left
                if (discardEdges)
                {
                    yThis++;
                    yOther++;
                    heightThis  -= 2;
                    heightOther -= 2;
                }

                xMin = xMax = xThis;
                yMin = Mathf.Max(yThis, yOther);
                yMax = Mathf.Min(yThis + height - 1, yOther + heightOther - 1);
            }

            for (int i = xMin; i <= xMax; i++)
            {
                for (int j = yMin; j <= yMax; j++)
                {
                    result.Add(new int2(i, j));
                }
            }
        }

        return(result);
    }
コード例 #28
0
 public SpriteDefinition AddSpriteDefinition(string spriteName, RectangleInt spriteRectangle, Vector? origin = null)
 {
     var spriteDefinition = new SpriteDefinition(this, spriteName, spriteRectangle, origin);
     this.definitions.Add(spriteName, spriteDefinition);
     return spriteDefinition;
 }
コード例 #29
0
        public static void ServerTrySpawnMobsCustom(
            IProtoCharacter protoMob,
            ICollection <ICharacter> spawnedCollection,
            int countToSpawn,
            RectangleInt excludeBounds,
            int maxSpawnDistanceFromExcludeBounds,
            double noObstaclesCheckRadius,
            int maxAttempts)
        {
            var spawnBounds = excludeBounds.Inflate(maxSpawnDistanceFromExcludeBounds,
                                                    maxSpawnDistanceFromExcludeBounds);
            var physicsSpace = Api.Server.World.GetPhysicsSpace();

            while (maxAttempts-- > 0)
            {
                var position = new Vector2D(spawnBounds.Left + RandomHelper.NextDouble() * spawnBounds.Width,
                                            spawnBounds.Bottom + RandomHelper.NextDouble() * spawnBounds.Height);
                if (IsTooClose(position))
                {
                    continue;
                }

                var character = ServerTrySpawnMob(position);
                if (character == null)
                {
                    // cannot spawn there
                    continue;
                }

                spawnedCollection.Add(character);

                countToSpawn--;
                if (countToSpawn == 0)
                {
                    return;
                }
            }

            bool IsTooClose(in Vector2D position)
            => position.X >= excludeBounds.X &&
            position.Y >= excludeBounds.Y &&
            position.X < excludeBounds.X + excludeBounds.Width &&
            position.Y < excludeBounds.Y + excludeBounds.Height;

            ICharacter ServerTrySpawnMob(Vector2D worldPosition)
            {
                foreach (var _ in physicsSpace.TestCircle(worldPosition,
                                                          radius: noObstaclesCheckRadius,
                                                          CollisionGroups.Default,
                                                          sendDebugEvent: false))
                {
                    // position is not valid for spawning
                    return(null);
                }

                if (!ServerCharacterSpawnHelper.IsValidSpawnTile(
                        Api.Server.World.GetTile(worldPosition.ToVector2Ushort()),
                        checkNeighborTiles: true))
                {
                    return(null);
                }

                return(Api.Server.Characters.SpawnCharacter(protoMob,
                                                            worldPosition));
            }
        }
コード例 #30
0
 public ImageLayer(string name, Texture texture, RectangleInt rectangle)
     : base(name)
 {
     this.Texture = texture;
     this.Rectangle = rectangle;
 }
コード例 #31
0
ファイル: MapSection.cs プロジェクト: drminor/FractalStudio
 public MapSection(RectangleInt rectangleInt)
 {
     SectionAnchor = new Point(rectangleInt.Point.X, rectangleInt.Point.Y);
     CanvasSize    = new CanvasSize(rectangleInt.Size.W, rectangleInt.Size.H);
 }
コード例 #32
0
        public static bool clip_move_point(int x1, int y1, int x2, int y2, 
                             RectangleInt clip_box, 
                             ref int x, ref int y, int flags)
        {
           int bound;

           if ((flags & (int)clipping_flags_e.clipping_flags_x_clipped) != 0)
           {
               if(x1 == x2)
               {
                   return false;
               }
               bound = ((flags & (int)clipping_flags_e.clipping_flags_x1_clipped) != 0) ? clip_box.Left : clip_box.Right;
               y = (int)((double)(bound - x1) * (y2 - y1) / (x2 - x1) + y1);
               x = bound;
           }

           flags = clipping_flags_y(y, clip_box);
           if ((flags & (int)clipping_flags_e.clipping_flags_y_clipped) != 0)
           {
               if(y1 == y2)
               {
                   return false;
               }
               bound = ((flags & (int)clipping_flags_e.clipping_flags_x1_clipped) != 0) ? clip_box.Bottom : clip_box.Top;
               x = (int)((double)(bound - y1) * (x2 - x1) / (y2 - y1) + x1);
               y = bound;
           }
           return true;
        }
コード例 #33
0
ファイル: RayTracer.cs プロジェクト: asmboom/PixelFarm
        public void RayTraceScene(ImageBuffer destImage, RectangleInt viewport, Scene scene)
        {
            int maxsamples = (int)AntiAliasing;

            //graphics2D.FillRectangle(viewport, RGBA_Floats.Black);

            if (imageBufferAsDoubles == null || imageBufferAsDoubles.Length < viewport.Width || imageBufferAsDoubles[0].Length < viewport.Height)
            {
                imageBufferAsDoubles = new RGBA_Floats[viewport.Width][];
                for (int i = 0; i < viewport.Width; i++)
                {
                    imageBufferAsDoubles[i] = new RGBA_Floats[viewport.Height];
                }
            }

            if (destImage.BitDepth != 32)
            {
                throw new Exception("We can only render to 32 bit dest at the moment.");
            }

            Byte[] destBuffer = destImage.GetBuffer();

            viewport.Bottom = Math.Max(0, Math.Min(destImage.Height, viewport.Bottom));
            viewport.Top = Math.Max(0, Math.Min(destImage.Height, viewport.Top));

#if MULTI_THREAD
            System.Threading.Tasks.Parallel.For(viewport.Bottom, viewport.Height, y => //  
#else
            for (int y = viewport.Bottom; y < viewport.Height; y++)
#endif
            {
                for (int x = viewport.Left; x < viewport.Right; x++)
                {
                    if (traceWithRayBundles)
                    {
                        int width = Math.Min(8, viewport.Right - x);
                        int height = Math.Min(8, viewport.Top - y);
                        FrustumRayBundle rayBundle = new FrustumRayBundle(width * height);
                        IntersectInfo[] intersectionsForBundle = new IntersectInfo[width * height];
                        for (int rayY = 0; rayY < height; rayY++)
                        {
                            for (int rayX = 0; rayX < width; rayX++)
                            {
                                rayBundle.rayArray[rayX + rayY * width] = scene.camera.GetRay(x + rayX, y + rayY);
                                intersectionsForBundle[rayX + rayY * width] = new IntersectInfo();
                            }
                        }

                        rayBundle.CalculateFrustum(width, height,  scene.camera.Origin);
                        
                        FullyTraceRayBundle(rayBundle, intersectionsForBundle, scene);

                        for (int rayY = 0; rayY < height; rayY++)
                        {
                            int bufferOffset = destImage.GetBufferOffsetY(y + rayY);

                            for (int rayX = 0; rayX < width; rayX++)
                            {
                                imageBufferAsDoubles[x + rayX][y + rayY] = intersectionsForBundle[rayX + rayY * width].totalColor;

                                if (AntiAliasing == AntiAliasing.None)
                                {
                                    // we don't need to set this if we are anti-aliased
                                    int totalOffset = bufferOffset + (x + rayX) * 4;
                                    destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x + rayX][y + rayY].Blue0To255;
                                    destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x + rayX][y + rayY].Green0To255;
                                    destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x + rayX][y + rayY].Red0To255;
                                    destBuffer[totalOffset] = 255;
                                }
                            }
                        }
                        x += width - 1; // skip all the pixels we bundled
                        y += height - 1; // skip all the pixels we bundled
                    }
                    else
                    {
                        int bufferOffset = destImage.GetBufferOffsetY(y);

                        Ray ray = scene.camera.GetRay(x, y);

                        imageBufferAsDoubles[x][y] = FullyTraceRay(ray, scene);

                        // we don't need to set this if we are anti-aliased
                        int totalOffset = bufferOffset + x * 4;
                        destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x][y].Blue0To255;
                        destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x][y].Green0To255;
                        destBuffer[totalOffset++] = (byte)imageBufferAsDoubles[x][y].Red0To255;
                        destBuffer[totalOffset] = 255;
                    }
                }
            }
コード例 #34
0
        //-------------------------------------------------------clip_line_segment
        // Returns: ret >= 4        - Fully clipped
        //          (ret & 1) != 0  - First point has been moved
        //          (ret & 2) != 0  - Second point has been moved
        //
        //template<class T>
        public static int clip_line_segment(ref int x1, ref int y1, ref int x2, ref int y2,
                                   RectangleInt clip_box)
        {
            int f1 = clipping_flags(x1, y1, clip_box);
            int f2 = clipping_flags(x2, y2, clip_box);
            int ret = 0;

            if((f2 | f1) == 0)
            {
                // Fully visible
                return 0;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_x_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_x_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_x_clipped))
            {
                // Fully clipped
                return 4;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_y_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_y_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_y_clipped))
            {
                // Fully clipped
                return 4;
            }

            int tx1 = x1;
            int ty1 = y1;
            int tx2 = x2;
            int ty2 = y2;
            if(f1 != 0) 
            {   
                if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x1, ref y1, f1)) 
                {
                    return 4;
                }
                if(x1 == x2 && y1 == y2) 
                {
                    return 4;
                }
                ret |= 1;
            }
            if(f2 != 0) 
            {
                if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x2, ref y2, f2))
                {
                    return 4;
                }
                if(x1 == x2 && y1 == y2) 
                {
                    return 4;
                }
                ret |= 2;
            }
            return ret;
        }
コード例 #35
0
        /// <summary>
        /// This method will purge the land in the decayed land claim area.
        /// Please note: there is a small chance that the savegame is made right in the middle of the deletion.
        /// This way when the savegame is loaded the deletion will not resume.
        /// </summary>
        private static async void ServerPurgeStructuresInDestroyedLandClaimArea(
            IStaticWorldObject landClaimStructure,
            RectangleInt areaBounds)
        {
            await Api.Server.Core.AwaitEndOfFrame;

            var logger      = Api.Logger;
            var stopwatch   = Stopwatch.StartNew();
            var tempObjects = new HashSet <IStaticWorldObject>();
            var serverWorld = Api.Server.World;
            var serverItems = Api.Server.Items;

            var yieldIfOutOfTime = (Func <Task>)Api.Server.Core.YieldIfOutOfTime;

            for (var x = areaBounds.X; x < areaBounds.X + areaBounds.Width; x++)
            {
                for (var y = areaBounds.Y; y < areaBounds.Y + areaBounds.Height; y++)
                {
                    if (x < 0 ||
                        y < 0 ||
                        x >= ushort.MaxValue ||
                        y >= ushort.MaxValue)
                    {
                        continue;
                    }

                    var staticObjects = serverWorld.GetStaticObjects(new Vector2Ushort((ushort)x, (ushort)y));
                    foreach (var worldObject in staticObjects)
                    {
                        tempObjects.Add(worldObject);
                    }

                    await yieldIfOutOfTime();
                }
            }

            var objectsDeletedCount   = 0;
            var purgedContainersCount = 0;

            foreach (var worldObject in tempObjects)
            {
                await yieldIfOutOfTime();

                var protoStaticWorldObject = worldObject.ProtoStaticWorldObject;
                if (!(protoStaticWorldObject is IProtoObjectStructure) ||
                    LandClaimSystem.SharedIsObjectInsideAnyArea(worldObject))
                {
                    continue;
                }

                switch (protoStaticWorldObject)
                {
                case IProtoObjectCrate:
                {
                    var privateState = worldObject.GetPrivateState <ObjectCratePrivateState>();
                    PurgeContainer(privateState.ItemsContainer);
                    break;
                }

                case IProtoObjectTradingStation:
                {
                    var privateState = worldObject.GetPrivateState <ObjectTradingStationPrivateState>();
                    PurgeContainer(privateState.StockItemsContainer);
                    break;
                }

                case IProtoObjectBarrel:
                {
                    var privateState = worldObject.GetPrivateState <ProtoBarrelPrivateState>();
                    privateState.LiquidAmount = 0;
                    privateState.LiquidType   = null;
                    PurgeManufacturerContainers(privateState);
                    break;
                }

                case IProtoObjectManufacturer:
                {
                    var privateState = worldObject.GetPrivateState <ObjectManufacturerPrivateState>();
                    PurgeManufacturerContainers(privateState);
                    break;
                }
                }
            }

            if (PveSystem.ServerIsPvE)
            {
                // on PvE server, delete all the structures within the decayed land claim area
                objectsDeletedCount = await ServerDeleteAllStructuresAsync(tempObjects, yieldIfOutOfTime);
            }

            stopwatch.Stop();
            logger.Important(
                $"Land claim decayed (destroyed by decay): {landClaimStructure}. Objects deleted: {objectsDeletedCount}. Item containers purged: {purgedContainersCount}. Time spent: {stopwatch.Elapsed.TotalMilliseconds}ms (spread across multiple frames)");

            void PurgeContainer(IItemsContainer container)
            {
                if (container is null ||
                    container.OccupiedSlotsCount == 0)
                {
                    return;
                }

                logger.Important("Purging items container in the destroyed land claim area: " + container);
                using var items = Api.Shared.WrapInTempList(container.Items);
                foreach (var item in items.AsList())
                {
                    serverItems.DestroyItem(item);
                }

                purgedContainersCount++;
            }

            void PurgeManufacturerContainers(ObjectManufacturerPrivateState privateState)
            {
                PurgeContainer(privateState.ManufacturingState?.ContainerInput);
                PurgeContainer(privateState.ManufacturingState?.ContainerOutput);
                PurgeContainer(privateState.FuelBurningState?.ContainerFuel);
            }
        }
コード例 #36
0
 public static int clipping_flags_x(int x, RectangleInt clip_box)
 {
     return ((x > clip_box.Right ? 1 : 0) | ((x < clip_box.Left ? 1 : 0) << 2));
 }
コード例 #37
0
 public static int clipping_flags_y(int y, RectangleInt clip_box)
 {
     return(((y > clip_box.Top ? 1 : 0) << 1) | ((y < clip_box.Bottom ? 1 : 0) << 3));
 }
コード例 #38
0
 public static int clipping_flags_y(int y, RectangleInt clip_box)
 {
     return (((y > clip_box.Top ? 1 : 0) << 1) | ((y < clip_box.Bottom ? 1 : 0) << 3));
 }
コード例 #39
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		public RectangleInt GetBoundingRect()
		{
			RectangleInt boundingRect = new RectangleInt(0, 0, Width, Height);
			boundingRect.Offset((int)OriginOffset.x, (int)OriginOffset.y);
			return boundingRect;
		}
コード例 #40
0
        public static int clip_liang_barsky(int x1, int y1, int x2, int y2,
                                          RectangleInt clip_box,
                                          int[] x, int[] y)
        {
            int XIndex = 0;
            int YIndex = 0;
            double nearzero = 1e-30;

            double deltax = x2 - x1;
            double deltay = y2 - y1; 
            double xin;
            double xout;
            double yin;
            double yout;
            double tinx;
            double tiny;
            double toutx;
            double touty;  
            double tin1;
            double tin2;
            double tout1;
            int np = 0;

            if(deltax == 0.0) 
            {   
                // bump off of the vertical
                deltax = (x1 > clip_box.Left) ? -nearzero : nearzero;
            }

            if(deltay == 0.0) 
            { 
                // bump off of the horizontal 
                deltay = (y1 > clip_box.Bottom) ? -nearzero : nearzero;
            }
            
            if(deltax > 0.0) 
            {                
                // points to right
                xin = clip_box.Left;
                xout = clip_box.Right;
            }
            else 
            {
                xin = clip_box.Right;
                xout = clip_box.Left;
            }

            if(deltay > 0.0) 
            {
                // points up
                yin = clip_box.Bottom;
                yout = clip_box.Top;
            }
            else 
            {
                yin = clip_box.Top;
                yout = clip_box.Bottom;
            }
            
            tinx = (xin - x1) / deltax;
            tiny = (yin - y1) / deltay;
            
            if (tinx < tiny) 
            {
                // hits x first
                tin1 = tinx;
                tin2 = tiny;
            }
            else
            {
                // hits y first
                tin1 = tiny;
                tin2 = tinx;
            }
            
            if(tin1 <= 1.0) 
            {
                if(0.0 < tin1) 
                {
                    x[XIndex++] = (int)xin;
                    y[YIndex++] = (int)yin;
                    ++np;
                }

                if(tin2 <= 1.0)
                {
                    toutx = (xout - x1) / deltax;
                    touty = (yout - y1) / deltay;
                    
                    tout1 = (toutx < touty) ? toutx : touty;
                    
                    if(tin2 > 0.0 || tout1 > 0.0) 
                    {
                        if(tin2 <= tout1) 
                        {
                            if(tin2 > 0.0) 
                            {
                                if(tinx > tiny) 
                                {
                                    x[XIndex++] = (int)xin;
                                    y[YIndex++] = (int)(y1 + tinx * deltay);
                                }
                                else 
                                {
                                    x[XIndex++] = (int)(x1 + tiny * deltax);
                                    y[YIndex++] = (int)yin;
                                }
                                ++np;
                            }

                            if(tout1 < 1.0) 
                            {
                                if(toutx < touty) 
                                {
                                    x[XIndex++] = (int)xout;
                                    y[YIndex++] = (int)(y1 + toutx * deltay);
                                }
                                else 
                                {
                                    x[XIndex++] = (int)(x1 + touty * deltax);
                                    y[YIndex++] = (int)yout;
                                }
                            }
                            else 
                            {
                                x[XIndex++] = x2;
                                y[YIndex++] = y2;
                            }
                            ++np;
                        }
                        else 
                        {
                            if(tinx > tiny) 
                            {
                                x[XIndex++] = (int)xin;
                                y[YIndex++] = (int)yout;
                            }
                            else 
                            {
                                x[XIndex++] = (int)xout;
                                y[YIndex++] = (int)yin;
                            }
                            ++np;
                        }
                    }
                }
            }
            return np;
        }
コード例 #41
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		public bool Attach(IImageByte sourceImage, int x1, int y1, int x2, int y2)
		{
			m_ByteBuffer = null;
			DettachBuffer();

			if (x1 > x2 || y1 > y2)
			{
				throw new Exception("You need to have your x1 and y1 be the lower left corner of your sub image.");
			}
			RectangleInt boundsRect = new RectangleInt(x1, y1, x2, y2);
			if (boundsRect.clip(new RectangleInt(0, 0, (int)sourceImage.Width - 1, (int)sourceImage.Height - 1)))
			{
				SetDimmensionAndFormat(boundsRect.Width, boundsRect.Height, sourceImage.StrideInBytes(), sourceImage.BitDepth, sourceImage.GetBytesBetweenPixelsInclusive(), false);
				int bufferOffset = sourceImage.GetBufferOffsetXY(boundsRect.Left, boundsRect.Bottom);
				byte[] buffer = sourceImage.GetBuffer();
				SetBuffer(buffer, bufferOffset);
				return true;
			}

			return false;
		}
コード例 #42
0
ファイル: Day24.cs プロジェクト: w200338/Advent-of-Code-2019
        private int CountNeighbours(List <GridDepth> grids, Vector3Int position)
        {
            int output = 0;

            RectangleInt bounds = new RectangleInt(Vector2Int.Zero, new Vector2Int(4, 4));
            Vector2Int   pos2D  = new Vector2Int(position.X, position.Y);

            // check direct neighbours
            foreach (Vector2Int neighbour in Around(pos2D))
            {
                if (neighbour != new Vector2Int(2, 2) && bounds.IsInRectangle(neighbour))
                {
                    if (grids.FirstOrDefault(g => g.Depth == position.Z)?.Grid[neighbour.Y][neighbour.X] == '#')
                    //if (grids[depthIndex].Grid[neighbour.Y][neighbour.X] == '#')
                    {
                        output++;
                    }
                }
            }

            // check depth below
            if (pos2D == new Vector2Int(2, 1))
            {
                for (int i = 0; i < 5; i++)
                {
                    output += grids.FirstOrDefault(g => g.Depth == position.Z + 1)?.Grid[0][i] == '#' ? 1 : 0;
                    //output += grids[depthIndex + 1]?.Grid[0][i] == '#' ? 1 : 0;
                }
            }
            else if (pos2D == new Vector2Int(1, 2))
            {
                for (int i = 0; i < 5; i++)
                {
                    output += grids.FirstOrDefault(g => g.Depth == position.Z + 1)?.Grid[i][0] == '#' ? 1 : 0;
                    //output += grids[depthIndex + 1].Grid[i][0] == '#' ? 1 : 0;
                }
            }
            else if (pos2D == new Vector2Int(3, 2))
            {
                for (int i = 0; i < 5; i++)
                {
                    output += grids.FirstOrDefault(g => g.Depth == position.Z + 1)?.Grid[i][4] == '#' ? 1 : 0;
                    //output += grids[depthIndex + 1].Grid[i][4] == '#' ? 1 : 0;
                }
            }
            else if (pos2D == new Vector2Int(2, 3))
            {
                for (int i = 0; i < 5; i++)
                {
                    output += grids.FirstOrDefault(g => g.Depth == position.Z + 1)?.Grid[4][i] == '#' ? 1 : 0;
                    //output += grids[depthIndex + 1].Grid[4][i] == '#' ? 1 : 0;
                }
            }

            // check depth above
            if (position.X == 0)
            {
                output += grids.FirstOrDefault(g => g.Depth == position.Z - 1)?.Grid[2][1] == '#' ? 1 : 0;
                //output += grids[depthIndex - 1].Grid[2][1] == '#' ? 1 : 0;
            }
            else if (position.X == 4)
            {
                output += grids.FirstOrDefault(g => g.Depth == position.Z - 1)?.Grid[2][3] == '#' ? 1 : 0;
                //output += grids[depthIndex - 1].Grid[2][3] == '#' ? 1 : 0;
            }

            if (position.Y == 0)
            {
                output += grids.FirstOrDefault(g => g.Depth == position.Z - 1)?.Grid[1][2] == '#' ? 1 : 0;
                //output += grids[depthIndex - 1].Grid[1][2] == '#' ? 1 : 0;
            }
            else if (position.Y == 4)
            {
                output += grids.FirstOrDefault(g => g.Depth == position.Z - 1)?.Grid[3][2] == '#' ? 1 : 0;
                //output += grids[depthIndex - 1].Grid[3][2] == '#' ? 1 : 0;
            }

            return(output);
        }
コード例 #43
0
ファイル: ImageBuffer.cs プロジェクト: glocklueng/agg-sharp
		public void CopyFrom(IImageByte sourceImage, RectangleInt sourceImageRect, int destXOffset, int destYOffset)
		{
			RectangleInt sourceImageBounds = sourceImage.GetBounds();
			RectangleInt clippedSourceImageRect = new RectangleInt();
			if (clippedSourceImageRect.IntersectRectangles(sourceImageRect, sourceImageBounds))
			{
				RectangleInt destImageRect = clippedSourceImageRect;
				destImageRect.Offset(destXOffset, destYOffset);
				RectangleInt destImageBounds = GetBounds();
				RectangleInt clippedDestImageRect = new RectangleInt();
				if (clippedDestImageRect.IntersectRectangles(destImageRect, destImageBounds))
				{
					// we need to make sure the source is also clipped to the dest. So, we'll copy this back to source and offset it.
					clippedSourceImageRect = clippedDestImageRect;
					clippedSourceImageRect.Offset(-destXOffset, -destYOffset);
					CopyFromNoClipping(sourceImage, clippedSourceImageRect, destXOffset, destYOffset);
				}
			}
		}
コード例 #44
0
ファイル: Day24.cs プロジェクト: w200338/Advent-of-Code-2019
        /// <inheritdoc />
        public string Part1()
        {
            List <int> bioRatings = new List <int>();

            bioRatings.Add(CalcScore(inputGrid));
            RectangleInt bounds = new RectangleInt(Vector2Int.Zero, new Vector2Int(4, 4));

            // do a step
            while (true)
            {
                List <List <char> > newGrid = new List <List <char> >();

                for (int i = 0; i < inputGrid.Count; i++)
                {
                    newGrid.Add(new List <char>());

                    for (int j = 0; j < inputGrid[0].Count; j++)
                    {
                        // check neighbours
                        int neighbourCount = 0;
                        foreach (Vector2Int neighbour in Around(new Vector2Int(j, i)))
                        {
                            if (bounds.IsInRectangle(neighbour))
                            {
                                if (inputGrid[neighbour.Y][neighbour.X] == '#')
                                {
                                    neighbourCount++;
                                }
                            }
                        }

                        // add or remove creature
                        if (inputGrid[i][j] == '#')
                        {
                            newGrid[i].Add(neighbourCount == 1 ? '#' : '.');
                        }
                        else
                        {
                            if (neighbourCount == 1 || neighbourCount == 2)
                            {
                                newGrid[i].Add('#');
                            }
                            else
                            {
                                newGrid[i].Add('.');
                            }
                        }

                        //newGrid[i].Add()
                    }
                }

                // print board

                // calc bio rating
                int bioRating = CalcScore(newGrid);

                // check if it already existed
                if (bioRatings.Contains(bioRating))
                {
                    return(bioRating.ToString());
                }

                bioRatings.Add(bioRating);

                inputGrid = newGrid;
            }

            return($"");
        }
コード例 #45
0
ファイル: ImageProxy.cs プロジェクト: annafeldman/agg-sharp
 public virtual void CopyFrom(IImageFloat sourceImage, RectangleInt sourceImageRect, int destXOffset, int destYOffset)
 {
     linkedImage.CopyFrom(sourceImage, sourceImageRect, destXOffset, destYOffset);
 }
コード例 #46
0
ファイル: ImageProxy.cs プロジェクト: CNCBrasil/agg-sharp
		public virtual void CopyFrom(IImageFloat sourceImage, RectangleInt sourceImageRect, int destXOffset, int destYOffset)
		{
			linkedImage.CopyFrom(sourceImage, sourceImageRect, destXOffset, destYOffset);
		}
コード例 #47
0
        public RectangleInt clip_rect_area(ref RectangleInt destRect, ref RectangleInt sourceRect, int sourceWidth, int sourceHeight)
        {
            RectangleInt rc = new RectangleInt(0, 0, 0, 0);
            RectangleInt cb = clip_box();

            ++cb.Right;
            ++cb.Top;

            if (sourceRect.Left < 0)
            {
                destRect.Left  -= sourceRect.Left;
                sourceRect.Left = 0;
            }
            if (sourceRect.Bottom < 0)
            {
                destRect.Bottom  -= sourceRect.Bottom;
                sourceRect.Bottom = 0;
            }

            if (sourceRect.Right > sourceWidth)
            {
                sourceRect.Right = sourceWidth;
            }
            if (sourceRect.Top > sourceHeight)
            {
                sourceRect.Top = sourceHeight;
            }

            if (destRect.Left < cb.Left)
            {
                sourceRect.Left += cb.Left - destRect.Left;
                destRect.Left    = cb.Left;
            }
            if (destRect.Bottom < cb.Bottom)
            {
                sourceRect.Bottom += cb.Bottom - destRect.Bottom;
                destRect.Bottom    = cb.Bottom;
            }

            if (destRect.Right > cb.Right)
            {
                destRect.Right = cb.Right;
            }
            if (destRect.Top > cb.Top)
            {
                destRect.Top = cb.Top;
            }

            rc.Right = destRect.Right - destRect.Left;
            rc.Top   = destRect.Top - destRect.Bottom;

            if (rc.Right > sourceRect.Right - sourceRect.Left)
            {
                rc.Right = sourceRect.Right - sourceRect.Left;
            }
            if (rc.Top > sourceRect.Top - sourceRect.Bottom)
            {
                rc.Top = sourceRect.Top - sourceRect.Bottom;
            }
            return(rc);
        }
コード例 #48
0
 public HexDefinition(HexSheet sheet, string name, RectangleInt rectangle)
 {
     this.Sheet = sheet;
     this.Name = name;
     this.Rectangle = rectangle;
 }
コード例 #49
0
 public override void LinkToImage(IImageFloat ren)
 {
     base.LinkToImage(ren);
     m_ClippingRect = new RectangleInt(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
 }
コード例 #50
0
ファイル: RoundedRect.cs プロジェクト: CNCBrasil/agg-sharp
		public RoundedRect(RectangleInt bounds, double r)
			: this(bounds.Left, bounds.Bottom, bounds.Right, bounds.Top, r)
		{
		}
コード例 #51
0
ファイル: RoundedRect.cs プロジェクト: annafeldman/agg-sharp
 public RoundedRect(RectangleInt bounds, double r)
     : this(bounds.Left, bounds.Bottom, bounds.Right, bounds.Top, r)
 {
 }
コード例 #52
0
 private void Init(int x, int y, int width, int height)
 {
     connections = new Dictionary <int2, Zone>();
     tiles       = new HashSet <int2>();
     bounds      = new RectangleInt(x, y, width, height);
 }
コード例 #53
0
ファイル: GUIWidget.cs プロジェクト: eriser/agg-sharp
		public void SetBoundsRelativeToParent(RectangleInt newBounds)
		{
			RectangleDouble bounds = new RectangleDouble(newBounds.Left, newBounds.Bottom, newBounds.Right, newBounds.Top);

			BoundsRelativeToParent = bounds;
		}
コード例 #54
0
 public bool IsAdjacent(RectangleInt other)
 {
     return(((y + height == other.y || y == other.y + other.height) && (x < other.x + other.width || x + width > other.x)) ||
            ((x + width == other.x || x == other.x + other.width) && (y < other.y + other.height || y + height > other.y)));
 }