Core: optimize away Item.world (#840)

* Core: optimize away Item.world

* Update test/general/TestFill.py

* Test: undo unnecessary changes

* lttp: remove two more Item.world writes

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
Fabian Dill 2022-08-05 17:09:21 +02:00 committed by GitHub
parent d15c30f63b
commit 21f7c6c0ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 18 deletions

View File

@ -384,7 +384,6 @@ class MultiWorld():
return self.worlds[player].create_item(item_name)
def push_precollected(self, item: Item):
item.world = self
self.precollected_items[item.player].append(item)
self.state.collect(item, True)
@ -392,7 +391,6 @@ class MultiWorld():
assert location.can_fill(self.state, item, False), f"Cannot place {item} into {location}."
location.item = item
item.location = location
item.world = self # try to not have this here anymore and create it with item?
if collect:
self.state.collect(item, location.event, location)
@ -1102,7 +1100,6 @@ class Location:
self.item = item
item.location = self
self.event = item.advancement
self.item.world = self.parent_region.world
self.locked = True
def __repr__(self):
@ -1148,7 +1145,6 @@ class ItemClassification(IntFlag):
class Item:
location: Optional[Location] = None
world: Optional[MultiWorld] = None
code: Optional[int] = None # an item with ID None is called an Event, and does not get written to multidata
name: str
game: str = "Generic"
@ -1175,11 +1171,11 @@ class Item:
self.code = code
@property
def hint_text(self):
def hint_text(self) -> str:
return getattr(self, "_hint_text", self.name.replace("_", " ").replace("-", " "))
@property
def pedestal_hint_text(self):
def pedestal_hint_text(self) -> str:
return getattr(self, "_pedestal_hint_text", self.name.replace("_", " ").replace("-", " "))
@property
@ -1205,7 +1201,7 @@ class Item:
def __eq__(self, other):
return self.name == other.name and self.player == other.player
def __lt__(self, other: Item):
def __lt__(self, other: Item) -> bool:
if other.player != self.player:
return other.player < self.player
return self.name < other.name
@ -1213,11 +1209,13 @@ class Item:
def __hash__(self):
return hash((self.name, self.player))
def __repr__(self):
def __repr__(self) -> str:
return self.__str__()
def __str__(self):
return self.world.get_name_string_for_object(self) if self.world else f'{self.name} (Player {self.player})'
def __str__(self) -> str:
if self.location:
return self.location.parent_region.world.get_name_string_for_object(self)
return f"{self.name} (Player {self.player})"
class Spoiler():

View File

@ -217,9 +217,6 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
logger.info("Running Item Plando")
for item in world.itempool:
item.world = world
distribute_planned(world)
logger.info('Running Pre Main Fill.')

View File

@ -49,8 +49,7 @@ class PlayerDefinition(object):
region_name = "player" + str(self.id) + region_tag
region = Region("player" + str(self.id) + region_tag, RegionType.Generic,
"Region Hint", self.id, self.world)
self.locations += generate_locations(size,
self.id, None, region, region_tag)
self.locations += generate_locations(size, self.id, None, region, region_tag)
entrance = Entrance(self.id, region_name + "_entrance", parent)
parent.exits.append(entrance)

View File

@ -15,7 +15,6 @@ def create_dungeons(world, player):
dungeon_items, player)
for item in dungeon.all_items:
item.dungeon = dungeon
item.world = world
dungeon.boss = BossFactory(default_boss, player) if default_boss else None
for region in dungeon.regions:
world.get_region(region, player).dungeon = dungeon

View File

@ -935,7 +935,6 @@ def set_trock_key_rules(world, player):
else:
# A key is required in the Big Key Chest to prevent a possible softlock. Place an extra key to ensure 100% locations still works
item = ItemFactory('Small Key (Turtle Rock)', player)
item.world = world
location = world.get_location('Turtle Rock - Big Key Chest', player)
location.place_locked_item(item)
location.event = True

View File

@ -335,7 +335,6 @@ def create_shops(world, player: int):
else:
loc.item = ItemFactory(GetBeemizerItem(world, player, 'Nothing'), player)
loc.shop_slot_disabled = True
loc.item.world = world
shop.region.locations.append(loc)
world.clear_location_cache()