Skip to content

Commit

Permalink
Automatic merge of X1.3.1-189-gab83b4ca9 and 9 pull requests
Browse files Browse the repository at this point in the history
- Pull request #40 at e81861b: Monogame upgrade
- Pull request #79 at 7d9f14b: Update version calculation for new unstable versions
- Pull request #216 at 927a49c: Upgrade and replace web server with EmbedIO
- Pull request #221 at 13ba17f: Refactor try-catch blocks in RunActivity
- Pull request #225 at bb67fb6: Fix advanced adhesion wheelslip upon resuming from save: https://bugs.launchpad.net/or/+bug/1294410
- Pull request #226 at e66ced3: EmbedIO web server graphical track monitor
- Pull request #227 at c0543e1: EmbedIO web server graphical train driving monitor
- Pull request #228 at 4343221: adds links to OR on Elvas Tower
- Pull request #229 at e2aba9e: Fix MSTS-compatible physics reverting to Davis physics: https://bugs.launchpad.net/or/+bug/1886566
  • Loading branch information
openrails-bot committed Jul 7, 2020
11 parents 06e7a27 + ab83b4c + e81861b + 7d9f14b + 927a49c + 13ba17f + bb67fb6 + e66ced3 + c0543e1 + 4343221 + e2aba9e commit 3223a4d
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 346 deletions.
6 changes: 3 additions & 3 deletions Source/RunActivity/Processes/Profiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void SetThread()
// This is so that you can identify threads from debuggers like Visual Studio.
try
{
Thread.CurrentThread.Name = Name + " Process";
Thread.CurrentThread.Name = $"{Name} Process";
}
catch { }
catch (InvalidOperationException) { }

// This is so that you can identify threads from programs like Process Monitor. The call
// should always fail but will appear in Process Monitor's log against the correct thread.
try
{
File.ReadAllBytes(@"DEBUG\THREAD\" + Name + " Process");
File.ReadAllBytes($@"DEBUG\THREAD\{Name} Process");
}
catch { }

Expand Down
159 changes: 75 additions & 84 deletions Source/RunActivity/Viewer3D/Debugging/DebugViewerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public DispatchViewer(Simulator simulator, Viewer viewer)

MultiPlayer.MPManager.Instance().MessageReceived += (sender, e) =>
{
addNewMessage(e.Time, e.Message);
AddNewMessage(e.Time, e.Message);
};
}

