prevent infinite history track

This commit is contained in:
Ruben van de Ven 2024-11-05 14:29:51 +01:00
parent 9871848407
commit 9aff9c7c06

View file

@ -78,19 +78,31 @@ class DrawnTrack:
self.track_id = track_id
self.renderer = renderer
self.drawn_positions = []
self.drawn_predictions = []
self.predictions: deque[DrawnPrediction] = deque(maxlen=20) # TODO; make configurable
# self.drawn_predictions = []
self.predictions: deque[DrawnPrediction] = deque(maxlen=2) # TODO; make configurable
self.shapes: list[pyglet.shapes.Line] = []
self.set_track(track, H)
self.set_prediction(track)
def __del__(self):
self.destroy()
def destroy(self):
# TODO)) not working yet
logger.warning(f'del track {self}')
for s in self.shapes:
s.delete()
for p in self.predictions:
p.destroy()
def set_track(self, track: Track, H):
self.update_at = time.time()
self.track = track
self.H = H
self.coords = [d.get_foot_coords() for d in track.history]
self.coords = [d.get_foot_coords() for d in track.history[-30:]] # maximum of 30 past positions (prevent collapse of FPS on loitering object)
# perhaps only do in constructor:
self.inv_H = np.linalg.pinv(self.H)
@ -98,6 +110,7 @@ class DrawnTrack:
def set_prediction(self, track: Track):
# TODO: turn into add_prediction
pred_coords = []
if not track.predictions:
return
@ -249,6 +262,11 @@ class DrawnPrediction:
prediction_shapes.append(line)
self.pred_shapes.append(prediction_shapes)
def destroy(self):
for pred in self.pred_shapes:
for shape in pred:
shape.delete()
def update_opacities(self, dt: float):
"""
@ -547,6 +565,7 @@ class Renderer:
# TODO make delay configurable
if self.drawn_tracks[track_id].update_at < time.time() - 5:
# TODO fade out
self.drawn_tracks[track_id].destroy()
del self.drawn_tracks[track_id]
def update_predictions(self):
@ -593,6 +612,7 @@ class Renderer:
self.batch_bg.draw()
for track in self.drawn_tracks.values():
for shape in track.shapes:
shape.draw() # for some reason the batches don't work