Skip to content

Commit

Permalink
Optimize _read_tile_block (10s gain!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffo99 committed Jun 10, 2020
1 parent 985644e commit 8e4f115
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lihzahrd/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def crimson_hearts(self, value):
self.shadow_orbs = value

@staticmethod
def _read_tile_block(fr: FileReader, tileframeimportant) -> List:
def _read_tile_block(fr: FileReader, tileframeimportant) -> Tuple[Tile, int]:
# Once again, this code is a mess
flags1 = fr.bits()
has_block = flags1[1]
Expand Down Expand Up @@ -320,7 +320,7 @@ def _read_tile_block(fr: FileReader, tileframeimportant) -> List:
multiply_by = 1
# Create tile
tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring)
return [tile] * multiply_by
return tile, multiply_by

@property
def is_classic(self):
Expand Down Expand Up @@ -351,8 +351,10 @@ def _create_tilematrix(cls, f, world_size: Coordinates, tileframeimportant: List
while tm.size.x < world_size.x:
column = []
while len(column) < world_size.y:
readtiles = cls._read_tile_block(f, tileframeimportant)
column = [*column, *readtiles]
tile, multiply_by = cls._read_tile_block(f, tileframeimportant)
for _ in range(multiply_by):
# This works by reference, and stops working if write support is added
column.append(tile)
tm.add_column(column)
return tm

Expand Down

0 comments on commit 8e4f115

Please sign in to comment.