示例#1
0
        private void Clear()
        {
            ClientName     = ServiceName = Password = tieBreaker = sslHost = configChannel = null;
            keepAlive      = syncTimeout = asyncTimeout = connectTimeout = writeBuffer = connectRetry = configCheckSeconds = DefaultDatabase = null;
            allowAdmin     = abortOnConnectFail = highPrioritySocketThreads = resolveDns = ssl = null;
            defaultVersion = null;
            EndPoints.Clear();
            commandMap = null;

            CertificateSelection  = null;
            CertificateValidation = null;
            ChannelPrefix         = default(RedisChannel);
            SocketManager         = null;
        }
示例#2
0
        public void Clear(Shadow2DLight shadow2DLight)
        {
            Segments.Clear();
            EndPoints.Clear();
            Open.Clear();
            Output.Clear();

            Center = shadow2DLight.transform.position;
            Size   = shadow2DLight.size;
            Color  = shadow2DLight.color;

            MergeCollinearSegments = shadow2DLight.mergeCollinearShadowSegments;

            float top   = Size / 2f;
            float btm   = -Size / 2f;
            float left  = -Size / 2f;
            float right = Size / 2f;

            TopLeft     = shadow2DLight.transform.TransformPoint(new Vector3(left, top, 0f));
            BottomLeft  = shadow2DLight.transform.TransformPoint(new Vector3(left, btm, 0f));
            BottomRight = shadow2DLight.transform.TransformPoint(new Vector3(right, btm, 0f));
            _drawGizmos = shadow2DLight._drawGizmos;
            _clipping   = shadow2DLight.clipping;
        }
示例#3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (!DesignMode && EndPaintObjects != null && BeginPaintObjects != null)
            {
                BeginPoints.Clear();
                EndPoints.Clear();
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                var top           = 40F;
                var beginHeight   = 40F;
                var maxBeginWidth = 0F;
                foreach (var beginObject in BeginPaintObjects)
                {
                    var beginSize = beginObject.Paint(e.Graphics, BeginPoints, EndPoints, 40, top);
                    if (maxBeginWidth < beginSize.Width)
                    {
                        maxBeginWidth = beginSize.Width;
                    }
                    top         += beginSize.Height + 10;
                    beginHeight += beginSize.Height + 10;
                }

                var endHeight    = 40F;
                var controlWidth = maxBeginWidth + 240;
                foreach (var endObject in EndPaintObjects)
                {
                    var endSize = endObject.Paint(e.Graphics, BeginPoints, EndPoints, maxBeginWidth + 240, endHeight);
                    if (controlWidth < maxBeginWidth + 240 + endSize.Width + 10)
                    {
                        controlWidth = maxBeginWidth + 240 + endSize.Width + 10;
                    }
                    endHeight += endSize.Height + 10;
                }
                var controlHeight = Math.Max(endHeight, beginHeight);

                foreach (var beginPoint in BeginPoints)
                {
                    foreach (var endPoint in EndPoints)
                    {
                        var ev = new UpdateConnectEventArgs(beginPoint, endPoint);
                        UpdateConnect(this, ev);
                        if (ev.IsConnect)
                        {
                            e.Graphics.DrawLine(new Pen(ev.ConnectorColor), endPoint.Position, beginPoint.Position);
                        }
                    }
                }

                if (BeginPoint != null)
                {
                    var beginPos = BeginPoint.Position;
                    e.Graphics.DrawEllipse(Pens.Blue, beginPos.X - 5, beginPos.Y - 5, 10, 10);
                    if (EndPoint != null)
                    {
                        var endPos = EndPoint.Position;
                        e.Graphics.DrawEllipse(Pens.Blue, endPos.X - 5, endPos.Y - 5, 10, 10);
                        e.Graphics.DrawLine(Pens.Blue, beginPos.X, beginPos.Y, endPos.X, endPos.Y);
                    }
                    else
                    {
                        e.Graphics.DrawLine(Pens.Blue, beginPos.X, beginPos.Y, EndMousePoint.X, EndMousePoint.Y);
                    }
                }

                Size = new Size(Convert.ToInt32(controlWidth), Convert.ToInt32(controlHeight));
            }
        }
