feat(rcf): attempt to use queue
This commit is contained in:
35
client.py
35
client.py
@ -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,11 +68,12 @@ 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()
|
||||||
|
|
||||||
def connect(self, id, address, port):
|
def connect(self, id, address, port):
|
||||||
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
||||||
id, str) else id), (address.encode() if isinstance(
|
id, str) else id), (address.encode() if isinstance(
|
||||||
@ -186,7 +188,7 @@ class RCFClientAgent(object):
|
|||||||
logger.info("{} dumped".format(key))
|
logger.info("{} dumped".format(key))
|
||||||
# Send key-value pair on to server
|
# Send key-value pair on to server
|
||||||
rcfmsg = message.RCFMessage(key=key, id=self.id, mtype="", body=value)
|
rcfmsg = message.RCFMessage(key=key, id=self.id, mtype="", body=value)
|
||||||
|
|
||||||
rcfmsg.store(self.property_map)
|
rcfmsg.store(self.property_map)
|
||||||
rcfmsg.send(self.publisher)
|
rcfmsg.send(self.publisher)
|
||||||
else:
|
else:
|
||||||
@ -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):
|
||||||
|
@ -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',
|
||||||
@ -111,9 +112,9 @@ def load_object(target=None, data=None, create=False):
|
|||||||
|
|
||||||
target = bpy.data.objects.new(data["name"], pointer)
|
target = bpy.data.objects.new(data["name"], pointer)
|
||||||
|
|
||||||
# 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:
|
||||||
|
17
operators.py
17
operators.py
@ -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)
|
||||||
|
Reference in New Issue
Block a user