Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brien Shrimp

Why is SDL so slow?

This topic is 5660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yikes. I wanted to try SDL (http://www.libsdl.org/). I was pointed to a set of tutorials at Cone3D: (http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/index ). And so I wrote a simple frame for SDL projects in VC++ Dot Net. Wow. All it's doing is initalizing SDL and the SDL_mixer library but when I compile and run, it's taking 100% of my cpu usage and 8 friggen megs of RAM (have an AthlonXP 1800+). I've written complete (yet simple) games with GLUT that only take 8% of my cpu time and maybe 6 MB of RAM, max. And this is without optimization. I'm either doing something wrong or SDL is far too inefficent for me to waste my time on. I'm no good at optimization yet. [edited by - Brien Shrimp on June 4, 2003 7:10:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
most games use 100% of the CPU... and most game designers want their games to use 100% CPU, this way, when the game is ready doing one thing, it starts with the next right away! if you want it to only do this and that every frame, you need to tell it to do that.... you can make "a = 1 + 1" use 100% of the CPU if you want...

Share this post


Link to post
Share on other sites
Okay, well, I''ve gotten it to be less of a resource hog by using the SDL_Delay() function. So now it pauses for about 10 ms before looping. This is probably an idiotic brute-force method, but I''m having trouble finding any resources to tell me otherwise.

I don''t want this game to run at 100%. This is going to be a 2D sprite-based game. There is no reason this should need more resources than my full 3D tank game I did with GLUT. I never needed any ''wait'' functions with GLUT. It ran render() to display and in ran render() when idle! It always did the same thing, never demanded more than 8% from my CPU.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t think you know what CPU usage means. Something will use 100% of the CPU, regardless of what it is doing, if it never yields to the operating system. As uncutno said, a=1+1 willl use the entire CPU if you don''t give the OS some time to do it''s own thing. GLUT is doing this for you, internally. You just don''t realize it because it''s all behind an API.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you need to read up on how to use the SDL thread functionality.

Share this post


Link to post
Share on other sites
I''m assuming you entered a loop that does nothing but check for an escape key press and/or a close event. If you are clearing the screen in the loop as well, it might even cause the window to appear unresponsive. This has nothing to do with SDL. Your loop is hogging the cpu and because it is using the full timeslice the OS gives it even though it doesn''t need to. That''s why your call to SDL_Delay helped. It would be even nicer to call SDL_Delay with an argument of 0ms (assuming SDL_Delay is the equivalent of Sleep). This basically yields the unused time remaining in the timeslice back to the OS. Once you have a complete game around the loop though, you''ll want to use as much of that timeslice as you can get of course

If you want to experiment, write up a quick DirectDraw windowed app (if you''re on windows), or even OpenGL (without GLUT if possible). Run the standard windows game loop (if peek message do the message stuff, else do the game loop) which does nothing but clear the screen. Try to interact with the window. You''ll see a delay everytime you try to move it or resize it. Even without the call to clear the screen you''ll see a contimuous 100% cpu usage like you are now.

Share this post


Link to post
Share on other sites
I''ve got a full Tetris game built on SDL that isn''t using more than 8% CPU while the game is running.

It isn''t placing any calls to SDL_Wait() either - though SDL_PumpEvents() might do it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!