Cached MapInfos.rxdata and map_connections.dat, reduced usage of load_data

This commit is contained in:
Maruno17
2021-02-26 23:00:27 +00:00
parent c9903c59c8
commit b281734312
16 changed files with 65 additions and 41 deletions

View File

@@ -416,11 +416,7 @@ module MapFactoryHelper
def self.getMapConnections def self.getMapConnections
if !@@MapConnections if !@@MapConnections
@@MapConnections = [] @@MapConnections = []
begin conns = pbLoadMapConnections
conns = load_data("Data/map_connections.dat")
rescue
conns = []
end
for i in 0...conns.length for i in 0...conns.length
conn = conns[i] conn = conns[i]
v = getMapEdge(conn[0],conn[1]) v = getMapEdge(conn[0],conn[1])

View File

@@ -153,7 +153,7 @@ def createMinimap2(mapid)
bitmap=BitmapWrapper.new(map.width*4,map.height*4) bitmap=BitmapWrapper.new(map.width*4,map.height*4)
black=Color.new(0,0,0) black=Color.new(0,0,0)
bigmap=(map.width>40 && map.height>40) bigmap=(map.width>40 && map.height>40)
tilesets=load_data("Data/Tilesets.rxdata") tilesets=$data_tilesets
tileset=tilesets[map.tileset_id] tileset=tilesets[map.tileset_id]
return bitmap if !tileset return bitmap if !tileset
helper=TileDrawingHelper.fromTileset(tileset) helper=TileDrawingHelper.fromTileset(tileset)
@@ -181,7 +181,7 @@ def createMinimap(mapid)
return BitmapWrapper.new(32,32) if !map return BitmapWrapper.new(32,32) if !map
bitmap=BitmapWrapper.new(map.width*4,map.height*4) bitmap=BitmapWrapper.new(map.width*4,map.height*4)
black=Color.new(0,0,0) black=Color.new(0,0,0)
tilesets=load_data("Data/Tilesets.rxdata") tilesets=$data_tilesets
tileset=tilesets[map.tileset_id] tileset=tilesets[map.tileset_id]
return bitmap if !tileset return bitmap if !tileset
helper=TileDrawingHelper.fromTileset(tileset) helper=TileDrawingHelper.fromTileset(tileset)

View File

