From dcd0fe8b2147cfdee127e2513b6737b2a7be9f6f Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 11 Apr 2021 16:19:58 +0100 Subject: [PATCH] Rewrote perma-caching code, added another controls help page --- .../005_Sprites/003_Sprite_Character.rb | 2 +- .../005_Sprites/005_Sprite_SurfBase.rb | 4 +-- .../001_BitmapCache.rb | 11 ++++---- .../004_SpriteWindow.rb | 6 ++--- .../005_SpriteWindow_text.rb | 8 +++--- .../017_UI/001_Animations/002_UI_Controls.rb | 25 +++++++++++-------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Data/Scripts/005_Sprites/003_Sprite_Character.rb b/Data/Scripts/005_Sprites/003_Sprite_Character.rb index 089a8f60f..a7d1da2eb 100644 --- a/Data/Scripts/005_Sprites/003_Sprite_Character.rb +++ b/Data/Scripts/005_Sprites/003_Sprite_Character.rb @@ -122,7 +122,7 @@ class Sprite_Character < RPG::Sprite @charbitmap.dispose if @charbitmap @charbitmap = AnimatedBitmap.new( "Graphics/Characters/"+@character_name,@character_hue) - RPG::Cache.addRef("Graphics/Characters/", @character_name, @character_hue) if @character == $game_player + RPG::Cache.retain("Graphics/Characters/", @character_name, @character_hue) if @character == $game_player @charbitmapAnimated = true @bushbitmap.dispose if @bushbitmap @bushbitmap = nil diff --git a/Data/Scripts/005_Sprites/005_Sprite_SurfBase.rb b/Data/Scripts/005_Sprites/005_Sprite_SurfBase.rb index 10c59c368..d4fcbb749 100644 --- a/Data/Scripts/005_Sprites/005_Sprite_SurfBase.rb +++ b/Data/Scripts/005_Sprites/005_Sprite_SurfBase.rb @@ -10,8 +10,8 @@ class Sprite_SurfBase @disposed = false @surfbitmap = AnimatedBitmap.new("Graphics/Characters/base_surf") @divebitmap = AnimatedBitmap.new("Graphics/Characters/base_dive") - RPG::Cache.addRef("Graphics/Characters/base_surf") - RPG::Cache.addRef("Graphics/Characters/base_dive") + RPG::Cache.retain("Graphics/Characters/base_surf") + RPG::Cache.retain("Graphics/Characters/base_dive") @cws = @surfbitmap.width/4 @chs = @surfbitmap.height/4 @cwd = @divebitmap.width/4 diff --git a/Data/Scripts/007_Objects and windows/001_BitmapCache.rb b/Data/Scripts/007_Objects and windows/001_BitmapCache.rb index f42040fca..2ae4404bb 100644 --- a/Data/Scripts/007_Objects and windows/001_BitmapCache.rb +++ b/Data/Scripts/007_Objects and windows/001_BitmapCache.rb @@ -86,30 +86,31 @@ module RPG self.load_bitmap("Graphics/Transitions/", filename) end - def self.addRef(folder_name, filename = "", hue = 0) + def self.retain(folder_name, filename = "", hue = 0) path = folder_name + filename ret = fromCache(path) if hue > 0 key = [path, hue] ret2 = fromCache(key) if ret2 - ret2.addRef + ret2.never_dispose = true return end end - ret.addRef if ret + ret.never_dispose = true if ret end end end class BitmapWrapper < Bitmap - attr_reader :refcount + attr_reader :refcount + attr_accessor :never_dispose def dispose return if self.disposed? @refcount -= 1 - super if @refcount <= 0 + super if @refcount <= 0 && !never_dispose end def initialize(*arg) diff --git a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb index 549cd0683..3a4ac911d 100644 --- a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb +++ b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb @@ -837,7 +837,7 @@ class SpriteWindow_Base < SpriteWindow @curframe=MessageConfig.pbGetSystemFrame() @curfont=MessageConfig.pbGetSystemFontName() @sysframe=AnimatedBitmap.new(@curframe) - RPG::Cache.addRef(@curframe) if @curframe && !@curframe.empty? + RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty? @customskin=nil __setWindowskin(@sysframe.bitmap) __resolveSystemFrame() @@ -870,7 +870,7 @@ class SpriteWindow_Base < SpriteWindow resolvedName=pbResolveBitmap(skin) return if !resolvedName || resolvedName=="" @customskin=AnimatedBitmap.new(resolvedName) - RPG::Cache.addRef(resolvedName) + RPG::Cache.retain(resolvedName) __setWindowskin(@customskin.bitmap) if self.skinformat==1 skinbase=resolvedName.sub(/\.[^\.\/\\]+$/,"") @@ -905,7 +905,7 @@ class SpriteWindow_Base < SpriteWindow if @sysframe && !@customskin @sysframe.dispose if @sysframe @sysframe=AnimatedBitmap.new(@curframe) - RPG::Cache.addRef(@curframe) if @curframe && !@curframe.empty? + RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty? @resolvedFrame=nil __setWindowskin(@sysframe.bitmap) __resolveSystemFrame() diff --git a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb index cb0fc12cb..5b4bd4ee1 100644 --- a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb +++ b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb @@ -964,8 +964,8 @@ module UpDownArrowMixin def initUpDownArrow @uparrow = AnimatedSprite.create("Graphics/Pictures/uparrow",8,2,self.viewport) @downarrow = AnimatedSprite.create("Graphics/Pictures/downarrow",8,2,self.viewport) - RPG::Cache.addRef("Graphics/Pictures/uparrow") - RPG::Cache.addRef("Graphics/Pictures/downarrow") + RPG::Cache.retain("Graphics/Pictures/uparrow") + RPG::Cache.retain("Graphics/Pictures/downarrow") @uparrow.z = 99998 @downarrow.z = 99998 @uparrow.visible = false @@ -1048,10 +1048,10 @@ class Window_DrawableCommand < SpriteWindow_SelectableEx self.viewport = viewport if viewport if isDarkWindowskin(self.windowskin) @selarrow = AnimatedBitmap.new("Graphics/Pictures/selarrow_white") - RPG::Cache.addRef("Graphics/Pictures/selarrow_white") + RPG::Cache.retain("Graphics/Pictures/selarrow_white") else @selarrow = AnimatedBitmap.new("Graphics/Pictures/selarrow") - RPG::Cache.addRef("Graphics/Pictures/selarrow") + RPG::Cache.retain("Graphics/Pictures/selarrow") end @index = 0 colors = getDefaultTextColors(self.windowskin) diff --git a/Data/Scripts/017_UI/001_Animations/002_UI_Controls.rb b/Data/Scripts/017_UI/001_Animations/002_UI_Controls.rb index 167328d50..386043094 100644 --- a/Data/Scripts/017_UI/001_Animations/002_UI_Controls.rb +++ b/Data/Scripts/017_UI/001_Animations/002_UI_Controls.rb @@ -16,18 +16,23 @@ class ButtonEventScene < EventScene @keys = [] @key_screens = [] - addImageForScreen(1, 16, 158, "Graphics/Pictures/help_arrows") - addLabelForScreen(1, 134, 100, 352, _INTL("Use the Arrow keys to move the main character.\r\n\r\nYou can also use the Arrow keys to select entries and navigate menus.")) + addImageForScreen(1, 44, 122, "Graphics/Pictures/help_f1") + addImageForScreen(1, 44, 252, "Graphics/Pictures/help_f8") + addLabelForScreen(1, 134, 84, 352, _INTL("Opens the Key Bindings window, where you can choose which keyboard keys to use for each control.")) + addLabelForScreen(1, 134, 244, 352, _INTL("Take a screenshot. It is put in the same folder as the save file.")) - addImageForScreen(2, 16, 106, "Graphics/Pictures/help_usekey") - addImageForScreen(2, 16, 236, "Graphics/Pictures/help_backkey") - addLabelForScreen(2, 134, 84, 352, _INTL("Used to confirm a choice, interact with people and things, and move through text. (Default: C)")) - addLabelForScreen(2, 134, 212, 352, _INTL("Used to exit, cancel a choice, and cancel a mode. Also used to open the Pause Menu. (Default: X)")) + addImageForScreen(2, 16, 158, "Graphics/Pictures/help_arrows") + addLabelForScreen(2, 134, 100, 352, _INTL("Use the Arrow keys to move the main character.\r\n\r\nYou can also use the Arrow keys to select entries and navigate menus.")) - addImageForScreen(3, 16, 90, "Graphics/Pictures/help_actionkey") - addImageForScreen(3, 16, 252, "Graphics/Pictures/help_specialkey") - addLabelForScreen(3, 134, 52, 352, _INTL("Has various functions depending on context. While moving around, hold to move at a different speed. (Default: Z)")) - addLabelForScreen(3, 134, 212, 352, _INTL("Press to open the Ready Menu, where registered items and available field moves can be used. (Default: D)")) + addImageForScreen(3, 16, 106, "Graphics/Pictures/help_usekey") + addImageForScreen(3, 16, 236, "Graphics/Pictures/help_backkey") + addLabelForScreen(3, 134, 84, 352, _INTL("Used to confirm a choice, interact with people and things, and move through text. (Default: C)")) + addLabelForScreen(3, 134, 212, 352, _INTL("Used to exit, cancel a choice, and cancel a mode. Also used to open the Pause Menu. (Default: X)")) + + addImageForScreen(4, 16, 90, "Graphics/Pictures/help_actionkey") + addImageForScreen(4, 16, 252, "Graphics/Pictures/help_specialkey") + addLabelForScreen(4, 134, 52, 352, _INTL("Has various functions depending on context. While moving around, hold to move at a different speed. (Default: Z)")) + addLabelForScreen(4, 134, 212, 352, _INTL("Press to open the Ready Menu, where registered items and available field moves can be used. (Default: D)")) set_up_screen(@current_screen) Graphics.transition(20)