加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 九靈 于 2013-8-23 01:20 编辑
module RPG module Cache [url=home.php?mod=space&uid=341345]@Cache[/url] = {} def self.load_bitmap(folder_name, filename, hue = 0) path = folder_name + filename if not @cache.include?(path) or @cache[path].disposed? if filename != "" @cache[path] = Bitmap.new(path) 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
module RPG
module Cache
[url=home.php?mod=space&uid=341345]@Cache[/url] = {}
def self.load_bitmap(folder_name, filename, hue = 0)
path = folder_name + filename
if not @cache.include?(path) or @cache[path].disposed?
if filename != ""
@cache[path] = Bitmap.new(path)
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
第18行的
@cache[key] = @cache[path].clone
clone 是必要吗?
何不直接
@cache[key] = @cache[path] 呢?
换句话说
一般而言 clone 的目的是什么?
|