fix: delayable from accessing session data before its ready

refactor: remove
feat: submodule update
This commit is contained in:
Swann Martinez 2020-02-07 17:08:36 +01:00
parent 22eb65358b
commit 81752e9a23
No known key found for this signature in database
GPG Key ID: 414CCAFD8DA720E1
4 changed files with 32 additions and 38 deletions

View File

@ -3,7 +3,7 @@ import logging
import bpy
from . import operators, presence, utils
from .libs.replication.replication.constants import FETCHED, RP_COMMON
from .libs.replication.replication.constants import FETCHED, RP_COMMON, STATE_ACTIVE
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
@ -89,7 +89,7 @@ class DynamicRightSelectTimer(Timer):
session = operators.client
settings = bpy.context.window_manager.session
if session:
if session and session.state == STATE_ACTIVE:
# Find user
if self._user is None:
self._user = session.online_users.get(settings.username)
@ -195,19 +195,20 @@ class DrawClient(Draw):
session = getattr(operators, 'client', None)
renderer = getattr(presence, 'renderer', None)
if session and renderer:
if session and renderer and session.state == STATE_ACTIVE:
settings = bpy.context.window_manager.session
users = session.online_users
for user in users.values():
metadata = user.get('metadata')
if settings.presence_show_selected and 'selected_objects' in metadata.keys():
renderer.draw_client_selection(
user['id'], metadata['color'], metadata['selected_objects'])
if settings.presence_show_user and 'view_corners' in metadata:
renderer.draw_client_camera(
user['id'], metadata['view_corners'], metadata['color'])
if 'color' in metadata:
if settings.presence_show_selected and 'selected_objects' in metadata.keys():
renderer.draw_client_selection(
user['id'], metadata['color'], metadata['selected_objects'])
if settings.presence_show_user and 'view_corners' in metadata:
renderer.draw_client_camera(
user['id'], metadata['view_corners'], metadata['color'])
class ClientUpdate(Timer):
@ -220,7 +221,7 @@ class ClientUpdate(Timer):
session = getattr(operators, 'client', None)
renderer = getattr(presence, 'renderer', None)
if session and renderer:
if session and renderer and session.state == STATE_ACTIVE:
# Check if session has been closes prematurely
if session.state == 0:
bpy.ops.session.stop()

@ -1 +1 @@
Subproject commit 44af43ddb4a08070c7d872abe08a781c682b0fde
Subproject commit d0f2338fb62f2b21dba4ed4737ecaa2b28a9e2ff

View File

@ -83,7 +83,8 @@ class SessionStartOperator(bpy.types.Operator):
client = Session(
factory=bpy_factory,
python_path=bpy.app.binary_path_python)
python_path=bpy.app.binary_path_python,
default_strategy=settings.right_strategy)
# Host a session
if self.host:
@ -92,29 +93,21 @@ class SessionStartOperator(bpy.types.Operator):
utils.clean_scene()
try:
for scene in bpy.data.scenes:
scene_uuid = client.add(scene)
client.commit(scene_uuid)
client.host(
id=settings.username,
address=settings.ip,
port=settings.port,
ttl_port=settings.ttl_port,
right_strategy=settings.right_strategy
)
ttl_port=settings.ttl_port)
except Exception as e:
self.report({'ERROR'}, repr(e))
logger.error(f"Error: {e}")
settings.is_admin = True
time.sleep(2) # Removed as soon as server will be launched from replication
for scene in bpy.data.scenes:
scene_uuid = client.add(scene)
# for node in client.list():
client.commit(scene_uuid)
# Push all added values
client.push_all()
# Join a session
else:
utils.clean_scene()
@ -130,13 +123,12 @@ class SessionStartOperator(bpy.types.Operator):
self.report({'ERROR'}, repr(e))
logger.error(f"Error: {e}")
# Background client updates service
#TODO: Refactoring
delayables.append(delayable.ClientUpdate())
delayables.append(delayable.DrawClient())
delayables.append(delayable.DynamicRightSelectTimer())
# Launch drawing module
if settings.enable_presence:
presence.renderer.run()
@ -408,17 +400,18 @@ class ApplyArmatureOperator(bpy.types.Operator):
if event.type == 'TIMER':
global client
nodes = client.list(filter=bl_types.bl_armature.BlArmature)
if client.state == STATE_ACTIVE:
nodes = client.list(filter=bl_types.bl_armature.BlArmature)
for node in nodes:
node_ref = client.get(uuid=node)
for node in nodes:
node_ref = client.get(uuid=node)
if node_ref.state == FETCHED:
try:
client.apply(node)
except Exception as e:
logger.error(
"fail to apply {}: {}".format(node_ref.uuid, e))
if node_ref.state == FETCHED:
try:
client.apply(node)
except Exception as e:
logger.error(
"fail to apply {}: {}".format(node_ref.uuid, e))
return {'PASS_THROUGH'}

View File

@ -229,7 +229,7 @@ class SESSION_UL_users(bpy.types.UIList):
if user:
ping = str(user['latency'])
metadata = user.get('metadata')
if metadata:
if metadata and 'frame_current' in metadata:
frame_current = str(metadata['frame_current'])
split = layout.split(factor=0.5)