Skip to content

Commit

Permalink
TMPE 1.9.3:
Browse files Browse the repository at this point in the history
- Disabled notification of route recalculating because some players report crashes
- Removed default vehicle restrictions from bus lanes
- Modified junction restrictions come into effect instantaneously
- UI: Saving a timed step does not reset the timed traffic light to the first state
- Bugfix: AI: Segment traffic data is not taken into account
- Bugfix: Priority rules are not properly obeyed
- Bugfix: Under certain circumstances priority signs cannot be removed
- Bugfix: Path-finding is unable to calculate certain paths
  • Loading branch information
VictorPhilipp committed May 21, 2017
1 parent fb35622 commit 93cfc84
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 228 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ A work-in-progress modification for **Cities: Skylines** to add additional traff

User manual: http://www.viathinksoft.de/tmpe

# Changelog
# Changelog
1.9.3, 05/22/2017
- Disabled notification of route recalculating because some players report crashes
- Removed default vehicle restrictions from bus lanes
- Modified junction restrictions come into effect instantaneously
- UI: Saving a timed step does not reset the timed traffic light to the first state
- Bugfix: AI: Segment traffic data is not taken into account
- Bugfix: Priority rules are not properly obeyed
- Bugfix: Under certain circumstances priority signs cannot be removed
- Bugfix: Path-finding is unable to calculate certain paths

1.9.2, 05/20/2017
- UI: Main menu & UI tools performance improved
- Bugfix: Traffic lights can be removed from junctions that are controlled by a timed traffic light program
Expand Down
184 changes: 75 additions & 109 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion TLM/TLM/Custom/PathFinding/OldCustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3327,7 +3327,7 @@ protected virtual bool CanUseLane(bool debug, ushort segmentId, NetInfo segmentI
if ((laneInfo.m_vehicleType & (VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train)) == VehicleInfo.VehicleType.None)
return true;

ExtVehicleType allowedTypes = vehicleRestrictionsManager.GetAllowedVehicleTypes(segmentId, segmentInfo, laneIndex, laneInfo);
ExtVehicleType allowedTypes = vehicleRestrictionsManager.GetAllowedVehicleTypes(segmentId, segmentInfo, laneIndex, laneInfo, false);
#if DEBUGPF
if (debug) {
Log._Debug($"CanUseLane: segmentId={segmentId} laneIndex={laneIndex} _extVehicleType={_extVehicleType} _vehicleTypes={_vehicleTypes} _laneTypes={_laneTypes} _transportVehicle={_transportVehicle} _isHeavyVehicle={_isHeavyVehicle} allowedTypes={allowedTypes} res={((allowedTypes & _extVehicleType) != ExtVehicleType.None)}");
Expand Down
16 changes: 12 additions & 4 deletions TLM/TLM/Manager/JunctionRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool start
if (!Services.NetService.IsSegmentValid(segmentId))
return false;
Flags.setStraightLaneChangingAllowed(segmentId, startNode, value);
SubscribeToSegmentGeometry(segmentId);
OnSegmentChange(segmentId);
return true;
}

Expand All @@ -87,7 +87,7 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) {
if (!value && LaneConnectionManager.Instance.HasUturnConnections(segmentId, startNode))
return false;
Flags.setUTurnAllowed(segmentId, startNode, value);
SubscribeToSegmentGeometry(segmentId);
OnSegmentChange(segmentId);
return true;
}

Expand All @@ -99,7 +99,7 @@ public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode,
if (!Services.NetService.IsSegmentValid(segmentId))
return false;
Flags.setEnterWhenBlockedAllowed(segmentId, startNode, value);
SubscribeToSegmentGeometry(segmentId);
OnSegmentChange(segmentId);
return true;
}

Expand All @@ -111,10 +111,18 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool
if (!Services.NetService.IsSegmentValid(segmentId))
return false;
Flags.setPedestrianCrossingAllowed(segmentId, startNode, !IsPedestrianCrossingAllowed(segmentId, startNode));
SubscribeToSegmentGeometry(segmentId);
OnSegmentChange(segmentId);
return true;
}

protected void OnSegmentChange(ushort segmentId) {
RoutingManager.Instance.RequestRecalculation(segmentId);
SubscribeToSegmentGeometry(segmentId);
if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}
}

