mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Move Frameworkmanager to OtterGui.
This commit is contained in:
parent
513df2beac
commit
deb630795d
4 changed files with 9 additions and 110 deletions
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
|||
Subproject commit d018a822212a68492771db1ee6a8921df36f677d
|
||||
Subproject commit 43b78fd8dcdc12e0c2ba831bd037ad8e8a415e0e
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue