Skip to content

Commit a07aa61

Browse files
committed
Merge branch 'master' of https://github.com/MidLevel/MLAPI
2 parents 699d18c + b6db47d commit a07aa61

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

MLAPI/Core/NetworkingManager.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class NetworkingManager : MonoBehaviour
4141
public float NetworkTime => Time.unscaledTime + currentNetworkTimeOffset;
4242
private float networkTimeOffset;
4343
private float currentNetworkTimeOffset;
44-
private bool networkTimeInitialized;
4544
/// <summary>
4645
/// Gets or sets if the NetworkingManager should be marked as DontDestroyOnLoad
4746
/// </summary>
@@ -336,7 +335,6 @@ private void Init(bool server)
336335
LocalClientId = 0;
337336
networkTimeOffset = 0f;
338337
currentNetworkTimeOffset = 0f;
339-
networkTimeInitialized = false;
340338
lastEventTickTime = 0f;
341339
lastReceiveTickTime = 0f;
342340
eventOvershootCounter = 0f;
@@ -734,17 +732,14 @@ private void Update()
734732
}
735733
}
736734

737-
internal void UpdateNetworkTime(ulong clientId, float netTime, float receiveTime, bool onlyIfNotInitialized = false)
735+
internal void UpdateNetworkTime(ulong clientId, float netTime, float receiveTime, bool warp = false)
738736
{
739-
if (onlyIfNotInitialized && networkTimeInitialized)
740-
return;
741737
float rtt = NetworkConfig.NetworkTransport.GetCurrentRtt(clientId) / 1000f;
742738
networkTimeOffset = netTime - receiveTime + rtt / 2f;
743-
if (!networkTimeInitialized) {
739+
if (warp) {
744740
currentNetworkTimeOffset = networkTimeOffset;
745-
networkTimeInitialized = true;
746741
}
747-
if (LogHelper.CurrentLogLevel <= LogLevel.Developer) LogHelper.LogInfo($"Received network time {netTime}, RTT to server is {rtt}, setting offset to {networkTimeOffset} (delta {networkTimeOffset - currentNetworkTimeOffset})");
742+
if (LogHelper.CurrentLogLevel <= LogLevel.Developer) LogHelper.LogInfo($"Received network time {netTime}, RTT to server is {rtt}, {(warp ? "setting" : "smearing")} offset to {networkTimeOffset} (delta {networkTimeOffset - currentNetworkTimeOffset})");
748743
}
749744

750745
internal void SendConnectionRequest()

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

docs/_docs/advanced-topics/bitwriter-bitreader-bitstream.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MyEnum value = (Myenum)reader.ReadBits(3);
4545
```
4646

4747
#### Performance concideration
48-
When the stream is not aligned, (BitAlgiend == false, this occurs when writing bits that does fill the whole byte, or when writing bools as they are written as bits), performance is decreased for each write and read. This is only a big concern if you are about to write a large amount of data after not being aligned. To solve this, the BitWriter allows you to "WritePadBits" and the BitReader then lets you skip those bits with "SkipPadBits" to align the stream to the nearest byte.
48+
When the stream is not aligned, (BitAligned == false, this occurs when writing bits that does fill the whole byte, or when writing bools as they are written as bits), performance is decreased for each write and read. This is only a big concern if you are about to write a large amount of data after not being aligned. To solve this, the BitWriter allows you to "WritePadBits" and the BitReader then lets you skip those bits with "SkipPadBits" to align the stream to the nearest byte.
4949

5050
```csharp
5151
writer.WriteBool(true); //Now the stream is no longer aligned. Every byte has to be offset by 1 bit.
@@ -71,4 +71,4 @@ using (PooledBitWriter writer = PooledBitWriter.Get(myStreamToWriteTo))
7171
{
7272
// Write here
7373
}
74-
```
74+
```

docs/_docs/the-basics/networkedvar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Since the NetworkedVar container is a wrapper container around the value, the va
1515
<h3 class="panel-title">Disclaimer</h3>
1616
</div>
1717
<div class="panel-body">
18-
The NetworkedVar, NetworkedList and NetworkedDictionary implementations are <b>primarly</b> designed as samples showing to do create INetworkedVar structures. The NetworkedVar container is however concidered production ready for simple types.
18+
The NetworkedVar, NetworkedList and NetworkedDictionary implementations are <b>primarily</b> designed as samples showing how to create INetworkedVar structures. The NetworkedVar container is however concidered production ready for simple types.
1919
</div>
2020
</div>
2121

@@ -38,4 +38,4 @@ If you want values to be synced only once (at spawn), the built-in containers se
3838
### Serialization
3939
Since the NetworkedVar class is a generic, editor serialization is NOT supported, it's only avalible through editor scripts for viewing the values. To get proper serialization. A clone of the NetworkedVar implementation has to be done for each type you wish to use. Ex: NetworkedVarInt where you replace all the usages of T with int.
4040

41-
The MLAPI provides a few default serializable implementations of the NetworkedVar, they are called NetworkedVar<TYPE> where "<TYPE>" is the type.
41+
The MLAPI provides a few default serializable implementations of the NetworkedVar, they are called NetworkedVar<TYPE> where "<TYPE>" is the type.

docs/_docs/the-basics/object-ownership.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Object Ownership
33
permalink: /wiki/object-ownership/
44
---
55

6-
Each NetworkedObject is be owned by a specific client. This can be any client or the server.
6+
Each NetworkedObject is owned by a specific client. This can be any client or the server.
77

88
Giving ownership of an object can be done like this
99
```csharp
@@ -15,10 +15,10 @@ The default behavior is that an object is owned by the server. To give ownership
1515
GetComponent<NetworkedObject>().RemoveOwnership();
1616
```
1717

18-
When you are owner of an object. You can check for ``IsOwner`` in any NetworkedBehaviour, similar to how player objects can do ``IsLocalPlayer``
18+
When you are owner of an object, you can check for ``IsOwner`` in any NetworkedBehaviour, similar to how player objects can do ``IsLocalPlayer``
1919

2020
## Object destruction
21-
When a client disconnects. All objects owned by that client will be destroyed. If you don't want that. (Ex. if you want the objects to be dropped), you can remove ownership just before they are destroyed.
21+
When a client disconnects, all objects owned by that client will be destroyed. If you don't want that (Ex. if you want the objects to be dropped), you can remove ownership just before they are destroyed.
2222

2323

24-
Simply remove the ownership in the OnDestroy method on the player object that owns the object and remove ownership there. That will be handled before the owned object is destroyed.
24+
Simply remove the ownership in the OnDestroy method on the player object that owns the object and remove ownership there. That will be handled before the owned object is destroyed.

docs/_docs/the-basics/object-visibility.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ permalink: /wiki/object-visibility/
44
---
55

66
Starting with MLAPI version 6.0.0, clients have no explicit knowledge of all objects or clients that are connected to the server.
7-
This allows you to only show a subset of objects to any client and any given time. To allow this, a visibility API was introduced
7+
This allows you to only show a subset of objects to any client at any given time. To allow this, a visibility API was introduced
88
to the NetworkedObject component and consists of 4 parts.
99

1010

@@ -41,4 +41,4 @@ and
4141
```csharp
4242
NetworkedObject netObject = GetComponent<NetworkedObject>();
4343
netObject.NetworkHide(clientIdToHideFrom);
44-
```
44+
```

docs/_docs/the-basics/scene-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Scene Management
33
permalink: /wiki/scene-management/
44
---
55

6-
The MLAPI can manage synchronized scene management for you. To use this, it first has to be enabled in NetworkingConfiguration. EnableSceneSwitching has to be set to true and all scenes that are going to be used during Networking has to be registered. The NetworkingConfiguration.RegisteredScenes list has to be populated with all scene names, this a simple security measure to ensure rouge servers don't request client's to switch to sensitive scenes.
6+
The MLAPI can manage synchronized scene management for you. To use this, it first has to be enabled in NetworkingConfiguration. EnableSceneSwitching has to be set to true and all scenes that are going to be used during Networking have to be registered. The NetworkingConfiguration.RegisteredScenes list has to be populated with all scene names, this a simple security measure to ensure rogue servers don't request client's to switch to sensitive scenes.
77

88
Note:
99
_The scene that is active when the Server is started has to be registered_
@@ -12,4 +12,4 @@ _The scene that is active when the Server is started has to be registered_
1212
```csharp
1313
//This can only be called on the server
1414
NetworkSceneManager.SwitchScene(mySceneName);
15-
```
15+
```

0 commit comments

Comments
 (0)