Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DrawWalls()

void Terraria.GameContent.Drawing.WallDrawing.DrawWalls ( )
inline

Definition at line 40 of file WallDrawing.cs.

41 {
42 float gfxQuality = Main.gfxQuality;
43 int offScreenRange = Main.offScreenRange;
44 bool drawToScreen = Main.drawToScreen;
45 Vector2 screenPosition = Main.screenPosition;
46 int screenWidth = Main.screenWidth;
47 int screenHeight = Main.screenHeight;
48 int maxTilesX = Main.maxTilesX;
49 int maxTilesY = Main.maxTilesY;
50 int[] wallBlend = Main.wallBlend;
51 SpriteBatch spriteBatch = Main.spriteBatch;
52 TileBatch tileBatch = Main.tileBatch;
53 _tileArray = Main.tile;
54 Stopwatch stopwatch = new Stopwatch();
55 stopwatch.Start();
56 int num = (int)(120f * (1f - gfxQuality) + 40f * gfxQuality);
57 int num2 = (int)((float)num * 0.4f);
58 int num3 = (int)((float)num * 0.35f);
59 int num4 = (int)((float)num * 0.3f);
60 Vector2 vector = new Vector2(offScreenRange, offScreenRange);
61 if (drawToScreen)
62 {
63 vector = Vector2.Zero;
64 }
65 int num5 = (int)((screenPosition.X - vector.X) / 16f - 1f);
66 int num6 = (int)((screenPosition.X + (float)screenWidth + vector.X) / 16f) + 2;
67 int num7 = (int)((screenPosition.Y - vector.Y) / 16f - 1f);
68 int num8 = (int)((screenPosition.Y + (float)screenHeight + vector.Y) / 16f) + 5;
69 int num9 = offScreenRange / 16;
70 int num10 = offScreenRange / 16;
71 if (num5 - num9 < 4)
72 {
73 num5 = num9 + 4;
74 }
75 if (num6 + num9 > maxTilesX - 4)
76 {
77 num6 = maxTilesX - num9 - 4;
78 }
79 if (num7 - num10 < 4)
80 {
81 num7 = num10 + 4;
82 }
83 if (num8 + num10 > maxTilesY - 4)
84 {
85 num8 = maxTilesY - num10 - 4;
86 }
87 VertexColors vertices = default(VertexColors);
88 Rectangle value = new Rectangle(0, 0, 32, 32);
89 int underworldLayer = Main.UnderworldLayer;
90 Point screenOverdrawOffset = Main.GetScreenOverdrawOffset();
91 for (int i = num7 - num10 + screenOverdrawOffset.Y; i < num8 + num10 - screenOverdrawOffset.Y; i++)
92 {
93 for (int j = num5 - num9 + screenOverdrawOffset.X; j < num6 + num9 - screenOverdrawOffset.X; j++)
94 {
95 Tile tile = _tileArray[j, i];
96 if (tile == null)
97 {
98 tile = new Tile();
99 _tileArray[j, i] = tile;
100 }
101 ushort wall = tile.wall;
102 if (wall <= 0 || FullTile(j, i) || (wall == 318 && !_shouldShowInvisibleWalls) || (tile.invisibleWall() && !_shouldShowInvisibleWalls))
103 {
104 continue;
105 }
106 Color color = Lighting.GetColor(j, i);
107 if (tile.fullbrightWall())
108 {
109 color = Color.White;
110 }
111 if (wall == 318)
112 {
113 color = Color.White;
114 }
115 if (color.R == 0 && color.G == 0 && color.B == 0 && i < underworldLayer)
116 {
117 continue;
118 }
119 Main.instance.LoadWall(wall);
120 value.X = tile.wallFrameX();
121 value.Y = tile.wallFrameY() + Main.wallFrame[wall] * 180;
122 ushort wall2 = tile.wall;
123 if ((uint)(wall2 - 242) <= 1u)
124 {
125 int num11 = 20;
126 int num12 = (Main.wallFrameCounter[wall] + j * 11 + i * 27) % (num11 * 8);
127 value.Y = tile.wallFrameY() + 180 * (num12 / num11);
128 }
129 if (Lighting.NotRetro && !Main.wallLight[wall] && tile.wall != 241 && (tile.wall < 88 || tile.wall > 93) && !WorldGen.SolidTile(tile))
130 {
131 Texture2D tileDrawTexture = GetTileDrawTexture(tile, j, i);
132 if (tile.wall == 346)
133 {
134 vertices.TopRightColor = (vertices.TopLeftColor = (vertices.BottomRightColor = (vertices.BottomLeftColor = new Color((byte)Main.DiscoR, (byte)Main.DiscoG, (byte)Main.DiscoB))));
135 }
136 else if (tile.wall == 44)
137 {
138 vertices.TopRightColor = (vertices.TopLeftColor = (vertices.BottomRightColor = (vertices.BottomLeftColor = new Color((byte)Main.DiscoR, (byte)Main.DiscoG, (byte)Main.DiscoB))));
139 }
140 else
141 {
142 Lighting.GetCornerColors(j, i, out vertices);
143 wall2 = tile.wall;
144 if ((uint)(wall2 - 341) <= 4u)
145 {
146 LerpVertexColorsWithColor(ref vertices, Color.White, 0.5f);
147 }
148 if (tile.fullbrightWall())
149 {
150 vertices = _glowPaintColors;
151 }
152 }
153 tileBatch.Draw(tileDrawTexture, new Vector2(j * 16 - (int)screenPosition.X - 8, i * 16 - (int)screenPosition.Y - 8) + vector, value, vertices, Vector2.Zero, 1f, SpriteEffects.None);
154 }
155 else
156 {
157 Color color2 = color;
158 if (wall == 44 || wall == 346)
159 {
160 color2 = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB);
161 }
162 if ((uint)(wall - 341) <= 4u)
163 {
164 color2 = Color.Lerp(color2, Color.White, 0.5f);
165 }
166 Texture2D tileDrawTexture2 = GetTileDrawTexture(tile, j, i);
167 spriteBatch.Draw(tileDrawTexture2, new Vector2(j * 16 - (int)screenPosition.X - 8, i * 16 - (int)screenPosition.Y - 8) + vector, value, color2, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
168 }
169 if (color.R > num2 || color.G > num3 || color.B > num4)
170 {
171 bool num13 = _tileArray[j - 1, i].wall > 0 && wallBlend[_tileArray[j - 1, i].wall] != wallBlend[tile.wall];
172 bool flag = _tileArray[j + 1, i].wall > 0 && wallBlend[_tileArray[j + 1, i].wall] != wallBlend[tile.wall];
173 bool flag2 = _tileArray[j, i - 1].wall > 0 && wallBlend[_tileArray[j, i - 1].wall] != wallBlend[tile.wall];
174 bool flag3 = _tileArray[j, i + 1].wall > 0 && wallBlend[_tileArray[j, i + 1].wall] != wallBlend[tile.wall];
175 if (num13)
176 {
177 spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y) + vector, new Rectangle(0, 0, 2, 16), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
178 }
179 if (flag)
180 {
181 spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2(j * 16 - (int)screenPosition.X + 14, i * 16 - (int)screenPosition.Y) + vector, new Rectangle(14, 0, 2, 16), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
182 }
183 if (flag2)
184 {
185 spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y) + vector, new Rectangle(0, 0, 16, 2), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
186 }
187 if (flag3)
188 {
189 spriteBatch.Draw(TextureAssets.WallOutline.Value, new Vector2(j * 16 - (int)screenPosition.X, i * 16 - (int)screenPosition.Y + 14) + vector, new Rectangle(0, 14, 16, 2), color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
190 }
191 }
192 }
193 }
194 Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitReplace);
195 Main.instance.DrawTileCracks(2, Main.LocalPlayer.hitTile);
196 TimeLogger.DrawTime(2, stopwatch.Elapsed.TotalMilliseconds);
197 }
void Draw(Texture2D texture, Vector2 position, Color color)
Texture2D GetTileDrawTexture(Tile tile, int tileX, int tileY)
void LerpVertexColorsWithColor(ref VertexColors colors, Color lerpColor, float percent)
void Draw(Texture2D texture, Vector2 position, VertexColors colors)
Definition TileBatch.cs:127
ushort wall
Definition Tile.cs:10
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
double TotalMilliseconds
Definition TimeSpan.cs:46

