changes to LinkedModCollection nullability

This commit is contained in:
Stanley Dimant 2022-09-03 19:36:41 +02:00 committed by Ottermandias
parent e0000c9ef9
commit 75182d094b
3 changed files with 9 additions and 15 deletions

View file

@ -1,4 +1,4 @@
using System; using System;
using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.Game.Object;
namespace Penumbra.Collections; namespace Penumbra.Collections;
@ -6,11 +6,7 @@ namespace Penumbra.Collections;
public class LinkedModCollection public class LinkedModCollection
{ {
private IntPtr? _associatedGameObject; private IntPtr? _associatedGameObject;
public IntPtr AssociatedGameObject public IntPtr AssociatedGameObject = IntPtr.Zero;
{
get => _associatedGameObject ?? IntPtr.Zero;
set => _associatedGameObject = value;
}
public ModCollection ModCollection; public ModCollection ModCollection;
public LinkedModCollection(ModCollection modCollection) public LinkedModCollection(ModCollection modCollection)
@ -18,15 +14,13 @@ public class LinkedModCollection
ModCollection = modCollection; ModCollection = modCollection;
} }
public LinkedModCollection(IntPtr? gameObject, ModCollection collection) public LinkedModCollection(IntPtr gameObject, ModCollection collection)
{ {
AssociatedGameObject = gameObject ?? IntPtr.Zero; AssociatedGameObject = gameObject;
ModCollection = collection; ModCollection = collection;
} }
public unsafe LinkedModCollection(GameObject* gameObject, ModCollection collection) public unsafe LinkedModCollection(GameObject* gameObject, ModCollection collection) : this((IntPtr)gameObject, collection)
{ {
AssociatedGameObject = ( IntPtr )gameObject;
ModCollection = collection;
} }
} }

View file

@ -81,7 +81,7 @@ public unsafe partial class PathResolver
// Just add or remove the resolved path. // Just add or remove the resolved path.
[MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )] [MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )]
public IntPtr ResolvePath( IntPtr? gameObject, ModCollection collection, IntPtr path ) public IntPtr ResolvePath( IntPtr gameObject, ModCollection collection, IntPtr path )
{ {
if( path == IntPtr.Zero ) if( path == IntPtr.Zero )
{ {
@ -94,7 +94,7 @@ public unsafe partial class PathResolver
} }
// Special handling for paths so that we do not store non-owned temporary strings in the dictionary. // Special handling for paths so that we do not store non-owned temporary strings in the dictionary.
public void SetCollection( IntPtr? gameObject, Utf8String path, ModCollection collection ) public void SetCollection( IntPtr gameObject, Utf8String path, ModCollection collection )
{ {
if( _pathCollections.ContainsKey( path ) || path.IsOwned ) if( _pathCollections.ContainsKey( path ) || path.IsOwned )
{ {

View file

@ -227,7 +227,7 @@ public partial class PathResolver
// Implementation // Implementation
[MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )] [MethodImpl( MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization )]
private IntPtr ResolvePath( IntPtr drawObject, IntPtr path ) private IntPtr ResolvePath( IntPtr drawObject, IntPtr path )
=> _parent._paths.ResolvePath( (IntPtr?)FindParent( drawObject, out _), FindParent( drawObject, out var collection ) == null => _parent._paths.ResolvePath( (IntPtr?)FindParent( drawObject, out _) ?? IntPtr.Zero, FindParent( drawObject, out var collection ) == null
? Penumbra.CollectionManager.Default ? Penumbra.CollectionManager.Default
: collection.ModCollection, path ); : collection.ModCollection, path );
@ -251,7 +251,7 @@ public partial class PathResolver
} }
parent = FindParent( parentObject, out collection ); parent = FindParent( parentObject, out collection );
return _parent._paths.ResolvePath( (IntPtr?)parent, parent == null return _parent._paths.ResolvePath( (IntPtr?)parent ?? IntPtr.Zero, parent == null
? Penumbra.CollectionManager.Default ? Penumbra.CollectionManager.Default
: collection.ModCollection, path ); : collection.ModCollection, path );
} }