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

Settings: add FPS cap #532

Merged
merged 15 commits into from
Jul 1, 2024
Merged

Conversation

archbirdplus
Copy link
Contributor

@archbirdplus archbirdplus commented Jun 28, 2024

Adds fpsCap field which lets Cubyz sleep if it processes the frame fast enough. On lower end hardware, this would let Cubyz deliver a more consistent framerate, albeit lower.

  • settings.json option
  • in-game menu slider
  • update physics to use real time, not rendering time
  • update fps label in debug window to count actual frames, not inverse rendering time
  • update fps label to use real time between frames, not rendering time

Resolves #487.

@archbirdplus
Copy link
Contributor Author

Actually, I would group point 4 along with #438.

src/main.zig Outdated Show resolved Hide resolved
@archbirdplus archbirdplus marked this pull request as ready for review June 29, 2024 22:10
@archbirdplus
Copy link
Contributor Author

Sliders are bugged for me in general. We might want to round the fps from the slider because people probably usually just want to reset it to 60 fps without a hassle. On the other hand, some people prefer to set their framerate just under the refresh rate for some reason, so I'm not sure which is a priority.

@IntegratedQuantum
Copy link
Member

You could also make it a text field. Then players could be arbitrarily precise.

@IntegratedQuantum
Copy link
Member

It crashes when I move the slider to the end:

Segmentation fault at address 0x1211879
/home/mint/Cubyz/compiler/zig/lib/compiler_rt/memset.zig:19:14: 0x17fb1d0 in memset (compiler_rt)
            d[0] = c;
             ^
/home/mint/Cubyz/compiler/zig/lib/std/mem/Allocator.zig:313:26: 0x137d134 in free__anon_31205 (Cubyzig)
    @memset(non_const_ptr[0..bytes_len], undefined);
                         ^
/home/mint/Downloads/Cubyz/src/utils.zig:749:22: 0x134c6de in free__anon_29033 (Cubyzig)
  self.allocator.free(memory);
                     ^
/home/mint/Downloads/Cubyz/src/gui/components/ContinuousSlider.zig:91:27: 0x14a39db in updateLabel (Cubyzig)
 main.globalAllocator.free(self.currentText);
                          ^
/home/mint/Downloads/Cubyz/src/gui/components/ContinuousSlider.zig:104:19: 0x14ef408 in updateValueFromButtonPos (Cubyzig)
  self.updateLabel(value, self.size[0]);
                  ^
/home/mint/Downloads/Cubyz/src/gui/components/ContinuousSlider.zig:142:32: 0x14814d4 in render (Cubyzig)
  self.updateValueFromButtonPos();
                               ^
/home/mint/Downloads/Cubyz/src/gui/gui_component.zig:102:17: 0x13f98b8 in render (Cubyzig)
     impl.render(mousePosition);
                ^
/home/mint/Downloads/Cubyz/src/gui/components/VerticalList.zig:141:15: 0x1481c9c in render (Cubyzig)
  child.render(mousePosition - shiftedPos);
              ^
/home/mint/Downloads/Cubyz/src/gui/gui_component.zig:102:17: 0x13f9930 in render (Cubyzig)
     impl.render(mousePosition);
                ^
/home/mint/Downloads/Cubyz/src/gui/GuiWindow.zig:467:19: 0x1361148 in render (Cubyzig)
  component.render((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
                  ^
/home/mint/Downloads/Cubyz/src/gui/gui.zig:539:16: 0x1327fd0 in updateAndRenderGui (Cubyzig)
  window.render(mousePos);
               ^
/home/mint/Downloads/Cubyz/src/main.zig:486:26: 0x131e8eb in main (Cubyzig)
   gui.updateAndRenderGui();
                         ^
/home/mint/Cubyz/compiler/zig/lib/std/start.zig:514:22: 0x131db19 in main (Cubyzig)
            root.main();
                     ^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7f01d253ed8f in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:392:3: 0x7f01d253ee3f in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x131d7c4 in ??? (???)
???:?:?: 0x0 in ??? (???)

I'm guess this happens because you return a global string from your format function, which gets freed later.

@archbirdplus
Copy link
Contributor Author

Does it crash in release mode for you?

@IntegratedQuantum
Copy link
Member

It not crash in ReleaseFast, but it does crash in ReleaseSafe.

@archbirdplus
Copy link
Contributor Author

Zig no longer reports memory issues, but I don't think I accomplished that in the cleanest way.

@IntegratedQuantum
Copy link
Member

Could you also fix the merge conflicts?

@archbirdplus
Copy link
Contributor Author

Fixed.

@IntegratedQuantum IntegratedQuantum merged commit ad9cad6 into PixelGuys:master Jul 1, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

Allow setting Max FPS value
2 participants