Jump to content
  • Advertisement

Archived

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

Pegu

SDL eats too much resources (problems with mouse solved) check the 3rd message.

This topic is 6013 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

Hello. I've encountered a strange problem in SDL. I will post some simplified info on how my game works:
Uint8 buttons;
buttons = SDL_GetMouseState(NULL, NULL);

// This works, I've tested it, and it works perfectly
if (buttons == SDL_BUTTON_LEFT)
{
    PlaceABlockOnScreen();
}

// Later on, I wanted to add the feature to discard the block
// with right mouse button. I encounter problems here...
if (buttons == SDL_BUTTON_RIGHT)
{
    DiscardTheBlock();
}
   
The game wont recognize it, if I press the right mouse button. It just simply wont discard the block. I tried to change the buttons, so that the left button will discard and right will place. Okay, the left button discards the block. Good. But right mouse button wont place the damned block ! It just wont work. I tried with a different mouse, and it still wouldn't work. Does someone have a piece of code that does the thing that I want to archieve ? Please help me... this feature is for my game, and it would be good if this feature would be implemented (16 hours more to go...) [advertisement] Check out my game (it's my first game, so don't laugh at it): My homepage [/advertisement] [edited by - Pegu on May 29, 2002 4:01:55 PM] [edited by - Pegu on May 29, 2002 4:03:38 PM]

Share this post


Link to post
Share on other sites
Advertisement
This is how I handle the same thing


  
bool CInput::MouseButtonPressed(Sint16 Button)
{
if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(Button))
return(true); // Mouse button is down

else
return(false); // Mouse button is not down

}


with these as the mouse keys


  
#define MOUSELEFT 1
#define MOUSEMIDDLE 2
#define MOUSERIGHT 3
#define MOUSEROLLERBALLUP 4
#define MOUSEROLLERBALLDOWN 5




Ballistic Programs

Share this post


Link to post
Share on other sites
It works, it works !
Thanks man. Gamedev.net saves again.

Btw, do you have any idea, why my game (should be just a normal SDL application...) takes 100% of CPU speed ? My friend has somekind of a program that shows the current usage of system resources...

Some person also told me, that it actually slows down his other applications, which are running at the moment.

Is there any way to reduce the usage of CPU, or is it just Windows... ?

Share this post


Link to post
Share on other sites
SDL shouldn''t eat into your CPU like that, have you checked your main game loop, to make sure you arn''t flipping your buffer more tha once or somethig silly that that? Also did you compile the exe in visual c++? If so did you set it to release version?

Ballistic Programs

Share this post


Link to post
Share on other sites
quote:
Original post by Drazgal
SDL shouldn''t eat into your CPU like that, have you checked your main game loop, to make sure you arn''t flipping your buffer more tha once or somethig silly that that? Also did you compile the exe in visual c++? If so did you set it to release version?



I use Dev-C++, and it doesn''t generate debug info, or anything like that. I will check the flippings, thanks for the idea

Will post results soon.

Share this post


Link to post
Share on other sites
The "100% CPU Usage" thing is quite common (at least in Windows). Put a delay at the end of your game loop for the smallest amount of time that''s possible. SDL_Delay only goes down to milliseconds, so that''d be 1ms.

Share this post


Link to post
Share on other sites
quote:
Original post by Pegu
I use Dev-C++, and it doesn''t generate debug info, or anything like that.

It can, but it doesn''t by default. I don''t know if you get the debug tools with Dev C++ or if you need the entire Cygwin environment, but if you compile with -ggdb (in GCC, which is what Dev C++ uses) you can use gdb to debug the applications. There''s a graphical version of gdb called xxgdb for X11, but I don''t know if you can get a graphical version that runs in Windows.

Share this post


Link to post
Share on other sites
There is a graphical debugger for dev C++ in windows, I don''t know what it''s called but you can download it at the dev C++ site (or the resource site)

go here

Share this post


Link to post
Share on other sites
Hmm... it still uses too much CPU...
Basically using the SDL_Delay is limiting the FPS, right ? So I perhaps should make a thing, that limits the FPS to 30 or something...

This is a puzzlegame, so even FPS of 10 would be good

Share this post


Link to post
Share on other sites
quote:
Original post by Pegu
Basically using the SDL_Delay is limiting the FPS, right?

Yes and no. We''re only doing it so that other processes have more chances to get their turn on the CPU. You may want to do this instead:

#ifdef _WIN32
Sleep(0);
#endif

I''m very sure that should work (SDL_Delay may be using the performance timer, which wouldn''t help much).
quote:
Original post by Pegu
So I perhaps should make a thing, that limits the FPS to 30 or something...

There''s _no_ reason to do that.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!