@@ -128,7 +128,7 @@ module RTP
end end
# Gets all RGSS search paths. # 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 # the passage of time and introduction of MKXP make
# it useless, but leaving it for compatibility # it useless, but leaving it for compatibility
# reasons # reasons
@@ -179,7 +179,7 @@ end
# and matching mount points added through System.mount # and matching mount points added through System.mount
def pbRgssExists?(filename) def pbRgssExists?(filename)
filename = canonicalize(filename) filename = canonicalize(filename)
if safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a") if safeExists?("./Game.rgssad")
return pbGetFileChar(filename)!=nil return pbGetFileChar(filename)!=nil
else else
return safeExists?(filename) return safeExists?(filename)
@@ -193,7 +193,7 @@ end
# and matching mount points added through System.mount # and matching mount points added through System.mount
def pbRgssOpen(file,mode=nil) def pbRgssOpen(file,mode=nil)
#File.open("debug.txt","ab") { |fw| fw.write([file,mode,Time.now.to_f].inspect+"\r\n") } #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? if block_given?
File.open(file,mode) { |f| yield f } File.open(file,mode) { |f| yield f }
return nil return nil
@@ -216,7 +216,7 @@ end
# encrypted archives. # encrypted archives.
def pbGetFileChar(file) def pbGetFileChar(file)
file = canonicalize(file) file = canonicalize(file)
if !safeExists?("./Game.rgssad") && !safeExists?("./Game.rgss2a") if !safeExists?("./Game.rgssad")
return nil if !safeExists?(file) return nil if !safeExists?(file)
begin begin
File.open(file,"rb") { |f| return f.read(1) } # read one byte 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 # and matching mount points added through System.mount
def pbGetFileString(file) def pbGetFileString(file)
file = canonicalize(file) file = canonicalize(file)
if !(safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a")) if !safeExists?("./Game.rgssad")
return nil if !safeExists?(file) return nil if !safeExists?(file)
begin begin
File.open(file,"rb") { |f| return f.read } # read all data File.open(file,"rb") { |f| return f.read } # read all data

View File

@@ -96,7 +96,7 @@ def pbSetTextMessages
choices|=[] choices|=[]
items.concat(choices) items.concat(choices)
MessageTypes.setMapMessagesAsHash(0,items) MessageTypes.setMapMessagesAsHash(0,items)
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
mapnames=[] mapnames=[]
for id in mapinfos.keys for id in mapinfos.keys
mapnames[id]=mapinfos[id].name mapnames[id]=mapinfos[id].name

View File

@@ -343,7 +343,7 @@ end
#=============================================================================== #===============================================================================
def pbGetBasicMapNameFromId(id) def pbGetBasicMapNameFromId(id)
begin begin
map = load_data("Data/MapInfos.rxdata") map = pbLoadMapInfos
return "" if !map return "" if !map
return map[id].name return map[id].name
rescue rescue

View File

@@ -8,6 +8,8 @@ class PokemonTemp
attr_accessor :speciesShadowMovesets attr_accessor :speciesShadowMovesets
attr_accessor :moveToAnim attr_accessor :moveToAnim
attr_accessor :battleAnims attr_accessor :battleAnims
attr_accessor :mapInfos
attr_accessor :mapConnections
end end
def pbClearData def pbClearData
@@ -18,15 +20,14 @@ def pbClearData
$PokemonTemp.speciesShadowMovesets = nil $PokemonTemp.speciesShadowMovesets = nil
$PokemonTemp.moveToAnim = nil $PokemonTemp.moveToAnim = nil
$PokemonTemp.battleAnims = nil $PokemonTemp.battleAnims = nil
$PokemonTemp.mapInfos = nil
$PokemonTemp.mapConnections = nil
end end
MapFactoryHelper.clear MapFactoryHelper.clear
$PokemonEncounters.setup($game_map.map_id) if $game_map && $PokemonEncounters $PokemonEncounters.setup($game_map.map_id) if $game_map && $PokemonEncounters
if pbRgssExists?("Data/Tilesets.rxdata") if pbRgssExists?("Data/Tilesets.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata") $data_tilesets = load_data("Data/Tilesets.rxdata")
end end
if pbRgssExists?("Data/Tilesets.rvdata")
$data_tilesets = load_data("Data/Tilesets.rvdata")
end
end end
#=============================================================================== #===============================================================================
@@ -95,3 +96,25 @@ def pbLoadBattleAnimations
end end
return $PokemonTemp.battleAnims return $PokemonTemp.battleAnims
end 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

View File

@@ -405,7 +405,7 @@ Events.onMapChanging += proc { |_sender, e|
next if new_map_ID == 0 next if new_map_ID == 0
old_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) old_map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
next if !old_map_metadata || !old_map_metadata.weather 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 if $game_map.name == map_infos[new_map_ID].name
new_map_metadata = GameData::MapMetadata.try_get(new_map_ID) new_map_metadata = GameData::MapMetadata.try_get(new_map_ID)
next if new_map_metadata && new_map_metadata.weather 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 $PokemonGlobal.visitedMaps[$game_map.map_id] = true
next if old_map_ID == 0 || old_map_ID == $game_map.map_id next if old_map_ID == 0 || old_map_ID == $game_map.map_id
next if !new_map_metadata || !new_map_metadata.weather 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 if $game_map.name == map_infos[old_map_ID].name
old_map_metadata = GameData::MapMetadata.try_get(old_map_ID) old_map_metadata = GameData::MapMetadata.try_get(old_map_ID)
next if old_map_metadata && old_map_metadata.weather 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 Settings::NO_SIGNPOSTS[2 * i] == $game_map.map_id
break if nosignpost break if nosignpost
end end
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
oldmapname = mapinfos[$PokemonGlobal.mapTrail[1]].name oldmapname = mapinfos[$PokemonGlobal.mapTrail[1]].name
nosignpost = true if $game_map.name == oldmapname nosignpost = true if $game_map.name == oldmapname
end end

View File

@@ -96,7 +96,7 @@ end
Events.onMapChange += proc { |_sender,e| Events.onMapChange += proc { |_sender,e|
oldMapID = e[0] oldMapID = e[0]
# Get and compare map names # Get and compare map names
mapInfos = load_data("Data/MapInfos.rxdata") mapInfos = pbLoadMapInfos
next if mapInfos && oldMapID>0 && mapInfos[oldMapID] && next if mapInfos && oldMapID>0 && mapInfos[oldMapID] &&
mapInfos[oldMapID].name && $game_map.name==mapInfos[oldMapID].name mapInfos[oldMapID].name && $game_map.name==mapInfos[oldMapID].name
# Make roaming Pokémon roam # Make roaming Pokémon roam

View File

@@ -2,7 +2,7 @@
# exists, the real file is deleted to ensure that the file is loaded from the # exists, the real file is deleted to ensure that the file is loaded from the
# encrypted archive. # encrypted archive.
def pbSafeLoad(file) def pbSafeLoad(file)
if (safeExists?("./Game.rgssad") || safeExists?("./Game.rgss2a")) && safeExists?(file) if safeExists?("./Game.rgssad") && safeExists?(file)
File.delete(file) rescue nil File.delete(file) rescue nil
end end
return load_data(file) return load_data(file)

View File

@@ -422,7 +422,7 @@ class SpriteWindow_DebugRoamers < Window_DrawableCommand
# roaming # roaming
curmap = $PokemonGlobal.roamPosition[index] curmap = $PokemonGlobal.roamPosition[index]
if curmap if curmap
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
status = "[ROAMING][#{curmap}: #{mapinfos[curmap].name}]" status = "[ROAMING][#{curmap}: #{mapinfos[curmap].name}]"
else else
status = "[ROAMING][map not set]" status = "[ROAMING][map not set]"
@@ -771,7 +771,7 @@ end
def pbDebugFixInvalidTiles def pbDebugFixInvalidTiles
num_errors = 0 num_errors = 0
num_error_maps = 0 num_error_maps = 0
@tilesets = load_data("Data/Tilesets.rxdata") @tilesets = $data_tilesets
mapData = MapData.new mapData = MapData.new
t = Time.now.to_i t = Time.now.to_i
Graphics.update Graphics.update

View File

@@ -4,7 +4,7 @@
# Main editor method for editing wild encounters. Lists all defined encounter # Main editor method for editing wild encounters. Lists all defined encounter
# sets, and edits them. # sets, and edits them.
def pbEncountersEditor def pbEncountersEditor
map_infos = load_data("Data/MapInfos.rxdata") map_infos = pbLoadMapInfos
commands = [] commands = []
maps = [] maps = []
list = pbListWindow([]) list = pbListWindow([])
@@ -122,7 +122,7 @@ end
# Lists the map ID, version number and defined encounter types for the given # Lists the map ID, version number and defined encounter types for the given
# encounter data (a GameData::Encounter instance), and edits them. # encounter data (a GameData::Encounter instance), and edits them.
def pbEncounterMapVersionEditor(enc_data) def pbEncounterMapVersionEditor(enc_data)
map_infos = load_data("Data/MapInfos.rxdata") map_infos = pbLoadMapInfos
commands = [] commands = []
enc_types = [] enc_types = []
list = pbListWindow([]) list = pbListWindow([])
@@ -720,7 +720,7 @@ def pbMetadataScreen(map_id = 0)
end end
def pbEditMetadata(map_id = 0) def pbEditMetadata(map_id = 0)
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
data = [] data = []
if map_id == 0 # Global metadata if map_id == 0 # Global metadata
map_name = _INTL("Global Metadata") map_name = _INTL("Global Metadata")

View File

@@ -59,7 +59,7 @@ def pbAllocateAnimation(animations,name)
end end
def pbMapTree def pbMapTree
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
maplevels = [] maplevels = []
retarray = [] retarray = []
for i in mapinfos.keys for i in mapinfos.keys

View File

@@ -285,6 +285,7 @@ class MapScreenScene
def serializeConnectionData def serializeConnectionData
conndata=generateConnectionData() conndata=generateConnectionData()
save_data(conndata, "Data/map_connections.dat") save_data(conndata, "Data/map_connections.dat")
$PokemonTemp.mapConnections = nil
Compiler.write_connections Compiler.write_connections
@mapconns=conndata @mapconns=conndata
end end
@@ -330,7 +331,7 @@ class MapScreenScene
@sprites["title"] = Window_UnformattedTextPokemon.newWithSize(_INTL("F: Help"), @sprites["title"] = Window_UnformattedTextPokemon.newWithSize(_INTL("F: Help"),
0, 600 - 64, 800, 64, @viewport) 0, 600 - 64, 800, 64, @viewport)
@sprites["title"].z = 2 @sprites["title"].z = 2
@mapinfos=load_data("Data/MapInfos.rxdata") @mapinfos=pbLoadMapInfos
conns=MapFactoryHelper.getMapConnections conns=MapFactoryHelper.getMapConnections
@mapconns=[] @mapconns=[]
for c in conns for c in conns

View File

@@ -69,12 +69,10 @@ module Compiler
record.push(csvInt!(thisline,lineno)) record.push(csvInt!(thisline,lineno))
record.push(csvEnumFieldOrInt!(thisline,hashenum,"",sprintf("(line %d)",lineno))) record.push(csvEnumFieldOrInt!(thisline,hashenum,"",sprintf("(line %d)",lineno)))
record.push(csvInt!(thisline,lineno)) record.push(csvInt!(thisline,lineno))
if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[0])) && if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[0]))
!pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[0]))
print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[0],FileLineData.linereport) print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[0],FileLineData.linereport)
end end
if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[3])) && if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[3]))
!pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[3]))
print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[3],FileLineData.linereport) print _INTL("Warning: Map {1}, as mentioned in the map connection data, was not found.\r\n{2}",record[3],FileLineData.linereport)
end end
case record[1] case record[1]
@@ -1530,6 +1528,7 @@ module Compiler
rescue rescue
pbanims = PBAnimations.new pbanims = PBAnimations.new
end end
changed = false
move2anim = [[],[]] move2anim = [[],[]]
=begin =begin
anims = load_data("Data/Animations.rxdata") anims = load_data("Data/Animations.rxdata")
@@ -1550,16 +1549,20 @@ module Compiler
if pbanims[i].name[/^OppMove\:\s*(.*)$/] if pbanims[i].name[/^OppMove\:\s*(.*)$/]
if GameData::Move.exists?($~[1]) if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id_number moveid = GameData::Move.get($~[1]).id_number
changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i
move2anim[1][moveid] = i move2anim[1][moveid] = i
end end
elsif pbanims[i].name[/^Move\:\s*(.*)$/] elsif pbanims[i].name[/^Move\:\s*(.*)$/]
if GameData::Move.exists?($~[1]) if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id_number moveid = GameData::Move.get($~[1]).id_number
changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i
move2anim[0][moveid] = i move2anim[0][moveid] = i
end end
end end
end end
save_data(move2anim,"Data/move2anim.dat") if changed
save_data(pbanims,"Data/PkmnAnimations.rxdata") save_data(move2anim,"Data/move2anim.dat")
save_data(pbanims,"Data/PkmnAnimations.rxdata")
end
end end
end end