References Terraria.GameContent.Drawing.WallDrawing._glowPaintColors, Terraria.GameContent.Drawing.WallDrawing._shouldShowInvisibleWalls, Terraria.GameContent.Drawing.WallDrawing._tileArray, Microsoft.Xna.Framework.Color.B, Microsoft.Xna.Framework.Graphics.Color, Terraria.Main.DiscoB, Terraria.Main.DiscoG, Terraria.Main.DiscoR, Microsoft.Xna.Framework.Graphics.SpriteBatch.Draw(), Terraria.Graphics.TileBatch.Draw(), Terraria.TimeLogger.DrawTime(), Terraria.Main.drawToScreen, System.Diagnostics.Stopwatch.Elapsed, Terraria.Tile.fullbrightWall(), Terraria.GameContent.Drawing.WallDrawing.FullTile(), Microsoft.Xna.Framework.Color.G, Terraria.Lighting.GetColor(), Terraria.Lighting.GetCornerColors(), Terraria.Main.GetScreenOverdrawOffset(), Terraria.GameContent.Drawing.WallDrawing.GetTileDrawTexture(), Terraria.Main.gfxQuality, Terraria.Main.instance, Terraria.Tile.invisibleWall(), Microsoft.Xna.Framework.Color.Lerp(), Terraria.GameContent.Drawing.WallDrawing.LerpVertexColorsWithColor(), Terraria.Main.LocalPlayer, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Lighting.NotRetro, Terraria.Main.offScreenRange, Microsoft.Xna.Framework.Color.R, Terraria.Main.screenHeight, Terraria.Main.screenPosition, Terraria.Main.screenWidth, Terraria.WorldGen.SolidTile(), Terraria.Main.spriteBatch, System.Diagnostics.Stopwatch.Start(), Terraria.Main.tile, Terraria.Main.tileBatch, System.TimeSpan.TotalMilliseconds, Terraria.Main.UnderworldLayer, Microsoft.Xna.Framework.Graphics.Vector2, Terraria.Tile.wall, Terraria.Main.wallBlend, Terraria.Main.wallFrame, Terraria.Main.wallFrameCounter, Terraria.Tile.wallFrameX(), Terraria.Tile.wallFrameY(), Terraria.Main.wallLight, Terraria.GameContent.TextureAssets.WallOutline, Microsoft.Xna.Framework.Color.White, Microsoft.Xna.Framework.Point.X, Microsoft.Xna.Framework.Vector2.X, Microsoft.Xna.Framework.Point.Y, Microsoft.Xna.Framework.Vector2.Y, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.Main.DrawWalls().