feat(rcf): attempt to use queue

This commit is contained in:
Swann Martinez
2019-04-11 18:07:59 +02:00
parent 65f85ee76d
commit f8da8a836d
3 changed files with 44 additions and 15 deletions

View File

@ -8,8 +8,9 @@ import time
from enum import Enum from enum import Enum
from random import randint from random import randint
from uuid import uuid4 from uuid import uuid4
import copy
import queue
lock = threading.Lock()
try: try:
from .libs import umsgpack from .libs import umsgpack
@ -67,8 +68,9 @@ class RCFClient(object):
def __init__(self): def __init__(self):
self.ctx = zmq.Context() self.ctx = zmq.Context()
self.pipe, peer = zpipe(self.ctx) self.pipe, peer = zpipe(self.ctx)
self.queue = queue.Queue()
self.agent = threading.Thread( self.agent = threading.Thread(
target=rcf_client_agent, args=(self.ctx, peer)) target=rcf_client_agent, args=(self.ctx, peer,self.queue))
self.agent.daemon = True self.agent.daemon = True
self.agent.start() self.agent.start()
@ -201,9 +203,10 @@ class RCFClientAgent(object):
self.pipe.send(umsgpack.packb(list(self.property_map))) self.pipe.send(umsgpack.packb(list(self.property_map)))
def rcf_client_agent(ctx, pipe): def rcf_client_agent(ctx, pipe,queue):
agent = RCFClientAgent(ctx, pipe) agent = RCFClientAgent(ctx, pipe)
server = None server = None
update_queue = queue
global stop global stop
while True: while True:
if stop: if stop:
@ -239,6 +242,7 @@ def rcf_client_agent(ctx, pipe):
agent.control_message() agent.control_message()
elif server_socket in items: elif server_socket in items:
rcfmsg = message.RCFMessage.recv(server_socket) rcfmsg = message.RCFMessage.recv(server_socket)
if agent.state == State.SYNCING: if agent.state == State.SYNCING:
# Store snapshot # Store snapshot
if rcfmsg.key == "SNAPSHOT_END": if rcfmsg.key == "SNAPSHOT_END":
@ -249,8 +253,14 @@ def rcf_client_agent(ctx, pipe):
rcfmsg.store(agent.property_map) rcfmsg.store(agent.property_map)
elif agent.state == State.ACTIVE: elif agent.state == State.ACTIVE:
if rcfmsg.id != agent.id: if rcfmsg.id != agent.id:
helpers.load(rcfmsg.key,rcfmsg.body) update_queue.put((rcfmsg.key,rcfmsg.body))
# helpers.load(rcfmsg.key,rcfmsg.body)
# logger.info("load") # logger.info("load")
# agent.serial.send_multipart([b"LOAD", umsgpack.packb(rcfmsg.key), umsgpack.packb(rcfmsg.body)])
# reply = agent.serial.recv_multipart()
# if reply == b"DONE":
rcfmsg.store(agent.property_map) rcfmsg.store(agent.property_map)
# action = "update" if rcfmsg.body else "delete" # action = "update" if rcfmsg.body else "delete"
# logging.info("{}: received from {}:{},{} {}".format(rcfmsg.key, # logging.info("{}: received from {}:{},{} {}".format(rcfmsg.key,
@ -280,9 +290,18 @@ class SerializationAgent(object):
if command == b"DUMP": if command == b"DUMP":
key = umsgpack.unpackb(msg[0]) key = umsgpack.unpackb(msg[0])
value = helpers.dump(key)
self.pipe.send_multipart(umsgpack.packb(value))
elif command == b"LOAD": elif command == b"LOAD":
key, value = msg
key = umsgpack.unpackb(msg[0])
value = umsgpack.unpackb(msg[1])
helpers.load(key,value)
self.pipe.send_multipart([b"DONE"])
def serialization_agent(ctx, pipe): def serialization_agent(ctx, pipe):

View File

@ -1,4 +1,5 @@
import bpy import bpy
import mathutils
from .libs import dump_anything from .libs import dump_anything
CORRESPONDANCE = {'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials', CORRESPONDANCE = {'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects', 'Material': 'materials',
@ -113,7 +114,7 @@ def load_object(target=None, data=None, create=False):
# Load other meshes metadata # Load other meshes metadata
dump_anything.load(target, data) dump_anything.load(target, data)
import mathutils
target.matrix_world = mathutils.Matrix(data["matrix_world"]) target.matrix_world = mathutils.Matrix(data["matrix_world"])
except: except:

View File

@ -305,8 +305,13 @@ def default_tick():
# print("pull error: {}".format(e)) # print("pull error: {}".format(e))
# bpy.ops.session.refresh() # bpy.ops.session.refresh()
global client_instance
return 0.5 if not client_instance.queue.empty():
update = client_instance.queue.get()
helpers.load(update[0],update[1])
return 0.01
def mesh_tick(): def mesh_tick():
@ -637,15 +642,19 @@ def depsgraph_update(scene):
# if updated_data.is_updated_transform: # if updated_data.is_updated_transform:
# add_update(updated_data.id.bl_rna.name, updated_data.id.name) # add_update(updated_data.id.bl_rna.name, updated_data.id.name)
# else: # else:
if is_dirty(updates) or push: if is_dirty(updates):
for update in ordered(updates): for update in ordered(updates):
if update[2] == "Master Collection": if update[2] == "Master Collection":
pass pass
elif update[1] in SUPPORTED_TYPES: elif update[1] in SUPPORTED_TYPES:
client_instance.set("{}/{}".format(update[1], update[2])) client_instance.set("{}/{}".format(update[1], update[2]))
push = False
if len(updates) is 1 and len(bpy.context.selected_objects)>0:
updated_data = updates[0]
if updated_data.id.name == bpy.context.selected_objects[0].name:
if updated_data.is_updated_transform or updated_data.is_updated_geometry:
client_instance.set("{}/{}".format(updated_data.id.bl_rna.name, updated_data.id.name))
# elif scene.session_settings.active_object and updated_data.id.name == scene.session_settings.active_object.name: # elif scene.session_settings.active_object and updated_data.id.name == scene.session_settings.active_object.name:
# if updated_data.is_updated_transform or updated_data.is_updated_geometry: # if updated_data.is_updated_transform or updated_data.is_updated_geometry:
# add_update(updated_data.id.bl_rna.name, updated_data.id.name) # add_update(updated_data.id.bl_rna.name, updated_data.id.name)