Skip to content

Commit c39984c

Browse files
committed
Small cleanup
1 parent ccd1d82 commit c39984c

File tree

2 files changed

+24
-56
lines changed

2 files changed

+24
-56
lines changed

Source/RunActivity/Viewer3D/Map/MapDataProvider.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,9 @@ public void PopulateItemLists()
132132
// Instead create a single item which replaces the 2 platform items.
133133
var replacement = new PlatformWidget(item as PlatformItem)
134134
{
135-
Extent1 = oldLocation
136-
,
137-
Extent2 = newLocation
138-
// Give it the right-hand location
139-
,
140-
Location = GetRightHandPoint(oldLocation, newLocation)
135+
Extent1 = oldLocation,
136+
Extent2 = newLocation,
137+
Location = GetRightHandPoint(oldLocation, newLocation) // Give it the right-hand location
141138
};
142139

143140
// Replace the old platform item with the replacement
@@ -204,8 +201,8 @@ public void FixForBadData(float width, ref PointF scaledA, ref PointF scaledB, P
204201
public bool IsActiveTrain(Simulation.AIs.AITrain t)
205202
{
206203
return t != null
207-
&& (t.MovementState != Simulation.AIs.AITrain.AI_MOVEMENT_STATE.AI_STATIC
208-
&& !(t.TrainType == Train.TRAINTYPE.AI_INCORPORATED && !t.IncorporatingTrain.IsPathless)
204+
&& ((t.MovementState != Simulation.AIs.AITrain.AI_MOVEMENT_STATE.AI_STATIC
205+
&& !(t.TrainType == Train.TRAINTYPE.AI_INCORPORATED && !t.IncorporatingTrain.IsPathless))
209206

210207
|| t.TrainType == Train.TRAINTYPE.PLAYER);
211208
}
@@ -232,7 +229,7 @@ public static bool ContainsDeadlockIndicators(string text)
232229
// Arrays are used instead of lists to avoid delays for memory management.
233230
public void CleanTextCells()
234231
{
235-
if (F.alignedTextY == null || F.alignedTextY.Length != F.mapCanvas.Height / MapViewer.spacing) //first time to put text, or the text height has changed
232+
if (F.alignedTextY == null || F.alignedTextY.Length != F.mapCanvas.Height / MapViewer.spacing) // First time to put text, or the text height has changed
236233
{
237234
F.alignedTextY = new Vector2[F.mapCanvas.Height / MapViewer.spacing][];
238235
F.alignedTextNum = new int[F.mapCanvas.Height / MapViewer.spacing];
@@ -251,20 +248,20 @@ public float GetUnusedYLocation(float startX, float wantY, string name)
251248

252249
var desiredPositionY = (int)(wantY / MapViewer.spacing); // The positionY of the ideal row for the text.
253250
var endX = startX + (name.Length * F.trainFont.Size);
254-
//out of drawing area
255-
if (endX < 0)
251+
252+
if (endX < 0) // Out of drawing area
256253
return noFreeSlotFound;
257254

258255
var positionY = desiredPositionY;
259256
while (positionY >= 0 && positionY < F.alignedTextY.Length)
260257
{
261-
//if the line contains no text yet, put it there
258+
// If the line contains no text yet, put it there
262259
if (F.alignedTextNum[positionY] == 0)
263260
return SaveLabelLocation(startX, endX, positionY);
264261

265262
var conflict = false;
266263

267-
//check if it intersects with any labels already in this row
264+
// Check if it intersects with any labels already in this row
268265
for (var col = 0; col < F.alignedTextNum[positionY]; col++)
269266
{
270267
var v = F.alignedTextY[positionY][col];
@@ -297,7 +294,7 @@ public float GetUnusedYLocation(float startX, float wantY, string name)
297294

298295
private float SaveLabelLocation(float startX, float endX, int positionY)
299296
{
300-
// add start and end location for the new label
297+
// Add start and end location for the new label
301298
F.alignedTextY[positionY][F.alignedTextNum[positionY]] = new Vector2 { X = startX, Y = endX };
302299

303300
F.alignedTextNum[positionY]++;

Source/RunActivity/Viewer3D/Map/MapForm.cs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public partial class MapViewer : Form
7575
public double switchPickedTime;
7676
public bool signalPickedItemHandled;
7777
public double signalPickedTime;
78-
public bool DrawPath = true; //draw train path
78+
public bool DrawPath = true; // Whether the train path should be drawn
7979
readonly TrackNode[] nodes;
8080

8181
public List<Train> selectedTrainList;
@@ -380,8 +380,8 @@ public void GenerateView()
380380
xScale = yScale = Math.Max(xScale, yScale); // Make X and Y scales the same to maintain correct angles
381381

382382
// Set the default pen to represent 1 meter
383-
var scale = (float)Math.Round(xScale); // Round to nearest pixels/meter
384-
var penWidth = (int)MathHelper.Clamp(scale, 1, 4); // Keep 1 <= width <= 4 pixels
383+
var scale = (float)Math.Round(xScale); // Round to nearest pixels/meter
384+
var penWidth = (int)MathHelper.Clamp(scale, 1, 4); // Keep 1 <= width <= 4 pixels
385385

386386
PointF[] points = new PointF[3];
387387
Pen p = grayPen;
@@ -396,10 +396,6 @@ public void GenerateView()
396396

397397
var forwardDist = 100 / xScale; if (forwardDist < 5) forwardDist = 5;
398398

399-
/*PointF scaledA = new PointF(0, 0);
400-
PointF scaledB = new PointF(0, 0);
401-
PointF scaledC = new PointF(0, 0);*/
402-
403399
// Draw platforms first because track is drawn over the thicker platform line
404400
DrawPlatforms(g, penWidth);
405401

@@ -421,7 +417,7 @@ public void GenerateView()
421417
ShowSwitches(g, widgetWidth);
422418

423419
// Draw labels for sidings and platforms last so they go on top for readability
424-
MapDataProvider.CleanTextCells(); // Empty the listing of labels ready for adding labels again
420+
MapDataProvider.CleanTextCells(); // Empty the listing of labels ready for adding labels again
425421
ShowPlatformLabels(g); // Platforms take priority over sidings and signal states
426422
ShowSidingLabels(g);
427423

@@ -497,21 +493,8 @@ private void DrawTrains(Graphics g, PointF scaledA, PointF scaledB)
497493

498494
selectedTrainList.Clear();
499495

500-
/*if (simulator.TimetableMode)
501-
{
502-
// Add the player's train...
503-
if (simulator.PlayerLocomotive.Train is AITrain)
504-
selectedTrainList.Add(simulator.PlayerLocomotive.Train as AITrain);
505-
506-
// ...then all the AI trains, including static consists.
507-
foreach (AITrain train in simulator.AI.AITrains)
508-
selectedTrainList.Add(train);
509-
}
510-
else
511-
{*/
512496
foreach (var train in simulator.Trains)
513497
selectedTrainList.Add(train);
514-
/*}*/
515498

516499
foreach (var train in selectedTrainList)
517500
{
@@ -677,9 +660,6 @@ private void SetTrainColor(Train t, TrainCar locoCar, TrainCar car)
677660

678661
private void DrawTrainLabels(Graphics g, Train t, string trainName, PointF scaledTrain)
679662
{
680-
/*WorldPosition worldPos = firstCar.WorldPosition;
681-
scaledTrain.X = ((worldPos.TileX * 2048) - subX + worldPos.Location.X) * xScale;
682-
scaledTrain.Y = -25 + mapCanvas.Height - (((worldPos.TileZ * 2048) - subY + worldPos.Location.Z) * yScale);*/
683663
if (showActiveTrainsRadio.Checked)
684664
{
685665
if (t is AITrain && MapDataProvider.IsActiveTrain(t as AITrain))
@@ -945,7 +925,7 @@ SignallingDebugWindow.TrackSectionCacheEntry GetCacheEntry(Traveller position)
945925
return rv;
946926
}
947927

948-
//draw the train path if it is within the window
928+
// Draw the train path if it is within the window
949929
public void DrawTrainPath(Train train, float subX, float subY, Pen pathPen, Graphics g, PointF scaledA, PointF scaledB, float stepDist, float MaximumSectionDistance)
950930
{
951931
if (DrawPath != true) return;
@@ -1314,10 +1294,6 @@ private void mapCanvas_MouseDown(object sender, MouseEventArgs e)
13141294
LastCursorPosition.X = e.X;
13151295
LastCursorPosition.Y = e.Y;
13161296
MPManager.Instance().ComposingText = false;
1317-
/*lblInstruction1.Visible = true;
1318-
lblInstruction2.Visible = true;
1319-
lblInstruction3.Visible = true;
1320-
lblInstruction4.Visible = true;*/
13211297
}
13221298

13231299
private void mapCanvas_MouseUp(object sender, MouseEventArgs e)
@@ -1383,10 +1359,6 @@ private void mapCanvas_MouseUp(object sender, MouseEventArgs e)
13831359
}
13841360

13851361
}
1386-
/*lblInstruction1.Visible = false;
1387-
lblInstruction2.Visible = false;
1388-
lblInstruction3.Visible = false;
1389-
lblInstruction4.Visible = false;*/
13901362
}
13911363

13921364
private void UnHandleItemPick()
@@ -1397,8 +1369,9 @@ private void UnHandleItemPick()
13971369

13981370
private void HandlePickedSignal()
13991371
{
1400-
if (MPManager.IsClient() && !MPManager.Instance().AmAider) // normal client not server or aider
1372+
if (MPManager.IsClient() && !MPManager.Instance().AmAider) // Normal client (not server nor aider)
14011373
return;
1374+
14021375
setSwitchMenu.Visible = false;
14031376
if (signalPickedItem == null) return;
14041377

@@ -1415,8 +1388,8 @@ private void HandlePickedSignal()
14151388

14161389
private void HandlePickedSwitch()
14171390
{
1418-
if (MPManager.IsClient() && !MPManager.Instance().AmAider)
1419-
return;//normal client not server
1391+
if (MPManager.IsClient() && !MPManager.Instance().AmAider) // Normal client (not server nor aider)
1392+
return;
14201393

14211394
setSignalMenu.Visible = false;
14221395
if (switchPickedItem == null) return;
@@ -1521,11 +1494,9 @@ private void setSwitchMenu_ItemClicked(object sender, ToolStripItemClickedEventA
15211494
{
15221495
case "mainRoute":
15231496
Program.Simulator.Signals.RequestSetSwitch(sw.TN, (int)switchPickedItem.main);
1524-
//sw.SelectedRoute = (int)switchPickedItem.main;
15251497
break;
15261498
case "sideRoute":
15271499
Program.Simulator.Signals.RequestSetSwitch(sw.TN, 1 - (int)switchPickedItem.main);
1528-
//sw.SelectedRoute = 1 - (int)switchPickedItem.main;
15291500
break;
15301501
}
15311502
}
@@ -1541,7 +1512,7 @@ private ItemWidget findItemFromMouse(int x, int y, int range)
15411512
{
15421513
foreach (var item in switchItemsDrawn)
15431514
{
1544-
//if out of range, continue
1515+
// If out of range, continue
15451516
if (item.Location2D.X < x - range || item.Location2D.X > x + range
15461517
|| item.Location2D.Y < y - range || item.Location2D.Y > y + range)
15471518
continue;
@@ -1566,7 +1537,7 @@ private ItemWidget findItemFromMouse(int x, int y, int range)
15661537
{
15671538
foreach (var item in signalItemsDrawn)
15681539
{
1569-
//if out of range, continue
1540+
// If out of range, continue
15701541
if (item.Location2D.X < x - range || item.Location2D.X > x + range
15711542
|| item.Location2D.Y < y - range || item.Location2D.Y > y + range)
15721543
continue;
@@ -1588,7 +1559,7 @@ private ItemWidget findItemFromMouse(int x, int y, int range)
15881559
}
15891560
}
15901561

1591-
//now check for trains (first car only)
1562+
// Now check for trains (first car only)
15921563
TrainCar firstCar;
15931564
PickedTrain = null; float tX, tY;
15941565
closest = 100f;
@@ -1621,7 +1592,7 @@ private ItemWidget findItemFromMouse(int x, int y, int range)
16211592
if (PickedTrain == null)
16221593
PickedTrain = t;
16231594
}
1624-
//if a train is picked, will clear the avatar list selection
1595+
// If a train is picked, will clear the player list selection
16251596
if (PickedTrain != null)
16261597
{
16271598
//AvatarView.SelectedItems.Clear();

0 commit comments

Comments
 (0)