Skip to content

Commit

Permalink
Merge pull request #394 from FFXIV-CombatReborn/frameworkstyle
Browse files Browse the repository at this point in the history
Refactor Configs and MajorUpdater for flexible framework updates
  • Loading branch information
LTS-FFXIV authored Sep 22, 2024
2 parents 8dd637b + 06f1397 commit a201079
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public const string
PvPFilter = JobFilterType.NoJob)]
private static readonly bool _interruptibleMoreCheck = true;

[ConditionBool, UI("Use work task for acceleration. (EXPERIMENTAL, WILL CAUSE CRASHES AND OTHER ISSUES)",
[UI("Framework Update Method (Experimental: Changing this off of game thread will cause crashes)",
Filter = BasicParams)]
private static readonly bool _useWorkTask = false;
public FrameworkStyle FrameworkStyle { get; set; } = FrameworkStyle.MainThread;

[ConditionBool, UI("Stop casting if the target dies.", Filter = Extra)]
private static readonly bool _useStopCasting = false;
Expand Down
25 changes: 25 additions & 0 deletions RotationSolver.Basic/Data/FrameworkStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace RotationSolver.Basic.Data;

/// <summary>
/// The way the framework updates.
/// </summary>
public enum FrameworkStyle : byte
{
/// <summary>
/// On the game thread.
/// </summary>
[Description("On the game thread")]
MainThread,

/// <summary>
/// Running outside of game thread.
/// </summary>
[Description("Running outside of game thread")]
WorkTask,

/// <summary>
/// Running on Game Tick.
/// </summary>
[Description("Running on Game Tick")]
RunOnTick,
}
35 changes: 18 additions & 17 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private unsafe static void FrameworkUpdate(IFramework framework)
}
}

HandleWorkUpdate();
HandleWorkUpdateAsync().ConfigureAwait(false);
}

private static void HandleSystemWarnings()
Expand All @@ -97,34 +97,35 @@ private static void HandleSystemWarnings()
}
}

private static void HandleWorkUpdate()
private static async Task HandleWorkUpdateAsync()
{
var now = DateTime.UtcNow;
try
{
if (now - _lastUpdatedWork < TimeSpan.FromSeconds(Service.Config.MinUpdatingTime))
return;
if (now - _lastUpdatedWork < TimeSpan.FromSeconds(Service.Config.MinUpdatingTime))
return;

_lastUpdatedWork = now;
_lastUpdatedWork = now;

try
try
{
if (Service.Config.FrameworkStyle == FrameworkStyle.WorkTask)
{
UpdateWork();
await Task.Run(() => UpdateWork());
}
catch (Exception tEx)
else if (Service.Config.FrameworkStyle == FrameworkStyle.RunOnTick)
{
Svc.Log.Error(tEx, "Worker Task Exception");
if (Service.Config.InDebug)
#pragma warning disable CS0436
WarningHelper.AddSystemWarning("Worker Task Exception");
await Svc.Framework.RunOnTick(() => UpdateWork());
}
else if (Service.Config.FrameworkStyle == FrameworkStyle.MainThread)
{
UpdateWork();
}
}
catch (Exception ex)
catch (Exception tEx)
{
Svc.Log.Error(ex, "Worker Exception in HandleWorkUpdate");
Svc.Log.Error(tEx, "Worker Task Exception");
if (Service.Config.InDebug)
#pragma warning disable CS0436
WarningHelper.AddSystemWarning("Worker Exception in HandleWorkUpdate");
WarningHelper.AddSystemWarning("Inner Worker Exception");
}
}

Expand Down

0 comments on commit a201079

Please sign in to comment.