Get monitor refresh rate as an integer?

Get help using Construct 2

Post » Fri Jan 09, 2015 11:56 am

Is it possible to get the refresh rate of the monitor?

From what I've seen C2's tick rate seems to match the monitor refresh rate.

I'm building a real-time scrolling FPS graph, and I would like the max value on the graph to be the monitor refresh rate.
Often the refresh rate will be 60, but there are also 120, and 144 Hz monitors (among others), and it would be nice if the graph could automatically adjust its max, to match the monitor refresh rate, when started.

I know I might be able to guess the refresh rate by tracking the average frame rate, but I'm hoping to avoid that kind of solution if possible.
B
27
S
18
G
8
Posts: 331
Reputation: 6,164

Post » Fri Jan 09, 2015 12:09 pm

Actually, C2 is capped at 60 FPS rendered, no matter what the power of the CPU is and what the refresh rate of the client's monitor is.

Moreover I'm afraid you don't have a definite access to the information "Monitor refresh rate" from the browser/HTML5.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Fri Jan 09, 2015 1:04 pm

Kyatric wrote:Actually, C2 is capped at 60 FPS rendered.


I read somewhere that trying to change this had catastrophic consequences, but I really wish this wasn't the case, for simpler games or, say, an editor app like mine 30 or even 15fps would be perfect. And, of course, save resources of all sorts.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Fri Jan 09, 2015 2:04 pm

Thanks for the reply @Kyatric, :)

I was afraid that the monitor refresh rate might have been hidden beyond reach from within a browser.

Hey @Somebody, you might be able to get some optimization by placing large amounts of run every tick code inside a group that runs every other tick, or every forth tick, in effect making some of the more intensive code run at around 30 to 15 fps. It would probably depend on the code though.



As for the frame cap, I may be wrong, but it looks to me like C2's frame draw rate and event sheet tick rate can both increase beyond 60 Hz, to match monitor refresh rates greater than 60 Hz. Though the monitor refresh rate must be set before the game is launched. I don't know if this is normal behavior, but it seems to work on my system pretty much the way I'd expect.

I recently reworked the movement and animation math in one of my games to make it frame rate independent, specifically so it would run correctly at both 60 Hz (for my older monitor), and 144 Hz (for my newer monitor).

Beyond 60, so far I've only tried 85, 120, and 144 Hz refresh rates, though I mainly work with C2 at 60 and 144. In each case, it seems that C2 is forced to run events and draw frames at a rate matching the monitor refresh rate.




Again, I could be misinterpreting what I'm seeing, but just now as a simple test, with my monitor set to 144 Hz, I created a sprite, gave it the "Drag and drop" behavior and then dragged it around the layout in a preview.

In the Node Webkit preview, I got a C2 frame update matching every draw update of the windows hardware mouse pointer. Albeit with a one frame delay, because it's the hardware pointer after all, but I appear to be getting 144 updates per second from C2 none the less. That is, the sprite steps exactly the same distance as the hardware pointer with every C2 frame draw. If the mouse pointer was updating at 144 Hz, and C2 was updating at 60 Hz, then the sprite would be getting updated less often, and would need to step over a larger distance to keep up with the mouse pointer.

In the Chrome preview, I got pretty much the same thing. 144 Hz.

In the Firefox preview, I got a choppy mess with very little matchup between C2 frame draws and hardware pointer updates. The frame rate repeatedly went well below 60 fps, but that's pretty much what I always get from Firefox. Maybe I have Firefox configured wrong, or maybe it just doesn't like HTML5, either way C2 seems fine on every other browser, so I don't think it's an issue with C2.



Okay, I actually just went back and added an FPS read-out to that test, via "every second, set text to 1 / dt".
Node Webkit and Chrome show an average of almost exactly 144, and Firefox is closer to 90 on average, but fluctuated wildly, going as low as 20 fps every few seconds.

On the off chance my system specs are important, I have Win 7, a pretty good Nvidia card, and variable refresh monitor with a max of 144 Hz. I can provide more detail if needed. Though other than the monitor refresh rate, I'm not sure what might be especially important.
B
27
S
18
G
8
Posts: 331
Reputation: 6,164

Post » Fri Jan 09, 2015 2:08 pm

Hey, @fisholith, interesting idea - I might look into that. Will need to see what the performance change is like, if any.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Fri Jan 09, 2015 5:44 pm

Kyatric wrote:Actually, C2 is capped at 60 FPS rendered

That's not true actually - C2 games run at the refresh rate of the display, at least in modern browsers. Also even if on some platform the game is being capped at 60 FPS, it's not C2 doing it, it's the browser engine - we've coded our engine to run at any refresh rate.

You generally can't get hardware information in a browser. Browser developers are very cagey about giving out hardware details since it improves fingerprinting on the web which has privacy implications. I don't think you actually need to get the refresh rate for what you described though - if you measure the FPS and the system is fast enough, then the FPS will report the refresh rate. You can default your graph to 60, but if the FPS goes over then set a new maximum for the graph. You could even round it up to known common refresh rates like 75, 120 etc.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Fri Jan 09, 2015 11:13 pm

Thanks for the clarification @Ashley. Good to know I had the wrong information.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Sat Jan 10, 2015 2:51 pm

Thanks for the replies everyone. :)

And thanks for the suggestion @Ashley. I'm going to try doing a kind of running average over time of the frame rate I think. When directly using 1/dt with no temporal averaging, I tend to get some sudden single-tick spikes where 1/dt = 1000+, which throws off the max frame rate a little. :)

I think as long as the game isn't running stably at a strangely low fps, it should work for guessing the monitor refresh rate decently.

Thanks again. :)
B
27
S
18
G
8
Posts: 331
Reputation: 6,164

Post » Sat Jan 10, 2015 5:50 pm

@fisholith - the system 'fps' expression is based on the number of frames over 1 second, and is probably a much less noisy measurement.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Tue May 30, 2017 4:19 am

Message: Gamingfield can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hello! I used Acer predator for gaming. This is the best gaming monitor. It's refresh rate is 144Hz which is good for gaming. It provides me amazing gaming experience. I bought this PC after viewing the reviews at https://gamingbuff.com/.
B
2
Posts: 1
Reputation: 152


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 43 guests