Tips / Tricks for silky-smooth 60fps

Monkey Targets Forums/Desktop/Tips / Tricks for silky-smooth 60fps

Nobuyuki(Posted 2015) [#1]
Hey!

I'm starting a new project for Desktop, and while likely going to be mojo1 for compatibility purposes (probably because mojo2 won't have Spine bindings for a while), I noticed that even with small demos, I'm often getting a lot of hiccupping which is causing SwapRate 1 projects to dip below the 60fps threshold. In previous projects, this wasn't a big deal, since I was doing puzzle games and other casual games which didn't require a "perfect" 60fps, but now it's starting to get under my skin a bit, and I'd like to know what you guys have done to get around this.

I've heard that the bmax and xna targets don't have these issues, but I'm not willing to switch to these. I am however, willing to entertain switching to mojo2 + angle, if it's been shown to really provide that reliability boost I'm looking for.

I don't believe I'm smashing up the GC much, but I don't have any experience with app profiling (particularly C++), so I can't say for sure if I'm doing something that's constantly irritating GC. But, for argument purposes, let's pretend that I'm not doing this and taking "optimize your code to use the GC less" off the table. What other ways have you guys been able to achieve a stable 60fps in Monkey without the hiccups which seem to plague GLFW / Android projects? Will switching to Angle as a target help? Is trying to aim for SwapRate 1 with uncapped UpdateRate generally a bad idea? Do other targets have these same hiccups?


ImmutableOctet(SKNG)(Posted 2015) [#2]
It might just be the GC, because even with my own delta-timing module, it's hard to get it to stutter.

I put this together when Mojo 2 came out (Modified, so my 'deltatime' module is optional):

Tested with both the GLFW3 and GLFW+ANGLE targets.

It's smooth for me. The only time it isn't is when using a high frame-average with my 'deltatime' module, or when the framerate is uncapped without it (Tearing). Press space to toggle the frame-cap.


Nobuyuki(Posted 2015) [#3]
Did you get a lot of hiccups for similar code on glfw3 when using mojo1? Hmm,.... I'm getting some stuttering on this app too for some reason, I wonder if it's related to my setup

Edit 2: I need your DeltaTime class to compile it with the delta time enabled !


ImmutableOctet(SKNG)(Posted 2015) [#4]
Just enable 'SMOOTHNESS_DEMO_DELTATIME' at the top, and you can grab this.


GC-Martijn(Posted 2015) [#5]
In mojo1 i'm using only one global variable and that is [dt] and use that with every movement.
(Speed * dt.delta)

I test this code using mojo2 and the one above in this forum and both don't give me a super smooth movement.
There are very small stotter in the rects.

Using GLFW3, OSX, Monkey 84c, NVIDIA Quadro 2000 (must be able to show this simple thing smoothly)

@ImmutableOctet(SKNG)
Don't you see non stottering, and a super smooth movement (after pressing space) ?



co



EDIT:
Its hard to see on a video, but you can see it maybe.
https://youtu.be/FA-_tqHWYsU
(and you can see a little gab at the top, between to rects)

but again, a video is not the best way to show the problem

EDIT2:
OMG, I thought I did know how to handle the basic game principles.
Stuttinger is not done, so after searching this forum, I found this topic.
http://www.monkey-x.com/Community/posts.php?topic=1436&page=-
With ends with:
"The bottom line is this: if you want to lock to the frame, you are best advised to perform your game update in the OnRender."


So I place everything inside the onRender() and what do you think...
Super smooth !

But now i'm wondering, what I have been learned/read to put everything in the update is wrong. Or maybe not necessary, in this case it gaves me very smooth graphics.

But how much can you put in the onRender only, without using OnUpdate() ?
Everything ?

This is a very interesting point for me, maybe someone can give some extra info about this topic.




ImmutableOctet(SKNG)(Posted 2015) [#6]
It really depends on the setup, I guess. If I press space, I do get the stuttering, as it's tearing/inconsistent with the delta-timing. If it's just running normally, I get perfect results. I'm really not sure if Mojo 1 would be any different; I could run some tests, I guess. Either way, using a global variable makes effectively no difference.

Here's what I get with GLFW+ANGLE on Windows (Delta-timing on): https://www.youtube.com/watch?v=EwcqzBCow5E (Video's currently processing; not sure if 60FPS will work)

I get the same results with normal GLFW3, from what I can tell. As I said, it does get inconsistent with higher framerates, though. That's partially my demo's configuration, though.

Basic System Information:
CPU: AMD Phenom II X4 820
GPU: AMD Radeon HD 6950
OS: Windows 8.1 (x64)


GC-Martijn(Posted 2015) [#7]
@ImmutableOctet(SKNG)
See my edit one topic above yours, its very super smooth now.
But gives more questions than answers haha.


ImmutableOctet(SKNG)(Posted 2015) [#8]
You're supposed to update everything in 'OnUpdate', but delta-timing might be interesting to try in 'OnRender'. The fact is, the operating system and driver usually dictate when 'OnRender' is called, so it can be called at any point. For this reason, updating in 'OnRender' is discouraged.


GC-Martijn(Posted 2015) [#9]
I'm now testing several things using OnRender() OnUpdate() SetUpdateRate() DeltaTimer

I thought you did set SetUpdateRate(60), I din't know about SetUpdateRate(0) because the documentation says:
This is the number of times per second that the application's OnUpdate method should be called. Commonly used update rates are 15, 30 or 60 updates per second.

OnRender is also called at the same frequency if possible (after each OnUpdate), meaning SetUpdateRate effectively also sets the target frames per second.

But don't say it could be 0.
http://www.monkey-x.com/Community/posts.php?topic=8156


Slight stutter


stuttering


super smooth


very slight stuttering


Super smooth


So put the delta inside the onRender() and use SetUpdateRate(0)
This is the Glfw3 target and I don't know how other targets will handle this.

Final test code



Nobuyuki(Posted 2015) [#10]
@ImmutableOctet(SKNG): thanks a bunch. I'm starting to believe that Firefox and Jungle maxing out my primary CPU core is the reason for the large amount of hiccups I'm seeing in my monkey builds; as everything seems to run smooth until loading up all of my "usual applications" (I haven't thoroughly tested to see if the problem persists, but I just wanted to point out that there doesn't seem to be any problem with the code you posted.) I feel like there might be some "fragility" either in my system or in the way Monkey games work, or possibly how we expect them to work given the usual coding patterns, but I'm still unsure as to which of these it is (although I believe my system's the most significant factor here, despite it being new).

CPU: Core i3-4360
GPU: NVidia GTX 750
OS: Windows 8.1 u1 (x64)


@GC-Martijn: Please consider using [codebox] instead of [code] for posting long blocks of code; it takes up far less space and makes it easier to skim a thread -- I'd love to dig into your post but I find myself being distracted by the very large code blocks...


GC-Martijn(Posted 2015) [#11]
updated the topics.
the last code gives me at the moment the best results.