FluidTimestep -- Fix the game speed

Discussion in 'JS Plugin Releases (RMMV)' started by Galenmereth, Nov 17, 2015.

    Tags:
  1. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A

    [​IMG]




    Important: if you're using MV 1.1.0 or newer, you don't need this plugin




    Introduction


    Makes the game run at normal speed (animation, movement, and anything else) regardless of framerate. By default, MV run on a 144hz monitor would run at 144fps and everything would move at 2,4 times normal speed. Likewise, if someone ran the game and only managed 30fps, everything would move at half normal speed.


     


    While simply limiting the framerate to 60 is one solution, it wouldn’t solve the problem where a player getting sub-60 frames per second would experience the game’s speed being slower than normal. At 30fps, the game would move at half normal speed. The solution used in this plugin makes it so logic updates in the engine always occur at the rate of 60 times per second, while the display gets updated as fast as the user’s device can handle it.


     


    Inspired by http://gafferongames.com/game-physics/fix-your-timestep/

    Before asking for help, please read the documentation page to see if it might already be covered there. That page will be updated over time and always be the most current documentation available for the plugin.


    Latest version


    1.0.2 - 2015-11-22


    Features

    • Visual frame updates are independent of logic updates so that movement, animations, and all other gameplay elements move at the normal speed regardless of the device frame rate.

    How to use


    Add the plugin to your game and check the parameter settings for help. The Help section contains general information and a link the plugin's documentation page.


    Documentation


    Official documentation page


    Download


    GitHub (if you're using MV 1.1.0 or newer, you don't need this plugin)


    Dependencies


    None


    FAQ


    No items yet


    Credit


    Tor Damian Design


    Terms of use


    Free for non-commercial and commercial use. See terms of use for the full terms.
     
    Last edited by a moderator: Mar 3, 2016
    #1
    Kike, Marsigne, Harken_W and 33 others like this.
  2. Prescott

    Prescott riju Veteran

    Messages:
    401
    Likes Received:
    178
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Wow, this is super helpful, and really makes the game playable on a wide variety of systems. I can't tell you how much I hate it when games run at 40 fps that are supposed to go 60 and everything is just super slow, while other 30 fps games look much smoother.

    Thanks for this, very much!
     
    #2
    Galenmereth likes this.
  3. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    I have to mention that someone playing the game at 30fps would naturally get some "stuttering" visually, as that's what a lower fps would do. But it should be significantly less of a problem than running the game at half game speed :p

    A few nice benefits I've noticed so far from running the game at a higher framerate using this:

    • The mouse feels more responsive since its visual position keeps getting updated every frame update
    • Drag and drop in my game is even smoother, because despite the logic and input only updating 60 times per second, visually it gets to catch up at double the speed.
    • Overall it looks smoother visually, since it gets updated at my display's nature refresh rate visually.
     
    #3
  4. Roguedeus

    Roguedeus Veteran Veteran

    Messages:
    505
    Likes Received:
    103
    First Language:
    English
    This combined with masked's Smooth Scroll plugin can do wonders for quality of game play.

    Thanks for this!
     
    #4
    Galenmereth likes this.
  5. fallenlorelei

    fallenlorelei Veteran Veteran

    Messages:
    246
    Likes Received:
    266
    First Language:
    English
    Omgosh!

    Thank you x100!

    I made my game on a 144hz monitor and didn't realize the fast rates was a *thing.* I thought it was a quirk of the program! So I had slowed ALL of my events down to like x4 slower just so they would look normal. For conversations, I had to wait "Wait 120 frame" commands so it went at an average pace. Then when I finally uploaded my first draft and tried it out on my work computer, holy crap. Everything was so slow, it was ridiculous. Needless to say I was upset and frustrated that I thought I had a decent game ready for the public, but instead had to go back, edit all of my events and movement speeds, and "guess" what a normal speed was.

    Rant aside. This is amazing. Thanks again. =]
     
    #5
    Prescott and Galenmereth like this.
  6. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    835
    First Language:
    German
    How would you know that 1 iteration of your while-loop lasts exactly 1/60s?


    /edit: Just read the linked article. Funny enough, i remember reading that some time ago, but forgot about it.
     
    Last edited by a moderator: Nov 17, 2015
    #6
  7. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    @Iavra: While the accumulator var is greater than the delta time var, it'll run logic updates until that is no longer true. The accumulator is increased every visual frame update by the time in milliseconds since the last update, while the delta time is set to 1.0 / 60.0, i.e. 1/60th of a second. This means that if your framerate is faster than 60fps, it will skip doing logic updates until the accumulator has time to build up to the delta time, hindering logic updates happening too fast. Reversely, if the framerate is below 60fps, it will run the logic updates multiple times per frame update to "keep up" logic-wise. Thus both 30fps and 120fps make the characters move the same number of pixels over the same time, but the smoothness of the motion will vary. This is generally the optimal solution since framerate won't impede gameplay.

    Some additional info for the curious:

    The reason the delta time is set to 1.0 / 60.0 is that everything in MV is pretty much hardcoded around the assumption that 60 updates should happen per second. Thus we lock our game logic to that, while we let the frame update run free. Now optimally we would take time and delta time into consideration in all things that move and animate in MV; if we did we could minimize jittering on "awkward" framerates by having movement and positional logic take the time and delta time into consideration. We could even implement alpha difference to "smooth" the awkward in-between positional updates. But this would require us to alter so many of the fundamental objects in MV that plugin compatibility would go down the drain.

    So what you may notice is that sometimes on some framerates there appears to be a tiny bit of visual jitter when moving here and there. It very rarely occurs intermittently on my 120hz refresh rate too, and I noticed it on 144hz a bit more. This is because sometimes we end up with logic updates and screen updates that don't play too well together to be 100% smooth, but the only way to solve it would be to rewrite pretty much all the movement logic in the engine, and I don't think it's worth it. A miniscule occasional visual jitter is still better than the default behavior, I'd say :)  And for anyone on a 60hz monitor running the game at 60fps, nothing should look different whatsoever.
     
    Last edited by a moderator: Nov 17, 2015
    #7
  8. Iavra

    Iavra Veteran Veteran

    Messages:
    1,797
    Likes Received:
    835
    First Language:
    German
    Yeah, i know. I missed the part where you calculated the time used by the last frame.
     
    #8
  9. tsunetakaryu

    tsunetakaryu Veteran Veteran

    Messages:
    40
    Likes Received:
    25
    First Language:
    Chinese
    Mate, I found a minor bug with this plugin enabled, while I press F9 or use the main menu ( or any other way ) to call the debug scene, sometimes the game will be freeze. 
     
    #9
  10. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    Version updated from 1.0.0 to 1.0.1

    Changes:

    • Bugfix: Moved changeScene call to after updateInputData for some scene boot crashes for the debug scene. Should fix other similarly structured scenes too.
    Thanks to @tsunetakaryu for reporting this bug.

    Please see the documentation page for the full changelog.
     
    Last edited by a moderator: Nov 18, 2015
    #10
  11. tsunetakaryu

    tsunetakaryu Veteran Veteran

    Messages:
    40
    Likes Received:
    25
    First Language:
    Chinese
    yep, no freezing anymore. Thanks! 
     
    #11
  12. orlando

    orlando Veteran Veteran

    Messages:
    174
    Likes Received:
    79
    Just a small enhancement idea: you should probably use

    performance.now() / 1000.0(that also results in milliseconds) rather than
    Code:
    Date.now()
    .
    The reasons are that 1. the time reported by performance.now() is more accurate 2. Date.now can jump if system time is changed by the user, in which case your code will be eternally confused - performance.now on the other hand is guaranteed to be monotonic and won't jump around even if system time is altered while the game is running.
     
    Last edited by a moderator: Nov 23, 2015
    #12
  13. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    Version updated to 1.0.2

    Changes:

    • Using performance.now() rather than Date.now() for more reliable highres timestamps.
    Thanks to @blubberblubb for the post on this.

    Please see the documentation page for the full changelog.
     
    #13
  14. jackseg

    jackseg Villager Member

    Messages:
    22
    Likes Received:
    5
    Location:
    Switzerland
    First Language:
    French
    Hello,

    I don't understand, don't work for me.

    I use now FPSLimit.js for 60fps, it work but I want test your plugin  ;_;

    We must do something special?

    I have 120Hz screen.

    Thanks.
     
    #14
  15. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    Disable FPSLimit plugin :)
     
    #15
  16. jackseg

    jackseg Villager Member

    Messages:
    22
    Likes Received:
    5
    Location:
    Switzerland
    First Language:
    French
    I may be stupid but not at this level  ;)
    FPSLimit is disable when I test your plugin.

    [​IMG]
     
    Last edited by a moderator: Nov 23, 2015
    #16
  17. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    What happens when you playtest? Does the game still run too fast? If so, does it help if you place TDDP_FluidTimestep at the very end of the plugin list?
     
    #17
  18. jackseg

    jackseg Villager Member

    Messages:
    22
    Likes Received:
    5
    Location:
    Switzerland
    First Language:
    French
    You have right, I'm stupid  ;_;

    The speed is good. I was wrong because with F2, it still shows allways 120FPS and not 60, but in play you feel the difference.

    Thanks for your help.
     
    #18
  19. Galenmereth

    Galenmereth Not so Grump Veteran

    Messages:
    2,171
    Likes Received:
    1,718
    Location:
    Norway
    First Language:
    English
    Primarily Uses:
    N/A
    That's good to hear though, then it works perfectly :D
     
    #19
  20. jackseg

    jackseg Villager Member

    Messages:
    22
    Likes Received:
    5
    Location:
    Switzerland
    First Language:
    French
    So it's normal not to display 60fps with F2 key ?
     
    #20

Share This Page