private unsafe void InternalDraw( SpriteBatch spriteBatch, Vector2 drawOffset, int waterStyle, float globalAlpha, bool isBackgroundDraw) { Rectangle drawArea = this._drawArea; Main.tileBatch.Begin(); fixed(LiquidRenderer.LiquidDrawCache *liquidDrawCachePtr1 = &this._drawCache[0]) { LiquidRenderer.LiquidDrawCache *liquidDrawCachePtr2 = liquidDrawCachePtr1; for (int x = drawArea.X; x < drawArea.X + drawArea.Width; ++x) { for (int y = drawArea.Y; y < drawArea.Y + drawArea.Height; ++y) { if (liquidDrawCachePtr2->IsVisible) { Rectangle sourceRectangle = liquidDrawCachePtr2->SourceRectangle; if (liquidDrawCachePtr2->IsSurfaceLiquid) { sourceRectangle.Y = 1280; } else { sourceRectangle.Y += this._animationFrame * 80; } Vector2 liquidOffset = liquidDrawCachePtr2->LiquidOffset; float val2 = liquidDrawCachePtr2->Opacity * (isBackgroundDraw ? 1f : LiquidRenderer.DEFAULT_OPACITY[(int)liquidDrawCachePtr2->Type]); int index = (int)liquidDrawCachePtr2->Type; switch (index) { case 0: index = waterStyle; val2 *= globalAlpha; break; case 2: index = 11; break; } float num = Math.Min(1f, val2); VertexColors vertices; Lighting.GetCornerColors(x, y, out vertices, 1f); vertices.BottomLeftColor *= num; vertices.BottomRightColor *= num; vertices.TopLeftColor *= num; vertices.TopRightColor *= num; Main.DrawTileInWater(drawOffset, x, y); Main.tileBatch.Draw(this._liquidTextures[index].Value, new Vector2((float)(x << 4), (float)(y << 4)) + drawOffset + liquidOffset, new Rectangle?(sourceRectangle), vertices, Vector2.Zero, 1f, SpriteEffects.None); } ++liquidDrawCachePtr2; } } } Main.tileBatch.End(); }
private unsafe void InternalDraw(SpriteBatch spriteBatch, Vector2 drawOffset, int waterStyle, float globalAlpha, bool isBackgroundDraw) { Rectangle drawArea = _drawArea; Main.tileBatch.Begin(); fixed(LiquidDrawCache *ptr = &_drawCache[0]) { LiquidDrawCache *ptr2 = ptr; for (int i = drawArea.X; i < drawArea.X + drawArea.Width; i++) { for (int j = drawArea.Y; j < drawArea.Y + drawArea.Height; j++) { if (ptr2->IsVisible) { Rectangle sourceRectangle = ptr2->SourceRectangle; if (ptr2->IsSurfaceLiquid) { sourceRectangle.Y = 1280; } else { sourceRectangle.Y += _animationFrame * 80; } Vector2 liquidOffset = ptr2->LiquidOffset; float num = ptr2->Opacity * (isBackgroundDraw ? 1f : DEFAULT_OPACITY[ptr2->Type]); int num2 = ptr2->Type; switch (num2) { case 0: num2 = waterStyle; num *= globalAlpha; break; case 2: num2 = 11; break; } num = Math.Min(1f, num); Lighting.GetCornerColors(i, j, out VertexColors vertices); vertices.BottomLeftColor *= num; vertices.BottomRightColor *= num; vertices.TopLeftColor *= num; vertices.TopRightColor *= num; Main.DrawTileInWater(drawOffset, i, j); Main.tileBatch.Draw(_liquidTextures[num2].get_Value(), new Vector2(i << 4, j << 4) + drawOffset + liquidOffset, sourceRectangle, vertices, Vector2.Zero, 1f, SpriteEffects.None); } ptr2++; } } } Main.tileBatch.End(); }
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); }
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); }