Skip to content

Updated entities package to 1.2.0-pre.6, updated obsolete code to use new version #15

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions Assets/Scripts/Example/GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using UnityS.Physics.Systems;
using UnityS.Transforms;

public class GameController : SystemBase
public partial class GameController : SystemBase
{
public static GameController Instance;

Expand All @@ -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<FixedStepSimulationSystemGroup>().Timestep = (float)(sfloat.One / (sfloat)60.0f);
World.GetOrCreateSystemManaged<FixedStepSimulationSystemGroup>().Timestep = (float)(sfloat.One / (sfloat)60.0f);
Entity physicsStep = EntityManager.CreateEntity(typeof(PhysicsStep));
PhysicsStep physicsStepParams = PhysicsStep.Default;
physicsStepParams.SolverStabilizationHeuristicSettings = new Solver.StabilizationHeuristicSettings
Expand All @@ -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;
Expand Down Expand Up @@ -111,8 +112,13 @@ private Color RandomColor()
);
}

private Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference<UnityS.Physics.Collider>> ballColliders = new Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference<UnityS.Physics.Collider>>();
public void CreateBall(float3 position, sfloat radius, UnityS.Physics.Material material, PhysicsParams physicsParams)
private Dictionary<(sfloat radius, UnityS.Physics.Material material), BlobAssetReference<UnityS.Physics.Collider>>
ballColliders =
new Dictionary<(sfloat radius, UnityS.Physics.Material material),
BlobAssetReference<UnityS.Physics.Collider>>();

public void CreateBall(float3 position, sfloat radius, UnityS.Physics.Material material,
PhysicsParams physicsParams)
{
if (!ballColliders.TryGetValue((radius, material), out BlobAssetReference<UnityS.Physics.Collider> collider))
{
Expand All @@ -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<UnityS.Physics.Collider>> boxColliders = new Dictionary<(float3 size, UnityS.Physics.Material material), BlobAssetReference<UnityS.Physics.Collider>>();
public void CreateBox(float3 position, float3 size, quaternion rotation, UnityS.Physics.Material material, PhysicsParams physicsParams)
private Dictionary<(float3 size, UnityS.Physics.Material material), BlobAssetReference<UnityS.Physics.Collider>>
boxColliders =
new Dictionary<(float3 size, UnityS.Physics.Material material),
BlobAssetReference<UnityS.Physics.Collider>>();

public void CreateBox(float3 position, float3 size, quaternion rotation, UnityS.Physics.Material material,
PhysicsParams physicsParams)
{
if (!boxColliders.TryGetValue((size, material), out BlobAssetReference<UnityS.Physics.Collider> collider))
{
Expand Down Expand Up @@ -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<UnityS.Physics.Collider> collider,
public Entity CreateEntity(float3 position, quaternion rotation,
BlobAssetReference<UnityS.Physics.Collider> collider,
PhysicsParams physicsParams)
{
return CreatePhysicsBody(position, rotation, collider, physicsParams);
}

private readonly List<ComponentType> componentTypes = new List<ComponentType>(20);
public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation, BlobAssetReference<UnityS.Physics.Collider> collider,

public unsafe Entity CreatePhysicsBody(float3 position, quaternion orientation,
BlobAssetReference<UnityS.Physics.Collider> collider,
PhysicsParams physicsParams)
{
componentTypes.Clear();
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -298,4 +320,4 @@ public struct PhysicsParams
linearDamping = sfloat.FromRaw(0x3c23d70a),
angularDamping = sfloat.FromRaw(0x3d4ccccd)
};
}
}
1 change: 0 additions & 1 deletion Assets/Scripts/SoftFloat/math/float3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace UnityS.Mathematics
{
[DebuggerTypeProxy(typeof(float3.DebuggerProxy))]
[System.Serializable]
public partial struct float3 : System.IEquatable<float3>, IFormattable
{
public sfloat x;
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/SoftFloat/transforms/CompositeRotation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Unity.Burst;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
Expand Down Expand Up @@ -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;

Expand All @@ -51,7 +52,7 @@ struct ToCompositeRotation : IJobChunk
public ComponentTypeHandle<CompositeRotation> 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);
Expand Down Expand Up @@ -375,7 +376,7 @@ protected override void OnCreate()
});
}

