Esempio n. 1
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 topLeft, Vector2 bottomRight, int row, int column)
        {
            bool    colorSwap   = values[row, column] < 0;
            Color32 colorTop    = colors[row % colorCount, colorSwap ? 1 : 0] * color;
            Color32 colorBottom = colors[row % colorCount, colorSwap ? 0 : 1] * color;

            Bar bar = new Bar();

            bar.firstVertex = Vertices.Count;
            bar.row         = row;
            bar.column      = column;
            bar.rect        = new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
            bars.Add(bar);

            Vertices.Add(topLeft);
            VertexColors.Add(colorTop);

            Vertices.Add(new Vector3(bottomRight.x, topLeft.y, 0));
            VertexColors.Add(colorTop);

            Vertices.Add(bottomRight);
            VertexColors.Add(colorBottom);

            Vertices.Add(new Vector3(topLeft.x, bottomRight.y, 0));
            VertexColors.Add(colorBottom);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public virtual bool Equals(Material other)
 {
     if (other == null)
     {
         return(false);
     }
     return(AlphaTest.Equals(other.AlphaTest) &&
            Blending.Equals(other.Blending) &&
            ClipIntersections.Equals(other.ClipIntersections) &&
            ClipShadows.Equals(other.ClipShadows) &&
            ColorWrite.Equals(other.ColorWrite) &&
            DepthTest.Equals(other.DepthTest) &&
            DepthWrite.Equals(other.DepthWrite) &&
            Dithering.Equals(other.Dithering) &&
            FlatShading.Equals(other.FlatShading) &&
            Fog.Equals(other.Fog) &&
            Lights.Equals(other.Lights) &&
            Opacity.Equals(other.Opacity) &&
            Overdraw.Equals(other.Overdraw) &&
            PremultipliedAlpha.Equals(other.PremultipliedAlpha) &&
            Side.Equals(other.Side) &&
            Transparent.Equals(other.Transparent) &&
            VertexColors.Equals(other.VertexColors) &&
            Visible.Equals(other.Visible) &&
            UserData == other.UserData &&
            ClippingPlanes == other.ClippingPlanes &&
            string.Equals(Precision, other.Precision));
 }
Esempio n. 3
0
 private void SetColors(int numOfVertexes)
 {
     for (int i = 0; i < numOfVertexes; i++)
     {
         Color color = Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
         VertexColors.Add(color);
     }
 }
Esempio n. 4
0
 ///<summary>
 /// Add triangle with colors
 ///</summary>
 void AddTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Color32 color1, Color32 color2)
 {
     Vertices.Add(p1);
     Vertices.Add(p2);
     Vertices.Add(p3);
     VertexColors.Add(color1);
     VertexColors.Add(color2);
     VertexColors.Add(color2);
     Triangles.Add(Vertices.Count - 3);
     Triangles.Add(Vertices.Count - 2);
     Triangles.Add(Vertices.Count - 1);
 }
        private void Visit([NotNull] TVertex u, int depth)
        {
            Debug.Assert(u != null);

            if (depth > MaxDepth)
            {
                return;
            }

            VertexColors[u] = GraphColor.Gray;
            OnDiscoverVertex(u);

            ICancelManager cancelManager = Services.CancelManager;

            foreach (TEdge edge in VisitedGraph.OutEdges(u))
            {
                if (cancelManager.IsCancelling)
                {
                    return;
                }

                OnExamineEdge(edge);
                TVertex v = edge.Target;

                if (!VertexColors.TryGetValue(v, out GraphColor vColor))
                {
                    OnTreeEdge(edge);
                    Visit(v, depth + 1);
                }
                else
                {
                    if (vColor == GraphColor.Gray)
                    {
                        OnBackEdge(edge);
                    }
                    else
                    {
                        OnForwardOrCrossEdge(edge);
                    }
                }
            }

            VertexColors[u] = GraphColor.Black;
            OnVertexFinished(u);
        }
Esempio n. 6
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color1, Color32 color2)
        {
            float z = mode_3d ? -size.z / 2 : 0.0f;

            Vertices.Add(new Vector3(p0.x * size.x, p0.y * size.y, z));
            Vertices.Add(new Vector3(p1.x * size.x, p1.y * size.y, z));
            Vertices.Add(new Vector3(p2.x * size.x, p2.y * size.y, z));
            Vertices.Add(new Vector3(p3.x * size.x, p3.y * size.y, z));
            VertexColors.Add(color1);
            VertexColors.Add(color2);
            VertexColors.Add(color2);
            VertexColors.Add(color1);
            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
        }
