Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MapHeadRenderer.cs
Go to the documentation of this file.
1using System;
7using Terraria.ID;
8
10
12{
13 private bool _anyDirty;
14
16
17 private readonly List<DrawData> _drawData = new List<DrawData>();
18
19 public bool IsReady => !_anyDirty;
20
22 {
23 for (int i = 0; i < _playerRenders.Length; i++)
24 {
26 }
27 }
28
29 public void Reset()
30 {
31 _anyDirty = false;
33 for (int i = 0; i < _playerRenders.Length; i++)
34 {
36 }
37 }
38
39 public void DrawPlayerHead(Camera camera, Player drawPlayer, Vector2 position, float alpha = 1f, float scale = 1f, Color borderColor = default(Color))
40 {
42 playerHeadDrawRenderTargetContent.UsePlayer(drawPlayer);
45 _anyDirty = true;
48 {
50 _drawData.Add(new DrawData(target, position, null, Color.White, 0f, ((Texture2D)target).Size() / 2f, scale, SpriteEffects.None));
51 RenderDrawData(drawPlayer);
52 }
53 }
54
55 private void RenderDrawData(Player drawPlayer)
56 {
57 Effect pixelShader = Main.pixelShader;
59 SpriteBatch spriteBatch = Main.spriteBatch;
60 for (int i = 0; i < _drawData.Count; i++)
61 {
63 if (!cdd.sourceRect.HasValue)
64 {
65 cdd.sourceRect = cdd.texture.Frame();
66 }
67 PlayerDrawHelper.SetShaderForData(drawPlayer, drawPlayer.cHead, ref cdd);
68 if (cdd.texture != null)
69 {
70 cdd.Draw(spriteBatch);
71 }
72 }
73 pixelShader.CurrentTechnique.Passes[0].Apply();
74 }
75
76 public void PrepareRenderTarget(GraphicsDevice device, SpriteBatch spriteBatch)
77 {
78 if (_anyDirty)
79 {
80 for (int i = 0; i < _playerRenders.Length; i++)
81 {
82 _playerRenders[i].PrepareRenderTarget(device, spriteBatch);
83 }
84 _anyDirty = false;
85 }
86 }
87
88 private void CreateOutlines(float alpha, float scale, Color borderColor)
89 {
91 {
92 return;
93 }
97 float num = 2f * scale;
98 Color color = borderColor;
99 color *= alpha * alpha;
101 black *= alpha * alpha;
103 for (int i = 0; i < list.Count; i++)
104 {
105 DrawData value = list[i];
106 value.shader = colorOnlyShaderIndex;
107 value.color = black;
108 list[i] = value;
109 }
110 int num2 = 2;
112 for (int j = -num2; j <= num2; j++)
113 {
114 for (int k = -num2; k <= num2; k++)
115 {
116 if (Math.Abs(j) + Math.Abs(k) == num2)
117 {
118 vector = new Vector2((float)j * num, (float)k * num);
119 for (int l = 0; l < list.Count; l++)
120 {
121 DrawData item = list[l];
122 item.position += vector;
124 }
125 }
126 }
127 }
128 for (int m = 0; m < list.Count; m++)
129 {
131 value2.shader = colorOnlyShaderIndex;
132 value2.color = color;
133 list[m] = value2;
134 }
136 num2 = 1;
137 for (int n = -num2; n <= num2; n++)
138 {
139 for (int num3 = -num2; num3 <= num2; num3++)
140 {
141 if (Math.Abs(n) + Math.Abs(num3) == num2)
142 {
143 vector = new Vector2((float)n * num, (float)num3 * num);
144 for (int num4 = 0; num4 < list.Count; num4++)
145 {
147 item2.position += vector;
149 }
150 }
151 }
152 }
154 }
155}
unsafe EffectTechnique CurrentTechnique
Definition Effect.cs:34
void AddRange(IEnumerable< T > collection)
Definition List.cs:275
static double Abs(double value)
static void SetShaderForData(Player player, int cHead, ref DrawData cdd)
void PrepareRenderTarget(GraphicsDevice device, SpriteBatch spriteBatch)
void PrepareRenderTarget(GraphicsDevice device, SpriteBatch spriteBatch)
void CreateOutlines(float alpha, float scale, Color borderColor)
void DrawPlayerHead(Camera camera, Player drawPlayer, Vector2 position, float alpha=1f, float scale=1f, Color borderColor=default(Color))
PlayerHeadDrawRenderTargetContent[] _playerRenders
static SpriteBatch spriteBatch
Definition Main.cs:974
static Effect pixelShader
Definition Main.cs:2764
static Projectile[] projectile
Definition Main.cs:1691
static Color Transparent
Definition Color.cs:76