Jump to content
  • Advertisement
Sign in to follow this  
linek98

Mouse motion event slows down the game

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

Just as title says I'm using:
while (SDL_Poll(event)
{
   HandleEvent(event);
}
Well everything is good until mouse motion event appears. Till I dont move my mouse processor usage is 0-5% and when I start to move mouse over the application window it's 25% and lags are clearly visible. I tried something like this but didn't work:
while (SDL_Poll(event)
{
   if (event.type == SDL_MOUSEMOTION)
      continue;
   HandleEvent(event);
}
Well, it skips but doesn't change processor usage anyway. Any suggestions how can I get rid of it? EDIT: Forgot to mention. It's SDL + OpenGL graphic render.

Share this post


Link to post
Share on other sites
Advertisement
What exactly is your mouse handling doing? And what are you doing outside of that while loop? If you have 0% CPU time that implies that you just call sleep() a lot or something like that. If so, it's not surprising that mouse motion increases your CPU usage since the application actually starts having to do something, as opposed to nothing.

Share this post


Link to post
Share on other sites
Sorry, forgot to add 1 thing. When I just comment all the code and just leave while loop it does exactly the same. Also if I add SDL_Delay(10) I cant't do anything while moving mouse in application window. I mean it looks like it doesn't handle any inputs just mouse motion.

Share this post


Link to post
Share on other sites
I've been looking how to solve it like a week and now I found the solution in just 20 minutes lol......

The thing is to turn off vsync in opengl using the code below:

typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int );
PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;

const char *extensions = (char*)glGetString( GL_EXTENSIONS );

if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 )
return false; // Error: WGL_EXT_swap_control extension not supported on your computer.\n");


The guy who posted it didn't use (char*) to convert but for some reasons visual studio 2008 didn't allow me to compile the code without it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!