示例#4
0
        private bool InitializePanel()
        {
            if (panel != null)
            {
                Walls.Clear();
                StartPoints.Clear();
                EndPoints.Clear();
                renderedTetrisTextures.Clear();

                PuzzleDimensions = new Point(panel.Width, panel.Height);

                // Calculation of puzzle sizes for current screen size
                int width  = screenSize.X;
                int height = screenSize.Y;

                int maxPuzzleDimension = Math.Max(PuzzleDimensions.X, PuzzleDimensions.Y);

                int screenMinSize = Math.Min(width, height);
                int puzzleMaxSize = (int)(screenMinSize * PuzzleSpaceRatio(maxPuzzleDimension));
                LineWidth          = (int)(puzzleMaxSize * LineSizeRatio(maxPuzzleDimension));
                BlockWidth         = (int)(puzzleMaxSize * BlockSizeRatio(maxPuzzleDimension));
                HalfLineWidthPoint = new Point(LineWidth / 2);
                LineWidthPoint     = new Point(LineWidth);
                BlockSizePoint     = new Point(BlockWidth);

                int endAppendixLength = (int)(BlockWidth * endPointLegth);

                int puzzleWidth  = LineWidth * (PuzzleDimensions.X + 1) + BlockWidth * PuzzleDimensions.X;
                int puzzleHeight = LineWidth * (PuzzleDimensions.Y + 1) + BlockWidth * PuzzleDimensions.Y;

                int   xMargin = (width - puzzleWidth) / 2;
                int   yMargin = (height - puzzleHeight) / 2;
                Point margins = new Point(xMargin, yMargin);

                PuzzleConfig = new Rectangle(xMargin, yMargin, puzzleWidth, puzzleHeight);

                NodePadding = LineWidth + BlockWidth;

                // Creating walls hitboxes
                CreateHorizontalWalls(false);   // Top walls
                CreateHorizontalWalls(true);    // Bottom walls
                CreateVerticalWalls(false);     // Left walls
                CreateVerticalWalls(true);      // Right walls

                for (int i = 0; i < PuzzleDimensions.X; i++)
                {
                    for (int j = 0; j < PuzzleDimensions.Y; j++)
                    {
                        Walls.Add(new Rectangle(xMargin + LineWidth * (i + 1) + BlockWidth * i, yMargin + LineWidth * (j + 1) + BlockWidth * j, BlockWidth, BlockWidth));
                    }
                }

                // Creating walls for broken edges
                var brokenEdges = panel.Edges.Where(x => x.State == EdgeState.Broken);
                foreach (Edge edge in brokenEdges)
                {
                    Point nodeA  = NodeIdToPoint(edge.Id % 100).Multiply(NodePadding) + margins;
                    Point nodeB  = NodeIdToPoint(edge.Id / 100).Multiply(NodePadding) + margins;
                    Point middle = (nodeA + nodeB).Divide(2);
                    Walls.Add(new Rectangle(middle, new Point(LineWidth)));
                }

                // Creating hitboxes for starting nodes
                foreach (Point start in GetStartNodes())
                {
                    StartPoints.Add(new Rectangle(xMargin + start.X * NodePadding - LineWidth, yMargin + start.Y * NodePadding - LineWidth, LineWidth * 3, LineWidth * 3));
                }

                // Generate textures for tetris rules
                CreateTetrisRuleTextures();

                #region === Inner methods region ===
                // Returns a coef k: Total free space in pixels * k = puzzle size in pixels
                float PuzzleSpaceRatio(float puzzleDimension) => (float)(-0.0005 * Math.Pow(puzzleDimension, 4) + 0.0082 * Math.Pow(puzzleDimension, 3) - 0.0439 * Math.Pow(puzzleDimension, 2) + 0.1011 * puzzleDimension + 0.6875);

                // Returns a coef k: Puzzle size in pixels * k = block size in pixels
                float BlockSizeRatio(float puzzleDimension) => (float)(0.8563 * Math.Pow(puzzleDimension, -1.134));

                // Returns a coef k: Puzzle size in pixels * k = line width in pixels
                float LineSizeRatio(float puzzleDimension) => - 0.0064f * puzzleDimension + 0.0859f;

                IEnumerable <Point> GetStartNodes() => panel.Nodes.Where(x => x.State == NodeState.Start).Select(x => NodeIdToPoint(x.Id));

                IEnumerable <Point> GetEndNodesTop()
                {
                    for (int i = 1; i < panel.Width; i++)
                    {
                        if (panel.Nodes[i].State == NodeState.Exit)
                        {
                            yield return(new Point(i, 0));
                        }
                    }
                }

                IEnumerable <Point> GetEndNodesBot()
                {
                    for (int i = 1; i < panel.Width; i++)
                    {
                        int index = panel.Height * (panel.Width + 1) + i;
                        if (panel.Nodes[index].State == NodeState.Exit)
                        {
                            yield return(new Point(i, panel.Height));
                        }
                    }
                }

                IEnumerable <Point> GetEndNodesLeft()
                {
                    for (int j = 0; j < panel.Height + 1; j++)
                    {
                        int index = j * (panel.Width + 1);
                        if (panel.Nodes[index].State == NodeState.Exit)
                        {
                            yield return(new Point(0, j));
                        }
                    }
                }

                IEnumerable <Point> GetEndNodesRight()
                {
                    for (int j = 0; j < panel.Height + 1; j++)
                    {
                        int index = j * (panel.Width + 1) + panel.Width;
                        if (panel.Nodes[index].State == NodeState.Exit)
                        {
                            yield return(new Point(panel.Width, j));
                        }
                    }
                }

                void CreateHorizontalWalls(bool isBottom)
                {
                    int yStartPoint = isBottom ? yMargin + puzzleHeight : 0;
                    var ends        = isBottom ? GetEndNodesBot() : GetEndNodesTop();

                    if (ends.Count() == 0)
                    {
                        Walls.Add(new Rectangle(0, yStartPoint, width, yMargin));
                    }
                    else
                    {
                        Walls.Add(new Rectangle(0, yStartPoint + (isBottom ? endAppendixLength : 0), width, yMargin - endAppendixLength));

                        int lastXPoint = 0;
                        foreach (Point endPoint in ends)
                        {
                            int x = xMargin + endPoint.X * (NodePadding);
                            Walls.Add(new Rectangle(lastXPoint, isBottom ? yStartPoint : (yMargin - endAppendixLength), x - lastXPoint, endAppendixLength));
                            EndPoints.Add(new EndPoint(new Rectangle(x, isBottom ? yStartPoint + endAppendixLength - LineWidth : (yMargin - endAppendixLength), LineWidth, LineWidth), isBottom ? Facing.Down : Facing.Up));
                            lastXPoint = x + LineWidth;
                        }
                        Walls.Add(new Rectangle(lastXPoint, isBottom ? yStartPoint : (yMargin - endAppendixLength), width - lastXPoint, endAppendixLength));
                    }
                }

                void CreateVerticalWalls(bool isRight)
                {
                    int xStartPoint = isRight ? xMargin + puzzleWidth : 0;
                    var ends        = isRight ? GetEndNodesRight() : GetEndNodesLeft();

                    if (ends.Count() == 0)
                    {
                        Walls.Add(new Rectangle(xStartPoint, 0, xMargin, height));
                    }
                    else
                    {
                        Walls.Add(new Rectangle(xStartPoint + (isRight ? endAppendixLength : 0), 0, xMargin - endAppendixLength, height));

                        int lastYPoint = 0;
                        foreach (Point endPoint in ends)
                        {
                            int y = yMargin + endPoint.Y * (NodePadding);
                            Walls.Add(new Rectangle(isRight ? xStartPoint : (xMargin - endAppendixLength), lastYPoint, endAppendixLength, y - lastYPoint));
                            EndPoints.Add(new EndPoint(new Rectangle(isRight ? xStartPoint + endAppendixLength - LineWidth : xMargin - endAppendixLength, y, LineWidth, LineWidth), isRight ? Facing.Right : Facing.Left));
                            lastYPoint = y + LineWidth;
                        }
                        Walls.Add(new Rectangle(isRight ? xStartPoint : (xMargin - endAppendixLength), lastYPoint, endAppendixLength, height - lastYPoint));
                    }
                }

                void CreateTetrisRuleTextures()
                {
                    // Render shape into texture for each tetris rule
                    var tetrisBlocks = panel.Blocks.Where(x => x.Rule is TetrisRule).ToList();

                    if (tetrisBlocks.Count > 0)
                    {
                        int maxDimension = tetrisBlocks.Select(x => x.Rule as TetrisRule).Select(x => Math.Max(x.Shape.GetLength(0), x.Shape.GetLength(1))).Max();
                        if (maxDimension < 3)
                        {
                            maxDimension++;
                        }
                        tetrisTextureSize = new Point((maxDimension + 1) * texTetris[0].Width);
                        foreach (Block block in tetrisBlocks)
                        {
                            TetrisRule rule = block.Rule as TetrisRule;
                            bool[,] shape = rule.Shape;
                            // If shape is rotatable, then rotate it randomly before render
                            if (rule is TetrisRotatableRule r)
                            {
                                shape = TetrisRotatableRule.RotateShapeCW(shape, rnd.Next(0, 4));
                            }
                            // Draw shape on a texture
                            RenderTarget2D texture = CreateTetrisTexture(shape, rule is TetrisRotatableRule, rule.IsSubtractive);
                            // Save it to the dictionary
                            renderedTetrisTextures.Add(block.Id, texture);
                        }
                    }
                }

                #endregion
                return(true);
            }
            return(false);
        }