diff options
author | Florian Jung <flo@windfisch.org> | 2015-08-24 18:06:59 +0200 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2015-08-24 18:06:59 +0200 |
commit | c2e13a67d969f1208a8b8c127c94a9841c7048d9 (patch) | |
tree | 9a44f247aa8e66b7ce71dae63ebe9c8a84c5babc /subscriber.py | |
parent | 58b0b9da0241ff8623581b2cb837eaf34b8f165d (diff) |
cell motion history
Diffstat (limited to 'subscriber.py')
-rw-r--r-- | subscriber.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/subscriber.py b/subscriber.py index a637e67..1dcccc6 100644 --- a/subscriber.py +++ b/subscriber.py @@ -1,4 +1,5 @@ from log import log +from collections import deque import sys class DummySubscriber: @@ -65,3 +66,33 @@ class DummySubscriber: def on_debug_line(self,x,y): log("debug line") +class CellHistory: + def __init__(self): + self.poslog = deque(maxlen=10) + self.stale = False + +class EnhancingSubscriber(DummySubscriber): + def __init__(self): + self.c = None + self.history = {} + + def set_client(self,c): + self.c = c + + def on_world_update_post(self): + for cid in self.history: + self.history[cid].stale = True + + for cid in self.c.world.cells: + if cid not in self.history: + self.history[cid] = CellHistory() + print("unknown cell") + + self.history[cid].poslog.append(self.c.world.cells[cid].pos.copy()) + self.c.world.cells[cid].poslog = self.history[cid].poslog + print("poslog of size="+str(len(self.history[cid].poslog))) + + self.history[cid].stale = False + + self.history = {k: v for k, v in self.history.items() if v.stale == False} + |