Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Unity.Netcode
public class NetworkList<T> : NetworkVariableSerialization<T> where T : unmanaged, IEquatable<T>
{
private NativeList<T> m_List = new NativeList<T>(64, Allocator.Persistent);
private NativeList<T> m_ListAtLastReset = new NativeList<T>(64, Allocator.Persistent);
private NativeList<NetworkListEvent<T>> m_DirtyEvents = new NativeList<NetworkListEvent<T>>(64, Allocator.Persistent);

/// <summary>
Expand Down Expand Up @@ -41,7 +42,11 @@ public NetworkList(IEnumerable<T> values = default,
public override void ResetDirty()
{
base.ResetDirty();
m_DirtyEvents.Clear();
if (m_DirtyEvents.Length > 0)
{
m_DirtyEvents.Clear();
m_ListAtLastReset.CopyFrom(m_List);
}
}

/// <inheritdoc />
Expand Down Expand Up @@ -109,10 +114,10 @@ public override void WriteDelta(FastBufferWriter writer)
/// <inheritdoc />
public override void WriteField(FastBufferWriter writer)
{
writer.WriteValueSafe((ushort)m_List.Length);
for (int i = 0; i < m_List.Length; i++)
writer.WriteValueSafe((ushort)m_ListAtLastReset.Length);
for (int i = 0; i < m_ListAtLastReset.Length; i++)
{
Write(writer, m_List[i]);
Write(writer, m_ListAtLastReset[i]);
}
}

Expand Down Expand Up @@ -454,6 +459,7 @@ public int LastModifiedTick
public override void Dispose()
{
m_List.Dispose();
m_ListAtLastReset.Dispose();
m_DirtyEvents.Dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,12 @@ public override bool StartClient()
return false;
}

return ClientBindAndConnect();
var succeeded = ClientBindAndConnect();
if (!succeeded)
{
Shutdown();
}
return succeeded;
}

public override bool StartServer()
Expand All @@ -1057,12 +1062,23 @@ public override bool StartServer()
return false;
}

bool succeeded;
switch (m_ProtocolType)
{
case ProtocolType.UnityTransport:
return ServerBindAndListen(ConnectionData.ListenEndPoint);
succeeded = ServerBindAndListen(ConnectionData.ListenEndPoint);
if (!succeeded)
{
Shutdown();
}
return succeeded;
case ProtocolType.RelayUnityTransport:
return StartRelayServer();
succeeded = StartRelayServer();
if (!succeeded)
{
Shutdown();
}
return succeeded;
default:
return false;
}
Expand Down