-
Notifications
You must be signed in to change notification settings - Fork 459
feat: host tells client which IDs it uses for INetworkMessages #2103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e5ecbe4
Reordering messages when host and client have different sets
jeffreyrainy 89648b6
Reordering messages when host and client have different sets (working)
jeffreyrainy 1dcd9c1
style: improved comments and fixed coding convention
jeffreyrainy 0be53b1
fix: not depending on the NetworkManager singleton
jeffreyrainy d5a359d
Merge branch 'develop' into feat/message-id-ordering
jeffreyrainy 4496a31
correcting the approach so that it works even if some of the priority…
jeffreyrainy c7c5f3d
Update com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
jeffreyrainy e2c91ed
Using XXHash.Hash32() instead of String.GetHashCode()
jeffreyrainy 418cc88
Merge branch 'feat/message-id-ordering' of github.com:Unity-Technolog…
jeffreyrainy fc0cd45
adding test and reverting unneeded private->internal change
jeffreyrainy e8a3905
Code review comments
jeffreyrainy 98c8035
minor coding style
jeffreyrainy 51f0240
More code review changes
jeffreyrainy 53992a7
coding convention
jeffreyrainy a161f89
final adjustment
jeffreyrainy f1493eb
more final adjustment
jeffreyrainy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
com.unity.netcode.gameobjects/Runtime/Messaging/Messages/OrderingMessage.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
|
||
namespace Unity.Netcode | ||
{ | ||
/// <summary> | ||
/// Upon connecting, the host sends a series of OrderingMessage to the client so that it can make sure both sides | ||
/// have the same message types in the same positions in | ||
/// - MessagingSystem.m_MessageHandlers | ||
/// - MessagingSystem.m_ReverseTypeMap | ||
/// even if one side has extra messages (compilation, version, patch, or platform differences, etc...) | ||
/// | ||
/// The ConnectionRequestedMessage, ConnectionApprovedMessage and OrderingMessage are prioritized at the beginning | ||
/// of the mapping, to guarantee they can be exchanged before the two sides share their ordering | ||
/// The sorting used in also stable so that even if MessageType names share hashes, it will work most of the time | ||
/// </summary> | ||
internal struct OrderingMessage : INetworkMessage | ||
jeffreyrainy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public int Order; | ||
public uint Hash; | ||
|
||
public void Serialize(FastBufferWriter writer) | ||
{ | ||
if (!writer.TryBeginWrite(FastBufferWriter.GetWriteSize(Order) + FastBufferWriter.GetWriteSize(Hash))) | ||
{ | ||
throw new OverflowException($"Not enough space in the buffer to write {nameof(OrderingMessage)}"); | ||
} | ||
|
||
writer.WriteValue(Order); | ||
writer.WriteValue(Hash); | ||
} | ||
|
||
public bool Deserialize(FastBufferReader reader, ref NetworkContext context) | ||
{ | ||
if (!reader.TryBeginRead(FastBufferWriter.GetWriteSize(Order) + FastBufferWriter.GetWriteSize(Hash))) | ||
{ | ||
throw new OverflowException($"Not enough data in the buffer to read {nameof(OrderingMessage)}"); | ||
} | ||
|
||
reader.ReadValue(out Order); | ||
reader.ReadValue(out Hash); | ||
|
||
return true; | ||
} | ||
|
||
public void Handle(ref NetworkContext context) | ||
{ | ||
((NetworkManager)context.SystemOwner).MessagingSystem.ReorderMessage(Order, Hash); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Runtime/Messaging/Messages/OrderingMessage.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.