Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched to Dispatch Timers because Tasks had intermittend issues with updating. #164

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 +267,9 @@
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
private OverlayCanvasData canvasData = new OverlayCanvasData();

private float intelUrgentPeriod = 300;
Expand Down Expand Up @@ -301,6 +300,9 @@
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 @@
// 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 @@
}
}

/// <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 @@
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
Loading