Skip to content

Commit 73deca3

Browse files
committed
Try and make refresh more robust
1 parent d759930 commit 73deca3

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

Brio/Game/Actor/ActorRedrawService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public unsafe void Redraw(GameObject gameObject, RedrawType redrawType, bool pre
4747
raw->DrawObject->Object.Position = originalPositon;
4848
CanRedraw = true;
4949
},
50-
50);
50+
50,
51+
1,
52+
true);
5153
}
5254
else
5355
{

Brio/Game/Actor/ActorSpawnService.cs

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ private void GPoseService_OnGPoseStateChange(bool isInGpose)
5656
newPlayer->GameObject.Position= originalPlayer->GameObject.Position;
5757
newPlayer->GameObject.SetName(((int)newId).ToCharacterName());
5858

59-
newPlayer->GameObject.DisableDraw();
60-
6159
newPlayer->CopyFromCharacter(newPlayer, 0); // Some tools get confused (Like Penumbra) unless we copy onto ourselves after name change
6260

6361
newPlayer->GameObject.EnableDraw();

Brio/Game/Core/FrameworkUtils.cs

+40-22
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public void RunDeferred(
3030
{
3131
var newTask = new DeferredTask()
3232
{
33-
ConditionAction = (task) => task.TickCount >= task.FrameTarget,
33+
ConditionAction = (task) => task.TickCount >= task.StartFrame,
3434
CompleteAction = action,
35-
FrameTarget = delay,
35+
MaxFrames = delay,
36+
StartFrame = delay,
3637
DebugPath = $"{callerFile}:{callerLine} - {callerMember}"
3738
};
3839

@@ -42,7 +43,9 @@ public void RunDeferred(
4243
public void RunUntilSatisfied(
4344
Func<bool> condition,
4445
Action<bool> onSatisfied,
45-
int attempts = 0,
46+
int attempts,
47+
int dontStartFor = 0,
48+
bool waitOneMore = false,
4649
[CallerFilePath] string callerFile = "",
4750
[CallerLineNumber] int callerLine = 0,
4851
[CallerMemberName] string callerMember = ""
@@ -52,7 +55,9 @@ public void RunUntilSatisfied(
5255
{
5356
ConditionAction = (_) => condition.Invoke(),
5457
CompleteAction = onSatisfied.Invoke,
55-
FrameTarget = attempts,
58+
MaxFrames = attempts,
59+
StartFrame = dontStartFor,
60+
DeferOnceMore = waitOneMore,
5661
DebugPath = $"{callerFile}:{callerLine} - {callerMember}"
5762
};
5863

@@ -72,20 +77,31 @@ private void TickTasks()
7277
var task = _deferredTasks[i];
7378
task.TickCount++;
7479

75-
var conditionSatisfied = CheckTask(task);
76-
77-
if(conditionSatisfied == true)
78-
{
79-
_deferredTasks.RemoveAt(i--);
80-
CompleteTask(task, true);
81-
}
82-
else if(conditionSatisfied == null || task.FrameTarget <= task.TickCount)
80+
if (task.TickCount >= task.StartFrame)
8381
{
84-
if (task.FrameTarget <= task.TickCount)
85-
PluginLog.Warning($"Task timed out. {task}");
86-
87-
_deferredTasks.RemoveAt(i--);
88-
CompleteTask(task, false);
82+
var conditionSatisfied = CheckTask(task);
83+
84+
if (conditionSatisfied == true)
85+
{
86+
if (task.DeferOnceMore)
87+
{
88+
task.DeferOnceMore = false;
89+
task.ConditionAction = (_) => true;
90+
}
91+
else
92+
{
93+
_deferredTasks.RemoveAt(i--);
94+
CompleteTask(task, true);
95+
}
96+
}
97+
else if (conditionSatisfied == null || task.MaxFrames <= task.TickCount)
98+
{
99+
if (task.MaxFrames <= task.TickCount)
100+
PluginLog.Warning($"Task timed out. {task}");
101+
102+
_deferredTasks.RemoveAt(i--);
103+
CompleteTask(task, false);
104+
}
89105
}
90106
}
91107
}
@@ -117,11 +133,13 @@ private void CompleteTask(DeferredTask task, bool success)
117133

118134
class DeferredTask
119135
{
120-
public Func<DeferredTask, bool> ConditionAction { get; init; } = null!;
121-
public Action<bool> CompleteAction { get; init; } = null!;
122-
public string DebugPath { get; init; } = null!;
123-
public int FrameTarget { get; init; }
136+
public Func<DeferredTask, bool> ConditionAction { get; set; } = null!;
137+
public Action<bool> CompleteAction { get; set; } = null!;
138+
public string DebugPath { get; set; } = null!;
139+
public int MaxFrames { get; set; }
140+
public int StartFrame { get; set; }
124141
public int TickCount { get; set; } = -1;
142+
public bool DeferOnceMore { get; set; } = false;
125143

126-
public override string ToString() => $"{DebugPath}. T: {FrameTarget} C: {TickCount}";
144+
public override string ToString() => $"{DebugPath}. T: {MaxFrames} C: {TickCount}";
127145
}

Brio/IPC/PenumbraIPC.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public unsafe void RedrawActorWithCollection(GameObject gameObject, string colle
9999
Ipc.SetCollectionForObject.Subscriber(Dalamud.PluginInterface).Invoke(index, oldName, true, true);
100100
CanApplyCollection = true;
101101
},
102-
50
102+
50,
103+
3,
104+
true
103105
);
104106
}
105107
catch(Exception ex)

0 commit comments

Comments
 (0)