Skip to content

Commit 2ab3759

Browse files
authored
feat(lag): add method to simulate a subset of tracked objects. (#314)
1 parent 234fdbf commit 2ab3759

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

MLAPI/LagCompensation/LagCompensationManager.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using MLAPI.Exceptions;
@@ -28,22 +28,33 @@ public static class LagCompensationManager
2828
/// <param name="secondsAgo">The amount of seconds</param>
2929
/// <param name="action">The action to invoke when time is turned back</param>
3030
public static void Simulate(float secondsAgo, Action action)
31+
{
32+
Simulate(secondsAgo, SimulationObjects, action);
33+
}
34+
35+
/// <summary>
36+
/// Turns time back a given amount of second on the given objects, invokes an action and turns it back
37+
/// </summary>
38+
/// <param name="secondsAgo">The amount of seconds</param>
39+
/// <param name="simulatedObjects">The object to simulate back in time</param>
40+
/// <param name="action">The action to invoke when time is turned back</param>
41+
public static void Simulate(float secondsAgo, IList<TrackedObject> simulatedObjects, Action action)
3142
{
3243
if (!NetworkingManager.Singleton.IsServer)
3344
{
3445
throw new NotServerException("Only the server can perform lag compensation");
3546
}
36-
37-
for (int i = 0; i < SimulationObjects.Count; i++)
47+
48+
for (int i = 0; i < simulatedObjects.Count; i++)
3849
{
39-
SimulationObjects[i].ReverseTransform(secondsAgo);
50+
simulatedObjects[i].ReverseTransform(secondsAgo);
4051
}
4152

4253
action.Invoke();
4354

44-
for (int i = 0; i < SimulationObjects.Count; i++)
55+
for (int i = 0; i < simulatedObjects.Count; i++)
4556
{
46-
SimulationObjects[i].ResetStateTransform();
57+
simulatedObjects[i].ResetStateTransform();
4758
}
4859
}
4960

0 commit comments

Comments
 (0)