public bool LoadData(List<Configuration.SegmentNodeConf> data) {
bool success = true;
Log.Info($"Loading junction restrictions. {data.Count} elements");
Expand Down
38 changes: 18 additions & 20 deletions TLM/TLM/Manager/RoutingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public struct LaneTransitionData {
public byte laneIndex;
public LaneEndTransitionType type;
public byte distance;
#if DEBUGROUTING
#if DEBUG
public ushort segmentId;
#endif

public override string ToString() {
return $"[LaneTransitionData\n" +
"\t" + $"laneId = {laneId}\n" +
"\t" + $"laneIndex = {laneIndex}\n" +
#if DEBUGROUTING
#if DEBUG
"\t" + $"segmentId = {segmentId}\n" +
#endif
"\t" + $"type = {type}\n" +
Expand All @@ -178,26 +178,26 @@ public override string ToString() {
}

public void Set(uint laneId, byte laneIndex, LaneEndTransitionType type, byte distance
#if DEBUGROUTING
#if DEBUG
, ushort segmentId
#endif
) {
this.laneId = laneId;
this.laneIndex = laneIndex;
this.type = type;
this.distance = distance;
#if DEBUGROUTING
#if DEBUG
this.segmentId = segmentId;
#endif
}

public void Set(uint laneId, byte laneIndex, LaneEndTransitionType type
#if DEBUGROUTING
#if DEBUG
, ushort segmentId
#endif
) {
Set(laneId, laneIndex, type, 0
#if DEBUGROUTING
#if DEBUG
, segmentId
#endif
);
Expand Down Expand Up @@ -259,9 +259,9 @@ public void SimulationStep() {

try {
Monitor.Enter(updateLock);
if (updateNotificationRequired) {
/*if (updateNotificationRequired) {
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage(Translation.GetString("Please_wait") + "...", Translation.GetString("Recalculating_lane_routing") + "...", false);
}
}*/ // TODO seems to crash the game for some users
segmentsUpdated = false;

int len = updatedSegmentBuckets.Length;
Expand All @@ -278,9 +278,9 @@ public void SimulationStep() {
}
}

if (updateNotificationRequired) {
/*if (updateNotificationRequired) {
UIView.library.Hide("ExceptionPanel");
}
}*/
updateNotificationRequired = false;
} finally {
Monitor.Exit(updateLock);
Expand Down Expand Up @@ -532,17 +532,15 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, int laneIndex, ui
nextSegmentId = node.GetSegment(k);
return true;
});

if (nextSegmentId == 0) {
continue;
}
}

int outgoingVehicleLanes = 0;
int incomingVehicleLanes = 0;

laneEndRoutings[index].SetTransitions(k, null);

if (nextSegmentId == 0) {
break;
}

bool uturn = nextSegmentId == prevSegmentId;
bool isNextStartNodeOfNextSegment = false;
bool nextSegIsInverted = false;
Expand Down Expand Up @@ -703,7 +701,7 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, int laneIndex, ui
transitionType = LaneEndTransitionType.Relaxed;
if (numNextRelaxedTransitionDatas < MAX_NUM_TRANSITIONS) {
nextRelaxedTransitionDatas[numNextRelaxedTransitionDatas++].Set(nextLaneId, nextLaneIndex, transitionType, GlobalConfig.Instance.IncompatibleLaneDistance
#if DEBUGROUTING
#if DEBUG
, nextSegmentId
#endif
);
Expand All @@ -722,7 +720,7 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, int laneIndex, ui
nextCompatibleOuterSimilarIndices[numNextCompatibleTransitionDatas] = nextOuterSimilarLaneIndex;
//compatibleLaneIndicesMask |= POW2MASKS[numNextCompatibleTransitionDatas];
nextCompatibleTransitionDatas[numNextCompatibleTransitionDatas++].Set(nextLaneId, nextLaneIndex, transitionType
#if DEBUGROUTING
#if DEBUG
, nextSegmentId
#endif
);
Expand Down Expand Up @@ -1075,9 +1073,9 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, int laneIndex, ui
return true;
});

if (nextSegmentId == prevSegmentId) {
if (nextSegmentId == prevSegmentId || nextSegmentId == 0) {
// we reached the first segment again
nextSegmentId = 0;
break;
}
}
} // foreach segment
Expand Down
21 changes: 17 additions & 4 deletions TLM/TLM/Manager/SegmentEndManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void RemoveSegmentEnd(SegmentEndId endId) {
}

public void RemoveSegmentEnd(ushort segmentId, bool startNode) {
#if DEBUG
Log.Warning($"SegmentEndManager.RemoveSegmentEnd({segmentId}, {startNode}) called");
#endif
DestroySegmentEnd(GetIndex(segmentId, startNode));
}

Expand All @@ -71,13 +74,20 @@ public bool UpdateSegmentEnd(SegmentEndId endId) {
}

public bool UpdateSegmentEnd(ushort segmentId, bool startNode) {
SegmentEndGeometry end = SegmentGeometry.Get(segmentId)?.GetEnd(startNode);
if (end == null) {
Log._Debug($"SegmentEndManager.UpdateSegmentEnd({segmentId}, {startNode}): Segment {segmentId} is invalid. Removing segment end {segmentId} @ {startNode}");
SegmentGeometry segGeo = SegmentGeometry.Get(segmentId);
if (segGeo == null) {
Log._Debug($"SegmentEndManager.UpdateSegmentEnd({segmentId}, {startNode}): Segment {segmentId} is invalid. Removing all segment ends.");
RemoveSegmentEnds(segmentId);
return false;
}

SegmentEndGeometry end = segGeo.GetEnd(startNode);
if (end == null) {
Log._Debug($"SegmentEndManager.UpdateSegmentEnd({segmentId}, {startNode}): Segment end {segmentId} @ {startNode} is invalid. Removing segment end.");
RemoveSegmentEnd(segmentId, startNode);
return false;
}

if (TrafficPriorityManager.Instance.HasSegmentPrioritySign(segmentId, startNode) ||
TrafficLightSimulationManager.Instance.HasTimedSimulation(end.NodeId())) {
Log._Debug($"SegmentEndManager.UpdateSegmentEnd({segmentId}, {startNode}): Segment {segmentId} @ {startNode} has timed light or priority sign. Adding segment end {segmentId} @ {startNode}");
Expand All @@ -91,7 +101,7 @@ public bool UpdateSegmentEnd(ushort segmentId, bool startNode) {
}

private int GetIndex(ushort segmentId, bool startNode) {
return (int)segmentId + (startNode ? 0 : 1);
return (int)segmentId + (startNode ? 0 : NetManager.MAX_SEGMENT_COUNT);
}

/*protected override void HandleInvalidSegment(SegmentGeometry geometry) {
Expand All @@ -103,6 +113,9 @@ protected override void HandleValidSegment(SegmentGeometry geometry) {
}*/

protected void DestroySegmentEnd(int index) {
#if DEBUG
Log.Warning($"SegmentEndManager.DestroySegmentEnd({index}) called");
#endif
SegmentEnds[index]?.Destroy();
SegmentEnds[index] = null;
}
Expand Down
18 changes: 6 additions & 12 deletions TLM/TLM/Manager/TrafficMeasurementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public class SegmentDirTrafficData {
/// Current minimum lane speed
/// </summary>
public ushort minSpeed;
#if DEBUG
public ushort meanSpeed;
#endif

/// <summary>
/// Number of times the segment had been marked as congested
Expand All @@ -104,9 +102,7 @@ public override string ToString() {
"\t" + $"accumulatedDensities = {accumulatedDensities}\n" +
#endif
"\t" + $"minSpeed = {minSpeed}\n" +
#if DEBUG
"\t" + $"meanSpeed = {meanSpeed}\n" +
#endif
"\t" + $"totalPathFindTrafficBuffer = {totalPathFindTrafficBuffer}\n" +
"\t" + $"numCongested = {numCongested}\n" +
"\t" + $"numCongestionMeasurements = {numCongestionMeasurements}\n" +
Expand All @@ -129,10 +125,9 @@ public override string ToString() {
private ushort[] minSpeeds = { MAX_SPEED, MAX_SPEED };
private uint[] densities = { 0, 0 };
private uint[] totalPfBuf = { 0, 0 };
#if DEBUG

private uint[] meanSpeeds = { 0, 0 };
private int[] meanSpeedLanes = { 0, 0 };
#endif

private TrafficMeasurementManager() {
laneTrafficData = new LaneTrafficData[NetManager.MAX_SEGMENT_COUNT][];
Expand Down Expand Up @@ -201,10 +196,10 @@ public void SimulationStep(ushort segmentId, ref NetSegment segmentData) {
for (int i = 0; i < 2; ++i) {
minSpeeds[i] = MAX_SPEED;
densities[i] = 0;
#if DEBUG

meanSpeeds[i] = 0;
meanSpeedLanes[i] = 0;
#endif

totalPfBuf[i] = 0;
}

Expand Down Expand Up @@ -282,10 +277,10 @@ public void SimulationStep(ushort segmentId, ref NetSegment segmentData) {
newSpeed = (ushort)maxTolerableSpeed;
}*/

#if DEBUG

meanSpeeds[dirIndex] += newSpeed;
meanSpeedLanes[dirIndex]++;
#endif

laneTrafficData[segmentId][laneIndex].meanSpeed = newSpeed;

// reset buffers
Expand Down Expand Up @@ -325,13 +320,12 @@ public void SimulationStep(ushort segmentId, ref NetSegment segmentData) {
segmentDirTrafficData[segmentId][i].accumulatedDensities = densities[i];
#endif
segmentDirTrafficData[segmentId][i].totalPathFindTrafficBuffer = totalPfBuf[i];
#if DEBUG

if (meanSpeedLanes[i] > 0) {
segmentDirTrafficData[segmentId][i].meanSpeed = (ushort)(meanSpeeds[i] / meanSpeedLanes[i]);
} else {
segmentDirTrafficData[segmentId][i].meanSpeed = MAX_SPEED;
}
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Manager/TrafficPriorityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public bool HasIncomingVehiclesWithHigherPriority(ushort vehicleId, ref Vehicle
SegmentEnd otherEnd = SegmentEndManager.Instance.GetSegmentEnd(otherSegmentId, otherStartNode);
if (otherEnd == null) {
#if DEBUG
Log.Warning($"HasIncomingVehicles: No segment end found for other segment {otherSegmentId} @ {otherStartNode}");
Log.Error($"HasIncomingVehicles: No segment end found for other segment {otherSegmentId} @ {otherStartNode}");
#endif
continue;
}
Expand Down
Loading

0 comments on commit 93cfc84

Please sign in to comment.