Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: multi thread for acceleration.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 1, 2023
1 parent 5858428 commit 7950f91
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
2 changes: 2 additions & 0 deletions RotationSolver/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class PluginConfiguration : IPluginConfiguration
public float InterruptDelayMin = 0.5f;
public float InterruptDelayMax = 1;

public int WorkTaskDelay = 20;

public string PositionalErrorText = string.Empty;

public int MoveTargetAngle = 24;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static bool CanInterrupt(this BattleChara b)

//跳过扇形圆型
if (act.CastType is 3 or 4) return false;
if (ActionManager.GetActionRange(b.CastActionId) < 8) return false;
if (ActionManager.GetActionRange(b.CastActionId) is > 0 and < 8) return false;
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions RotationSolver/Localization/Strings_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ internal partial class Strings

public string Configwindow_Param_HealDelay { get; set; } = "Set the range of random delay for healing people in second.";

public string Configwindow_Param_WorkTaskDelay { get; set; } = "Set the work task delay in millisecond. Smaller, more precise, more resource-intensive";

public string Configwindow_Param_Display { get; set; } = "Display";
public string Configwindow_Param_PoslockCasting { get; set; } = "Lock the movement when casting";
public string Configwindow_Param_PoslockModifier { get; set; } = "Set the modifier key to unlock the movement temporary";
Expand Down
48 changes: 37 additions & 11 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Game;
using RotationSolver.Commands;
using System.Threading.Tasks;

namespace RotationSolver.Updaters;

Expand All @@ -8,7 +9,7 @@ internal static class MajorUpdater
//#if DEBUG
// private static readonly Dictionary<int, bool> _valus = new Dictionary<int, bool>();
//#endif
private unsafe static void FrameworkUpdate(Framework framework)
private static void FrameworkUpdate(Framework framework)
{
if (!Service.Conditions.Any() || Service.ClientState.LocalPlayer == null) return;

Expand All @@ -30,31 +31,56 @@ private unsafe static void FrameworkUpdate(Framework framework)
// }
// }
//#endif
//Update State.
PreviewUpdater.UpdatePreview();

ActionUpdater.UpdateActionInfo();

TargetUpdater.UpdateTarget();

MovingUpdater.UpdateLocation();
PreviewUpdater.UpdatePreview();
//ActionUpdater.UpdateActionInfo();
//TargetUpdater.UpdateTarget();
//MovingUpdater.UpdateLocation();

ActionUpdater.DoAction();

RSCommands.UpdateRotationState();
TimeLineUpdater.UpdateTimelineAction();
ActionUpdater.UpdateNextAction();
//TimeLineUpdater.UpdateTimelineAction();
//ActionUpdater.UpdateNextAction();
//RSCommands.UpdateRotationState();
MacroUpdater.UpdateMacro();
}

static bool _quit = false;
public static void Enable()
{
Service.Framework.Update += FrameworkUpdate;
Task.Run(() =>
{
while (true)
{
if(_quit) return;
if (!Service.Conditions.Any() || Service.ClientState.LocalPlayer == null)
{
Task.Delay(200);
continue;
}

//PreviewUpdater.UpdatePreview();
ActionUpdater.UpdateActionInfo();
TargetUpdater.UpdateTarget();
MovingUpdater.UpdateLocation();

//ActionUpdater.DoAction();

TimeLineUpdater.UpdateTimelineAction();
ActionUpdater.UpdateNextAction();
RSCommands.UpdateRotationState();
//MacroUpdater.UpdateMacro();

Task.Delay(Service.Configuration.WorkTaskDelay);
}
});
MovingUpdater.Enable();
}

public static void Dispose()
{
_quit = true;
Service.Framework.Update -= FrameworkUpdate;
PreviewUpdater.Dispose();
MovingUpdater.Dispose();
Expand Down
3 changes: 0 additions & 3 deletions RotationSolver/Updaters/MovingUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ internal static void UpdateLocation()

_moving = _lastPosition != p;
_lastPosition = p;

if (Service.ClientState.LocalPlayer.HasStatus(true, StatusID.TenChiJin)) IsMoving = false;

}

private static bool MovingDetour(IntPtr ptr)
Expand Down
13 changes: 5 additions & 8 deletions RotationSolver/Updaters/PreviewUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ private static unsafe void UpdateCastBar()
&& !Service.Conditions[Dalamud.Game.ClientState.Conditions.ConditionFlag.Casting];

ByteColor c = canMove && Service.Configuration.CastingDisplay ? greenColor : redColor;
var isTarDead = false;
if (Service.ObjectTable.SearchById(Service.ClientState.LocalPlayer.CastTargetObjectId) is BattleChara b
&& b.CurrentHp == 0)
{
isTarDead = true;
}
var isTarDead = Service.ObjectTable.SearchById(Service.ClientState.LocalPlayer.CastTargetObjectId)
is BattleChara b && b.CurrentHp == 0;

var specialStatus = Service.ClientState.LocalPlayer.HasStatus(true, StatusID.PhantomFlurry);
MovingUpdater.IsMoving = specialStatus ? false : canMove || isTarDead;
//For lock
var specialStatus = Service.ClientState.LocalPlayer.HasStatus(true, StatusID.PhantomFlurry, StatusID.TenChiJin);
MovingUpdater.IsMoving = specialStatus ? false : (canMove || isTarDead);

var castBar = Service.GameGui.GetAddonByName("_CastBar", 1);
if (castBar == IntPtr.Zero) return;
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/Windows/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ private void DrawParamDelay()

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_HealDelay,
ref Service.Configuration.HealDelayMin, ref Service.Configuration.HealDelayMax);

DrawIntNumber(LocalizationManager.RightLang.Configwindow_Param_WorkTaskDelay,
ref Service.Configuration.WorkTaskDelay, min: 0, max: 200);
}

private void DrawParamDisplay()
Expand Down

0 comments on commit 7950f91

Please sign in to comment.