Skip to content

Commit

Permalink
Rework CPlugTreeVisualMip
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Jul 19, 2024
1 parent a7039c0 commit 3134d18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Src/GBX.NET/Engines/Plug/CPlugTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static IEnumerable<CPlugTree> GetAllChildren(CPlugTree tree, bool includeVisualM
{
foreach (var level in mip.Levels)
{
foreach (var descendant in GetAllChildren(level.Value, includeVisualMipLevels))
foreach (var descendant in GetAllChildren(level.Tree, includeVisualMipLevels))
{
yield return descendant;
}
Expand Down Expand Up @@ -122,12 +122,12 @@ static Iso4 MultiplyAddIso4(Iso4 a, Iso4 b)
static CPlugTree GetLodTree(CPlugTreeVisualMip mip, int lod)
{
return mip.Levels
.OrderBy(x => x.Key)
.Select(x => x.Value)
.OrderBy(x => x.FarZ)
.Select(x => x.Tree)
.ElementAtOrDefault(lod) ?? mip.Levels
.OrderBy(x => x.Key)
.OrderBy(x => x.FarZ)
.First()
.Value;
.Tree;
}
}

Expand Down
16 changes: 10 additions & 6 deletions Src/GBX.NET/Engines/Plug/CPlugTreeVisualMip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ namespace GBX.NET.Engines.Plug;

public partial class CPlugTreeVisualMip
{
public IDictionary<float, CPlugTree> Levels { get; set; } = new Dictionary<float, CPlugTree>();
private IList<Level> levels = new List<Level>();
[AppliedWithChunk<Chunk09015002>]
public IList<Level> Levels { get => levels; set => levels = value; }

public partial class Chunk09015002
{
Expand All @@ -15,9 +17,9 @@ public override void Read(CPlugTreeVisualMip n, GbxReader r)

for (var i = 0; i < length; i++)
{
var key = r.ReadSingle();
var value = r.ReadNodeRef<CPlugTree>()!;
n.Levels.Add(key, value);
var farZ = r.ReadSingle();
var tree = r.ReadNodeRef<CPlugTree>()!;
n.Levels.Add(new(farZ, tree));
}
}

Expand All @@ -27,9 +29,11 @@ public override void Write(CPlugTreeVisualMip n, GbxWriter w)

foreach (var pair in n.Levels)
{
w.Write(pair.Key);
w.WriteNodeRef(pair.Value);
w.Write(pair.FarZ);
w.WriteNodeRef(pair.Tree);
}
}
}

public sealed record Level(float FarZ, CPlugTree Tree);
}

0 comments on commit 3134d18

Please sign in to comment.