From 644702ebdf00bde3066745b7934cd75f523048e4 Mon Sep 17 00:00:00 2001 From: Swann Date: Fri, 24 Jul 2020 14:56:20 +0200 Subject: [PATCH] feat: client state update as soon a client are in the lobby --- multi_user/delayable.py | 49 ++++++++++++++++++++++++----------------- multi_user/operators.py | 4 ++++ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/multi_user/delayable.py b/multi_user/delayable.py index 171ddba..eb12c13 100644 --- a/multi_user/delayable.py +++ b/multi_user/delayable.py @@ -239,7 +239,7 @@ class DrawClient(Draw): class ClientUpdate(Timer): - def __init__(self, timout=.016): + def __init__(self, timout=.1): super().__init__(timout) self.handle_quit = False self.users_metadata = {} @@ -298,27 +298,36 @@ class ClientUpdate(Timer): local_user_metadata['view_corners'] = current_view_corners local_user_metadata['view_matrix'] = presence.get_view_matrix() session.update_user_metadata(local_user_metadata) - # sync online users - session_users = operators.client.online_users - ui_users = bpy.context.window_manager.online_users - - for index, user in enumerate(ui_users): - if user.username not in session_users.keys(): - ui_users.remove(index) - renderer.flush_selection() - renderer.flush_users() - break - - for user in session_users: - if user not in ui_users: - new_key = ui_users.add() - new_key.name = user - new_key.username = user - class SessionStatusUpdate(Timer): - def __init__(self, timout=.1): + def __init__(self, timout=1): super().__init__(timout) def execute(self): - presence.refresh_sidebar_view() \ No newline at end of file + presence.refresh_sidebar_view() + +class SessionUserSync(Timer): + def __init__(self, timout=1): + super().__init__(timout) + + def execute(self): + session = getattr(operators, 'client', None) + renderer = getattr(presence, 'renderer', None) + + if session and renderer: + # sync online users + session_users = operators.client.online_users + ui_users = bpy.context.window_manager.online_users + + for index, user in enumerate(ui_users): + if user.username not in session_users.keys(): + ui_users.remove(index) + renderer.flush_selection() + renderer.flush_users() + break + + for user in session_users: + if user not in ui_users: + new_key = ui_users.add() + new_key.name = user + new_key.username = user \ No newline at end of file diff --git a/multi_user/operators.py b/multi_user/operators.py index 56dd6eb..8f9561e 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -151,9 +151,13 @@ class SessionStartOperator(bpy.types.Operator): delayables.append(delayable.DynamicRightSelectTimer()) session_update = delayable.SessionStatusUpdate() + session_user_sync = delayable.SessionUserSync() session_update.register() + session_user_sync.register() delayables.append(session_update) + delayables.append(session_user_sync) + @client.register('on_connection') def initialize_session():