Esempio n. 7
0
 public void Clear()
 {
     if (Vertices != null)
     {
         Vertices.Clear();
     }
     if (Uvs != null)
     {
         Uvs.Clear();
     }
     if (VertexColors != null)
     {
         VertexColors.Clear();
     }
     if (Triangles != null)
     {
         Triangles.Clear();
     }
 }
Esempio n. 8
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color1, Color32 color2)
        {
            Vertices.Add(new Vector3(p0.x * rectTransform.rect.width, p0.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p1.x * rectTransform.rect.width, p1.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p2.x * rectTransform.rect.width, p2.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p3.x * rectTransform.rect.width, p3.y * rectTransform.rect.height, 0));

            VertexColors.Add(color1);
            VertexColors.Add(color2);
            VertexColors.Add(color2);
            VertexColors.Add(color1);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Esempio n. 9
0
		///<summary>
		/// Add a quad
		///</summary>
		void AddQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 color1, Color32 color2)
		{
			Vertices.Add(a);
			Vertices.Add(b);
			Vertices.Add(c);
			Vertices.Add(d);

			VertexColors.Add(color1);
			VertexColors.Add(color1);
			VertexColors.Add(color2);
			VertexColors.Add(color2);

			Triangles.Add(Vertices.Count - 4);
			Triangles.Add(Vertices.Count - 3);
			Triangles.Add(Vertices.Count - 2);

			Triangles.Add(Vertices.Count - 3);
			Triangles.Add(Vertices.Count - 1);
			Triangles.Add(Vertices.Count - 2);
		}
