Skip Navigation
How do I cap fps with SDL2 and gsync monitor?

I guess the question is straightforward. I'm creating a simple 2D game with a few animation and 30 or 60 fps are more than enough. I'd like to cap the fps to reduce power consumption on my laptop when testing my own game. I can manage that from the nvidia control panel, but I can do that from ingame code? I can see many games provide a fps cap option. How do they achieve that? Sleeping/calling Sdl_delay doesn't seem a great option and neither is active waiting while checking for passed time. Is there an hardware mechanism I can block to?

1
GRRM Confirms That He's Hasn't Worked On ASOIAF Since 2022
  • Lol, I'm not exactly a fan of the series (I only really liked the first two books) but this is ridiculous. At this point he is just trolling. I'd say I'm happy I moved on. I haven't even bought A dance with dragons because I couldn't finish the one before that as I didn't really like it. That being said, I'd like to get a conclusion to the story and I'm willing to go back to the series AFTER it's concluded (which most likely will never happen).

  • Deleted
    Why do we pretend to care about Privacy?
  • You know how they say there is a difference between what people need and what they want? This is one of those cases. We gave up privacy in exchange for convenience. E.g. Cloud storage is convenient. For files, for documents, for code. It's so convenient that apart from acting in outrage when we discover that companies are scanning our data to train AIs, among other things, we are willing to do absolute nothing. And I think that's because we fear to lose that convenience if we force a change (not that we could even if we wanted). In other words, we are getting what we pay for (which makes sense because often all those cloud services are "free").

    There is also another problem: some personal data is irrelevant to us, but it makes companies money when the data is all aggregate together. So, it's easy to let it pass (apart from some outrage) when you are informed that there is a leak and everyone can know how many hours you spend using a service. We don't feel it's very relevant. But having this kind of data about everyone can help companies to tailor their service to tske advantage of our habits, bringing THEM a lot of money. Most data they have is irrelevant for you but very relevant for companies that try to sell services.

    Ideally I'd like to get paid. I'll allow you to track me, but I get 1$ every time records on the database with my data are returned by a query. See if they like it...

  • D&D honour among thieves

    Well, I finally watched this movie yesterday, with 0 expectations and I actually enjoyed it. I'm surprised to learn it jas >90% score on Rotten Tomatoes as I wouldn't rate it that high, but I found it very compelling; I was actually looking forward to how they would come out of those bad situations this time. Characters were strangely well developed with backstory that didn't make my eyes roll. Sure, not original, but well told. I was expecting a Netflix movie type (dull and somewhat boring) and ended up with a good pic. Hoping for a sequel.

    45
    Tried Kennedy Approach for C64...

    ... and found it incredibly addicting. It's my first attempt at playing an ATC game and I keep coming back to it. I looked around for modern alternatives, but they seem a bit too complicated for my tastes. KA hits the sweet spot, because it's very simple to learn (almost "arcadey") and yet though to play. I wasn't expecting it. Was it popular back in the day?

    2
    How to conduct an effective code review
  • The things he asks to do are the reasons why I find no joy anymore working in coding. Hammering my thumbs seems to be more interesting than doing most of these actions. I swear, I got so bored I couldn't finish the read. Specifically "if you find yourself commenting on every line of code" the right thing to do is to setup a meeting with te hiring department.

  • Merge then review
  • Code review can't fix incompence though. I lost count of how many times my boss told me "review that PR well because X is not very good". Also my point is that they are overrated, not that they are useless.

  • Merge then review
  • Probably unpopular opinion, but peer reviews are overrated. If coders are good AND know the project, the only thing you can do in a PR is nitpicking. They are more useful for open source collaborators because you want to double-check their code fits with the current architecture. But people here are reacting as if peer reviews could actually spot bugs that tests can't catch. That happens rarely unless the contributor is junion/not good.

  • Deleted
    *Permanently Deleted*
  • Lol I feel so old reading these replies... I learnt copying BASIC games from magazines and typing them manually on the computer.

    But jokes apart, when it comes to learning, I think the best thing is to tinker with weather language you choose and don't worry about making the "right choices" since the start. Forget about writing "pythonic" code and don't worry about being "idiomatic": just build something. Building good software is not just constructs, but also knowning which subsystem to improve and when. That's what makes experience.

    When it comes to improving, you can dig deep into the language.

  • Don't write Rust like it's Java
  • Sometimes I wonder if this pure search for being "idiomatic" is worth the effort. On paper yes, more idiomatic code is almost always a good thing, it feels more natural to create code in a way the language was designed to be used. But it practice, you don't get any points for being more idiomatic and your code isn't necessarily going to be safer either (smart pointers are often "good enough"). I'm fine using references to pass parameters to function and I love the idea to "force" the programmer to organize objects in a tree way (funny enough I was already doing that in C++), but I'll take a Rc rather than a lifetimed reference as a field in a structure any day. That shit becomes unreadable fast!

    EDIT: but I love cargo clippy! It tells me what to change to get more idiomatic points. Who knows why an if/then/else is better than a match for two values, but clippy says so, and who am I to question the idiomatic gods?

  • Let's talk about Zig

    I have been reading about this new language for a while. It's a C competitor, very slim language with very interesting choices, like supporting cross platform compilation out of the box, supports compiling C/C++ code (and can be used as a drop in replacement for C) to the point in can be used as replacement of (c)make and executables are very small.

    But, like all languages, adoption is what makes the difference. And we don't know how it goes.

    Is anyone actually using Zig right now? Any thoughts?

    40
    InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)BL
    Blackthorn @programming.dev
    Posts 4
    Comments 34