Skip to content

Instantly share code, notes, and snippets.

@jaames
Last active April 18, 2020 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaames/6b3bdfe858ad29a4b9f8e3ad6766e722 to your computer and use it in GitHub Desktop.
Save jaames/6b3bdfe858ad29a4b9f8e3ad6766e722 to your computer and use it in GitHub Desktop.
kwz optimisation idea
# original code:
for tile_offset_y in range(0, 240, 128):
for tile_offset_x in range(0, 320, 128):
# each large tile is made of 8 * 8 small tiles
for sub_tile_offset_y in range(0, 128, 8):
y = tile_offset_y + sub_tile_offset_y
# if the tile falls off the bottom of the frame, jump to the next large tile
if y >= 240: break
for sub_tile_offset_x in range(0, 128, 8):
x = tile_offset_x + sub_tile_offset_x
# if the tile falls off the right of the frame, jump to the next small tile row
if x >= 320:
break
# ... decode tile @ (x, y)
# precompute this as table
KWZ_TILE_COORDS = []
for tile_offset_y in range(0, 240, 128):
for tile_offset_x in range(0, 320, 128):
for sub_tile_offset_y in range(0, 128, 8):
y = tile_offset_y + sub_tile_offset_y
if y >= 240: break
for sub_tile_offset_x in range(0, 128, 8):
x = tile_offset_x + sub_tile_offset_x
if x >= 320:
break
KWZ_TILE_OFFSETS.append((x, y))
# replace nested loop
for (x, y) in KWZ_TILE_COORDS:
# ... decode tile @ (x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment