オプションでフレームレート設定項目

アバター
シンゴビッチ
記事: 38
登録日時: 2020年5月25日(月) 03:12
連絡を取る:

オプションでフレームレート設定項目

投稿記事by シンゴビッチ » 2020年11月28日(土) 01:51

オプション画面.png
スマホや低スペックpc用にオプション項目としてfpsを下げるものを追加したのですが機能しません。

アツマール版Community_basicを参考にしてfpsを制御する事自体は上手くいきましたが、オプションで変更したものが反映されません。半日ぐらい粘りましたが問題点が見つかりませんでしたので、指南をお願いしたいです。

1.アツマール版Community_basicを参考にfpsを制御し箇所

コード: 全て選択

var currentTime = Date.now();
    var deltaTime = 1000 / ConfigManager.fpsControl;
    var accumulator = 0;
    var _SceneManager_renderScene = SceneManager.renderScene;
    SceneManager.renderScene = function() {
        var newTime = Date.now();
        accumulator += newTime - currentTime;
        currentTime = newTime;
        if (accumulator >= deltaTime) {
            accumulator -= deltaTime;
            _SceneManager_renderScene.apply(this, arguments);
        }
    };
})();


2.ConfigManager.fpsControlの初期値(この初期値60を弄るとフレームレートが変わる)

コード: 全て選択

ConfigManager.alwaysDashOnOff        = false;
ConfigManager.commandRememberOnOff   = false;
ConfigManager.fpsControl   = 60;



3.ConfigManager(上手くいってない箇所候補。その1)多分最有力箇所

コード: 全て選択

ConfigManager.makeData = function() {
    var config = {};
    config.alwaysDashOnOff = this.alwaysDashOnOff;
    config.commandRememberOnOff = this.commandRememberOnOff;
    config.bgmVolume = this.bgmVolume;
    config.bgsVolume = this.bgsVolume;
    config.meVolume = this.meVolume;
    config.seVolume = this.seVolume;
    config.fpsControl = this.fpsControl;
    return config;
};

ConfigManager.applyData = function(config) {
    this.alwaysDashOnOff = this.readFlag(config, 'alwaysDashOnOff');
    this.commandRememberOnOff = this.readFlag(config, 'commandRememberOnOff');
    this.bgmVolume = this.readVolume(config, 'bgmVolume');
    this.bgsVolume = this.readVolume(config, 'bgsVolume');
    this.meVolume = this.readVolume(config, 'meVolume');
    this.seVolume = this.readVolume(config, 'seVolume');
    this.fpsControl = this.readFpsValue(config, 'fpsControl');
};

ConfigManager.readFlag = function(config, name) {
    return !!config[name];
};

ConfigManager.readVolume = function(config, name) {
    var value = config[name];
    if (value !== undefined) {
        return Number(value).clamp(0, 100);
    } else {
        return 100;
    }
};

ConfigManager.readFpsValue = function(config, name) {
    var value = config[name];
    if (value !== undefined) {
        return Number(value).clamp(15, 60);
    } else {
        return 60;
    }
};



3.Window_Options(上手くいってない箇所候補。その2)

コード: 全て選択

Window_Options.prototype.addVolumeOptions = function() {
    this.addCommand("フレームレート", 'fpsControl');
    this.addCommand(TextManager.bgmVolume, 'bgmVolume');
    this.addCommand(TextManager.bgsVolume, 'bgsVolume');
    this.addCommand(TextManager.meVolume, 'meVolume');
    this.addCommand(TextManager.seVolume, 'seVolume');
};

Window_Options.prototype.drawItem = function(index) {
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawText(this.commandName(index), rect.x, rect.y, titleWidth, 'left');
    this.drawText(this.statusText(index), titleWidth, rect.y, statusWidth, 'right');
};

Window_Options.prototype.statusWidth = function() {
    return 120;
};

Window_Options.prototype.statusText = function(index) {
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    if (this.isVolumeSymbol(symbol)) {
        return this.volumeStatusText(value);
    } else if(this.isBooleanSymbol(symbol)){
        return this.booleanStatusText(value);
    } else if(this.isFpsSymbol(symbol)){
        return this.fpsStatusText(value);
    } else {
        return ""
    }
};

Window_Options.prototype.isVolumeSymbol = function(symbol) {
    return symbol.contains('Volume');
};

Window_Options.prototype.isBooleanSymbol = function(symbol) {
    return symbol.contains('OnOff');
};


Window_Options.prototype.isFpsSymbol = function(symbol) {
    return symbol.contains('fps');
};



Window_Options.prototype.booleanStatusText = function(value) {
    return value ? 'ON' : 'OFF';
};


Window_Options.prototype.fpsStatusText = function(value) {
    return value + 'Fps';
};


Window_Options.prototype.volumeStatusText = function(value) {
    return value + '%';
};

