设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 6997|回复: 6
打印 上一主题 下一主题

[原创发布] 自定义FPS+修复高刷新率显示器的BUG

[复制链接]

Lv1.梦旅人

Mr.Gandum

梦石
0
星屑
226
在线时间
2070 小时
注册时间
2007-1-31
帖子
3039

贵宾

跳转到指定楼层
1
发表于 2015-10-26 22:47:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 feizhaodan 于 2015-11-24 19:35 编辑

MV使用requestAnimationFrame()来进行屏幕刷新,但是这个有一些特征不太适用于游戏。
这个插件添加一个简单的计时器来控制FPS,也提供了不使用计时器来解决这个问题的方法。
具体内容看插件的帮助栏内。
JAVASCRIPT 代码复制下载
  1. //=============================================================================
  2. // Alternative Screen Refresh Timer
  3. // TimerRefreshRate.js
  4. // Version: 1.02
  5. // Changelog:         1.02:
  6. //                                - Fix a bug that when Using Custom Timer the game not progress.
  7. //                                1.01:
  8. //                                - Fix Refresh Rate is not working at monitor with <60 Hz.
  9. //=============================================================================
  10. var Imported = Imported || {};
  11. Imported.Kien_Alt_Screen_Refresh_Timer = true;
  12.  
  13. var Kien = Kien || {};
  14. Kien.ASRT = {};
  15. //=============================================================================
  16. /*:
  17.  * @plugindesc Provide an alternative refresh rate process, or just fix the glitch
  18.  * when the game is played at monitor with higher refresh rate.
  19.  * @author Kien
  20.  *
  21.  * @param Use Alternative Timer
  22.  * @desc Use Alternative timer to solve the problem of refresh rate and background
  23.  * movements, but is not stable as default
  24.  * @default false
  25.  
  26.  * @param Allow Backgronud
  27.  * @desc allow the game process when the tab/browser is not active. Only works
  28.  * when using alternative timer. Currently have no work
  29.  * @default true
  30.  *
  31.  * @param Custom FPS
  32.  * @desc use a refresh rate other than 60. don't chagne this unless you know
  33.  * what you are doing.
  34.  * @default 60
  35.  *
  36.  * @param Fix Refresh Rate
  37.  * @desc fix the problem with higher refresh rates. Only works when NOT using
  38.  * alternative timer.
  39.  * @default true
  40.  *
  41.  * @help
  42.  * ============================================================================
  43.  * Alternative Screen Refresh Timer (English Document)
  44.  * ============================================================================
  45.  *                 Provide an alternative refresh rate process, or just fix the glitch
  46.  * when the game is played at monitor with higher refresh rate.
  47.  * ============================================================================
  48.  * * About Refresh Rate
  49.  * ============================================================================
  50.  *                 In RPG Maker MV, the refresh rate is controlled by requestAnimationFrame()
  51.  * function provided by the browser. This function will automatically ensures
  52.  * the animation works in a proper rate, but there have some problem when we use
  53.  * this directly in a game.
  54.  * 1. Refresh Rate
  55.  *             Refresh rate of the monitor is not a fixed value, while we want our game
  56.  * have a fixed 60 fps. This will make the game have accelerated game speed in
  57.  * those monitor have a refresh ratemore than 60, and deccelerated game speed
  58.  * in those monitor have a refresh rate lower than 60.
  59.  *
  60.  * 2. No Background Proess
  61.  *             requestAnimationFrame() is used to show animation, so it will NOT give
  62.  * timing when the animation not need to show. That is, when the game is at
  63.  * a tab/browser that is not the active tab/browser, the game will not have any
  64.  * process.
  65.  * ============================================================================
  66.  * * What does this plugin do
  67.  * ============================================================================
  68.  *           This plugin will fix both problem by adding a timer like other games
  69.  * and (maybe) previous RPG Makers, or just solve the first problem by give
  70.  * pauses to default process. This can tweeks at Options provided by this
  71.  * plugin.
  72.  * ============================================================================
  73.  * * Note
  74.  * ============================================================================
  75.  *                 Make sure to put this plugin at top of the list, or maybe there have
  76.  * some problems. Also, it seems that setTimeout is not precise as
  77.  * requestAnimationFrame(), so in some time, this custom timer will not work.
  78.  * ============================================================================
  79.  * * End of Document (English Document)
  80.  * ============================================================================
  81.  * ============================================================================
  82.  * * 自作FPSタイマー(Japanese Document)
  83.  * ============================================================================
  84.  *   FPSタイマーを別に追加し、デフォルト状態の一部のバグを修復します。または、デフォルトで発生するリフレッシュ
  85.  * レートの高いモニターで発生するバグを修復します。
  86.  * ============================================================================
  87.  * * リフレッシュレートについて
  88.  * ============================================================================
  89.  *   RPGツクールMVでは、従来のタイマー式と推測されるFPS進行をブラウザーが提供する
  90.  * requestAnimationFrame()という関数で管理するようにしています。この関数は、ブラウザーが適切なタイミング
  91.  * でコールバックを呼び出すことで、アニメーションを正確に更新できるようにするためのものですが、ゲームとして使用する
  92.  * 場合、以下のような不都合が発生します:
  93.  * 1. リフレッシュレート
  94.  *   requestAnimationFrame()関数はモニターのリフレッシュレートに合わせるようにコールバックを呼び出し
  95.  * ますが、すべてのモニターが60FPSで更新されているわけではありません。そのため、60FPSとして想定されているRPG
  96.  * ツクールMV製のゲームをそれらのモニターで使用すると、ゲームが加速あるいは減速した状態で処理されてしまいます
  97.  * 。
  98.  * 2. バックグラウンド処理
  99.  *   requestAnimationFrame()はアニメーションを表示するために提供されている関数ですが、アニメーションを
  100.  * 表示する必要がない場合、つまりタブ・ブラウザーが非アクティブ時は全く処理されなくなるということです。
  101.  * ============================================================================
  102.  * * このプラグインについて
  103.  * ============================================================================
  104.  *   このプラグインは上記の問題を、自作のFPSタイマーでFPSを管理することで解消します。また、デフォルトのFPS
  105.  * 管理でいいという人のために、致命的な一番目の問題だけを解決する部分も提供します。
  106.  * ============================================================================
  107.  * * 注意
  108.  * ============================================================================
  109.  *   このプラグインは、可能な限りリストの一番上に来るようにしてください。また、タイマーとして用いている
  110.  * setTimeout() 関数はrequestAnimationFrame()ほど正確ではないため、動作環境によってはデフォルト
  111.  * タイマーのほうが優れている。
  112.  * ============================================================================
  113.  * * ドキュメント終了 (Japanese Document)
  114.  * ============================================================================
  115.  * ============================================================================
  116.  * * FPS时钟(Chinese Document)
  117.  * ============================================================================
  118.  *     提供另外一种FPS计算方法,或者只修复一个默认系统的BUG。
  119.  * ============================================================================
  120.  * * 关于刷新率
  121.  * ============================================================================
  122.  *     RPG Maker MV使用浏览器提供的requestAnimationFrame() 函数来控制游戏的FPS,而不是像
  123.  * 通常的游戏使用计时器来进行。虽然这个函数提供了稳定的FPS,但是会造成以下的两个问题:
  124.  * 1. 刷新率
  125.  *    requestAnimationFrame() 函数根据屏幕的刷新率来呼出回调函数。但是不是所有的屏幕都是
  126.  * 60Hz。在那些有不是60Hz刷新率的屏幕上执行MV的游戏会造成游戏速度变速,严重影响游戏体验。
  127.  * 2. 后台运行
  128.  *    requestAnimationFrame() 函数本来是用来绘制动画。当不需要绘制动画,即网页是在后台状
  129.  * 态时,requestAnimationFrame() 函数不会调用回调函数,令游戏无法后台运行。
  130.  * ============================================================================
  131.  * * 关于这个插件
  132.  * ============================================================================
  133.  *     本插件通过使用计时器来管理FPS,解决上面的两个问题。也提供不适用计时器的方法来解决比较
  134.  * 严重的第一个问题。另外,setTimeout()的精准度没有requestAnimationFrame()准确,因此根据
  135.  * 情况可能会造成更多延迟。
  136.  * ============================================================================
  137.  * * 注意
  138.  * ============================================================================
  139.  *     请将本插件放到插件列表的最上方以防止出现不可预料的冲突。
  140.  * ============================================================================
  141.  * * 文档结束 (Chinese Document)
  142.  * ============================================================================
  143.  */
  144.  
  145. Kien.ASRT.parameters = PluginManager.parameters("TimerRefreshRate");
  146. Kien.ASRT.useTimer = Kien.ASRT.parameters["Use Alternative Timer"];
  147. Kien.ASRT.allowBackground = Kien.ASRT.parameters["Allow Backgronud"];
  148. Kien.ASRT.fps = Kien.ASRT.parameters["Custom FPS"];
  149. Kien.ASRT.fixFPS = Kien.ASRT.parameters["Fix Refresh Rate"];
  150.  
  151. Kien.ASRT.Timer = function(){
  152.         this._fps = Kien.ASRT.fps;
  153.         this._lastDate = Date.now();
  154.         this._msToNext10 = 10000 / this._fps
  155.         this._msPassed10 = 0;
  156. }
  157.  
  158. Kien.ASRT.Timer.prototype.updateTimer = function(){
  159.         var nowDate = Date.now();
  160.         this._msPassed10 += (nowDate - this._lastDate) * 10;
  161.         this._lastDate = nowDate;
  162. }
  163.  
  164. Kien.ASRT.Timer.prototype.checkTimer = function(){
  165.         if (this._msPassed10 > this._msToNext10){
  166.                 this._msPassed10 -= this._msToNext10;
  167.                 return true;
  168.         }
  169.         return false;
  170. }
  171.  
  172. Kien.ASRT.SceneManager_requestUpdate = SceneManager.requestUpdate;
  173. SceneManager.requestUpdate = function() {
  174.         if (!Kien.ASRT.useTimer){
  175.                 Kien.ASRT.SceneManager_requestUpdate.call(this);
  176.         } else {
  177.                 this._timer.updateTimer();
  178.                 while (this._timer.checkTimer()){
  179.                         this.update();
  180.                 }
  181.                 setTimeout(this.requestUpdate.bind(this),1);
  182.         }
  183. };
  184.  
  185. Kien.ASRT.SceneManager_initialize = SceneManager.initialize;
  186. SceneManager.initialize = function() {
  187.         Kien.ASRT.SceneManager_initialize.call(this);
  188.         this._timer = new Kien.ASRT.Timer();
  189. };
  190.  
  191.  
  192. if(Kien.ASRT.fixFPS && !Kien.ASRT.useTimer){
  193.         Kien.ASRT.SceneManager_update = SceneManager.update;
  194.         SceneManager.update = function() {
  195.                 this._timer.updateTimer()
  196.                 while (this._timer.checkTimer()){
  197.                         Kien.ASRT.SceneManager_update.call(this);
  198.                 }
  199.         }
  200. };

