Changeset - ffa69645e9dc
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 8 months ago 2024-05-28 22:41:53
drewp@bigasterisk.com
refactor
1 file changed with 5 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/light9/blender/time_sync/time_from_graph.py
Show inline comments
 
@@ -14,16 +14,12 @@ from light9.run_local import log
 

	
 

	
 
def clamp(lo, hi, x):
 
    return max(lo, min(hi, x))
 

	
 

	
 
def floatValue(graph: SyncedGraph, s: URIRef, p: URIRef) -> float | None:
 
    return typedValue(float | None, graph, s, p)
 

	
 

	
 
UPDATE_PERIOD = 1 / 20
 

	
 

	
 
class Sync:
 
    lock = threading.Lock()
 
    duration: float = 1
 
@@ -33,31 +29,30 @@ class Sync:
 
    latestTime: float
 

	
 
    def __init__(self):
 
        # main thread
 
        self.lastSetFrame = -1
 
        self.lastGraphFrame = -1
 
        self.frameSetBy = 'init'
 
        startLoopInThread(self.task())
 
        bpy.app.timers.register(self.update)
 
        bpy.app.handlers.frame_change_post.append(self.on_frame_change_post)
 

	
 
    ## read from graph
 
    ## updates from graph -> self
 

	
 
    async def task(self):
 
        # bg thread with asyncio loop
 
        self.graph = SyncedGraph(networking.rdfdb.url, "time_sync")
 
        self.graph.addHandler(self.syncFromGraph)
 

	
 
    def syncFromGraph(self):
 
        # bg thread
 
        with self.lock:
 
            asco = L9['ascoltami']
 
            self.wallStartTime = floatValue(self.graph, asco, L9['wallStartTime'])
 
            self.pausedSongTime = floatValue(self.graph, asco, L9['pausedSongTime'])
 
            self.duration = floatValue(self.graph, asco, L9['duration']) or 1.0
 
            self.wallStartTime = typedValue(float | None, self.graph, asco, L9['wallStartTime'])
 
            self.pausedSongTime = typedValue(float | None, self.graph, asco, L9['pausedSongTime'])
 
            self.duration = typedValue(float | None, self.graph, asco, L9['duration']) or 1.0
 
            self.playing = typedValue(bool, self.graph, asco, L9['playing'])
 

	
 
    def currentTime(self) -> float | None:
 
        if self.wallStartTime is not None:
 
            return time.time() - self.wallStartTime
 
        if self.pausedSongTime is not None:
 
@@ -94,7 +89,7 @@ class Sync:
 
            # self.setGraphTime(scene.frame_current / scene.render.fps, self.duration)
 
            self.lastSetFrame = scene.frame_current
 
            t = scene.frame_current / scene.render.fps
 
            self.setInGraph(t)
 

	
 
    def setInGraph(self, t: float):
 
        log.warning(f'todo: set graph to {t}')
 
\ No newline at end of file
 
        log.warning(f'todo: set graph to {t}')
0 comments (0 inline, 0 general)