Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LegacyLighting.cs
Go to the documentation of this file.
1using System;
8
10
12{
13 public struct RectArea
14 {
15 public int Left;
16
17 public int Right;
18
19 public int Top;
20
21 public int Bottom;
22
23 public void Set(int left, int right, int top, int bottom)
24 {
25 Left = left;
26 Right = right;
27 Top = top;
28 Bottom = bottom;
29 }
30 }
31
32 private class LightingSwipeData
33 {
34 public int InnerLoop1Start;
35
36 public int InnerLoop1End;
37
38 public int InnerLoop2Start;
39
40 public int InnerLoop2End;
41
43
45 {
47 InnerLoop1End = 0;
49 InnerLoop2End = 0;
50 }
51
53 {
54 InnerLoop1Start = from.InnerLoop1Start;
55 InnerLoop1End = from.InnerLoop1End;
56 InnerLoop2Start = from.InnerLoop2Start;
57 InnerLoop2End = from.InnerLoop2End;
58 JaggedArray = from.JaggedArray;
59 }
60 }
61
62 private class LightingState
63 {
64 public float R;
65
66 public float R2;
67
68 public float G;
69
70 public float G2;
71
72 public float B;
73
74 public float B2;
75
76 public bool StopLight;
77
78 public bool WetLight;
79
80 public bool HoneyLight;
81
83 {
84 return new Vector3(R, G, B);
85 }
86 }
87
88 private struct ColorTriplet
89 {
90 public float R;
91
92 public float G;
93
94 public float B;
95
96 public ColorTriplet(float R, float G, float B)
97 {
98 this.R = R;
99 this.G = G;
100 this.B = B;
101 }
102
104 {
105 R = (G = (B = averageColor));
106 }
107 }
108
109 public static int RenderPhases = 4;
110
111 private bool _rgb = true;
112
113 private int _offScreenTiles2 = 35;
114
115 private float _oldSkyColor;
116
117 private float _skyColor;
118
120
122
123 private int _requestedRectTop;
124
126
128
130
132
134
135 private int _scrX;
136
137 private int _scrY;
138
139 private int _minX;
140
141 private int _maxX;
142
143 private int _minY;
144
145 private int _maxY;
146
147 private const int MAX_TEMP_LIGHTS = 2000;
148
150
151 private int _expandedRectLeft;
152
153 private int _expandedRectTop;
154
156
158
159 private float _negLight = 0.04f;
160
161 private float _negLight2 = 0.16f;
162
163 private float _wetLightR = 0.16f;
164
165 private float _wetLightG = 0.16f;
166
167 private float _wetLightB = 0.16f;
168
169 private float _honeyLightR = 0.16f;
170
171 private float _honeyLightG = 0.16f;
172
173 private float _honeyLightB = 0.16f;
174
175 private float _blueWave = 1f;
176
177 private int _blueDir = 1;
178
180
182
184
186
188
189 private readonly Camera _camera;
190
192
193 private LightMap _lightMap = new LightMap();
194
195 public int Mode { get; set; }
196
197 public bool IsColorOrWhiteMode => Mode < 2;
198
200 {
201 _camera = camera;
202 }
203
204 public Vector3 GetColor(int x, int y)
205 {
209 if (num < 0 || num2 < 0 || (float)num >= unscaledSize.X / 16f + (float)(Lighting.OffScreenTiles * 2) + 10f || (float)num2 >= unscaledSize.Y / 16f + (float)(Lighting.OffScreenTiles * 2))
210 {
211 return Vector3.Zero;
212 }
215 }
216
217 public void Rebuild()
218 {
222 for (int i = 0; i < _threadSwipes.Length; i++)
223 {
225 }
226 int num = (int)_camera.UnscaledSize.X / 16 + 90 + 10;
227 int num2 = (int)_camera.UnscaledSize.Y / 16 + 90 + 10;
228 _lightMap.SetSize(num, num2);
229 if (_states != null && _states.Length >= num && _states[0].Length >= num2)
230 {
231 return;
232 }
233 _states = new LightingState[num][];
235 for (int j = 0; j < num2; j++)
236 {
237 _axisFlipStates[j] = new LightingState[num];
238 }
239 for (int k = 0; k < num; k++)
240 {
242 for (int l = 0; l < num2; l++)
243 {
246 }
247 _states[k] = array;
248 }
249 }
250
251 public void AddLight(int x, int y, Vector3 color)
252 {
253 float x2 = color.X;
254 float y2 = color.Y;
255 float z = color.Z;
257 {
258 return;
259 }
260 Point16 key = new Point16(x, y);
262 {
263 if (_rgb)
264 {
265 if (value.R < x2)
266 {
267 value.R = x2;
268 }
269 if (value.G < y2)
270 {
271 value.G = y2;
272 }
273 if (value.B < z)
274 {
275 value.B = z;
276 }
278 }
279 else
280 {
281 float num = (x2 + y2 + z) / 3f;
282 if (value.R < num)
283 {
284 _tempLights[key] = new ColorTriplet(num);
285 }
286 }
287 }
288 else
289 {
290 value = ((!_rgb) ? new ColorTriplet((x2 + y2 + z) / 3f) : new ColorTriplet(x2, y2, z));
292 }
293 }
294
296 {
298 float num = (float)(int)Main.tileColor.R / 255f;
299 float num2 = (float)(int)Main.tileColor.G / 255f;
300 float num3 = (float)(int)Main.tileColor.B / 255f;
301 _skyColor = (num + num2 + num3) / 3f;
303 {
304 _offScreenTiles2 = 34;
305 Lighting.OffScreenTiles = 40;
306 }
307 else
308 {
309 _offScreenTiles2 = 18;
310 Lighting.OffScreenTiles = 23;
311 }
315 _requestedRectBottom = area.Bottom;
323 if (Main.renderCount < 3)
324 {
325 DoColors();
326 }
327 if (Main.renderCount == 2)
328 {
330 }
331 else if (!Main.renderNow)
332 {
334 if (Netplay.Connection.StatusMax > 0)
335 {
336 Main.mapTime = 1;
337 }
338 if (Main.mapDelay > 0)
339 {
340 Main.mapDelay--;
341 }
342 else if (Main.mapTime == 0 && Main.mapEnabled && Main.renderCount == 3)
343 {
344 try
345 {
347 }
348 catch
349 {
350 }
351 }
352 if (_oldSkyColor != _skyColor)
353 {
355 }
356 }
358 {
360 }
361 }
362
364 {
365 Main.mapTime = Main.mapTimeMax;
366 Main.updateMap = true;
367 int num = 40;
369 float x = _camera.UnscaledSize.X;
370 float y = _camera.UnscaledSize.Y;
371 x = (int)(x / Main.GameViewMatrix.Zoom.X);
372 y = (int)(y / Main.GameViewMatrix.Zoom.Y);
374 int value = (int)Math.Floor(vector.X / 16f);
375 int value2 = (int)Math.Floor((vector.X + x) / 16f) + 1;
376 int value3 = (int)Math.Floor(vector.Y / 16f);
377 int value4 = (int)Math.Floor((vector.Y + y) / 16f) + 1;
382 Main.mapMinX = Utils.Clamp(_requestedRectLeft, num, Main.maxTilesX - num);
383 Main.mapMaxX = Utils.Clamp(_requestedRectRight, num, Main.maxTilesX - num);
384 Main.mapMinY = Utils.Clamp(_requestedRectTop, num, Main.maxTilesY - num);
385 Main.mapMaxY = Utils.Clamp(_requestedRectBottom, num, Main.maxTilesY - num);
386 Main.mapMinX = Utils.Clamp(Main.mapMinX, value, value2);
387 Main.mapMaxX = Utils.Clamp(Main.mapMaxX, value, value2);
388 Main.mapMinY = Utils.Clamp(Main.mapMinY, value3, value4);
389 Main.mapMaxY = Utils.Clamp(Main.mapMaxY, value3, value4);
391 for (int i = Main.mapMinX; i < Main.mapMaxX; i++)
392 {
394 for (int j = Main.mapMinY; j < Main.mapMaxY; j++)
395 {
397 Tile tile = Main.tile[i, j];
398 float num2 = 0f;
399 if (lightingState.R > num2)
400 {
402 }
403 if (lightingState.G > num2)
404 {
406 }
407 if (lightingState.B > num2)
408 {
410 }
412 {
413 num2 *= 1.5f;
414 }
415 byte b = (byte)Math.Min(255f, num2 * 255f);
416 if ((double)j < Main.worldSurface && !tile.active() && tile.wall == 0 && tile.liquid == 0)
417 {
418 b = 22;
419 }
420 if (b > 18 || Main.Map[i, j].Light > 0)
421 {
422 if (b < 22)
423 {
424 b = 22;
425 }
426 Main.Map.UpdateLighting(i, j, b);
427 }
428 }
429 }
430 }
431
432 private void UpdateLightToSkyColor(float tileR, float tileG, float tileB)
433 {
434 int num = Utils.Clamp(_expandedRectLeft, 0, Main.maxTilesX - 1);
435 int num2 = Utils.Clamp(_expandedRectRight, 0, Main.maxTilesX - 1);
436 int num3 = Utils.Clamp(_expandedRectTop, 0, Main.maxTilesY - 1);
437 int num4 = Utils.Clamp(_expandedRectBottom, 0, (int)Main.worldSurface - 1);
438 if (!((double)num3 < Main.worldSurface))
439 {
440 return;
441 }
442 for (int i = num; i < num2; i++)
443 {
445 for (int j = num3; j < num4; j++)
446 {
448 Tile tile = Main.tile[i, j];
449 if (tile == null)
450 {
451 tile = new Tile();
452 Main.tile[i, j] = tile;
453 }
454 if ((!tile.active() || !Main.tileNoSunLight[tile.type]) && lightingState.R < _skyColor && tile.liquid < 200 && (Main.wallLight[tile.wall] || tile.wall == 73))
455 {
456 lightingState.R = tileR;
457 if (lightingState.G < _skyColor)
458 {
459 lightingState.G = tileG;
460 }
461 if (lightingState.B < _skyColor)
462 {
463 lightingState.B = tileB;
464 }
465 }
466 }
467 }
468 }
469
471 {
472 Vector2 screenLastPosition = Main.screenLastPosition;
474 int num = (int)Math.Floor(unscaledPosition.X / 16f) - (int)Math.Floor(screenLastPosition.X / 16f);
475 if (num > 5 || num < -5)
476 {
477 num = 0;
478 }
479 int num2;
480 int num3;
481 int num4;
482 if (num < 0)
483 {
484 num2 = -1;
485 num *= -1;
487 num4 = num;
488 }
489 else
490 {
491 num2 = 1;
492 num3 = 0;
493 num4 = maxLightArrayX - num;
494 }
495 int num5 = (int)Math.Floor(unscaledPosition.Y / 16f) - (int)Math.Floor(screenLastPosition.Y / 16f);
496 if (num5 > 5 || num5 < -5)
497 {
498 num5 = 0;
499 }
500 int num6;
501 int num7;
502 int num8;
503 if (num5 < 0)
504 {
505 num6 = -1;
506 num5 *= -1;
508 num8 = num5;
509 }
510 else
511 {
512 num6 = 1;
513 num7 = 0;
515 }
516 if (num == 0 && num5 == 0)
517 {
518 return;
519 }
520 for (int i = num3; i != num4; i += num2)
521 {
523 LightingState[] array2 = _states[i + num * num2];
524 for (int j = num7; j != num8; j += num6)
525 {
528 obj.R = lightingState.R;
529 obj.G = lightingState.G;
530 obj.B = lightingState.B;
531 }
532 }
533 }
534
536 {
538 int num = (int)Math.Floor(unscaledPosition.X / 16f) - _scrX;
539 int num2 = (int)Math.Floor(unscaledPosition.Y / 16f) - _scrY;
540 if (num > 16)
541 {
542 num = 0;
543 }
544 if (num2 > 16)
545 {
546 num2 = 0;
547 }
548 int num3 = 0;
549 int num4 = maxLightArrayX;
550 int num5 = 0;
551 int num6 = maxLightArrayY;
552 if (num < 0)
553 {
554 num3 -= num;
555 }
556 else
557 {
558 num4 -= num;
559 }
560 if (num2 < 0)
561 {
562 num5 -= num2;
563 }
564 else
565 {
566 num6 -= num2;
567 }
568 if (_rgb)
569 {
570 int num7 = maxLightArrayX;
571 if (_states.Length <= num7 + num)
572 {
573 num7 = _states.Length - num - 1;
574 }
575 for (int i = num3; i < num7; i++)
576 {
578 LightingState[] array2 = _states[i + num];
579 int num8 = num6;
580 if (array2.Length <= num8 + num)
581 {
582 num8 = array2.Length - num2 - 1;
583 }
584 for (int j = num5; j < num8; j++)
585 {
588 obj.R = lightingState.R2;
589 obj.G = lightingState.G2;
590 obj.B = lightingState.B2;
591 }
592 }
593 return;
594 }
595 int num9 = num4;
596 if (_states.Length <= num9 + num)
597 {
598 num9 = _states.Length - num - 1;
599 }
600 for (int k = num3; k < num9; k++)
601 {
603 LightingState[] array4 = _states[k + num];
604 int num10 = num6;
605 if (array4.Length <= num10 + num)
606 {
607 num10 = array4.Length - num2 - 1;
608 }
609 for (int l = num5; l < num10; l++)
610 {
613 obj2.R = lightingState2.R2;
614 obj2.G = lightingState2.R2;
615 obj2.B = lightingState2.R2;
616 }
617 }
618 }
619
620 public void Clear()
621 {
622 int num = (int)_camera.UnscaledSize.X / 16 + Lighting.OffScreenTiles * 2;
623 int num2 = (int)_camera.UnscaledSize.Y / 16 + Lighting.OffScreenTiles * 2;
624 for (int i = 0; i < num; i++)
625 {
626 if (i >= _states.Length)
627 {
628 continue;
629 }
631 for (int j = 0; j < num2; j++)
632 {
633 if (j < array.Length)
634 {
636 obj.R = 0f;
637 obj.G = 0f;
638 obj.B = 0f;
639 }
640 }
641 }
642 }
643
644 private void PreRenderPhase()
645 {
646 _ = (float)(int)Main.tileColor.R / 255f;
647 _ = (float)(int)Main.tileColor.G / 255f;
648 _ = (float)(int)Main.tileColor.B / 255f;
650 stopwatch.Start();
651 int num = 0;
652 int num2 = (int)_camera.UnscaledSize.X / 16 + Lighting.OffScreenTiles * 2 + 10;
653 int num3 = 0;
654 int num4 = (int)_camera.UnscaledSize.Y / 16 + Lighting.OffScreenTiles * 2 + 10;
655 _minX = num2;
656 _maxX = num;
657 _minY = num4;
658 _maxY = num3;
659 _rgb = Mode == 0 || Mode == 3;
660 for (int i = num; i < num2; i++)
661 {
663 for (int j = num3; j < num4; j++)
664 {
666 obj.R2 = 0f;
667 obj.G2 = 0f;
668 obj.B2 = 0f;
669 obj.StopLight = false;
670 obj.WetLight = false;
671 obj.HoneyLight = false;
672 }
673 }
674 if (Main.wofNPCIndex >= 0 && Main.player[Main.myPlayer].gross)
675 {
676 try
677 {
678 int num5 = (int)_camera.UnscaledPosition.Y / 16 - 10;
679 int num6 = (int)(_camera.UnscaledPosition.Y + _camera.UnscaledSize.Y) / 16 + 10;
680 int num7 = (int)Main.npc[Main.wofNPCIndex].position.X / 16;
681 num7 = ((Main.npc[Main.wofNPCIndex].direction <= 0) ? (num7 + 2) : (num7 - 3));
682 int num8 = num7 + 8;
683 float num9 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
684 float num10 = 0.3f;
685 float num11 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
686 num9 *= 0.2f;
687 num10 *= 0.1f;
688 num11 *= 0.3f;
689 for (int k = num7; k <= num8; k++)
690 {
692 for (int l = num5; l <= num6; l++)
693 {
695 if (lightingState.R2 < num9)
696 {
697 lightingState.R2 = num9;
698 }
699 if (lightingState.G2 < num10)
700 {
701 lightingState.G2 = num10;
702 }
703 if (lightingState.B2 < num11)
704 {
705 lightingState.B2 = num11;
706 }
707 }
708 }
709 }
710 catch
711 {
712 }
713 }
714 num = Utils.Clamp(_expandedRectLeft, 5, Main.maxTilesX - 1);
715 num2 = Utils.Clamp(_expandedRectRight, 5, Main.maxTilesX - 1);
716 num3 = Utils.Clamp(_expandedRectTop, 5, Main.maxTilesY - 1);
718 Main.SceneMetrics.ScanAndExportToMain(new SceneMetricsScanSettings
719 {
720 VisualScanArea = new Rectangle(num, num3, num2 - num, num4 - num3),
721 BiomeScanCenterPositionInWorld = Main.LocalPlayer.Center,
722 ScanOreFinderData = Main.LocalPlayer.accOreFinder
723 });
726 {
727 DrawInvisibleWalls = Main.ShouldShowInvisibleWalls()
728 });
729 for (int m = num; m < num2; m++)
730 {
732 for (int n = num3; n < num4; n++)
733 {
735 Tile tile = Main.tile[m, n];
736 if (tile == null)
737 {
738 tile = new Tile();
739 Main.tile[m, n] = tile;
740 }
741 _lightMap.GetLight(m - num, n - num3, out var color);
742 if (_rgb)
743 {
744 lightingState2.R2 = color.X;
745 lightingState2.G2 = color.Y;
746 lightingState2.B2 = color.Z;
747 }
748 else
749 {
750 lightingState2.B2 = (lightingState2.G2 = (lightingState2.R2 = (color.X + color.Y + color.Z) / 3f));
751 }
752 switch (_lightMap.GetMask(m - num, n - num3))
753 {
754 case LightMaskMode.Solid:
755 lightingState2.StopLight = true;
756 break;
757 case LightMaskMode.Water:
758 lightingState2.WetLight = true;
759 break;
760 case LightMaskMode.Honey:
761 lightingState2.WetLight = true;
762 lightingState2.HoneyLight = true;
763 break;
764 }
765 if (lightingState2.R2 > 0f || (_rgb && (lightingState2.G2 > 0f || lightingState2.B2 > 0f)))
766 {
767 int num12 = m - _expandedRectLeft;
768 int num13 = n - _expandedRectTop;
769 if (_minX > num12)
770 {
771 _minX = num12;
772 }
773 if (_maxX < num12 + 1)
774 {
775 _maxX = num12 + 1;
776 }
777 if (_minY > num13)
778 {
779 _minY = num13;
780 }
781 if (_maxY < num13 + 1)
782 {
783 _maxY = num13 + 1;
784 }
785 }
786 }
787 }
789 {
790 int num14 = tempLight.Key.X - _requestedRectLeft + Lighting.OffScreenTiles;
791 int num15 = tempLight.Key.Y - _requestedRectTop + Lighting.OffScreenTiles;
792 if (num14 >= 0 && (float)num14 < _camera.UnscaledSize.X / 16f + (float)(Lighting.OffScreenTiles * 2) + 10f && num15 >= 0 && (float)num15 < _camera.UnscaledSize.Y / 16f + (float)(Lighting.OffScreenTiles * 2) + 10f)
793 {
795 if (lightingState3.R2 < tempLight.Value.R)
796 {
797 lightingState3.R2 = tempLight.Value.R;
798 }
799 if (lightingState3.G2 < tempLight.Value.G)
800 {
801 lightingState3.G2 = tempLight.Value.G;
802 }
803 if (lightingState3.B2 < tempLight.Value.B)
804 {
805 lightingState3.B2 = tempLight.Value.B;
806 }
807 if (_minX > num14)
808 {
809 _minX = num14;
810 }
811 if (_maxX < num14 + 1)
812 {
813 _maxX = num14 + 1;
814 }
815 if (_minY > num15)
816 {
817 _minY = num15;
818 }
819 if (_maxY < num15 + 1)
820 {
821 _maxY = num15 + 1;
822 }
823 }
824 }
825 if (!Main.gamePaused)
826 {
828 }
839 Main.renderCount = 0;
840 TimeLogger.LightingTime(0, stopwatch.Elapsed.TotalMilliseconds);
841 DoColors();
842 }
843
844 private void DoColors()
845 {
846 //IL_09bf: Unknown result type (might be due to invalid IL or missing references)
847 //IL_09c6: Expected O, but got Unknown
848 //IL_09cf: Unknown result type (might be due to invalid IL or missing references)
849 //IL_09d6: Expected O, but got Unknown
850 //IL_09df: Unknown result type (might be due to invalid IL or missing references)
851 //IL_09e6: Expected O, but got Unknown
852 //IL_09ef: Unknown result type (might be due to invalid IL or missing references)
853 //IL_09f6: Expected O, but got Unknown
854 //IL_09ff: Unknown result type (might be due to invalid IL or missing references)
855 //IL_0a06: Expected O, but got Unknown
857 {
858 _blueWave += (float)_blueDir * 0.0001f;
859 if (_blueWave > 1f)
860 {
861 _blueWave = 1f;
862 _blueDir = -1;
863 }
864 else if (_blueWave < 0.97f)
865 {
866 _blueWave = 0.97f;
867 _blueDir = 1;
868 }
869 if (_rgb)
870 {
871 _negLight = 0.91f;
872 _negLight2 = 0.56f;
874 _honeyLightR = 0.75f * _negLight * _blueWave;
876 switch (Main.waterStyle)
877 {
878 case 0:
879 case 1:
880 case 7:
881 case 8:
882 _wetLightG = 0.96f * _negLight * _blueWave;
883 _wetLightR = 0.88f * _negLight * _blueWave;
884 _wetLightB = 1.015f * _negLight * _blueWave;
885 break;
886 case 2:
887 _wetLightG = 0.85f * _negLight * _blueWave;
888 _wetLightR = 0.94f * _negLight * _blueWave;
889 _wetLightB = 1.01f * _negLight * _blueWave;
890 break;
891 case 3:
892 _wetLightG = 0.95f * _negLight * _blueWave;
893 _wetLightR = 0.84f * _negLight * _blueWave;
894 _wetLightB = 1.015f * _negLight * _blueWave;
895 break;
896 case 4:
897 _wetLightG = 0.86f * _negLight * _blueWave;
898 _wetLightR = 0.9f * _negLight * _blueWave;
899 _wetLightB = 1.01f * _negLight * _blueWave;
900 break;
901 case 5:
902 _wetLightG = 0.99f * _negLight * _blueWave;
903 _wetLightR = 0.84f * _negLight * _blueWave;
904 _wetLightB = 1.01f * _negLight * _blueWave;
905 break;
906 case 6:
907 _wetLightR = 0.83f * _negLight * _blueWave;
908 _wetLightG = 0.93f * _negLight * _blueWave;
909 _wetLightB = 0.98f * _negLight * _blueWave;
910 break;
911 case 9:
912 _wetLightG = 0.88f * _negLight * _blueWave;
914 _wetLightB = 0.84f * _negLight * _blueWave;
915 break;
916 case 10:
918 _wetLightR = 0.83f * _negLight * _blueWave;
920 break;
921 case 12:
922 _wetLightG = 0.98f * _negLight * _blueWave;
923 _wetLightR = 0.95f * _negLight * _blueWave;
924 _wetLightB = 0.85f * _negLight * _blueWave;
925 break;
926 default:
927 _wetLightG = 0f;
928 _wetLightR = 0f;
929 _wetLightB = 0f;
930 break;
931 }
932 }
933 else
934 {
935 _negLight = 0.9f;
936 _negLight2 = 0.54f;
937 _wetLightR = 0.95f * _negLight * _blueWave;
938 }
939 if (Main.player[Main.myPlayer].nightVision)
940 {
941 _negLight *= 1.03f;
942 _negLight2 *= 1.03f;
943 }
944 if (Main.player[Main.myPlayer].blind)
945 {
946 _negLight *= 0.95f;
947 _negLight2 *= 0.95f;
948 }
949 if (Main.player[Main.myPlayer].blackout)
950 {
951 _negLight *= 0.85f;
952 _negLight2 *= 0.85f;
953 }
954 if (Main.player[Main.myPlayer].headcovered)
955 {
956 _negLight *= 0.85f;
957 _negLight2 *= 0.85f;
958 }
959 }
960 else
961 {
962 _negLight = 0.04f;
963 _negLight2 = 0.16f;
964 if (Main.player[Main.myPlayer].nightVision)
965 {
966 _negLight -= 0.013f;
967 _negLight2 -= 0.04f;
968 }
969 if (Main.player[Main.myPlayer].blind)
970 {
971 _negLight += 0.03f;
972 _negLight2 += 0.06f;
973 }
974 if (Main.player[Main.myPlayer].blackout)
975 {
976 _negLight += 0.09f;
977 _negLight2 += 0.18f;
978 }
979 if (Main.player[Main.myPlayer].headcovered)
980 {
981 _negLight += 0.09f;
982 _negLight2 += 0.18f;
983 }
984 _wetLightR = _negLight * 1.2f;
985 _wetLightG = _negLight * 1.1f;
986 }
987 int num;
988 int num2;
989 switch (Main.renderCount)
990 {
991 case 0:
992 num = 0;
993 num2 = 1;
994 break;
995 case 1:
996 num = 1;
997 num2 = 3;
998 break;
999 case 2:
1000 num = 3;
1001 num2 = 4;
1002 break;
1003 default:
1004 num = 0;
1005 num2 = 0;
1006 break;
1007 }
1009 int left = _expandedArea.Left;
1010 int top = _expandedArea.Top;
1011 for (int i = num; i < num2; i++)
1012 {
1013 stopwatch.Restart();
1014 int num3 = 0;
1015 int num4 = 0;
1016 switch (i)
1017 {
1018 case 0:
1019 _swipe.InnerLoop1Start = _minBoundArea.Top - top;
1020 _swipe.InnerLoop2Start = _minBoundArea.Bottom - top;
1021 _swipe.InnerLoop1End = _requestedArea.Bottom + RenderPhases - top;
1022 _swipe.InnerLoop2End = _requestedArea.Top - RenderPhases - top;
1023 num3 = _minBoundArea.Left - left;
1024 num4 = _minBoundArea.Right - left;
1025 _swipe.JaggedArray = _states;
1026 break;
1027 case 1:
1028 _swipe.InnerLoop1Start = _expandedArea.Left - left;
1029 _swipe.InnerLoop2Start = _expandedArea.Right - left;
1030 _swipe.InnerLoop1End = _requestedArea.Right + RenderPhases - left;
1031 _swipe.InnerLoop2End = _requestedArea.Left - RenderPhases - left;
1032 num3 = _expandedArea.Top - top;
1033 num4 = _expandedArea.Bottom - top;
1034 _swipe.JaggedArray = _axisFlipStates;
1035 break;
1036 case 2:
1037 _swipe.InnerLoop1Start = _offScreenTiles2ExpandedArea.Top - top;
1038 _swipe.InnerLoop2Start = _offScreenTiles2ExpandedArea.Bottom - top;
1039 _swipe.InnerLoop1End = _requestedArea.Bottom + RenderPhases - top;
1040 _swipe.InnerLoop2End = _requestedArea.Top - RenderPhases - top;
1041 num3 = _offScreenTiles2ExpandedArea.Left - left;
1042 num4 = _offScreenTiles2ExpandedArea.Right - left;
1043 _swipe.JaggedArray = _states;
1044 break;
1045 case 3:
1046 _swipe.InnerLoop1Start = _offScreenTiles2ExpandedArea.Left - left;
1047 _swipe.InnerLoop2Start = _offScreenTiles2ExpandedArea.Right - left;
1048 _swipe.InnerLoop1End = _requestedArea.Right + RenderPhases - left;
1049 _swipe.InnerLoop2End = _requestedArea.Left - RenderPhases - left;
1050 num3 = _offScreenTiles2ExpandedArea.Top - top;
1051 num4 = _offScreenTiles2ExpandedArea.Bottom - top;
1052 _swipe.JaggedArray = _axisFlipStates;
1053 break;
1054 }
1056 {
1057 _swipe.InnerLoop1Start = _swipe.InnerLoop1End;
1058 }
1060 {
1061 _swipe.InnerLoop2Start = _swipe.InnerLoop2End;
1062 }
1063 if (num3 > num4)
1064 {
1065 num3 = num4;
1066 }
1068 {
1069 0 => (object)new ParallelForAction(doColors_Mode0_Swipe),
1070 1 => (object)new ParallelForAction(doColors_Mode1_Swipe),
1071 2 => (object)new ParallelForAction(doColors_Mode2_Swipe),
1072 3 => (object)new ParallelForAction(doColors_Mode3_Swipe),
1073 _ => (object)new ParallelForAction(doColors_Mode0_Swipe),
1074 }), (object)_swipe);
1075 _swipeRandom.NextSeed();
1076 TimeLogger.LightingTime(i + 1, stopwatch.Elapsed.TotalMilliseconds);
1077 }
1078 }
1079
1080 private void doColors_Mode0_Swipe(int outerLoopStart, int outerLoopEnd, object context)
1081 {
1083 FastRandom fastRandom = default(FastRandom);
1084 try
1085 {
1086 bool flag = true;
1087 while (true)
1088 {
1089 int num;
1090 int val;
1091 int val2;
1092 if (flag)
1093 {
1094 num = 1;
1095 val = lightingSwipeData.InnerLoop1Start;
1096 val2 = lightingSwipeData.InnerLoop1End;
1097 }
1098 else
1099 {
1100 num = -1;
1101 val = lightingSwipeData.InnerLoop2Start;
1102 val2 = lightingSwipeData.InnerLoop2End;
1103 }
1104 for (int i = outerLoopStart; i < outerLoopEnd; i++)
1105 {
1106 LightingState[] array = lightingSwipeData.JaggedArray[i];
1107 float num2 = 0f;
1108 float num3 = 0f;
1109 float num4 = 0f;
1110 int num5 = Math.Min(array.Length - 1, Math.Max(0, val));
1111 int num6 = Math.Min(array.Length - 1, Math.Max(0, val2));
1112 for (int j = num5; j != num6; j += num)
1113 {
1116 bool flag2;
1117 bool flag3 = (flag2 = false);
1118 if (lightingState.R2 > num2)
1119 {
1120 num2 = lightingState.R2;
1121 }
1122 else if ((double)num2 <= 0.0185)
1123 {
1124 flag3 = true;
1125 }
1126 else if (lightingState.R2 < num2)
1127 {
1128 lightingState.R2 = num2;
1129 }
1130 if (lightingState.WetLight)
1131 {
1132 fastRandom = _swipeRandom.WithModifier((ulong)(i * 1000 + j));
1133 }
1134 if (!flag3 && lightingState2.R2 <= num2)
1135 {
1136 num2 = (lightingState.StopLight ? (num2 * _negLight2) : ((!lightingState.WetLight) ? (num2 * _negLight) : ((!lightingState.HoneyLight) ? (num2 * (_wetLightR * (float)fastRandom.Next(98, 100) * 0.01f)) : (num2 * (_honeyLightR * (float)fastRandom.Next(98, 100) * 0.01f)))));
1137 }
1138 if (lightingState.G2 > num3)
1139 {
1140 num3 = lightingState.G2;
1141 }
1142 else if ((double)num3 <= 0.0185)
1143 {
1144 flag2 = true;
1145 }
1146 else
1147 {
1148 lightingState.G2 = num3;
1149 }
1150 if (!flag2 && lightingState2.G2 <= num3)
1151 {
1152 num3 = (lightingState.StopLight ? (num3 * _negLight2) : ((!lightingState.WetLight) ? (num3 * _negLight) : ((!lightingState.HoneyLight) ? (num3 * (_wetLightG * (float)fastRandom.Next(97, 100) * 0.01f)) : (num3 * (_honeyLightG * (float)fastRandom.Next(97, 100) * 0.01f)))));
1153 }
1154 if (lightingState.B2 > num4)
1155 {
1156 num4 = lightingState.B2;
1157 }
1158 else
1159 {
1160 if ((double)num4 <= 0.0185)
1161 {
1162 continue;
1163 }
1164 lightingState.B2 = num4;
1165 }
1166 if (!(lightingState2.B2 >= num4))
1167 {
1168 num4 = ((!lightingState.StopLight) ? ((!lightingState.WetLight) ? (num4 * _negLight) : ((!lightingState.HoneyLight) ? (num4 * (_wetLightB * (float)fastRandom.Next(97, 100) * 0.01f)) : (num4 * (_honeyLightB * (float)fastRandom.Next(97, 100) * 0.01f)))) : (num4 * _negLight2));
1169 }
1170 }
1171 }
1172 if (flag)
1173 {
1174 flag = false;
1175 continue;
1176 }
1177 break;
1178 }
1179 }
1180 catch
1181 {
1182 }
1183 }
1184
1185 private void doColors_Mode1_Swipe(int outerLoopStart, int outerLoopEnd, object context)
1186 {
1188 FastRandom fastRandom = default(FastRandom);
1189 try
1190 {
1191 bool flag = true;
1192 while (true)
1193 {
1194 int num;
1195 int num2;
1196 int num3;
1197 if (flag)
1198 {
1199 num = 1;
1200 num2 = lightingSwipeData.InnerLoop1Start;
1201 num3 = lightingSwipeData.InnerLoop1End;
1202 }
1203 else
1204 {
1205 num = -1;
1206 num2 = lightingSwipeData.InnerLoop2Start;
1207 num3 = lightingSwipeData.InnerLoop2End;
1208 }
1209 for (int i = outerLoopStart; i < outerLoopEnd; i++)
1210 {
1211 LightingState[] array = lightingSwipeData.JaggedArray[i];
1212 float num4 = 0f;
1213 for (int j = num2; j != num3; j += num)
1214 {
1216 if (lightingState.R2 > num4)
1217 {
1218 num4 = lightingState.R2;
1219 }
1220 else
1221 {
1222 if ((double)num4 <= 0.0185)
1223 {
1224 continue;
1225 }
1226 if (lightingState.R2 < num4)
1227 {
1228 lightingState.R2 = num4;
1229 }
1230 }
1231 if (!(array[j + num].R2 > num4))
1232 {
1233 if (lightingState.StopLight)
1234 {
1235 num4 *= _negLight2;
1236 }
1237 else if (lightingState.WetLight)
1238 {
1239 fastRandom = _swipeRandom.WithModifier((ulong)(i * 1000 + j));
1240 num4 = ((!lightingState.HoneyLight) ? (num4 * (_wetLightR * (float)fastRandom.Next(98, 100) * 0.01f)) : (num4 * (_honeyLightR * (float)fastRandom.Next(98, 100) * 0.01f)));
1241 }
1242 else
1243 {
1244 num4 *= _negLight;
1245 }
1246 }
1247 }
1248 }
1249 if (flag)
1250 {
1251 flag = false;
1252 continue;
1253 }
1254 break;
1255 }
1256 }
1257 catch
1258 {
1259 }
1260 }
1261
1262 private void doColors_Mode2_Swipe(int outerLoopStart, int outerLoopEnd, object context)
1263 {
1265 try
1266 {
1267 bool flag = true;
1268 while (true)
1269 {
1270 int num;
1271 int num2;
1272 int num3;
1273 if (flag)
1274 {
1275 num = 1;
1276 num2 = lightingSwipeData.InnerLoop1Start;
1277 num3 = lightingSwipeData.InnerLoop1End;
1278 }
1279 else
1280 {
1281 num = -1;
1282 num2 = lightingSwipeData.InnerLoop2Start;
1283 num3 = lightingSwipeData.InnerLoop2End;
1284 }
1285 for (int i = outerLoopStart; i < outerLoopEnd; i++)
1286 {
1287 LightingState[] array = lightingSwipeData.JaggedArray[i];
1288 float num4 = 0f;
1289 for (int j = num2; j != num3; j += num)
1290 {
1292 if (lightingState.R2 > num4)
1293 {
1294 num4 = lightingState.R2;
1295 }
1296 else
1297 {
1298 if (num4 <= 0f)
1299 {
1300 continue;
1301 }
1302 lightingState.R2 = num4;
1303 }
1304 num4 = ((!lightingState.StopLight) ? ((!lightingState.WetLight) ? (num4 - _negLight) : (num4 - _wetLightR)) : (num4 - _negLight2));
1305 }
1306 }
1307 if (flag)
1308 {
1309 flag = false;
1310 continue;
1311 }
1312 break;
1313 }
1314 }
1315 catch
1316 {
1317 }
1318 }
1319
1320 private void doColors_Mode3_Swipe(int outerLoopStart, int outerLoopEnd, object context)
1321 {
1323 try
1324 {
1325 bool flag = true;
1326 while (true)
1327 {
1328 int num;
1329 int num2;
1330 int num3;
1331 if (flag)
1332 {
1333 num = 1;
1334 num2 = lightingSwipeData.InnerLoop1Start;
1335 num3 = lightingSwipeData.InnerLoop1End;
1336 }
1337 else
1338 {
1339 num = -1;
1340 num2 = lightingSwipeData.InnerLoop2Start;
1341 num3 = lightingSwipeData.InnerLoop2End;
1342 }
1343 for (int i = outerLoopStart; i < outerLoopEnd; i++)
1344 {
1345 LightingState[] array = lightingSwipeData.JaggedArray[i];
1346 float num4 = 0f;
1347 float num5 = 0f;
1348 float num6 = 0f;
1349 for (int j = num2; j != num3; j += num)
1350 {
1352 bool flag2;
1353 bool flag3 = (flag2 = false);
1354 if (lightingState.R2 > num4)
1355 {
1356 num4 = lightingState.R2;
1357 }
1358 else if (num4 <= 0f)
1359 {
1360 flag3 = true;
1361 }
1362 else
1363 {
1364 lightingState.R2 = num4;
1365 }
1366 if (!flag3)
1367 {
1368 num4 = (lightingState.StopLight ? (num4 - _negLight2) : ((!lightingState.WetLight) ? (num4 - _negLight) : (num4 - _wetLightR)));
1369 }
1370 if (lightingState.G2 > num5)
1371 {
1372 num5 = lightingState.G2;
1373 }
1374 else if (num5 <= 0f)
1375 {
1376 flag2 = true;
1377 }
1378 else
1379 {
1380 lightingState.G2 = num5;
1381 }
1382 if (!flag2)
1383 {
1384 num5 = (lightingState.StopLight ? (num5 - _negLight2) : ((!lightingState.WetLight) ? (num5 - _negLight) : (num5 - _wetLightG)));
1385 }
1386 if (lightingState.B2 > num6)
1387 {
1388 num6 = lightingState.B2;
1389 }
1390 else
1391 {
1392 if (num6 <= 0f)
1393 {
1394 continue;
1395 }
1396 lightingState.B2 = num6;
1397 }
1398 num6 = ((!lightingState.StopLight) ? (num6 - _negLight) : (num6 - _negLight2));
1399 }
1400 }
1401 if (flag)
1402 {
1403 flag = false;
1404 continue;
1405 }
1406 break;
1407 }
1408 }
1409 catch
1410 {
1411 }
1412 }
1413}
static void For(int fromInclusive, int toExclusive, ParallelForAction callback, object context=null)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static int ProcessorCount
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Floor(double d)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
Vector2 UnscaledPosition
Definition Camera.cs:8
void doColors_Mode1_Swipe(int outerLoopStart, int outerLoopEnd, object context)
void ShiftUnProcessedDataOver(int maxLightArrayX, int maxLightArrayY)
void doColors_Mode3_Swipe(int outerLoopStart, int outerLoopEnd, object context)
void doColors_Mode0_Swipe(int outerLoopStart, int outerLoopEnd, object context)
void doColors_Mode2_Swipe(int outerLoopStart, int outerLoopEnd, object context)
void AddLight(int x, int y, Vector3 color)
void UpdateLightToSkyColor(float tileR, float tileG, float tileB)
void CopyFullyProcessedDataOver(int maxLightArrayX, int maxLightArrayY)
Dictionary< Point16, ColorTriplet > _tempLights
void GetLight(int x, int y, out Vector3 color)
Definition LightMap.cs:57
LightMaskMode GetMask(int x, int y)
Definition LightMap.cs:62
void SetSize(int width, int height)
Definition LightMap.cs:244
void ExportTo(Rectangle area, LightMap outputMap, TileLightScannerOptions options)
static int OffScreenTiles
Definition Lighting.cs:17
static SceneMetrics SceneMetrics
Definition Main.cs:1344
static int mapDelay
Definition Main.cs:207
static bool[] tileNoSunLight
Definition Main.cs:1463
static int maxTilesY
Definition Main.cs:1116
static int mapTimeMax
Definition Main.cs:882
static bool ShouldShowInvisibleWalls()
Definition Main.cs:54895
static double worldSurface
Definition Main.cs:1272
static int waterStyle
Definition Main.cs:1208
static int myPlayer
Definition Main.cs:1801
static float demonTorch
Definition Main.cs:1330
static Vector2 screenLastPosition
Definition Main.cs:1717
static int wofNPCIndex
Definition Main.cs:828
static int maxTilesX
Definition Main.cs:1114
static SpriteViewMatrix GameViewMatrix
Definition Main.cs:227
static Tile[,] tile
Definition Main.cs:1675
static int mapMinY
Definition Main.cs:878
static WorldMap Map
Definition Main.cs:1673
static int mapMaxX
Definition Main.cs:876
static int mapMinX
Definition Main.cs:874
static NPC[] npc
Definition Main.cs:1685
static bool renderNow
Definition Main.cs:598
static bool mapEnabled
Definition Main.cs:906
static bool[] wallLight
Definition Main.cs:1445
static int mapMaxY
Definition Main.cs:880
static int mapTime
Definition Main.cs:884
static Player LocalPlayer
Definition Main.cs:2829
static bool gamePaused
Definition Main.cs:1072
static Player[] player
Definition Main.cs:1803
static int renderCount
Definition Main.cs:968
static RemoteServer Connection
Definition Netplay.cs:39
byte liquid
Definition Tile.cs:12
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
ushort wall
Definition Tile.cs:10
static void LightingTime(int lightingType, double timeElapsed)
delegate void ParallelForAction(int fromInclusive, int toExclusive, object context)
void Set(int left, int right, int top, int bottom)
static FastRandom CreateWithRandomSeed()
Definition FastRandom.cs:37