Skip to content

Commit

Permalink
transition lane index/uturn flags
Browse files Browse the repository at this point in the history
  • Loading branch information
kianzarrin committed Dec 12, 2022
1 parent aa5b6d3 commit 4d2fd72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion AdaptiveRoads/AdaptiveRoads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Deterministic>false</Deterministic>
<AssemblyVersion>3.16.17.*</AssemblyVersion>
<AssemblyVersion>3.16.18.*</AssemblyVersion>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
Expand Down
43 changes: 33 additions & 10 deletions AdaptiveRoads/Data/NetworkExtensions/LaneTransition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public enum Flags {

[Hint("transition is between two segments with unbroken median.")]
UnbrokenMedian = 1 << 10,

[Hint("transition is between two matching lanes with similar lane index.")]
SimilarLaneIndex = 1 << 11,

Uturn = 1 << 12,
}

public Flags m_flags; // TODO complete
Expand Down Expand Up @@ -101,6 +106,9 @@ public void Init(uint laneID1, uint laneID2, ushort nodeID, int antiFlickerIndex
internal ref NetLane LaneD => ref LaneIDTarget.ToLane();
internal ref NetLaneExt LaneExtA => ref LaneIDSource.ToLaneExt();
internal ref NetLaneExt LaneExtD => ref LaneIDTarget.ToLaneExt();
internal LaneData LaneDataA => LaneExtA.LaneData;
internal LaneData LaneDataD => LaneExtD.LaneData;

internal ref NetSegment SegmentA => ref LaneA.m_segment.ToSegment();
internal ref NetSegment SegmentD => ref LaneD.m_segment.ToSegment();
internal ref NetSegmentExt SegmentExtA => ref LaneA.m_segment.ToSegmentExt();
Expand All @@ -112,13 +120,13 @@ public void Init(uint laneID1, uint laneID2, ushort nodeID, int antiFlickerIndex
internal NetInfo Info => Node.Info;
internal NetInfo InfoA => SegmentA.Info;
internal NetInfoExtionsion.Net InfoExtA => segmentID_A.ToSegment().Info?.GetMetaData();
internal NetInfo.Lane laneInfoA => LaneExtA.LaneData.LaneInfo;
internal int laneIndexA => LaneExtA.LaneData.LaneIndex;
internal NetInfo.Lane LaneInfoA => LaneExtA.LaneData.LaneInfo;
internal int LaneIndexA => LaneExtA.LaneData.LaneIndex;
internal NetInfo InfoD => SegmentD.Info;
internal NetInfoExtionsion.Net InfoExtD => segmentID_D.ToSegment().Info?.GetMetaData();
internal NetInfo.Lane laneInfoD => LaneExtD.LaneData.LaneInfo;
internal int laneIndexD => LaneExtD.LaneData.LaneIndex;
internal float Width => laneInfoA.m_width;
internal NetInfo.Lane LaneInfoD => LaneExtD.LaneData.LaneInfo;
internal int LaneIndexD => LaneExtD.LaneData.LaneIndex;
internal float Width => LaneInfoA.m_width;
#endregion

public bool Nodeless => OutLine.Empty;
Expand All @@ -130,7 +138,7 @@ public void UpdateScriptedFlags(int index) {
foreach (var scriptedFlag in Flags.ExpressionMask.ExtractPow2Flags()) {
bool condition = false;
if (net.ScriptedFlags.TryGetValue(scriptedFlag, out var expression)) {
condition = expression.Condition(segmentID: segmentID_A, nodeID: NodeID, laneIndex: laneIndexA, index);
condition = expression.Condition(segmentID: segmentID_A, nodeID: NodeID, laneIndex: LaneIndexA, index);
}
m_flags = m_flags.SetFlags(scriptedFlag, condition);
}
Expand All @@ -146,14 +154,29 @@ public void Calculate() {

{
bool nearCurb = RoadUtils.IsNearCurb(
LaneIDSource.ToLaneExt().LaneData, LaneIDTarget.ToLaneExt().LaneData, NodeID);
LaneDataA, LaneDataD, NodeID);
m_flags = m_flags.SetFlags(Flags.NearCurb, nearCurb);
}

{
bool unBrokenMedian = !DirectConnectUtil.OpenMedian(segmentID_A, segmentID_D);
m_flags = m_flags.SetFlags(Flags.UnbrokenMedian, on: unBrokenMedian);
}

{
var laneInfoA = this.LaneInfoA;
var laneInfoD = this.LaneInfoD;
bool similar = laneInfoA.m_finalDirection == laneInfoD.m_finalDirection &&
laneInfoA.m_laneType == laneInfoD.m_laneType &&
LaneInfoA.m_vehicleType == LaneInfoD.m_vehicleType &&
laneInfoA.m_similarLaneIndex == laneInfoD.m_similarLaneIndex;
m_flags = m_flags.SetFlags(Flags.SimilarLaneIndex, on: similar);
}

{
m_flags = m_flags.SetFlags(Flags.Uturn, on: segmentID_A == segmentID_D);
}

Bezier3 bezierA = LaneExtA.LaneData.GetBezier(NodeID);
Bezier3 bezierD = LaneExtD.LaneData.GetBezier(NodeID);

Expand Down Expand Up @@ -181,7 +204,7 @@ public TrackRenderData GenerateRenderData(ref OutlineData outline, Vector3? pos
ret.MeshScale = new Vector4(1f / Width, 1f / InfoA.m_segmentLength, 1f, 1f);

float vScale = InfoA.m_netAI.GetVScale();
ret.TurnAround = laneInfoA.IsGoingBackward();
ret.TurnAround = LaneInfoA.IsGoingBackward();
ret.TurnAround ^= SegmentA.IsInvert();
ret.CalculateControlMatrix(outline, vScale);

Expand Down Expand Up @@ -216,7 +239,7 @@ public void CalculateProps() {
}

private bool Check(NetInfoExtionsion.Track trackInfo) {
if (!trackInfo.HasTrackLane(laneIndexA))
if (!trackInfo.HasTrackLane(LaneIndexA))
return false;

bool junction = Node.m_flags.IsFlagSet(NetNode.Flags.Junction);
Expand All @@ -242,7 +265,7 @@ private bool Check(NetInfoExtionsion.Track trackInfo) {
}

private DynamicFlags LaneTagsFlagsD =>
InfoExtD?.Lanes?[laneInfoD]?.LaneTags?.Flags ?? DynamicFlagsUtil.NONE;
InfoExtD?.Lanes?[LaneInfoD]?.LaneTags?.Flags ?? DynamicFlagsUtil.NONE;

public void RenderTrackInstance(RenderManager.CameraInfo cameraInfo, int layerMask) {
if(Nodeless) return;
Expand Down

0 comments on commit 4d2fd72

Please sign in to comment.