feat(client): append load to serial agent
This commit is contained in:
parent
5ae044bd31
commit
2caf909267
57
client.py
57
client.py
@ -13,19 +13,14 @@ import queue
|
||||
# import zmq
|
||||
lock = threading.Lock()
|
||||
|
||||
try:
|
||||
from .libs import umsgpack
|
||||
from .libs import zmq
|
||||
from .libs import dump_anything
|
||||
from . import helpers
|
||||
from . import message
|
||||
except:
|
||||
# Server import
|
||||
from libs import umsgpack
|
||||
from libs import zmq
|
||||
from libs import dump_anything
|
||||
import helpers
|
||||
import message
|
||||
|
||||
from .libs import umsgpack
|
||||
from .libs import zmq
|
||||
from .libs import dump_anything
|
||||
from . import helpers
|
||||
from . import message
|
||||
from . import draw
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
@ -76,7 +71,7 @@ class RCFClient(object):
|
||||
|
||||
# Database and connexion agent
|
||||
self.net_agent = threading.Thread(
|
||||
target=rcf_client_agent, args=(self.ctx, self.store, peer, self.serial_product), name="net-agent")
|
||||
target=rcf_client_agent, args=(self.ctx, self.store, peer, self.serial_product,self.serial_feed), name="net-agent")
|
||||
self.net_agent.daemon = True
|
||||
self.net_agent.start()
|
||||
|
||||
@ -122,7 +117,7 @@ class RCFClient(object):
|
||||
self.pipe.send_multipart(
|
||||
[b"SET", umsgpack.packb(key), (umsgpack.packb(value) if value else umsgpack.packb('None')),umsgpack.packb(override)])
|
||||
else:
|
||||
self.serial_feed.put(key)
|
||||
self.serial_feed.put(('DUMP',key,None))
|
||||
# self.serial_pipe.send_multipart(
|
||||
# [b"DUMP", umsgpack.packb(key)])
|
||||
# self.pipe.send_multipart(
|
||||
@ -156,7 +151,7 @@ class RCFClient(object):
|
||||
global stop
|
||||
stop = True
|
||||
for a in range(0,DUMP_AGENTS_NUMBER):
|
||||
self.serial_feed.put('exit')
|
||||
self.serial_feed.put(('exit',None,None))
|
||||
|
||||
|
||||
# READ-ONLY FUNCTIONS
|
||||
@ -377,10 +372,12 @@ class RCFClientAgent(object):
|
||||
elif command == b"STATE":
|
||||
self.pipe.send(umsgpack.packb(self.state.value))
|
||||
|
||||
def rcf_client_agent(ctx,store, pipe, queue):
|
||||
|
||||
def rcf_client_agent(ctx,store, pipe, serial_product, serial_feed):
|
||||
agent = RCFClientAgent(ctx,store, pipe)
|
||||
server = None
|
||||
net_feed = queue
|
||||
net_feed = serial_product
|
||||
net_product = serial_feed
|
||||
global stop
|
||||
while True:
|
||||
if stop:
|
||||
@ -434,15 +431,17 @@ def rcf_client_agent(ctx,store, pipe, queue):
|
||||
logger.info("snapshot complete")
|
||||
agent.state = State.ACTIVE
|
||||
else:
|
||||
helpers.load(rcfmsg.key, rcfmsg.body)
|
||||
net_product.put(('LOAD',rcfmsg.key, rcfmsg.body))
|
||||
# helpers.load(rcfmsg.key, rcfmsg.body)
|
||||
rcfmsg.store(agent.property_map)
|
||||
logger.info("snapshot from {} stored".format(rcfmsg.id))
|
||||
elif agent.state == State.ACTIVE:
|
||||
# IN
|
||||
if rcfmsg.id != agent.id:
|
||||
|
||||
with lock:
|
||||
helpers.load(rcfmsg.key, rcfmsg.body)
|
||||
# with lock:
|
||||
# helpers.load(rcfmsg.key, rcfmsg.body)
|
||||
net_product.put(('LOAD',rcfmsg.key, rcfmsg.body))
|
||||
rcfmsg.store(agent.property_map)
|
||||
|
||||
else:
|
||||
@ -473,15 +472,19 @@ def rcf_client_agent(ctx,store, pipe, queue):
|
||||
# else: else
|
||||
# agent.state = State.INITIAL
|
||||
|
||||
|
||||
def dumper_agent(product, feed):
|
||||
while True:
|
||||
key = feed.get()
|
||||
command,key,value = feed.get()
|
||||
|
||||
if key == 'exit':
|
||||
if command == 'exit':
|
||||
break
|
||||
elif command == 'DUMP':
|
||||
value = helpers.dump(key)
|
||||
|
||||
value = helpers.dump(key)
|
||||
|
||||
if value:
|
||||
product.put((key,value))
|
||||
if value:
|
||||
product.put((key,value))
|
||||
elif command == 'LOAD':
|
||||
if value:
|
||||
helpers.load(key, value)
|
||||
|
54
draw.py
54
draw.py
@ -82,7 +82,7 @@ def get_client_2d(coords):
|
||||
|
||||
class HUD(object):
|
||||
|
||||
def __init__(self, client_instance=None):
|
||||
def __init__(self):
|
||||
self.d3d_items = {}
|
||||
self.d2d_items = {}
|
||||
self.draw3d_handle = None
|
||||
@ -91,11 +91,9 @@ class HUD(object):
|
||||
self.coords = None
|
||||
self.active_object = None
|
||||
|
||||
if client_instance:
|
||||
self.client = client_instance
|
||||
|
||||
self.draw_clients()
|
||||
self.register_handlers()
|
||||
# self.draw_clients()
|
||||
self.register_handlers()
|
||||
|
||||
def register_handlers(self):
|
||||
self.draw3d_handle = bpy.types.SpaceView3D.draw_handler_add(
|
||||
@ -163,32 +161,31 @@ class HUD(object):
|
||||
for k in key_to_remove:
|
||||
del self.d3d_items[k]
|
||||
|
||||
def draw_clients(self):
|
||||
def draw_client(self, client):
|
||||
clients = self.client.get("Client")
|
||||
|
||||
if clients:
|
||||
for client in clients:
|
||||
name = client[0].split('/')[1]
|
||||
local_username = bpy.context.scene.session_settings.username
|
||||
if client:
|
||||
name = client['id']
|
||||
local_username = bpy.context.scene.session_settings.username
|
||||
|
||||
if name != local_username:
|
||||
try:
|
||||
indices = (
|
||||
(1, 3), (2, 1), (3, 0), (2, 0),(4, 5)
|
||||
)
|
||||
if name != local_username:
|
||||
try:
|
||||
indices = (
|
||||
(1, 3), (2, 1), (3, 0), (2, 0),(4, 5)
|
||||
)
|
||||
|
||||
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||
position = client[1]['location']
|
||||
color = client[1]['color']
|
||||
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
|
||||
position = client['location']
|
||||
color = client['color']
|
||||
|
||||
batch = batch_for_shader(
|
||||
shader, 'LINES', {"pos": position}, indices=indices)
|
||||
batch = batch_for_shader(
|
||||
shader, 'LINES', {"pos": position}, indices=indices)
|
||||
|
||||
self.d3d_items[client[0]] = (shader, batch, color)
|
||||
self.d2d_items[client[0]] = (position[1], name, color)
|
||||
self.d3d_items[client[0]] = (shader, batch, color)
|
||||
self.d2d_items[client[0]] = (position[1], name, color)
|
||||
|
||||
except Exception as e:
|
||||
print("Draw client exception {}".format(e))
|
||||
except Exception as e:
|
||||
print("Draw client exception {}".format(e))
|
||||
|
||||
def draw3d_callback(self):
|
||||
bgl.glLineWidth(2)
|
||||
@ -213,12 +210,3 @@ class HUD(object):
|
||||
|
||||
except Exception as e:
|
||||
print("2D EXCEPTION")
|
||||
|
||||
def draw(self):
|
||||
if self.client:
|
||||
self.d3d_items.clear()
|
||||
self.d2d_items.clear()
|
||||
|
||||
# Draw clients
|
||||
self.draw_clients()
|
||||
self.draw_selected_object()
|
||||
|
@ -71,8 +71,6 @@ def load(key, value):
|
||||
elif target_type == 'Client':
|
||||
load_client(key.split('/')[1], value)
|
||||
|
||||
|
||||
|
||||
|
||||
def resolve_bpy_path(path):
|
||||
"""
|
||||
|
42
operators.py
42
operators.py
@ -173,7 +173,8 @@ def draw_tick():
|
||||
# drawing
|
||||
global drawer
|
||||
|
||||
drawer.draw()
|
||||
|
||||
# drawer.draw()
|
||||
|
||||
# Upload
|
||||
upload_client_instance_position()
|
||||
@ -197,9 +198,9 @@ def sync():
|
||||
|
||||
def register_ticks():
|
||||
# REGISTER Updaters
|
||||
bpy.app.timers.register(draw_tick)
|
||||
# bpy.app.timers.register(draw_tick)
|
||||
bpy.app.timers.register(sync)
|
||||
# bpy.app.timers.register(default_tick)
|
||||
bpy.app.timers.register(default_tick)
|
||||
pass
|
||||
|
||||
def unregister_ticks():
|
||||
@ -246,7 +247,7 @@ class session_join(bpy.types.Operator):
|
||||
net_settings.ip, net_settings.port)
|
||||
|
||||
# net_settings.is_running = True
|
||||
drawer = draw.HUD(client_instance=client_instance)
|
||||
drawer = draw.HUD()
|
||||
# bpy.ops.session.refresh()
|
||||
register_ticks()
|
||||
return {"FINISHED"}
|
||||
@ -563,39 +564,6 @@ def depsgraph_update(scene):
|
||||
update_selected_object(bpy.context)
|
||||
|
||||
|
||||
# selected_objects = helpers.get_selected_objects(scene)
|
||||
|
||||
|
||||
# if len(selected_objects) > 0:
|
||||
# for update in updates:
|
||||
# update_key = "{}/{}".format(update.id.bl_rna.name, update.id.name)
|
||||
# remote_update = client_instance.get(update_key)
|
||||
|
||||
# if remote_update and remote_update[0][1]["uuid"] == update.id.uuid:
|
||||
# print("{} sending update".format(username))
|
||||
# client_instance.set(
|
||||
# "{}/{}".format(update.id.bl_rna.name, update.id.name))
|
||||
# else:
|
||||
# print("{} applying update".format(username))
|
||||
|
||||
|
||||
# for update in ordered(updates):
|
||||
# if update[2] == "Master Collection":
|
||||
# pass
|
||||
# elif update[1] in SUPPORTED_TYPES:
|
||||
# key = "{}/{}".format(update[1], update[2])
|
||||
|
||||
# data = client_instance.get(key)
|
||||
|
||||
# if data:
|
||||
# if update[3].id == username:
|
||||
# # Queue update
|
||||
# client_instance.set(key)
|
||||
# else:
|
||||
# # Instance new object ?
|
||||
# print("new")
|
||||
# client_instance.add(key)
|
||||
|
||||
selected_objects = helpers.get_selected_objects(scene)
|
||||
if len(selected_objects) > 0:
|
||||
for updated_data in updates:
|
||||
|
Loading…
Reference in New Issue
Block a user