Esempio n. 10
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color)
        {
            Vertices.Add(p0);
            VertexColors.Add(color);

            Vertices.Add(p1);
            VertexColors.Add(color);

            Vertices.Add(p2);
            VertexColors.Add(color);

            Vertices.Add(p3);
            VertexColors.Add(color);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Esempio n. 11
0
        public static void GetCornerColors(int centerX, int centerY, out VertexColors vertices, float scale = 1f)
        {
            vertices = default(VertexColors);
            Vector3 color  = _activeEngine.GetColor(centerX, centerY);
            Vector3 color2 = _activeEngine.GetColor(centerX, centerY - 1);
            Vector3 color3 = _activeEngine.GetColor(centerX, centerY + 1);
            Vector3 color4 = _activeEngine.GetColor(centerX - 1, centerY);
            Vector3 color5 = _activeEngine.GetColor(centerX + 1, centerY);
            Vector3 color6 = _activeEngine.GetColor(centerX - 1, centerY - 1);
            Vector3 color7 = _activeEngine.GetColor(centerX + 1, centerY - 1);
            Vector3 color8 = _activeEngine.GetColor(centerX - 1, centerY + 1);
            Vector3 color9 = _activeEngine.GetColor(centerX + 1, centerY + 1);
            float   num    = GlobalBrightness * scale * 63.75f;
            int     num2   = (int)((color2.X + color6.X + color4.X + color.X) * num);
            int     num3   = (int)((color2.Y + color6.Y + color4.Y + color.Y) * num);
            int     num4   = (int)((color2.Z + color6.Z + color4.Z + color.Z) * num);

            if (num2 > 255)
            {
                num2 = 255;
            }
            if (num3 > 255)
            {
                num3 = 255;
            }
            if (num4 > 255)
            {
                num4 = 255;
            }
            num3 <<= 8;
            num4 <<= 16;
            vertices.TopLeftColor.PackedValue = (uint)(num2 | num3 | num4) | 0xFF000000u;
            num2 = (int)((color2.X + color7.X + color5.X + color.X) * num);
            num3 = (int)((color2.Y + color7.Y + color5.Y + color.Y) * num);
            num4 = (int)((color2.Z + color7.Z + color5.Z + color.Z) * num);
            if (num2 > 255)
            {
                num2 = 255;
            }
            if (num3 > 255)
            {
                num3 = 255;
            }
            if (num4 > 255)
            {
                num4 = 255;
            }
            num3 <<= 8;
            num4 <<= 16;
            vertices.TopRightColor.PackedValue = (uint)(num2 | num3 | num4) | 0xFF000000u;
            num2 = (int)((color3.X + color8.X + color4.X + color.X) * num);
            num3 = (int)((color3.Y + color8.Y + color4.Y + color.Y) * num);
            num4 = (int)((color3.Z + color8.Z + color4.Z + color.Z) * num);
            if (num2 > 255)
            {
                num2 = 255;
            }
            if (num3 > 255)
            {
                num3 = 255;
            }
            if (num4 > 255)
            {
                num4 = 255;
            }
            num3 <<= 8;
            num4 <<= 16;
            vertices.BottomLeftColor.PackedValue = (uint)(num2 | num3 | num4) | 0xFF000000u;
            num2 = (int)((color3.X + color9.X + color5.X + color.X) * num);
            num3 = (int)((color3.Y + color9.Y + color5.Y + color.Y) * num);
            num4 = (int)((color3.Z + color9.Z + color5.Z + color.Z) * num);
            if (num2 > 255)
            {
                num2 = 255;
            }
            if (num3 > 255)
            {
                num3 = 255;
            }
            if (num4 > 255)
            {
                num4 = 255;
            }
            num3 <<= 8;
            num4 <<= 16;
            vertices.BottomRightColor.PackedValue = (uint)(num2 | num3 | num4) | 0xFF000000u;
        }
Esempio n. 12
0
        public static void GetCornerColors(
            int centerX,
            int centerY,
            out VertexColors vertices,
            float scale = 1f)
        {
            vertices = new VertexColors();
            int     x      = centerX;
            int     y      = centerY;
            Vector3 color1 = Lighting._activeEngine.GetColor(x, y);
            Vector3 color2 = Lighting._activeEngine.GetColor(x, y - 1);
            Vector3 color3 = Lighting._activeEngine.GetColor(x, y + 1);
            Vector3 color4 = Lighting._activeEngine.GetColor(x - 1, y);
            Vector3 color5 = Lighting._activeEngine.GetColor(x + 1, y);
            Vector3 color6 = Lighting._activeEngine.GetColor(x - 1, y - 1);
            Vector3 color7 = Lighting._activeEngine.GetColor(x + 1, y - 1);
            Vector3 color8 = Lighting._activeEngine.GetColor(x - 1, y + 1);
            Vector3 color9 = Lighting._activeEngine.GetColor(x + 1, y + 1);
            float   num1   = (float)((double)Lighting.GlobalBrightness * (double)scale * 63.75);
            int     num2   = (int)(((double)color2.X + (double)color6.X + (double)color4.X + (double)color1.X) * (double)num1);
            int     num3   = (int)(((double)color2.Y + (double)color6.Y + (double)color4.Y + (double)color1.Y) * (double)num1);
            int     num4   = (int)(((double)color2.Z + (double)color6.Z + (double)color4.Z + (double)color1.Z) * (double)num1);

            if (num2 > (int)byte.MaxValue)
            {
                num2 = (int)byte.MaxValue;
            }
            if (num3 > (int)byte.MaxValue)
            {
                num3 = (int)byte.MaxValue;
            }
            if (num4 > (int)byte.MaxValue)
            {
                num4 = (int)byte.MaxValue;
            }
            int num5 = num3 << 8;
            int num6 = num4 << 16;

            vertices.TopLeftColor.PackedValue = (uint)(num2 | num5 | num6 | -16777216);
            int num7 = (int)(((double)color2.X + (double)color7.X + (double)color5.X + (double)color1.X) * (double)num1);
            int num8 = (int)(((double)color2.Y + (double)color7.Y + (double)color5.Y + (double)color1.Y) * (double)num1);
            int num9 = (int)(((double)color2.Z + (double)color7.Z + (double)color5.Z + (double)color1.Z) * (double)num1);

            if (num7 > (int)byte.MaxValue)
            {
                num7 = (int)byte.MaxValue;
            }
            if (num8 > (int)byte.MaxValue)
            {
                num8 = (int)byte.MaxValue;
            }
            if (num9 > (int)byte.MaxValue)
            {
                num9 = (int)byte.MaxValue;
            }
            int num10 = num8 << 8;
            int num11 = num9 << 16;

            vertices.TopRightColor.PackedValue = (uint)(num7 | num10 | num11 | -16777216);
            int num12 = (int)(((double)color3.X + (double)color8.X + (double)color4.X + (double)color1.X) * (double)num1);
            int num13 = (int)(((double)color3.Y + (double)color8.Y + (double)color4.Y + (double)color1.Y) * (double)num1);
            int num14 = (int)(((double)color3.Z + (double)color8.Z + (double)color4.Z + (double)color1.Z) * (double)num1);

            if (num12 > (int)byte.MaxValue)
            {
                num12 = (int)byte.MaxValue;
            }
            if (num13 > (int)byte.MaxValue)
            {
                num13 = (int)byte.MaxValue;
            }
            if (num14 > (int)byte.MaxValue)
            {
                num14 = (int)byte.MaxValue;
            }
            int num15 = num13 << 8;
            int num16 = num14 << 16;

            vertices.BottomLeftColor.PackedValue = (uint)(num12 | num15 | num16 | -16777216);
            int num17 = (int)(((double)color3.X + (double)color9.X + (double)color5.X + (double)color1.X) * (double)num1);
            int num18 = (int)(((double)color3.Y + (double)color9.Y + (double)color5.Y + (double)color1.Y) * (double)num1);
            int num19 = (int)(((double)color3.Z + (double)color9.Z + (double)color5.Z + (double)color1.Z) * (double)num1);

            if (num17 > (int)byte.MaxValue)
            {
                num17 = (int)byte.MaxValue;
            }
            if (num18 > (int)byte.MaxValue)
            {
                num18 = (int)byte.MaxValue;
            }
            if (num19 > (int)byte.MaxValue)
            {
                num19 = (int)byte.MaxValue;
            }
            int num20 = num18 << 8;
            int num21 = num19 << 16;

            vertices.BottomRightColor.PackedValue = (uint)(num17 | num20 | num21 | -16777216);
        }
        /// <inheritdoc />
        protected override void Initialize()
        {
            base.Initialize();

            VertexColors.Clear();
        }
Esempio n. 14
0
        public void DrawWalls()
        {
            float   gfxQuality     = Main.gfxQuality;
            int     offScreenRange = Main.offScreenRange;
            int     num1           = Main.drawToScreen ? 1 : 0;
            Vector2 screenPosition = Main.screenPosition;
            int     screenWidth    = Main.screenWidth;
            int     screenHeight   = Main.screenHeight;
            int     maxTilesX      = Main.maxTilesX;
            int     maxTilesY      = Main.maxTilesY;

            int[]       wallBlend   = Main.wallBlend;
            SpriteBatch spriteBatch = Main.spriteBatch;
            TileBatch   tileBatch   = Main.tileBatch;

            this._tileArray = Main.tile;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            int     num2;
            int     num3    = (int)((double)(num2 = (int)(120.0 * (1.0 - (double)gfxQuality) + 40.0 * (double)gfxQuality)) * 0.400000005960464);
            int     num4    = (int)((double)num2 * 0.349999994039536);
            int     num5    = (int)((double)num2 * 0.300000011920929);
            Vector2 vector2 = new Vector2((float)offScreenRange, (float)offScreenRange);

            if (num1 != 0)
            {
                vector2 = Vector2.Zero;
            }
            int num6  = (int)(((double)screenPosition.X - (double)vector2.X) / 16.0 - 1.0);
            int num7  = (int)(((double)screenPosition.X + (double)screenWidth + (double)vector2.X) / 16.0) + 2;
            int num8  = (int)(((double)screenPosition.Y - (double)vector2.Y) / 16.0 - 1.0);
            int num9  = (int)(((double)screenPosition.Y + (double)screenHeight + (double)vector2.Y) / 16.0) + 5;
            int num10 = offScreenRange / 16;
            int num11 = offScreenRange / 16;

            if (num6 - num10 < 4)
            {
                num6 = num10 + 4;
            }
            if (num7 + num10 > maxTilesX - 4)
            {
                num7 = maxTilesX - num10 - 4;
            }
            if (num8 - num11 < 4)
            {
                num8 = num11 + 4;
            }
            if (num9 + num11 > maxTilesY - 4)
            {
                num9 = maxTilesY - num11 - 4;
            }
            VertexColors vertices             = new VertexColors();
            Rectangle    rectangle            = new Rectangle(0, 0, 32, 32);
            int          underworldLayer      = Main.UnderworldLayer;
            Point        screenOverdrawOffset = Main.GetScreenOverdrawOffset();

            for (int index1 = num8 - num11 + screenOverdrawOffset.Y; index1 < num9 + num11 - screenOverdrawOffset.Y; ++index1)
            {
                for (int index2 = num6 - num10 + screenOverdrawOffset.X; index2 < num7 + num10 - screenOverdrawOffset.X; ++index2)
                {
                    Tile tile = this._tileArray[index2, index1];
                    if (tile == null)
                    {
                        tile = new Tile();
                        this._tileArray[index2, index1] = tile;
                    }
                    ushort wall = tile.wall;
                    if (wall > (ushort)0 && !this.FullTile(index2, index1))
                    {
                        Color color1 = Lighting.GetColor(index2, index1);
                        if (tile.wallColor() == (byte)31)
                        {
                            color1 = Color.White;
                        }
                        if (color1.R != (byte)0 || color1.G != (byte)0 || (color1.B != (byte)0 || index1 >= underworldLayer))
                        {
                            Main.instance.LoadWall((int)wall);
                            rectangle.X = tile.wallFrameX();
                            rectangle.Y = tile.wallFrameY() + (int)Main.wallFrame[(int)wall] * 180;
                            switch (tile.wall)
                            {
                            case 242:
                            case 243:
                                int num12 = 20;
                                int num13 = ((int)Main.wallFrameCounter[(int)wall] + index2 * 11 + index1 * 27) % (num12 * 8);
                                rectangle.Y = tile.wallFrameY() + 180 * (num13 / num12);
                                break;
                            }
                            if (Lighting.NotRetro && !Main.wallLight[(int)wall] && tile.wall != (ushort)241 && ((tile.wall <(ushort)88 || tile.wall> (ushort) 93) && !WorldGen.SolidTile(tile)))
                            {
                                Texture2D tileDrawTexture = this.GetTileDrawTexture(tile, index2, index1);
                                if (tile.wall == (ushort)44)
                                {
                                    Color color2 = new Color((int)(byte)Main.DiscoR, (int)(byte)Main.DiscoG, (int)(byte)Main.DiscoB);
                                    vertices.BottomLeftColor  = color2;
                                    vertices.BottomRightColor = color2;
                                    vertices.TopLeftColor     = color2;
                                    vertices.TopRightColor    = color2;
                                }
                                else
                                {
                                    Lighting.GetCornerColors(index2, index1, out vertices, 1f);
                                    if (tile.wallColor() == (byte)31)
                                    {
                                        vertices = WallDrawing._glowPaintColors;
                                    }
                                }
                                tileBatch.Draw(tileDrawTexture, new Vector2((float)(index2 * 16 - (int)screenPosition.X - 8), (float)(index1 * 16 - (int)screenPosition.Y - 8)) + vector2, new Rectangle?(rectangle), vertices, Vector2.Zero, 1f, SpriteEffects.None);
                            }
                            else
                            {
                                Color color2 = color1;
                                if (wall == (ushort)44)
                                {
                                    color2 = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB);
                                }
                                Texture2D tileDrawTexture = this.GetTileDrawTexture(tile, index2, index1);
                                spriteBatch.Draw(tileDrawTexture, new Vector2((float)(index2 * 16 - (int)screenPosition.X - 8), (float)(index1 * 16 - (int)screenPosition.Y - 8)) + vector2, new Rectangle?(rectangle), color2, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
                            }
                            if ((int)color1.R > num3 || (int)color1.G > num4 || (int)color1.B > num5)
                            {
                                int  num14 = this._tileArray[index2 - 1, index1].wall <= (ushort)0 ? 0 : (wallBlend[(int)this._tileArray[index2 - 1, index1].wall] != wallBlend[(int)tile.wall] ? 1 : 0);
                                bool flag1 = this._tileArray[index2 + 1, index1].wall > (ushort)0 && wallBlend[(int)this._tileArray[index2 + 1, index1].wall] != wallBlend[(int)tile.wall];
                                bool flag2 = this._tileArray[index2, index1 - 1].wall > (ushort)0 && wallBlend[(int)this._tileArray[index2, index1 - 1].wall] != wallBlend[(int)tile.wall];
                                bool flag3 = this._tileArray[index2, index1 + 1].wall > (ushort)0 && wallBlend[(int)this._tileArray[index2, index1 + 1].wall] != wallBlend[(int)tile.wall];
                                if (num14 != 0)
                                {
                                    spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2((float)(index2 * 16 - (int)screenPosition.X), (float)(index1 * 16 - (int)screenPosition.Y)) + vector2, new Rectangle?(new Rectangle(0, 0, 2, 16)), color1, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
                                }
                                if (flag1)
                                {
                                    spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2((float)(index2 * 16 - (int)screenPosition.X + 14), (float)(index1 * 16 - (int)screenPosition.Y)) + vector2, new Rectangle?(new Rectangle(14, 0, 2, 16)), color1, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
                                }
                                if (flag2)
                                {
                                    spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2((float)(index2 * 16 - (int)screenPosition.X), (float)(index1 * 16 - (int)screenPosition.Y)) + vector2, new Rectangle?(new Rectangle(0, 0, 16, 2)), color1, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
                                }
                                if (flag3)
                                {
                                    spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2((float)(index2 * 16 - (int)screenPosition.X), (float)(index1 * 16 - (int)screenPosition.Y + 14)) + vector2, new Rectangle?(new Rectangle(0, 14, 16, 2)), color1, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
                                }
                            }
                        }
                    }
                }
            }
            Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitReplace);
            Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitTile);
            TimeLogger.DrawTime(2, stopwatch.Elapsed.TotalMilliseconds);
        }
