Skip to content

Commit

Permalink
Move best line Displacement to separate property
Browse files Browse the repository at this point in the history
  • Loading branch information
codemeyer committed May 3, 2019
1 parent 42f0e6c commit b67ca95
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 25 deletions.
12 changes: 4 additions & 8 deletions Source/ArgData.Tests/Internals/BestLineReaderFacts.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using System.IO;
using System.Linq;
using ArgData.Entities;
using ArgData.Internals;
using FluentAssertions;
using Xunit;

namespace ArgData.Tests.Internals
{
public class BestLineReaderFacts
{
{
[Fact]
public void Phoenix_FirstSegment_IsDisplacement()
public void Phoenix_Displacement_576()
{
var trackData = TrackFactsHelper.GetTrackPhoenix();

using (var reader = new BinaryReader(MemoryStreamProvider.Open(trackData.Path)))
{
var result = BestLineReader.Read(reader, trackData.KnownBestLineSectionDataStart);

var firstSegment = result.BestLineSegments.First();
firstSegment.SegmentType.Should().Be(TrackBestLineSegmentType.Displacement);
firstSegment.Displacement.Should().Be(576);
result.Displacement.Should().Be(576);
}
}

Expand All @@ -39,7 +36,7 @@ public void PhoenixBestLineHas40Segments()
}

[Fact]
public void PhoenixBestLineHasFirstSegmentWithLength40()
public void PhoenixBestLineHasFirstSegmentWithLength48()
{
var trackData = TrackFactsHelper.GetTrackPhoenix();

Expand All @@ -49,7 +46,6 @@ public void PhoenixBestLineHasFirstSegmentWithLength40()

var firstSegment = result.BestLineSegments.First();
firstSegment.Length.Should().Be(48);
firstSegment.Displacement.Should().Be(576);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/ArgData.Tests/TrackReaderFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void PhoenixDataIntegration()

track.TrackSections.Count.Should().Be(67);
track.PitLaneSections.Count.Should().Be(13);
track.BestLineDisplacement.Should().Be(576);
track.BestLineSegments.Count.Should().Be(40);
track.ComputerCarSetup.FrontWing.Should().Be(48);
track.ComputerCarSetup.TyreCompound.Should().Be(SetupTyreCompound.C);
Expand Down
5 changes: 5 additions & 0 deletions Source/ArgData/Entities/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public Track()
/// </summary>
public IList<TrackSection> TrackSections { get; internal set; }

/// <summary>
/// Gets or sets the displacement of the best line.
/// </summary>
public short BestLineDisplacement { get; set; }

/// <summary>
/// Gets a list of the best line/computer car line segments.
/// </summary>
Expand Down
12 changes: 1 addition & 11 deletions Source/ArgData/Entities/TrackBestLineSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ public class TrackBestLineSegment
/// </summary>
public int Length { get; set; }

/// <summary>
/// Gets or sets the displacement value. Only used when SegmentType is Displacement.
/// </summary>
public short Displacement { get; set; }

/// <summary>
/// Gets or sets the correction value. Called Tighter/Wider in GP2 Track Editor.
/// </summary>
public short Correction { get; set; }

/// <summary>
/// Gets or sets the corner radius.
/// Gets or sets the corner radius. Only used when SegmentType is Normal.
/// </summary>
public short Radius { get; set; }

Expand All @@ -46,11 +41,6 @@ public class TrackBestLineSegment
/// </summary>
public enum TrackBestLineSegmentType
{
/// <summary>
/// Displacement. Always the first one for a track.
/// </summary>
Displacement,

/// <summary>
/// Normal segment.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Source/ArgData/Internals/BestLineReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static TrackBestLineReadingResult Read(BinaryReader reader, int startPosi
list.Add(new TrackBestLineSegment
{
Length = firstLength,
Displacement = displacement,
Correction = correction,
Radius = radius
});
Expand Down Expand Up @@ -74,7 +73,7 @@ public static TrackBestLineReadingResult Read(BinaryReader reader, int startPosi
}

int position = (int)reader.BaseStream.Position;
return new TrackBestLineReadingResult(list, position);
return new TrackBestLineReadingResult(displacement, list, position);
}
}
}
6 changes: 5 additions & 1 deletion Source/ArgData/Internals/TrackBestLineReadingResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ namespace ArgData.Internals
{
internal class TrackBestLineReadingResult
{
public TrackBestLineReadingResult(List<TrackBestLineSegment> bestLineSegments, int positionAfterReading)
public TrackBestLineReadingResult(short displacement,
List<TrackBestLineSegment> bestLineSegments, int positionAfterReading)
{
Displacement = displacement;
BestLineSegments = bestLineSegments;
PositionAfterReading = positionAfterReading;
}

public short Displacement { get; set; }

public List<TrackBestLineSegment> BestLineSegments { get; set; }

public int PositionAfterReading { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions Source/ArgData/TrackReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Track Read(string path)
track.TrackSections = sectionReading.TrackSections;

var bestLines = BestLineReader.Read(reader, sectionReading.Position);
track.BestLineDisplacement = bestLines.Displacement;
track.BestLineSegments = bestLines.BestLineSegments;

int positionAfterReadingBestLine = bestLines.PositionAfterReading;
Expand Down
6 changes: 3 additions & 3 deletions Source/ArgData/TrackWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Write(Track trackData, string path)
var trackSectionBytes = GetTrackSectionBytes(trackData.TrackSections);
trackBytes.Add(trackSectionBytes);

var bestLineBytes = GetBestLineBytes(trackData.BestLineSegments);
var bestLineBytes = GetBestLineBytes(trackData.BestLineDisplacement, trackData.BestLineSegments);
trackBytes.Add(bestLineBytes);

var computerCarSetupBytes = GetComputerCarSetupBytes(trackData.ComputerCarSetup);
Expand Down Expand Up @@ -361,15 +361,15 @@ private static byte[] GetTrackSectionBytes(IEnumerable<TrackSection> sections)
return sectionBytes.GetBytes();
}

private static byte[] GetBestLineBytes(IList<TrackBestLineSegment> bestLines)
private static byte[] GetBestLineBytes(short displacement, IList<TrackBestLineSegment> bestLines)
{
var bestLineBytes = new ByteList();

var first = bestLines.First();

bestLineBytes.Add((byte)first.Length);
bestLineBytes.Add((byte)0x80);
bestLineBytes.Add(first.Displacement);
bestLineBytes.Add(displacement);
bestLineBytes.Add(first.Correction);
bestLineBytes.Add(first.Radius);

Expand Down

0 comments on commit b67ca95

Please sign in to comment.