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:
parent
d15c30f63b
commit
21f7c6c0ad
|
@ -384,7 +384,6 @@ class MultiWorld():
|
||||||
return self.worlds[player].create_item(item_name)
|
return self.worlds[player].create_item(item_name)
|
||||||
|
|
||||||
def push_precollected(self, item: Item):
|
def push_precollected(self, item: Item):
|
||||||
item.world = self
|
|
||||||
self.precollected_items[item.player].append(item)
|
self.precollected_items[item.player].append(item)
|
||||||
self.state.collect(item, True)
|
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}."
|
assert location.can_fill(self.state, item, False), f"Cannot place {item} into {location}."
|
||||||
location.item = item
|
location.item = item
|
||||||
item.location = location
|
item.location = location
|
||||||
item.world = self # try to not have this here anymore and create it with item?
|
|
||||||
if collect:
|
if collect:
|
||||||
self.state.collect(item, location.event, location)
|
self.state.collect(item, location.event, location)
|
||||||
|
|
||||||
|
@ -1102,7 +1100,6 @@ class Location:
|
||||||
self.item = item
|
self.item = item
|
||||||
item.location = self
|
item.location = self
|
||||||
self.event = item.advancement
|
self.event = item.advancement
|
||||||
self.item.world = self.parent_region.world
|
|
||||||
self.locked = True
|
self.locked = True
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -1148,7 +1145,6 @@ class ItemClassification(IntFlag):
|
||||||
|
|
||||||
class Item:
|
class Item:
|
||||||
location: Optional[Location] = None
|
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
|
code: Optional[int] = None # an item with ID None is called an Event, and does not get written to multidata
|
||||||
name: str
|
name: str
|
||||||
game: str = "Generic"
|
game: str = "Generic"
|
||||||
|
@ -1175,11 +1171,11 @@ class Item:
|
||||||
self.code = code
|
self.code = code
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hint_text(self):
|
def hint_text(self) -> str:
|
||||||
return getattr(self, "_hint_text", self.name.replace("_", " ").replace("-", " "))
|
return getattr(self, "_hint_text", self.name.replace("_", " ").replace("-", " "))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pedestal_hint_text(self):
|
def pedestal_hint_text(self) -> str:
|
||||||
return getattr(self, "_pedestal_hint_text", self.name.replace("_", " ").replace("-", " "))
|
return getattr(self, "_pedestal_hint_text", self.name.replace("_", " ").replace("-", " "))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1205,7 +1201,7 @@ class Item:
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self.name == other.name and self.player == other.player
|
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:
|
if other.player != self.player:
|
||||||
return other.player < self.player
|
return other.player < self.player
|
||||||
return self.name < other.name
|
return self.name < other.name
|
||||||
|
@ -1213,11 +1209,13 @@ class Item:
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name, self.player))
|
return hash((self.name, self.player))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self) -> str:
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return self.world.get_name_string_for_object(self) if self.world else f'{self.name} (Player {self.player})'
|
if self.location:
|
||||||
|
return self.location.parent_region.world.get_name_string_for_object(self)
|
||||||
|
return f"{self.name} (Player {self.player})"
|
||||||
|
|
||||||
|
|
||||||
class Spoiler():
|
class Spoiler():
|
||||||
|
|
3
Main.py
3
Main.py
|
@ -217,9 +217,6 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
||||||
|
|
||||||
logger.info("Running Item Plando")
|
logger.info("Running Item Plando")
|
||||||
|
|
||||||
for item in world.itempool:
|
|
||||||
item.world = world
|
|
||||||
|
|
||||||
distribute_planned(world)
|
distribute_planned(world)
|
||||||
|
|
||||||
logger.info('Running Pre Main Fill.')
|
logger.info('Running Pre Main Fill.')
|
||||||
|
|
|
@ -49,8 +49,7 @@ class PlayerDefinition(object):
|
||||||
region_name = "player" + str(self.id) + region_tag
|
region_name = "player" + str(self.id) + region_tag
|
||||||
region = Region("player" + str(self.id) + region_tag, RegionType.Generic,
|
region = Region("player" + str(self.id) + region_tag, RegionType.Generic,
|
||||||
"Region Hint", self.id, self.world)
|
"Region Hint", self.id, self.world)
|
||||||
self.locations += generate_locations(size,
|
self.locations += generate_locations(size, self.id, None, region, region_tag)
|
||||||
self.id, None, region, region_tag)
|
|
||||||
|
|
||||||
entrance = Entrance(self.id, region_name + "_entrance", parent)
|
entrance = Entrance(self.id, region_name + "_entrance", parent)
|
||||||
parent.exits.append(entrance)
|
parent.exits.append(entrance)
|
||||||
|
|
|
@ -15,7 +15,6 @@ def create_dungeons(world, player):
|
||||||
dungeon_items, player)
|
dungeon_items, player)
|
||||||
for item in dungeon.all_items:
|
for item in dungeon.all_items:
|
||||||
item.dungeon = dungeon
|
item.dungeon = dungeon
|
||||||
item.world = world
|
|
||||||
dungeon.boss = BossFactory(default_boss, player) if default_boss else None
|
dungeon.boss = BossFactory(default_boss, player) if default_boss else None
|
||||||
for region in dungeon.regions:
|
for region in dungeon.regions:
|
||||||
world.get_region(region, player).dungeon = dungeon
|
world.get_region(region, player).dungeon = dungeon
|
||||||
|
|
|
@ -935,7 +935,6 @@ def set_trock_key_rules(world, player):
|
||||||
else:
|
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
|
# 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 = ItemFactory('Small Key (Turtle Rock)', player)
|
||||||
item.world = world
|
|
||||||
location = world.get_location('Turtle Rock - Big Key Chest', player)
|
location = world.get_location('Turtle Rock - Big Key Chest', player)
|
||||||
location.place_locked_item(item)
|
location.place_locked_item(item)
|
||||||
location.event = True
|
location.event = True
|
||||||
|
|
|
@ -335,7 +335,6 @@ def create_shops(world, player: int):
|
||||||
else:
|
else:
|
||||||
loc.item = ItemFactory(GetBeemizerItem(world, player, 'Nothing'), player)
|
loc.item = ItemFactory(GetBeemizerItem(world, player, 'Nothing'), player)
|
||||||
loc.shop_slot_disabled = True
|
loc.shop_slot_disabled = True
|
||||||
loc.item.world = world
|
|
||||||
shop.region.locations.append(loc)
|
shop.region.locations.append(loc)
|
||||||
world.clear_location_cache()
|
world.clear_location_cache()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue