Skip to content

Commit

Permalink
[server] filewatcher setup for input fragment shader
Browse files Browse the repository at this point in the history
  • Loading branch information
mugulmd committed Jun 2, 2023
1 parent 9287ee4 commit 7e9f506
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
8 changes: 3 additions & 5 deletions claude_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
args = parser.parse_args()

# Register resources directories
register_dir((Path(__file__).parents[1] / 'resources').resolve())
if not args.res:
register_dir(Path.cwd())
else:
register_dir(args.res)
ClaudeApp.resource_dir = (Path(__file__).parents[1] / 'resources').resolve()
if args.res:
ClaudeApp.resource_dir = args.res

# Configuration
ClaudeApp.fragment_shader = args.frag
Expand Down
32 changes: 31 additions & 1 deletion claude_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import moderngl_window as mglw
import numpy as np

from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler

from multiprocessing import Process, Queue


Expand Down Expand Up @@ -48,9 +51,32 @@ def __init__(self, **kwargs):
self.queue = Queue()

# Create and launch server process
self.server = Process(target=server_feed, args=(ClaudeApp.ip, ClaudeApp.port, self.queue,))
self.server = Process(
target=server_feed,
args=(ClaudeApp.ip, ClaudeApp.port, self.queue,)
)
self.server.start()

# Create filewatcher event handler
filewatcher_handler = PatternMatchingEventHandler(
patterns=[ClaudeApp.fragment_shader],
ignore_directories=True,
case_sensitive=True
)
filewatcher_handler.on_modified = self.on_frag_changed

# Create and launch filewatcher
self.observer = Observer()
self.observer.schedule(
filewatcher_handler,
path=ClaudeApp.resource_dir,
recursive=False
)
self.observer.start()

def on_frag_changed(self, event):
print(f'{event.src_path} changed')

def write_uniform(self, np_dtype, name, value):
try:
self.program.get(name, None).write(np.array(value).astype(np_dtype).tobytes())
Expand All @@ -76,3 +102,7 @@ def render(self, time, frametime):
def close(self):
# Terminate server
self.server.terminate()

# Stop filewatcher
self.observer.stop()
self.observer.join()

0 comments on commit 7e9f506

Please sign in to comment.