1
Fork 0
mirror of https://github.com/Steffo99/lihzahrd.git synced 2024-11-25 01:24:21 +00:00

Optimize _read_tile_block (10s gain!)

This commit is contained in:
Steffo 2020-06-08 02:55:59 +02:00
parent 906f2094b8
commit be6e1a0b18
Signed by: steffo
GPG key ID: 896A80F55F7C97F0

View file

@ -240,7 +240,7 @@ class World:
self.shadow_orbs = value self.shadow_orbs = value
@staticmethod @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 # Once again, this code is a mess
flags1 = fr.bits() flags1 = fr.bits()
has_block = flags1[1] has_block = flags1[1]
@ -320,7 +320,7 @@ class World:
multiply_by = 1 multiply_by = 1
# Create tile # Create tile
tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring) tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring)
return [tile] * multiply_by return tile, multiply_by
@property @property
def is_classic(self): def is_classic(self):
@ -351,8 +351,10 @@ class World:
while tm.size.x < world_size.x: while tm.size.x < world_size.x:
column = [] column = []
while len(column) < world_size.y: while len(column) < world_size.y:
readtiles = cls._read_tile_block(f, tileframeimportant) tile, multiply_by = cls._read_tile_block(f, tileframeimportant)
column = [*column, *readtiles] for _ in range(multiply_by):
# This works by reference, and stops working if write support is added
column.append(tile)
tm.add_column(column) tm.add_column(column)
return tm return tm