refactor(rcf): Cleanup operators, cleanup client
This commit is contained in:
@ -96,14 +96,11 @@ class RCFMessage(object):
|
|||||||
mtype = None # data mtype (string)
|
mtype = None # data mtype (string)
|
||||||
body = None # data blob
|
body = None # data blob
|
||||||
|
|
||||||
def __init__(self, key=None, id=None, mtype=None, body=None, pointer=None):
|
def __init__(self, key=None, id=None, mtype=None, body=None):
|
||||||
self.key = key
|
self.key = key
|
||||||
self.mtype = mtype
|
self.mtype = mtype
|
||||||
self.body = body
|
self.body = body
|
||||||
self.id = id
|
self.id = id
|
||||||
self.pointer = pointer
|
|
||||||
self.get = None
|
|
||||||
self.set = None
|
|
||||||
|
|
||||||
def store(self, dikt):
|
def store(self, dikt):
|
||||||
"""Store me in a dict if I have anything to store"""
|
"""Store me in a dict if I have anything to store"""
|
||||||
@ -162,24 +159,25 @@ class Client():
|
|||||||
factory=None,
|
factory=None,
|
||||||
address="localhost"):
|
address="localhost"):
|
||||||
|
|
||||||
self.status = RCFStatus.IDLE
|
|
||||||
self.is_admin = is_admin
|
|
||||||
|
|
||||||
# 0MQ vars
|
# 0MQ vars
|
||||||
self.context = context
|
self.context = context
|
||||||
self.pull_sock = None
|
self.pull_sock = None
|
||||||
self.req_sock = None
|
self.req_sock = None
|
||||||
self.poller = None
|
self.poller = None
|
||||||
|
|
||||||
|
# Client configuration
|
||||||
self.id = id.encode()
|
self.id = id.encode()
|
||||||
self.on_recv = on_recv
|
self.on_recv = on_recv
|
||||||
self.on_post_init = on_post_init
|
self.on_post_init = on_post_init
|
||||||
|
self.status = RCFStatus.IDLE
|
||||||
|
self.is_admin = is_admin
|
||||||
self.address = address
|
self.address = address
|
||||||
|
|
||||||
self.bind_ports()
|
self.bind_ports()
|
||||||
# Main client loop registration
|
|
||||||
self.task = asyncio.ensure_future(self.main())
|
# client routine registration
|
||||||
|
self.load_task = asyncio.ensure_future(self.load())
|
||||||
|
self.tick_task = None
|
||||||
|
|
||||||
self.property_map = RCFStore(custom_factory=factory)
|
self.property_map = RCFStore(custom_factory=factory)
|
||||||
|
|
||||||
@ -212,7 +210,7 @@ class Client():
|
|||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
async def main(self):
|
async def load(self):
|
||||||
self.status = RCFStatus.CONNECTING
|
self.status = RCFStatus.CONNECTING
|
||||||
logger.info("{} client syncing".format(id))
|
logger.info("{} client syncing".format(id))
|
||||||
|
|
||||||
@ -238,11 +236,14 @@ class Client():
|
|||||||
|
|
||||||
logger.info("{} client running".format(id))
|
logger.info("{} client running".format(id))
|
||||||
|
|
||||||
self.push_update("net/clients/{}".format(self.id.decode()),"client",None)
|
self.push_update("net/clients/{}".format(self.id.decode()),"client",self.id)
|
||||||
self.push_update("net/objects/{}".format(self.id.decode()),"client_object",None)
|
self.push_update("net/objects/{}".format(self.id.decode()),"client_object","None")
|
||||||
|
|
||||||
|
self.tick_task = asyncio.ensure_future(self.tick())
|
||||||
|
|
||||||
self.status = RCFStatus.CONNECTED
|
self.status = RCFStatus.CONNECTED
|
||||||
|
|
||||||
|
async def tick(self):
|
||||||
# Main loop
|
# Main loop
|
||||||
while True:
|
while True:
|
||||||
# TODO: find a better way
|
# TODO: find a better way
|
||||||
@ -250,10 +251,8 @@ class Client():
|
|||||||
|
|
||||||
if self.pull_sock in socks:
|
if self.pull_sock in socks:
|
||||||
rcfmsg = RCFMessage.recv(self.pull_sock)
|
rcfmsg = RCFMessage.recv(self.pull_sock)
|
||||||
|
|
||||||
# if rcfmsg.pointer:
|
|
||||||
rcfmsg.store(self.property_map)
|
|
||||||
|
|
||||||
|
rcfmsg.store(self.property_map)
|
||||||
|
|
||||||
for f in self.on_recv:
|
for f in self.on_recv:
|
||||||
f(rcfmsg)
|
f(rcfmsg)
|
||||||
@ -263,7 +262,6 @@ class Client():
|
|||||||
def push_update(self, key, mtype, body):
|
def push_update(self, key, mtype, body):
|
||||||
rcfmsg = RCFMessage(key, self.id, mtype, body)
|
rcfmsg = RCFMessage(key, self.id, mtype, body)
|
||||||
rcfmsg.send(self.push_sock)
|
rcfmsg.send(self.push_sock)
|
||||||
# self.push_sock.send_multipart()
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
logger.debug("Stopping client")
|
logger.debug("Stopping client")
|
||||||
@ -271,7 +269,8 @@ class Client():
|
|||||||
self.req_sock.close()
|
self.req_sock.close()
|
||||||
self.push_sock.close()
|
self.push_sock.close()
|
||||||
self.pull_sock.close()
|
self.pull_sock.close()
|
||||||
self.task.cancel()
|
self.load_task.cancel()
|
||||||
|
self.tick_task.cancel()
|
||||||
|
|
||||||
class Server():
|
class Server():
|
||||||
def __init__(self, context=zmq.Context(), id="admin"):
|
def __init__(self, context=zmq.Context(), id="admin"):
|
||||||
|
@ -20,18 +20,9 @@ client = None
|
|||||||
server = None
|
server = None
|
||||||
context = None
|
context = None
|
||||||
|
|
||||||
SUPPORTED_DATABLOCKS = ['objects']
|
|
||||||
|
|
||||||
REPLICATED_PROPERTIES = ['matrix_world']
|
|
||||||
# 'actions','armatures','cameras','collections','curves','grease_pencils','images','materials','materials',,'scenes','textures'
|
|
||||||
COLOR_TABLE = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
|
COLOR_TABLE = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
|
||||||
(0, 0.5, 1, 1), (0.5, 0, 1, 1)]
|
(0, 0.5, 1, 1), (0.5, 0, 1, 1)]
|
||||||
NATIVE_TYPES = (
|
|
||||||
int,
|
|
||||||
float,
|
|
||||||
bool,
|
|
||||||
string,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def view3d_find():
|
def view3d_find():
|
||||||
@ -154,7 +145,7 @@ def observer(scene):
|
|||||||
|
|
||||||
def mark_objects_for_update(scene):
|
def mark_objects_for_update(scene):
|
||||||
for item in dir(bpy.data):
|
for item in dir(bpy.data):
|
||||||
if item in SUPPORTED_DATABLOCKS:
|
# if item in SUPPORTED_DATABLOCKS:
|
||||||
for datablock in getattr(bpy.data,item):
|
for datablock in getattr(bpy.data,item):
|
||||||
if bpy.context.object.is_evaluated:
|
if bpy.context.object.is_evaluated:
|
||||||
print("EVALUATED: {}:{}".format(item,datablock.name))
|
print("EVALUATED: {}:{}".format(item,datablock.name))
|
||||||
|
Reference in New Issue
Block a user