Skip to content

Commit 595be4f

Browse files
committed
sort SaveLoadActions
(this is the actual released v3.27.5)
1 parent c40120d commit 595be4f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

SpeedrunTool/Source/DebugTool/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static class Config {
77
public const bool Log_WhenSaving = false;
88
public const bool Log_WhenLoading = false;
99
public const bool Log_SavedLevel = false;
10-
public const bool Log_AllActions = false;
10+
public const bool Log_AllActions = true;
1111

1212
// Assets
1313
public const bool Log_Assets = false;

SpeedrunTool/Source/SaveLoad/SaveLoadAction.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static bool slotInitialized {
3030
public static List<EventInstance> ClonedEventInstancesWhenPreClone => SaveSlotsManager.Slot.ClonedEventInstancesWhenPreClone;
3131

3232
// only actions, no values stored. Share among all save slots
33-
private static readonly List<SaveLoadAction> SharedActions = new();
33+
private static List<SaveLoadAction> SharedActions = new();
3434

3535
private static readonly List<SaveLoadAction> ToBeAddedModSharedActions = new();
3636
// external actions will be first added to here, then this list merge into SharedActions
@@ -69,7 +69,14 @@ internal static Dictionary<int, Dictionary<Type, Dictionary<string, object>>> In
6969
private readonly Action preCloneEntities;
7070
internal readonly SlAction loadState;
7171
private readonly SlAction saveState;
72-
internal Action<Level, List<Entity>, Entity> unloadLevel;
72+
internal Action<Level, List<Entity>, Entity> unloadLevel;
73+
private int executeOrder;
74+
75+
private static int? contextOrder = null;
76+
private const int Order_InternalCoreAction = 0;
77+
private const int Order_InternalOtherAction = 100;
78+
private const int Order_ExternalAction = 10000;
79+
private const int Order_ExecuteAtLast = 1000000;
7380

7481
public SaveLoadAction(SlAction saveState = null, SlAction loadState = null, Action clearState = null,
7582
Action<Level> beforeSaveState = null, Action preCloneEntities = null) {
@@ -120,6 +127,7 @@ internal static SaveLoadAction InternalSafeAdd(Action<Dictionary<Type, Dictionar
120127
throw new Exception("Internal SaveLoad actions are added after expected time!");
121128
}
122129
SaveLoadAction saveLoadAction = new(CreateSlAction(saveState), CreateSlAction(loadState), clearState, beforeSaveState, beforeLoadState, preCloneEntities);
130+
saveLoadAction.executeOrder = contextOrder.GetValueOrDefault(Order_InternalOtherAction);
123131
#if DEBUG
124132
AddDebugDescription(saveLoadAction, internalCall: true);
125133
#endif
@@ -138,6 +146,7 @@ public static object SafeAdd(Action<Dictionary<Type, Dictionary<string, object>>
138146
Action<Dictionary<Type, Dictionary<string, object>>, Level> loadState, Action clearState,
139147
Action<Level> beforeSaveState, Action<Level> beforeLoadState, Action preCloneEntities = null) {
140148
SaveLoadAction saveLoadAction = new(CreateSlAction(saveState), CreateSlAction(loadState), clearState, beforeSaveState, beforeLoadState, preCloneEntities);
149+
saveLoadAction.executeOrder = Order_ExternalAction;
141150
#if DEBUG
142151
AddDebugDescription(saveLoadAction, internalCall: false);
143152
#endif
@@ -309,6 +318,7 @@ private static void InitActions() {
309318
return;
310319
}
311320

321+
contextOrder = Order_InternalCoreAction;
312322
SupportTracker();
313323
InitFields();
314324
SupportSimpleStaticFields();
@@ -340,9 +350,11 @@ private static void InitActions() {
340350
BrokemiaHelperUtils.Support();
341351
VivHelperUtils.Support();
342352

343-
// 放最后,确保收集了所有克隆的 VirtualAssets 与 EventInstance
353+
// 放最后,确保收集了所有克隆的 VirtualAssets 与 EventInstance
354+
contextOrder = Order_ExecuteAtLast;
344355
GraphicResourcesHandler.AddSaveLoadAction();
345356
ReleaseEventInstances();
357+
contextOrder = null;
346358

347359
internalActionInitialized = true;
348360
needInitializeDictionaryId = true;
@@ -359,6 +371,7 @@ public static void InitSlots() {
359371
SharedActions.AddRange(ToBeAddedModSharedActions);
360372
}
361373
ToBeAddedModSharedActions.Clear();
374+
SharedActions = SharedActions.OrderBy(x => x.executeOrder).ToList(); // it's a stable sort
362375
int i = 0;
363376
foreach (SaveLoadAction action in SharedActions) {
364377
i++;

0 commit comments

Comments
 (0)