Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

View file

@ -0,0 +1,23 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Graphics.Light.ILightingEngine
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.Graphics.Light
{
public interface ILightingEngine
{
void Rebuild();
void AddLight(int x, int y, Vector3 color);
void ProcessArea(Rectangle area);
Vector3 GetColor(int x, int y);
void Clear();
}
}

File diff suppressed because it is too large Load diff

198
Graphics/Light/LightMap.cs Normal file
View file

@ -0,0 +1,198 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Graphics.Light.LightMap
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using ReLogic.Threading;
using Terraria.Utilities;
namespace Terraria.Graphics.Light
{
public class LightMap
{
private Vector3[] _colors;
private LightMaskMode[] _mask;
private FastRandom _random = FastRandom.CreateWithRandomSeed();
private const int DEFAULT_WIDTH = 203;
private const int DEFAULT_HEIGHT = 203;
public int NonVisiblePadding { get; set; }
public int Width { get; private set; }
public int Height { get; private set; }
public float LightDecayThroughAir { get; set; }
public float LightDecayThroughSolid { get; set; }
public Vector3 LightDecayThroughWater { get; set; }
public Vector3 LightDecayThroughHoney { get; set; }
public Vector3 this[int x, int y]
{
get => this._colors[this.IndexOf(x, y)];
set => this._colors[this.IndexOf(x, y)] = value;
}
public LightMap()
{
this.LightDecayThroughAir = 0.91f;
this.LightDecayThroughSolid = 0.56f;
this.LightDecayThroughWater = new Vector3(0.88f, 0.96f, 1.015f) * 0.91f;
this.LightDecayThroughHoney = new Vector3(0.75f, 0.7f, 0.6f) * 0.91f;
this.Width = 203;
this.Height = 203;
this._colors = new Vector3[41209];
this._mask = new LightMaskMode[41209];
}
public void GetLight(int x, int y, out Vector3 color) => color = this._colors[this.IndexOf(x, y)];
public LightMaskMode GetMask(int x, int y) => this._mask[this.IndexOf(x, y)];
public void Clear()
{
for (int index = 0; index < this._colors.Length; ++index)
{
this._colors[index].X = 0.0f;
this._colors[index].Y = 0.0f;
this._colors[index].Z = 0.0f;
this._mask[index] = LightMaskMode.None;
}
}
public void SetMaskAt(int x, int y, LightMaskMode mode) => this._mask[this.IndexOf(x, y)] = mode;
public void Blur()
{
this.BlurPass();
this.BlurPass();
this._random.NextSeed();
}
private void BlurPass()
{
// ISSUE: method pointer
FastParallel.For(0, this.Width, new ParallelForAction((object) this, __methodptr(\u003CBlurPass\u003Eb__42_0)), (object) null);
// ISSUE: method pointer
FastParallel.For(0, this.Height, new ParallelForAction((object) this, __methodptr(\u003CBlurPass\u003Eb__42_1)), (object) null);
}
private void BlurLine(int startIndex, int endIndex, int stride)
{
Vector3 zero = Vector3.Zero;
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
for (int index = startIndex; index != endIndex + stride; index += stride)
{
if ((double) zero.X < (double) this._colors[index].X)
{
zero.X = this._colors[index].X;
flag1 = false;
}
else if (!flag1)
{
if ((double) zero.X < 0.0185000002384186)
flag1 = true;
else
this._colors[index].X = zero.X;
}
if ((double) zero.Y < (double) this._colors[index].Y)
{
zero.Y = this._colors[index].Y;
flag2 = false;
}
else if (!flag2)
{
if ((double) zero.Y < 0.0185000002384186)
flag2 = true;
else
this._colors[index].Y = zero.Y;
}
if ((double) zero.Z < (double) this._colors[index].Z)
{
zero.Z = this._colors[index].Z;
flag3 = false;
}
else if (!flag3)
{
if ((double) zero.Z < 0.0185000002384186)
flag3 = true;
else
this._colors[index].Z = zero.Z;
}
if (!(flag1 & flag3 & flag2))
{
switch (this._mask[index])
{
case LightMaskMode.None:
if (!flag1)
zero.X *= this.LightDecayThroughAir;
if (!flag2)
zero.Y *= this.LightDecayThroughAir;
if (!flag3)
{
zero.Z *= this.LightDecayThroughAir;
continue;
}
continue;
case LightMaskMode.Solid:
if (!flag1)
zero.X *= this.LightDecayThroughSolid;
if (!flag2)
zero.Y *= this.LightDecayThroughSolid;
if (!flag3)
{
zero.Z *= this.LightDecayThroughSolid;
continue;
}
continue;
case LightMaskMode.Water:
float num = (float) this._random.WithModifier((ulong) index).Next(98, 100) / 100f;
if (!flag1)
zero.X *= this.LightDecayThroughWater.X * num;
if (!flag2)
zero.Y *= this.LightDecayThroughWater.Y * num;
if (!flag3)
{
zero.Z *= this.LightDecayThroughWater.Z * num;
continue;
}
continue;
case LightMaskMode.Honey:
if (!flag1)
zero.X *= this.LightDecayThroughHoney.X;
if (!flag2)
zero.Y *= this.LightDecayThroughHoney.Y;
if (!flag3)
{
zero.Z *= this.LightDecayThroughHoney.Z;
continue;
}
continue;
default:
continue;
}
}
}
}
private int IndexOf(int x, int y) => x * this.Height + y;
public void SetSize(int width, int height)
{
if (width * height > this._colors.Length)
{
this._colors = new Vector3[width * height];
this._mask = new LightMaskMode[width * height];
}
this.Width = width;
this.Height = height;
}
}
}

