Cubyz icon indicating copy to clipboard operation
Cubyz copied to clipboard

Settings: add FPS cap

Open archbirdplus opened this issue 1 year ago • 7 comments

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.

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

Resolves #487.

archbirdplus avatar Jun 28 '24 22:06 archbirdplus

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

archbirdplus avatar Jun 29 '24 02:06 archbirdplus

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.

archbirdplus avatar Jun 29 '24 22:06 archbirdplus

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

IntegratedQuantum avatar Jun 30 '24 08:06 IntegratedQuantum

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.

IntegratedQuantum avatar Jun 30 '24 20:06 IntegratedQuantum

Does it crash in release mode for you?

archbirdplus avatar Jun 30 '24 20:06 archbirdplus

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

IntegratedQuantum avatar Jun 30 '24 20:06 IntegratedQuantum

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

archbirdplus avatar Jun 30 '24 21:06 archbirdplus

Could you also fix the merge conflicts?

IntegratedQuantum avatar Jul 01 '24 09:07 IntegratedQuantum

Fixed.

archbirdplus avatar Jul 01 '24 09:07 archbirdplus