feat: Add global manager to track client & debug panel instances#816
Merged
Conversation
Fixes #810, closes #670 This adds a global client manager which all clients register and unregister with when they start/stop. Mounting/unmounting the debug panel is now delegated to this manager, which allows us to only ever render one debug panel. To handle this, the debug panel now displays a client switcher when multiple clients are in use. Toggling the players will also try to switch to a client for that player before it actually updates the current client.
Member
|
Looks good @delucis! I can't think of another way to do the client switching without storing global state. |
nicolodavis
approved these changes
Oct 16, 2020
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.
This PR fixes bugs created by rendering multiple debug panels when there are multiple clients. It does so by:
Adding a
ClientManagerclass, a global instance of which is used by all clients to register/unregister as they start/stop.Rendering the debug panel is delegated to this manager, which can therefore ensure only one panel at a time is rendered.
I’ve added a client “switcher” to the bottom of the main debug pane whenever there is more than one active client to allow users to toggle the client the debug panel is connected to. (You can see this in action by running the examples and checking out the tic-tac-toe multiplayer example.)
There’s no simple way of identifying a client, so the menu shows various bits of client info to try to help clarify which one’s which.
When switching player IDs, the manager also checks to see if there’s an active client for that player and switches clients before toggling the
playerIDfor the current client.The main positive here is that confusion around the debug panel when using multiple clients should be solved. For example, this fixes #810 and closes #670.
The main drawback is that the
ClientManagerclass is only currently used to bridge between the clients and the debug panel, but it will be bundled and instantiated even in production builds where (in most cases) the debug panel won’t be used. Also, it’s a global instance. I’m not sure if there’s another way to do this, but would be interested in feedback or thoughts for different approaches.