Expand Down Expand Up @@ -594,41 +594,26 @@ public void GenerateView()
else { rmvButton.Visible = false; chkAllowNew.Visible = false; chkAllowUserSwitch.Visible = false; chkBoxPenalty.Visible = false; chkPreferGreen.Visible = false; }
}
if (firstShow || followTrain) {
WorldPosition pos;
//see who should I look at:
//if the player is selected in the avatar list, show the player, otherwise, show the one with the lowest index
if (Program.Simulator.PlayerLocomotive != null) pos = Program.Simulator.PlayerLocomotive.WorldPosition;
else pos = Program.Simulator.Trains[0].Cars[0].WorldPosition;
bool hasSelectedTrain = false;
WorldPosition pos = Program.Simulator.PlayerLocomotive == null ? Program.Simulator.Trains.First().Cars.First().WorldPosition : Program.Simulator.PlayerLocomotive.WorldPosition;
if (AvatarView.SelectedIndices.Count > 0 && !AvatarView.SelectedIndices.Contains(0))
{
try
{
var i = 10000;
foreach (var index in AvatarView.SelectedIndices)
{
if ((int)index < i) i = (int)index;
}
var name = AvatarView.Items[i].Text.Split(' ')[0].Trim() ;
if (MultiPlayer.MPManager.OnlineTrains.Players.ContainsKey(name))
{
pos = MultiPlayer.MPManager.OnlineTrains.Players[name].Train.Cars[0].WorldPosition;
}
else if (MultiPlayer.MPManager.Instance().lostPlayer.ContainsKey(name))
{
pos = MultiPlayer.MPManager.Instance().lostPlayer[name].Train.Cars[0].WorldPosition;
}
hasSelectedTrain = true;
}
catch { }
int i = AvatarView.SelectedIndices.Cast<int>().Min();
string name = (AvatarView.Items[i].Text ?? "").Split(' ').First().Trim();
if (MultiPlayer.MPManager.OnlineTrains.Players.TryGetValue(name, out MultiPlayer.OnlinePlayer player))
pos = player?.Train?.Cars?.FirstOrDefault()?.WorldPosition;
else if (MultiPlayer.MPManager.Instance().lostPlayer.TryGetValue(name, out MultiPlayer.OnlinePlayer lost))
pos = lost?.Train?.Cars?.FirstOrDefault()?.WorldPosition;
}
if (hasSelectedTrain == false && PickedTrain != null && PickedTrain.Cars != null && PickedTrain.Cars.Count > 0)
if (pos == null)
pos = PickedTrain?.Cars?.FirstOrDefault()?.WorldPosition;
if (pos != null)
{
pos = PickedTrain.Cars[0].WorldPosition;
var ploc = new PointF(pos.TileX * 2048 + pos.Location.X, pos.TileZ * 2048 + pos.Location.Z);
ViewWindow.X = ploc.X - minX - ViewWindow.Width / 2; ViewWindow.Y = ploc.Y - minY - ViewWindow.Width / 2;
firstShow = false;
}
var ploc = new PointF(pos.TileX * 2048 + pos.Location.X, pos.TileZ * 2048 + pos.Location.Z);
ViewWindow.X = ploc.X - minX - ViewWindow.Width / 2; ViewWindow.Y = ploc.Y - minY - ViewWindow.Width / 2;
firstShow = false;
}

try
Expand Down Expand Up @@ -809,14 +794,11 @@ public void GenerateView()
var drawRed = 0;
int ValidTrain = selectedTrainList.Count();
//add trains quit into the end, will draw them in gray
try
{
foreach (var lost in MultiPlayer.MPManager.Instance().lostPlayer)
{
if (lost.Value.Train != null && !selectedTrainList.Contains(lost.Value.Train)) selectedTrainList.Add(lost.Value.Train);
}
}
catch { }
var quitTrains = MultiPlayer.MPManager.Instance().lostPlayer.Values
.Select((MultiPlayer.OnlinePlayer lost) => lost?.Train)
.Where((Train t) => t != null)
.Where((Train t) => !selectedTrainList.Contains(t));
selectedTrainList.AddRange(quitTrains);
foreach (Train t in selectedTrainList)
{
drawRed++;//how many red has been drawn
Expand Down Expand Up @@ -1662,24 +1644,13 @@ private void pictureBoxMouseMove(object sender, MouseEventArgs e)
LastCursorPosition.Y = e.Y;
}

public bool addNewMessage(double time, string msg)
public bool AddNewMessage(double _, string msg)
{
var count = 0;
while (count < 3)
{
try
{
if (messages.Items.Count > 10)
{
messages.Items.RemoveAt(0);
}
messages.Items.Add(msg);
messages.SelectedIndex = messages.Items.Count - 1;
messages.SelectedIndex = -1;
break;
}
catch { count++; }
}
if (messages.Items.Count > 10)
messages.Items.RemoveAt(0);
messages.Items.Add(msg);
messages.SelectedIndex = messages.Items.Count - 1;
messages.SelectedIndex = -1;
return true;
}

