Deal with multiple resource containers in resource manager.

This commit is contained in:
Ottermandias 2022-07-26 16:25:20 +02:00
parent 842b1c1fe5
commit 0b2b0d1beb
4 changed files with 20 additions and 13 deletions

View file

@ -16,7 +16,7 @@ public unsafe partial class ResourceLoader
{ {
// If in debug mode, this logs any resource at refcount 0 that gets decremented again, and skips the decrement instead. // If in debug mode, this logs any resource at refcount 0 that gets decremented again, and skips the decrement instead.
private delegate byte ResourceHandleDecRef( ResourceHandle* handle ); private delegate byte ResourceHandleDecRef( ResourceHandle* handle );
private readonly Hook<ResourceHandleDecRef> _decRefHook; private readonly Hook< ResourceHandleDecRef > _decRefHook;
public delegate IntPtr ResourceHandleDestructor( ResourceHandle* handle ); public delegate IntPtr ResourceHandleDestructor( ResourceHandle* handle );
@ -146,7 +146,7 @@ public unsafe partial class ResourceLoader
// Find a resource in the resource manager by its category, extension and crc-hash // Find a resource in the resource manager by its category, extension and crc-hash
public static ResourceHandle* FindResource( ResourceCategory cat, ResourceType ext, uint crc32 ) public static ResourceHandle* FindResource( ResourceCategory cat, ResourceType ext, uint crc32 )
{ {
var manager = *ResourceManager; ref var manager = ref *ResourceManager;
var catIdx = ( uint )cat >> 0x18; var catIdx = ( uint )cat >> 0x18;
cat = ( ResourceCategory )( ushort )cat; cat = ( ResourceCategory )( ushort )cat;
var category = ( ResourceGraph.CategoryContainer* )manager->ResourceGraph->ContainerArray + ( int )cat; var category = ( ResourceGraph.CategoryContainer* )manager->ResourceGraph->ContainerArray + ( int )cat;
@ -161,18 +161,25 @@ public unsafe partial class ResourceLoader
return ret == null ? null : ret->Value; return ret == null ? null : ret->Value;
} }
public delegate void ExtMapAction( ResourceCategory category, StdMap< uint, Pointer< StdMap< uint, Pointer< ResourceHandle > > > >* graph ); public delegate void ExtMapAction( ResourceCategory category, StdMap< uint, Pointer< StdMap< uint, Pointer< ResourceHandle > > > >* graph, int idx );
public delegate void ResourceMapAction( uint ext, StdMap< uint, Pointer< ResourceHandle > >* graph ); public delegate void ResourceMapAction( uint ext, StdMap< uint, Pointer< ResourceHandle > >* graph );
public delegate void ResourceAction( uint crc32, ResourceHandle* graph ); public delegate void ResourceAction( uint crc32, ResourceHandle* graph );
// Iteration functions through the resource manager. // Iteration functions through the resource manager.
public static void IterateGraphs( ExtMapAction action ) public static void IterateGraphs( ExtMapAction action )
{ {
var manager = *ResourceManager; ref var manager = ref *ResourceManager;
foreach( var resourceType in Enum.GetValues< ResourceCategory >().SkipLast( 1 ) ) foreach( var resourceType in Enum.GetValues< ResourceCategory >().SkipLast( 1 ) )
{ {
var graph = ( ResourceGraph.CategoryContainer* )manager->ResourceGraph->ContainerArray + ( int )resourceType; var graph = ( ResourceGraph.CategoryContainer* )manager->ResourceGraph->ContainerArray + ( int )resourceType;
action( resourceType, graph->MainMap ); for( var i = 0; i < 20; ++i )
{
var map = ( StdMap< uint, Pointer< StdMap< uint, Pointer< ResourceHandle > > > >* )graph->CategoryMaps[ i ];
if( map != null )
{
action( resourceType, map, i );
}
}
} }
} }
@ -184,7 +191,7 @@ public unsafe partial class ResourceLoader
public static void IterateResources( ResourceAction action ) public static void IterateResources( ResourceAction action )
{ {
IterateGraphs( ( _, extMap ) IterateGraphs( ( _, extMap, _ )
=> IterateExtMap( extMap, ( _, resourceMap ) => IterateExtMap( extMap, ( _, resourceMap )
=> IterateResourceMap( resourceMap, action ) ) ); => IterateResourceMap( resourceMap, action ) ) );
} }

View file

@ -235,7 +235,7 @@ public partial class Mod
// Recursively delete all empty directories starting from the given directory. // Recursively delete all empty directories starting from the given directory.
// Deletes inner directories first, so that a tree of empty directories is actually deleted. // Deletes inner directories first, so that a tree of empty directories is actually deleted.
private void DeleteEmptyDirectories( DirectoryInfo baseDir ) private static void DeleteEmptyDirectories( DirectoryInfo baseDir )
{ {
try try
{ {

View file

@ -564,8 +564,8 @@ public partial class ConfigWindow
// Move from one group to another by deleting, then adding the option. // Move from one group to another by deleting, then adding the option.
var sourceGroup = _dragDropGroupIdx; var sourceGroup = _dragDropGroupIdx;
var sourceOption = _dragDropOptionIdx; var sourceOption = _dragDropOptionIdx;
var option = @group[ _dragDropOptionIdx ]; var option = group[ _dragDropOptionIdx ];
var priority = @group.OptionPriority( _dragDropGroupIdx ); var priority = group.OptionPriority( _dragDropGroupIdx );
panel._delayedActions.Enqueue( () => panel._delayedActions.Enqueue( () =>
{ {
Penumbra.ModManager.DeleteOption( panel._mod, sourceGroup, sourceOption ); Penumbra.ModManager.DeleteOption( panel._mod, sourceGroup, sourceOption );

View file

@ -119,14 +119,14 @@ public partial class ConfigWindow
// Draw a full category for the resource manager. // Draw a full category for the resource manager.
private unsafe void DrawCategoryContainer( ResourceCategory category, private unsafe void DrawCategoryContainer( ResourceCategory category,
StdMap< uint, Pointer< StdMap< uint, Pointer< ResourceHandle > > > >* map ) StdMap< uint, Pointer< StdMap< uint, Pointer< ResourceHandle > > > >* map, int idx )
{ {
if( map == null ) if( map == null )
{ {
return; return;
} }
using var tree = ImRaii.TreeNode( $"({( uint )category:D2}) {category} - {map->Count}###{( uint )category}" ); using var tree = ImRaii.TreeNode( $"({( uint )category:D2}) {category} (Ex {idx}) - {map->Count}###{( uint )category}_{idx}" );
if( tree ) if( tree )
{ {
SetTableWidths(); SetTableWidths();