Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WallDrawing.cs
Go to the documentation of this file.
5using Terraria.ID;
6
8
9public class WallDrawing
10{
12
13 private Tile[,] _tileArray;
14
16
18
19 public void LerpVertexColorsWithColor(ref VertexColors colors, Color lerpColor, float percent)
20 {
21 colors.TopLeftColor = Color.Lerp(colors.TopLeftColor, lerpColor, percent);
22 colors.TopRightColor = Color.Lerp(colors.TopRightColor, lerpColor, percent);
23 colors.BottomLeftColor = Color.Lerp(colors.BottomLeftColor, lerpColor, percent);
24 colors.BottomRightColor = Color.Lerp(colors.BottomRightColor, lerpColor, percent);
25 }
26
27 public WallDrawing(TilePaintSystemV2 paintSystem)
28 {
29 _paintSystem = paintSystem;
30 }
31
32 public void Update()
33 {
34 if (!Main.dedServ)
35 {
37 }
38 }
39
40 public void DrawWalls()
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;
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);
197 }
198
199 private Texture2D GetTileDrawTexture(Tile tile, int tileX, int tileY)
200 {
201 Texture2D result = TextureAssets.Wall[tile.wall].Value;
202 int wall = tile.wall;
204 if (texture2D != null)
205 {
206 result = texture2D;
207 }
208 return result;
209 }
210
211 protected bool FullTile(int x, int y)
212 {
213 if (_tileArray[x - 1, y] == null || _tileArray[x - 1, y].blockType() != 0 || _tileArray[x + 1, y] == null || _tileArray[x + 1, y].blockType() != 0)
214 {
215 return false;
216 }
217 Tile tile = _tileArray[x, y];
218 if (tile == null)
219 {
220 return false;
221 }
222 if (tile.active())
223 {
224 if (tile.type < TileID.Sets.DrawsWalls.Length && TileID.Sets.DrawsWalls[tile.type])
225 {
226 return false;
227 }
229 {
230 return false;
231 }
232 if (Main.tileSolid[tile.type] && !Main.tileSolidTop[tile.type])
233 {
234 int frameX = tile.frameX;
235 int frameY = tile.frameY;
236 if (Main.tileLargeFrames[tile.type] > 0)
237 {
238 if (frameY == 18 || frameY == 108)
239 {
240 if (frameX >= 18 && frameX <= 54)
241 {
242 return true;
243 }
244 if (frameX >= 108 && frameX <= 144)
245 {
246 return true;
247 }
248 }
249 }
250 else if (frameY == 18)
251 {
252 if (frameX >= 18 && frameX <= 54)
253 {
254 return true;
255 }
256 if (frameX >= 108 && frameX <= 144)
257 {
258 return true;
259 }
260 }
261 else if (frameY >= 90 && frameY <= 196)
262 {
263 if (frameX <= 70)
264 {
265 return true;
266 }
267 if (frameX >= 144 && frameX <= 232)
268 {
269 return true;
270 }
271 }
272 }
273 }
274 return false;
275 }
276}
void Draw(Texture2D texture, Vector2 position, Color color)
WallDrawing(TilePaintSystemV2 paintSystem)
Texture2D GetTileDrawTexture(Tile tile, int tileX, int tileY)
void LerpVertexColorsWithColor(ref VertexColors colors, Color lerpColor, float percent)
static Asset< Texture2D > WallOutline
static Asset< Texture2D >[] Wall
Texture2D TryGetWallAndRequestIfNotReady(int wallType, int paintColor)
void Draw(Texture2D texture, Vector2 position, VertexColors colors)
Definition TileBatch.cs:127
static bool[] DrawsWalls
Definition TileID.cs:171
static void GetCornerColors(int centerX, int centerY, out VertexColors vertices, float scale=1f)
Definition Lighting.cs:295
static Color GetColor(Point tileCoords)
Definition Lighting.cs:182
static bool NotRetro
Definition Lighting.cs:64
static int maxTilesY
Definition Main.cs:1116
static byte[] wallFrame
Definition Main.cs:1661
static bool[] tileSolidTop
Definition Main.cs:1469
static bool ShouldShowInvisibleWalls()
Definition Main.cs:54895
static SpriteBatch spriteBatch
Definition Main.cs:974
static int DiscoR
Definition Main.cs:1062
static float gfxQuality
Definition Main.cs:1056
static bool drawToScreen
Definition Main.cs:600
static bool dedServ
Definition Main.cs:1226
static Main instance
Definition Main.cs:283
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static int maxTilesX
Definition Main.cs:1114
static int DiscoG
Definition Main.cs:1066
static int offScreenRange
Definition Main.cs:836
static int[] wallBlend
Definition Main.cs:1447
static bool[] tileSolid
Definition Main.cs:1471
static Tile[,] tile
Definition Main.cs:1675
static TileBatch tileBatch
Definition Main.cs:976
static int DiscoB
Definition Main.cs:1064
static byte[] tileLargeFrames
Definition Main.cs:1477
static Microsoft.Xna.Framework.Point GetScreenOverdrawOffset()
Definition Main.cs:50910
static byte[] wallFrameCounter
Definition Main.cs:1663
static bool[] wallLight
Definition Main.cs:1445
static int screenWidth
Definition Main.cs:1719
static int UnderworldLayer
Definition Main.cs:2825
static Player LocalPlayer
Definition Main.cs:2829
bool fullbrightWall()
Definition Tile.cs:694
bool invisibleWall()
Definition Tile.cs:521
int wallFrameY()
Definition Tile.cs:460
short frameY
Definition Tile.cs:24
ushort type
Definition Tile.cs:8
short frameX
Definition Tile.cs:22
bool invisibleBlock()
Definition Tile.cs:504
bool active()
Definition Tile.cs:565
int wallFrameX()
Definition Tile.cs:430
ushort wall
Definition Tile.cs:10
byte wallColor()
Definition Tile.cs:352
static void DrawTime(int drawType, double timeElapsed)
static bool SolidTile(Tile testTile)
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
double TotalMilliseconds
Definition TimeSpan.cs:46