Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ThreadPersistentData Docs #284

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Scripts/Runtime/Entities/Data/IWorldUniqueID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
namespace Anvil.Unity.DOTS.Entities
{
/// <summary>
/// Provides a <see cref="World"/> unique ID
/// Provides a <see cref="World"/> unique ID.
/// This ID is unique within the current World instance.
/// This ID is not unique globally between all world instances.
mbaker3 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <typeparam name="TWorldUniqueID">The type of ID</typeparam>
public interface IWorldUniqueID<out TWorldUniqueID>
{
/// <summary>
/// The <see cref="World"/> unique ID
/// The <see cref="World"/> unique ID.
/// This ID is unique within the current World instance.
/// This ID is not unique globally between all world instances.
mbaker3 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public TWorldUniqueID WorldUniqueID { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Anvil.Unity.DOTS.Entities
{
// TODO: #283 - Devise a different name to better reflect the intended use and nature of this data type
/// <summary>
/// An <see cref="IAbstractPersistentData"/> that is owned by the overall application and
/// used to provide a unique instance of the data that persists for a thread index.
Expand All @@ -19,7 +20,7 @@ public interface IThreadPersistentData<T> : IAbstractPersistentData
/// <param name="accessor">The <see cref="ThreadPersistentDataAccessor{T}"/></param>
/// <returns>A <see cref="JobHandle"/> to wait on</returns>
public JobHandle AcquireAsync(out ThreadPersistentDataAccessor<T> accessor);

/// <summary>
/// Allows other jobs to use the underlying data for the <see cref="ThreadPersistentDataAccessor{T}"/>
/// and ensures data integrity across those other usages.
Expand All @@ -34,11 +35,11 @@ public interface IThreadPersistentData<T> : IAbstractPersistentData
/// </summary>
/// <returns>The <see cref="ThreadPersistentDataAccessor{TInstance}"/></returns>
public ThreadPersistentDataAccessor<T> Acquire();

/// <summary>
/// Allows other jobs or code to use to underlying data for the <see cref="ThreadPersistentDataAccessor{TInstance}"/>
/// and ensures data integrity across those other usages.
/// </summary>
public void Release();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

namespace Anvil.Unity.DOTS.Entities
{
// TODO: #283 - Devise a different name to better reflect the intended use and nature of this data type
internal class ThreadPersistentData<T> : AbstractTypedPersistentData<UnsafeArray<T>>,
IThreadPersistentData<T>
where T : unmanaged, IThreadPersistentDataInstance
{
public ThreadPersistentData(IDataOwner dataOwner, string uniqueContextIdentifier)
: base(
dataOwner,
new UnsafeArray<T>(ParallelAccessUtil.CollectionSizeForMaxThreads, Allocator.Persistent),
dataOwner,
new UnsafeArray<T>(ParallelAccessUtil.CollectionSizeForMaxThreads, Allocator.Persistent),
uniqueContextIdentifier)
{
ref UnsafeArray<T> data = ref Data;
Expand Down Expand Up @@ -58,4 +59,4 @@ public ThreadPersistentDataAccessor<T> Acquire()
return CreateThreadPersistentDataAccessor();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override void OnDestroy()
// INIT
//*************************************************************************************************************

// TODO: #283 - Devise a different name to better reflect the intended use and nature of this data type
public ThreadPersistentData<T> GetOrCreateThreadPersistentData<T>(string uniqueContextIdentifier)
where T : unmanaged, IThreadPersistentDataInstance
{
Expand Down Expand Up @@ -101,6 +102,7 @@ private EntityPersistentData<T> CreateEntityPersistentDataInstance<T>(IDataOwner
return new EntityPersistentData<T>(dataOwner, uniqueContextIdentifier);
}

// TODO: #283 - Devise a different name to better reflect the intended use and nature of this data type
private ThreadPersistentData<T> CreateThreadPersistentDataInstance<T>(IDataOwner dataOwner, string uniqueContextIdentifier)
where T : unmanaged, IThreadPersistentDataInstance
{
Expand All @@ -118,6 +120,7 @@ JobHandle IEntityWorldMigrationObserver.MigrateTo(JobHandle dependsOn, World des

NativeArray<JobHandle> migrationDependencies = new NativeArray<JobHandle>(m_EntityPersistentData.Count, Allocator.Temp);
int index = 0;
// TODO: #283 - Devise a different name to better reflect the intended use and nature of this data type
//We only need to migrate EntityPersistentData.
//ThreadPersistentData is global to the app and doesn't need to be migrated because no jobs or data should be in flight during migration.
foreach (KeyValuePair<DataTargetID, AbstractPersistentData> entry in m_EntityPersistentData)
Expand Down Expand Up @@ -149,4 +152,4 @@ private void Debug_EnsureOtherWorldPersistentDataSystemExists(World destinationW
}
}
}
}
}