查看: 11490|回复: 30

[交流讨论] 【Image Cache问题】感觉MV游戏跑着跑着内存会越来越大

[复制链接]
梦石
0
星屑
80
在线时间
386 小时
注册时间
2007-7-27
回帖
4075

开拓者

发表于 2015-12-27 01:10:27 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 trentswd 于 2015-12-27 01:12 编辑

这个问题很早就看RPGMAKERWEB上讨论过了,当时没仔细看
最近看了看,惊了
RMMV的Image Load的实现是这样的:
[pre lang="javascript"]
ImageManager.loadNormalBitmap = function(path, hue) {
    var key = path + ':' + hue;
    if (!this._cache[key]) {
        var bitmap = Bitmap.load(path);
        bitmap.addLoadListener(function() {
            bitmap.rotateHue(hue);
        });
        this._cache[key] = bitmap;
    }
    return this._cache[key];
};

ImageManager.clear = function() {
    this._cache = {};
};
[/pre]
按照这个用法,每个载入的图片都会保存在ImageManager._cache中,根本不会释放,也没有什么先入先出、最少使用先出之类的清空方法
只有使用ImageManager.clear才会清空,然而默认脚本里面压根就没调用过这个方法

理论上游戏很大的话,随着游戏时间的增加,最后会把所有的图片都读到内存里面去?还是说Html5的Image会自动释放?
吸吸
梦石
0
星屑
50
在线时间
491 小时
注册时间
2015-1-7
回帖
110
发表于 2015-12-27 01:18:01 | 显示全部楼层
我发现每天第一次开游戏很慢,然后就快了,应该是电脑关了就消了吧

点评

第一次读文件慢 开fps的话看的很清楚 读取进来就好了  发表于 2015-12-27 11:17
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2015-12-27 09:53:11 | 显示全部楼层
于是该怎么办呢?
添加一个预加载和过多处理的方法吗?
回复

使用道具 举报

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2015-12-27 11:17:06 | 显示全部楼层
搬运一个插件 还没研究细节
其实要能做的只能一点在事件里面调用的话应该很方便
做远景地图的话 离开一个区域可以在传送点加入清缓存代码

