Skip to content

Commit

Permalink
Merge pull request #164 from EVEJay/master
Browse files Browse the repository at this point in the history
Switched to Dispatch Timers because Tasks had intermittend issues with updating.
  • Loading branch information
Slazanger authored Jun 20, 2024
2 parents 62a070e + 50ea557 commit b6c5820
Showing 1 changed file with 41 additions and 54 deletions.
95 changes: 41 additions & 54 deletions SMT/Overlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Windows.Services;
using Microsoft.IdentityModel.Tokens;
using NHotkey;
Expand Down Expand Up @@ -266,8 +267,6 @@ public partial class Overlay : Window
private Brush toolTipBackgroundBrush;
private Brush toolTipForegroundBrush;

private PeriodicTimer dataUpdateTimer, characterUpdateTimer;

private int overlayDepth = 8;
private Dictionary<LocalCharacter, OverlaySystemData> currentPlayersSystemData = new ();
private OverlaySystemData currentPlayerSystemData;

Check warning on line 272 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 272 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 272 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 272 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used
Expand Down Expand Up @@ -301,6 +300,9 @@ public partial class Overlay : Window
private bool showAllCharacterNames = false;
private bool individualCharacterWindows = false;

private DispatcherTimer locationUpdateTimer = new DispatcherTimer();
private DispatcherTimer dataUpdateTimer = new DispatcherTimer();

private DoubleCollection dashStroke = new DoubleCollection(new List<double> { 2, 2 });

private DoubleAnimation dashAnimation;
Expand Down Expand Up @@ -434,8 +436,15 @@ public Overlay(MainWindow mw)
// Start the magic
ToggleClickTrough(mainWindow.OverlayWindowsAreClickTrough);
RefreshCurrentView();
_ = CharacterLocationUpdateLoop();
_ = DataOverlayUpdateLoop();

locationUpdateTimer.Interval = TimeSpan.FromMilliseconds(250);
locationUpdateTimer.Tick += UpdatePlayerLocations;

dataUpdateTimer.Interval = TimeSpan.FromSeconds(1);
dataUpdateTimer.Tick += UpdateDataOverlay;

locationUpdateTimer.Start();
dataUpdateTimer.Start();
}

private void OnClickTroughToggle(object sender, HotkeyEventArgs e)
Expand Down Expand Up @@ -633,68 +642,45 @@ private void UpdateCharacterData()
}
}

/// <summary>
/// Starts a timer that will periodically check for changes in the
/// players location to update the map.
/// </summary>
/// <returns></returns>
/// TODO: Make intervall a global setting.
private async Task CharacterLocationUpdateLoop()
private void UpdatePlayerLocations(object sender, EventArgs e)
{
characterUpdateTimer = new PeriodicTimer(TimeSpan.FromMilliseconds(250));
UpdateCharacterData();

while (await characterUpdateTimer.WaitForNextTickAsync())
if (OverlayCharacter != null)
{
// If the location differs from the last known location, trigger a change.
if (OverlayCharacter != null)
if (currentPlayersSystemData[OverlayCharacter].system == null)
{
if (currentPlayersSystemData[OverlayCharacter].system == null)
{
RefreshCurrentView();
}
else if (OverlayCharacter.Location != currentPlayersSystemData[OverlayCharacter].system.Name || routeLines.Count > 0 && (routeLines.Count != OverlayCharacter.ActiveRoute.Count - 1))
{
RefreshCurrentView();
}
else
RefreshCurrentView();
}
else if (OverlayCharacter.Location != currentPlayersSystemData[OverlayCharacter].system.Name || routeLines.Count > 0 && (routeLines.Count != OverlayCharacter.ActiveRoute.Count - 1))
{
RefreshCurrentView();
}
else
{
foreach (LocalCharacter additionalCharacter in mainWindow.EVEManager.LocalCharacters)
{
foreach (LocalCharacter additionalCharacter in mainWindow.EVEManager.LocalCharacters)
if (additionalCharacter != OverlayCharacter)
{
if (additionalCharacter != OverlayCharacter)
if (additionalCharacter.Location != currentPlayersSystemData[additionalCharacter].system.Name)
{
if (additionalCharacter.Location != currentPlayersSystemData[additionalCharacter].system.Name)
{
RefreshCurrentView();
break;
}
RefreshCurrentView();
break;
}
}
}
}
}
}
}
}

/// <summary>
/// Starts a timer that will periodically update the additional information displayed.
/// </summary>
/// <returns></returns>
/// TODO: Make intervall a global setting.
private async Task DataOverlayUpdateLoop()
private void UpdateDataOverlay(object sender, EventArgs e)
{
dataUpdateTimer = new PeriodicTimer(TimeSpan.FromSeconds(1));

while (await dataUpdateTimer.WaitForNextTickAsync())
try
{
UpdateIntelData();
if (!gathererMode && (showNPCKillData || showNPCKillDeltaData)) UpdateNPCKillData();
UpdateRouteData();
}
catch (Exception)
{
try
{
UpdateIntelData();
if (!gathererMode && (showNPCKillData || showNPCKillDeltaData)) UpdateNPCKillData();
UpdateRouteData();
}
catch (Exception)
{
}
}
}

Expand Down Expand Up @@ -1577,10 +1563,11 @@ private void DrawSystemToOverlay(OverlaySystemData sysData, double left, double
systemData[sysData.system.Name].systemNameElement.Foreground = Brushes.White;
systemData[sysData.system.Name].systemNameElement.FontSize = 10;
systemData[sysData.system.Name].systemNameElement.TextAlignment = TextAlignment.Center;
systemData[sysData.system.Name].systemNameElement.IsHitTestVisible = false;

Canvas.SetLeft(systemData[sysData.system.Name].systemNameElement, leftCoord - (systemData[sysData.system.Name].systemNameElement.Width * 0.5f) + (systemData[sysData.system.Name].systemCanvasElement.Width * 0.5f));
Canvas.SetTop(systemData[sysData.system.Name].systemNameElement, topCoord + systemData[sysData.system.Name].systemCanvasElement.Height + 2);
Canvas.SetZIndex(systemData[sysData.system.Name].systemNameElement, 99);
Canvas.SetZIndex(systemData[sysData.system.Name].systemNameElement, 125);

if (!overlay_Canvas.Children.Contains(systemData[sysData.system.Name].systemNameElement))
{
Expand Down

0 comments on commit b6c5820

Please sign in to comment.