working on actors
This commit is contained in:
@@ -12,11 +12,11 @@ namespace RebootReality.jelycho.Ropes {
|
||||
public class RopesManager : MonoBehaviour {
|
||||
[SerializeField] float m_RopeSegmentLength = 0.5f;
|
||||
[SerializeField] int m_ConstrainIterations = 50;
|
||||
|
||||
|
||||
[SerializeField] bool m_ShowGizmos = true;
|
||||
|
||||
readonly List<RopeData> m_Ropes = new List<RopeData>();
|
||||
|
||||
|
||||
public int RopesCount {
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get {
|
||||
@@ -45,9 +45,9 @@ namespace RebootReality.jelycho.Ropes {
|
||||
RopeConfig ropeConfig = RopeConfig.Default;
|
||||
ropeConfig.segmentLength = m_RopeSegmentLength;
|
||||
ropeConfig.numberOfConstrainIterations = m_ConstrainIterations;
|
||||
|
||||
|
||||
float deltaTime = Time.fixedDeltaTime;
|
||||
|
||||
|
||||
Profiler.BeginSample("RopesManager.SimulateRopes");
|
||||
NativeArray<JobHandle> jobHandles = new NativeArray<JobHandle>(m_Ropes.Count, Allocator.Temp);
|
||||
|
||||
@@ -73,21 +73,18 @@ namespace RebootReality.jelycho.Ropes {
|
||||
|
||||
Profiler.BeginSample("RopesManager.CalculateRopeBounds");
|
||||
// @TODO: figure out a way to avoid this job dependency chain.
|
||||
NativeArray<NativeArray<float3>> boundsArrays = new NativeArray<NativeArray<float3>>(m_Ropes.Count, Allocator.Temp);
|
||||
|
||||
NativeArray<NativeArray<float3>> boundsArrays =
|
||||
new NativeArray<NativeArray<float3>>(m_Ropes.Count, Allocator.Temp);
|
||||
|
||||
for (int i = 0; i < m_Ropes.Count; i++) {
|
||||
boundsArrays[i] = new NativeArray<float3>(2, Allocator.TempJob);
|
||||
|
||||
|
||||
CalculateRopeBoundsJob calculateBoundsJob = new CalculateRopeBoundsJob {
|
||||
Positions = m_Ropes[i].Positions,
|
||||
Bounds = boundsArrays[i]
|
||||
};
|
||||
|
||||
// if (i > 0) {
|
||||
// jobHandles[i] = calculateBoundsJob.Schedule(jobHandles[i - 1]);
|
||||
// } else {
|
||||
jobHandles[i] = calculateBoundsJob.Schedule();
|
||||
// }
|
||||
jobHandles[i] = calculateBoundsJob.Schedule();
|
||||
}
|
||||
JobHandle.CompleteAll(jobHandles);
|
||||
|
||||
@@ -100,7 +97,7 @@ namespace RebootReality.jelycho.Ropes {
|
||||
m_Ropes[i] = rope;
|
||||
}
|
||||
Profiler.EndSample();
|
||||
|
||||
|
||||
foreach (NativeArray<float3> boundsArray in boundsArrays) {
|
||||
boundsArray.Dispose();
|
||||
}
|
||||
@@ -111,11 +108,11 @@ namespace RebootReality.jelycho.Ropes {
|
||||
|
||||
// @TODO: finish the rope spawning logic.
|
||||
public void SpawnRope(float3 start, float3 end, bool lockFirst = false, bool lockLast = false) {
|
||||
int segmentsCount = (int)(math.distance(start, end) / m_RopeSegmentLength) + 1;
|
||||
int segmentsCount = (int) (math.distance(start, end) / m_RopeSegmentLength) + 1;
|
||||
NativeArray<float3> positions = new NativeArray<float3>(segmentsCount, Allocator.Temp);
|
||||
|
||||
|
||||
for (int i = 0; i < segmentsCount; ++i) {
|
||||
float t = (float)i / (segmentsCount - 1);
|
||||
float t = (float) i / (segmentsCount - 1);
|
||||
positions[i] = math.lerp(start, end, t);
|
||||
}
|
||||
|
||||
@@ -126,11 +123,11 @@ namespace RebootReality.jelycho.Ropes {
|
||||
}
|
||||
|
||||
public void SpawnLockedRope(float ropeLength, float3 start, float3 end) {
|
||||
int segmentsCount = (int)(ropeLength / m_RopeSegmentLength) + 1;
|
||||
int segmentsCount = (int) (ropeLength / m_RopeSegmentLength) + 1;
|
||||
NativeArray<float3> positions = new NativeArray<float3>(segmentsCount, Allocator.Temp);
|
||||
|
||||
|
||||
for (int i = 0; i < segmentsCount; ++i) {
|
||||
float t = (float)i / (segmentsCount - 1);
|
||||
float t = (float) i / (segmentsCount - 1);
|
||||
positions[i] = math.lerp(start, end, t);
|
||||
}
|
||||
|
||||
@@ -144,7 +141,7 @@ namespace RebootReality.jelycho.Ropes {
|
||||
public NativeArray<float3> PeekRopePositions(int index) {
|
||||
return m_Ropes[index].Positions;
|
||||
}
|
||||
|
||||
|
||||
static readonly Plane[] s_Planes = new Plane[6];
|
||||
|
||||
public bool IsRopeBoundsInFrustum(int index, Camera cam) {
|
||||
@@ -153,11 +150,11 @@ namespace RebootReality.jelycho.Ropes {
|
||||
GeometryUtility.CalculateFrustumPlanes(cam, s_Planes);
|
||||
return GeometryUtility.TestPlanesAABB(s_Planes, bound);
|
||||
}
|
||||
|
||||
|
||||
public Bounds GetRopeBounds(int index) {
|
||||
return m_Ropes[index].Bounds;
|
||||
}
|
||||
|
||||
|
||||
void Clear() {
|
||||
foreach (RopeData rope in m_Ropes) {
|
||||
rope.Dispose();
|
||||
@@ -171,7 +168,7 @@ namespace RebootReality.jelycho.Ropes {
|
||||
public NativeArray<float3> OldPositions;
|
||||
public NativeArray<bool> IsLocked;
|
||||
public Bounds Bounds;
|
||||
|
||||
|
||||
public int SegmentCount {
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get {
|
||||
@@ -201,13 +198,13 @@ namespace RebootReality.jelycho.Ropes {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[BurstCompile]
|
||||
struct SimulateRopeJob : IJobParallelFor {
|
||||
public NativeArray<float3> Positions;
|
||||
public NativeArray<float3> OldPositions;
|
||||
[ReadOnly] public NativeArray<bool> IsLocked;
|
||||
|
||||
|
||||
[ReadOnly] public float DeltaTime;
|
||||
[ReadOnly] public RopeConfig Config;
|
||||
|
||||
@@ -218,7 +215,7 @@ namespace RebootReality.jelycho.Ropes {
|
||||
|
||||
float3 position = Positions[index];
|
||||
float3 segmentPositionBeforeUpdate = position;
|
||||
|
||||
|
||||
position += (position - OldPositions[index]) * Config.dampingFactor;
|
||||
position.y += Config.gravity * DeltaTime;
|
||||
|
||||
@@ -239,7 +236,7 @@ namespace RebootReality.jelycho.Ropes {
|
||||
for (int i = 0; i < Positions.Length - 1; ++i) {
|
||||
float3 position = Positions[i];
|
||||
float3 nextPosition = Positions[i + 1];
|
||||
|
||||
|
||||
float currentDistance = math.distance(position, nextPosition);
|
||||
float difference = currentDistance - Config.segmentLength;
|
||||
float3 direction = math.normalize(position - nextPosition);
|
||||
@@ -254,15 +251,15 @@ namespace RebootReality.jelycho.Ropes {
|
||||
nextPosition += change;
|
||||
Positions[i + 1] = nextPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[BurstCompile]
|
||||
struct CalculateRopeBoundsJob: IJob {
|
||||
struct CalculateRopeBoundsJob : IJob {
|
||||
[ReadOnly] public NativeArray<float3> Positions;
|
||||
|
||||
|
||||
public NativeArray<float3> Bounds;
|
||||
|
||||
public void Execute() {
|
||||
|
||||
Reference in New Issue
Block a user