protected override JobHandle OnUpdate(JobHandle inputDeps)
protected override void OnUpdate()
{
var compositeRotationType = GetComponentTypeHandle<CompositeRotation>(false);
var rotationType = GetComponentTypeHandle<Rotation>(true);
Expand All @@ -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);
}
}
}
26 changes: 10 additions & 16 deletions Assets/Scripts/SoftFloat/transforms/CompositeScale.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Unity.Burst;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
Expand Down Expand Up @@ -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;

Expand All @@ -47,7 +48,7 @@ struct ToCompositeScale : IJobChunk
public ComponentTypeHandle<CompositeScale> 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);
Expand Down Expand Up @@ -290,25 +291,18 @@ protected override void OnCreate()
});
}

protected override JobHandle OnUpdate(JobHandle inputDeps)
protected override void OnUpdate()
{
var compositeScaleType = GetComponentTypeHandle<CompositeScale>(false);
var scaleType = GetComponentTypeHandle<Scale>(true);
var scaleAxisType = GetComponentTypeHandle<NonUniformScale>(true);
var scalePivotTranslationType = GetComponentTypeHandle<ScalePivotTranslation>(true);
var scalePivotType = GetComponentTypeHandle<ScalePivot>(true);

var toCompositeScaleJob = new ToCompositeScale
{
CompositeScaleTypeHandle = compositeScaleType,
NonUniformScaleTypeHandle = scaleAxisType,
ScaleTypeHandle = scaleType,
ScalePivotTypeHandle = scalePivotType,
ScalePivotTranslationTypeHandle = scalePivotTranslationType,
CompositeScaleTypeHandle = GetComponentTypeHandle<CompositeScale>(false),
NonUniformScaleTypeHandle = GetComponentTypeHandle<NonUniformScale>(true),
ScaleTypeHandle = GetComponentTypeHandle<Scale>(true),
ScalePivotTypeHandle = GetComponentTypeHandle<ScalePivot>(true),
ScalePivotTranslationTypeHandle = GetComponentTypeHandle<ScalePivotTranslation>(true),
LastSystemVersion = LastSystemVersion
};
var toCompositeScaleJobHandle = toCompositeScaleJob.Schedule(m_Group, inputDeps);
return toCompositeScaleJobHandle;
Dependency = toCompositeScaleJob.ScheduleParallel(m_Group, Dependency);
}
}
}
22 changes: 11 additions & 11 deletions Assets/Scripts/SoftFloat/transforms/EndFrameTransformSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}

Expand All @@ -43,15 +43,15 @@ public class EndFrameCompositeRotationSystem : CompositeRotationSystem
[UpdateAfter(typeof(EndFrameCompositeRotationSystem))]
[UpdateAfter(typeof(EndFrameCompositeScaleSystem))]
[UpdateBefore(typeof(EndFrameLocalToParentSystem))]
public class EndFrameTRSToLocalToWorldSystem : TRSToLocalToWorldSystem
public partial class EndFrameTRSToLocalToWorldSystem : TRSToLocalToWorldSystem
{
}

[UnityEngine.ExecuteAlways]
[UpdateInGroup(typeof(TransformSystemGroup))]
[UpdateAfter(typeof(EndFrameParentSystem))]
[UpdateAfter(typeof(EndFrameCompositeRotationSystem))]
public class EndFrameParentScaleInverseSystem : ParentScaleInverseSystem
public partial class EndFrameParentScaleInverseSystem : ParentScaleInverseSystem
{
}

Expand All @@ -60,22 +60,22 @@ 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
{
}

[UnityEngine.ExecuteAlways]
[UpdateInGroup(typeof(TransformSystemGroup))]
[UpdateAfter(typeof(EndFrameTRSToLocalToWorldSystem))]
[UpdateAfter(typeof(EndFrameLocalToParentSystem))]
public class EndFrameWorldToLocalSystem : WorldToLocalSystem
public partial class EndFrameWorldToLocalSystem : WorldToLocalSystem
{
}
}
Loading