MAC_High_Hz_Fixes - Fixes for various problems with >60Hz monitors

● ARCHIVED · READ-ONLY
Started by Mac15001900 48 posts Page 1 of 3 View original ↗
  1. Synopsis
    This is a plugin that, unless you've done something similar yourself, you'd almost certainly benefit from adding to your game, no matter what kind of game it is. Let me explain why.

    MV games have the tendency to break in various ways when they're played on a monitor with a refresh rate higher than 60Hz, even if they work perfectly fine otherwise. This is not the fault of their developers, but the core scripts that in many places fail to account for the fact that such devices exist.

    Things that can happen when an MV game is played on a high refresh rate monitor include:
    - Inaccurately counted playtime
    - Inaccurate FPS counter
    - Some plugins' animations and other effects playing faster than they should
    - CPU usage climbing considerably higher than it should
    - And rarely the game just freezing completely

    This plugin, as you might have guessed, fixes those issues.

    How does this work?
    You don't need to know that to use this plugin, but if you're curious, read ahead.
    If you have a good understanding of RM's code, it might be quicker for you to look through the plugin file - there are comments indicating what changes were made.

    MV games run at 60 frames per second. Or at least they try to: they render frames as often as they can, but run game logic so that it always happens 60 times per second, even if this results in multiple logical frames happening during a single frame.

    Now, this works out fine if "as often as they can" is 60 times per second. But what if we have a monitor and a computer that can handle more? Then the engine will draw more frames, even though game logic still only runs 60 times per second. This often leads to the exact same image being redrawn multiple times, as multiple frames are drawn before anything visible changes, causing a higher than needed CPU load. So there's our first optimisation: only draw a new frame if it will be different than the previous one (or at least it's possible for it to be different). On my 165Hz screen, this halves CPU usage, without affecting the game in any way.

    Now, there are some more things that run on the "as often as they can" cycle. This includes the FPS counter, which rather uselessly counts all those attempt to draw a frame. Even if the game is lagging (e.g. can only handle 40 real frames per second) it can still show a much higher value.

    Similarly, Graphics.frameCount also gets updated too often, which leads to a multiple different effects. For one, playtime will be counted inaccurately (e.g. up to twice as much as on a 120Hz screen). Various plugins that use Graphics.frameCount for timing might also have that timing go a lot faster.

    Game_2024-09-18_18-42-14.gif
    Example of an animation added by a plugin

    Game_2024-09-18_18-42-59.gif
    The same animation on a 165Hz screen (without MAC_High_Hz_Fixes)

    Now, as to the rare thing that can freeze the entire game. The freeze is actually purely graphical - you'll still be able to hear sounds, just that what's drawn on screen won't ever change. It's caused by a bug in Graphics.render that could theoretically happen on 60Hz screens too, but high refresh rates make it exponentially more likely. More discussion about it can be found in this thread.

    Special thanks
    I didn't exactly come up with all of this myself; half of those fixes wouldn't exist without the help of others. So I'd like to thank:

    kido0617 for the fix for the game freeze, and @TheAM-Dol for bringing it to my attention
    @caethyril for the fix to Graphics.frameCount and additional insight about the likely cause of the game freeze bug
    @chaucer and @Arthran for their insight in the discussion about the CPU usage optimisation, as well as @TheAM-Dol and @Robro33 for their help in testing it for unintended consequences

    Plugin compatibility

    If you're already using fixes to some of those problems, place this plugin below them (though in general you should also be able to just remove them now).
    If you're using Chau_SceneStabilizer, place MAC_High_Hz_Fixes below it.

    If there are any other incompatibilities you discover, please let me know! I think it's quite important to make this plugin available to everyone, and I'll try to fix any issues like this.

    Terms

    This plugin is available under the MIT Licence. You're free to use it in any games, commercial or not, or use the code in your own plugins. Credit is appreciated, but not required.
  2. Holy hell man, this is a surprise! I almost missed that you had posted this too because it had already been pushed down to the 2nd page of new topics.

    I'll need to update my graphics freeze tutorial post with this!
    It'll also be nice to take the plugin load down by 2 since there are 3 plugin functions basically rolled into this one. :kaojoy:
  3. Might be useful since I have a lot of simultaneous effects happening on parallel in my game.
  4. AquaEcho said:
    Might be useful since I have a lot of simultaneous effects happening on parallel in my game.
    From my understanding, this does not improve all game performance levels. This only improves CPU utilization for games that are running on high refresh rate monitors.
    So if you are on a 60hz monitor and having CPU bottlenecks, that likely won't be fixed by this.
  5. Can't really test it because I have a cheap 60Hz monitor.
  6. TheAM-Dol said:
    From my understanding, this does not improve all game performance levels. This only improves CPU utilization for games that are running on high refresh rate monitors.
    That is true.

    If a game cannot keep up with maintaining 60 fps, this optimisation will barely have any effect. It will just stop the game from wasting CPU cycles by re-rendering frames if the computer can handle much more than 60. So no game will run faster, but it might drain noticeably less battery from gaming laptops.
  7. The fps counter seems a bit broken. If you press F2 twice to see the render time, it is always 0.
  8. utunnels said:
    The fps counter seems a bit broken. If you press F2 twice to see the render time, it is always 0.
    That's the expected behaviour on a fast computer and a project without too much going on, where the render time is below 1ms. You could just be witnessing the resource conservation this plugin enables in action ;)

    Try to add some lag and see if it still stays at 0, e.g. by doing this:
    JavaScript:
    for (let i = 0; i < 40000; i++) {
        SceneManager._scene.addChild(new Sprite(ImageManager.loadBitmap("img/pictures/","test")));
    }
    Replacing test with the name of any image in your pictures folder.
  9. Ah, OK. I think ms should reflect rendering time of the frame?
    I made a very slow render function so the game runs at 30 fps, but 0 ms 99% of the time.
    1739201761758.png1739201775342.png
  10. utunnels said:
    Ah, OK. I think ms should reflect rendering time of the frame?
    I made a very slow render function so the game runs at 30 fps, but 0 ms 99% of the time.
    View attachment 331153View attachment 331154
    Oh, alright, that's definitely wrong. Are you using any other plugins? And especially ones that change SceneManager.updateMain?
  11. Not really. I only changed scene._renderWebGL to let it draw some extra things.
  12. And to be clear, those changes result in an incorrect rendering time display with this plugin, but a correct one without it?

    If you want to share a sample project that recreates this bug I'll try to take a look at it, since I do want those fixes to be compatible with everything, including strange modification to low-level rendering functions ;)

    Though, out of curiosity, why modify _renderWebGL for this instead of just adding more children to the scene?
  13. Let me see if I can make something when I have my pc again.
    As for the render function, it may not be the best place but it works. A child of the scene could also do. But I don't think they are relevant.

    Edit*
    Done
    It seems when the delay is long enough, the ms display does changes. but only for a split second, before returning to display a small value.
  14. I don't get the MS part as I think its for MilliSeconds, which are 0 if
    it runs 30/60 fps and if lower, it increases?

    or does it have another meaning in running the game?
  15. Version 1.1 is now available

    Bugfixes
    :
    - Fixed the FPS counter incorrectly counting time in the renderScene step. Thanks to @utunnels for reporting!

    Compatibility:
    - Added compatibility with Chau_SceneStabilizer

    utunnels said:
    Done
    Thanks for making the demo, the problem was absolutely on my end. It should be fixed now!

    And you had some really good timing, because I just found another, unrelated issue with Chau_SceneStabilizer, so I was able to bundle both in the update.

    ShadowDragon said:
    I don't get the MS part as I think its for MilliSeconds, which are 0 if
    it runs 30/60 fps and if lower, it increases?
    It does indeed stand for milliseconds, specifically the average amount of milliseconds it took to render a frame - it's quite a useful metric to measure lag even when your game runs at an even 60 fps.
    They were 0 because of a bug - they should have been higher.
  16. @WinterDepression don't use GraphicRenderFix as it is included in his plugin.
    as for the FixImageLoading, no idea.
  17. WinterDepression said:
    Sorry if these are dumb questions
    Don't worry about it. Most people here aren't programmers, and it's not like you could tell without being one.

    GraphicsRenderFix is already included in this plugin - in fact kido0617 is the first person listed in the "Special thanks" section ;)
    So you don't really need to use it.

    FixImageLoading doesn't seem like it should cause any problems.

    In general I'm not aware of any plugins that would cause compatibility problems, except the ones listed in the "Plugin compatibility" section. Doesn't mean there definitely aren't any, but it should be rather rare.
  18. Hi ! Is it also useful in MZ ? I'm having some weird drops on some devices with my project I was wondering if this might solve this