Esempio n. 15
0
        public void DrawWalls()
        {
            float   gfxQuality     = Main.gfxQuality;
            int     offScreenRange = Main.offScreenRange;
            bool    drawToScreen   = Main.drawToScreen;
            Vector2 screenPosition = Main.screenPosition;
            int     screenWidth    = Main.screenWidth;
            int     screenHeight   = Main.screenHeight;
            int     maxTilesX      = Main.maxTilesX;
            int     maxTilesY      = Main.maxTilesY;

            int[]       wallBlend   = Main.wallBlend;
            SpriteBatch spriteBatch = Main.spriteBatch;
            TileBatch   tileBatch   = Main.tileBatch;

            _tileArray = Main.tile;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            int     num   = (int)(120f * (1f - gfxQuality) + 40f * gfxQuality);
            int     num2  = (int)((float)num * 0.4f);
            int     num3  = (int)((float)num * 0.35f);
            int     num4  = (int)((float)num * 0.3f);
            Vector2 value = new Vector2(offScreenRange, offScreenRange);

            if (drawToScreen)
            {
                value = Vector2.Zero;
            }
            int num5  = (int)((screenPosition.X - value.X) / 16f - 1f);
            int num6  = (int)((screenPosition.X + (float)screenWidth + value.X) / 16f) + 2;
            int num7  = (int)((screenPosition.Y - value.Y) / 16f - 1f);
            int num8  = (int)((screenPosition.Y + (float)screenHeight + value.Y) / 16f) + 5;
            int num9  = offScreenRange / 16;
            int num10 = offScreenRange / 16;

            if (num5 - num9 < 4)
            {
                num5 = num9 + 4;
            }
            if (num6 + num9 > maxTilesX - 4)
            {
                num6 = maxTilesX - num9 - 4;
            }
            if (num7 - num10 < 4)
            {
                num7 = num10 + 4;
            }
            if (num8 + num10 > maxTilesY - 4)
            {
                num8 = maxTilesY - num10 - 4;
            }
            VertexColors vertices             = default(VertexColors);
            Rectangle    value2               = new Rectangle(0, 0, 32, 32);
            int          underworldLayer      = Main.UnderworldLayer;
            Point        screenOverdrawOffset = Main.GetScreenOverdrawOffset();

            for (int i = num7 - num10 + screenOverdrawOffset.Y; i < num8 + num10 - screenOverdrawOffset.Y; i++)
            {
                for (int j = num5 - num9 + screenOverdrawOffset.X; j < num6 + num9 - screenOverdrawOffset.X; j++)
                {
                    Tile tile = _tileArray[j, i];
                    if (tile == null)
                    {
                        tile             = new Tile();
                        _tileArray[j, i] = tile;
                    }
                    ushort wall = tile.wall;
                    if (wall <= 0 || FullTile(j, i))
                    {
                        continue;
                    }
                    Color color = Lighting.GetColor(j, i);
                    if (tile.wallColor() == 31)
                    {
                        color = Color.White;
                    }
                    if (color.R == 0 && color.G == 0 && color.B == 0 && i < underworldLayer)
                    {
                        continue;
                    }
                    Main.instance.LoadWall(wall);
                    value2.X = tile.wallFrameX();
                    value2.Y = tile.wallFrameY() + Main.wallFrame[wall] * 180;
                    ushort wall2 = tile.wall;
                    if ((uint)(wall2 - 242) <= 1u)
                    {
                        int num11 = 20;
                        int num12 = (Main.wallFrameCounter[wall] + j * 11 + i * 27) % (num11 * 8);
                        value2.Y = tile.wallFrameY() + 180 * (num12 / num11);
                    }
                    if (Lighting.NotRetro && !Main.wallLight[wall] && tile.wall != 241 && (tile.wall < 88 || tile.wall > 93) && !WorldGen.SolidTile(tile))
                    {
                        Texture2D tileDrawTexture = GetTileDrawTexture(tile, j, i);
                        if (tile.wall == 44)
                        {
                            vertices.TopRightColor = (vertices.TopLeftColor = (vertices.BottomRightColor = (vertices.BottomLeftColor = new Color((byte)Main.DiscoR, (byte)Main.DiscoG, (byte)Main.DiscoB))));
                        }
                        else
                        {
                            Lighting.GetCornerColors(j, i, out vertices);
                            if (tile.wallColor() == 31)
                            {
                                vertices = _glowPaintColors;
                            }
                        }
                        tileBatch.Draw(tileDrawTexture, new Vector2(j * 16 - (int)screenPosition.X - 8, i * 16 - (int)screenPosition.Y - 8) + value, value2, vertices, Vector2.Zero, 1f, SpriteEffects.None);
                    }
                    else
                    {
                        Color color2 = color;
                        if (wall == 44)
                        {
                            color2 = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB);
                        }
                        Texture2D tileDrawTexture2 = GetTileDrawTexture(tile, j, i);
                        spriteBatch.Draw(tileDrawTexture2, new Vector2(j * 16 - (int)screenPosition.X - 8, i * 16 - (int)screenPosition.Y - 8) + value, value2, color2, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                    }
                    if (color.R > num2 || color.G > num3 || color.B > num4)
                    {
                        bool num13 = _tileArray[j - 1, i].wall > 0 && wallBlend[_tileArray[j - 1, i].wall] != wallBlend[tile.wall];
                        bool flag  = _tileArray[j + 1, i].wall > 0 && wallBlend[_tileArray[j + 1, i].wall] != wallBlend[tile.wall];
                        bool flag2 = _tileArray[j, i - 1].wall > 0 && wallBlend[_tileArray[j, i - 1].wall] != wallBlend[tile.wall];
                        bool flag3 = _tileArray[j, i + 1].wall > 0 && wallBlend[_tileArray[j, i + 1].wall] != wallBlend[tile.wall];
                        if (num13)
                        {
                            spriteBatch.Draw(TextureAssets.WallOutline.get_Value(), new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y) + value, new Rectangle(0, 0, 2, 16), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                        }
                        if (flag)
                        {
                            spriteBatch.Draw(TextureAssets.WallOutline.get_Value(), new Vector2(j * 16 - (int)screenPosition.X + 14, i * 16 - (int)screenPosition.Y) + value, new Rectangle(14, 0, 2, 16), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                        }
                        if (flag2)
                        {
                            spriteBatch.Draw(TextureAssets.WallOutline.get_Value(), new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y) + value, new Rectangle(0, 0, 16, 2), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                        }
                        if (flag3)
                        {
                            spriteBatch.Draw(TextureAssets.WallOutline.get_Value(), new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y + 14) + value, new Rectangle(0, 14, 16, 2), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                        }
                    }
                }
            }
            Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitReplace);
            Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitTile);
            TimeLogger.DrawTime(2, stopwatch.Elapsed.TotalMilliseconds);
        }
