Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ShaderSelector.cs
Go to the documentation of this file.
1using System;
3
5
6internal class ShaderSelector
7{
8 private class ConditionalShader
9 {
10 public readonly ChromaShader Shader;
11
12 public readonly ChromaCondition Condition;
13
14 public float Opacity;
15
16 public bool IsActive { get; private set; }
17
18 public bool IsVisible => Opacity > 0f;
19
21 {
22 Shader = shader;
23 Condition = condition;
24 IsActive = false;
25 }
26
27 public void UpdateVisibility(float timeElapsed)
28 {
30 if (IsActive)
31 {
33 }
34 else
35 {
37 }
38 }
39 }
40
41 private class ShaderGroup
42 {
44
45 public void Add(ChromaShader shader, ChromaCondition condition)
46 {
47 Shaders.AddLast(new ConditionalShader(shader, condition));
48 }
49
50 public void Remove(ChromaShader shader)
51 {
53 while (linkedListNode != null)
54 {
56 if (linkedListNode.Value.Shader == shader)
57 {
58 Shaders.Remove(linkedListNode);
59 }
60 linkedListNode = next;
61 }
62 }
63
64 public void UpdateVisibility(float timeElapsed)
65 {
67 while (linkedListNode != null)
68 {
71 bool isVisible = value.IsVisible;
72 value.UpdateVisibility(timeElapsed);
73 if (!isVisible && value.IsVisible)
74 {
75 Shaders.Remove(linkedListNode);
76 Shaders.AddFirst(value);
77 }
78 linkedListNode = next;
79 }
80 }
81
82 public bool UpdateShaders(float timeElapsed)
83 {
84 foreach (ConditionalShader shader in Shaders)
85 {
87 if (shader.IsVisible && shader.Opacity >= 1f)
88 {
90 }
91 }
92 return false;
93 }
94
96 {
97 foreach (ConditionalShader shader in Shaders)
98 {
99 if (shader.IsVisible)
100 {
101 bool flag = shader.Shader.IsTransparentAt(quality);
102 ShaderBlendState blendState = new ShaderBlendState((!flag) ? BlendMode.GlobalOpacityOnly : BlendMode.PerPixelOpacity, shader.Opacity);
103 operations.Add(new ShaderOperation(shader.Shader, blendState, quality));
104 if (shader.Opacity >= 1f)
105 {
106 return !flag;
107 }
108 }
109 }
110 return false;
111 }
112 }
113
115
117
119 {
120 for (int i = 0; i < _operationsByDetailLevel.Length; i++)
121 {
123 }
124 for (int j = 0; j < 11; j++)
125 {
127 }
128 }
129
130 public void Register(ChromaShader shader, ChromaCondition condition, ShaderLayer layer)
131 {
132 _shaderGroups[(int)layer].Add(shader, condition);
133 }
134
135 public void Unregister(ChromaShader shader)
136 {
137 for (int i = 0; i < 11; i++)
138 {
139 _shaderGroups[i].Remove(shader);
140 }
141 }
142
147
154
156 {
158 {
159 shaderGroup.UpdateVisibility(timeElapsed);
160 }
161 }
162
163 private void UpdateShaders(float timeElapsed)
164 {
165 int num = _shaderGroups.Count - 1;
166 while (num >= 0 && !_shaderGroups[num].UpdateShaders(timeElapsed))
167 {
168 num--;
169 }
170 }
171
172 private void BuildOperationsList()
173 {
174 for (int i = 0; i <= 1; i++)
175 {
177 list.Clear();
178 int num = _shaderGroups.Count - 1;
179 while (num >= 0 && !_shaderGroups[num].AppendOperations((EffectDetailLevel)i, list))
180 {
181 num--;
182 }
183 list.Reverse();
184 if (list.Count > 0)
185 {
186 list[0] = list[0].WithBlendState(new ShaderBlendState(BlendMode.None));
187 }
188 }
189 }
190}
virtual void Update(float elapsedTime)
virtual bool IsTransparentAt(EffectDetailLevel quality)
ConditionalShader(ChromaShader shader, ChromaCondition condition)
void Add(ChromaShader shader, ChromaCondition condition)
bool AppendOperations(EffectDetailLevel quality, List< ShaderOperation > operations)
readonly List< ShaderGroup > _shaderGroups
ICollection< ShaderOperation > AtDetailLevel(EffectDetailLevel quality)
void UpdateShaderVisibility(float timeElapsed)
readonly List< ShaderOperation >[] _operationsByDetailLevel
void Unregister(ChromaShader shader)
void Register(ChromaShader shader, ChromaCondition condition, ShaderLayer layer)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738