From b144ad5df76e458297bd6dc030cad4af0f344901 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 24 Aug 2024 13:04:21 -0700 Subject: [PATCH] fix remove_entity method --- kennel/engine/entities/entity.py | 12 +++++++----- kennel/engine/game.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/kennel/engine/entities/entity.py b/kennel/engine/entities/entity.py index b72e996..6623512 100644 --- a/kennel/engine/entities/entity.py +++ b/kennel/engine/entities/entity.py @@ -57,11 +57,13 @@ class EntityManager: self.component_entities[component.component_type].add(entity) def remove_entity(self, entity_id: str) -> None: - if entity_id in self.entities: - entity = self.entities[entity_id] - for component in entity.components.values(): - if component.component_type in self.component_entities: - self.component_entities[component.component_type].remove(entity) + if entity_id not in self.entities: + return + entity = self.entities[entity_id] + for component in entity.components.values(): + if component.component_type in self.component_entities: + self.component_entities[component.component_type].remove(entity) + del self.entities[entity_id] def get_entity(self, entity_id: str) -> Optional[Entity]: return self.entities.get(entity_id) diff --git a/kennel/engine/game.py b/kennel/engine/game.py index 2236306..f3134be 100644 --- a/kennel/engine/game.py +++ b/kennel/engine/game.py @@ -42,9 +42,9 @@ class Game: self.last_time = current_time await self.update(delta_time) - await asyncio.sleep( - max(self.min_time_step - (time.time() - current_time), 0) - ) + sleep_time = max(self.min_time_step - (time.time() - current_time), 0) + if sleep_time > 0: + await asyncio.sleep(sleep_time) steps_since_log += 1