Esempio n. 16
0
        ///<summary>
        /// Close the line with given color
        ///</summary>
        void CloseLine(Color32 color)
        {
            if (vertices.Count == 0)
            {
                return;
            }

            int        offset        = Vertices.Count;
            int        triangleCount = vertices.Count - 2;
            List <int> triangles     = new List <int>();

            for (int i = 0; i < triangleCount / 2; i++)
            {
                triangles.Add(offset + i * 2);
                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 1);

                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 3);
                triangles.Add(offset + i * 2 + 1);
            }

            for (int i = 0; i < vertices.Count; i++)
            {
                VertexColors.Add(color);
            }

            if (mode_3d)
            {
                List <Vector3> v2 = new List <Vector3>();
                List <int>     t2 = new List <int>();

                for (int i = 0; i < vertices.Count; i++)
                {
                    v2.Add(new Vector3(vertices[i].x, vertices[i].y, z1));
                    VertexColors.Add(color);
                }

                for (int i = 0; i < triangleCount * 3; i += 3)
                {
                    t2.Add(triangles[i] + vertices.Count);
                    t2.Add(triangles[i + 2] + vertices.Count);
                    t2.Add(triangles[i + 1] + vertices.Count);
                }

                for (int i = 0; i < triangles.Count; i += 6)
                {
                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 1]);
                    t2.Add(triangles[i + 2]);

                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 5]);
                    t2.Add(t2[i + 1]);

                    t2.Add(triangles[i]);
                    t2.Add(t2[i]);
                    t2.Add(t2[i + 2]);

                    t2.Add(triangles[i + 1]);
                    t2.Add(triangles[i]);
                    t2.Add(t2[i + 2]);
                }

                t2.Add(offset);
                t2.Add(offset + 1);
                t2.Add(offset + vertices.Count);

                t2.Add(offset + vertices.Count + 1);
                t2.Add(offset + vertices.Count);
                t2.Add(offset + 1);

                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 1);

                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 2);

                vertices.AddRange(v2);
                triangles.AddRange(t2);
            }

            Vertices.AddRange(vertices);
            Triangles.AddRange(triangles);

            vertices.Clear();
        }