View File

@@ -69,9 +69,9 @@ module Compiler
end end
def write_connections def write_connections
conndata = load_data("Data/map_connections.dat") rescue nil conndata = pbLoadMapConnections
return if !conndata return if !conndata
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
File.open("PBS/connections.txt","wb") { |f| File.open("PBS/connections.txt","wb") { |f|
add_PBS_header_to_file(f) add_PBS_header_to_file(f)
f.write("\#-------------------------------\r\n") f.write("\#-------------------------------\r\n")
@@ -518,7 +518,7 @@ module Compiler
# Save wild encounter data to PBS file # Save wild encounter data to PBS file
#============================================================================= #=============================================================================
def write_encounters def write_encounters
map_infos = load_data("Data/MapInfos.rxdata") map_infos = pbLoadMapInfos
File.open("PBS/encounters.txt", "wb") { |f| File.open("PBS/encounters.txt", "wb") { |f|
add_PBS_header_to_file(f) add_PBS_header_to_file(f)
GameData::Encounter.each do |encounter_data| GameData::Encounter.each do |encounter_data|
@@ -735,7 +735,7 @@ module Compiler
f.write("\r\n") f.write("\r\n")
end end
# Write map metadata # Write map metadata
map_infos = load_data("Data/MapInfos.rxdata") map_infos = pbLoadMapInfos
schema = GameData::MapMetadata::SCHEMA schema = GameData::MapMetadata::SCHEMA
keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] } keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] }
GameData::MapMetadata.each do |map_data| GameData::MapMetadata.each do |map_data|

