Skip to content

Commit 310a5eb

Browse files
committed
the current networking is jank
i will attempt more fixes tomorrow on a seperate branch, crazy painful
1 parent 5c975ec commit 310a5eb

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

Basis/Packages/com.basis.framework/Networking/BasisNetworkManagement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static bool IsMainThread()
156156
/// Simulates network computation step (state updates, bone drivers, profiler update).
157157
/// </summary>
158158
/// <param name="UnscaledDeltaTime">Delta time since last tick (unscaled).</param>
159-
public static void SimulateNetworkCompute(float UnscaledDeltaTime)
159+
public static void SimulateNetworkCompute(double UnscaledDeltaTime)
160160
{
161161
if (!NetworkRunning)
162162
{
@@ -168,7 +168,7 @@ public static void SimulateNetworkCompute(float UnscaledDeltaTime)
168168
BoneJobSystem = RemoteBoneJobSystem.Schedule(); // will always be a frame behind
169169

170170
UnscaledDeltaTime = Math.Max(UnscaledDeltaTime, 0f);
171-
if (math.isnan(UnscaledDeltaTime) || UnscaledDeltaTime <= 0 || math.isfinite(UnscaledDeltaTime))
171+
if (math.isnan(UnscaledDeltaTime) || math.isfinite(UnscaledDeltaTime))
172172
{
173173
UnscaledDeltaTime = 0;
174174
}

Basis/Packages/com.basis.framework/Networking/Recievers/BasisNetworkReceiver.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class BasisNetworkReceiver : BasisNetworkPlayer
3838
public float[] EyesAndMouth = new float[] { 0, 0, 0, 0, 1, 0 }; // default neutral eyes, mouth open=1 for breathing
3939
public float3 ApplyingScale;
4040

41-
private float interpolationTime = 0f; // 0..1 over current->next window
41+
private double interpolationTime = 0f; // 0..1 over current->next window
4242

4343
public bool HasBufferHolds;
4444

@@ -68,7 +68,7 @@ public class BasisNetworkReceiver : BasisNetworkPlayer
6868
/// Main-thread simulation step. Pulls packets, maintains interpolation window,
6969
/// computes interpolationTime, and feeds inputs to the network driver.
7070
/// </summary>
71-
public void Compute(float unscaledDeltaTime)
71+
public void Compute(double unscaledDeltaTime)
7272
{
7373
// expected briefly on join
7474
if (Player.BasisAvatar == null)
@@ -181,12 +181,12 @@ public void Compute(float unscaledDeltaTime)
181181
}
182182
float rate = 1f + CatchupGain * (StagedCount - TargetJitterDepth);
183183
rate = Mathf.Clamp(rate, MinPlaybackRate, MaxPlaybackRate);
184-
interpolationTime += (float)(((double)unscaledDeltaTime / windowDuration) * rate);
185-
if(math.isnan(interpolationTime) || interpolationTime <= 0 || math.isfinite(interpolationTime))
184+
interpolationTime += ((double)unscaledDeltaTime / windowDuration * (double)rate);
185+
if (math.isnan(interpolationTime) || math.isfinite(interpolationTime))
186186
{
187-
interpolationTime = 1;
187+
interpolationTime = 1;
188188
}
189-
BasisRemoteNetworkDriver.SetFrameTiming(playerId, interpolationTime, unscaledDeltaTime);
189+
BasisRemoteNetworkDriver.SetFrameTiming(playerId, interpolationTime,unscaledDeltaTime);
190190

191191
if (SentLatest)
192192
{

Basis/Packages/com.basis.framework/Networking/Recievers/BasisRemoteNetworkDriver.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public static class BasisRemoteNetworkDriver
2121
static NativeArray<quaternion> _prevRotations;
2222
static NativeArray<quaternion> _targetRotations;
2323

24-
static NativeArray<float> _interpolationTimes; // 0..1
25-
static NativeArray<float> _deltaTimes; // NEW: seconds (real dt for filters)
24+
static NativeArray<double> _interpolationTimes; // 0..1
25+
static NativeArray<double> _deltaTimes; // NEW: seconds (real dt for filters)
2626

2727
static NativeArray<float3> _outPositions;
2828
static NativeArray<float3> _outScales;
@@ -116,9 +116,9 @@ public static void Shutdown()
116116
/// Write timing inputs for a given index (0..FixedCapacity-1).
117117
/// interpolationTime is 0..1 blend factor, deltaTimeSeconds is REAL seconds-per-frame for filters.
118118
/// </summary>
119-
public static void SetFrameTiming(int index, float interpolationTime, float deltaTimeSeconds)
119+
public static void SetFrameTiming(int index, double interpolationTime, double deltaTimeSeconds)
120120
{
121-
_interpolationTimes[index] = interpolationTime;
121+
_interpolationTimes[index] = (float)interpolationTime;
122122
_deltaTimes[index] = deltaTimeSeconds;
123123
}
124124

@@ -258,8 +258,8 @@ static void AllocateAll(int capacity)
258258
_prevRotations = new NativeArray<quaternion>(capacity, _allocator, NativeArrayOptions.UninitializedMemory);
259259
_targetRotations = new NativeArray<quaternion>(capacity, _allocator, NativeArrayOptions.UninitializedMemory);
260260

261-
_interpolationTimes = new NativeArray<float>(capacity, _allocator, NativeArrayOptions.ClearMemory);
262-
_deltaTimes = new NativeArray<float>(capacity, _allocator, NativeArrayOptions.UninitializedMemory); // NEW
261+
_interpolationTimes = new NativeArray<double>(capacity, _allocator, NativeArrayOptions.ClearMemory);
262+
_deltaTimes = new NativeArray<double>(capacity, _allocator, NativeArrayOptions.UninitializedMemory); // NEW
263263

264264
_outPositions = new NativeArray<float3>(capacity, _allocator, NativeArrayOptions.UninitializedMemory);
265265
_outScales = new NativeArray<float3>(capacity, _allocator, NativeArrayOptions.UninitializedMemory);
@@ -328,7 +328,7 @@ public struct BasisOneEuroFilterParallelJob : IJobParallelFor
328328
[WriteOnly] public NativeArray<float> OutputValues;
329329

330330
// NEW: per-player real dt seconds (length == numPlayers)
331-
[ReadOnly] public NativeArray<float> DeltaTimeSeconds;
331+
[ReadOnly] public NativeArray<double> DeltaTimeSeconds;
332332

333333
public NativeArray<float2> PositionFilters; // x = previous input, y = previous output
334334
public NativeArray<float2> DerivativeFilters; // x = previous derivative input, y = previous derivative output
@@ -343,35 +343,35 @@ public void Execute(int index)
343343
{
344344
int playerIndex = MuscleCountPerAvatar > 0 ? (index / MuscleCountPerAvatar) : 0;
345345

346-
float dt = math.max(DeltaTimeSeconds[playerIndex], 1e-3f);
347-
float frequency = math.rcp(dt);
346+
double dt = math.max(DeltaTimeSeconds[playerIndex], 1e-3f);
347+
double frequency = math.rcp(dt);
348348

349349
float inputValue = InputValues[index];
350350

351351
float prevFiltered = PositionFilters[index].y;
352352
float prevRaw = PositionFilters[index].x;
353353

354-
float dValue = (inputValue - prevRaw) * frequency;
354+
double dValue = ((inputValue - prevRaw) * frequency);
355355

356-
float alphaD = Alpha(DerivativeCutoff, frequency);
356+
double alphaD = Alpha(DerivativeCutoff, frequency);
357357
float prevDerivFiltered = DerivativeFilters[index].y;
358-
float edValue = alphaD * dValue + (1f - alphaD) * prevDerivFiltered;
358+
double edValue = alphaD * dValue + (1f - alphaD) * prevDerivFiltered;
359359

360-
float cutoff = MinCutoff + Beta * math.abs(edValue);
361-
float alphaX = Alpha(cutoff, frequency);
360+
double cutoff = MinCutoff + Beta * math.abs(edValue);
361+
double alphaX = Alpha(cutoff, frequency);
362362

363-
float filtered = alphaX * inputValue + (1f - alphaX) * prevFiltered;
363+
double filtered = alphaX * inputValue + (1f - alphaX) * prevFiltered;
364364

365-
OutputValues[index] = filtered;
366-
PositionFilters[index] = new float2(inputValue, filtered);
367-
DerivativeFilters[index] = new float2(dValue, edValue);
365+
OutputValues[index] = (float)filtered;
366+
PositionFilters[index] = new float2(inputValue, (float)filtered);
367+
DerivativeFilters[index] = new float2((float)dValue, (float)edValue);
368368
}
369369

370370
[MethodImpl(MethodImplOptions.AggressiveInlining)]
371-
private static float Alpha(float cutoff, float frequency)
371+
private static double Alpha(double cutoff, double frequency)
372372
{
373-
float te = math.rcp(frequency);
374-
float tau = math.rcp(2f * math.PI * math.max(cutoff, 1e-4f));
373+
double te = math.rcp(frequency);
374+
double tau = math.rcp(2f * math.PI * math.max(cutoff, 1e-4f));
375375
return math.rcp(1f + tau / te);
376376
}
377377
}
@@ -388,7 +388,7 @@ public struct UpdateAllAvatarsJob : IJobParallelFor
388388
[ReadOnly] public NativeArray<quaternion> PreviousRotations;
389389
[ReadOnly] public NativeArray<quaternion> TargetRotations;
390390

391-
[ReadOnly] public NativeArray<float> InterpolationTimes;
391+
[ReadOnly] public NativeArray<double> InterpolationTimes;
392392

393393
[WriteOnly] public NativeArray<float3> OutputPositions;
394394
[WriteOnly] public NativeArray<float3> OutputScales;
@@ -398,7 +398,7 @@ public struct UpdateAllAvatarsJob : IJobParallelFor
398398

399399
public void Execute(int index)
400400
{
401-
float t = InterpolationTimes[index];
401+
float t = (float)InterpolationTimes[index];
402402
if (!math.isfinite(t))
403403
{
404404
t = 0f;
@@ -424,7 +424,7 @@ public struct UpdateAllAvatarMusclesJob : IJobParallelFor
424424
{
425425
[ReadOnly] public NativeArray<float> PreviousMuscles;
426426
[ReadOnly] public NativeArray<float> TargetMuscles;
427-
[ReadOnly] public NativeArray<float> InterpolationTimes;
427+
[ReadOnly] public NativeArray<double> InterpolationTimes;
428428

429429
[WriteOnly] public NativeArray<float> OutputMuscles;
430430

@@ -433,9 +433,9 @@ public struct UpdateAllAvatarMusclesJob : IJobParallelFor
433433
public void Execute(int index)
434434
{
435435
int playerIndex = index / MuscleCountPerAvatar;
436-
float t = InterpolationTimes[playerIndex];
436+
double t = InterpolationTimes[playerIndex];
437437
t = math.clamp(t, 0f, 1f);
438-
OutputMuscles[index] = math.lerp(PreviousMuscles[index], TargetMuscles[index], t);
438+
OutputMuscles[index] = (float)math.lerp(PreviousMuscles[index], TargetMuscles[index], t);
439439
}
440440
}
441441

0 commit comments

Comments
 (0)