Skip to content

Commit

Permalink
Maybe sort race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed May 1, 2023
1 parent a38a989 commit ee50994
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Penumbra/Collections/Cache/CollectionCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public CollectionCacheManager(FrameworkManager framework, CommunicatorService co
_active = active;
_storage = storage;

if (!_active.Individuals.IsLoaded)
_active.Individuals.Loaded += CreateNecessaryCaches;
_communicator.CollectionChange.Subscribe(OnCollectionChange, -100);
_communicator.ModPathChanged.Subscribe(OnModChangeAddition, -100);
_communicator.ModPathChanged.Subscribe(OnModChangeRemoval, 100);
_communicator.TemporaryGlobalModChange.Subscribe(OnGlobalModChange);
_communicator.ModOptionChanged.Subscribe(OnModOptionChange, -100);
_communicator.ModSettingChanged.Subscribe(OnModSettingChange);
_communicator.CollectionInheritanceChanged.Subscribe(OnCollectionInheritanceChange);
CreateNecessaryCaches();
_active.Individuals.Loaded += CreateNecessaryCaches;

if (!MetaFileManager.CharacterUtility.Ready)
MetaFileManager.CharacterUtility.LoadingFinished += IncrementCounters;

CreateNecessaryCaches();
}

public void Dispose()
Expand Down Expand Up @@ -303,6 +305,7 @@ private void CreateNecessaryCaches()
.Select(c => Task.Run(() => CalculateEffectiveFileListInternal(c)))
.ToArray();

Penumbra.Log.Debug($"Creating {tasks.Length} necessary caches.");
Task.WaitAll(tasks);
}
}
2 changes: 1 addition & 1 deletion Penumbra/Collections/Manager/ActiveCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ActiveCollections(Configuration config, CollectionStorage storage, ActorS
Current = storage.DefaultNamed;
Default = storage.DefaultNamed;
Interface = storage.DefaultNamed;
Individuals = new IndividualCollections(actors, config);
Individuals = new IndividualCollections(actors, config, false);
_communicator.CollectionChange.Subscribe(OnCollectionChange, -100);
LoadCollections();
UpdateCurrentCollectionInUse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Game;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Interface.Internal.Notifications;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -37,6 +36,7 @@ void Func()
{
if (ReadJObjectInternal(obj, storage))
saver.ImmediateSave(parent);
IsLoaded = true;
Loaded.Invoke();
_actorService.FinishedCreation -= Func;
});
Expand Down
4 changes: 3 additions & 1 deletion Penumbra/Collections/Manager/IndividualCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public sealed partial class IndividualCollections
private readonly Dictionary<ActorIdentifier, ModCollection> _individuals = new();

public event Action Loaded;
public bool IsLoaded { get; private set; }

public IReadOnlyList<(string DisplayName, IReadOnlyList<ActorIdentifier> Identifiers, ModCollection Collection)> Assignments
=> _assignments;

public IndividualCollections(ActorService actorService, Configuration config)
public IndividualCollections(ActorService actorService, Configuration config, bool temporary)
{
_config = config;
_actorService = actorService;
IsLoaded = temporary;
Loaded += () => Penumbra.Log.Information($"{_assignments.Count} Individual Assignments loaded after delay.");
}

Expand Down
2 changes: 1 addition & 1 deletion Penumbra/Collections/Manager/TempCollectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TempCollectionManager(Configuration config, CommunicatorService communica
_communicator = communicator;
_actors = actors;
_storage = storage;
Collections = new IndividualCollections(actors, config);
Collections = new IndividualCollections(actors, config, true);

_communicator.TemporaryGlobalModChange.Subscribe(OnGlobalModChange);
}
Expand Down

0 comments on commit ee50994

Please sign in to comment.