Skip to content

Commit

Permalink
Merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGadget1024 committed Jul 20, 2024
2 parents c67f639 + 86d8bc9 commit 75e7fea
Show file tree
Hide file tree
Showing 28 changed files with 4,232 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/RunUnityTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- 2019.4.40f1
- 2020.3.48f1
- 2021.3.38f1
- 2022.3.37f1
- 2022.3.38f1
- 2023.2.20f1
- 6000.0.10f1
- 6000.0.11f1

steps:
- name: Checkout repository
Expand Down
34 changes: 22 additions & 12 deletions Assets/Mirror/Core/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public struct NetworkIdentitySerialization
public int tick;
public NetworkWriter ownerWriter;
public NetworkWriter observersWriter;

public void ResetWriters()
{
ownerWriter.Position = 0;
observersWriter.Position = 0;
}
}

/// <summary>NetworkIdentity identifies objects across the network.</summary>
Expand Down Expand Up @@ -844,9 +850,9 @@ internal void OnStopLocalPlayer()
for (int i = 0; i < components.Length; ++i)
{
NetworkBehaviour component = components[i];
ulong nthBit = (1u << i);

bool dirty = component.IsDirty();
ulong nthBit = (1u << i);

// owner needs to be considered for both SyncModes, because
// Observers mode always includes the Owner.
Expand All @@ -857,14 +863,17 @@ internal void OnStopLocalPlayer()
if (initialState || (component.syncDirection == SyncDirection.ServerToClient && dirty))
ownerMask |= nthBit;

// observers need to be considered only in Observers mode
//
// for initial, it should always sync to observers.
// for delta, only if dirty.
// SyncDirection is irrelevant, as both are broadcast to
// observers which aren't the owner.
if (component.syncMode == SyncMode.Observers && (initialState || dirty))
observerMask |= nthBit;
// observers need to be considered only in Observers mode,
// otherwise they receive no sync data of this component ever.
if (component.syncMode == SyncMode.Observers)
{
// for initial, it should always sync to observers.
// for delta, only if dirty.
// SyncDirection is irrelevant, as both are broadcast to
// observers which aren't the owner.
if (initialState || dirty)
observerMask |= nthBit;
}
}

return (ownerMask, observerMask);
Expand All @@ -888,11 +897,13 @@ ulong ClientDirtyMask()

// on client, only consider owned components with SyncDirection to server
NetworkBehaviour component = components[i];
ulong nthBit = (1u << i);

if (isOwned && component.syncDirection == SyncDirection.ClientToServer)
{
// set the n-th bit if dirty
// shifting from small to large numbers is varint-efficient.
if (component.IsDirty()) mask |= (1u << i);
if (component.IsDirty()) mask |= nthBit;
}
}

Expand Down Expand Up @@ -1126,8 +1137,7 @@ internal NetworkIdentitySerialization GetServerSerializationAtTick(int tick)
)
{
// reset
lastSerialization.ownerWriter.Position = 0;
lastSerialization.observersWriter.Position = 0;
lastSerialization.ResetWriters();

// serialize
SerializeServer(false,
Expand Down
4 changes: 4 additions & 0 deletions Assets/Mirror/Core/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ static void Initialize()
static void AddTransportHandlers()
{
// += so that other systems can also hook into it (i.e. statistics)
#pragma warning disable CS0618 // Type or member is obsolete
Transport.active.OnServerConnected += OnTransportConnected;
#pragma warning restore CS0618 // Type or member is obsolete
Transport.active.OnServerConnectedWithAddress += OnTransportConnectedWithAddress;
Transport.active.OnServerDataReceived += OnTransportData;
Transport.active.OnServerDisconnected += OnTransportDisconnected;
Expand Down Expand Up @@ -264,7 +266,9 @@ public static void Shutdown()
static void RemoveTransportHandlers()
{
// -= so that other systems can also hook into it (i.e. statistics)
#pragma warning disable CS0618 // Type or member is obsolete
Transport.active.OnServerConnected -= OnTransportConnected;
#pragma warning restore CS0618 // Type or member is obsolete
Transport.active.OnServerConnectedWithAddress -= OnTransportConnectedWithAddress;
Transport.active.OnServerDataReceived -= OnTransportData;
Transport.active.OnServerDisconnected -= OnTransportDisconnected;
Expand Down
6 changes: 5 additions & 1 deletion Assets/Mirror/Core/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ public abstract class Transport : MonoBehaviour
public Action OnClientDisconnected;

// server //////////////////////////////////////////////////////////////
/// <summary>Called by Transport when a new client connected to the server.</summary>

// Deprecated 2024-07-20
[Obsolete("Use OnServerConnectedWithAddress and pass the remote client address instead")]
public Action<int> OnServerConnected;

/// <summary>Called by Transport when a new client connected to the server.</summary>
public Action<int, string> OnServerConnectedWithAddress;

/// <summary>Called by Transport when the server received a message from a client.</summary>
Expand Down
8 changes: 8 additions & 0 deletions Assets/Mirror/Examples/AutoLANClientController.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 75e7fea

Please sign in to comment.