[pre lang="javascript"]       

    //=============================================================================
    // Cache Manager
    // by Shaz
    // Last Updated: 2015.10.30
    //=============================================================================
     
    /*:
     * @plugindesc Selectively clear the image cache for memory usage improvements
     * @author Shaz
     *
     * @param Mobile only
     * @desc Cache management only runs on mobile platforms (N to run on all platforms)
     * @default Y
     *
     * @param --------------------------------------------
     *
     * @param Clear All
     * @desc Clears all cached images except System (if Y, ignore remaining parameters)
     * @default Y
     *
     * @param Clear Animations
     * @desc Clear Animation images
     * @default Y
     *
     * @param Clear Battlebacks
     * @desc Clear Battleback images
     * @default Y
     *
     * @param Clear Battlers
     * @desc Clear Battler images
     * @default Y
     *
     * @param Clear Characters
     * @desc Clear Character images
     * @default Y
     *
     * @param Clear Faces
     * @desc Clear Face images
     * @default Y
     *
     * @param Clear Parallaxes
     * @desc Clear Parallax images
     * @default Y
     *
     * @param Clear Pictures
     * @desc Clear Picture images
     * @default Y
     *
     * @param Clear System
     * @desc Clear System images (not recommended)
     * @default N
     *
     * @param Clear Tilesets
     * @desc Clear Tileset images
     * @default Y
     *
     * @param Clear Titles
     * @desc Clear Title images
     * @default Y
     *
     * @param Custom Images
     * @desc List custom image paths to clear, separated by ; (img/fogs; img/busts)
     * @default
     *
     * @help This plugin does not provide plugin commands.
     *
     * This plugin allows you to specify how often the image cache should be
     * cleared, and what kind of images should be cleared.  This can be used
     * to improve memory usage on low-memory platforms, but will also result
     * in more frequent loading delays.
     *
     * If not using the 'clear all' default option, and you have plugins that
     * use their own custom image paths, list those paths in the Custom Images
     * parameter to clear any images cached from those locations.
     *
     */
     
    (function() {
      var params = PluginManager.parameters('CacheManager');
      var mobile = (params['Mobile only'] || 'Y').toUpperCase().substring(0,1) === 'Y';
      var clearAll = (params['Clear All'] || 'Y').toUpperCase().substring(0,1) === 'Y';
      if (!clearAll) {
        pathsToClear = [];
        if ((params['Clear Animations'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/animations');
        if ((params['Clear Battlebacks'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/battlebacks1', 'img/battlebacks2');
        if ((params['Clear Battlers'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/enemies', 'img/sv-actors', 'img/sv-enemies');
        if ((params['Clear Characters'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/characters');
        if ((params['Clear Faces'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/faces');
        if ((params['Clear Parallaxes'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/parallaxes');
        if ((params['Clear Pictures'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/pictures');
        if ((params['Clear System'] || 'N').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/system');
        if ((params['Clear Tilesets'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/tilesets');
        if ((params['Clear Titles'] || 'Y').toUpperCase().substring(0,1) === 'Y')
          pathsToClear.push('img/titles1', 'img/titles2');
        (params['Custom Images'] || '').split(';').forEach(function(path) { if (path) pathsToClear.push(path.trim()) }.bind(this));
      }
     
      ImageManager.clear = function() {
        for (image in this._cache) {
          if (clearAll && image.indexOf('img/system') === -1)
            this.removeFromCache(image);
          else if (!clearAll && pathsToClear.some(function(path) { return image.indexOf(path) > -1}.bind(this)))
            this.removeFromCache(image);
        }
      };
     
      ImageManager.removeFromCache = function(image) {
        if (image !== 'null') {
          if (this._cache.hasOwnProperty(image) && this._cache[image] instanceof Bitmap) {
            if (this._cache[image].baseTexture) {
              this._cache[image].baseTexture.destroy();
            }
          }
          delete this._cache[image];
        }
      };
     
      var _Scene_Map_create = Scene_Map.prototype.create;
      Scene_Map.prototype.create = function() {
        _Scene_Map_create.call(this);
        if (this._transfer && (!mobile || Utils.isMobileDevice())) {
          ImageManager.clear();
        }
      };
    })();

[/pre]

点评

看了一下这个插件说:This plugin allows you to specify how often the image cache should be cleared,但是实际我没找到怎么配置清理时间  发表于 2015-12-27 15:12
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-12-27 11:33:55 | 显示全部楼层
RM 所有版本都是这样的,并不会有什么问题。

正常电脑的内存是够用的。

点评

当年xp的时候512MB内存都算大。256主流,远景图地图玩久也会卡  发表于 2015-12-28 01:29
电脑上问题可能不大,手机上就需要担心了  发表于 2015-12-27 17:29
PC版一般都还好,打到手机上玩简直爆炸的卡  发表于 2015-12-27 14:55
回复

使用道具 举报

梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
回帖
403
发表于 2015-12-27 13:10:15 | 显示全部楼层
我个人觉得目前主流电脑的内存已经足够适应足够大的RM游戏。
  点我进入    
       ↓      
回复

使用道具 举报

梦石
0
星屑
50
在线时间
145 小时
注册时间
2015-12-22
回帖
33
发表于 2015-12-27 13:45:29 | 显示全部楼层
以空间换时间,以耗内存为代价换取流畅性,是软件发展的主流趋势。
回复

使用道具 举报

梦石
0
星屑
100
在线时间
268 小时
注册时间
2010-12-22
回帖
17
发表于 2015-12-27 13:49:39 | 显示全部楼层
最近剛好也在查這個問題,因為一些舊型手機在執行時FPS 相當低, 這邊查到了一個preload 跟 控制記憶體使用的
插件,但怎麼都不會用,還望大神能夠教學

http://liply.net/2015/11/14/preload/

点评

虽然我也看不懂,但是LFU应该是按使用频率来清除。不过它既然是alpha还是暂时不要使用了……  发表于 2015-12-27 17:34
回复

使用道具 举报

梦石
0
星屑
50
在线时间
145 小时
注册时间
2015-12-22
回帖
33
发表于 2015-12-27 13:53:57 | 显示全部楼层
吃内存是现代软件的优化方式,如果把它“优化”掉,只能提高游戏在低配手机上的流畅性,在高配手机和电脑上会变得更卡,大内存用户的游戏体验会变差。
回复

使用道具 举报

梦石
0
星屑
55
在线时间
388 小时
注册时间
2009-8-4
回帖
212
发表于 2015-12-27 13:54:28 | 显示全部楼层
本帖最后由 andrewx 于 2015-12-27 13:56 编辑
taroxd 发表于 2015-12-27 11:33
RM 所有版本都是这样的,并不会有什么问题。

正常电脑的内存是够用的。


但是放在手机上可能就要出问题了吧?目前移动端运行起来效率确实有点糟糕
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部