Skip to content

Commit bbc7f27

Browse files
committed
further improvements
1 parent cb23eea commit bbc7f27

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ public static void SimulateNetworkCompute(float UnscaledDeltaTime)
165165
BasisNetworkPlayers.PublishReceiversSnapshot();
166166

167167
BoneJobSystem = RemoteBoneJobSystem.Schedule(); // will always be a frame behind
168+
169+
UnscaledDeltaTime = Math.Max(UnscaledDeltaTime, 0f);
170+
171+
if (BasisNetworkPlayers.ReceiverCount > BasisRemoteNetworkDriver.FixedCapacity)
172+
{
173+
BasisDebug.LogError($"Exceeded Fixed Capacity! {BasisNetworkPlayers.ReceiverCount} > {BasisRemoteNetworkDriver.FixedCapacity}", BasisDebug.LogTag.Networking);
174+
return;
175+
}
176+
168177
for (int Index = 0; Index < BasisNetworkPlayers.ReceiverCount; Index++)
169178
{
170179
BasisNetworkPlayers.ReceiversSnapshot[Index].Compute(UnscaledDeltaTime);

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class BasisNetworkReceiver : BasisNetworkPlayer
4141
private float interpolationTime = 0f; // 0..1 over current->next window
4242

4343
public bool HasBufferHolds;
44-
public bool PassedSimulate = false;
4544

4645
// ---------------- staging (ring buffer) ----------------
4746
private const int MaxStage = 64;
@@ -180,16 +179,12 @@ public void Compute(float unscaledDeltaTime)
180179
{
181180
windowDuration = 1e-3;
182181
}
183-
184-
double step = Math.Max(unscaledDeltaTime, 0.0);
185-
186-
int depth = _stagedRing.Count;
187-
float rate = 1f + CatchupGain * (depth - TargetJitterDepth);
182+
float rate = 1f + CatchupGain * (StagedCount - TargetJitterDepth);
188183
rate = Mathf.Clamp(rate, MinPlaybackRate, MaxPlaybackRate);
189-
interpolationTime += (float)((step / windowDuration) * rate);
190-
PassedSimulate = BasisRemoteNetworkDriver.SetFrameTiming(playerId, interpolationTime, unscaledDeltaTime);
184+
interpolationTime += (float)(((double)unscaledDeltaTime / windowDuration) * rate);
185+
BasisRemoteNetworkDriver.SetFrameTiming(playerId, interpolationTime, unscaledDeltaTime);
191186

192-
if (PassedSimulate && SentLatest)
187+
if (SentLatest)
193188
{
194189

195190
BasisRemoteNetworkDriver.SetFrameInputs(
@@ -201,24 +196,26 @@ public void Compute(float unscaledDeltaTime)
201196
);
202197

203198
BasisRemoteNetworkDriver.SetMuscleWindow(playerId, first.Muscles, last.Muscles);
199+
IsDataReady = true;
204200
SentLatest = false;
205201
}
206202
}
207203
}
208-
204+
public bool IsDataReady = false;
209205
/// <summary>
210206
/// Main-thread application step. Pulls posed outputs from the driver and applies
211207
/// body position/rotation/muscles to the avatar via PoseHandler.
212208
/// </summary>
213209
public void Apply()
214210
{
215-
if (PassedSimulate)
211+
if (IsDataReady)
216212
{
217213
// These outputs should be stable when simulate passed.
218214
BasisRemoteNetworkDriver.GetOutputs_NoAlloc(playerId, out bool outscale, out var ApplyingRotation, out float3 scaledBody);
219-
BasisRemoteNetworkDriver.GetMuscleArray(playerId,ref HumanPose,EyesAndMouth,EyesAndMouthOffset,EyeAndMouthCountInBytes);
215+
BasisRemoteNetworkDriver.GetMuscleArray(playerId, ref HumanPose, EyesAndMouth, EyesAndMouthOffset, EyeAndMouthCountInBytes);
220216
HumanPose.bodyPosition = scaledBody;
221217
HumanPose.bodyRotation = ApplyingRotation;
218+
222219
if (outscale)
223220
{
224221
ApplyScale();
@@ -231,9 +228,8 @@ public void Apply()
231228
DidLastAvatarTransformChanged = false;
232229
}
233230
}
234-
PassedSimulate = false;
235231
}
236-
if (hasRequiredData)
232+
if (IsDataReady && hasRequiredData)
237233
{
238234
PoseHandler.SetHumanPose(ref HumanPose);
239235
if (HasOverridenDestination)
@@ -264,8 +260,6 @@ public override void Initialize()
264260
StagedCount = 0;
265261
ClearAndRelease();
266262
interpolationTime = 0f;
267-
PassedSimulate = false;
268-
269263
// Clear any packets that arrived before init (rare, but safe)
270264
while (PayloadQueue.TryDequeue(out var buf))
271265
{
@@ -349,7 +343,6 @@ public override void DeInitialize()
349343
}
350344

351345
AudioReceiverModule?.OnDestroy();
352-
PassedSimulate = false;
353346
}
354347

355348
public void ReceiveNetworkAudio(ServerAudioSegmentMessage msg)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ public static void Shutdown()
121121
/// </summary>
122122
public static bool SetFrameTiming(int index, float interpolationTime, float deltaTimeSeconds)
123123
{
124-
if ((uint)index >= FixedCapacity)
125-
{
126-
BasisDebug.LogError("Exceeded Fixed Capacity!", BasisDebug.LogTag.Networking);
127-
return false;
128-
}
129-
130124
_interpolationTimes[index] = interpolationTime;
131125
_deltaTimes[index] = deltaTimeSeconds;
132126

0 commit comments

Comments
 (0)