View File

@@ -14,7 +14,7 @@ module Compiler
mapfiles[$1.to_i(10)] = true if map[/map(\d+)\.rxdata/i] mapfiles[$1.to_i(10)] = true if map[/map(\d+)\.rxdata/i]
end end
} }
mapinfos = load_data("Data/MapInfos.rxdata") mapinfos = pbLoadMapInfos
maxOrder = 0 maxOrder = 0
# Exclude maps found in mapinfos # Exclude maps found in mapinfos
for id in mapinfos.keys for id in mapinfos.keys
@@ -38,6 +38,7 @@ module Compiler
end end
if imported if imported
save_data(mapinfos,"Data/MapInfos.rxdata") save_data(mapinfos,"Data/MapInfos.rxdata")
$PokemonTemp.mapInfos = nil
pbMessage(_INTL("{1} new map(s) copied to the Data folder were successfully imported.",count)) pbMessage(_INTL("{1} new map(s) copied to the Data folder were successfully imported.",count))
end end
return imported return imported
@@ -239,7 +240,7 @@ module Compiler
attr_reader :mapinfos attr_reader :mapinfos
def initialize def initialize
@mapinfos = load_data("Data/MapInfos.rxdata") @mapinfos = pbLoadMapInfos
@system = load_data("Data/System.rxdata") @system = load_data("Data/System.rxdata")
@tilesets = load_data("Data/Tilesets.rxdata") @tilesets = load_data("Data/Tilesets.rxdata")
@mapxy = [] @mapxy = []