sketching icon indicating copy to clipboard operation
sketching copied to clipboard

Frame-rate system variable doesn't seem to do anything

Open hasn0life opened this issue 3 years ago • 5 comments

Printing the frame-rate variable always shows 10, at least on Windows. This is even the case when I try the example in the documentation.

hasn0life avatar Dec 01 '21 04:12 hasn0life

I hope the commit fixes the problem.

I am working on improving the frame rate when bitmaps are used, so I already had code for the frame rate on my local copy - it just hadn't made to to Github yet.

Currently Sketching draws everything into an off-screen bitmap and the copies the bitmap onto the screen each frame.

This makes it easy to support load-pixels, save-image and others. It's slower than drawing directly to the canvas though - so I am working having two modes a "slow" and a "fast" mode. The latter will draw to the screen directly.

In the mean time - send me a message if you see something with an unexpected low frame rate.

soegaard avatar Dec 01 '21 12:12 soegaard

Ok this fixes it for me, thank you!

But I'm gonna suggest that you don't make the frame rate an average, but give instantaneous frame times instead. This makes it easier to see hiccups, which I think is useful for performance tuning.

As far as performance, I notice the frame rate seems to hover beneath the target frame rate, even though the system is technically capable of maintaining the target frame rate. So for example, in my testing if I set a sketch to run at 30 fps, it runs around 24-26 fps pretty consistently. However if I set it to 60fps, it hovers around 43-47fps, which seems to suggest that the program is capable of maintaining a consistent 30fps possibly. This is on Windows 10.

If you want to try this yourself, my methodology is to take the little game I cloned and (after disabling the averaging on the framerate) save the frame rate of every frame into a list. Then I plot the list of frame rates with my plotting quickscript to visualize it, which I find useful.

hasn0life avatar Dec 03 '21 07:12 hasn0life

Great to hear the fix works.

Wrt using the average instead of instanteneous, I am following the lead of

https://processing.org/reference/frameRate.html

The way I use it, is simply to use text and draw the fps in the upper, left corner of the screen. It becomes very erratic unless the average is taken.

I have noticed the same phenomenon that the actual fps is lower than the intended frame rate. I am not sure why it happens. The timer code is here:

https://github.com/soegaard/sketching/blob/main/sketching-lib/sketching/gui.rkt#L333

It's a great idea to plot the fps as a function of time. I tried following the game link, but I think that repository is private, I just get a 404 page.

soegaard avatar Dec 03 '21 10:12 soegaard

I made it public now, whoops

hasn0life avatar Dec 03 '21 17:12 hasn0life

Great game! Fun and hard in true Asteroids tradition.

soegaard avatar Dec 04 '21 11:12 soegaard