Skip to content

Commit

Permalink
- Segment ends are reset when their geometry changes
Browse files Browse the repository at this point in the history
- timed step error handling
- Bugfix: Segments where all vehicle have been banned do not get a traffic light assigned
  • Loading branch information
VictorPhilipp committed Jan 9, 2017
1 parent a3ef25a commit abc3425
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
8 changes: 8 additions & 0 deletions TLM/TLM/Manager/TrafficPriorityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,13 @@ protected override void HandleInvalidSegment(SegmentGeometry geometry) {
protected override void HandleValidSegment(SegmentGeometry geometry) {
HousekeepNode(geometry.StartNodeId());
HousekeepNode(geometry.EndNodeId());

TrafficSegment trafficSegment = TrafficSegments[geometry.SegmentId];
if (trafficSegment == null) {
return;
}
trafficSegment.Instance1?.Reset();
trafficSegment.Instance2?.Reset();
}

protected void HousekeepNode(ushort nodeId) {
Expand All @@ -948,6 +955,7 @@ protected void HousekeepNode(ushort nodeId) {
if (! TrafficLightSimulationManager.Instance.HasSimulation(nodeId)) {
if (TrafficLightManager.Instance.HasTrafficLight(nodeId) || !IsPriorityNode(nodeId, true)) {
RemovePrioritySegments(nodeId);
return;
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions TLM/TLM/Manager/VehicleRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ internal Dictionary<byte, ExtVehicleType> GetAllowedVehicleTypesAsDict(ushort se

if (toNodeId == nodeId) {
ExtVehicleType vehicleTypes = GetAllowedVehicleTypes(segmentId, segmentInfo, laneIndex, laneInfo);
if (vehicleTypes != ExtVehicleType.None)
ret[(byte)laneIndex] = vehicleTypes;
ret[(byte)laneIndex] = vehicleTypes;
}
curLaneId = netManager.m_lanes.m_buffer[curLaneId].m_nextLane;
++laneIndex;
Expand Down
10 changes: 0 additions & 10 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@
<Compile Include="Custom\Manager\CustomNetManager.cs" />
<Compile Include="Custom\Manager\CustomCitizenManager.cs" />
<Compile Include="Custom\Manager\CustomVehicleManager.cs" />
<Compile Include="GameBridge\INetLaneBridge.cs" />
<Compile Include="GameBridge\INetNodeBridge.cs" />
<Compile Include="GameBridge\INetSegmentBridge.cs" />
<Compile Include="Manager\AbstractCustomManager.cs" />
<Compile Include="Manager\AbstractNodeGeometryObservingManager.cs" />
<Compile Include="Manager\AbstractSegmentGeometryObservingManager.cs" />
<Compile Include="Manager\ExtBuildingManager.cs" />
<Compile Include="Manager\ICustomDataManager.cs" />
<Compile Include="Manager\LaneArrowManager.cs" />
<Compile Include="Manager\OptionsManager.cs" />
<Compile Include="Manager\TemplateManager.cs" />
<Compile Include="Manager\TrafficLightManager.cs" />
<Compile Include="Manager\TrafficMeasurementManager.cs" />
<Compile Include="Manager\JunctionRestrictionsManager.cs" />
Expand All @@ -126,12 +122,6 @@
<Compile Include="Geometry\SegmentEndGeometry.cs" />
<Compile Include="Manager\VehicleStateManager.cs" />
<Compile Include="Manager\VehicleRestrictionsManager.cs" />
<Compile Include="Traffic\Template\SegmentEndRestrictionsTemplate.cs" />
<Compile Include="Traffic\Template\NodeTemplate.cs" />
<Compile Include="Traffic\Template\LaneConnectionTemplate.cs" />
<Compile Include="Traffic\Template\LaneTemplate.cs" />
<Compile Include="Traffic\Template\SegmentEndTemplate.cs" />
<Compile Include="Traffic\Template\SegmentEndLightsTemplate.cs" />
<Compile Include="Traffic\VehicleJunctionTransitState.cs" />
<Compile Include="State\Configuration.cs" />
<Compile Include="Custom\AI\CustomCarAI.cs" />
Expand Down
22 changes: 12 additions & 10 deletions TLM/TLM/Traffic/SegmentEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SegmentEnd(ushort nodeId, ushort segmentId, PriorityType type) {
SegmentId = segmentId;
Type = type;
FirstRegisteredVehicleId = 0;
Housekeeping();
Reset();
}

~SegmentEnd() {
Expand Down Expand Up @@ -124,16 +124,18 @@ public Dictionary<ushort, uint> GetVehicleMetricGoingToSegment(bool includeStopp

Dictionary<ushort, uint> ret = includeStopped ? numVehiclesGoingToSegmentId : numVehiclesFlowingToSegmentId;

for (var s = 0; s < 8; s++) {
ushort segmentId = netManager.m_nodes.m_buffer[NodeId].GetSegment(s);

if (segmentId == 0)
foreach (SegmentEndGeometry endGeo in NodeGeometry.Get(NodeId).SegmentEndGeometries) {
if (endGeo == null)
continue;

if (!ret.ContainsKey(segmentId))
continue;
if (!endGeo.IncomingOneWay && !ret.ContainsKey(endGeo.SegmentId)) {
#if DEBUG
Log._Debug($"SegmentEnd.GetVehicleMetricGoingToSegment: return dict does not contain entry for segment {endGeo.SegmentId}");
#endif
}


ret[segmentId] = 0;
ret[endGeo.SegmentId] = 0;
}

#if DEBUGMETRIC
Expand Down Expand Up @@ -161,7 +163,7 @@ public Dictionary<ushort, uint> GetVehicleMetricGoingToSegment(bool includeStopp

if (!ret.ContainsKey(nextPos.m_segment)) {
#if DEBUGMETRIC2
if (debug)
if (debug)
Log._Debug($" GetVehicleMetricGoingToSegment: ret does not contain key for target segment {nextPos.m_segment}");
#endif
return;
Expand Down Expand Up @@ -250,7 +252,7 @@ private void UnregisterAllVehicles() {
}
}

internal void Housekeeping() {
internal void Reset() {
//Log._Debug($"SegmentEnd.Housekeeping: Housekeeping at segment {SegmentId} @ {NodeId}");

StartNode = Singleton<NetManager>.instance.m_segments.m_buffer[SegmentId].m_startNode == NodeId;
Expand Down
5 changes: 5 additions & 0 deletions TLM/TLM/TrafficLight/TimedTrafficLightsStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ public bool calcWaitFlow(bool onlyMoving, int stepRefIndex, out float wait, out
ushort targetSegmentId = f.Key;
uint totalNumCars = f.Value;

if (!directions.ContainsKey(targetSegmentId)) {
Log._Debug($"TimedTrafficLightsStep.calcWaitFlow: Direction undefined for target segment {targetSegmentId} @ {timedNodeId}");
continue;
}

if (evalFlowingVehicles) {
uint totalNumFlowingCars = onlyMoving ? carsFlowingToSegmentMetric[f.Key] : totalNumCars;

Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/UI/SubTools/PrioritySignsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ public override void Cleanup() {

foreach (TrafficSegment trafficSegment in prioMan.TrafficSegments) {
try {
trafficSegment?.Instance1?.Housekeeping();
trafficSegment?.Instance2?.Housekeeping();
trafficSegment?.Instance1?.Reset();
trafficSegment?.Instance2?.Reset();
} catch (Exception e) {
Log.Error($"Error occured while performing PrioritySignsTool.Cleanup: {e.ToString()}");
}
Expand Down

0 comments on commit abc3425

Please sign in to comment.