Adds cache for autogen sprites to reduce lag when loading sprites

This commit is contained in:
infinitefusion
2023-11-23 19:25:28 -05:00
parent cbe71d8530
commit 1af9d853cb
8 changed files with 30 additions and 6 deletions

View File

@@ -48,7 +48,7 @@ module GameData
end
if !self::DATA.has_key?(other)
echo _INTL("Unknown ID {1}.", other)
echoln _INTL("Unknown ID {1}.", other)
return self::get(:PIKACHU)
end

View File

@@ -229,7 +229,7 @@ class PokemonStorage
def pbStoreCaught(pkmn)
if @currentBox>=0
pkmn.time_form_set = nil
pkmn.form = 0 if pkmn.isSpecies?(:SHAYMIN)
#pkmn.form = 0 if pkmn.isSpecies?(:SHAYMIN)
#pkmn.heal
end
for i in 0...maxPokemon(@currentBox)

View File

@@ -1932,7 +1932,7 @@ class PokemonStorageScreen
if heldpoke || selected[0] == -1
p = (heldpoke) ? heldpoke : @storage[-1, index]
p.time_form_set = nil
p.form = 0 if p.isSpecies?(:SHAYMIN)
#p.form = 0 if p.isSpecies?(:SHAYMIN)
#p.heal
end
@scene.pbStore(selected, heldpoke, destbox, firstfree)

View File

@@ -257,7 +257,18 @@ def record_sprite_substitution(substitution_id, sprite_name)
$PokemonGlobal.alt_sprite_substitutions[substitution_id] = sprite_name
end
def add_to_autogen_cache(pokemon_id, sprite_name)
return if !$PokemonGlobal
return if !$PokemonGlobal.autogen_sprites_cache
$PokemonGlobal.autogen_sprites_cache[pokemon_id]=sprite_name
end
class PokemonGlobalMetadata
attr_accessor :autogen_sprites_cache
end
def get_fusion_sprite_path(head_id, body_id, spriteform_body = nil, spriteform_head = nil)
$PokemonGlobal.autogen_sprites_cache = {} if $PokemonGlobal && !$PokemonGlobal.autogen_sprites_cache
#Todo: ça va chier si on fusionne une forme d'un pokemon avec une autre forme, mais pas un problème pour tout de suite
form_suffix = ""
form_suffix += "_" + spriteform_body.to_s if spriteform_body
@@ -286,6 +297,11 @@ def get_fusion_sprite_path(head_id, body_id, spriteform_body = nil, spriteform_h
record_sprite_substitution(substitution_id, local_custom_path)
return local_custom_path
end
echoln $PokemonGlobal.autogen_sprites_cache
#if the game has loaded an autogen earlier, no point in trying to redownload, so load that instead
return $PokemonGlobal.autogen_sprites_cache[substitution_id] if $PokemonGlobal.autogen_sprites_cache[substitution_id] && $PokemonGlobal
#Try to download custom sprite if none found locally
downloaded_custom = download_custom_sprite(head_id, body_id, spriteform_body_letter, spriteform_head_letter, random_alt)
if downloaded_custom
@@ -295,11 +311,17 @@ def get_fusion_sprite_path(head_id, body_id, spriteform_body = nil, spriteform_h
#Try local generated sprite
local_generated_path = Settings::BATTLERS_FOLDER + head_id.to_s + spriteform_head_letter + "/" + filename
return local_generated_path if pbResolveBitmap(local_generated_path)
if pbResolveBitmap(local_generated_path)
add_to_autogen_cache(substitution_id,local_generated_path)
return local_generated_path
end
#Download generated sprite if nothing else found
autogen_path = download_autogen_sprite(head_id, body_id,spriteform_body,spriteform_head)
return autogen_path if pbResolveBitmap(autogen_path)
if pbResolveBitmap(autogen_path)
add_to_autogen_cache(substitution_id,autogen_path)
return autogen_path
end
return Settings::DEFAULT_SPRITE_PATH
end

View File

@@ -75,6 +75,7 @@ def download_sprite(base_path, head_id, body_id, saveLocation = "Graphics/temp",
echoln _INTL("\nDownloaded file from {1} to {2}", base_path, saveLocation)
return downloaded_file_name
end
echoln "tried to download " + base_path
return nil
rescue MKXPError, Errno::ENOENT
return nil

View File

@@ -412,6 +412,7 @@ class PokemonLoadScreen
Game.load(@save_data)
$game_switches[SWITCH_V5_1] = true
$PokemonGlobal.alt_sprite_substitutions = {} if !$PokemonGlobal.alt_sprite_substitutions
$PokemonGlobal.autogen_sprites_cache = {}
return
when cmd_new_game
@scene.pbEndScene

View File

@@ -1482,7 +1482,7 @@ def pbUnfuse(pokemon, scene, supersplicers, pcPosition = nil)
bodyPoke = getBasePokemonID(pokemon.species_data.id_number, true)
headPoke = getBasePokemonID(pokemon.species_data.id_number, false)
if (pokemon.obtain_method == 2 || pokemon.ot != $Trainer.name) # && !canunfuse
if (pokemon.obtain_method == 2 || pokemon.ot != $Trainer.name) && false # && !canunfuse
scene.pbDisplay(_INTL("You can't unfuse a Pokémon obtained in a trade!"))
return false
else

Binary file not shown.