From b281734312bb4f324704e33aebc763c0825026a4 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Fri, 26 Feb 2021 23:00:27 +0000 Subject: [PATCH] Cached MapInfos.rxdata and map_connections.dat, reduced usage of load_data --- .../003_Game classes/011_MapFactory.rb | 6 +--- .../005_Map renderer/005_TileDrawingHelper.rb | 4 +-- .../007_Events and files/001_FileTests.rb | 10 +++---- .../007_Events and files/003_Intl_Messages.rb | 2 +- .../009_Objects and windows/011_Messages.rb | 2 +- Data/Scripts/011_Data/001_Data_Cache.rb | 29 +++++++++++++++++-- .../Scripts/013_Overworld/002_PField_Field.rb | 6 ++-- .../009_PField_RoamingPokemon.rb | 2 +- .../002_PSystem_System.rb | 2 +- .../003_Debug_MenuExtraCode.rb | 4 +-- Data/Scripts/021_Debug/004_Editor_Screens.rb | 6 ++-- .../Scripts/021_Debug/009_Editor_Utilities.rb | 2 +- .../021_Debug/011_Editor_MapConnections.rb | 3 +- .../022_Compiler/002_Compiler_CompilePBS.rb | 15 ++++++---- .../022_Compiler/003_Compiler_WritePBS.rb | 8 ++--- .../004_Compiler_MapsAndEvents.rb | 5 ++-- 16 files changed, 65 insertions(+), 41 deletions(-) diff --git a/Data/Scripts/003_Game classes/011_MapFactory.rb b/Data/Scripts/003_Game classes/011_MapFactory.rb index 9a76f9072..e4864bb3e 100644 --- a/Data/Scripts/003_Game classes/011_MapFactory.rb +++ b/Data/Scripts/003_Game classes/011_MapFactory.rb @@ -416,11 +416,7 @@ module MapFactoryHelper def self.getMapConnections if !@@MapConnections @@MapConnections = [] - begin - conns = load_data("Data/map_connections.dat") - rescue - conns = [] - end + conns = pbLoadMapConnections for i in 0...conns.length conn = conns[i] v = getMapEdge(conn[0],conn[1]) diff --git a/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb b/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb index 6e8995eda..707b4d9af 100644 --- a/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb +++ b/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb @@ -153,7 +153,7 @@ def createMinimap2(mapid) bitmap=BitmapWrapper.new(map.width*4,map.height*4) black=Color.new(0,0,0) bigmap=(map.width>40 && map.height>40) - tilesets=load_data("Data/Tilesets.rxdata") + tilesets=$data_tilesets tileset=tilesets[map.tileset_id] return bitmap if !tileset helper=TileDrawingHelper.fromTileset(tileset) @@ -181,7 +181,7 @@ def createMinimap(mapid) return BitmapWrapper.new(32,32) if !map bitmap=BitmapWrapper.new(map.width*4,map.height*4) black=Color.new(0,0,0) - tilesets=load_data("Data/Tilesets.rxdata") + tilesets=$data_tilesets tileset=tilesets[map.tileset_id] return bitmap if !tileset helper=TileDrawingHelper.fromTileset(tileset) diff --git a/Data/Scripts/007_Events and files/001_FileTests.rb b/Data/Scripts/007_Events and files/001_FileTests.rb index 0f41dd9f8..4b0bf17a6 100644 --- a/Data/Scripts/007_Events and files/001_FileTests.rb +++ b/Data/Scripts/007_Events and files/001_FileTests.rb @@ -128,7 +128,7 @@ module RTP end # Gets all RGSS search paths. - # This function basically does nothing now, because + # This function basically does nothing now, because # the passage of time and introduction of MKXP make # it useless, but leaving it for compatibility # reasons @@ -179,7 +179,7 @@ end # and matching mount points added through System.mount def pbRgssExists?(filename) filename = canonicalize(filename) - if safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a") + if safeExists?("./Game.rgssad") return pbGetFileChar(filename)!=nil else return safeExists?(filename) @@ -193,7 +193,7 @@ end # and matching mount points added through System.mount def pbRgssOpen(file,mode=nil) #File.open("debug.txt","ab") { |fw| fw.write([file,mode,Time.now.to_f].inspect+"\r\n") } - if !safeExists?("./Game.rgssad") && !safeExists?("./Game.rgss2a") + if !safeExists?("./Game.rgssad") if block_given? File.open(file,mode) { |f| yield f } return nil @@ -216,7 +216,7 @@ end # encrypted archives. def pbGetFileChar(file) file = canonicalize(file) - if !safeExists?("./Game.rgssad") && !safeExists?("./Game.rgss2a") + if !safeExists?("./Game.rgssad") return nil if !safeExists?(file) begin File.open(file,"rb") { |f| return f.read(1) } # read one byte @@ -245,7 +245,7 @@ end # and matching mount points added through System.mount def pbGetFileString(file) file = canonicalize(file) - if !(safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a")) + if !safeExists?("./Game.rgssad") return nil if !safeExists?(file) begin File.open(file,"rb") { |f| return f.read } # read all data diff --git a/Data/Scripts/007_Events and files/003_Intl_Messages.rb b/Data/Scripts/007_Events and files/003_Intl_Messages.rb index 29faea357..bcc5a2ace 100644 --- a/Data/Scripts/007_Events and files/003_Intl_Messages.rb +++ b/Data/Scripts/007_Events and files/003_Intl_Messages.rb @@ -96,7 +96,7 @@ def pbSetTextMessages choices|=[] items.concat(choices) MessageTypes.setMapMessagesAsHash(0,items) - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos mapnames=[] for id in mapinfos.keys mapnames[id]=mapinfos[id].name diff --git a/Data/Scripts/009_Objects and windows/011_Messages.rb b/Data/Scripts/009_Objects and windows/011_Messages.rb index 5b2e0966c..82a1db9be 100644 --- a/Data/Scripts/009_Objects and windows/011_Messages.rb +++ b/Data/Scripts/009_Objects and windows/011_Messages.rb @@ -343,7 +343,7 @@ end #=============================================================================== def pbGetBasicMapNameFromId(id) begin - map = load_data("Data/MapInfos.rxdata") + map = pbLoadMapInfos return "" if !map return map[id].name rescue diff --git a/Data/Scripts/011_Data/001_Data_Cache.rb b/Data/Scripts/011_Data/001_Data_Cache.rb index b22e25b3f..073c0bc16 100644 --- a/Data/Scripts/011_Data/001_Data_Cache.rb +++ b/Data/Scripts/011_Data/001_Data_Cache.rb @@ -8,6 +8,8 @@ class PokemonTemp attr_accessor :speciesShadowMovesets attr_accessor :moveToAnim attr_accessor :battleAnims + attr_accessor :mapInfos + attr_accessor :mapConnections end def pbClearData @@ -18,15 +20,14 @@ def pbClearData $PokemonTemp.speciesShadowMovesets = nil $PokemonTemp.moveToAnim = nil $PokemonTemp.battleAnims = nil + $PokemonTemp.mapInfos = nil + $PokemonTemp.mapConnections = nil end MapFactoryHelper.clear $PokemonEncounters.setup($game_map.map_id) if $game_map && $PokemonEncounters if pbRgssExists?("Data/Tilesets.rxdata") $data_tilesets = load_data("Data/Tilesets.rxdata") end - if pbRgssExists?("Data/Tilesets.rvdata") - $data_tilesets = load_data("Data/Tilesets.rvdata") - end end #=============================================================================== @@ -95,3 +96,25 @@ def pbLoadBattleAnimations end return $PokemonTemp.battleAnims end + +#=============================================================================== +# Method relating to map connections data. +#=============================================================================== +def pbLoadMapConnections + $PokemonTemp = PokemonTemp.new if !$PokemonTemp + if !$PokemonTemp.mapConnections + $PokemonTemp.mapConnections = load_data("Data/map_connections.dat") || [] + end + return $PokemonTemp.mapConnections +end + +#=============================================================================== +# Method relating to map infos data. +#=============================================================================== +def pbLoadMapInfos + $PokemonTemp = PokemonTemp.new if !$PokemonTemp + if !$PokemonTemp.mapInfos + $PokemonTemp.mapInfos = load_data("Data/MapInfos.rxdata") + end + return $PokemonTemp.mapInfos +end diff --git a/Data/Scripts/013_Overworld/002_PField_Field.rb b/Data/Scripts/013_Overworld/002_PField_Field.rb index 6efdb84ec..37d3daeee 100644 --- a/Data/Scripts/013_Overworld/002_PField_Field.rb +++ b/Data/Scripts/013_Overworld/002_PField_Field.rb @@ -405,7 +405,7 @@ Events.onMapChanging += proc { |_sender, e| next if new_map_ID == 0 old_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) next if !old_map_metadata || !old_map_metadata.weather - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos if $game_map.name == map_infos[new_map_ID].name new_map_metadata = GameData::MapMetadata.try_get(new_map_ID) next if new_map_metadata && new_map_metadata.weather @@ -425,7 +425,7 @@ Events.onMapChange += proc { |_sender, e| $PokemonGlobal.visitedMaps[$game_map.map_id] = true next if old_map_ID == 0 || old_map_ID == $game_map.map_id next if !new_map_metadata || !new_map_metadata.weather - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos if $game_map.name == map_infos[old_map_ID].name old_map_metadata = GameData::MapMetadata.try_get(old_map_ID) next if old_map_metadata && old_map_metadata.weather @@ -470,7 +470,7 @@ Events.onMapSceneChange += proc { |_sender, e| Settings::NO_SIGNPOSTS[2 * i] == $game_map.map_id break if nosignpost end - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos oldmapname = mapinfos[$PokemonGlobal.mapTrail[1]].name nosignpost = true if $game_map.name == oldmapname end diff --git a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb index 6e14cd59f..5fe5362d7 100644 --- a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb +++ b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb @@ -96,7 +96,7 @@ end Events.onMapChange += proc { |_sender,e| oldMapID = e[0] # Get and compare map names - mapInfos = load_data("Data/MapInfos.rxdata") + mapInfos = pbLoadMapInfos next if mapInfos && oldMapID>0 && mapInfos[oldMapID] && mapInfos[oldMapID].name && $game_map.name==mapInfos[oldMapID].name # Make roaming Pokémon roam diff --git a/Data/Scripts/020_System and utilities/002_PSystem_System.rb b/Data/Scripts/020_System and utilities/002_PSystem_System.rb index a271974e9..d81679421 100644 --- a/Data/Scripts/020_System and utilities/002_PSystem_System.rb +++ b/Data/Scripts/020_System and utilities/002_PSystem_System.rb @@ -2,7 +2,7 @@ # exists, the real file is deleted to ensure that the file is loaded from the # encrypted archive. def pbSafeLoad(file) - if (safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a")) && safeExists?(file) + if safeExists?("./Game.rgssad") && safeExists?(file) File.delete(file) rescue nil end return load_data(file) diff --git a/Data/Scripts/021_Debug/001_Debug menus/003_Debug_MenuExtraCode.rb b/Data/Scripts/021_Debug/001_Debug menus/003_Debug_MenuExtraCode.rb index 4f3d99b7f..3e1efa4a8 100644 --- a/Data/Scripts/021_Debug/001_Debug menus/003_Debug_MenuExtraCode.rb +++ b/Data/Scripts/021_Debug/001_Debug menus/003_Debug_MenuExtraCode.rb @@ -422,7 +422,7 @@ class SpriteWindow_DebugRoamers < Window_DrawableCommand # roaming curmap = $PokemonGlobal.roamPosition[index] if curmap - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos status = "[ROAMING][#{curmap}: #{mapinfos[curmap].name}]" else status = "[ROAMING][map not set]" @@ -771,7 +771,7 @@ end def pbDebugFixInvalidTiles num_errors = 0 num_error_maps = 0 - @tilesets = load_data("Data/Tilesets.rxdata") + @tilesets = $data_tilesets mapData = MapData.new t = Time.now.to_i Graphics.update diff --git a/Data/Scripts/021_Debug/004_Editor_Screens.rb b/Data/Scripts/021_Debug/004_Editor_Screens.rb index b3d4cb6d5..3741c54a7 100644 --- a/Data/Scripts/021_Debug/004_Editor_Screens.rb +++ b/Data/Scripts/021_Debug/004_Editor_Screens.rb @@ -4,7 +4,7 @@ # Main editor method for editing wild encounters. Lists all defined encounter # sets, and edits them. def pbEncountersEditor - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos commands = [] maps = [] list = pbListWindow([]) @@ -122,7 +122,7 @@ end # Lists the map ID, version number and defined encounter types for the given # encounter data (a GameData::Encounter instance), and edits them. def pbEncounterMapVersionEditor(enc_data) - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos commands = [] enc_types = [] list = pbListWindow([]) @@ -720,7 +720,7 @@ def pbMetadataScreen(map_id = 0) end def pbEditMetadata(map_id = 0) - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos data = [] if map_id == 0 # Global metadata map_name = _INTL("Global Metadata") diff --git a/Data/Scripts/021_Debug/009_Editor_Utilities.rb b/Data/Scripts/021_Debug/009_Editor_Utilities.rb index 9e61786b1..5e27503f8 100644 --- a/Data/Scripts/021_Debug/009_Editor_Utilities.rb +++ b/Data/Scripts/021_Debug/009_Editor_Utilities.rb @@ -59,7 +59,7 @@ def pbAllocateAnimation(animations,name) end def pbMapTree - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos maplevels = [] retarray = [] for i in mapinfos.keys diff --git a/Data/Scripts/021_Debug/011_Editor_MapConnections.rb b/Data/Scripts/021_Debug/011_Editor_MapConnections.rb index f9b7820f6..cd983cb17 100644 --- a/Data/Scripts/021_Debug/011_Editor_MapConnections.rb +++ b/Data/Scripts/021_Debug/011_Editor_MapConnections.rb @@ -285,6 +285,7 @@ class MapScreenScene def serializeConnectionData conndata=generateConnectionData() save_data(conndata, "Data/map_connections.dat") + $PokemonTemp.mapConnections = nil Compiler.write_connections @mapconns=conndata end @@ -330,7 +331,7 @@ class MapScreenScene @sprites["title"] = Window_UnformattedTextPokemon.newWithSize(_INTL("F: Help"), 0, 600 - 64, 800, 64, @viewport) @sprites["title"].z = 2 - @mapinfos=load_data("Data/MapInfos.rxdata") + @mapinfos=pbLoadMapInfos conns=MapFactoryHelper.getMapConnections @mapconns=[] for c in conns diff --git a/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb index b7b62f652..4812cdcbb 100644 --- a/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb @@ -69,12 +69,10 @@ module Compiler record.push(csvInt!(thisline,lineno)) record.push(csvEnumFieldOrInt!(thisline,hashenum,"",sprintf("(line %d)",lineno))) record.push(csvInt!(thisline,lineno)) - if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[0])) && - !pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[0])) + if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[0])) print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[0],FileLineData.linereport) end - if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[3])) && - !pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[3])) + if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[3])) print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[3],FileLineData.linereport) end case record[1] @@ -1530,6 +1528,7 @@ module Compiler rescue pbanims = PBAnimations.new end + changed = false move2anim = [[],[]] =begin anims = load_data("Data/Animations.rxdata") @@ -1550,16 +1549,20 @@ module Compiler if pbanims[i].name[/^OppMove\:\s*(.*)$/] if GameData::Move.exists?($~[1]) moveid = GameData::Move.get($~[1]).id_number + changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i move2anim[1][moveid] = i end elsif pbanims[i].name[/^Move\:\s*(.*)$/] if GameData::Move.exists?($~[1]) moveid = GameData::Move.get($~[1]).id_number + changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i move2anim[0][moveid] = i end end end - save_data(move2anim,"Data/move2anim.dat") - save_data(pbanims,"Data/PkmnAnimations.rxdata") + if changed + save_data(move2anim,"Data/move2anim.dat") + save_data(pbanims,"Data/PkmnAnimations.rxdata") + end end end diff --git a/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb b/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb index be87a9a81..247fbcba4 100644 --- a/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb +++ b/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb @@ -69,9 +69,9 @@ module Compiler end def write_connections - conndata = load_data("Data/map_connections.dat") rescue nil + conndata = pbLoadMapConnections return if !conndata - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos File.open("PBS/connections.txt","wb") { |f| add_PBS_header_to_file(f) f.write("\#-------------------------------\r\n") @@ -518,7 +518,7 @@ module Compiler # Save wild encounter data to PBS file #============================================================================= def write_encounters - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos File.open("PBS/encounters.txt", "wb") { |f| add_PBS_header_to_file(f) GameData::Encounter.each do |encounter_data| @@ -735,7 +735,7 @@ module Compiler f.write("\r\n") end # Write map metadata - map_infos = load_data("Data/MapInfos.rxdata") + map_infos = pbLoadMapInfos schema = GameData::MapMetadata::SCHEMA keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] } GameData::MapMetadata.each do |map_data| diff --git a/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb b/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb index 5b88fabcb..2d3f071b9 100644 --- a/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb @@ -14,7 +14,7 @@ module Compiler mapfiles[$1.to_i(10)] = true if map[/map(\d+)\.rxdata/i] end } - mapinfos = load_data("Data/MapInfos.rxdata") + mapinfos = pbLoadMapInfos maxOrder = 0 # Exclude maps found in mapinfos for id in mapinfos.keys @@ -38,6 +38,7 @@ module Compiler end if imported save_data(mapinfos,"Data/MapInfos.rxdata") + $PokemonTemp.mapInfos = nil pbMessage(_INTL("{1} new map(s) copied to the Data folder were successfully imported.",count)) end return imported @@ -239,7 +240,7 @@ module Compiler attr_reader :mapinfos def initialize - @mapinfos = load_data("Data/MapInfos.rxdata") + @mapinfos = pbLoadMapInfos @system = load_data("Data/System.rxdata") @tilesets = load_data("Data/Tilesets.rxdata") @mapxy = []