Skip to content

feat: Add global manager to track client & debug panel instances#816

Merged
nicolodavis merged 10 commits into
masterfrom
delucis/feat/debug-manager
Oct 16, 2020
Merged

feat: Add global manager to track client & debug panel instances#816
nicolodavis merged 10 commits into
masterfrom
delucis/feat/debug-manager

Conversation

@delucis
Copy link
Copy Markdown
Member

@delucis delucis commented Oct 6, 2020

This PR fixes bugs created by rendering multiple debug panels when there are multiple clients. It does so by:

  • Adding a ClientManager class, 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.)

    Screen capture showing use of the client switcher

    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 playerID for 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 ClientManager class 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.

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.
@delucis delucis requested a review from nicolodavis October 6, 2020 15:30
@nicolodavis
Copy link
Copy Markdown
Member

Looks good @delucis!

I can't think of another way to do the client switching without storing global state.

@nicolodavis nicolodavis merged commit c8c648e into master Oct 16, 2020
@nicolodavis nicolodavis deleted the delucis/feat/debug-manager branch October 16, 2020 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moves from debug panel are disallowed when playing with local master Debug UI buggy ....

2 participants