Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ PreRenderPhase()

void Terraria.Graphics.Light.LegacyLighting.PreRenderPhase ( )
inlineprivate

Definition at line 644 of file LegacyLighting.cs.

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 {
662 LightingState[] array = _states[i];
663 for (int j = num3; j < num4; j++)
664 {
665 LightingState obj = array[j];
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 {
691 LightingState[] array2 = _states[k - num7];
692 for (int l = num5; l <= num6; l++)
693 {
694 LightingState lightingState = array2[l - _expandedRectTop];
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);
717 num4 = Utils.Clamp(_expandedRectBottom, 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 });
725 _tileScanner.ExportTo(new Rectangle(num, num3, num2 - num, num4 - num3), _lightMap, new TileLightScannerOptions
726 {
727 DrawInvisibleWalls = Main.ShouldShowInvisibleWalls()
728 });
729 for (int m = num; m < num2; m++)
730 {
731 LightingState[] array3 = _states[m - _expandedRectLeft];
732 for (int n = num3; n < num4; n++)
733 {
734 LightingState lightingState2 = array3[n - _expandedRectTop];
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 {
794 LightingState lightingState3 = _states[num14][num15];
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 }
static double Floor(double d)
Vector2 UnscaledPosition
Definition Camera.cs:8
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 ExportTo(Rectangle area, LightMap outputMap, TileLightScannerOptions options)
void Set(int left, int right, int top, int bottom)

References Terraria.Graphics.Light.LegacyLighting._camera, Terraria.Graphics.Light.LegacyLighting._expandedArea, Terraria.Graphics.Light.LegacyLighting._expandedRectBottom, Terraria.Graphics.Light.LegacyLighting._expandedRectLeft, Terraria.Graphics.Light.LegacyLighting._expandedRectRight, Terraria.Graphics.Light.LegacyLighting._expandedRectTop, Terraria.Graphics.Light.LegacyLighting._lightMap, Terraria.Graphics.Light.LegacyLighting._maxX, Terraria.Graphics.Light.LegacyLighting._maxY, Terraria.Graphics.Light.LegacyLighting._minBoundArea, Terraria.Graphics.Light.LegacyLighting._minX, Terraria.Graphics.Light.LegacyLighting._minY, Terraria.Graphics.Light.LegacyLighting._offScreenTiles2, Terraria.Graphics.Light.LegacyLighting._offScreenTiles2ExpandedArea, Terraria.Graphics.Light.LegacyLighting._requestedArea, Terraria.Graphics.Light.LegacyLighting._requestedRectBottom, Terraria.Graphics.Light.LegacyLighting._requestedRectLeft, Terraria.Graphics.Light.LegacyLighting._requestedRectRight, Terraria.Graphics.Light.LegacyLighting._requestedRectTop, Terraria.Graphics.Light.LegacyLighting._rgb, Terraria.Graphics.Light.LegacyLighting._scrX, Terraria.Graphics.Light.LegacyLighting._scrY, Terraria.Graphics.Light.LegacyLighting._states, Terraria.Graphics.Light.LegacyLighting._tempLights, Terraria.Graphics.Light.LegacyLighting._tileScanner, System.array, System.Collections.Generic.Dictionary< TKey, TValue >.Clear(), Terraria.Main.demonTorch, Terraria.Graphics.Light.LegacyLighting.DoColors(), Terraria.Graphics.Light.TileLightScanner.ExportTo(), System.Math.Floor(), Terraria.Main.gamePaused, Terraria.Graphics.Light.LightMap.GetLight(), Terraria.Graphics.Light.LightMap.GetMask(), Terraria.TimeLogger.LightingTime(), Terraria.Main.LocalPlayer, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Main.myPlayer, Terraria.Main.npc, System.obj, Terraria.Lighting.OffScreenTiles, Terraria.Main.player, Terraria.Main.SceneMetrics, Terraria.Graphics.Light.LegacyLighting.RectArea.Set(), Terraria.Main.ShouldShowInvisibleWalls(), Terraria.DataStructures.Tile, Terraria.Main.tile, Terraria.Graphics.Camera.UnscaledPosition, Terraria.Graphics.Camera.UnscaledSize, Terraria.Graphics.Light.TileLightScanner.Update(), Terraria.Main.wofNPCIndex, Microsoft.Xna.Framework.Vector2.X, and Microsoft.Xna.Framework.Vector2.Y.

Referenced by Terraria.Graphics.Light.LegacyLighting.ProcessArea().