Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL - CPU usage


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Vexorian   Members   -  Reputation: 152

Like
0Likes
Like

Posted 25 November 2005 - 12:53 AM

I was testing my just converted SDL game, well after all the work the game works correctly, the problem is that if you switch to other app that app freezes/becomes horribly slow. I succesfully disabled the game loop for non active times, but the problem is still there, so I am sure that it is nothing on the game itself but something related with SDL perhaps PollEvent doesn't sleep or something? Any way to fix this? Edit: Wait a second It was my mistake Edit 2: Just in case any body finds it useful in the future:
while (!done)
    {
        // message processing loop
        while (SDL_PollEvent(&event)) //Poll event doesn't sleep by itself
        {
            ....
        }
        SDL_Delay(10); //Makes it sleep for a small time
    }



Edit 2: There is a major improvement if you increase the delay to 1000 during app inactivity [Edited by - Vexorian on November 25, 2005 7:09:35 AM]

Sponsor:

#2 Gorg   Members   -  Reputation: 248

Like
0Likes
Like

Posted 30 November 2005 - 09:36 AM

You want SDL_WaitEvent in your pause loop.


SDL_pollevent is there so you can check if there is something in the event queue and do something else than event handling if there are none.

#3 Spippo   Members   -  Reputation: 158

Like
0Likes
Like

Posted 30 November 2005 - 11:58 PM

I think there is a small problem in your solution:

If you use SDL_Delay(1000);
It will wait sometime before it checks again to see if an event happend. But the whole program/game will wait for that amount of time, so you get a lower framerate.

Or am I wrong?

#4 Kylotan   Moderators   -  Reputation: 3338

Like
0Likes
Like

Posted 01 December 2005 - 01:28 AM

You're right. Every frame will take a second, but he did say 'during inactivity'.

Generally using 100% CPU for a game is not a problem. But depending on the kind of game, you might want to get around this, either by pausing the game completely - especially when it's not focused, or perhaps using SDL_Delay(0) (which should work ok on Windows, at least).

#5 Vexorian   Members   -  Reputation: 152

Like
0Likes
Like

Posted 02 December 2005 - 02:30 AM

Quote:
Original post by Spippo
I think there is a small problem in your solution:

If you use SDL_Delay(1000);
It will wait sometime before it checks again to see if an event happend. But the whole program/game will wait for that amount of time, so you get a lower framerate.

Or am I wrong?


It was rather:


st=SDL_GetAppState();
if ((st==SDL_APPACTIVE) || (! st) ) SDL_Delay(1000)
else SDL_Delay(0)
PollEvents...
...


...



And so and so, it only waited for 1 second when the app was not active.

I am gonna try the WaitEvent thing. SDL_Delay(0) didn't help a lot other graphic apps were (kind-of) freezing anyways. The thing was only fixed correctly after the 1000 thing, although when focus was back on the application next frame took some time
------ XYE - A new edition of the classic Kye

#6 steffenomak   Members   -  Reputation: 100

Like
0Likes
Like

Posted 12 March 2010 - 02:20 AM

Oh, this helped me, thank you , when I tried whit a normal window, the window used a 100% on one core, but when i added SDL_Delay( 0 ); it made the load go down to 0% when nothing happaned.

#7 TheBuzzSaw   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 March 2010 - 08:53 AM

I use SDL_Delay(1) in my program. What is the fundamental difference between that at SDL_Delay(0)?

#8 rip-off   Moderators   -  Reputation: 8165

Like
0Likes
Like

Posted 13 March 2010 - 09:07 AM

Quote:
Original post by TheBuzzSaw
I use SDL_Delay(1) in my program. What is the fundamental difference between that at SDL_Delay(0)?


I believe that on some implementations of SDL, SDL_Delay(0) may return immediately, whereas SDL_Delay(1) will always sleep for some period (generally a timeslice, which could have a granularity of 10 milliseconds for example on Windows).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS