Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Traffic Light namespace cleanup and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
seiggy committed Jul 14, 2015
1 parent 78d4da5 commit bc1ed83
Show file tree
Hide file tree
Showing 14 changed files with 1,088 additions and 1,187 deletions.
2 changes: 1 addition & 1 deletion TLM/TLM/CustomAI/CustomRoadAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Update()
{
var timedNode = TrafficLightsTimed.GetTimedLight(nodeId);

foreach (var timedNodeItem in timedNode.nodeGroup)
foreach (var timedNodeItem in timedNode.NodeGroup)
{
var nodeSim = GetNodeSimulation(timedNodeItem);

Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public override void OnLevelUnloading()
TrafficPriority.PrioritySegments.Clear();
CustomRoadAI.NodeDictionary.Clear();
TrafficLightsManual.ManualSegments.Clear();
TrafficLightsTimed.timedScripts.Clear();
TrafficLightsTimed.TimedScripts.Clear();

Instance.NodeSimulationLoaded = false;
}
Expand Down
102 changes: 51 additions & 51 deletions TLM/TLM/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ private static void OnLoadDataTimed(System.Object source, ElapsedEventArgs e)
CustomRoadAI.AddNodeToSimulation((ushort)configuration.nodeDictionary[i][0]);
var nodeDict = CustomRoadAI.GetNodeSimulation((ushort)configuration.nodeDictionary[i][0]);

nodeDict._manualTrafficLights = Convert.ToBoolean(configuration.nodeDictionary[i][1]);
nodeDict._timedTrafficLights = Convert.ToBoolean(configuration.nodeDictionary[i][2]);
nodeDict.ManualTrafficLights = Convert.ToBoolean(configuration.nodeDictionary[i][1]);
nodeDict.TimedTrafficLights = Convert.ToBoolean(configuration.nodeDictionary[i][2]);
nodeDict.TimedTrafficLightsActive = Convert.ToBoolean(configuration.nodeDictionary[i][3]);
}
}
Expand All @@ -119,14 +119,14 @@ private static void OnLoadDataTimed(System.Object source, ElapsedEventArgs e)
TrafficLightsManual.AddSegmentLight((ushort)segmentData[0], segmentData[1],
RoadBaseAI.TrafficLightState.Green);
var segment = TrafficLightsManual.GetSegmentLight((ushort)segmentData[0], segmentData[1]);
segment.currentMode = (ManualSegmentLight.Mode)segmentData[2];
segment.lightLeft = (RoadBaseAI.TrafficLightState)segmentData[3];
segment.lightMain = (RoadBaseAI.TrafficLightState)segmentData[4];
segment.lightRight = (RoadBaseAI.TrafficLightState)segmentData[5];
segment.lightPedestrian = (RoadBaseAI.TrafficLightState)segmentData[6];
segment.lastChange = (uint)segmentData[7];
segment.lastChangeFrame = (uint)segmentData[8];
segment.pedestrianEnabled = Convert.ToBoolean(segmentData[9]);
segment.CurrentMode = (ManualSegmentLight.Mode)segmentData[2];
segment.LightLeft = (RoadBaseAI.TrafficLightState)segmentData[3];
segment.LightMain = (RoadBaseAI.TrafficLightState)segmentData[4];
segment.LightRight = (RoadBaseAI.TrafficLightState)segmentData[5];
segment.LightPedestrian = (RoadBaseAI.TrafficLightState)segmentData[6];
segment.LastChange = (uint)segmentData[7];
segment.LastChangeFrame = (uint)segmentData[8];
segment.PedestrianEnabled = Convert.ToBoolean(segmentData[9]);
}
}

Expand All @@ -148,15 +148,15 @@ private static void OnLoadDataTimed(System.Object source, ElapsedEventArgs e)
TrafficLightsTimed.AddTimedLight(nodeid, nodeGroup);
var timedNode = TrafficLightsTimed.GetTimedLight(nodeid);

timedNode.currentStep = configuration.timedNodes[i][1];
timedNode.CurrentStep = configuration.timedNodes[i][1];

