From deb630795df26f671a1053729b4595b3491e355f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 22 Jan 2023 12:56:36 +0100 Subject: [PATCH] Move Frameworkmanager to OtterGui. --- OtterGui | 2 +- .../Interop/Resolver/PathResolver.Subfiles.cs | 16 ++- Penumbra/Penumbra.cs | 2 +- Penumbra/Util/FrameworkManager.cs | 99 ------------------- 4 files changed, 9 insertions(+), 110 deletions(-) delete mode 100644 Penumbra/Util/FrameworkManager.cs diff --git a/OtterGui b/OtterGui index d018a822..43b78fd8 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit d018a822212a68492771db1ee6a8921df36f677d +Subproject commit 43b78fd8dcdc12e0c2ba831bd037ad8e8a415e0e diff --git a/Penumbra/Interop/Resolver/PathResolver.Subfiles.cs b/Penumbra/Interop/Resolver/PathResolver.Subfiles.cs index 3359270f..a705fd6d 100644 --- a/Penumbra/Interop/Resolver/PathResolver.Subfiles.cs +++ b/Penumbra/Interop/Resolver/PathResolver.Subfiles.cs @@ -43,15 +43,13 @@ public unsafe partial class PathResolver { switch( type ) { - case ResourceType.Tex: - case ResourceType.Shpk: - if( _mtrlData.Value.Valid ) - { - collection = _mtrlData.Value; - return true; - } - - break; + case ResourceType.Tex when _mtrlData.Value.Valid: + case ResourceType.Shpk when _mtrlData.Value.Valid: + collection = _mtrlData.Value; + return true; + case ResourceType.Scd when _avfxData.Value.Valid: + collection = _avfxData.Value; + return true; case ResourceType.Atex when _avfxData.Value.Valid: collection = _avfxData.Value; return true; diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 79f6ba77..2c90c01d 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -99,7 +99,7 @@ public class Penumbra : IDalamudPlugin ItemData = new ItemData( Dalamud.PluginInterface, Dalamud.GameData, Dalamud.GameData.Language ); Actors = new ActorManager( Dalamud.PluginInterface, Dalamud.Objects, Dalamud.ClientState, Dalamud.GameData, Dalamud.GameGui, ResolveCutscene ); - Framework = new FrameworkManager(); + Framework = new FrameworkManager(Dalamud.Framework, Log); CharacterUtility = new CharacterUtility(); Backup.CreateBackup( pluginInterface.ConfigDirectory, PenumbraBackupFiles() ); Config = Configuration.Load(); diff --git a/Penumbra/Util/FrameworkManager.cs b/Penumbra/Util/FrameworkManager.cs deleted file mode 100644 index 5a52d340..00000000 --- a/Penumbra/Util/FrameworkManager.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Dalamud.Game; - -namespace Penumbra.Util; - -// Manage certain actions to only occur on framework updates. -public class FrameworkManager : IDisposable -{ - private readonly Dictionary< string, Action > _important = new(); - private readonly Dictionary< string, Action > _delayed = new(); - - public FrameworkManager() - => Dalamud.Framework.Update += OnUpdate; - - // Register an action that is not time critical. - // One action per frame will be executed. - // On dispose, any remaining actions will be executed. - public void RegisterDelayed( string tag, Action action ) - { - lock( _delayed ) - { - _delayed[ tag ] = action; - } - } - - // Register an action that should be executed on the next frame. - // All of those actions will be executed in the next frame. - // If there are more than one, they will be launched in separated tasks, but waited for. - public void RegisterImportant( string tag, Action action ) - { - lock( _important ) - { - _important[ tag ] = action; - } - } - - public void Dispose() - { - Dalamud.Framework.Update -= OnUpdate; - foreach( var (_, action) in _delayed ) - { - action(); - } - - _delayed.Clear(); - } - - private void OnUpdate( Framework _ ) - { - try - { - HandleOne( _delayed ); - HandleAllTasks( _important ); - } - catch( Exception e ) - { - Penumbra.Log.Error( $"Problem saving data:\n{e}" ); - } - } - - private static void HandleOne( IDictionary< string, Action > dict ) - { - if( dict.Count == 0 ) - { - return; - } - - Action action; - lock( dict ) - { - ( var key, action ) = dict.First(); - dict.Remove( key ); - } - - action(); - } - - private static void HandleAllTasks( IDictionary< string, Action > dict ) - { - if( dict.Count < 2 ) - { - HandleOne( dict ); - } - else - { - Task[] tasks; - lock( dict ) - { - tasks = dict.Values.Select( Task.Run ).ToArray(); - dict.Clear(); - } - - Task.WaitAll( tasks ); - } - } -} \ No newline at end of file