From 46ed10a31dbde11829748d71144fa9112da98bac Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Thu, 25 Feb 2021 22:57:39 +0000 Subject: [PATCH] Tweaks relating to previous commit --- Data/Scripts/001_Technical/007_Errors.rb | 2 +- .../005_Map renderer/001_Tilemap_XP.rb | 8 +- .../005_Map renderer/005_TileDrawingHelper.rb | 12 +- .../001_BitmapCache.rb | 125 +----------------- .../Scripts/013_Overworld/002_PField_Field.rb | 6 +- .../017_UI/004_PScreen_PokedexEntry.rb | 4 +- Data/Scripts/017_UI/009_PScreen_RegionMap.rb | 6 +- .../001_AnimEditor_SceneElements.rb | 12 +- .../005_AnimEditor_Functions.rb | 2 +- 9 files changed, 31 insertions(+), 146 deletions(-) diff --git a/Data/Scripts/001_Technical/007_Errors.rb b/Data/Scripts/001_Technical/007_Errors.rb index 37fa974a5..f482aea2f 100644 --- a/Data/Scripts/001_Technical/007_Errors.rb +++ b/Data/Scripts/001_Technical/007_Errors.rb @@ -50,7 +50,7 @@ def pbPrintException(e) print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl after closing this message to copy it to the clipboard.") # Give a ~500ms coyote time to start holding Control - (0.5 / (1.0 / Graphics.frame_rate)).ceil.times{ + (Graphics.frame_rate / 2).ceil.times{ Graphics.update Input.update if Input.press?(Input::CTRL) diff --git a/Data/Scripts/005_Map renderer/001_Tilemap_XP.rb b/Data/Scripts/005_Map renderer/001_Tilemap_XP.rb index 1c313be0b..d536ddda6 100644 --- a/Data/Scripts/005_Map renderer/001_Tilemap_XP.rb +++ b/Data/Scripts/005_Map renderer/001_Tilemap_XP.rb @@ -20,7 +20,7 @@ #======================================================================= module TileWrap - + TILESET_WIDTH = 0x100 # Looks useless, but covers weird numbers given to mkxp.json or a funky driver MAX_TEX_SIZE = (Bitmap.max_size / 1024) * 1024 @@ -37,13 +37,13 @@ module TileWrap height = originalbmp.height if width == TILESET_WIDTH && originalbmp.mega? columns = (height / MAX_TEX_SIZE.to_f).ceil - + if columns * TILESET_WIDTH > MAX_TEX_SIZE raise "Tilemap is too long!\n\nSIZE: #{originalbmp.height}px\nHARDWARE LIMIT: #{MAX_TEX_SIZE}px\nBOOSTED LIMIT: #{MAX_TEX_SIZE_BOOSTED}px" end bmp = Bitmap.new(TILESET_WIDTH*columns, MAX_TEX_SIZE) remainder = height % MAX_TEX_SIZE - + columns.times{|col| srcrect = Rect.new(0, col * MAX_TEX_SIZE, width, (col + 1 == columns) ? remainder : MAX_TEX_SIZE) bmp.blt(col*TILESET_WIDTH, 0, originalbmp, srcrect) @@ -464,7 +464,7 @@ class CustomTilemap else sprite.bitmap = @tileset if sprite.bitmap!=@tileset rect = Rect.new(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight, - @tileSrcWidth,@tileSrcHeight) + @tileSrcWidth,@tileSrcHeight) rect = TileWrap::getWrappedRect(rect) if @shouldWrap sprite.src_rect = rect end diff --git a/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb b/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb index 51d399ee6..6e8995eda 100644 --- a/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb +++ b/Data/Scripts/005_Map renderer/005_TileDrawingHelper.rb @@ -66,8 +66,15 @@ class TileDrawingHelper return self.new(bmtileset,bmautotiles) end - def initialize(tileset,autotiles) - @tileset = tileset + def initialize(tileset, autotiles) + if tileset.mega? + @tileset = TileWrap::wrapTileset(tileset) + tileset.dispose + @shouldWrap = true + else + @tileset = tileset + @shouldWrap = false + end @autotiles = autotiles end @@ -107,6 +114,7 @@ class TileDrawingHelper def bltSmallRegularTile(bitmap,x,y,cxTile,cyTile,id) return if id < 384 || !@tileset || @tileset.disposed? rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32) + rect = TileWrap::getWrappedRect(rect) if @shouldWrap bitmap.stretch_blt(Rect.new(x, y, cxTile, cyTile), @tileset, rect) end diff --git a/Data/Scripts/009_Objects and windows/001_BitmapCache.rb b/Data/Scripts/009_Objects and windows/001_BitmapCache.rb index 60eb24713..a088f7d4e 100644 --- a/Data/Scripts/009_Objects and windows/001_BitmapCache.rb +++ b/Data/Scripts/009_Objects and windows/001_BitmapCache.rb @@ -38,113 +38,6 @@ end -##################################################################### -# TODO: Delete this class in Ruby 2+. -class WeakRef - @@id_map = {} - @@id_rev_map = {} - @@final = lambda do |id| - rids = @@id_map[id] - if rids - rids.each { |rid| @@id_rev_map.delete(rid) } - @@id_map.delete(id) - end - rid = @@id_rev_map[id] - if rid - @@id_rev_map.delete(id) - @@id_map[rid].delete(id) - @@id_map.delete(rid) if @@id_map[rid].empty? - end - end - - # Create a new WeakRef from +orig+. - def initialize(orig) - __setobj__(orig) - end - - def __getobj__ - unless @@id_rev_map[self.__id__] == @__id - return nil - end - begin - ObjectSpace._id2ref(@__id) - rescue RangeError - return nil - end - end - - def __setobj__(obj) - @__id = obj.__id__ - unless @@id_rev_map.key?(self) - ObjectSpace.define_finalizer obj, @@final - ObjectSpace.define_finalizer self, @@final - end - @@id_map[@__id] = [] unless @@id_map[@__id] - @@id_map[@__id].push self.__id__ - @@id_rev_map[self.__id__] = @__id - end - - # Returns true if the referenced object still exists, and false if it has - # been garbage collected. - def weakref_alive? - @@id_rev_map[self.__id__] == @__id - end -end - - - -# TODO: Delete this class in Ruby 2+. -class WeakHashtable - include Enumerable - - def initialize - @hash = {} - end - - def clear - @hash.clear - end - - def delete(value) - @hash.delete(value) - end - - def include?(value) - @hash.include?(value) - end - - def each - @hash.each { |i| yield i } - end - - def keys - @hash.keys - end - - def values - @hash.values - end - - def [](key) - o = @hash[key] - return o if !o - if o.weakref_alive? - o = o.__getobj__ - else - @hash.delete(key) - o = nil - end - return o - end - - def []=(key, o) - o = WeakRef.new(o) if o != nil - @hash[key] = o - end -end - - - module RPG module Cache def self.load_bitmap(folder_name, filename, hue = 0) @@ -247,9 +140,7 @@ end module BitmapCache - # TODO: Replace this with the commented line in Ruby 2+. - @cache = WeakHashtable.new -# @cache = ObjectSpace::WeakMap.new + @cache = ObjectSpace::WeakMap.new def self.fromCache(i) return nil if !@cache.include?(i) @@ -279,17 +170,9 @@ module BitmapCache def self.load_bitmap(path, hue = 0, failsafe = false) cached = true - path = canonicalize(path) + path = -canonicalize(path) # Creates a frozen string from the path, to ensure identical paths are treated as identical objPath = fromCache(path) if !objPath - # TODO: Delete this in Ruby 2+. - @cleancounter = ((@cleancounter || 0) + 1) % 10 - if @cleancounter == 0 - for i in @cache.keys - @cache.delete(i) if !fromCache(i) - end - end - # TODO: Up to here. begin bm = BitmapWrapper.new(path) rescue Hangup @@ -402,9 +285,7 @@ module BitmapCache end def self.clear - # TODO: Replace this with the commented line in Ruby 2+. - @cache.clear -# @cache = ObjectSpace::WeakMap.new + @cache = ObjectSpace::WeakMap.new GC.start end end diff --git a/Data/Scripts/013_Overworld/002_PField_Field.rb b/Data/Scripts/013_Overworld/002_PField_Field.rb index e7ddceb58..6efdb84ec 100644 --- a/Data/Scripts/013_Overworld/002_PField_Field.rb +++ b/Data/Scripts/013_Overworld/002_PField_Field.rb @@ -373,12 +373,12 @@ def pbBattleOnStepTaken(repel_active) return if !$PokemonEncounters.encounter_possible_here? encounterType = $PokemonEncounters.encounter_type return if encounterType < 0 - return if !$PokemonEncounter.step_triggers_encounter?(encounterType) + return if !$PokemonEncounters.step_triggers_encounter?(encounterType) $PokemonTemp.encounterType = encounterType encounter = $PokemonEncounters.choose_wild_pokemon(encounterType) encounter = EncounterModifier.trigger(encounter) - if $PokemonEncounter.allow_encounter?(encounter, repel_active) - if $PokemonEncounter.have_double_wild_battle? + if $PokemonEncounters.allow_encounter?(encounter, repel_active) + if $PokemonEncounters.have_double_wild_battle? encounter2 = $PokemonEncounters.choose_wild_pokemon(encounterType) encounter2 = EncounterModifier.trigger(encounter2) pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1]) diff --git a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb index 974347c80..690f9495b 100644 --- a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb +++ b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb @@ -229,7 +229,7 @@ class PokemonPokedexInfo_Scene # Write the height and weight height = species_data.height weight = species_data.weight - if pbGetCountry == 0xF4 # If the user is in the United States + if System.user_language[3..4] == "US" # If the user is in the United States inches = (height / 0.254).round pounds = (weight / 0.45359).round textpos.push([_ISPRINTF("{1:d}'{2:02d}\"", inches / 12, inches % 12), 460, 158, 1, base, shadow]) @@ -263,7 +263,7 @@ class PokemonPokedexInfo_Scene # Write the category textpos.push([_INTL("????? Pokémon"), 246, 74, 0, base, shadow]) # Write the height and weight - if pbGetCountry == 0xF4 # If the user is in the United States + if System.user_language[3..4] == "US" # If the user is in the United States textpos.push([_INTL("???'??\""), 460, 158, 1, base, shadow]) textpos.push([_INTL("????.? lbs."), 494, 190, 1, base, shadow]) else diff --git a/Data/Scripts/017_UI/009_PScreen_RegionMap.rb b/Data/Scripts/017_UI/009_PScreen_RegionMap.rb index ba2dcb1a8..cf0107ae0 100644 --- a/Data/Scripts/017_UI/009_PScreen_RegionMap.rb +++ b/Data/Scripts/017_UI/009_PScreen_RegionMap.rb @@ -171,11 +171,7 @@ class PokemonRegionMap_Scene # TODO: Why is this PBS file writer here? def pbSaveMapData File.open("PBS/townmap.txt","wb") { |f| - f.write(0xEF.chr) - f.write(0xBB.chr) - f.write(0xBF.chr) - f.write("\# "+_INTL("See the documentation on the wiki to learn how to edit this file.")) - f.write("\r\n") + Compiler.add_PBS_header_to_file(f) for i in 0...@mapdata.length map = @mapdata[i] next if !map diff --git a/Data/Scripts/021_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb b/Data/Scripts/021_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb index ffdf00723..3fe78ac40 100644 --- a/Data/Scripts/021_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb +++ b/Data/Scripts/021_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb @@ -851,33 +851,33 @@ class AnimationCanvas < Sprite @dirty[@currentcel]=true return end - if Input.triggerex?(0x50) || Input.repeatex?(0x50) # "P" for properties + if Input.triggerex?(:P) || Input.repeatex?(:P) # Properties pbCellProperties(self) @dirty[@currentcel]=true return end - if Input.triggerex?(0x4C) || Input.repeatex?(0x4C) # "L" for lock + if Input.triggerex?(:L) || Input.repeatex?(:L) # Lock cel[AnimFrame::LOCKED]=(cel[AnimFrame::LOCKED]==0) ? 1 : 0 @dirty[@currentcel]=true end - if Input.triggerex?(0x52) || Input.repeatex?(0x52) # "R" for rotate right + if Input.triggerex?(:R) || Input.repeatex?(:R) # Rotate right cel[AnimFrame::ANGLE]+=10 cel[AnimFrame::ANGLE]%=360 @dirty[@currentcel]=true end - if Input.triggerex?(0x45) || Input.repeatex?(0x45) # "E" for rotate left + if Input.triggerex?(:E) || Input.repeatex?(:E) # Rotate left cel[AnimFrame::ANGLE]-=10 cel[AnimFrame::ANGLE]%=360 @dirty[@currentcel]=true end - if Input.triggerex?(0x6B) || Input.repeatex?(0x6B) # "+" for zoom in + if Input.triggerex?(:KP_PLUS) || Input.repeatex?(:KP_PLUS) # Zoom in cel[AnimFrame::ZOOMX]+=10 cel[AnimFrame::ZOOMX]=1000 if cel[AnimFrame::ZOOMX]>1000 cel[AnimFrame::ZOOMY]+=10 cel[AnimFrame::ZOOMY]=1000 if cel[AnimFrame::ZOOMY]>1000 @dirty[@currentcel]=true end - if Input.triggerex?(0x6D) || Input.repeatex?(0x6D) # "-" for zoom in + if Input.triggerex?(:KP_MINUS) || Input.repeatex?(:KP_MINUS) # Zoom out cel[AnimFrame::ZOOMX]-=10 cel[AnimFrame::ZOOMX]=10 if cel[AnimFrame::ZOOMX]<10 cel[AnimFrame::ZOOMY]-=10 diff --git a/Data/Scripts/021_Debug/002_Animation editor/005_AnimEditor_Functions.rb b/Data/Scripts/021_Debug/002_Animation editor/005_AnimEditor_Functions.rb index 83dc04e8f..d2c644c5a 100644 --- a/Data/Scripts/021_Debug/002_Animation editor/005_AnimEditor_Functions.rb +++ b/Data/Scripts/021_Debug/002_Animation editor/005_AnimEditor_Functions.rb @@ -1054,7 +1054,7 @@ def animationEditorMain(animation) sliderwin.invalidate end next - elsif Input.triggerex?(0x51) # Q + elsif Input.triggerex?(:Q) if canvas.currentCel pbDefinePath(canvas) sliderwin.invalidate