Esempio n. 17
0
        ///<summary>
        /// Generate a point at given location
        ///</summary>
        void CreatePoint(Vector3 center, int row, int column)
        {
            float   r     = size.x * pointSize;
            Color32 color = colors[row % colorCount, 1];

            switch (point)
            {
            case PointType.CIRCLE:
            {
                Vector3 p1 = new Vector3(r, 0, 0);
                for (int i = 0; i < 360 / 30; i++)
                {
                    Vector3 p = p1;
                    p1 = Quaternion.Euler(0, 0, 30) * p1;

                    Vertices.Add(center);
                    Vertices.Add(center + p);
                    Vertices.Add(center + p1);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    Triangles.Add(Vertices.Count - 3);
                    Triangles.Add(Vertices.Count - 2);
                    Triangles.Add(Vertices.Count - 1);

                    if (mode_3d)
                    {
                        Vector3 p3 = center; p3.z = z1;
                        Vector3 p4 = center + p; p4.z = z1;
                        Vector3 p5 = center + p1; p5.z = z1;

                        AddTriangle(p3, p5, p4, color, color);

                        AddTriangle(center + p, p4, center + p1, color, color);
                        AddTriangle(center + p1, p4, p5, color, color);
                    }
                }
            }
            break;

            case PointType.RECTANGLE:
            {
                Vector3 p0 = center + new Vector3(-r, -r, 0);
                Vector3 p1 = center + new Vector3(-r, r, 0);
                Vector3 p2 = center + new Vector3(r, r, 0);
                Vector3 p3 = center + new Vector3(r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + Quaternion.Euler(0, 0, 45) * p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 135) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 225) * p;
                // Vector3 p3 = center + Quaternion.Euler(0, 0, 315) * p;

                AddTriangle(p0, p1, p3, color, color);
                AddTriangle(p3, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p4 = p0; p4.z = z1;
                    Vector3 p5 = p1; p5.z = z1;
                    Vector3 p6 = p2; p6.z = z1;
                    Vector3 p7 = p3; p7.z = z1;

                    AddTriangle(p4, p7, p5, color, color);
                    AddTriangle(p7, p6, p5, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p5, p1, p4, color, color);

                    AddTriangle(p2, p1, p5, color, color);
                    AddTriangle(p2, p5, p6, color, color);

                    AddTriangle(p2, p6, p3, color, color);
                    AddTriangle(p7, p3, p6, color, color);

                    AddTriangle(p3, p7, p0, color, color);
                    AddTriangle(p0, p7, p4, color, color);
                }
            }
            break;

            case PointType.TRIANGLE:
            {
                Vector3 p0 = center + new Vector3(0, r, 0);
                Vector3 p1 = center + new Vector3(r, -r, 0);
                Vector3 p2 = center + new Vector3(-r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 120) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 240) * p;

                AddTriangle(p0, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p3 = p0; p3.z = z1;
                    Vector3 p4 = p1; p4.z = z1;
                    Vector3 p5 = p2; p5.z = z1;

                    AddTriangle(p3, p5, p4, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p0, p3, p4, color, color);

                    AddTriangle(p1, p4, p2, color, color);
                    AddTriangle(p2, p4, p5, color, color);

                    AddTriangle(p2, p5, p0, color, color);
                    AddTriangle(p5, p3, p0, color, color);
                }
            }
            break;
            }
        }
