-
Notifications
You must be signed in to change notification settings - Fork 461
refactor: channel internally represented with bytes vs. strings [MTT-… #444
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
5 commits
Select commit
Hold shift + click to select a range
acffa02
refactor: channel internally represented with bytes vs. strings [MTT-…
mattwalsh-unity 460300b
proper channel default in custom message manager
mattwalsh-unity 2b745c3
cleaner and friendlier comment
mattwalsh-unity 3b6bfa7
develop merge conflict fix
mattwalsh-unity 7475aca
added jira comment
mattwalsh-unity 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
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| using MLAPI.Serialization; | ||
| using MLAPI.Serialization.Pooled; | ||
| using MLAPI.Spawning; | ||
| using MLAPI.Transports; | ||
| using BitStream = MLAPI.Serialization.BitStream; | ||
| using Unity.Profiling; | ||
|
|
||
|
|
@@ -38,11 +39,6 @@ internal enum NExec | |
| Client = 2 | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This is a temporary solution for channel names and the below hardcoded value might not be mandatory in the future. | ||
| /// </summary> | ||
| private const string StandardRpc_ChannelName = "STDRPC"; | ||
|
Comment on lines
-41
to
-44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like seeing this go :) |
||
|
|
||
| #pragma warning disable 414 | ||
| // RuntimeAccessModifiersILPP will make this `protected` | ||
| internal NExec __nexec = NExec.None; | ||
|
|
@@ -53,7 +49,7 @@ internal BitWriter BeginSendServerRpc(ServerRpcSendParams sendParams, bool isRel | |
| { | ||
| var rpcQueueContainer = NetworkingManager.Singleton.rpcQueueContainer; | ||
|
|
||
| var writer = rpcQueueContainer.BeginAddQueueItemToOutboundFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, StandardRpc_ChannelName, 0, NetworkingManager.Singleton.ServerClientId, null); | ||
| var writer = rpcQueueContainer.BeginAddQueueItemToOutboundFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, Transport.MLAPI_STDRPC_CHANNEL, 0, NetworkingManager.Singleton.ServerClientId, null); | ||
|
|
||
| if(!rpcQueueContainer.IsUsingBatching()) | ||
| { | ||
|
|
@@ -93,7 +89,7 @@ internal BitWriter BeginSendClientRpc(ClientRpcSendParams sendParams, bool isRel | |
| //This will start a new queue item entry and will then return the writer to the current frame's stream | ||
| var rpcQueueContainer = NetworkingManager.Singleton.rpcQueueContainer; | ||
|
|
||
| var writer = rpcQueueContainer.BeginAddQueueItemToOutboundFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, StandardRpc_ChannelName, 0, NetworkId, sendParams.TargetClientIds ?? NetworkingManager.Singleton.ConnectedClientsList.Select(c => c.ClientId).ToArray()); | ||
| var writer = rpcQueueContainer.BeginAddQueueItemToOutboundFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, Transport.MLAPI_STDRPC_CHANNEL, 0, NetworkId, sendParams.TargetClientIds ?? NetworkingManager.Singleton.ConnectedClientsList.Select(c => c.ClientId).ToArray()); | ||
|
|
||
| if(!rpcQueueContainer.IsUsingBatching()) | ||
| { | ||
|
|
@@ -309,7 +305,7 @@ protected NetworkedBehaviour GetBehaviour(ushort id) | |
| private bool varInit = false; | ||
|
|
||
| private readonly List<HashSet<int>> channelMappedNetworkedVarIndexes = new List<HashSet<int>>(); | ||
| private readonly List<string> channelsForNetworkedVarGroups = new List<string>(); | ||
| private readonly List<byte> channelsForNetworkedVarGroups = new List<byte>(); | ||
| internal readonly List<INetworkedVar> networkedVarFields = new List<INetworkedVar>(); | ||
|
|
||
| private static HashSet<MLAPI.NetworkedObject> touched = new HashSet<MLAPI.NetworkedObject>(); | ||
|
|
@@ -374,12 +370,16 @@ internal void InitializeVars() | |
|
|
||
| { | ||
| // Create index map for channels | ||
| Dictionary<string, int> firstLevelIndex = new Dictionary<string, int>(); | ||
| Dictionary<byte, int> firstLevelIndex = new Dictionary<byte, int>(); | ||
| int secondLevelCounter = 0; | ||
|
|
||
| for (int i = 0; i < networkedVarFields.Count; i++) | ||
| { | ||
| string channel = networkedVarFields[i].GetChannel(); // Cache this here. Some developers are stupid. You don't know what shit they will do in their methods | ||
| // this could be cleaner. The GetChannel() methods look for the SendChannel string channel name | ||
| // from the settings file, which could be easily misconfigured. If a bogus channel is specified, | ||
| // GetChannelByte() will return the default, MLAPI_INTERNAL_CHANNEL | ||
| string channelName = networkedVarFields[i].GetChannel(); | ||
| byte channel = Transport.GetChannelByte(channelName); | ||
|
|
||
| if (!firstLevelIndex.ContainsKey(channel)) | ||
| { | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"256 channels ought to be enough for everyone" ? 640K
I'm not arguing for more, I think 256 is enough. But just want to point out the limit and ask whether we stopped to consider the impact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wondered about the same thing, and even thought about putting dup channel detection in the registration function just in case. I thought from our discussion we wanted to stick with 'byte'. Happy to go all the way to a QWORD too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think byte should be fine for the next few milestones, but it could be that when we get into the MMO side of things this value could have potential to be increased to a ushort or even a uint.