for (var j = 0; j < configuration.timedNodes[i][2]; j++)
{
var cfgstep = configuration.timedNodeSteps[timedStepCount];

timedNode.addStep(cfgstep[0]);
timedNode.AddStep(cfgstep[0]);

var step = timedNode.steps[j];
var step = timedNode.Steps[j];

for (var k = 0; k < cfgstep[1]; k++)
{
Expand All @@ -173,7 +173,7 @@ private static void OnLoadDataTimed(System.Object source, ElapsedEventArgs e)

if (Convert.ToBoolean(configuration.timedNodes[i][3]))
{
timedNode.start();
timedNode.Start();
}
}
}
Expand Down Expand Up @@ -269,60 +269,60 @@ public void OnSaveData()
{
var nodeDict = CustomRoadAI.NodeDictionary[(ushort)i];

configuration.nodeDictionary.Add(new int[4] {nodeDict.NodeId, Convert.ToInt32(nodeDict._manualTrafficLights), Convert.ToInt32(nodeDict._timedTrafficLights), Convert.ToInt32(nodeDict.TimedTrafficLightsActive)});
configuration.nodeDictionary.Add(new int[4] {nodeDict.NodeId, Convert.ToInt32(nodeDict.ManualTrafficLights), Convert.ToInt32(nodeDict.TimedTrafficLights), Convert.ToInt32(nodeDict.TimedTrafficLightsActive)});
}

if (TrafficLightsManual.ManualSegments.ContainsKey(i))
{
if (TrafficLightsManual.ManualSegments[i].node_1 != 0)
if (TrafficLightsManual.ManualSegments[i].Node1 != 0)
{
var manualSegment = TrafficLightsManual.ManualSegments[i].instance_1;
var manualSegment = TrafficLightsManual.ManualSegments[i].Instance1;

configuration.manualSegments.Add(new int[10]
{
(int)manualSegment.node,
manualSegment.segment,
(int)manualSegment.currentMode,
(int)manualSegment.lightLeft,
(int)manualSegment.lightMain,
(int)manualSegment.lightRight,
(int)manualSegment.lightPedestrian,
(int)manualSegment.lastChange,
(int)manualSegment.lastChangeFrame,
Convert.ToInt32(manualSegment.pedestrianEnabled)
(int)manualSegment.Node,
manualSegment.Segment,
(int)manualSegment.CurrentMode,
(int)manualSegment.LightLeft,
(int)manualSegment.LightMain,
(int)manualSegment.LightRight,
(int)manualSegment.LightPedestrian,
(int)manualSegment.LastChange,
(int)manualSegment.LastChangeFrame,
Convert.ToInt32(manualSegment.PedestrianEnabled)
});
}
if (TrafficLightsManual.ManualSegments[i].node_2 != 0)
if (TrafficLightsManual.ManualSegments[i].Node2 != 0)
{
var manualSegment = TrafficLightsManual.ManualSegments[i].instance_2;
var manualSegment = TrafficLightsManual.ManualSegments[i].Instance2;

configuration.manualSegments.Add(new int[10]
{
(int)manualSegment.node,
manualSegment.segment,
(int)manualSegment.currentMode,
(int)manualSegment.lightLeft,
(int)manualSegment.lightMain,
(int)manualSegment.lightRight,
(int)manualSegment.lightPedestrian,
(int)manualSegment.lastChange,
(int)manualSegment.lastChangeFrame,
Convert.ToInt32(manualSegment.pedestrianEnabled)
(int)manualSegment.Node,
manualSegment.Segment,
(int)manualSegment.CurrentMode,
(int)manualSegment.LightLeft,
(int)manualSegment.LightMain,
(int)manualSegment.LightRight,
(int)manualSegment.LightPedestrian,
(int)manualSegment.LastChange,
(int)manualSegment.LastChangeFrame,
Convert.ToInt32(manualSegment.PedestrianEnabled)
});
}
}

