module RPG
module Cache
def self.load_bitmap(folder_name, filename, hue = 0)
path = folder_name + filename
#----------------------------------------------------------------
# 优先从 resource 里加载
#----------------------------------------------------------------
if not @cache.include?(path) or @cache[path].disposed?
if filename != ""
resource = 'Resource/' + md5(path)
if FileTest.exist?(resource)
@cache[path] = load_data(resource)
else
@cache[path] = Bitmap.new(path)
end
else
@cache[path] = Bitmap.new(32, 32)
end
end
if hue == 0
@cache[path]
else
key = [path, hue]
if not @cache.include?(key) or @cache[key].disposed?
@cache[key] = @cache[path].clone
@cache[key].hue_change(hue)
end
@cache[key]
end
end
def self.md5(string)
# 这里简单的用 crc32 值取代 md5 值
sprintf('%08x%08x', Zlib::crc32(string.downcase), Zlib::crc32(string.downcase.reverse))
end
end
end