Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LightingEngine.cs
Go to the documentation of this file.
1using System;
6
8
10{
11 private enum EngineState
12 {
15 Scan,
16 Blur,
17 Max
18 }
19
20 private struct PerFrameLight
21 {
22 public readonly Point Position;
23
24 public readonly Vector3 Color;
25
26 public PerFrameLight(Point position, Vector3 color)
27 {
28 Position = position;
29 Color = color;
30 }
31 }
32
33 public const int AREA_PADDING = 28;
34
35 private const int NON_VISIBLE_PADDING = 18;
36
38
40
42
44
46
48
49 private readonly Stopwatch _timer = new Stopwatch();
50
52
53 public void AddLight(int x, int y, Vector3 color)
54 {
55 _perFrameLights.Add(new PerFrameLight(new Point(x, y), color));
56 }
57
58 public void Clear()
59 {
63 }
64
65 public Vector3 GetColor(int x, int y)
66 {
68 {
69 return Vector3.Zero;
70 }
73 return _activeLightMap[x, y];
74 }
75
77 {
78 Main.renderCount = (Main.renderCount + 1) % 4;
79 _timer.Start();
81 switch (_state)
82 {
83 case EngineState.MinimapUpdate:
84 if (Main.mapDelay > 0)
85 {
86 Main.mapDelay--;
87 }
88 else
89 {
91 }
93 break;
94 case EngineState.ExportMetrics:
95 area.Inflate(28, 28);
96 Main.SceneMetrics.ScanAndExportToMain(new SceneMetricsScanSettings
97 {
98 VisualScanArea = area,
99 BiomeScanCenterPositionInWorld = Main.LocalPlayer.Center,
100 ScanOreFinderData = Main.LocalPlayer.accOreFinder
101 });
103 break;
104 case EngineState.Scan:
107 break;
108 case EngineState.Blur:
109 ProcessBlur();
110 Present();
112 break;
113 }
115 _timer.Reset();
116 }
117
118 private void IncrementState()
119 {
120 _state = (EngineState)((int)(_state + 1) % 4);
121 }
122
124 {
125 area.Inflate(28, 28);
127 _workingLightMap.SetSize(area.Width, area.Height);
128 _workingLightMap.NonVisiblePadding = 18;
131 {
132 DrawInvisibleWalls = Main.ShouldShowInvisibleWalls()
133 });
134 }
135
136 private void ProcessBlur()
137 {
141 }
142
148
149 private void UpdateLightDecay()
150 {
152 workingLightMap.LightDecayThroughAir = 0.91f;
153 workingLightMap.LightDecayThroughSolid = 0.56f;
154 workingLightMap.LightDecayThroughHoney = new Vector3(0.75f, 0.7f, 0.6f) * 0.91f;
155 switch (Main.waterStyle)
156 {
157 case 0:
158 case 1:
159 case 7:
160 case 8:
161 workingLightMap.LightDecayThroughWater = new Vector3(0.88f, 0.96f, 1.015f) * 0.91f;
162 break;
163 case 2:
164 workingLightMap.LightDecayThroughWater = new Vector3(0.94f, 0.85f, 1.01f) * 0.91f;
165 break;
166 case 3:
167 workingLightMap.LightDecayThroughWater = new Vector3(0.84f, 0.95f, 1.015f) * 0.91f;
168 break;
169 case 4:
170 workingLightMap.LightDecayThroughWater = new Vector3(0.9f, 0.86f, 1.01f) * 0.91f;
171 break;
172 case 5:
173 workingLightMap.LightDecayThroughWater = new Vector3(0.84f, 0.99f, 1.01f) * 0.91f;
174 break;
175 case 6:
176 workingLightMap.LightDecayThroughWater = new Vector3(0.83f, 0.93f, 0.98f) * 0.91f;
177 break;
178 case 9:
179 workingLightMap.LightDecayThroughWater = new Vector3(1f, 0.88f, 0.84f) * 0.91f;
180 break;
181 case 10:
182 workingLightMap.LightDecayThroughWater = new Vector3(0.83f, 1f, 1f) * 0.91f;
183 break;
184 case 12:
185 workingLightMap.LightDecayThroughWater = new Vector3(0.95f, 0.98f, 0.85f) * 0.91f;
186 break;
187 case 13:
188 workingLightMap.LightDecayThroughWater = new Vector3(0.9f, 1f, 1.02f) * 0.91f;
189 break;
190 }
191 if (Main.player[Main.myPlayer].nightVision)
192 {
193 workingLightMap.LightDecayThroughAir *= 1.03f;
194 workingLightMap.LightDecayThroughSolid *= 1.03f;
195 }
196 if (Main.player[Main.myPlayer].blind)
197 {
198 workingLightMap.LightDecayThroughAir *= 0.95f;
199 workingLightMap.LightDecayThroughSolid *= 0.95f;
200 }
201 if (Main.player[Main.myPlayer].blackout)
202 {
203 workingLightMap.LightDecayThroughAir *= 0.85f;
204 workingLightMap.LightDecayThroughSolid *= 0.85f;
205 }
206 if (Main.player[Main.myPlayer].headcovered)
207 {
208 workingLightMap.LightDecayThroughAir *= 0.85f;
209 workingLightMap.LightDecayThroughSolid *= 0.85f;
210 }
211 workingLightMap.LightDecayThroughAir *= Player.airLightDecay;
212 workingLightMap.LightDecayThroughSolid *= Player.solidLightDecay;
213 }
214
215 private void ApplyPerFrameLights()
216 {
217 for (int i = 0; i < _perFrameLights.Count; i++)
218 {
219 Point position = _perFrameLights[i].Position;
220 if (_workingProcessedArea.Contains(position))
221 {
222 Vector3 value = _perFrameLights[i].Color;
226 }
227 }
229 }
230
231 public void Rebuild()
232 {
235 _state = EngineState.MinimapUpdate;
238 }
239
240 private void ExportToMiniMap()
241 {
242 //IL_0102: Unknown result type (might be due to invalid IL or missing references)
243 //IL_010d: Expected O, but got Unknown
245 {
246 return;
247 }
250 value.Inflate(-40, -40);
252 Main.mapMinX = area.Left;
253 Main.mapMinY = area.Top;
254 Main.mapMaxX = area.Right;
255 Main.mapMaxY = area.Bottom;
256 FastParallel.For(area.Left, area.Right, (ParallelForAction)delegate(int start, int end, object context)
257 {
258 for (int i = start; i < end; i++)
259 {
260 for (int j = area.Top; j < area.Bottom; j++)
261 {
263 float num = Math.Max(Math.Max(vector.X, vector.Y), vector.Z);
264 byte light = (byte)Math.Min(255, (int)(num * 255f));
265 Main.Map.UpdateLighting(i, j, light);
266 }
267 }
268 }, (object)null);
269 Main.updateMap = true;
270 }
271}
static void For(int fromInclusive, int toExclusive, ParallelForAction callback, object context=null)
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
void SetSize(int width, int height)
Definition LightMap.cs:244
readonly List< PerFrameLight > _perFrameLights
void AddLight(int x, int y, Vector3 color)
void ExportTo(Rectangle area, LightMap outputMap, TileLightScannerOptions options)
static SceneMetrics SceneMetrics
Definition Main.cs:1344
static int mapDelay
Definition Main.cs:207
static int maxTilesY
Definition Main.cs:1116
static bool ShouldShowInvisibleWalls()
Definition Main.cs:54895
static int waterStyle
Definition Main.cs:1208
static int myPlayer
Definition Main.cs:1801
static int maxTilesX
Definition Main.cs:1114
static WorldMap Map
Definition Main.cs:1673
static bool mapEnabled
Definition Main.cs:906
static Player LocalPlayer
Definition Main.cs:2829
static Player[] player
Definition Main.cs:1803
static float solidLightDecay
Definition Player.cs:2603
static float airLightDecay
Definition Player.cs:2601
static void LightingTime(int lightingType, double timeElapsed)
delegate void ParallelForAction(int fromInclusive, int toExclusive, object context)
static Rectangle Intersect(Rectangle value1, Rectangle value2)
Definition Rectangle.cs:143
bool Contains(int x, int y)
Definition Rectangle.cs:92
static Vector3 Max(Vector3 value1, Vector3 value2)
Definition Vector3.cs:257
double TotalMilliseconds
Definition TimeSpan.cs:46