if (TrafficLightsTimed.timedScripts.ContainsKey((ushort)i))
if (TrafficLightsTimed.TimedScripts.ContainsKey((ushort)i))
{
var timedNode = TrafficLightsTimed.GetTimedLight((ushort) i);

configuration.timedNodes.Add(new int[4] { timedNode.nodeID, timedNode.currentStep, timedNode.NumSteps(), Convert.ToInt32(timedNode.isStarted())});
configuration.timedNodes.Add(new int[4] { timedNode.NodeId, timedNode.CurrentStep, timedNode.NumSteps(), Convert.ToInt32(timedNode.IsStarted())});

var nodeGroup = new ushort[timedNode.nodeGroup.Count];
var nodeGroup = new ushort[timedNode.NodeGroup.Count];

for (var j = 0; j < timedNode.nodeGroup.Count; j++)
for (var j = 0; j < timedNode.NodeGroup.Count; j++)
{
nodeGroup[j] = timedNode.nodeGroup[j];
nodeGroup[j] = timedNode.NodeGroup[j];
}

configuration.timedNodeGroups.Add(nodeGroup);
Expand All @@ -331,18 +331,18 @@ public void OnSaveData()
{
configuration.timedNodeSteps.Add(new int[2]
{
timedNode.steps[j].NumSteps,
timedNode.steps[j].Segments.Count
timedNode.Steps[j].NumSteps,
timedNode.Steps[j].Segments.Count
});

for (var k = 0; k < timedNode.steps[j].Segments.Count; k++)
for (var k = 0; k < timedNode.Steps[j].Segments.Count; k++)
{
configuration.timedNodeStepSegments.Add(new int[4]
{
(int)timedNode.steps[j].LightLeft[k],
(int)timedNode.steps[j].LightMain[k],
(int)timedNode.steps[j].LightRight[k],
(int)timedNode.steps[j].LightPedestrian[k],
(int)timedNode.Steps[j].LightLeft[k],
(int)timedNode.Steps[j].LightMain[k],
(int)timedNode.Steps[j].LightRight[k],
(int)timedNode.Steps[j].LightPedestrian[k],
});
}
}
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/TLM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Mod.cs" />
<Compile Include="TrafficLight\ManualSegment.cs" />
<Compile Include="TrafficLight\ManualSegmentLight.cs" />
<Compile Include="TrafficLight\ToolMode.cs" />
<Compile Include="TrafficLight\TrafficLightSimulation.cs" />
<Compile Include="TrafficLight\TrafficLightsManual.cs" />
<Compile Include="TrafficLight\TrafficLightsTimed.cs" />
Expand Down
16 changes: 8 additions & 8 deletions TLM/TLM/Traffic/TimedTrafficSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public void SetLights()
{
var segmentLight = TrafficLightsManual.GetSegmentLight(NodeId, segment);

segmentLight.lightMain = LightMain[s];
segmentLight.lightLeft = LightLeft[s];
segmentLight.lightRight = LightRight[s];
segmentLight.lightPedestrian = LightPedestrian[s];
segmentLight.LightMain = LightMain[s];
segmentLight.LightLeft = LightLeft[s];
segmentLight.LightRight = LightRight[s];
segmentLight.LightPedestrian = LightPedestrian[s];
segmentLight.UpdateVisuals();
}
}
Expand All @@ -96,10 +96,10 @@ public void UpdateLights()
{
var segmentLight = TrafficLightsManual.GetSegmentLight(NodeId, segment);

LightMain[s] = segmentLight.lightMain;
LightLeft[s] = segmentLight.lightLeft;
LightRight[s] = segmentLight.lightRight;
LightPedestrian[s] = segmentLight.lightPedestrian;
LightMain[s] = segmentLight.LightMain;
LightLeft[s] = segmentLight.LightLeft;
LightRight[s] = segmentLight.LightRight;
LightPedestrian[s] = segmentLight.LightPedestrian;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions TLM/TLM/TrafficLight/ManualSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ namespace TrafficManager.TrafficLight
{
class ManualSegment
{
public ushort node_1 = 0;
public ushort node_2 = 0;
public ushort Node1 = 0;
public ushort Node2 = 0;

public ManualSegmentLight instance_1;
public ManualSegmentLight instance_2;
public ManualSegmentLight Instance1;
public ManualSegmentLight Instance2;
}
}
Loading

0 comments on commit bc1ed83

Please sign in to comment.