Skip to content

Commit

Permalink
Merge pull request #54 from #53-map-update-performance
Browse files Browse the repository at this point in the history
Agent#53 map update performance
  • Loading branch information
sushiat authored Feb 13, 2022
2 parents ebfc2e2 + 37330d6 commit 10755c6
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 89 deletions.
14 changes: 13 additions & 1 deletion OpenSky.Agent.Simulator/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ public abstract partial class Simulator : INotifyPropertyChanged
/// -------------------------------------------------------------------------------------------------
protected Simulator(OpenSkyService openSkyServiceInstance)
{
Debug.WriteLine($"Simulator interface of type {this.GetType().Name} starting...");

// Initialize empty data structures, to prevent NullReferenceExceptions
this.PrimaryTracking = new PrimaryTracking();
this.SecondaryTracking = new SecondaryTracking();
this.FuelTanks = new FuelTanks();
this.PayloadStations = new PayloadStations();
this.AircraftIdentity = new AircraftIdentity();
this.WeightAndBalance = new WeightAndBalance();

// Create queues and collections
this.openSkyServiceInstance = openSkyServiceInstance;
this.primaryTrackingProcessingQueue = new ConcurrentQueue<ProcessPrimaryTracking>();
this.secondaryTrackingProcessingQueue = new ConcurrentQueue<ProcessSecondaryTracking>();
Expand Down Expand Up @@ -233,6 +244,7 @@ protected set
/// -------------------------------------------------------------------------------------------------
public static void SetSimulatorInstance(Simulator simulator)
{
Instance?.Close();
Instance = simulator;
}

Expand All @@ -246,7 +258,7 @@ public static void SetSimulatorInstance(Simulator simulator)
/// -------------------------------------------------------------------------------------------------
public void Close()
{
Debug.WriteLine("SimConnect simulator interface closing down...");
Debug.WriteLine($"Simulator interface of type {this.GetType().Name} closing down...");
if (this.TrackingStatus is TrackingStatus.GroundOperations or TrackingStatus.Tracking)
{
this.StopTracking(false);
Expand Down
8 changes: 0 additions & 8 deletions OpenSky.Agent.UdpXPlane11/UdpXPlane11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public UdpXPlane11(string simulatorIPAddress, uint simulatorPort, OpenSkyService
this.simulatorIPAddress = simulatorIPAddress;
this.simulatorPort = simulatorPort;

// Initialize empty data structures, to prevent NullReferenceExceptions
this.PrimaryTracking = new PrimaryTracking();
this.SecondaryTracking = new SecondaryTracking();
this.FuelTanks = new FuelTanks();
this.PayloadStations = new PayloadStations();
this.AircraftIdentity = new AircraftIdentity();
this.WeightAndBalance = new WeightAndBalance();

// Start our worker thread
new Thread(this.ReadFromXPlane) { Name = "UdpXPlane11.ReadFromXPlane" }.Start();
}
Expand Down
36 changes: 36 additions & 0 deletions OpenSky.Agent/Properties/Settings.Designer.cs

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

9 changes: 9 additions & 0 deletions OpenSky.Agent/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,14 @@
<Setting Name="XPlanePort" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">49000</Value>
</Setting>
<Setting Name="SimulatorHostName" Type="System.String" Scope="User">
<Value Profile="(Default)">localhost</Value>
</Setting>
<Setting Name="SimulatorPort" Type="System.String" Scope="User">
<Value Profile="(Default)">500</Value>
</Setting>
<Setting Name="AircraftPositionUpdateInterval" Type="System.Int32" Scope="User">
<Value Profile="(Default)">500</Value>
</Setting>
</Settings>
</SettingsFile>
4 changes: 2 additions & 2 deletions OpenSky.Agent/Views/FlightTracking.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ private void AddAircraftAndTrailsToMap()
aircraftPosition.SetValue(Panel.ZIndexProperty, 999);
aircraftPosition.SetValue(MapLayer.PositionOriginProperty, PositionOrigin.Center);
var rotateTransform = new RotateTransform { CenterX = 20, CenterY = 20 };
var headingBinding = new Binding { Source = this.DataContext, Path = new PropertyPath("Simulator.PrimaryTracking.Heading"), Mode = BindingMode.OneWay };
var headingBinding = new Binding { Source = this.DataContext, Path = new PropertyPath("AircraftHeading"), Mode = BindingMode.OneWay };
BindingOperations.SetBinding(rotateTransform, RotateTransform.AngleProperty, headingBinding);
aircraftPosition.RenderTransform = rotateTransform;
var aircraftDrawingImage = this.FindResource("OpenSkyLogoPointingUpForMap") as DrawingImage;
aircraftPosition.Source = aircraftDrawingImage;
var positionBinding = new Binding { Source = this.DataContext, Path = new PropertyPath("Simulator.PrimaryTracking.MapLocation"), Mode = BindingMode.OneWay };
var positionBinding = new Binding { Source = this.DataContext, Path = new PropertyPath("AircraftLocation"), Mode = BindingMode.OneWay };
BindingOperations.SetBinding(aircraftPosition, MapLayer.PositionProperty, positionBinding);
this.MapView.Children.Add(aircraftPosition);
}
Expand Down
Loading

0 comments on commit 10755c6

Please sign in to comment.