Slow mouse or slow in the head?

If I click on a object it take 3 sec. to register the click and the keyboard works fine. Is there a faster way to get the mouse events or is it my programming :slight_smile: I know, I need to test event.motion.x and event.motion.y with >, <, <=, =>.

Here the short verisoin of the code:

while (SDL_PollEvent(&event) >= 0 )
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
mouse_x = event.motion.x;
mouse_y = event.motion.y;
button = event.button.button;
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
default:break;
}
if(button == 1) // Check 64 boxes for mouse buttom 1 down
for(int i =0;i<8;i++)
for(int j =0;j<8;j++)
if(mouse_x >= board_c[i] && mouse_x <= board_c[i+1] && mouse_y >= board_c[j] && mouse_y <= board_c[j+1])
eng.move(i,j); // move to that box
}

Corey Carter wrote:

If I click on a object it take 3 sec. to register the click and the
keyboard works fine.

while (SDL_PollEvent(&event) >= 0 )
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
mouse_x = event.motion.x;
mouse_y = event.motion.y;
button = event.button.button;
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
default:break;
}

your problem is, this code is only grabbing a single event from the
event queue. since your game probably needs to draw some stuff each
frame also, it’s likely that events are being added to the queue faster
than you are taking them off the queue. especially if you are moving the
mouse a lot, it generates those SDL_MOUSEMOTION events very quick. this
is why it takes 3 seconds to get those pressed events. SDL is adding the
event to the queue right away, you just aren’t getting around to the
event until 3 seoconds later.

what you need to do is grab all the events from the queue until it is
empty. your code here is setup to do this perfectly, the only problem is
your “default:break;” line. that will break out of this little loop, and
leave a lot of events on the queue.

cut the “default:break;” line, and you should be running nice and
responsive.

Corey Carter wrote:

If I click on a object it take 3 sec. to register the click and the
keyboard works fine.

while (SDL_PollEvent(&event) >= 0 )
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
mouse_x = event.motion.x;
mouse_y = event.motion.y;
button = event.button.button;
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
default:break;
}

your problem is, this code is only grabbing a single event from the
event queue. since your game probably needs to draw some stuff each
frame also, it’s likely that events are being added to the queue
faster
than you are taking them off the queue. especially if you are moving
the
mouse a lot, it generates those SDL_MOUSEMOTION events very quick.
this
is why it takes 3 seconds to get those pressed events. SDL is adding
the
event to the queue right away, you just aren’t getting around to the
event until 3 seoconds later.

what you need to do is grab all the events from the queue until it is
empty. your code here is setup to do this perfectly, the only problem
is
your “default:break;” line. that will break out of this little loop,
and
leave a lot of events on the queue.

cut the “default:break;” line, and you should be running nice and
responsive.

“default:break;” breaks out of the switch statement, not out of the
while loop. Cutting it will not help.

AdamOn Tue, Dec 04, 2001 at 09:06:31AM -0800, Pete Shinners wrote:

Adam D’Angelo wrote:

“default:break;” breaks out of the switch statement, not out of the
while loop. Cutting it will not help.

ugh, no more early morning advice for me. :-/

If I click on a object it take 3 sec. to register the click and the keyboard works fine. Is there a faster way to get the mouse events or is it my programming :slight_smile: I know, I need to test event.motion.x and event.motion.y with >, <, <=, =>.

Are you running an OpenGL application with software rendering under X11?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

He’s using Win32 2D SDL.On Wed, Dec 05, 2001 at 02:55:05PM -0800, Sam Lantinga wrote:

If I click on a object it take 3 sec. to register the click and the keyboard works fine. Is there a faster way to get the mouse events or is it my programming :slight_smile: I know, I need to test event.motion.x and event.motion.y with >, <, <=, =>.

Are you running an OpenGL application with software rendering under X11?


Joseph Carter Free software developer

!netgod:! time flies when youre using linux
!doogie:
! yeah, infinite loops in 5 seconds.
!Teknix:! has anyone re-tested that with 2.2.x ?
!netgod:
! yeah, 4 seconds now

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011205/2c0b1207/attachment.pgp