注意关于高刷新率显示器的部分是未测试,因为我没有高刷新率的显示器囧

评分

参与人数 1星屑 +66 梦石 +2 收起 理由
余烬之中 + 66 + 2 图书馆收录

查看全部评分

Lv2.观梦者

梦石
0
星屑
624
在线时间
463 小时
注册时间
2009-9-29
帖子
67

开拓者

2
发表于 2015-10-26 23:15:07 | 只看该作者
救命稻草!!!昨天还在纠结这个,今天就有了现成的肉可以拿!!大感谢!!
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
5
星屑
3038
在线时间
612 小时
注册时间
2012-11-12
帖子
482

开拓者

3
发表于 2015-10-27 00:02:22 | 只看该作者
官方好像也发现这个bug了,今天更新了补丁
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止访问)

梦石
0
星屑
88
在线时间
631 小时
注册时间
2014-8-4
帖子
3600
4
发表于 2015-10-27 12:51:11 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv1.梦旅人 (暗夜天使)

永夜蟄居の玖瀨

梦石
0
星屑
71
在线时间
1018 小时
注册时间
2011-9-5
帖子
2813

开拓者贵宾

5
发表于 2015-10-27 16:36:08 | 只看该作者
三国语言大触(

回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
950
在线时间
4 小时
注册时间
2015-10-26
帖子
3
6
发表于 2015-10-27 17:46:35 | 只看该作者
不可思议 原来的帧数过低解决了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
42 小时
注册时间
2017-6-8
帖子
36
7
发表于 2017-7-24 15:15:20 | 只看该作者
鸟猫 发表于 2015-10-27 00:02
官方好像也发现这个bug了,今天更新了补丁

也就是说现在不管屏幕刷新率是多少,游戏帧率都是60吗?
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-11 04:01

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表