Window_Options.prototype.processOk = function() {
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    if (this.isVolumeSymbol(symbol)) {
        value += this.volumeOffset();
        if (value > 100) {
            value = 0;
        }
        value = value.clamp(0, 100);
        this.changeValue(symbol, value);
    } else if(this.isBooleanSymbol(symbol)){
        this.changeValue(symbol, !value);
    } else if(this.isFpsSymbol(symbol)){
        value += this.fpsOffset();
        if (value > 60) {
            value = 0;
        }
        value = value.clamp(15, 60);
        this.changeFpsValue(symbol, value);
    } else {
    Window_Options._lastCommandSymbol = this.currentSymbol();
    Window_Command.prototype.processOk.call(this);
    }
};

Window_Options.prototype.cursorRight = function(wrap) {
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    if (this.isVolumeSymbol(symbol)) {
        value += this.volumeOffset();
        value = value.clamp(0, 100);
        this.changeValue(symbol, value);
    } else if(this.isFpsSymbol(symbol)){
        value += this.fpsOffset();
        value = value.clamp(15, 60);
        this.changeFpsValue(symbol, value);
    } else {
        this.changeValue(symbol, true);
    }
};

Window_Options.prototype.cursorLeft = function(wrap) {
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    if (this.isVolumeSymbol(symbol)) {
        value -= this.volumeOffset();
        value = value.clamp(0, 100);
        this.changeValue(symbol, value);
    } else if(this.isFpsSymbol(symbol)){
        value -= this.fpsOffset();
        value = value.clamp(15, 60);
        this.changeFpsValue(symbol, value);
    } else {
        this.changeValue(symbol, false);
    }
};

Window_Options.prototype.volumeOffset = function() {
    return 20;
};

Window_Options.prototype.fpsOffset = function() {
    return 15;
};


Window_Options.prototype.changeValue = function(symbol, value) {
    var lastValue = this.getConfigValue(symbol);
    if (lastValue !== value) {
        this.setConfigValue(symbol, value);
        this.redrawItem(this.findSymbol(symbol));
        SoundManager.playCursor();
    }
};


Window_Options.prototype.changeFpsValue = function(symbol, value) {
    var lastValue = this.getConfigValue(symbol);
    if (lastValue !== value) {
        this.setFpsConfigValue(symbol, value);
        this.redrawItem(this.findSymbol(symbol));
        SoundManager.playCursor();
    }
};


Window_Options.prototype.getConfigValue = function(symbol) {
    return ConfigManager[symbol];
};

Window_Options.prototype.setConfigValue = function(symbol, volume) {
    ConfigManager[symbol] = volume;
};

Window_Options.prototype.setFpsConfigValue = function(symbol, value) {
    ConfigManager[symbol] = value;
}


【参考:オプション画面】

ゲーム作成用Twitterアカウント作りました https://twitter.com/RPGVV1
アバター
Plasma Dark
記事: 669
登録日時: 2020年2月08日(土) 02:29
連絡を取る:

Re: オプションでフレームレート設定項目

投稿記事by Plasma Dark » 2020年11月28日(土) 12:07

書いたコードが長い場合はgistとかに全部貼ってしまったほうが見やすいんじゃないかと思います。

ところで、ご自身の書かれたコードについて内容は理解されているでしょうか。
deltaTimeが何者で、どういうタイミングでどう書き換えられるかを考えれば、なぜ設定した初期値でFPSが固定されるのかわかるかと思います。
アバター
シンゴビッチ
記事: 38
登録日時: 2020年5月25日(月) 03:12
連絡を取る:

Re: オプションでフレームレート設定項目

投稿記事by シンゴビッチ » 2020年11月28日(土) 14:13

PLASMA DARKさん
ご指摘ありがとうございました。
ものすごい初歩的なミスをしてましたw。

確かにこれは”解っていないかも”と指摘されても仕方がない凡ミスでした。
あの言い方でないとおそらく気づかなかったと思います。
(ツクールのメインループ部分なのでここを触るのは最小限にしたいなと思ったので
チェックから外してました・・・)

コード: 全て選択

var currentTime = Date.now();
    var accumulator = 0;
    //var deltaTime = 1000 / ConfigManager.fpsControl;
     //関数の外に書いて動くわけがない・・・;
    var _SceneManager_renderScene = SceneManager.renderScene
    SceneManager.renderScene = function() {
        var newTime = Date.now();
        accumulator += newTime - currentTime;
        currentTime = newTime;
            var deltaTime = 1000 / ConfigManager.fpsControl;
            //ここに移動
        if (accumulator >= deltaTime) {
            accumulator -= deltaTime;
            _SceneManager_renderScene.apply(this, arguments);
        }
    };
})();
ゲーム作成用Twitterアカウント作りました https://twitter.com/RPGVV1

“MV:質問” へ戻る