Core: improve sweep_for_events efficiency (#1092)
This commit is contained in:
parent
f909576813
commit
0afb7096de
|
@ -689,14 +689,14 @@ class CollectionState():
|
||||||
def sweep_for_events(self, key_only: bool = False, locations: Optional[Iterable[Location]] = None) -> None:
|
def sweep_for_events(self, key_only: bool = False, locations: Optional[Iterable[Location]] = None) -> None:
|
||||||
if locations is None:
|
if locations is None:
|
||||||
locations = self.world.get_filled_locations()
|
locations = self.world.get_filled_locations()
|
||||||
new_locations = True
|
reachable_events = True
|
||||||
# since the loop has a good chance to run more than once, only filter the events once
|
# since the loop has a good chance to run more than once, only filter the events once
|
||||||
locations = {location for location in locations if location.event and
|
locations = {location for location in locations if location.event and
|
||||||
not key_only or getattr(location.item, "locked_dungeon_item", False)}
|
not key_only or getattr(location.item, "locked_dungeon_item", False)}
|
||||||
while new_locations:
|
while reachable_events:
|
||||||
reachable_events = {location for location in locations if location.can_reach(self)}
|
reachable_events = {location for location in locations if location.can_reach(self)}
|
||||||
new_locations = reachable_events - self.events
|
locations -= reachable_events
|
||||||
for event in new_locations:
|
for event in reachable_events:
|
||||||
self.events.add(event)
|
self.events.add(event)
|
||||||
assert isinstance(event.item, Item), "tried to collect Event with no Item"
|
assert isinstance(event.item, Item), "tried to collect Event with no Item"
|
||||||
self.collect(event.item, True, event)
|
self.collect(event.item, True, event)
|
||||||
|
|
Loading…
Reference in New Issue