Added: 8 months ago
From: thecplusplusguy
Views: 1,287
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (13)

Sign In or Sign Up now to post a comment!
  • I understand everything, but I don't know whu you do: 1000/FPS ??

    I think I got it but...

  • @linuxandunix4ever

    I calculate, how many milliseconds needed for 1 frame, there are 1000 miliseconds (ms) in a second, and we need to render FPS (for example 100) frames in this time, that's mean, that we need to render a frame every 1000/100=10ms. then I check, how much time already spend, while rendering the frame, for example, it needed 6ms, so we need to wait 4 more ms, to keep up the 100FPS (so every frame will take 10ms, so 1000/10=100FPS)

  • trying it now

  • Arigatou - works pretty well. My game now uses 15% CPU

  • Works really well, before the fps regulating code this program would run a thread on my processor to the max(25%), and with it keeps at 0% cuz of no rendering being done. and I don't have a weak poc: AMD phenom II x4 955 BE

  • I'm with MrKonnorsniper, these are great

  • Thanks

  • Thank you for making these videos! I'm trying to get into graphics api's and I'm having a hard time. Your programs actually compile, unlike a lot of other online tutorials! Keep up the great work! Subscribed

  • while((SDL_GetTicks() - start) < 33);

    this is more easier

  • @Hyrppa95

    Maybe it seems easier, but it will run your CPU at 100%, but the way i showed in this video (so the SDL_Delay) will actually wait without use the CPU (so it will stop the program for the amount of time, we gave to the SDL_Delay, so the OS can care other programs for that time). So yes, it's work, but it's not the best way, if every program would do that your CPU usage would be 100% all time.

    The other thing, you should use constants, it's not really matter in this program, but later..

  • @thecplusplusguy

    Hey man great tutorials, just out of interest would this work:

    if(1000/FPS>SDL_GetTicks()

    {

    SDL_Delay(1000/FPS - SDL-GetTicks());

    start = 0;

    }

    If it doesnt, why wouldnt it?

    Great Tutorials!

  • @viral262

    Hey, Thanks.

    No it wouldn't work, because the SDL_GetTicks() gets the time in millisecond, but not the time elapsed from the last frame, for example, in the first frame it's 30 and then 60,90... it will increasing, so the (1000/FPS>SDL_GetTicks() would only true for some cases, becase the 1000/FPS is always 33.3, but the SDL_GetTicks will always gets bigger.

    To get the time of this frame I subtract the starttime from the endtime. (+2 syntactic error: ) in the 1. line, _ in the 2 line)

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more