Expand Down Expand Up @@ -1743,19 +1714,19 @@ private void msgDefault()
{
if (MultiPlayer.MPManager.IsServer())
{
var users = MultiPlayer.MPManager.OnlineTrains.Players.Keys
.Select((string u) => $"{u}\r");
string user = string.Join("", users) + "0END";
string msgText = new MultiPlayer.MSGText(MultiPlayer.MPManager.GetUserName(), user, msg).ToString();
try
{
var user = "";
foreach (var p in MultiPlayer.MPManager.OnlineTrains.Players)
{
user += p.Key + "\r";
}
user += "0END";
MultiPlayer.MPManager.Notify((new MultiPlayer.MSGText(MultiPlayer.MPManager.GetUserName(), user, msg)).ToString());
MSG.Text = "";

MultiPlayer.MPManager.Notify(msgText);
}
catch { }
finally
{
MSG.Text = "";
}
}
else
{
Expand Down Expand Up @@ -1833,18 +1804,19 @@ private void checkKeys(object sender, PreviewKeyDownEventArgs e)

if (MultiPlayer.MPManager.IsServer())
{
var users = MultiPlayer.MPManager.OnlineTrains.Players.Keys
.Select((string u) => $"{u}\r");
user += string.Join("", users) + "0END";
string msgText = new MultiPlayer.MSGText(MultiPlayer.MPManager.GetUserName(), user, msg).ToString();
try
{
foreach (var p in MultiPlayer.MPManager.OnlineTrains.Players)
{
user += p.Key + "\r";
}
user += "0END";
MultiPlayer.MPManager.Notify((new MultiPlayer.MSGText(MultiPlayer.MPManager.GetUserName(), user, msg)).ToString());
MSG.Text = "";

MultiPlayer.MPManager.Notify(msgText);
}
catch { }
finally
{
MSG.Text = "";
}
}
else
{
Expand Down Expand Up @@ -2143,21 +2115,40 @@ public SignalWidget(SignalItem item, SignalObject signal)
Item = item;
Signal = signal;
hasDir = false;
Location.X = item.TileX * 2048 + item.X; Location.Y = item.TileZ * 2048 + item.Z;
try
Location.X = item.TileX * 2048 + item.X;
Location.Y = item.TileZ * 2048 + item.Z;
var node = Program.Simulator.TDB.TrackDB.TrackNodes?[signal.trackNode];
Vector2 v2;
if (node?.TrVectorNode != null)
{
var ts = node.TrVectorNode.TrVectorSections?.FirstOrDefault();
if (ts == null)
return;
v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
}
else if (node?.TrJunctionNode != null)
{
var ts = node?.UiD;
if (ts == null)
return;
v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z);
}
else
{
return;
}
var v1 = new Vector2(Location.X, Location.Y);
var v3 = v1 - v2;
v3.Normalize();
void copyTo(Vector2 input, ref PointF output)
{
var node = Program.Simulator.TDB.TrackDB.TrackNodes[signal.trackNode];
Vector2 v2;
if (node.TrVectorNode != null) { var ts = node.TrVectorNode.TrVectorSections[0]; v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z); }
else if (node.TrJunctionNode != null) { var ts = node.UiD; v2 = new Vector2(ts.TileX * 2048 + ts.X, ts.TileZ * 2048 + ts.Z); }
else throw new Exception();
var v1 = new Vector2(Location.X, Location.Y); var v3 = v1 - v2; v3.Normalize(); v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 12f : -12f);
Dir.X = v2.X; Dir.Y = v2.Y;
v2 = v1 - Vector2.Multiply(v3, signal.direction == 0 ? 1.5f : -1.5f);//shift signal along the dir for 2m, so signals will not be overlapped
Location.X = v2.X; Location.Y = v2.Y;
hasDir = true;
output.X = input.X;
output.Y = input.Y;
}
catch { }
copyTo(v1 - Vector2.Multiply(v3, signal.direction == 0 ? 12f : -12f), ref Dir);
//shift signal along the dir for 2m, so signals will not be overlapped
copyTo(v1 - Vector2.Multiply(v3, signal.direction == 0 ? 1.5f : -1.5f), ref Location);
hasDir = true;
}
}
#endregion
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3223a4d

Please sign in to comment.