secure sprite table fill with threadlock
This commit is contained in:
parent
99c2185410
commit
8e85e2892a
|
@ -161,7 +161,7 @@ def main(args=None, callback = ERmain):
|
||||||
if path:
|
if path:
|
||||||
try:
|
try:
|
||||||
settings = settings_cache[path] if settings_cache[path] else roll_settings(weights_cache[path])
|
settings = settings_cache[path] if settings_cache[path] else roll_settings(weights_cache[path])
|
||||||
if settings.sprite is not None and not os.path.isfile(settings.sprite) and not get_sprite_from_name(
|
if settings.sprite and not os.path.isfile(settings.sprite) and not get_sprite_from_name(
|
||||||
settings.sprite):
|
settings.sprite):
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"Warning: The chosen sprite, \"{settings.sprite}\", for yaml \"{path}\", does not exist.")
|
f"Warning: The chosen sprite, \"{settings.sprite}\", for yaml \"{path}\", does not exist.")
|
||||||
|
|
28
Rom.py
28
Rom.py
|
@ -336,21 +336,23 @@ def patch_enemizer(world, player: int, rom: LocalRom, enemizercli, random_sprite
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
sprite_list_lock = threading.Lock()
|
||||||
_sprite_table = {}
|
_sprite_table = {}
|
||||||
def _populate_sprite_table():
|
|
||||||
if not _sprite_table:
|
|
||||||
def load_sprite_from_file(file):
|
|
||||||
filepath = os.path.join(dir, file)
|
|
||||||
sprite = Sprite(filepath)
|
|
||||||
if sprite.valid:
|
|
||||||
_sprite_table[sprite.name.lower()] = sprite
|
|
||||||
_sprite_table[os.path.basename(filepath).split(".")[0]] = sprite # alias for filename base
|
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor() as pool:
|
|
||||||
for dir in [local_path('data/sprites/alttpr'), local_path('data/sprites/custom')]:
|
def _populate_sprite_table():
|
||||||
for file in os.listdir(dir):
|
with sprite_list_lock:
|
||||||
pool.submit(load_sprite_from_file, file)
|
if not _sprite_table:
|
||||||
|
def load_sprite_from_file(file):
|
||||||
|
sprite = Sprite(file)
|
||||||
|
if sprite.valid:
|
||||||
|
_sprite_table[sprite.name.lower()] = sprite
|
||||||
|
_sprite_table[os.path.basename(file).split(".")[0].lower()] = sprite # alias for filename base
|
||||||
|
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as pool:
|
||||||
|
for dir in [local_path('data/sprites/alttpr'), local_path('data/sprites/custom')]:
|
||||||
|
for file in os.listdir(dir):
|
||||||
|
pool.submit(load_sprite_from_file, os.path.join(dir, file))
|
||||||
|
|
||||||
def get_sprite_from_name(name, local_random=random):
|
def get_sprite_from_name(name, local_random=random):
|
||||||
_populate_sprite_table()
|
_populate_sprite_table()
|
||||||
|
|
Loading…
Reference in New Issue