Module: Cache

Defined in:
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)

Class Method Details

+ (Object) animation(filename, hue)


  • Get Animation Graphic




14
15
16
# File 'Cache.rb', line 14

def self.animation(filename, hue)
  load_bitmap("Graphics/Animations/", filename, hue)
end

+ (Object) battleback1(filename)


  • Get Battle Background (Floor) Graphic




20
21
22
# File 'Cache.rb', line 20

def self.battleback1(filename)
  load_bitmap("Graphics/Battlebacks1/", filename)
end

+ (Object) battleback2(filename)


  • Get Battle Background (Wall) Graphic




26
27
28
# File 'Cache.rb', line 26

def self.battleback2(filename)
  load_bitmap("Graphics/Battlebacks2/", filename)
end

+ (Object) battler(filename, hue)


  • Get Battle Graphic




32
33
34
# File 'Cache.rb', line 32

def self.battler(filename, hue)
  load_bitmap("Graphics/Battlers/", filename, hue)
end

+ (Object) character(filename)


  • Get Character Graphic




38
39
40
# File 'Cache.rb', line 38

def self.character(filename)
  load_bitmap("Graphics/Characters/", filename)
end

+ (Object) clear


  • Clear Cache




129
130
131
132
133
# File 'Cache.rb', line 129

def self.clear
  @cache ||= {}
  @cache.clear
  GC.start
end

+ (Object) empty_bitmap


  • Create Empty Bitmap




99
100
101
# File 'Cache.rb', line 99

def self.empty_bitmap
  Bitmap.new(32, 32)
end

+ (Object) face(filename)


  • Get Face Graphic




44
45
46
# File 'Cache.rb', line 44

def self.face(filename)
  load_bitmap("Graphics/Faces/", filename)
end

+ (Object) hue_changed_bitmap(path, hue)


  • Create/Get Hue-Changed Bitmap




112
113
114
115
116
117
118
119
# File '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

+ (Boolean) include?(key)


  • Check Cache Existence


Returns:

  • (Boolean)


123
124
125
# File 'Cache.rb', line 123

def self.include?(key)
  @cache[key] && !@cache[key].disposed?
end

+ (Object) load_bitmap(folder_name, filename, hue = 0)


  • Load Bitmap




86
87
88
89
90
91
92
93
94
95
# File '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

+ (Object) normal_bitmap(path)


  • Create/Get Normal Bitmap




105
106
107
108
# File 'Cache.rb', line 105

def self.normal_bitmap(path)
  @cache[path] = Bitmap.new(path) unless include?(path)
  @cache[path]
end

+ (Object) parallax(filename)


  • Get Parallax Background Graphic




50
51
52
# File 'Cache.rb', line 50

def self.parallax(filename)
  load_bitmap("Graphics/Parallaxes/", filename)
end

+ (Object) picture(filename)


  • Get Picture Graphic




56
57
58
# File 'Cache.rb', line 56

def self.picture(filename)
  load_bitmap("Graphics/Pictures/", filename)
end

+ (Object) system(filename)


  • Get System Graphic




62
63
64
# File 'Cache.rb', line 62

def self.system(filename)
  load_bitmap("Graphics/System/", filename)
end

+ (Object) tileset(filename)


  • Get Tileset Graphic




68
69
70
# File 'Cache.rb', line 68

def self.tileset(filename)
  load_bitmap("Graphics/Tilesets/", filename)
end

+ (Object) title1(filename)


  • Get Title (Background) Graphic




74
75
76
# File 'Cache.rb', line 74

def self.title1(filename)
  load_bitmap("Graphics/Titles1/", filename)
end

+ (Object) title2(filename)


  • Get Title (Frame) Graphic




80
81
82
# File 'Cache.rb', line 80

def self.title2(filename)
  load_bitmap("Graphics/Titles2/", filename)
end