Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TilePaintSystemV2.cs
Go to the documentation of this file.
1using System;
6
8
9public class TilePaintSystemV2
10{
11 public abstract class ARenderTargetHolder
12 {
14
15 protected bool _wasPrepared;
16
17 public bool IsReady => _wasPrepared;
18
19 public abstract void Prepare();
20
21 public abstract void PrepareShader();
22
23 public void Clear()
24 {
25 if (Target != null && !Target.IsDisposed)
26 {
28 }
29 }
30
32 {
33 if (Target == null || Target.IsContentLost)
34 {
35 Main instance = Main.instance;
36 if (!sourceRect.HasValue)
37 {
38 sourceRect = originalTexture.Frame();
39 }
40 Target = new RenderTarget2D(instance.GraphicsDevice, sourceRect.Value.Width, sourceRect.Value.Height, mipMap: false, instance.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
41 Target.ContentLost += Target_ContentLost;
42 Target.Disposing += Target_Disposing;
43 instance.GraphicsDevice.SetRenderTarget(Target);
44 instance.GraphicsDevice.Clear(Color.Transparent);
47 Rectangle value = sourceRect.Value;
48 value.X = 0;
49 value.Y = 0;
51 Main.spriteBatch.End();
52 instance.GraphicsDevice.SetRenderTarget(null);
53 _wasPrepared = true;
54 }
55 }
56
57 private void Target_Disposing(object sender, EventArgs e)
58 {
59 _wasPrepared = false;
60 Target = null;
61 }
62
63 private void Target_ContentLost(object sender, EventArgs e)
64 {
65 _wasPrepared = false;
66 }
67
68 protected void PrepareShader(int paintColor, TreePaintingSettings settings)
69 {
70 Effect tileShader = Main.tileShader;
71 tileShader.Parameters["leafHueTestOffset"].SetValue(settings.HueTestOffset);
72 tileShader.Parameters["leafMinHue"].SetValue(settings.SpecialGroupMinimalHueValue);
73 tileShader.Parameters["leafMaxHue"].SetValue(settings.SpecialGroupMaximumHueValue);
74 tileShader.Parameters["leafMinSat"].SetValue(settings.SpecialGroupMinimumSaturationValue);
75 tileShader.Parameters["leafMaxSat"].SetValue(settings.SpecialGroupMaximumSaturationValue);
76 tileShader.Parameters["invertSpecialGroupResult"].SetValue(settings.InvertSpecialGroupResult);
78 tileShader.CurrentTechnique.Passes[index].Apply();
79 }
80 }
81
97
113
115 {
117
118 public override void Prepare()
119 {
121 PrepareTextureIfNecessary(val.Value);
122 }
123
128 }
129
131 {
133
134 public override void Prepare()
135 {
137 PrepareTextureIfNecessary(val.Value);
138 }
139
144 }
145
146 public struct TileVariationkey
147 {
148 public int TileType;
149
150 public int TileStyle;
151
152 public int PaintColor;
153
155 {
156 if (TileType == other.TileType && TileStyle == other.TileStyle)
157 {
158 return PaintColor == other.PaintColor;
159 }
160 return false;
161 }
162
163 public override bool Equals(object obj)
164 {
166 {
167 return Equals((TileVariationkey)obj);
168 }
169 return false;
170 }
171
172 public override int GetHashCode()
173 {
174 return (((TileType * 397) ^ TileStyle) * 397) ^ PaintColor;
175 }
176
177 public static bool operator ==(TileVariationkey left, TileVariationkey right)
178 {
179 return left.Equals(right);
180 }
181
182 public static bool operator !=(TileVariationkey left, TileVariationkey right)
183 {
184 return !left.Equals(right);
185 }
186 }
187
188 public struct WallVariationKey
189 {
190 public int WallType;
191
192 public int PaintColor;
193
195 {
196 if (WallType == other.WallType)
197 {
198 return PaintColor == other.PaintColor;
199 }
200 return false;
201 }
202
203 public override bool Equals(object obj)
204 {
206 {
207 return Equals((WallVariationKey)obj);
208 }
209 return false;
210 }
211
212 public override int GetHashCode()
213 {
214 return (WallType * 397) ^ PaintColor;
215 }
216
217 public static bool operator ==(WallVariationKey left, WallVariationKey right)
218 {
219 return left.Equals(right);
220 }
221
222 public static bool operator !=(WallVariationKey left, WallVariationKey right)
223 {
224 return !left.Equals(right);
225 }
226 }
227
229 {
230 public int TextureIndex;
231
232 public int TextureStyle;
233
234 public int PaintColor;
235
237 {
238 if (TextureIndex == other.TextureIndex && TextureStyle == other.TextureStyle)
239 {
240 return PaintColor == other.PaintColor;
241 }
242 return false;
243 }
244
245 public override bool Equals(object obj)
246 {
248 {
250 }
251 return false;
252 }
253
254 public override int GetHashCode()
255 {
256 return (((TextureIndex * 397) ^ TextureStyle) * 397) ^ PaintColor;
257 }
258
260 {
261 return left.Equals(right);
262 }
263
265 {
266 return !left.Equals(right);
267 }
268 }
269
271
273
275
277
279
280 public void Reset()
281 {
283 {
284 value.Clear();
285 }
288 {
289 value2.Clear();
290 }
293 {
294 value3.Clear();
295 }
298 {
299 value4.Clear();
300 }
303 {
304 request.Clear();
305 }
307 }
308
310 {
312 {
314 {
315 Key = lookupKey
316 };
318 }
319 if (!value.IsReady)
320 {
322 }
323 }
324
326 {
327 if (lookupKey.TileType == 83)
328 {
330 tileVariationkey.TileType = 84;
331 tileVariationkey.TileStyle = lookupKey.TileStyle;
332 tileVariationkey.PaintColor = lookupKey.PaintColor;
335 }
336 }
337
339 {
341 {
343 {
344 Key = lookupKey
345 };
347 }
348 if (!value.IsReady)
349 {
351 }
352 }
353
355 {
357 {
359 {
360 Key = lookupKey
361 };
363 }
364 if (!value.IsReady)
365 {
367 }
368 }
369
371 {
373 {
375 {
376 Key = lookupKey
377 };
379 }
380 if (!value.IsReady)
381 {
383 }
384 }
385
386 public Texture2D TryGetTileAndRequestIfNotReady(int tileType, int tileStyle, int paintColor)
387 {
389 tileVariationkey.TileType = tileType;
390 tileVariationkey.TileStyle = tileStyle;
391 tileVariationkey.PaintColor = paintColor;
394 {
395 return value.Target;
396 }
398 return null;
399 }
400
402 {
404 wallVariationKey.WallType = wallType;
405 wallVariationKey.PaintColor = paintColor;
408 {
409 return value.Target;
410 }
412 return null;
413 }
414
416 {
418 treeFoliageVariantKey.TextureIndex = treeTopIndex;
419 treeFoliageVariantKey.TextureStyle = treeTopStyle;
420 treeFoliageVariantKey.PaintColor = paintColor;
423 {
424 return value.Target;
425 }
427 return null;
428 }
429
431 {
433 treeFoliageVariantKey.TextureIndex = treeTopIndex;
434 treeFoliageVariantKey.TextureStyle = treeTopStyle;
435 treeFoliageVariantKey.PaintColor = paintColor;
438 {
439 return value.Target;
440 }
442 return null;
443 }
444
445 public void PrepareAllRequests()
446 {
447 if (_requests.Count != 0)
448 {
449 for (int i = 0; i < _requests.Count; i++)
450 {
451 _requests[i].Prepare();
452 }
454 }
455 }
456}
static readonly BlendState AlphaBlend
Definition BlendState.cs:36
EffectParameterCollection Parameters
Definition Effect.cs:29
unsafe EffectTechnique CurrentTechnique
Definition Effect.cs:34
override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static Asset< Texture2D >[] Tile
static Asset< Texture2D >[] TreeTop
static Asset< Texture2D >[] TreeBranch
static Asset< Texture2D >[] Wall
void PrepareTextureIfNecessary(Texture2D originalTexture, Rectangle? sourceRect=null)
void PrepareShader(int paintColor, TreePaintingSettings settings)
Dictionary< TreeFoliageVariantKey, TreeBranchTargetHolder > _treeBranchRenders
Texture2D TryGetTileAndRequestIfNotReady(int tileType, int tileStyle, int paintColor)
Texture2D TryGetTreeTopAndRequestIfNotReady(int treeTopIndex, int treeTopStyle, int paintColor)
void RequestTreeBranch(ref TreeFoliageVariantKey lookupKey)
Texture2D TryGetWallAndRequestIfNotReady(int wallType, int paintColor)
Texture2D TryGetTreeBranchAndRequestIfNotReady(int treeTopIndex, int treeTopStyle, int paintColor)
Dictionary< TreeFoliageVariantKey, TreeTopRenderTargetHolder > _treeTopRenders
Dictionary< WallVariationKey, WallRenderTargetHolder > _wallsRenders
Dictionary< TileVariationkey, TileRenderTargetHolder > _tilesRenders
void RequestTreeTop(ref TreeFoliageVariantKey lookupKey)
List< ARenderTargetHolder > _requests
void RequestTile_CheckForRelatedTileRequests(ref TileVariationkey lookupKey)
void RequestTile(ref TileVariationkey lookupKey)
void RequestWall(ref WallVariationKey lookupKey)
static TreePaintingSettings GetTreeFoliageSettings(int foliageIndex, int foliageStyle)
static TreePaintingSettings GetWallSettings(int wallType)
static TreePaintingSettings GetTileSettings(int tileType, int tileStyle)
static Effect tileShader
Definition Main.cs:2768
static SpriteBatch spriteBatch
Definition Main.cs:974
static Main instance
Definition Main.cs:283
static IAssetRepository Assets
Definition Main.cs:209
static int ConvertPaintIdToTileShaderIndex(int paintIndexOnTile, bool isUsedForPaintingGrass, bool useWallShaderHacks)
Definition Main.cs:55654
static Color Transparent
Definition Color.cs:76
static bool operator==(TileVariationkey left, TileVariationkey right)
static bool operator!=(TileVariationkey left, TileVariationkey right)
static bool operator!=(TreeFoliageVariantKey left, TreeFoliageVariantKey right)
static bool operator==(TreeFoliageVariantKey left, TreeFoliageVariantKey right)
static bool operator==(WallVariationKey left, WallVariationKey right)
static bool operator!=(WallVariationKey left, WallVariationKey right)