From d47ab01964b07c771ce54a60b413a6f8b71a7300 Mon Sep 17 00:00:00 2001 From: hkc Date: Wed, 10 Jul 2024 00:40:42 +0300 Subject: [PATCH] Added more stats and fixed animations They weren't cleared on reload via SIGUSR1 --- swarm/manager.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/swarm/manager.py b/swarm/manager.py index 9828048..2b98f62 100644 --- a/swarm/manager.py +++ b/swarm/manager.py @@ -59,6 +59,8 @@ class Manager: print("Resetting shmem...") self.shmem.buf[OFFSET_AVOID:] = bytes(500000 - OFFSET_AVOID) + self.animations = [] + self.animation_functions = [] if fontconfig := settings.get("default_font"): self.default_font_size = int(fontconfig.get("size", 8)) @@ -265,6 +267,7 @@ class Manager: assert self.shmem is not None print("Caught SIGUSR1, dumping state") buf = bytes(self.shmem.buf[:]) + print("# Dumping state.png") with Image.new("RGB", (1000, 1000), 0) as im: for i in range(1000000): y, x = divmod(i, 1000) @@ -282,6 +285,7 @@ class Manager: ), ) im.save("state.png") + print("# Dumping avoid.png") with Image.new("L", (1000, 1000), 0) as im: for i in range(1000000): y, x = divmod(i, 1000) @@ -291,6 +295,19 @@ class Manager: 255 if (buf[OFFSET_AVOID + byte] << bit) & 0x80 else 0, ) im.save("avoid.png") + print(f"# Animations {len(self.animations)}") + for anim in self.animations: + frame = int(time.time() / anim.spf) % len(anim.frames) + print( + str.format( + "X: {:4d} Y: {:4d} Frames: {:3d} S/F: {:4.1f} Frame: {:d}", + anim.x, + anim.y, + len(anim.frames), + anim.spf, + frame, + ) + ) print("Dump done") def on_sigusr2(self, signum, frame):