Esempio n. 18
0
        ///<summary>
        /// Add a segment to chart
        ///</summary>
        void AddLineSegment(float x1, float y1, float x2, float y2, Color32 color)
        {
            float px     = y2 - y1;
            float py     = -(x2 - x1);
            float length = Mathf.Sqrt(px * px + py * py);

            float nx = (px / length) * rectTransform.rect.width * thickness;
            float ny = (py / length) * rectTransform.rect.width * thickness;

            Vector3 vert0 = new Vector3(x1 + nx, y1 + ny, 0);
            Vector3 vert1 = new Vector3(x2 + nx, y2 + ny, 0);
            Vector3 vert2 = new Vector3(x2 - nx, y2 - ny, 0);
            Vector3 vert3 = new Vector3(x1 - nx, y1 - ny, 0);

            if (Vertices.Count == 0 || newLine)
            {
                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);

                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
                newLine = false;
                return;
            }

            Vector3 vertP0 = Vertices[Vertices.Count - 4];
            Vector3 vertP1 = Vertices[Vertices.Count - 3];
            Vector3 vertP2 = Vertices[Vertices.Count - 2];
            Vector3 vertP3 = Vertices[Vertices.Count - 1];

            bool intersect = lineSegmentIntersection(vertP0, vertP1, vert1, vert0) | lineSegmentIntersection(vertP3, vertP2, vert2, vert3);

            if (!intersect)
            {
                if (vectorIntersection(vertP0, vertP1, vert1, vert0))
                {
                    vert0 = lineIntersectionPoint(vertP0, vertP1, vert1, vert0);
                    Vertices[Vertices.Count - 3] = vert0;
                }
                if (vectorIntersection(vertP3, vertP2, vert2, vert3))
                {
                    vert3 = lineIntersectionPoint(vertP3, vertP2, vert2, vert3);
                    Vertices[Vertices.Count - 2] = vert3;
                }

                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);

                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
            }
            else
            {
                vert0 = lineIntersectionPoint(vertP0, vertP1, vert1, vert0);
                vert3 = lineIntersectionPoint(vertP3, vertP2, vert2, vert3);
                Vertices[Vertices.Count - 3] = vert0;
                Vertices[Vertices.Count - 2] = vert3;
                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
            }
        }