Skip to content

Commit

Permalink
Landstalker: remove global ref to multiworld (#4175)
Browse files Browse the repository at this point in the history
* Landstalker: remove global ref to multiworld

`cached_spheres` holds a reference to the multiworld, which leaks the multiworld if multidata is skipped. Instead of making it a class variable, give a reference to each matching world.

* Switch to using `get_game_worlds`
  • Loading branch information
Zannick authored Nov 13, 2024
1 parent 85159a4 commit c295926
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions worlds/landstalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LandstalkerWorld(World):
item_name_to_id = build_item_name_to_id_table()
location_name_to_id = build_location_name_to_id_table()

cached_spheres: ClassVar[List[Set[Location]]]
cached_spheres: List[Set[Location]]

def __init__(self, multiworld, player):
super().__init__(multiworld, player)
Expand All @@ -47,6 +47,7 @@ def __init__(self, multiworld, player):
self.dark_region_ids = []
self.teleport_tree_pairs = []
self.jewel_items = []
self.cached_spheres = []

def fill_slot_data(self) -> dict:
# Generate hints.
Expand Down Expand Up @@ -220,14 +221,17 @@ def get_starting_health(self):
return 4

@classmethod
def stage_post_fill(cls, multiworld):
def stage_post_fill(cls, multiworld: MultiWorld):
# Cache spheres for hint calculation after fill completes.
cls.cached_spheres = list(multiworld.get_spheres())
cached_spheres = list(multiworld.get_spheres())
for world in multiworld.get_game_worlds(cls.game):
world.cached_spheres = cached_spheres

@classmethod
def stage_modify_multidata(cls, *_):
def stage_modify_multidata(cls, multiworld: MultiWorld, *_):
# Clean up all references in cached spheres after generation completes.
del cls.cached_spheres
for world in multiworld.get_game_worlds(cls.game):
world.cached_spheres = []

def adjust_shop_prices(self):
# Calculate prices for items in shops once all items have their final position
Expand Down

0 comments on commit c295926

Please sign in to comment.