Remove standalone server dependency on Unity#71
Merged
Conversation
…ency on Unity in server context
Contributor
|
One small thing i would change -- i would convert the interfaces to /// <summary>
/// Implementation of packet handler dispatcher to immediately invoke the handler directly for the server-side.
/// </summary>
internal class ServerPacketHandlerRegistryDispatcher : IPacketHandlerRegistryDispatcher {
public static readonly ServerPacketHandlerRegistryDispatcher Instance = new();
private ServerPacketHandlerRegistryDispatcher() { }
public void Dispatch(Action action) => action.Invoke();
}
/// <summary>
/// Implementation of packet handler dispatcher to invoke the handler on Unity's main thread.
/// </summary>
internal class ClientPacketHandlerRegistryDispatcher : IPacketHandlerRegistryDispatcher {
public static readonly ClientPacketHandlerRegistryDispatcher Instance = new();
private ClientPacketHandlerRegistryDispatcher() { }
public void Dispatch(Action action) => ThreadUtil.RunActionOnMainThread(action);
}
//PacketManager.cs
private readonly PacketHandlerRegistry<ClientExamplePacketId, ClientPacketHandler> _clientExampleRegistry = new(
"Example", ClientPacketHandlerRegistryDispatcher.Instance
);
private readonly PacketHandlerRegistry<ServerExamplePacketId, ServerPacketHandler> _serverExampleRegistry = new(
"Example", ServerPacketHandlerRegistryDispatcher.Instance
); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #70.
Server-side code depended on Unity due to the packet handlers using a type from Unity, because client-side dispatches handlers to Unity's main thread.
This PR fixes the issue by introducing an interface for dispatchers, where a server-side implementation dispatches immediately, while the client-side implementation dispatches by running it on main thread of Unity. Due to classes implementating an interface, the Unity types are no longer loaded when creating the packet handler registry instances on the server-side.