View file

@ -0,0 +1,16 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Graphics.Light.LightMaskMode
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Graphics.Light
{
public enum LightMaskMode : byte
{
None,
Solid,
Water,
Honey,
}
}

View file

@ -0,0 +1,16 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Graphics.Light.LightMode
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Graphics.Light
{
public enum LightMode
{
White,
Retro,
Trippy,
Color,
}
}

View file

@ -0,0 +1,249 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Graphics.Light.LightingEngine
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using ReLogic.Threading;
using System.Collections.Generic;
using System.Diagnostics;
namespace Terraria.Graphics.Light
{
public class LightingEngine : ILightingEngine
{
private const int AREA_PADDING = 28;
private const int NON_VISIBLE_PADDING = 18;
private readonly List<LightingEngine.PerFrameLight> _perFrameLights = new List<LightingEngine.PerFrameLight>();
private TileLightScanner _tileScanner;
private LightMap _activeLightMap = new LightMap();
private Rectangle _activeProcessedArea;
private LightMap _workingLightMap = new LightMap();
private Rectangle _workingProcessedArea;
private readonly Stopwatch _timer = new Stopwatch();
private LightingEngine.EngineState _state;
public LightingEngine(World world) => this.SetWorld(world);
public void AddLight(int x, int y, Vector3 color) => this._perFrameLights.Add(new LightingEngine.PerFrameLight(new Point(x, y), color));
public void Clear()
{
this._activeLightMap.Clear();
this._workingLightMap.Clear();
this._perFrameLights.Clear();
}
public Vector3 GetColor(int x, int y)
{
if (!this._activeProcessedArea.Contains(x, y))
return Vector3.Zero;
x -= this._activeProcessedArea.X;
y -= this._activeProcessedArea.Y;
return this._activeLightMap[x, y];
}
public void ProcessArea(Rectangle area)
{
Main.renderCount = (Main.renderCount + 1) % 4;
this._timer.Start();
TimeLogger.LightingTime(0, 0.0);
switch (this._state)
{
case LightingEngine.EngineState.MinimapUpdate:
if (Main.mapDelay > 0)
--Main.mapDelay;
else
this.ExportToMiniMap();
TimeLogger.LightingTime(1, this._timer.Elapsed.TotalMilliseconds);
break;
case LightingEngine.EngineState.ExportMetrics:
area.Inflate(28, 28);
Main.SceneMetrics.ScanAndExportToMain(new SceneMetricsScanSettings()
{
VisualScanArea = new Rectangle?(area),
BiomeScanCenterPositionInWorld = new Vector2?(Main.LocalPlayer.Center),
ScanOreFinderData = Main.LocalPlayer.accOreFinder
});
TimeLogger.LightingTime(2, this._timer.Elapsed.TotalMilliseconds);
break;
case LightingEngine.EngineState.Scan:
this.ProcessScan(area);
TimeLogger.LightingTime(3, this._timer.Elapsed.TotalMilliseconds);
break;
case LightingEngine.EngineState.Blur:
this.ProcessBlur();
this.Present();
TimeLogger.LightingTime(4, this._timer.Elapsed.TotalMilliseconds);
break;
}
this.IncrementState();
this._timer.Reset();
}
private void IncrementState() => this._state = (LightingEngine.EngineState) ((int) (this._state + 1) % 4);
private void ProcessScan(Rectangle area)
{
area.Inflate(28, 28);
this._workingProcessedArea = area;
this._workingLightMap.SetSize(area.Width, area.Height);
this._workingLightMap.NonVisiblePadding = 18;
this._tileScanner.Update();
this._tileScanner.ExportTo(area, this._workingLightMap);
}
private void ProcessBlur()
{
this.UpdateLightDecay();
this.ApplyPerFrameLights();
this._workingLightMap.Blur();
}
private void Present()
{
Utils.Swap<LightMap>(ref this._activeLightMap, ref this._workingLightMap);
Utils.Swap<Rectangle>(ref this._activeProcessedArea, ref this._workingProcessedArea);
}
private void UpdateLightDecay()
{
LightMap workingLightMap = this._workingLightMap;
workingLightMap.LightDecayThroughAir = 0.91f;
workingLightMap.LightDecayThroughSolid = 0.56f;
workingLightMap.LightDecayThroughHoney = new Vector3(0.75f, 0.7f, 0.6f) * 0.91f;
switch (Main.waterStyle)
{
case 0:
case 1:
case 7:
case 8:
workingLightMap.LightDecayThroughWater = new Vector3(0.88f, 0.96f, 1.015f) * 0.91f;
break;
case 2:
workingLightMap.LightDecayThroughWater = new Vector3(0.94f, 0.85f, 1.01f) * 0.91f;
break;
case 3:
workingLightMap.LightDecayThroughWater = new Vector3(0.84f, 0.95f, 1.015f) * 0.91f;
break;
case 4:
workingLightMap.LightDecayThroughWater = new Vector3(0.9f, 0.86f, 1.01f) * 0.91f;
break;
case 5:
workingLightMap.LightDecayThroughWater = new Vector3(0.84f, 0.99f, 1.01f) * 0.91f;
break;
case 6:
workingLightMap.LightDecayThroughWater = new Vector3(0.83f, 0.93f, 0.98f) * 0.91f;
break;
case 9:
workingLightMap.LightDecayThroughWater = new Vector3(1f, 0.88f, 0.84f) * 0.91f;
break;
case 10:
workingLightMap.LightDecayThroughWater = new Vector3(0.83f, 1f, 1f) * 0.91f;
break;
case 12:
workingLightMap.LightDecayThroughWater = new Vector3(0.95f, 0.98f, 0.85f) * 0.91f;
break;
}
if (Main.player[Main.myPlayer].nightVision)
{
workingLightMap.LightDecayThroughAir *= 1.03f;
workingLightMap.LightDecayThroughSolid *= 1.03f;
}
if (Main.player[Main.myPlayer].blind)
{
workingLightMap.LightDecayThroughAir *= 0.95f;
workingLightMap.LightDecayThroughSolid *= 0.95f;
}
if (Main.player[Main.myPlayer].blackout)
{
workingLightMap.LightDecayThroughAir *= 0.85f;
workingLightMap.LightDecayThroughSolid *= 0.85f;
}
if (!Main.player[Main.myPlayer].headcovered)
return;
workingLightMap.LightDecayThroughAir *= 0.85f;
workingLightMap.LightDecayThroughSolid *= 0.85f;
}
private void ApplyPerFrameLights()
{
for (int index = 0; index < this._perFrameLights.Count; ++index)
{
Point position = this._perFrameLights[index].Position;
if (this._workingProcessedArea.Contains(position))
{
Vector3 result = this._perFrameLights[index].Color;
Vector3 workingLight = this._workingLightMap[position.X - this._workingProcessedArea.X, position.Y - this._workingProcessedArea.Y];
Vector3.Max(ref workingLight, ref result, out result);
this._workingLightMap[position.X - this._workingProcessedArea.X, position.Y - this._workingProcessedArea.Y] = result;
}
}
this._perFrameLights.Clear();
}
public void Rebuild()
{
this._activeProcessedArea = Rectangle.Empty;
this._workingProcessedArea = Rectangle.Empty;
this._state = LightingEngine.EngineState.MinimapUpdate;
this._activeLightMap = new LightMap();
this._workingLightMap = new LightMap();
}
private void SetWorld(World world) => this._tileScanner = new TileLightScanner(world);
private void ExportToMiniMap()
{
// ISSUE: object of a compiler-generated type is created
// ISSUE: variable of a compiler-generated type
LightingEngine.\u003C\u003Ec__DisplayClass24_0 cDisplayClass240 = new LightingEngine.\u003C\u003Ec__DisplayClass24_0();
// ISSUE: reference to a compiler-generated field
cDisplayClass240.\u003C\u003E4__this = this;
if (!Main.mapEnabled || this._activeProcessedArea.Width <= 0 || this._activeProcessedArea.Height <= 0)
return;
// ISSUE: reference to a compiler-generated field
cDisplayClass240.area = new Rectangle(this._activeProcessedArea.X + 28, this._activeProcessedArea.Y + 28, this._activeProcessedArea.Width - 56, this._activeProcessedArea.Height - 56);
Rectangle rectangle = new Rectangle(0, 0, Main.maxTilesX, Main.maxTilesY);
rectangle.Inflate(-Main.Map.BlackEdgeWidth, -Main.Map.BlackEdgeWidth);
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
cDisplayClass240.area = Rectangle.Intersect(cDisplayClass240.area, rectangle);
// ISSUE: reference to a compiler-generated field
Main.mapMinX = cDisplayClass240.area.Left;
// ISSUE: reference to a compiler-generated field
Main.mapMinY = cDisplayClass240.area.Top;
// ISSUE: reference to a compiler-generated field
Main.mapMaxX = cDisplayClass240.area.Right;
// ISSUE: reference to a compiler-generated field
Main.mapMaxY = cDisplayClass240.area.Bottom;
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
// ISSUE: method pointer
FastParallel.For(cDisplayClass240.area.Left, cDisplayClass240.area.Right, new ParallelForAction((object) cDisplayClass240, __methodptr(\u003CExportToMiniMap\u003Eb__0)), (object) null);
Main.updateMap = true;
}
private enum EngineState
{
MinimapUpdate,
ExportMetrics,
Scan,
Blur,
Max,
}
private struct PerFrameLight
{
public readonly Point Position;
public readonly Vector3 Color;
public PerFrameLight(Point position, Vector3 color)
{
this.Position = position;
this.Color = color;
}
}
}
}

File diff suppressed because it is too large Load diff