Module: Cache
- Defined in:
- lib/rgss3_default_scripts/Cache.rb
Overview
** Cache
This module loads graphics, creates bitmap objects, and retains them.
To speed up load times and conserve memory, this module holds the created bitmap object in the internal hash, allowing the program to return preexisting objects when the same bitmap is requested again.
Class Method Summary collapse
-
.animation(filename, hue) ⇒ Object
————————————————————————– * Get Animation Graphic ————————————————————————–.
-
.battleback1(filename) ⇒ Object
————————————————————————– * Get Battle Background (Floor) Graphic ————————————————————————–.
-
.battleback2(filename) ⇒ Object
————————————————————————– * Get Battle Background (Wall) Graphic ————————————————————————–.
-
.battler(filename, hue) ⇒ Object
————————————————————————– * Get Battle Graphic ————————————————————————–.
-
.character(filename) ⇒ Object
————————————————————————– * Get Character Graphic ————————————————————————–.
-
.clear ⇒ Object
————————————————————————– * Clear Cache ————————————————————————–.
-
.empty_bitmap ⇒ Object
————————————————————————– * Create Empty Bitmap ————————————————————————–.
-
.face(filename) ⇒ Object
————————————————————————– * Get Face Graphic ————————————————————————–.
-
.hue_changed_bitmap(path, hue) ⇒ Object
————————————————————————– * Create/Get Hue-Changed Bitmap ————————————————————————–.
-
.include?(key) ⇒ Boolean
————————————————————————– * Check Cache Existence ————————————————————————–.
-
.load_bitmap(folder_name, filename, hue = 0) ⇒ Object
————————————————————————– * Load Bitmap ————————————————————————–.
-
.normal_bitmap(path) ⇒ Object
————————————————————————– * Create/Get Normal Bitmap ————————————————————————–.
-
.parallax(filename) ⇒ Object
————————————————————————– * Get Parallax Background Graphic ————————————————————————–.
-
.picture(filename) ⇒ Object
————————————————————————– * Get Picture Graphic ————————————————————————–.
-
.system(filename) ⇒ Object
————————————————————————– * Get System Graphic ————————————————————————–.
-
.tileset(filename) ⇒ Object
————————————————————————– * Get Tileset Graphic ————————————————————————–.
-
.title1(filename) ⇒ Object
————————————————————————– * Get Title (Background) Graphic ————————————————————————–.
-
.title2(filename) ⇒ Object
————————————————————————– * Get Title (Frame) Graphic ————————————————————————–.
Class Method Details
.animation(filename, hue) ⇒ Object
-
Get Animation Graphic
14 15 16 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 14 def self.animation(filename, hue) load_bitmap("Graphics/Animations/", filename, hue) end |
.battleback1(filename) ⇒ Object
-
Get Battle Background (Floor) Graphic
20 21 22 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 20 def self.battleback1(filename) load_bitmap("Graphics/Battlebacks1/", filename) end |
.battleback2(filename) ⇒ Object
-
Get Battle Background (Wall) Graphic
26 27 28 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 26 def self.battleback2(filename) load_bitmap("Graphics/Battlebacks2/", filename) end |
.battler(filename, hue) ⇒ Object
-
Get Battle Graphic
32 33 34 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 32 def self.battler(filename, hue) load_bitmap("Graphics/Battlers/", filename, hue) end |
.character(filename) ⇒ Object
-
Get Character Graphic
38 39 40 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 38 def self.character(filename) load_bitmap("Graphics/Characters/", filename) end |
.clear ⇒ Object
-
Clear Cache
129 130 131 132 133 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 129 def self.clear @cache ||= {} @cache.clear GC.start end |
.empty_bitmap ⇒ Object
-
Create Empty Bitmap
99 100 101 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 99 def self.empty_bitmap Bitmap.new(32, 32) end |
.face(filename) ⇒ Object
-
Get Face Graphic
44 45 46 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 44 def self.face(filename) load_bitmap("Graphics/Faces/", filename) end |
.hue_changed_bitmap(path, hue) ⇒ Object
-
Create/Get Hue-Changed Bitmap
112 113 114 115 116 117 118 119 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 112 def self.hue_changed_bitmap(path, hue) key = [path, hue] unless include?(key) @cache[key] = normal_bitmap(path).clone @cache[key].hue_change(hue) end @cache[key] end |
.include?(key) ⇒ Boolean
-
Check Cache Existence
123 124 125 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 123 def self.include?(key) @cache[key] && !@cache[key].disposed? end |
.load_bitmap(folder_name, filename, hue = 0) ⇒ Object
-
Load Bitmap
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 86 def self.load_bitmap(folder_name, filename, hue = 0) @cache ||= {} if filename.empty? empty_bitmap elsif hue == 0 normal_bitmap(folder_name + filename) else hue_changed_bitmap(folder_name + filename, hue) end end |
.normal_bitmap(path) ⇒ Object
-
Create/Get Normal Bitmap
105 106 107 108 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 105 def self.normal_bitmap(path) @cache[path] = Bitmap.new(path) unless include?(path) @cache[path] end |
.parallax(filename) ⇒ Object
-
Get Parallax Background Graphic
50 51 52 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 50 def self.parallax(filename) load_bitmap("Graphics/Parallaxes/", filename) end |
.picture(filename) ⇒ Object
-
Get Picture Graphic
56 57 58 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 56 def self.picture(filename) load_bitmap("Graphics/Pictures/", filename) end |
.system(filename) ⇒ Object
-
Get System Graphic
62 63 64 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 62 def self.system(filename) load_bitmap("Graphics/System/", filename) end |
.tileset(filename) ⇒ Object
-
Get Tileset Graphic
68 69 70 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 68 def self.tileset(filename) load_bitmap("Graphics/Tilesets/", filename) end |
.title1(filename) ⇒ Object
-
Get Title (Background) Graphic
74 75 76 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 74 def self.title1(filename) load_bitmap("Graphics/Titles1/", filename) end |
.title2(filename) ⇒ Object
-
Get Title (Frame) Graphic
80 81 82 |
# File 'lib/rgss3_default_scripts/Cache.rb', line 80 def self.title2(filename) load_bitmap("Graphics/Titles2/", filename) end |