mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add pap requested event, some cleanup.
This commit is contained in:
parent
0db70c89b1
commit
ee5a21f7a2
2 changed files with 44 additions and 25 deletions
|
|
@ -16,10 +16,10 @@ public unsafe class ResourceLoader : IDisposable, IService
|
||||||
private readonly ResourceService _resources;
|
private readonly ResourceService _resources;
|
||||||
private readonly FileReadService _fileReadService;
|
private readonly FileReadService _fileReadService;
|
||||||
private readonly TexMdlService _texMdlService;
|
private readonly TexMdlService _texMdlService;
|
||||||
|
private readonly PapHandler _papHandler;
|
||||||
private readonly PapHandler _papHandler;
|
|
||||||
|
|
||||||
private ResolveData _resolvedData = ResolveData.Invalid;
|
private ResolveData _resolvedData = ResolveData.Invalid;
|
||||||
|
public event Action<Utf8GamePath>? PapRequested;
|
||||||
|
|
||||||
public ResourceLoader(ResourceService resources, FileReadService fileReadService, TexMdlService texMdlService)
|
public ResourceLoader(ResourceService resources, FileReadService fileReadService, TexMdlService texMdlService)
|
||||||
{
|
{
|
||||||
|
|
@ -36,24 +36,28 @@ public unsafe class ResourceLoader : IDisposable, IService
|
||||||
_papHandler = new PapHandler(PapResourceHandler);
|
_papHandler = new PapHandler(PapResourceHandler);
|
||||||
_papHandler.Enable();
|
_papHandler.Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int PapResourceHandler(void* self, byte* path, int length)
|
private int PapResourceHandler(void* self, byte* path, int length)
|
||||||
{
|
{
|
||||||
Utf8GamePath.FromPointer(path, out var gamePath);
|
if (!Utf8GamePath.FromPointer(path, out var gamePath))
|
||||||
|
return length;
|
||||||
|
|
||||||
var (resolvedPath, _) = _incMode.Value
|
var (resolvedPath, _) = _incMode.Value
|
||||||
? (null, ResolveData.Invalid)
|
? (null, ResolveData.Invalid)
|
||||||
: _resolvedData.Valid
|
: _resolvedData.Valid
|
||||||
? (_resolvedData.ModCollection.ResolvePath(gamePath), _resolvedData)
|
? (_resolvedData.ModCollection.ResolvePath(gamePath), _resolvedData)
|
||||||
: ResolvePath(gamePath, ResourceCategory.Chara, ResourceType.Pap);
|
: ResolvePath(gamePath, ResourceCategory.Chara, ResourceType.Pap);
|
||||||
|
|
||||||
if (!resolvedPath.HasValue || !Utf8GamePath.FromString(resolvedPath.Value.FullName, out var utf8ResolvedPath))
|
|
||||||
|
if (!resolvedPath.HasValue || !Utf8GamePath.FromByteString(resolvedPath.Value.InternalName, out var utf8ResolvedPath))
|
||||||
{
|
{
|
||||||
|
PapRequested?.Invoke(gamePath, gamePath, _resolvedData);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeMemory.Copy(utf8ResolvedPath.Path.Path, path, (nuint)utf8ResolvedPath.Length);
|
NativeMemory.Copy(utf8ResolvedPath.Path.Path, path, (nuint)utf8ResolvedPath.Length);
|
||||||
path[utf8ResolvedPath.Length] = 0;
|
path[utf8ResolvedPath.Length] = 0;
|
||||||
|
PapRequested?.Invoke(gamePath, utf8ResolvedPath, _resolvedData);
|
||||||
return utf8ResolvedPath.Length;
|
return utf8ResolvedPath.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,31 +36,47 @@ public sealed class ResourceWatcher : IDisposable, ITab, IUiService
|
||||||
private Regex? _logRegex;
|
private Regex? _logRegex;
|
||||||
private int _newMaxEntries;
|
private int _newMaxEntries;
|
||||||
|
|
||||||
public unsafe ResourceWatcher(ActorManager actors, Configuration config, ResourceService resources, ResourceLoader loader, ResourceHandleDestructor destructor)
|
public unsafe ResourceWatcher(ActorManager actors, Configuration config, ResourceService resources, ResourceLoader loader,
|
||||||
|
ResourceHandleDestructor destructor)
|
||||||
{
|
{
|
||||||
_actors = actors;
|
_actors = actors;
|
||||||
_config = config;
|
_config = config;
|
||||||
_ephemeral = config.Ephemeral;
|
_ephemeral = config.Ephemeral;
|
||||||
_resources = resources;
|
_resources = resources;
|
||||||
_destructor = destructor;
|
_destructor = destructor;
|
||||||
_loader = loader;
|
_loader = loader;
|
||||||
_table = new ResourceWatcherTable(config.Ephemeral, _records);
|
_table = new ResourceWatcherTable(config.Ephemeral, _records);
|
||||||
_resources.ResourceRequested += OnResourceRequested;
|
_resources.ResourceRequested += OnResourceRequested;
|
||||||
_destructor.Subscribe(OnResourceDestroyed, ResourceHandleDestructor.Priority.ResourceWatcher);
|
_destructor.Subscribe(OnResourceDestroyed, ResourceHandleDestructor.Priority.ResourceWatcher);
|
||||||
_loader.ResourceLoaded += OnResourceLoaded;
|
_loader.ResourceLoaded += OnResourceLoaded;
|
||||||
_loader.FileLoaded += OnFileLoaded;
|
_loader.FileLoaded += OnFileLoaded;
|
||||||
|
_loader.PapRequested += OnPapRequested;
|
||||||
UpdateFilter(_ephemeral.ResourceLoggingFilter, false);
|
UpdateFilter(_ephemeral.ResourceLoggingFilter, false);
|
||||||
_newMaxEntries = _config.MaxResourceWatcherRecords;
|
_newMaxEntries = _config.MaxResourceWatcherRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPapRequested(Utf8GamePath original)
|
||||||
|
{
|
||||||
|
if (_ephemeral.EnableResourceLogging && FilterMatch(original.Path, out var match))
|
||||||
|
Penumbra.Log.Information($"[ResourceLoader] [REQ] {match} was requested asynchronously.");
|
||||||
|
|
||||||
|
if (!_ephemeral.EnableResourceWatcher)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var record = Record.CreateRequest(original.Path, false);
|
||||||
|
if (!_ephemeral.OnlyAddMatchingResources || _table.WouldBeVisible(record))
|
||||||
|
_newRecords.Enqueue(record);
|
||||||
|
}
|
||||||
|
|
||||||
public unsafe void Dispose()
|
public unsafe void Dispose()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
_records.TrimExcess();
|
_records.TrimExcess();
|
||||||
_resources.ResourceRequested -= OnResourceRequested;
|
_resources.ResourceRequested -= OnResourceRequested;
|
||||||
_destructor.Unsubscribe(OnResourceDestroyed);
|
_destructor.Unsubscribe(OnResourceDestroyed);
|
||||||
_loader.ResourceLoaded -= OnResourceLoaded;
|
_loader.ResourceLoaded -= OnResourceLoaded;
|
||||||
_loader.FileLoaded -= OnFileLoaded;
|
_loader.FileLoaded -= OnFileLoaded;
|
||||||
|
_loader.PapRequested -= OnPapRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Clear()
|
private void Clear()
|
||||||
|
|
@ -200,8 +216,7 @@ public sealed class ResourceWatcher : IDisposable, ITab, IUiService
|
||||||
|
|
||||||
|
|
||||||
private unsafe void OnResourceRequested(ref ResourceCategory category, ref ResourceType type, ref int hash, ref Utf8GamePath path,
|
private unsafe void OnResourceRequested(ref ResourceCategory category, ref ResourceType type, ref int hash, ref Utf8GamePath path,
|
||||||
Utf8GamePath original,
|
Utf8GamePath original, GetResourceParameters* parameters, ref bool sync, ref ResourceHandle* returnValue)
|
||||||
GetResourceParameters* parameters, ref bool sync, ref ResourceHandle* returnValue)
|
|
||||||
{
|
{
|
||||||
if (_ephemeral.EnableResourceLogging && FilterMatch(original.Path, out var match))
|
if (_ephemeral.EnableResourceLogging && FilterMatch(original.Path, out var match))
|
||||||
Penumbra.Log.Information($"[ResourceLoader] [REQ] {match} was requested {(sync ? "synchronously." : "asynchronously.")}");
|
Penumbra.Log.Information($"[ResourceLoader] [REQ] {match} was requested {(sync ? "synchronously." : "asynchronously.")}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue