Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hasn0life opened this issue Dec 1, 2021 · 5 comments
Open

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

hasn0life opened this issue Dec 1, 2021 · 5 comments

Comments

@hasn0life
Copy link
Contributor

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.

soegaard added a commit that referenced this issue Dec 1, 2021
Calculate actual framerate, so referencing `frame-rate` works.
This fixes issue #28 .
@soegaard
Copy link
Owner

soegaard commented Dec 1, 2021

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.

@hasn0life
Copy link
Contributor Author

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.

@soegaard
Copy link
Owner

soegaard commented Dec 3, 2021

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.

@hasn0life
Copy link
Contributor Author

I made it public now, whoops

@soegaard
Copy link
Owner

soegaard commented Dec 4, 2021

Great game! Fun and hard in true Asteroids tradition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants