Skip to content

Commit

Permalink
fixes long standing issue with movement borking
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Jan 6, 2025
1 parent 7da8a29 commit 0cf19c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,10 @@ public void Update()
// Schedule multithreaded tasks
for (int Index = 0; Index < ReceiverCount; Index++)
{
try
{
if (ReceiverArray[Index] != null)
{
ReceiverArray[Index].Compute(TimeAsDouble);
}
}
catch (Exception ex)
{
// Log the error and continue with the next iteration
BasisDebug.LogError($"Error in Compute at index {Index}: {ex.Message} {ex.StackTrace}");
}
}
}
public void LateUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public partial class BasisNetworkReceiver : BasisNetworkSendBase
public quaternion OutputRotation;
public AvatarBuffer First;
public AvatarBuffer Last;
// public int PayloadCount = 0;
public static int BufferCapacityBeforeCleanup = 3;
public float interpolationTime;
public double TimeBeforeCompletion;
Expand All @@ -54,17 +53,52 @@ public void Compute(double TimeAsDouble)
{
if (HasAvatarInitalized)
{

// Calculate interpolation time
interpolationTime = Mathf.Clamp01((float)((TimeAsDouble - TimeInThePast) / TimeBeforeCompletion));
if(First == null)
{
if(Last != null)
{
First = Last;
PayloadQueue.TryDequeue(out Last);
BasisDebug.LogError("Last != null filled in gap", BasisDebug.LogTag.Networking);
}
else
{
PayloadQueue.TryDequeue(out First);
BasisDebug.LogError("Last and first are null replacing First!", BasisDebug.LogTag.Networking);
}
}
if(Last == null)
{
PayloadQueue.TryDequeue(out Last);
BasisDebug.LogError("Last == null tried to dequeue", BasisDebug.LogTag.Networking);

// PayloadCount = PayloadQueue.Count;
TargetVectors[0] = Last.Position; // Target position at index 0
OuputVectors[0] = First.Position; // Position at index 0
}
try
{
TargetVectors[0] = Last.Position; // Target position at index 0
OuputVectors[0] = First.Position; // Position at index 0

OuputVectors[1] = First.Scale; // Scale at index 1
TargetVectors[1] = Last.Scale; // Target scale at index 1
muscles.CopyFrom(First.Muscles);
targetMuscles.CopyFrom(Last.Muscles);
OuputVectors[1] = First.Scale; // Scale at index 1
TargetVectors[1] = Last.Scale; // Target scale at index 1
}
catch (Exception ex)
{
// Log the full exception details, including stack trace
BasisDebug.LogError($"Error in Vector Set: {ex.Message}\nStack Trace:\n{ex.StackTrace}");
}
try
{
muscles.CopyFrom(First.Muscles);
targetMuscles.CopyFrom(Last.Muscles);
}
catch (Exception ex)
{
// Log the full exception details, including stack trace
BasisDebug.LogError($"Error in Muscle Copy: {ex.Message}\nStack Trace:\n{ex.StackTrace}");
}
AvatarJob.Time = interpolationTime;

AvatarHandle = AvatarJob.Schedule();
Expand Down Expand Up @@ -107,12 +141,14 @@ public void Apply(double TimeAsDouble, float DeltaTime)
{
if (LogFirstError == false)
{
// Log the error and continue with the next iteration
//muting the error for now
BasisDebug.LogError($"Error in Apply : {ex.Message} {ex.StackTrace}");
}
else
{
// Log the full exception details, including stack trace
BasisDebug.LogError($"Error in Apply: {ex.Message}\nStack Trace:\n{ex.StackTrace}");

// If the exception has an inner exception, log it as well
if (ex.InnerException != null)
{
BasisDebug.LogError($"Inner Exception: {ex.InnerException.Message}\nStack Trace:\n{ex.InnerException.StackTrace}");
}
LogFirstError = true;
}
}
Expand Down Expand Up @@ -150,6 +186,11 @@ public void EnQueueAvatarBuffer(ref AvatarBuffer avatarBuffer)
}
public void ApplyPoseData(Animator animator, float3 Scale, float3 Position, quaternion Rotation, NativeArray<float> Muscles)
{
if(animator == null)
{
BasisDebug.LogError("Missing Animator!");
return;
}
// Directly adjust scaling by applying the inverse of the AvatarHumanScale
Vector3 Scaling = Vector3.one / animator.humanScale; // Initial scaling with human scale inverse

Expand Down

0 comments on commit 0cf19c3

Please sign in to comment.