From bbe4a072ebf343c1eadc0e24cb4b733fb0872bd7 Mon Sep 17 00:00:00 2001 From: isaac10334 Date: Tue, 13 Feb 2024 18:20:11 -0600 Subject: [PATCH] Updated entities package to 1.2.0-pre.6 --- Assets/Scripts/Example/GameController.cs | 60 +++++-- Assets/Scripts/SoftFloat/math/float3.cs | 1 - .../SoftFloat/transforms/CompositeRotation.cs | 10 +- .../SoftFloat/transforms/CompositeScale.cs | 26 ++- .../transforms/EndFrameTransformSystems.cs | 22 +-- .../transforms/LocalToParentSystem.cs | 34 ++-- Assets/Scripts/SoftFloat/transforms/Parent.cs | 4 +- .../transforms/ParentScaleInverse.cs | 31 ++-- .../SoftFloat/transforms/ParentSystem.cs | 45 +++-- .../SoftFloat/transforms/PostRotationEuler.cs | 9 +- .../SoftFloat/transforms/RotationEuler.cs | 9 +- .../transforms/TRSToLocalToParentSystem.cs | 10 +- .../transforms/TRSToLocalToWorldSystem.cs | 71 +++++--- .../SoftFloat/transforms/WorldToLocal.cs | 14 +- .../Collision/Colliders/CompoundCollider.cs | 2 +- .../Collision/Colliders/ConvexCollider.cs | 2 +- .../Collision/Queries/Collector.cs | 3 +- .../Collision/World/CollisionWorld.cs | 8 +- .../Dynamics/Joint/Physics_Joint.cs | 2 +- .../Dynamics/World/DynamicsWorld.cs | 6 +- .../Base/Components/PhysicsJointComponents.cs | 24 +-- .../ECS/Base/Systems/BuildPhysicsWorld.cs | 135 +++++++++----- .../ECS/Base/Systems/EndFramePhysicsSystem.cs | 4 +- .../ECS/Base/Systems/ExportPhysicsWorld.cs | 71 +++++--- .../ECS/Base/Systems/StepPhysicsWorld.cs | 10 +- .../BufferInterpolatedRigidBodiesMotion.cs | 11 +- .../Systems/CopyPhysicsVelocityToSmoothing.cs | 13 +- .../Systems/RecordMostRecentFixedTime.cs | 6 +- .../SmoothRigidBodiesGraphicalMotion.cs | 19 +- .../Unity.Physics/Extensions/SafetyChecks.cs | 38 ++-- Packages/manifest.json | 23 +-- Packages/packages-lock.json | 168 +++++++----------- ProjectSettings/EntitiesClientSettings.asset | 16 ++ ProjectSettings/MemorySettings.asset | 35 ++++ ProjectSettings/MultiplayerManager.asset | 8 + ProjectSettings/ProjectVersion.txt | 4 +- 36 files changed, 540 insertions(+), 414 deletions(-) create mode 100644 ProjectSettings/EntitiesClientSettings.asset create mode 100644 ProjectSettings/MemorySettings.asset create mode 100644 ProjectSettings/MultiplayerManager.asset diff --git a/Assets/Scripts/Example/GameController.cs b/Assets/Scripts/Example/GameController.cs index 7de2720..a703fd1 100644 --- a/Assets/Scripts/Example/GameController.cs +++ b/Assets/Scripts/Example/GameController.cs @@ -7,7 +7,7 @@ using UnityS.Physics.Systems; using UnityS.Transforms; -public class GameController : SystemBase +public partial class GameController : SystemBase { public static GameController Instance; @@ -16,16 +16,15 @@ public class GameController : SystemBase private MaterialPropertyBlock matPropBlock; - protected override void OnCreate() + protected override void OnStartRunning() { base.OnCreate(); Instance = this; - UnityEngine.Physics.autoSimulation = false; - + Physics.simulationMode = SimulationMode.Script; matPropBlock = new MaterialPropertyBlock(); // setup physics parameters - World.GetOrCreateSystem().Timestep = (float)(sfloat.One / (sfloat)60.0f); + World.GetOrCreateSystemManaged().Timestep = (float)(sfloat.One / (sfloat)60.0f); Entity physicsStep = EntityManager.CreateEntity(typeof(PhysicsStep)); PhysicsStep physicsStepParams = PhysicsStep.Default; physicsStepParams.SolverStabilizationHeuristicSettings = new Solver.StabilizationHeuristicSettings @@ -50,7 +49,9 @@ protected override void OnCreate() PhysicsParams physicsParamsDynamic = PhysicsParams.Default; physicsParamsDynamic.isDynamic = true; - CreateBox(new float3(sfloat.Zero, sfloat.Zero, sfloat.Zero), new float3((sfloat)500.0f, (sfloat)2.0f, (sfloat)500.0f), quaternion.identity, material, physicsParamsStatic); + CreateBox(new float3(sfloat.Zero, sfloat.Zero, sfloat.Zero), + new float3((sfloat)500.0f, (sfloat)2.0f, (sfloat)500.0f), quaternion.identity, material, + physicsParamsStatic); sfloat radius = (sfloat)10.0f; int count = 7; @@ -111,8 +112,13 @@ private Color RandomColor() ); } - private Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference> ballColliders = new Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference>(); - public void CreateBall(float3 position, sfloat radius, UnityS.Physics.Material material, PhysicsParams physicsParams) + private Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference> + ballColliders = + new Dictionary<(sfloat radius, UnityS.Physics.Material material), + BlobAssetReference>(); + + public void CreateBall(float3 position, sfloat radius, UnityS.Physics.Material material, + PhysicsParams physicsParams) { if (!ballColliders.TryGetValue((radius, material), out BlobAssetReference collider)) { @@ -138,8 +144,13 @@ public void CreateBall(float3 position, sfloat radius, UnityS.Physics.Material m objects.Add(entity, obj); } - private Dictionary<(float3 size, UnityS.Physics.Material material), BlobAssetReference> boxColliders = new Dictionary<(float3 size, UnityS.Physics.Material material), BlobAssetReference>(); - public void CreateBox(float3 position, float3 size, quaternion rotation, UnityS.Physics.Material material, PhysicsParams physicsParams) + private Dictionary<(float3 size, UnityS.Physics.Material material), BlobAssetReference> + boxColliders = + new Dictionary<(float3 size, UnityS.Physics.Material material), + BlobAssetReference>(); + + public void CreateBox(float3 position, float3 size, quaternion rotation, UnityS.Physics.Material material, + PhysicsParams physicsParams) { if (!boxColliders.TryGetValue((size, material), out BlobAssetReference collider)) { @@ -172,14 +183,17 @@ public void CreateBox(float3 position, float3 size, quaternion rotation, UnityS. objects.Add(entity, obj); } - public Entity CreateEntity(float3 position, quaternion rotation, BlobAssetReference collider, + public Entity CreateEntity(float3 position, quaternion rotation, + BlobAssetReference collider, PhysicsParams physicsParams) { return CreatePhysicsBody(position, rotation, collider, physicsParams); } private readonly List componentTypes = new List(20); - public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation, BlobAssetReference collider, + + public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation, + BlobAssetReference collider, PhysicsParams physicsParams) { componentTypes.Clear(); @@ -207,9 +221,12 @@ public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation, if (physicsParams.isDynamic) { UnityS.Physics.Collider* colliderPtr = (UnityS.Physics.Collider*)collider.GetUnsafePtr(); - EntityManager.SetComponentData(entity, PhysicsMass.CreateDynamic(colliderPtr->MassProperties, physicsParams.mass)); + EntityManager.SetComponentData(entity, + PhysicsMass.CreateDynamic(colliderPtr->MassProperties, physicsParams.mass)); // Calculate the angular velocity in local space from rotation and world angular velocity - float3 angularVelocityLocal = math.mul(math.inverse(colliderPtr->MassProperties.MassDistribution.Transform.rot), physicsParams.startingAngularVelocity); + float3 angularVelocityLocal = + math.mul(math.inverse(colliderPtr->MassProperties.MassDistribution.Transform.rot), + physicsParams.startingAngularVelocity); EntityManager.SetComponentData(entity, new PhysicsVelocity() { Linear = physicsParams.startingLinearVelocity, @@ -228,7 +245,7 @@ public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation, [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateBefore(typeof(BuildPhysicsWorld))] -class PhysicsController : SystemBase +public partial class PhysicsController : SystemBase { private int frame = 0; @@ -265,15 +282,20 @@ protected override void OnUpdate() { if (frame >= 60 && frame % 10 == 0 && frame < 500) { - ShootBox((sfloat)0.25f, (sfloat)7.0f, new float3((sfloat)50.0f, (sfloat)20.0f, (sfloat)(-50.0f)), new float3((sfloat)(-100.0f), (sfloat)1.0f, (sfloat)100.0f)); + ShootBox((sfloat)0.25f, (sfloat)7.0f, new float3((sfloat)50.0f, (sfloat)20.0f, (sfloat)(-50.0f)), + new float3((sfloat)(-100.0f), (sfloat)1.0f, (sfloat)100.0f)); } + if (frame >= 100 && frame % 30 == 0 && frame < 900) { - ShootBall((sfloat)0.25f, (sfloat)5.0f, new float3((sfloat)0.0f, (sfloat)200.0f, (sfloat)(0.0f)), float3.zero); + ShootBall((sfloat)0.25f, (sfloat)5.0f, new float3((sfloat)0.0f, (sfloat)200.0f, (sfloat)(0.0f)), + float3.zero); } + if (frame == 720) { - ShootBall((sfloat)20.0f, (sfloat)12.0f, new float3((sfloat)50.0f, (sfloat)20.0f, (sfloat)(-50.0f)), new float3((sfloat)(-100.0f), (sfloat)1.0f, (sfloat)100.0f)); + ShootBall((sfloat)20.0f, (sfloat)12.0f, new float3((sfloat)50.0f, (sfloat)20.0f, (sfloat)(-50.0f)), + new float3((sfloat)(-100.0f), (sfloat)1.0f, (sfloat)100.0f)); } ++frame; @@ -298,4 +320,4 @@ public struct PhysicsParams linearDamping = sfloat.FromRaw(0x3c23d70a), angularDamping = sfloat.FromRaw(0x3d4ccccd) }; -} +} \ No newline at end of file diff --git a/Assets/Scripts/SoftFloat/math/float3.cs b/Assets/Scripts/SoftFloat/math/float3.cs index 17afb14..577dbe6 100644 --- a/Assets/Scripts/SoftFloat/math/float3.cs +++ b/Assets/Scripts/SoftFloat/math/float3.cs @@ -15,7 +15,6 @@ namespace UnityS.Mathematics { [DebuggerTypeProxy(typeof(float3.DebuggerProxy))] - [System.Serializable] public partial struct float3 : System.IEquatable, IFormattable { public sfloat x; diff --git a/Assets/Scripts/SoftFloat/transforms/CompositeRotation.cs b/Assets/Scripts/SoftFloat/transforms/CompositeRotation.cs index 12741cd..1de47f0 100644 --- a/Assets/Scripts/SoftFloat/transforms/CompositeRotation.cs +++ b/Assets/Scripts/SoftFloat/transforms/CompositeRotation.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -37,7 +38,7 @@ public struct RotationPivotTranslation : IComponentData } // CompositeRotation = RotationPivotTranslation * RotationPivot * Rotation * PostRotation * RotationPivot^-1 - public abstract class CompositeRotationSystem : JobComponentSystem + public abstract partial class CompositeRotationSystem : SystemBase { private EntityQuery m_Group; @@ -51,7 +52,7 @@ struct ToCompositeRotation : IJobChunk public ComponentTypeHandle CompositeRotationTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int index, int entityOffset) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { var chunkRotationPivotTranslations = chunk.GetNativeArray(RotationPivotTranslationTypeHandle); var chunkRotations = chunk.GetNativeArray(RotationTypeHandle); @@ -375,7 +376,7 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { var compositeRotationType = GetComponentTypeHandle(false); var rotationType = GetComponentTypeHandle(true); @@ -392,8 +393,7 @@ protected override JobHandle OnUpdate(JobHandle inputDeps) RotationPivotTranslationTypeHandle = rotationPivotTranslationType, LastSystemVersion = LastSystemVersion }; - var toCompositeRotationJobHandle = toCompositeRotationJob.Schedule(m_Group, inputDeps); - return toCompositeRotationJobHandle; + Dependency = toCompositeRotationJob.ScheduleParallel(m_Group, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/CompositeScale.cs b/Assets/Scripts/SoftFloat/transforms/CompositeScale.cs index 5758f59..3c38445 100644 --- a/Assets/Scripts/SoftFloat/transforms/CompositeScale.cs +++ b/Assets/Scripts/SoftFloat/transforms/CompositeScale.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -33,7 +34,7 @@ public struct ScalePivotTranslation : IComponentData // CompositeScale = ScalePivotTranslation * ScalePivot * Scale * ScalePivot^-1 // (or) CompositeScale = ScalePivotTranslation * ScalePivot * NonUniformScale * ScalePivot^-1 - public abstract class CompositeScaleSystem : JobComponentSystem + public abstract partial class CompositeScaleSystem : SystemBase { private EntityQuery m_Group; @@ -47,7 +48,7 @@ struct ToCompositeScale : IJobChunk public ComponentTypeHandle CompositeScaleTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int index, int entityOffset) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { var chunkScalePivotTranslations = chunk.GetNativeArray(ScalePivotTranslationTypeHandle); var chunkScales = chunk.GetNativeArray(ScaleTypeHandle); @@ -290,25 +291,18 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { - var compositeScaleType = GetComponentTypeHandle(false); - var scaleType = GetComponentTypeHandle(true); - var scaleAxisType = GetComponentTypeHandle(true); - var scalePivotTranslationType = GetComponentTypeHandle(true); - var scalePivotType = GetComponentTypeHandle(true); - var toCompositeScaleJob = new ToCompositeScale { - CompositeScaleTypeHandle = compositeScaleType, - NonUniformScaleTypeHandle = scaleAxisType, - ScaleTypeHandle = scaleType, - ScalePivotTypeHandle = scalePivotType, - ScalePivotTranslationTypeHandle = scalePivotTranslationType, + CompositeScaleTypeHandle = GetComponentTypeHandle(false), + NonUniformScaleTypeHandle = GetComponentTypeHandle(true), + ScaleTypeHandle = GetComponentTypeHandle(true), + ScalePivotTypeHandle = GetComponentTypeHandle(true), + ScalePivotTranslationTypeHandle = GetComponentTypeHandle(true), LastSystemVersion = LastSystemVersion }; - var toCompositeScaleJobHandle = toCompositeScaleJob.Schedule(m_Group, inputDeps); - return toCompositeScaleJobHandle; + Dependency = toCompositeScaleJob.ScheduleParallel(m_Group, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/EndFrameTransformSystems.cs b/Assets/Scripts/SoftFloat/transforms/EndFrameTransformSystems.cs index ee5bbba..2a3e8b9 100644 --- a/Assets/Scripts/SoftFloat/transforms/EndFrameTransformSystems.cs +++ b/Assets/Scripts/SoftFloat/transforms/EndFrameTransformSystems.cs @@ -3,38 +3,38 @@ namespace UnityS.Transforms { [UnityEngine.ExecuteAlways] - public class TransformSystemGroup : ComponentSystemGroup + public partial class TransformSystemGroup : ComponentSystemGroup { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] - public class EndFrameParentSystem : ParentSystem + public partial class EndFrameParentSystem : ParentSystem { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] - public class EndFrameCompositeScaleSystem : CompositeScaleSystem + public partial class EndFrameCompositeScaleSystem : CompositeScaleSystem { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] - public class EndFrameRotationEulerSystem : RotationEulerSystem + public partial class EndFrameRotationEulerSystem : RotationEulerSystem { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] - public class EndFramePostRotationEulerSystem : PostRotationEulerSystem + public partial class EndFramePostRotationEulerSystem : PostRotationEulerSystem { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] [UpdateAfter(typeof(EndFrameRotationEulerSystem))] - public class EndFrameCompositeRotationSystem : CompositeRotationSystem + public partial class EndFrameCompositeRotationSystem : CompositeRotationSystem { } @@ -43,7 +43,7 @@ public class EndFrameCompositeRotationSystem : CompositeRotationSystem [UpdateAfter(typeof(EndFrameCompositeRotationSystem))] [UpdateAfter(typeof(EndFrameCompositeScaleSystem))] [UpdateBefore(typeof(EndFrameLocalToParentSystem))] - public class EndFrameTRSToLocalToWorldSystem : TRSToLocalToWorldSystem + public partial class EndFrameTRSToLocalToWorldSystem : TRSToLocalToWorldSystem { } @@ -51,7 +51,7 @@ public class EndFrameTRSToLocalToWorldSystem : TRSToLocalToWorldSystem [UpdateInGroup(typeof(TransformSystemGroup))] [UpdateAfter(typeof(EndFrameParentSystem))] [UpdateAfter(typeof(EndFrameCompositeRotationSystem))] - public class EndFrameParentScaleInverseSystem : ParentScaleInverseSystem + public partial class EndFrameParentScaleInverseSystem : ParentScaleInverseSystem { } @@ -60,14 +60,14 @@ public class EndFrameParentScaleInverseSystem : ParentScaleInverseSystem [UpdateAfter(typeof(EndFrameCompositeRotationSystem))] [UpdateAfter(typeof(EndFrameCompositeScaleSystem))] [UpdateAfter(typeof(EndFrameParentScaleInverseSystem))] - public class EndFrameTRSToLocalToParentSystem : TRSToLocalToParentSystem + public partial class EndFrameTRSToLocalToParentSystem : TRSToLocalToParentSystem { } [UnityEngine.ExecuteAlways] [UpdateInGroup(typeof(TransformSystemGroup))] [UpdateAfter(typeof(EndFrameTRSToLocalToParentSystem))] - public class EndFrameLocalToParentSystem : LocalToParentSystem + public partial class EndFrameLocalToParentSystem : LocalToParentSystem { } @@ -75,7 +75,7 @@ public class EndFrameLocalToParentSystem : LocalToParentSystem [UpdateInGroup(typeof(TransformSystemGroup))] [UpdateAfter(typeof(EndFrameTRSToLocalToWorldSystem))] [UpdateAfter(typeof(EndFrameLocalToParentSystem))] - public class EndFrameWorldToLocalSystem : WorldToLocalSystem + public partial class EndFrameWorldToLocalSystem : WorldToLocalSystem { } } diff --git a/Assets/Scripts/SoftFloat/transforms/LocalToParentSystem.cs b/Assets/Scripts/SoftFloat/transforms/LocalToParentSystem.cs index 8e13dc0..21c84ec 100644 --- a/Assets/Scripts/SoftFloat/transforms/LocalToParentSystem.cs +++ b/Assets/Scripts/SoftFloat/transforms/LocalToParentSystem.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -8,7 +9,7 @@ namespace UnityS.Transforms { - public abstract class LocalToParentSystem : JobComponentSystem + public abstract partial class LocalToParentSystem : SystemBase { private EntityQuery m_RootsGroup; private EntityQueryMask m_LocalToWorldWriteGroupMask; @@ -19,13 +20,13 @@ struct UpdateHierarchy : IJobChunk { [ReadOnly] public ComponentTypeHandle LocalToWorldTypeHandle; [ReadOnly] public BufferTypeHandle ChildTypeHandle; - [ReadOnly] public BufferFromEntity ChildFromEntity; - [ReadOnly] public ComponentDataFromEntity LocalToParentFromEntity; + [ReadOnly] public BufferLookup ChildFromEntity; + [ReadOnly] public ComponentLookup LocalToParentFromEntity; [ReadOnly] public EntityQueryMask LocalToWorldWriteGroupMask; public uint LastSystemVersion; [NativeDisableContainerSafetyRestriction] - public ComponentDataFromEntity LocalToWorldFromEntity; + public ComponentLookup LocalToWorldFromEntity; void ChildLocalToWorld(float4x4 parentLocalToWorld, Entity entity, bool updateChildrenTransform) { @@ -34,7 +35,7 @@ void ChildLocalToWorld(float4x4 parentLocalToWorld, Entity entity, bool updateCh float4x4 localToWorldMatrix; - if (updateChildrenTransform && LocalToWorldWriteGroupMask.Matches(entity)) + if (updateChildrenTransform && LocalToWorldWriteGroupMask.MatchesIgnoreFilter(entity)) { var localToParent = LocalToParentFromEntity[entity]; localToWorldMatrix = math.mul(parentLocalToWorld, localToParent.Value); @@ -55,7 +56,7 @@ void ChildLocalToWorld(float4x4 parentLocalToWorld, Entity entity, bool updateCh } } - public void Execute(ArchetypeChunk chunk, int index, int entityOffset) + public void Execute(in ArchetypeChunk chunk, int index, bool useEnabledMask, in v128 chunkEnabledMask) { bool updateChildrenTransform = chunk.DidChange(LocalToWorldTypeHandle, LastSystemVersion) || @@ -103,26 +104,19 @@ protected override void OnCreate() })); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { - var localToWorldType = GetComponentTypeHandle(true); - var childType = GetBufferTypeHandle(true); - var childFromEntity = GetBufferFromEntity(true); - var localToParentFromEntity = GetComponentDataFromEntity(true); - var localToWorldFromEntity = GetComponentDataFromEntity(); - var updateHierarchyJob = new UpdateHierarchy { - LocalToWorldTypeHandle = localToWorldType, - ChildTypeHandle = childType, - ChildFromEntity = childFromEntity, - LocalToParentFromEntity = localToParentFromEntity, - LocalToWorldFromEntity = localToWorldFromEntity, + LocalToWorldTypeHandle = GetComponentTypeHandle(true), + ChildTypeHandle = GetBufferTypeHandle(true), + ChildFromEntity = GetBufferLookup(true), + LocalToParentFromEntity = GetComponentLookup(true), + LocalToWorldFromEntity = GetComponentLookup(), LocalToWorldWriteGroupMask = m_LocalToWorldWriteGroupMask, LastSystemVersion = LastSystemVersion }; - var updateHierarchyJobHandle = updateHierarchyJob.Schedule(m_RootsGroup, inputDeps); - return updateHierarchyJobHandle; + Dependency = updateHierarchyJob.ScheduleParallel(m_RootsGroup, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/Parent.cs b/Assets/Scripts/SoftFloat/transforms/Parent.cs index c77e2e1..ccfaef3 100644 --- a/Assets/Scripts/SoftFloat/transforms/Parent.cs +++ b/Assets/Scripts/SoftFloat/transforms/Parent.cs @@ -11,7 +11,7 @@ public struct Parent : IComponentData } [Serializable] - public struct PreviousParent : ISystemStateComponentData + public struct PreviousParent : ICleanupComponentData { public Entity Value; } @@ -19,7 +19,7 @@ public struct PreviousParent : ISystemStateComponentData [Serializable] [InternalBufferCapacity(8)] [WriteGroup(typeof(ParentScaleInverse))] - public struct Child : ISystemStateBufferElementData + public struct Child : ICleanupBufferElementData { public Entity Value; } diff --git a/Assets/Scripts/SoftFloat/transforms/ParentScaleInverse.cs b/Assets/Scripts/SoftFloat/transforms/ParentScaleInverse.cs index 69e1532..46a50c3 100644 --- a/Assets/Scripts/SoftFloat/transforms/ParentScaleInverse.cs +++ b/Assets/Scripts/SoftFloat/transforms/ParentScaleInverse.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -23,7 +24,7 @@ public struct ParentScaleInverse : IComponentData // ParentScaleInverse = Parent.CompositeScale^-1 // (or) ParentScaleInverse = Parent.Scale^-1 // (or) ParentScaleInverse = Parent.NonUniformScale^-1 - public abstract class ParentScaleInverseSystem : JobComponentSystem + public abstract partial class ParentScaleInverseSystem : SystemBase { private EntityQuery m_Group; @@ -34,10 +35,13 @@ struct ToChildParentScaleInverse : IJobChunk [ReadOnly] public ComponentTypeHandle NonUniformScaleTypeHandle; [ReadOnly] public ComponentTypeHandle CompositeScaleTypeHandle; [ReadOnly] public BufferTypeHandle ChildTypeHandle; - [NativeDisableContainerSafetyRestriction] public ComponentDataFromEntity ParentScaleInverseFromEntity; + + [NativeDisableContainerSafetyRestriction] + public ComponentLookup ParentScaleInverseFromEntity; + public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { var hasScale = chunk.Has(ScaleTypeHandle); var hasNonUniformScale = chunk.Has(NonUniformScaleTypeHandle); @@ -46,7 +50,7 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) if (hasCompositeScale) { var didChange = chunk.DidChange(CompositeScaleTypeHandle, LastSystemVersion) || - chunk.DidChange(ChildTypeHandle, LastSystemVersion); + chunk.DidChange(ChildTypeHandle, LastSystemVersion); if (!didChange) return; @@ -62,14 +66,14 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) if (!ParentScaleInverseFromEntity.HasComponent(childEntity)) continue; - ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {Value = inverseScale}; + ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse { Value = inverseScale }; } } } else if (hasScale) { var didChange = chunk.DidChange(ScaleTypeHandle, LastSystemVersion) || - chunk.DidChange(ChildTypeHandle, LastSystemVersion); + chunk.DidChange(ChildTypeHandle, LastSystemVersion); if (!didChange) return; @@ -85,14 +89,14 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) if (!ParentScaleInverseFromEntity.HasComponent(childEntity)) continue; - ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {Value = inverseScale}; + ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse { Value = inverseScale }; } } } else // if (hasNonUniformScale) { var didChange = chunk.DidChange(NonUniformScaleTypeHandle, LastSystemVersion) || - chunk.DidChange(ChildTypeHandle, LastSystemVersion); + chunk.DidChange(ChildTypeHandle, LastSystemVersion); if (!didChange) return; @@ -108,7 +112,7 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) if (!ParentScaleInverseFromEntity.HasComponent(childEntity)) continue; - ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {Value = inverseScale}; + ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse { Value = inverseScale }; } } } @@ -133,7 +137,7 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { var toParentScaleInverseJob = new ToChildParentScaleInverse { @@ -141,11 +145,10 @@ protected override JobHandle OnUpdate(JobHandle inputDeps) NonUniformScaleTypeHandle = GetComponentTypeHandle(true), CompositeScaleTypeHandle = GetComponentTypeHandle(true), ChildTypeHandle = GetBufferTypeHandle(true), - ParentScaleInverseFromEntity = GetComponentDataFromEntity(), + ParentScaleInverseFromEntity = GetComponentLookup(), LastSystemVersion = LastSystemVersion }; - var toParentScaleInverseJobHandle = toParentScaleInverseJob.Schedule(m_Group, inputDeps); - return toParentScaleInverseJobHandle; + Dependency = toParentScaleInverseJob.ScheduleParallel(m_Group, Dependency); } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/SoftFloat/transforms/ParentSystem.cs b/Assets/Scripts/SoftFloat/transforms/ParentSystem.cs index 7d1b7b2..127ce59 100644 --- a/Assets/Scripts/SoftFloat/transforms/ParentSystem.cs +++ b/Assets/Scripts/SoftFloat/transforms/ParentSystem.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -8,7 +9,7 @@ namespace UnityS.Transforms { - public abstract class ParentSystem : JobComponentSystem + public abstract partial class ParentSystem : SystemBase { EntityQuery m_NewParentsGroup; EntityQuery m_RemovedParentsGroup; @@ -48,16 +49,16 @@ void RemoveChildFromParent(Entity childEntity, Entity parentEntity) [BurstCompile] struct GatherChangedParents : IJobChunk { - public NativeMultiHashMap.ParallelWriter ParentChildrenToAdd; - public NativeMultiHashMap.ParallelWriter ParentChildrenToRemove; - public NativeHashMap.ParallelWriter UniqueParents; + public NativeParallelMultiHashMap.ParallelWriter ParentChildrenToAdd; + public NativeParallelMultiHashMap.ParallelWriter ParentChildrenToRemove; + public NativeParallelHashMap.ParallelWriter UniqueParents; public ComponentTypeHandle PreviousParentTypeHandle; [ReadOnly] public ComponentTypeHandle ParentTypeHandle; [ReadOnly] public EntityTypeHandle EntityTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { if (chunk.DidChange(ParentTypeHandle, LastSystemVersion)) { @@ -95,8 +96,8 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) [BurstCompile] struct FindMissingChild : IJob { - [ReadOnly] public NativeHashMap UniqueParents; - [ReadOnly] public BufferFromEntity ChildFromEntity; + [ReadOnly] public NativeParallelHashMap UniqueParents; + [ReadOnly] public BufferLookup ChildFromEntity; public NativeList ParentsMissingChild; public void Execute() @@ -116,11 +117,11 @@ public void Execute() [BurstCompile] struct FixupChangedChildren : IJob { - [ReadOnly] public NativeMultiHashMap ParentChildrenToAdd; - [ReadOnly] public NativeMultiHashMap ParentChildrenToRemove; - [ReadOnly] public NativeHashMap UniqueParents; + [ReadOnly] public NativeParallelMultiHashMap ParentChildrenToAdd; + [ReadOnly] public NativeParallelMultiHashMap ParentChildrenToRemove; + [ReadOnly] public NativeParallelHashMap UniqueParents; - public BufferFromEntity ChildFromEntity; + public BufferLookup ChildFromEntity; [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")] private static void ThrowChildEntityNotInParent() @@ -275,9 +276,9 @@ void UpdateChangeParents() // 2. Get (Parent,Child) to add // 3. Get unique Parent change list // 4. Set PreviousParent to new Parent - var parentChildrenToAdd = new NativeMultiHashMap(count, Allocator.TempJob); - var parentChildrenToRemove = new NativeMultiHashMap(count, Allocator.TempJob); - var uniqueParents = new NativeHashMap(count, Allocator.TempJob); + var parentChildrenToAdd = new NativeParallelMultiHashMap(count, Allocator.TempJob); + var parentChildrenToRemove = new NativeParallelMultiHashMap(count, Allocator.TempJob); + var uniqueParents = new NativeParallelHashMap(count, Allocator.TempJob); var gatherChangedParentsJob = new GatherChangedParents { ParentChildrenToAdd = parentChildrenToAdd.AsParallelWriter(), @@ -288,7 +289,7 @@ void UpdateChangeParents() EntityTypeHandle = GetEntityTypeHandle(), LastSystemVersion = LastSystemVersion }; - var gatherChangedParentsJobHandle = gatherChangedParentsJob.Schedule(m_ExistingParentsGroup); + var gatherChangedParentsJobHandle = gatherChangedParentsJob.Schedule(m_ExistingParentsGroup, Dependency); gatherChangedParentsJobHandle.Complete(); // 5. (Structural change) Add any missing Child to Parents @@ -296,7 +297,7 @@ void UpdateChangeParents() var findMissingChildJob = new FindMissingChild { UniqueParents = uniqueParents, - ChildFromEntity = GetBufferFromEntity(), + ChildFromEntity = GetBufferLookup(), ParentsMissingChild = parentsMissingChild }; var findMissingChildJobHandle = findMissingChildJob.Schedule(); @@ -311,7 +312,7 @@ void UpdateChangeParents() ParentChildrenToAdd = parentChildrenToAdd, ParentChildrenToRemove = parentChildrenToRemove, UniqueParents = uniqueParents, - ChildFromEntity = GetBufferFromEntity() + ChildFromEntity = GetBufferLookup() }; var fixupChangedChildrenJobHandle = fixupChangedChildrenJob.Schedule(); @@ -328,7 +329,7 @@ struct GatherChildEntities : IJob { public NativeArray Parents; public NativeList Children; - public BufferFromEntity ChildFromEntity; + public BufferLookup ChildFromEntity; public void Execute() { @@ -353,7 +354,7 @@ void UpdateDeletedParents() { Parents = previousParents, Children = childEntities, - ChildFromEntity = GetBufferFromEntity() + ChildFromEntity = GetBufferLookup() }; var gatherChildEntitiesJobHandle = gatherChildEntitiesJob.Schedule(); gatherChildEntitiesJobHandle.Complete(); @@ -367,10 +368,8 @@ void UpdateDeletedParents() previousParents.Dispose(); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { - inputDeps.Complete(); // #todo - k_ProfileDeletedParents.Begin(); UpdateDeletedParents(); k_ProfileDeletedParents.End(); @@ -386,8 +385,6 @@ protected override JobHandle OnUpdate(JobHandle inputDeps) k_ProfileChangeParents.Begin(); UpdateChangeParents(); k_ProfileChangeParents.End(); - - return new JobHandle(); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/PostRotationEuler.cs b/Assets/Scripts/SoftFloat/transforms/PostRotationEuler.cs index ba622b0..1093d4c 100644 --- a/Assets/Scripts/SoftFloat/transforms/PostRotationEuler.cs +++ b/Assets/Scripts/SoftFloat/transforms/PostRotationEuler.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -64,7 +65,7 @@ public struct PostRotationEulerZYX : IComponentData // (or) PostRotation = PostRotationEulerYZX // (or) PostRotation = PostRotationEulerZXY // (or) PostRotation = PostRotationEulerZYX - public abstract class PostRotationEulerSystem : JobComponentSystem + public abstract partial class PostRotationEulerSystem : SystemBase { private EntityQuery m_Group; @@ -101,7 +102,7 @@ struct PostRotationEulerToPostRotation : IJobChunk [ReadOnly] public ComponentTypeHandle PostRotationEulerZyxTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { if (chunk.Has(PostRotationEulerXyzTypeHandle)) { @@ -196,7 +197,7 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) } } - protected override JobHandle OnUpdate(JobHandle inputDependencies) + protected override void OnUpdate() { var job = new PostRotationEulerToPostRotation() { @@ -209,7 +210,7 @@ protected override JobHandle OnUpdate(JobHandle inputDependencies) PostRotationEulerZyxTypeHandle = GetComponentTypeHandle(true), LastSystemVersion = LastSystemVersion }; - return job.Schedule(m_Group, inputDependencies); + Dependency = job.ScheduleParallel(m_Group, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/RotationEuler.cs b/Assets/Scripts/SoftFloat/transforms/RotationEuler.cs index c704890..7791961 100644 --- a/Assets/Scripts/SoftFloat/transforms/RotationEuler.cs +++ b/Assets/Scripts/SoftFloat/transforms/RotationEuler.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -64,7 +65,7 @@ public struct RotationEulerZYX : IComponentData // (or) Rotation = RotationEulerYZX // (or) Rotation = RotationEulerZXY // (or) Rotation = RotationEulerZYX - public abstract class RotationEulerSystem : JobComponentSystem + public abstract partial class RotationEulerSystem : SystemBase { private EntityQuery m_Group; @@ -101,7 +102,7 @@ struct RotationEulerToRotation : IJobChunk [ReadOnly] public ComponentTypeHandle RotationEulerZyxTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { if (chunk.Has(RotationEulerXyzTypeHandle)) { @@ -196,7 +197,7 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) } } - protected override JobHandle OnUpdate(JobHandle inputDependencies) + protected override void OnUpdate() { var job = new RotationEulerToRotation() { @@ -209,7 +210,7 @@ protected override JobHandle OnUpdate(JobHandle inputDependencies) RotationEulerZyxTypeHandle = GetComponentTypeHandle(true), LastSystemVersion = LastSystemVersion }; - return job.Schedule(m_Group, inputDependencies); + Dependency = job.ScheduleParallel(m_Group, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/TRSToLocalToParentSystem.cs b/Assets/Scripts/SoftFloat/transforms/TRSToLocalToParentSystem.cs index 169290f..97921ab 100644 --- a/Assets/Scripts/SoftFloat/transforms/TRSToLocalToParentSystem.cs +++ b/Assets/Scripts/SoftFloat/transforms/TRSToLocalToParentSystem.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -29,7 +30,7 @@ namespace UnityS.Transforms // (or) LocalToParent = Translation * ParentScaleInverse * Rotation * CompositeScale // (or) LocalToParent = Translation * ParentScaleInverse * CompositeRotation * CompositeScale - public abstract class TRSToLocalToParentSystem : JobComponentSystem + public abstract partial class TRSToLocalToParentSystem : SystemBase { private EntityQuery m_Group; @@ -46,7 +47,7 @@ struct TRSToLocalToParent : IJobChunk public ComponentTypeHandle LocalToParentTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { bool changed = chunk.DidOrderChange(LastSystemVersion) || @@ -505,7 +506,7 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { var rotationType = GetComponentTypeHandle(true); var compositeRotationType = GetComponentTypeHandle(true); @@ -527,8 +528,7 @@ protected override JobHandle OnUpdate(JobHandle inputDeps) LocalToParentTypeHandle = localToWorldType, LastSystemVersion = LastSystemVersion }; - var trsToLocalToParentJobHandle = trsToLocalToParentJob.Schedule(m_Group, inputDeps); - return trsToLocalToParentJobHandle; + Dependency = trsToLocalToParentJob.ScheduleParallel(m_Group, Dependency); } } } diff --git a/Assets/Scripts/SoftFloat/transforms/TRSToLocalToWorldSystem.cs b/Assets/Scripts/SoftFloat/transforms/TRSToLocalToWorldSystem.cs index acc5d1c..11c1adc 100644 --- a/Assets/Scripts/SoftFloat/transforms/TRSToLocalToWorldSystem.cs +++ b/Assets/Scripts/SoftFloat/transforms/TRSToLocalToWorldSystem.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -22,7 +23,7 @@ namespace UnityS.Transforms // (or) LocalToWorld = Translation * CompositeRotation * Scale // (or) LocalToWorld = Translation * Rotation * CompositeScale // (or) LocalToWorld = Translation * CompositeRotation * CompositeScale - public abstract class TRSToLocalToWorldSystem : JobComponentSystem + public abstract partial class TRSToLocalToWorldSystem : SystemBase { private EntityQuery m_Group; @@ -38,7 +39,7 @@ struct TRSToLocalToWorld : IJobChunk public ComponentTypeHandle LocalToWorldTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { bool changed = chunk.DidOrderChange(LastSystemVersion) || @@ -80,7 +81,11 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) { for (int i = 0; i < count; i++) { - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); chunkLocalToWorld[i] = new LocalToWorld { @@ -106,7 +111,11 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) { for (int i = 0; i < count; i++) { - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); var translation = chunkTranslations[i].Value; chunkLocalToWorld[i] = new LocalToWorld @@ -137,7 +146,11 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) for (int i = 0; i < count; i++) { var rotation = chunkCompositeRotations[i].Value; - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); chunkLocalToWorld[i] = new LocalToWorld { @@ -166,11 +179,15 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) { var rotation = chunkCompositeRotations[i].Value; var translation = chunkTranslations[i].Value; - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); chunkLocalToWorld[i] = new LocalToWorld { - Value = math.mul(math.mul(float4x4.Translate(translation), rotation) , scale) + Value = math.mul(math.mul(float4x4.Translate(translation), rotation), scale) }; } } @@ -196,7 +213,11 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) for (int i = 0; i < count; i++) { var rotation = chunkRotations[i].Value; - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); chunkLocalToWorld[i] = new LocalToWorld { @@ -225,7 +246,11 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset) { var rotation = chunkRotations[i].Value; var translation = chunkTranslations[i].Value; - var scale = hasNonUniformScale ? float4x4.Scale(chunkNonUniformScales[i].Value) : (hasScale ? float4x4.Scale(new float3(chunkScales[i].Value)) : chunkCompositeScales[i].Value); + var scale = hasNonUniformScale + ? float4x4.Scale(chunkNonUniformScales[i].Value) + : (hasScale + ? float4x4.Scale(new float3(chunkScales[i].Value)) + : chunkCompositeScales[i].Value); chunkLocalToWorld[i] = new LocalToWorld { @@ -258,28 +283,20 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { - var rotationType = GetComponentTypeHandle(true); - var compositeRotationType = GetComponentTypeHandle(true); - var translationType = GetComponentTypeHandle(true); - var nonUniformScaleType = GetComponentTypeHandle(true); - var scaleType = GetComponentTypeHandle(true); - var compositeScaleType = GetComponentTypeHandle(true); - var localToWorldType = GetComponentTypeHandle(false); var trsToLocalToWorldJob = new TRSToLocalToWorld() { - RotationTypeHandle = rotationType, - CompositeRotationTypeHandle = compositeRotationType, - TranslationTypeHandle = translationType, - ScaleTypeHandle = scaleType, - NonUniformScaleTypeHandle = nonUniformScaleType, - CompositeScaleTypeHandle = compositeScaleType, - LocalToWorldTypeHandle = localToWorldType, + RotationTypeHandle = GetComponentTypeHandle(true), + CompositeRotationTypeHandle = GetComponentTypeHandle(true), + TranslationTypeHandle = GetComponentTypeHandle(true), + ScaleTypeHandle = GetComponentTypeHandle(true), + NonUniformScaleTypeHandle = GetComponentTypeHandle(true), + CompositeScaleTypeHandle = GetComponentTypeHandle(true), + LocalToWorldTypeHandle = GetComponentTypeHandle(false), LastSystemVersion = LastSystemVersion }; - var trsToLocalToWorldJobHandle = trsToLocalToWorldJob.Schedule(m_Group, inputDeps); - return trsToLocalToWorldJobHandle; + trsToLocalToWorldJob.ScheduleParallel(m_Group, Dependency).Complete(); } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/SoftFloat/transforms/WorldToLocal.cs b/Assets/Scripts/SoftFloat/transforms/WorldToLocal.cs index 0b778d2..6ace25b 100644 --- a/Assets/Scripts/SoftFloat/transforms/WorldToLocal.cs +++ b/Assets/Scripts/SoftFloat/transforms/WorldToLocal.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -18,7 +19,7 @@ public struct WorldToLocal : IComponentData public float3 Position => new float3(Value.c3.x, Value.c3.y, Value.c3.z); } - public abstract class WorldToLocalSystem : JobComponentSystem + public abstract partial class WorldToLocalSystem : SystemBase { private EntityQuery m_Group; @@ -29,7 +30,7 @@ struct ToWorldToLocal : IJobChunk public ComponentTypeHandle WorldToLocalTypeHandle; public uint LastSystemVersion; - public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk chunk, int chunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) { if (!chunk.DidChange(LocalToWorldTypeHandle, LastSystemVersion)) return; @@ -40,7 +41,7 @@ public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) for (int i = 0; i < chunk.Count; i++) { var localToWorld = chunkLocalToWorld[i].Value; - chunkWorldToLocal[i] = new WorldToLocal {Value = math.inverse(localToWorld)}; + chunkWorldToLocal[i] = new WorldToLocal { Value = math.inverse(localToWorld) }; } } } @@ -58,7 +59,7 @@ protected override void OnCreate() }); } - protected override JobHandle OnUpdate(JobHandle inputDeps) + protected override void OnUpdate() { var toWorldToLocalJob = new ToWorldToLocal { @@ -66,8 +67,7 @@ protected override JobHandle OnUpdate(JobHandle inputDeps) WorldToLocalTypeHandle = GetComponentTypeHandle(), LastSystemVersion = LastSystemVersion }; - var toWorldToLocalJobHandle = toWorldToLocalJob.Schedule(m_Group, inputDeps); - return toWorldToLocalJobHandle; + Dependency = toWorldToLocalJob.ScheduleParallel(m_Group, this.Dependency); } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/CompoundCollider.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/CompoundCollider.cs index 7099d50..bb88665 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/CompoundCollider.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/CompoundCollider.cs @@ -76,7 +76,7 @@ public static unsafe BlobAssetReference Create(NativeArray()); CollisionFilter filter = children[0].Collider.Value.Filter; - var srcToDestInstanceAddrs = new NativeHashMap(children.Length, Allocator.Temp); + var srcToDestInstanceAddrs = new NativeParallelHashMap(children.Length, Allocator.Temp); for (var childIndex = 0; childIndex < children.Length; childIndex++) { var child = children[childIndex]; diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/ConvexCollider.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/ConvexCollider.cs index 2e9cfa5..b03f2a5 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/ConvexCollider.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Colliders/ConvexCollider.cs @@ -255,7 +255,7 @@ public TempHull(ref ConvexHullBuilder builder) { case 3: { - var edgeMap = new NativeHashMap(builder.NumFaceVertices, Allocator.Temp); + var edgeMap = new NativeParallelHashMap(builder.NumFaceVertices, Allocator.Temp); for (ConvexHullBuilder.FaceEdge hullFace = builder.GetFirstFace(); hullFace.IsValid; hullFace = builder.GetNextFace(hullFace)) { // Store the plane diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Queries/Collector.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Queries/Collector.cs index d0f2760..a5047c1 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Queries/Collector.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/Queries/Collector.cs @@ -1,3 +1,4 @@ +using System; using Unity.Collections; using Unity.Entities; using UnityEngine.Assertions; @@ -135,7 +136,7 @@ public bool AddHit(T hit) } // A collector which stores every hit. - public struct AllHitsCollector : ICollector where T : struct, IQueryResult + public struct AllHitsCollector : ICollector where T : unmanaged, IQueryResult { public bool EarlyOutOnFirstHit => false; public sfloat MaxFraction { get; } diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/World/CollisionWorld.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/World/CollisionWorld.cs index c464fc6..725ffef 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/World/CollisionWorld.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Collision/World/CollisionWorld.cs @@ -18,7 +18,7 @@ public struct CollisionWorld : ICollidable, IDisposable { [NoAlias] private NativeArray m_Bodies; // storage for all the rigid bodies [NoAlias] internal Broadphase Broadphase; // bounding volume hierarchies around subsets of the rigid bodies - [NoAlias] internal NativeHashMap EntityBodyIndexMap; + [NoAlias] internal NativeParallelHashMap EntityBodyIndexMap; public int NumBodies => Broadphase.NumStaticBodies + Broadphase.NumDynamicBodies; public int NumStaticBodies => Broadphase.NumStaticBodies; @@ -36,14 +36,14 @@ public CollisionWorld(int numStaticBodies, int numDynamicBodies) { m_Bodies = new NativeArray(numStaticBodies + numDynamicBodies, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); Broadphase = new Broadphase(numStaticBodies, numDynamicBodies); - EntityBodyIndexMap = new NativeHashMap(m_Bodies.Length, Allocator.Persistent); + EntityBodyIndexMap = new NativeParallelHashMap(m_Bodies.Length, Allocator.Persistent); } internal CollisionWorld(NativeArray bodies, Broadphase broadphase) { m_Bodies = bodies; Broadphase = broadphase; - EntityBodyIndexMap = new NativeHashMap(m_Bodies.Length, Allocator.Persistent); + EntityBodyIndexMap = new NativeParallelHashMap(m_Bodies.Length, Allocator.Persistent); } public void Reset(int numStaticBodies, int numDynamicBodies) @@ -85,7 +85,7 @@ public CollisionWorld Clone() { m_Bodies = new NativeArray(m_Bodies, Allocator.Persistent), Broadphase = (Broadphase)Broadphase.Clone(), - EntityBodyIndexMap = new NativeHashMap(m_Bodies.Length, Allocator.Persistent), + EntityBodyIndexMap = new NativeParallelHashMap(m_Bodies.Length, Allocator.Persistent), }; clone.UpdateBodyIndexMap(); return clone; diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/Joint/Physics_Joint.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/Joint/Physics_Joint.cs index cce827f..84142ab 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/Joint/Physics_Joint.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/Joint/Physics_Joint.cs @@ -272,7 +272,7 @@ public struct Joint public MTransform AFromJoint; public MTransform BFromJoint; // Note that Constraints needs to be 4-byte aligned for Android 32. - public FixedList128 Constraints; + public FixedList128Bytes Constraints; public byte EnableCollision; // If non-zero, allows these bodies to collide public byte Version; diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/World/DynamicsWorld.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/World/DynamicsWorld.cs index 7bf8204..8448c64 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/World/DynamicsWorld.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Dynamics/World/DynamicsWorld.cs @@ -18,7 +18,7 @@ public struct DynamicsWorld : IDisposable [NoAlias] private NativeArray m_Joints; private int m_NumJoints; // number of joints currently in use - [NoAlias] internal NativeHashMap EntityJointIndexMap; + [NoAlias] internal NativeParallelHashMap EntityJointIndexMap; public NativeArray MotionDatas => m_MotionDatas.GetSubArray(0, m_NumMotions); public NativeArray MotionVelocities => m_MotionVelocities.GetSubArray(0, m_NumMotions); @@ -38,7 +38,7 @@ public DynamicsWorld(int numMotions, int numJoints) m_Joints = new NativeArray(numJoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); m_NumJoints = numJoints; - EntityJointIndexMap = new NativeHashMap(numJoints, Allocator.Persistent); + EntityJointIndexMap = new NativeParallelHashMap(numJoints, Allocator.Persistent); } public void Reset(int numMotions, int numJoints) @@ -84,7 +84,7 @@ public DynamicsWorld Clone() m_NumMotions = m_NumMotions, m_Joints = new NativeArray(m_Joints.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), m_NumJoints = m_NumJoints, - EntityJointIndexMap = new NativeHashMap(m_Joints.Length, Allocator.Persistent), + EntityJointIndexMap = new NativeParallelHashMap(m_Joints.Length, Allocator.Persistent), }; clone.m_MotionDatas.CopyFrom(m_MotionDatas); clone.m_MotionVelocities.CopyFrom(m_MotionVelocities); diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Components/PhysicsJointComponents.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Components/PhysicsJointComponents.cs index c3e7d2a..0a48ea7 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Components/PhysicsJointComponents.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Components/PhysicsJointComponents.cs @@ -120,7 +120,7 @@ public struct PhysicsJoint : IComponentData BodyFrame m_BodyBFromJoint; byte m_Version; JointType m_JointType; - FixedList128 m_Constraints; + FixedList128Bytes m_Constraints; /// /// The anchor point and orientation in the space of the first body. @@ -197,13 +197,13 @@ public JointType JointType /// /// Get the sequence of atoms to apply between the two bodies. /// - public FixedList128 GetConstraints() => m_Constraints; + public FixedList128Bytes GetConstraints() => m_Constraints; /// /// Set the sequence of atoms to apply between the two bodies. /// /// A sequence of atoms to apply in order. - public void SetConstraints(FixedList128 constraints) + public void SetConstraints(FixedList128Bytes constraints) { for (var i = 0; i < constraints.Length; ++i) { @@ -235,7 +235,7 @@ public static PhysicsJoint CreateBallAndSocket(float3 anchorA, float3 anchorB) BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.BallAndSocket, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 1, [0] = Constraint.BallAndSocket(Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping) @@ -254,7 +254,7 @@ public static PhysicsJoint CreateFixed(BodyFrame bodyAFromJoint, BodyFrame bodyB BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.Fixed, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 2, [0] = Constraint.BallAndSocket(Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -273,7 +273,7 @@ public static PhysicsJoint CreateHinge(BodyFrame bodyAFromJoint, BodyFrame bodyB BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.Hinge, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 2, [0] = Constraint.Hinge(0, Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -300,7 +300,7 @@ public static PhysicsJoint CreateLimitedDistance(float3 anchorA, float3 anchorB, BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.LimitedDistance, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 1, [k_LimitedDistanceRangeIndex] = Constraint.LimitedDistance(distanceRange.Sorted(), Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping) @@ -324,7 +324,7 @@ public static PhysicsJoint CreateLimitedHinge( BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.LimitedHinge, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 3, [k_LimitedHingeRangeIndex] = Constraint.Twist(0, angularRange.Sorted(), Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -349,7 +349,7 @@ public static PhysicsJoint CreatePrismatic( BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.Prismatic, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 3, [0] = Constraint.FixedAngle(Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -385,7 +385,7 @@ public static void CreateRagdoll( BodyAFromJoint = bodyAFromJoint, BodyBFromJoint = bodyBFromJoint, m_JointType = JointType.RagdollPrimaryCone, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 2, [k_RagdollPrimaryTwistRangeIndex] = Constraint.Twist(0, math.clamp(angularTwistRange.Sorted(), new float2(-math.PI), new float2(math.PI)), Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -403,7 +403,7 @@ public static void CreateRagdoll( Position = bodyBFromJoint.Position }, m_JointType = JointType.RagdollPerpendicularCone, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 2, [k_RagdollPerpendicularRangeIndex] = Constraint.Cone(0, math.clamp(angularPlaneRange.Sorted() + new float2(sfloat.FromRaw(0x3fc90fdb)), new float2(sfloat.Zero), new float2(math.PI)), Constraint.DefaultSpringFrequency, Constraint.DefaultSpringDamping), @@ -428,7 +428,7 @@ public static PhysicsJoint CreateLimitedDOF(RigidTransform offset, bool3 linearL BodyAFromJoint = BodyFrame.Identity, BodyBFromJoint = offset, m_JointType = JointType.LimitedDegreeOfFreedom, - m_Constraints = new FixedList128 + m_Constraints = new FixedList128Bytes { Length = 2, [k_LimitedDOFLinearIndex] = new Constraint diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/BuildPhysicsWorld.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/BuildPhysicsWorld.cs index 7cd1b42..8bef848 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/BuildPhysicsWorld.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/BuildPhysicsWorld.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -14,7 +15,7 @@ namespace UnityS.Physics.Systems // and a joint for every entity which has a joint component. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [AlwaysUpdateSystem] - public class BuildPhysicsWorld : SystemBase, IPhysicsSystem + public partial class BuildPhysicsWorld : SystemBase, IPhysicsSystem { private JobHandle m_InputDependencyToComplete; private JobHandle m_InputDependency; @@ -34,7 +35,8 @@ public class BuildPhysicsWorld : SystemBase, IPhysicsSystem StepPhysicsWorld m_StepPhysicsWorldSystem; #if ENABLE_UNITY_COLLECTIONS_CHECKS - internal NativeHashMap IntegrityCheckMap = new NativeHashMap(4, Allocator.Persistent); + internal NativeParallelHashMap IntegrityCheckMap = + new NativeParallelHashMap(4, Allocator.Persistent); #endif protected override void OnCreate() @@ -89,7 +91,7 @@ protected override void OnCreate() CollisionWorldProxyGroup = GetEntityQuery(ComponentType.ReadWrite()); - m_StepPhysicsWorldSystem = World.GetOrCreateSystem(); + m_StepPhysicsWorldSystem = World.GetOrCreateSystemManaged(); } protected override void OnDestroy() @@ -180,7 +182,7 @@ protected override void OnUpdate() PhysicsColliderType = physicsColliderType, m_LastSystemVersion = LastSystemVersion, Result = HaveStaticBodiesChanged - }.ScheduleParallel(StaticEntityGroup, 1, Dependency); + }.ScheduleParallel(StaticEntityGroup, Dependency); } } @@ -203,8 +205,13 @@ protected override void OnUpdate() // between dynamic bodies and their motions. if (numDynamicBodies > 0) { + var chunkBaseEntityIndices = DynamicEntityGroup.CalculateBaseEntityIndexArrayAsync( + this.World.UpdateAllocator.ToAllocator, + Dependency, out JobHandle indexArrayGen); + Dependency = indexArrayGen; jobHandles.Add(new Jobs.CreateRigidBodies { + ChunkBaseEntityIndices = chunkBaseEntityIndices, EntityType = entityType, LocalToWorldType = localToWorldType, ParentType = parentType, @@ -216,10 +223,15 @@ protected override void OnUpdate() FirstBodyIndex = 0, RigidBodies = PhysicsWorld.Bodies, EntityBodyIndexMap = PhysicsWorld.CollisionWorld.EntityBodyIndexMap.AsParallelWriter(), - }.ScheduleParallel(DynamicEntityGroup, 1, Dependency)); + }.ScheduleParallel(DynamicEntityGroup, Dependency)); + var chunkBaseEntityIndices2 = DynamicEntityGroup.CalculateBaseEntityIndexArrayAsync( + this.World.UpdateAllocator.ToAllocator, + Dependency, out JobHandle dep2); + Dependency = dep2; jobHandles.Add(new Jobs.CreateMotions { + ChunkBaseEntityIndices = chunkBaseEntityIndices2, PositionType = positionType, RotationType = rotationType, PhysicsVelocityType = physicsVelocityType, @@ -230,15 +242,21 @@ protected override void OnUpdate() MotionDatas = PhysicsWorld.MotionDatas, MotionVelocities = PhysicsWorld.MotionVelocities - }.ScheduleParallel(DynamicEntityGroup, 1, Dependency)); + }.ScheduleParallel(DynamicEntityGroup, Dependency)); } // Now, schedule creation of static bodies, with FirstBodyIndex pointing after // the dynamic and kinematic bodies if (numStaticBodies > 0) { + var indices = StaticEntityGroup.CalculateBaseEntityIndexArrayAsync( + this.World.UpdateAllocator.ToAllocator, + Dependency, out JobHandle indexArrayGen); + Dependency = indexArrayGen; + jobHandles.Add(new Jobs.CreateRigidBodies { + ChunkBaseEntityIndices = indices, EntityType = entityType, LocalToWorldType = localToWorldType, ParentType = parentType, @@ -250,7 +268,7 @@ protected override void OnUpdate() FirstBodyIndex = numDynamicBodies, RigidBodies = PhysicsWorld.Bodies, EntityBodyIndexMap = PhysicsWorld.CollisionWorld.EntityBodyIndexMap.AsParallelWriter(), - }.ScheduleParallel(StaticEntityGroup, 1, Dependency)); + }.ScheduleParallel(StaticEntityGroup, Dependency)); } var handle = JobHandle.CombineDependencies(jobHandles); @@ -259,8 +277,14 @@ protected override void OnUpdate() // Build joints if (numJoints > 0) { + var chunkBaseEntityIndices2 = JointEntityGroup.CalculateBaseEntityIndexArrayAsync( + this.World.UpdateAllocator.ToAllocator, + handle, out JobHandle dep2); + handle = dep2; + jobHandles.Add(new Jobs.CreateJoints { + ChunkBaseEntityIndices = chunkBaseEntityIndices2, ConstrainedBodyPairComponentType = physicsConstrainedBodyPairType, JointComponentType = physicsJointType, EntityType = entityType, @@ -270,12 +294,12 @@ protected override void OnUpdate() NumDynamicBodies = numDynamicBodies, EntityBodyIndexMap = PhysicsWorld.CollisionWorld.EntityBodyIndexMap, EntityJointIndexMap = PhysicsWorld.DynamicsWorld.EntityJointIndexMap.AsParallelWriter(), - }.ScheduleParallel(JointEntityGroup, 1, handle)); + }.ScheduleParallel(JointEntityGroup, handle)); } // Build the broadphase // TODO: could optimize this by gathering the AABBs and filters at the same time as building the bodies above - sfloat timeStep = (sfloat)Time.DeltaTime; + sfloat timeStep = (sfloat)SystemAPI.Time.DeltaTime; PhysicsStep stepComponent = PhysicsStep.Default; if (HasSingleton()) @@ -300,7 +324,8 @@ protected override void OnUpdate() public void AddInputDependencyToComplete(JobHandle dependencyToComplete) { - m_InputDependencyToComplete = JobHandle.CombineDependencies(m_InputDependencyToComplete, dependencyToComplete); + m_InputDependencyToComplete = + JobHandle.CombineDependencies(m_InputDependencyToComplete, dependencyToComplete); } public void AddInputDependency(JobHandle inputDep) @@ -331,7 +356,7 @@ private void ChainDependencies() private static class Jobs { [BurstCompile] - internal struct CheckStaticBodyChangesJob : IJobEntityBatch + internal struct CheckStaticBodyChangesJob : IJobChunk { [ReadOnly] public ComponentTypeHandle LocalToWorldType; [ReadOnly] public ComponentTypeHandle ParentType; @@ -339,12 +364,11 @@ internal struct CheckStaticBodyChangesJob : IJobEntityBatch [ReadOnly] public ComponentTypeHandle RotationType; [ReadOnly] public ComponentTypeHandle PhysicsColliderType; - [NativeDisableParallelForRestriction] - public NativeArray Result; + [NativeDisableParallelForRestriction] public NativeArray Result; public uint m_LastSystemVersion; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { bool didBatchChange = batchInChunk.DidChange(LocalToWorldType, m_LastSystemVersion) || @@ -368,10 +392,11 @@ internal struct CreateDefaultStaticRigidBody : IJob { [NativeDisableContainerSafetyRestriction] public NativeArray NativeBodies; + public int BodyIndex; [NativeDisableContainerSafetyRestriction] - public NativeHashMap.ParallelWriter EntityBodyIndexMap; + public NativeParallelHashMap.ParallelWriter EntityBodyIndexMap; public void Execute() { @@ -387,8 +412,9 @@ public void Execute() } [BurstCompile] - internal struct CreateRigidBodies : IJobEntityBatchWithIndex + internal struct CreateRigidBodies : IJobChunk { + [ReadOnly] public NativeArray ChunkBaseEntityIndices; [ReadOnly] public EntityTypeHandle EntityType; [ReadOnly] public ComponentTypeHandle LocalToWorldType; [ReadOnly] public ComponentTypeHandle ParentType; @@ -398,12 +424,17 @@ internal struct CreateRigidBodies : IJobEntityBatchWithIndex [ReadOnly] public ComponentTypeHandle PhysicsCustomTagsType; [ReadOnly] public int FirstBodyIndex; - [NativeDisableContainerSafetyRestriction] public NativeArray RigidBodies; - [NativeDisableContainerSafetyRestriction] public NativeHashMap.ParallelWriter EntityBodyIndexMap; + [NativeDisableContainerSafetyRestriction] + public NativeArray RigidBodies; + + [NativeDisableContainerSafetyRestriction] + public NativeParallelHashMap.ParallelWriter EntityBodyIndexMap; //public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) - public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { + int firstEntityIndex = ChunkBaseEntityIndices[batchIndex]; + NativeArray chunkColliders = batchInChunk.GetNativeArray(PhysicsColliderType); NativeArray chunkLocalToWorlds = batchInChunk.GetNativeArray(LocalToWorldType); NativeArray chunkPositions = batchInChunk.GetNativeArray(PositionType); @@ -469,8 +500,9 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntity } [BurstCompile] - internal struct CreateMotions : IJobEntityBatchWithIndex + internal struct CreateMotions : IJobChunk { + [ReadOnly] public NativeArray ChunkBaseEntityIndices; [ReadOnly] public ComponentTypeHandle PositionType; [ReadOnly] public ComponentTypeHandle RotationType; [ReadOnly] public ComponentTypeHandle PhysicsVelocityType; @@ -482,15 +514,18 @@ internal struct CreateMotions : IJobEntityBatchWithIndex [NativeDisableParallelForRestriction] public NativeArray MotionDatas; [NativeDisableParallelForRestriction] public NativeArray MotionVelocities; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { + int firstEntityIndex = ChunkBaseEntityIndices[batchIndex]; NativeArray chunkPositions = batchInChunk.GetNativeArray(PositionType); NativeArray chunkRotations = batchInChunk.GetNativeArray(RotationType); NativeArray chunkVelocities = batchInChunk.GetNativeArray(PhysicsVelocityType); NativeArray chunkMasses = batchInChunk.GetNativeArray(PhysicsMassType); - NativeArray chunkMassOverrides = batchInChunk.GetNativeArray(PhysicsMassOverrideType); + NativeArray chunkMassOverrides = + batchInChunk.GetNativeArray(PhysicsMassOverrideType); NativeArray chunkDampings = batchInChunk.GetNativeArray(PhysicsDampingType); - NativeArray chunkGravityFactors = batchInChunk.GetNativeArray(PhysicsGravityFactorType); + NativeArray chunkGravityFactors = + batchInChunk.GetNativeArray(PhysicsGravityFactorType); int motionStart = firstEntityIndex; int instanceCount = batchInChunk.Count; @@ -517,15 +552,21 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntity for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++) { - var isKinematic = !hasChunkPhysicsMassType || hasChunkPhysicsMassOverrideType && chunkMassOverrides[i].IsKinematic != 0; + var isKinematic = !hasChunkPhysicsMassType || + hasChunkPhysicsMassOverrideType && chunkMassOverrides[i].IsKinematic != 0; MotionVelocities[motionIndex] = new MotionVelocity { LinearVelocity = chunkVelocities[i].Linear, AngularVelocity = chunkVelocities[i].Angular, - InverseInertia = isKinematic ? defaultPhysicsMass.InverseInertia : chunkMasses[i].InverseInertia, + InverseInertia = isKinematic + ? defaultPhysicsMass.InverseInertia + : chunkMasses[i].InverseInertia, InverseMass = isKinematic ? defaultPhysicsMass.InverseMass : chunkMasses[i].InverseMass, - AngularExpansionFactor = hasChunkPhysicsMassType ? chunkMasses[i].AngularExpansionFactor : defaultPhysicsMass.AngularExpansionFactor, - GravityFactor = isKinematic ? sfloat.Zero : hasChunkPhysicsGravityFactorType ? chunkGravityFactors[i].Value : defaultGravityFactor + AngularExpansionFactor = hasChunkPhysicsMassType + ? chunkMasses[i].AngularExpansionFactor + : defaultPhysicsMass.AngularExpansionFactor, + GravityFactor = isKinematic ? sfloat.Zero : + hasChunkPhysicsGravityFactorType ? chunkGravityFactors[i].Value : defaultGravityFactor }; } @@ -547,7 +588,7 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntity WorldFromMotion = new RigidTransform( math.mul(chunkRotations[i].Value, mass.InertiaOrientation), math.rotate(chunkRotations[i].Value, mass.CenterOfMass) + chunkPositions[i].Value - ), + ), BodyFromMotion = new RigidTransform(mass.InertiaOrientation, mass.CenterOfMass), LinearDamping = damping.Linear, AngularDamping = damping.Angular @@ -557,23 +598,29 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntity } [BurstCompile] - internal struct CreateJoints : IJobEntityBatchWithIndex + internal struct CreateJoints : IJobChunk { + [ReadOnly] public NativeArray ChunkBaseEntityIndices; [ReadOnly] public ComponentTypeHandle ConstrainedBodyPairComponentType; [ReadOnly] public ComponentTypeHandle JointComponentType; [ReadOnly] public EntityTypeHandle EntityType; [ReadOnly] public NativeArray RigidBodies; [ReadOnly] public int NumDynamicBodies; - [ReadOnly] public NativeHashMap EntityBodyIndexMap; + [ReadOnly] public NativeParallelHashMap EntityBodyIndexMap; [NativeDisableParallelForRestriction] public NativeArray Joints; - [NativeDisableParallelForRestriction] public NativeHashMap.ParallelWriter EntityJointIndexMap; + + [NativeDisableParallelForRestriction] + public NativeParallelHashMap.ParallelWriter EntityJointIndexMap; public int DefaultStaticBodyIndex; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntityIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { - NativeArray chunkBodyPair = batchInChunk.GetNativeArray(ConstrainedBodyPairComponentType); + int firstEntityIndex = ChunkBaseEntityIndices[batchIndex]; + + NativeArray chunkBodyPair = + batchInChunk.GetNativeArray(ConstrainedBodyPairComponentType); NativeArray chunkJoint = batchInChunk.GetNativeArray(JointComponentType); NativeArray chunkEntities = batchInChunk.GetNativeArray(EntityType); @@ -631,16 +678,17 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int firstEntity #region Integrity checks [BurstCompile] - internal struct RecordDynamicBodyIntegrity : IJobEntityBatch + internal struct RecordDynamicBodyIntegrity : IJobChunk { [ReadOnly] public ComponentTypeHandle PositionType; [ReadOnly] public ComponentTypeHandle RotationType; [ReadOnly] public ComponentTypeHandle PhysicsVelocityType; [ReadOnly] public ComponentTypeHandle PhysicsColliderType; - public NativeHashMap IntegrityCheckMap; + public NativeParallelHashMap IntegrityCheckMap; - internal static void AddOrIncrement(NativeHashMap integrityCheckMap, uint systemVersion) + internal static void AddOrIncrement(NativeParallelHashMap integrityCheckMap, + uint systemVersion) { if (integrityCheckMap.TryGetValue(systemVersion, out long occurences)) { @@ -653,7 +701,7 @@ internal static void AddOrIncrement(NativeHashMap integrityCheckMap, } } - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { AddOrIncrement(IntegrityCheckMap, batchInChunk.GetOrderVersion()); AddOrIncrement(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsVelocityType)); @@ -661,10 +709,12 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) { AddOrIncrement(IntegrityCheckMap, batchInChunk.GetChangeVersion(PositionType)); } + if (batchInChunk.Has(RotationType)) { AddOrIncrement(IntegrityCheckMap, batchInChunk.GetChangeVersion(RotationType)); } + if (batchInChunk.Has(PhysicsColliderType)) { AddOrIncrement(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsColliderType)); @@ -673,16 +723,17 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) } [BurstCompile] - internal struct RecordColliderIntegrity : IJobEntityBatch + internal struct RecordColliderIntegrity : IJobChunk { [ReadOnly] public ComponentTypeHandle PhysicsColliderType; - public NativeHashMap IntegrityCheckMap; + public NativeParallelHashMap IntegrityCheckMap; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { if (batchInChunk.Has(PhysicsColliderType)) { - RecordDynamicBodyIntegrity.AddOrIncrement(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsColliderType)); + RecordDynamicBodyIntegrity.AddOrIncrement(IntegrityCheckMap, + batchInChunk.GetChangeVersion(PhysicsColliderType)); } } } @@ -694,7 +745,7 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) #region Integrity checks - internal void RecordIntegrity(NativeHashMap integrityCheckMap) + internal void RecordIntegrity(NativeParallelHashMap integrityCheckMap) { var positionType = GetComponentTypeHandle(true); var rotationType = GetComponentTypeHandle(true); diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/EndFramePhysicsSystem.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/EndFramePhysicsSystem.cs index b469b88..fad3434 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/EndFramePhysicsSystem.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/EndFramePhysicsSystem.cs @@ -7,7 +7,7 @@ namespace UnityS.Physics.Systems // so that any system which depends on all physics work to be finished can just depend on this single handle. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateAfter(typeof(StepPhysicsWorld)), UpdateAfter(typeof(ExportPhysicsWorld))] - public class EndFramePhysicsSystem : SystemBase, IPhysicsSystem + public partial class EndFramePhysicsSystem : SystemBase, IPhysicsSystem { private JobHandle m_InputDependency; private JobHandle m_OutputDependency; @@ -18,7 +18,7 @@ protected override void OnCreate() { m_OutputDependency = Dependency; - m_BuildPhysicsWorldSystem = World.GetOrCreateSystem(); + m_BuildPhysicsWorldSystem = World.GetOrCreateSystemManaged(); } protected override void OnDestroy() diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs index 449e7fa..065c459 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/ExportPhysicsWorld.cs @@ -1,5 +1,6 @@ using System; using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -12,7 +13,7 @@ namespace UnityS.Physics.Systems // A system which copies transforms and velocities from the physics world back to the original entity components. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(StepPhysicsWorld)), UpdateBefore(typeof(EndFramePhysicsSystem))] - public class ExportPhysicsWorld : SystemBase, IPhysicsSystem + public partial class ExportPhysicsWorld : SystemBase, IPhysicsSystem { private JobHandle m_InputDependency; private JobHandle m_OutputDependency; @@ -22,13 +23,14 @@ public class ExportPhysicsWorld : SystemBase, IPhysicsSystem internal unsafe struct SharedData : IDisposable { - [NativeDisableUnsafePtrRestriction] - public AtomicSafetyManager* SafetyManager; + [NativeDisableUnsafePtrRestriction] public AtomicSafetyManager* SafetyManager; public static SharedData Create() { var sharedData = new SharedData(); - sharedData.SafetyManager = (AtomicSafetyManager*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf(), 16, Allocator.Persistent); + sharedData.SafetyManager = + (AtomicSafetyManager*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf(), 16, + Allocator.Persistent); *sharedData.SafetyManager = AtomicSafetyManager.Create(); return sharedData; @@ -49,8 +51,8 @@ public void Sync() protected override void OnCreate() { - m_BuildPhysicsWorldSystem = World.GetOrCreateSystem(); - m_EndFramePhysicsSystem = World.GetOrCreateSystem(); + m_BuildPhysicsWorldSystem = World.GetOrCreateSystemManaged(); + m_EndFramePhysicsSystem = World.GetOrCreateSystemManaged(); m_SharedData = SharedData.Create(); @@ -81,15 +83,22 @@ protected override void OnUpdate() var rotationType = GetComponentTypeHandle(); var velocityType = GetComponentTypeHandle(); + var chunkBaseEntityIndices2 = + m_BuildPhysicsWorldSystem.DynamicEntityGroup.CalculateBaseEntityIndexArrayAsync( + this.World.UpdateAllocator.ToAllocator, + handle, out JobHandle handleWithEntityIndicesCalculation); + handle = handleWithEntityIndicesCalculation; + handle = new ExportDynamicBodiesJob { + ChunkBaseEntityIndices = chunkBaseEntityIndices2, MotionVelocities = world.MotionVelocities, MotionDatas = world.MotionDatas, PositionType = positionType, RotationType = rotationType, VelocityType = velocityType - }.ScheduleParallel(m_BuildPhysicsWorldSystem.DynamicEntityGroup, 1, handle); + }.ScheduleParallel(m_BuildPhysicsWorldSystem.DynamicEntityGroup, handle); // Sync shared data. m_SharedData.Sync(); @@ -102,7 +111,7 @@ protected override void OnUpdate() World = m_BuildPhysicsWorldSystem.PhysicsWorld, SharedData = m_SharedData, ProxyType = GetComponentTypeHandle() - }.ScheduleParallel(m_BuildPhysicsWorldSystem.CollisionWorldProxyGroup, 1, handle); + }.ScheduleParallel(m_BuildPhysicsWorldSystem.CollisionWorldProxyGroup, handle); } m_OutputDependency = handle; @@ -128,8 +137,9 @@ public JobHandle GetOutputDependency() } [BurstCompile] - internal struct ExportDynamicBodiesJob : IJobEntityBatchWithIndex + internal struct ExportDynamicBodiesJob : IJobChunk { + [ReadOnly] public NativeArray ChunkBaseEntityIndices; [ReadOnly] public NativeArray MotionVelocities; [ReadOnly] public NativeArray MotionDatas; @@ -137,8 +147,10 @@ internal struct ExportDynamicBodiesJob : IJobEntityBatchWithIndex public ComponentTypeHandle RotationType; public ComponentTypeHandle VelocityType; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int entityStartIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { + int entityStartIndex = ChunkBaseEntityIndices[batchIndex]; + var chunkPositions = batchInChunk.GetNativeArray(PositionType); var chunkRotations = batchInChunk.GetNativeArray(RotationType); var chunkVelocities = batchInChunk.GetNativeArray(VelocityType); @@ -161,14 +173,14 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex, int entityStart } [BurstCompile] - internal unsafe struct CopyCollisionWorld : IJobEntityBatch + internal unsafe struct CopyCollisionWorld : IJobChunk { [ReadOnly] public PhysicsWorld World; public SharedData SharedData; public ComponentTypeHandle ProxyType; //public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { NativeArray chunkProxies = batchInChunk.GetNativeArray(ProxyType); @@ -181,7 +193,7 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) #region Integrity checks - internal JobHandle CheckIntegrity(JobHandle inputDeps, NativeHashMap integrityCheckMap) + internal JobHandle CheckIntegrity(JobHandle inputDeps, NativeParallelHashMap integrityCheckMap) { var positionType = GetComponentTypeHandle(true); var rotationType = GetComponentTypeHandle(true); @@ -205,7 +217,8 @@ internal JobHandle CheckIntegrity(JobHandle inputDeps, NativeHashMap PhysicsColliderType = physicsColliderType }; - inputDeps = checkStaticBodyColliderIntegrity.Schedule(m_BuildPhysicsWorldSystem.StaticEntityGroup, inputDeps); + inputDeps = checkStaticBodyColliderIntegrity.Schedule(m_BuildPhysicsWorldSystem.StaticEntityGroup, + inputDeps); var checkTotalIntegrity = new CheckTotalIntegrity { @@ -216,15 +229,16 @@ internal JobHandle CheckIntegrity(JobHandle inputDeps, NativeHashMap } [BurstCompile] - internal struct CheckDynamicBodyIntegrity : IJobEntityBatch + internal struct CheckDynamicBodyIntegrity : IJobChunk { [ReadOnly] public ComponentTypeHandle PositionType; [ReadOnly] public ComponentTypeHandle RotationType; [ReadOnly] public ComponentTypeHandle PhysicsVelocityType; [ReadOnly] public ComponentTypeHandle PhysicsColliderType; - public NativeHashMap IntegrityCheckMap; + public NativeParallelHashMap IntegrityCheckMap; - internal static void DecrementIfExists(NativeHashMap integrityCheckMap, uint systemVersion) + internal static void DecrementIfExists(NativeParallelHashMap integrityCheckMap, + uint systemVersion) { if (integrityCheckMap.TryGetValue(systemVersion, out long occurences)) { @@ -233,7 +247,7 @@ internal static void DecrementIfExists(NativeHashMap integrityCheckM } } - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { DecrementIfExists(IntegrityCheckMap, batchInChunk.GetOrderVersion()); DecrementIfExists(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsVelocityType)); @@ -241,10 +255,12 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) { DecrementIfExists(IntegrityCheckMap, batchInChunk.GetChangeVersion(PositionType)); } + if (batchInChunk.Has(RotationType)) { DecrementIfExists(IntegrityCheckMap, batchInChunk.GetChangeVersion(RotationType)); } + if (batchInChunk.Has(PhysicsColliderType)) { DecrementIfExists(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsColliderType)); @@ -256,16 +272,17 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) } [BurstCompile] - internal struct CheckColliderIntegrity : IJobEntityBatch + internal struct CheckColliderIntegrity : IJobChunk { [ReadOnly] public ComponentTypeHandle PhysicsColliderType; - public NativeHashMap IntegrityCheckMap; + public NativeParallelHashMap IntegrityCheckMap; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { if (batchInChunk.Has(PhysicsColliderType)) { - CheckDynamicBodyIntegrity.DecrementIfExists(IntegrityCheckMap, batchInChunk.GetChangeVersion(PhysicsColliderType)); + CheckDynamicBodyIntegrity.DecrementIfExists(IntegrityCheckMap, + batchInChunk.GetChangeVersion(PhysicsColliderType)); var colliders = batchInChunk.GetNativeArray(PhysicsColliderType); CheckColliderFilterIntegrity(colliders); @@ -276,7 +293,8 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) [BurstCompile] internal struct CheckTotalIntegrity : IJob { - public NativeHashMap IntegrityCheckMap; + public NativeParallelHashMap IntegrityCheckMap; + public void Execute() { var values = IntegrityCheckMap.GetValueArray(Allocator.Temp); @@ -289,9 +307,11 @@ public void Execute() break; } } + if (!validIntegrity) { - SafetyChecks.ThrowInvalidOperationException("Adding/removing components or changing position/rotation/velocity/collider ECS data" + + SafetyChecks.ThrowInvalidOperationException( + "Adding/removing components or changing position/rotation/velocity/collider ECS data" + " on dynamic entities during physics step"); } } @@ -322,7 +342,8 @@ private static void CheckColliderFilterIntegrity(NativeArray co // If not, it means user has forgotten to call RefreshCollisionFilter() on the CompoundCollider. if (!rootFilter.Equals(combinedFilter)) { - SafetyChecks.ThrowInvalidOperationException("CollisionFilter of a compound collider is not a union of its children. " + + SafetyChecks.ThrowInvalidOperationException( + "CollisionFilter of a compound collider is not a union of its children. " + "You must call CompoundCollider.RefreshCollisionFilter() to update the root filter after changing child filters."); } } diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/StepPhysicsWorld.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/StepPhysicsWorld.cs index 1e41a8c..e04e0e5 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/StepPhysicsWorld.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/Base/Systems/StepPhysicsWorld.cs @@ -8,7 +8,7 @@ namespace UnityS.Physics.Systems // Simulates the physics world forwards in time [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(ExportPhysicsWorld)), AlwaysUpdateSystem] - public class StepPhysicsWorld : SystemBase, IPhysicsSystem + public partial class StepPhysicsWorld : SystemBase, IPhysicsSystem { private JobHandle m_InputDependency; private JobHandle m_OutputDependency; @@ -36,9 +36,9 @@ public class StepPhysicsWorld : SystemBase, IPhysicsSystem protected override void OnCreate() { - m_BuildPhysicsWorldSystem = World.GetOrCreateSystem(); - m_ExportPhysicsWorldSystem = World.GetOrCreateSystem(); - m_EndFramePhysicsSystem = World.GetOrCreateSystem(); + m_BuildPhysicsWorldSystem = World.GetOrCreateSystemManaged(); + m_ExportPhysicsWorldSystem = World.GetOrCreateSystemManaged(); + m_EndFramePhysicsSystem = World.GetOrCreateSystemManaged(); #if !NET_DOTS Assert.AreEqual(Enum.GetValues(typeof(SimulationType)).Length, k_NumSimulationTypes); @@ -88,7 +88,7 @@ protected override void OnUpdate() Simulation = m_SimulationCreators[(int)stepComponent.SimulationType](); } - sfloat timeStep = (sfloat)Time.DeltaTime; + sfloat timeStep = (sfloat)SystemAPI.Time.DeltaTime; // Schedule the simulation jobs Simulation.ScheduleStepJobs(new SimulationStepInput() diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/BufferInterpolatedRigidBodiesMotion.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/BufferInterpolatedRigidBodiesMotion.cs index 3a33215..b7f4faa 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/BufferInterpolatedRigidBodiesMotion.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/BufferInterpolatedRigidBodiesMotion.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -22,7 +23,7 @@ namespace UnityS.Physics.GraphicsIntegration /// [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(ExportPhysicsWorld))] - public class BufferInterpolatedRigidBodiesMotion : SystemBase, IPhysicsSystem + public partial class BufferInterpolatedRigidBodiesMotion : SystemBase, IPhysicsSystem { JobHandle m_InputDependency; JobHandle m_OutputDependency; @@ -49,7 +50,7 @@ public void AddInputDependency(JobHandle inputDep) => protected override void OnCreate() { - m_ExportPhysicsWorldSystem = World.GetOrCreateSystem(); + m_ExportPhysicsWorldSystem = World.GetOrCreateSystemManaged(); InterpolatedDynamicBodiesGroup = GetEntityQuery(new EntityQueryDesc { @@ -81,7 +82,7 @@ protected override void OnUpdate() RotationType = GetComponentTypeHandle(true), PhysicsVelocityType = GetComponentTypeHandle(true), InterpolationBufferType = GetComponentTypeHandle() - }.ScheduleParallel(InterpolatedDynamicBodiesGroup, 1, Dependency); + }.ScheduleParallel(InterpolatedDynamicBodiesGroup, Dependency); // Combine implicit output dependency with user one m_OutputDependency = Dependency; @@ -94,14 +95,14 @@ protected override void OnUpdate() } [BurstCompile] - unsafe struct UpdateInterpolationBuffersJob : IJobEntityBatch + unsafe struct UpdateInterpolationBuffersJob : IJobChunk { [ReadOnly] public ComponentTypeHandle PhysicsVelocityType; [ReadOnly] public ComponentTypeHandle TranslationType; [ReadOnly] public ComponentTypeHandle RotationType; public ComponentTypeHandle InterpolationBufferType; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { NativeArray physicsVelocities = batchInChunk.GetNativeArray(PhysicsVelocityType); NativeArray positions = batchInChunk.GetNativeArray(TranslationType); diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/CopyPhysicsVelocityToSmoothing.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/CopyPhysicsVelocityToSmoothing.cs index 506f26f..05779e4 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/CopyPhysicsVelocityToSmoothing.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/CopyPhysicsVelocityToSmoothing.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -14,7 +15,7 @@ namespace UnityS.Physics.GraphicsIntegration /// [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(ExportPhysicsWorld))] - public class CopyPhysicsVelocityToSmoothing : SystemBase, IPhysicsSystem + public partial class CopyPhysicsVelocityToSmoothing : SystemBase, IPhysicsSystem { JobHandle m_InputDependency; JobHandle m_OutputDependency; @@ -44,8 +45,8 @@ protected override void OnCreate() { base.OnCreate(); - m_ExportPhysicsWorld = World.GetOrCreateSystem(); - m_SmoothRigidBodiesGraphicalMotion = World.GetOrCreateSystem(); + m_ExportPhysicsWorld = World.GetOrCreateSystemManaged(); + m_SmoothRigidBodiesGraphicalMotion = World.GetOrCreateSystemManaged(); SmoothedDynamicBodiesGroup = GetEntityQuery(new EntityQueryDesc { @@ -75,7 +76,7 @@ protected override void OnUpdate() { PhysicsVelocityType = GetComponentTypeHandle(true), PhysicsGraphicalSmoothingType = GetComponentTypeHandle() - }.ScheduleParallel(SmoothedDynamicBodiesGroup, 1, Dependency); + }.ScheduleParallel(SmoothedDynamicBodiesGroup, Dependency); // Combine implicit output dependency with user one m_OutputDependency = Dependency; @@ -88,12 +89,12 @@ protected override void OnUpdate() } [BurstCompile] - unsafe struct CopyPhysicsVelocityJob : IJobEntityBatch + unsafe struct CopyPhysicsVelocityJob : IJobChunk { [ReadOnly] public ComponentTypeHandle PhysicsVelocityType; public ComponentTypeHandle PhysicsGraphicalSmoothingType; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { NativeArray physicsVelocities = batchInChunk.GetNativeArray(PhysicsVelocityType); NativeArray physicsGraphicalSmoothings = batchInChunk.GetNativeArray(PhysicsGraphicalSmoothingType); diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/RecordMostRecentFixedTime.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/RecordMostRecentFixedTime.cs index ec2d32e..fe1c4b6 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/RecordMostRecentFixedTime.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/RecordMostRecentFixedTime.cs @@ -9,7 +9,7 @@ namespace UnityS.Physics.GraphicsIntegration [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(ExportPhysicsWorld))] [AlwaysUpdateSystem] - public class RecordMostRecentFixedTime : SystemBase + public partial class RecordMostRecentFixedTime : SystemBase { /// /// The value of Time.ElapsedTime in the most recent tick of the FixedStepSimulationSystemGroup. @@ -23,8 +23,8 @@ public class RecordMostRecentFixedTime : SystemBase protected override void OnUpdate() { - MostRecentElapsedTime = Time.ElapsedTime; - MostRecentDeltaTime = Time.DeltaTime; + MostRecentElapsedTime = SystemAPI.Time.ElapsedTime; + MostRecentDeltaTime = SystemAPI.Time.DeltaTime; } } } diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/SmoothRigidBodiesGraphicalMotion.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/SmoothRigidBodiesGraphicalMotion.cs index 0290307..965887c 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/SmoothRigidBodiesGraphicalMotion.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/ECS/GraphicsIntegration/Systems/SmoothRigidBodiesGraphicalMotion.cs @@ -1,4 +1,5 @@ using Unity.Burst; +using Unity.Burst.Intrinsics; using Unity.Collections; using Unity.Entities; using Unity.Jobs; @@ -14,7 +15,7 @@ namespace UnityS.Physics.GraphicsIntegration /// [UpdateInGroup(typeof(TransformSystemGroup))] [UpdateBefore(typeof(EndFrameTRSToLocalToWorldSystem))] - public class SmoothRigidBodiesGraphicalMotion : SystemBase, IPhysicsSystem + public partial class SmoothRigidBodiesGraphicalMotion : SystemBase, IPhysicsSystem { JobHandle m_InputDependency; JobHandle m_OutputDependency; @@ -57,14 +58,14 @@ protected override void OnCreate() } }); RequireForUpdate(SmoothedDynamicBodiesGroup); - m_RecordMostRecentFixedTime = World.GetOrCreateSystem(); + m_RecordMostRecentFixedTime = World.GetOrCreateSystemManaged(); } protected override void OnUpdate() { // Note: this is only for rendering, not affecting the physics simulation // So float operations can be used here, because it's not required to be deterministic - sfloat timeAhead = (sfloat)(Time.ElapsedTime - m_RecordMostRecentFixedTime.MostRecentElapsedTime); + sfloat timeAhead = (sfloat)(SystemAPI.Time.ElapsedTime - m_RecordMostRecentFixedTime.MostRecentElapsedTime); sfloat timeStep = (sfloat)m_RecordMostRecentFixedTime.MostRecentDeltaTime; if (timeAhead <= sfloat.Zero || timeStep == sfloat.Zero) return; @@ -85,7 +86,7 @@ protected override void OnUpdate() LocalToWorldType = GetComponentTypeHandle(), TimeAhead = timeAhead, NormalizedTimeAhead = normalizedTimeAhead - }.ScheduleParallel(SmoothedDynamicBodiesGroup, 1, Dependency); + }.ScheduleParallel(SmoothedDynamicBodiesGroup, Dependency); // Combine implicit output dependency with user one m_OutputDependency = Dependency; @@ -97,7 +98,7 @@ protected override void OnUpdate() } [BurstCompile] - struct SmoothMotionJob : IJobEntityBatch + struct SmoothMotionJob : IJobChunk { [ReadOnly] public ComponentTypeHandle TranslationType; [ReadOnly] public ComponentTypeHandle RotationType; @@ -111,7 +112,7 @@ struct SmoothMotionJob : IJobEntityBatch public sfloat TimeAhead; public sfloat NormalizedTimeAhead; - public void Execute(ArchetypeChunk batchInChunk, int batchIndex) + public void Execute(in ArchetypeChunk batchInChunk, int batchIndex, bool useMask, in v128 mask) { var hasNonUniformScale = batchInChunk.Has(NonUniformScaleType); var hasScale = batchInChunk.Has(ScaleType); @@ -125,8 +126,10 @@ public void Execute(ArchetypeChunk batchInChunk, int batchIndex) NativeArray scales = batchInChunk.GetNativeArray(ScaleType); NativeArray compositeScales = batchInChunk.GetNativeArray(CompositeScaleType); NativeArray physicsMasses = batchInChunk.GetNativeArray(PhysicsMassType); - NativeArray physicsGraphicalSmoothings = batchInChunk.GetNativeArray(PhysicsGraphicalSmoothingType); - NativeArray interpolationBuffers = batchInChunk.GetNativeArray(InterpolationBufferType); + NativeArray physicsGraphicalSmoothings = + batchInChunk.GetNativeArray(PhysicsGraphicalSmoothingType); + NativeArray interpolationBuffers = + batchInChunk.GetNativeArray(InterpolationBufferType); NativeArray localToWorlds = batchInChunk.GetNativeArray(LocalToWorldType); var defaultPhysicsMass = PhysicsMass.CreateKinematic(MassProperties.UnitSphere); diff --git a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Extensions/SafetyChecks.cs b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Extensions/SafetyChecks.cs index 213b917..edada8c 100644 --- a/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Extensions/SafetyChecks.cs +++ b/Assets/Scripts/UnityPhysicsPackage/Unity.Physics/Extensions/SafetyChecks.cs @@ -11,7 +11,7 @@ static class SafetyChecks public const string ConditionalSymbol = "ENABLE_UNITY_COLLECTIONS_CHECKS"; [Conditional(ConditionalSymbol)] - public static unsafe void Check4ByteAlignmentAndThrow(void* data, in FixedString32 paramName) + public static unsafe void Check4ByteAlignmentAndThrow(void* data, in FixedString32Bytes paramName) { if (((long)data & 0x3) != 0) throw new InvalidOperationException($"{paramName} must be 4-byte aligned."); @@ -25,14 +25,14 @@ public static void CheckAreEqualAndThrow(SimulationType expected, SimulationType } [Conditional(ConditionalSymbol)] - public static void CheckFiniteAndThrow(float3 value, FixedString32 paramName) + public static void CheckFiniteAndThrow(float3 value, FixedString32Bytes paramName) { if (math.any(!math.isfinite(value))) throw new ArgumentException($"{value} was not finite.", $"{paramName}"); } [Conditional(ConditionalSymbol)] - public static void CheckFiniteAndPositiveAndThrow(float3 value, in FixedString32 paramName) + public static void CheckFiniteAndPositiveAndThrow(float3 value, in FixedString32Bytes paramName) { if (math.any(value < sfloat.Zero) || math.any(!math.isfinite(value))) throw new ArgumentOutOfRangeException($"{paramName}", $"{value} is not positive and finite."); @@ -46,14 +46,14 @@ public static void CheckIndexAndThrow(int index, int length, int min = 0) } [Conditional(ConditionalSymbol)] - public static void CheckInRangeAndThrow(int value, int2 range, in FixedString32 paramName) + public static void CheckInRangeAndThrow(int value, int2 range, in FixedString32Bytes paramName) { if (value < range.x || value > range.y) throw new ArgumentOutOfRangeException($"{paramName}", $"{value} is out of range [{range.x}, {range.y}]."); } [Conditional(ConditionalSymbol)] - public static void CheckNotEmptyAndThrow(NativeArray array, in FixedString32 paramName) where T : struct + public static void CheckNotEmptyAndThrow(NativeArray array, in FixedString32Bytes paramName) where T : struct { if (!array.IsCreated || array.Length == 0) throw new ArgumentException("Array is empty.", $"{paramName}"); @@ -62,7 +62,7 @@ public static void CheckNotEmptyAndThrow(NativeArray array, in FixedString #region Geometry Validation [Conditional(ConditionalSymbol)] - public static void CheckCoplanarAndThrow(float3 vertex0, float3 vertex1, float3 vertex2, float3 vertex3, in FixedString32 paramName) + public static void CheckCoplanarAndThrow(float3 vertex0, float3 vertex1, float3 vertex2, float3 vertex3, in FixedString32Bytes paramName) { var normal = math.normalize(math.cross(vertex1 - vertex0, vertex2 - vertex0)); if (math.abs(math.dot(normal, vertex3 - vertex0)) > sfloat.FromRaw(0x3a83126f)) @@ -70,7 +70,7 @@ public static void CheckCoplanarAndThrow(float3 vertex0, float3 vertex1, float3 } [Conditional(ConditionalSymbol)] - public static void CheckTriangleIndicesInRangeAndThrow(NativeArray triangles, int numVertices, in FixedString32 paramName) + public static void CheckTriangleIndicesInRangeAndThrow(NativeArray triangles, int numVertices, in FixedString32Bytes paramName) { for (var i = 0; i < triangles.Length; ++i) { @@ -80,35 +80,35 @@ public static void CheckTriangleIndicesInRangeAndThrow(NativeArray triangl } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static void Geometry_CheckFiniteAndThrow(float3 value, in FixedString32 paramName, in FixedString32 propertyName) + static void Geometry_CheckFiniteAndThrow(float3 value, in FixedString32Bytes paramName, in FixedString32Bytes propertyName) { if (math.any(!math.isfinite(value))) throw new ArgumentException($"{propertyName} {value} was not finite.", $"{paramName}"); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static void Geometry_CheckFiniteAndPositiveAndThrow(sfloat value, in FixedString32 paramName, in FixedString32 propertyName) + static void Geometry_CheckFiniteAndPositiveAndThrow(sfloat value, in FixedString32Bytes paramName, in FixedString32Bytes propertyName) { if (value < sfloat.Zero || !math.isfinite(value)) throw new ArgumentException($"{propertyName} {value} is not positive.", $"{paramName}"); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static void Geometry_CheckFiniteAndPositiveAndThrow(float3 value, in FixedString32 paramName, in FixedString32 propertyName) + static void Geometry_CheckFiniteAndPositiveAndThrow(float3 value, in FixedString32Bytes paramName, in FixedString32Bytes propertyName) { if (math.any(value < sfloat.Zero) || math.any(!math.isfinite(value))) throw new ArgumentException($"{paramName}", $"{propertyName} {value} is not positive."); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - static void Geometry_CheckValidAndThrow(quaternion q, in FixedString32 paramName, in FixedString32 propertyName) + static void Geometry_CheckValidAndThrow(quaternion q, in FixedString32Bytes paramName, in FixedString32Bytes propertyName) { if (q.Equals(default) || math.any(!math.isfinite(q.value))) throw new ArgumentException($"{propertyName} {q} is not valid.", $"{paramName}"); } [Conditional(ConditionalSymbol)] - public static void CheckValidAndThrow(NativeArray points, in FixedString32 pointsName, in ConvexHullGenerationParameters generationParameters, in FixedString32 paramName) + public static void CheckValidAndThrow(NativeArray points, in FixedString32Bytes pointsName, in ConvexHullGenerationParameters generationParameters, in FixedString32Bytes paramName) { Geometry_CheckFiniteAndPositiveAndThrow(generationParameters.BevelRadius, paramName, nameof(ConvexHullGenerationParameters.BevelRadius)); @@ -117,7 +117,7 @@ public static void CheckValidAndThrow(NativeArray points, in FixedString } [Conditional(ConditionalSymbol)] - public static void CheckValidAndThrow(in BoxGeometry geometry, in FixedString32 paramName) + public static void CheckValidAndThrow(in BoxGeometry geometry, in FixedString32Bytes paramName) { Geometry_CheckFiniteAndThrow(geometry.Center, paramName, nameof(BoxGeometry.Center)); Geometry_CheckValidAndThrow(geometry.Orientation, paramName, nameof(BoxGeometry.Orientation)); @@ -128,7 +128,7 @@ public static void CheckValidAndThrow(in BoxGeometry geometry, in FixedString32 } [Conditional(ConditionalSymbol)] - public static void CheckValidAndThrow(in CapsuleGeometry geometry, in FixedString32 paramName) + public static void CheckValidAndThrow(in CapsuleGeometry geometry, in FixedString32Bytes paramName) { Geometry_CheckFiniteAndThrow(geometry.Vertex0, paramName, nameof(CapsuleGeometry.Vertex0)); Geometry_CheckFiniteAndThrow(geometry.Vertex1, paramName, nameof(CapsuleGeometry.Vertex1)); @@ -136,7 +136,7 @@ public static void CheckValidAndThrow(in CapsuleGeometry geometry, in FixedStrin } [Conditional(ConditionalSymbol)] - public static void CheckValidAndThrow(in CylinderGeometry geometry, in FixedString32 paramName) + public static void CheckValidAndThrow(in CylinderGeometry geometry, in FixedString32Bytes paramName) { Geometry_CheckFiniteAndThrow(geometry.Center, paramName, nameof(CylinderGeometry.Center)); Geometry_CheckValidAndThrow(geometry.Orientation, paramName, nameof(CylinderGeometry.Orientation)); @@ -150,7 +150,7 @@ public static void CheckValidAndThrow(in CylinderGeometry geometry, in FixedStri } [Conditional(ConditionalSymbol)] - public static void CheckValidAndThrow(in SphereGeometry geometry, in FixedString32 paramName) + public static void CheckValidAndThrow(in SphereGeometry geometry, in FixedString32Bytes paramName) { Geometry_CheckFiniteAndThrow(geometry.Center, paramName, nameof(SphereGeometry.Center)); Geometry_CheckFiniteAndPositiveAndThrow(geometry.Radius, paramName, nameof(SphereGeometry.Radius)); @@ -161,16 +161,16 @@ public static void CheckValidAndThrow(in SphereGeometry geometry, in FixedString #region Throw Exceptions [Conditional(ConditionalSymbol)] - public static void ThrowInvalidOperationException(FixedString128 message = default) => throw new InvalidOperationException($"{message}"); + public static void ThrowInvalidOperationException(FixedString128Bytes message = default) => throw new InvalidOperationException($"{message}"); [Conditional(ConditionalSymbol)] public static void ThrowNotImplementedException() => throw new NotImplementedException(); [Conditional(ConditionalSymbol)] - public static void ThrowNotSupportedException(FixedString64 message = default) => throw new NotSupportedException($"{message}"); + public static void ThrowNotSupportedException(FixedString64Bytes message = default) => throw new NotSupportedException($"{message}"); [Conditional(ConditionalSymbol)] - public static void ThrowArgumentException(in FixedString32 paramName, FixedString64 message = default) => + public static void ThrowArgumentException(in FixedString32Bytes paramName, FixedString64Bytes message = default) => throw new ArgumentException($"{message}", $"{paramName}"); #endregion diff --git a/Packages/manifest.json b/Packages/manifest.json index b9cc8d2..e7eb360 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,16 +1,17 @@ { "dependencies": { - "com.unity.burst": "1.4.4", - "com.unity.collab-proxy": "1.3.9", - "com.unity.ide.rider": "2.0.7", - "com.unity.ide.visualstudio": "2.0.7", - "com.unity.test-framework": "1.1.19", - "com.unity.textmeshpro": "3.0.1", - "com.unity.timeline": "1.4.4", - "com.unity.ugui": "1.0.0", - "com.unity.collections": "0.14.0-preview.16", - "com.unity.entities": "0.16.0-preview.21", - "com.unity.jobs": "0.7.0-preview.17", + "com.unity.ai.navigation": "2.0.0", + "com.unity.burst": "1.8.12", + "com.unity.collab-proxy": "2.2.0", + "com.unity.collections": "2.4.0-pre.2", + "com.unity.entities": "1.2.0-pre.6", + "com.unity.ide.rider": "3.0.27", + "com.unity.ide.visualstudio": "2.0.22", + "com.unity.jobs": "0.70.0-preview.7", + "com.unity.test-framework": "1.4.2", + "com.unity.timeline": "1.8.6", + "com.unity.ugui": "2.0.0", + "com.unity.modules.accessibility": "1.0.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 11cab55..4b23c62 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,68 +1,81 @@ { "dependencies": { + "com.unity.ai.navigation": { + "version": "2.0.0", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.ai": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.burst": { - "version": "1.4.4", + "version": "1.8.12", "depth": 0, "source": "registry", "dependencies": { - "com.unity.mathematics": "1.2.1" + "com.unity.mathematics": "1.2.1", + "com.unity.modules.jsonserialize": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "1.3.9", + "version": "2.2.0", "depth": 0, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.collections": { - "version": "0.14.0-preview.16", + "version": "2.4.0-pre.2", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework.performance": "2.3.1-preview", - "com.unity.burst": "1.3.7" + "com.unity.burst": "1.8.10", + "com.unity.nuget.mono-cecil": "1.11.4", + "com.unity.test-framework": "1.3.8", + "com.unity.test-framework.performance": "3.0.3" }, "url": "https://packages.unity.com" }, "com.unity.entities": { - "version": "0.16.0-preview.21", + "version": "1.2.0-pre.6", "depth": 0, "source": "registry", "dependencies": { - "com.unity.burst": "1.3.7", - "com.unity.properties": "1.5.0-preview", - "com.unity.serialization": "1.5.0-preview", - "com.unity.collections": "0.14.0-preview.16", - "com.unity.mathematics": "1.2.1", + "com.unity.burst": "1.8.10", + "com.unity.serialization": "3.1.1", + "com.unity.collections": "2.4.0-pre.2", + "com.unity.mathematics": "1.3.1", "com.unity.modules.assetbundle": "1.0.0", - "com.unity.test-framework.performance": "2.3.1-preview", - "com.unity.nuget.mono-cecil": "0.1.6-preview.2", - "com.unity.jobs": "0.7.0-preview.17", - "com.unity.scriptablebuildpipeline": "1.9.0", - "com.unity.platforms": "0.9.0-preview.9" + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.unityanalytics": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.test-framework.performance": "3.0.3", + "com.unity.nuget.mono-cecil": "1.11.4", + "com.unity.scriptablebuildpipeline": "1.20.2", + "com.unity.profiling.core": "1.0.2" }, "url": "https://packages.unity.com" }, "com.unity.ext.nunit": { - "version": "1.0.5", + "version": "2.0.5", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "2.0.7", + "version": "3.0.27", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.1" + "com.unity.ext.nunit": "1.0.6" }, "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.7", + "version": "2.0.22", "depth": 0, "source": "registry", "dependencies": { @@ -71,123 +84,75 @@ "url": "https://packages.unity.com" }, "com.unity.jobs": { - "version": "0.7.0-preview.17", + "version": "0.70.0-preview.7", "depth": 0, "source": "registry", "dependencies": { - "com.unity.collections": "0.14.0-preview.16", - "com.unity.mathematics": "1.2.1" + "com.unity.collections": "1.4.0" }, "url": "https://packages.unity.com" }, "com.unity.mathematics": { - "version": "1.2.1", + "version": "1.3.1", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.nuget.mono-cecil": { - "version": "0.1.6-preview.2", + "version": "1.11.4", "depth": 1, "source": "registry", - "dependencies": { - "nuget.mono-cecil": "0.1.6-preview" - }, - "url": "https://packages.unity.com" - }, - "com.unity.nuget.newtonsoft-json": { - "version": "2.0.0-preview", - "depth": 2, - "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.platforms": { - "version": "0.9.0-preview.9", - "depth": 1, - "source": "registry", - "dependencies": { - "com.unity.properties": "1.5.0-preview", - "com.unity.properties.ui": "1.5.0-preview", - "com.unity.scriptablebuildpipeline": "1.6.4-preview", - "com.unity.serialization": "1.5.0-preview" - }, - "url": "https://packages.unity.com" - }, - "com.unity.properties": { - "version": "1.5.0-preview", + "com.unity.profiling.core": { + "version": "1.0.2", "depth": 1, "source": "registry", - "dependencies": { - "com.unity.nuget.mono-cecil": "0.1.6-preview.2", - "com.unity.test-framework.performance": "2.0.8-preview" - }, - "url": "https://packages.unity.com" - }, - "com.unity.properties.ui": { - "version": "1.5.0-preview", - "depth": 2, - "source": "registry", - "dependencies": { - "com.unity.properties": "1.5.0-preview", - "com.unity.serialization": "1.5.0-preview", - "com.unity.modules.uielements": "1.0.0" - }, + "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.scriptablebuildpipeline": { - "version": "1.9.0", + "version": "2.1.0", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.serialization": { - "version": "1.5.0-preview", + "version": "3.1.1", "depth": 1, "source": "registry", "dependencies": { - "com.unity.collections": "0.8.0-preview.5", - "com.unity.burst": "1.3.0-preview.12", - "com.unity.jobs": "0.2.9-preview.15", - "com.unity.properties": "1.4.3-preview", - "com.unity.test-framework.performance": "2.0.8-preview" + "com.unity.collections": "2.1.4", + "com.unity.burst": "1.7.2" }, "url": "https://packages.unity.com" }, "com.unity.test-framework": { - "version": "1.1.19", + "version": "1.4.2", "depth": 0, "source": "registry", "dependencies": { - "com.unity.ext.nunit": "1.0.5", + "com.unity.ext.nunit": "2.0.3", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.test-framework.performance": { - "version": "2.3.1-preview", + "version": "3.0.3", "depth": 1, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.0", - "com.unity.nuget.newtonsoft-json": "2.0.0-preview" - }, - "url": "https://packages.unity.com" - }, - "com.unity.textmeshpro": { - "version": "3.0.1", - "depth": 0, - "source": "registry", - "dependencies": { - "com.unity.ugui": "1.0.0" + "com.unity.test-framework": "1.1.31", + "com.unity.modules.jsonserialize": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.4.4", + "version": "1.8.6", "depth": 0, "source": "registry", "dependencies": { @@ -199,7 +164,7 @@ "url": "https://packages.unity.com" }, "com.unity.ugui": { - "version": "1.0.0", + "version": "2.0.0", "depth": 0, "source": "builtin", "dependencies": { @@ -207,12 +172,11 @@ "com.unity.modules.imgui": "1.0.0" } }, - "nuget.mono-cecil": { - "version": "0.1.6-preview", - "depth": 2, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" + "com.unity.modules.accessibility": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} }, "com.unity.modules.ai": { "version": "1.0.0", @@ -261,6 +225,12 @@ "com.unity.modules.animation": "1.0.0" } }, + "com.unity.modules.hierarchycore": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + }, "com.unity.modules.imageconversion": { "version": "1.0.0", "depth": 0, @@ -350,17 +320,7 @@ "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.uielementsnative": "1.0.0" - } - }, - "com.unity.modules.uielementsnative": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", - "dependencies": { - "com.unity.modules.ui": "1.0.0", - "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0" + "com.unity.modules.hierarchycore": "1.0.0" } }, "com.unity.modules.umbra": { diff --git a/ProjectSettings/EntitiesClientSettings.asset b/ProjectSettings/EntitiesClientSettings.asset new file mode 100644 index 0000000..3f1b7c4 --- /dev/null +++ b/ProjectSettings/EntitiesClientSettings.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 53 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2ea235c1fcfe29488ed97c467a0da53, type: 3} + m_Name: + m_EditorClassIdentifier: + FilterSettings: + ExcludedBakingSystemAssemblies: [] diff --git a/ProjectSettings/MemorySettings.asset b/ProjectSettings/MemorySettings.asset new file mode 100644 index 0000000..5b5face --- /dev/null +++ b/ProjectSettings/MemorySettings.asset @@ -0,0 +1,35 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!387306366 &1 +MemorySettings: + m_ObjectHideFlags: 0 + m_EditorMemorySettings: + m_MainAllocatorBlockSize: -1 + m_ThreadAllocatorBlockSize: -1 + m_MainGfxBlockSize: -1 + m_ThreadGfxBlockSize: -1 + m_CacheBlockSize: -1 + m_TypetreeBlockSize: -1 + m_ProfilerBlockSize: -1 + m_ProfilerEditorBlockSize: -1 + m_BucketAllocatorGranularity: -1 + m_BucketAllocatorBucketsCount: -1 + m_BucketAllocatorBlockSize: -1 + m_BucketAllocatorBlockCount: -1 + m_ProfilerBucketAllocatorGranularity: -1 + m_ProfilerBucketAllocatorBucketsCount: -1 + m_ProfilerBucketAllocatorBlockSize: -1 + m_ProfilerBucketAllocatorBlockCount: -1 + m_TempAllocatorSizeMain: -1 + m_JobTempAllocatorBlockSize: -1 + m_BackgroundJobTempAllocatorBlockSize: -1 + m_JobTempAllocatorReducedBlockSize: -1 + m_TempAllocatorSizeGIBakingWorker: -1 + m_TempAllocatorSizeNavMeshWorker: -1 + m_TempAllocatorSizeAudioWorker: -1 + m_TempAllocatorSizeCloudWorker: -1 + m_TempAllocatorSizeGfx: -1 + m_TempAllocatorSizeJobWorker: -1 + m_TempAllocatorSizeBackgroundWorker: -1 + m_TempAllocatorSizePreloadManager: -1 + m_PlatformMemorySettings: {} diff --git a/ProjectSettings/MultiplayerManager.asset b/ProjectSettings/MultiplayerManager.asset new file mode 100644 index 0000000..2b8e00b --- /dev/null +++ b/ProjectSettings/MultiplayerManager.asset @@ -0,0 +1,8 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!655991488 &1 +MultiplayerManager: + m_ObjectHideFlags: 0 + m_ActiveMultiplayerRoles: 3 + m_EnableMultiplayerRoles: 0 + m_StrippingTypes: {} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index a328ffd..fd034e1 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.2.1f1 -m_EditorVersionWithRevision: 2020.2.1f1 (270dd8c3da1c) +m_EditorVersion: 2023.3.0b3 +m_EditorVersionWithRevision: 2023.3.0b3 (205c101ad8b5)