Mouse Motion Events

I am using SDL on a RedHat 7.1 linux box with
XFree4.0.2. I am trying to use the Mouse motion
events, but I have found that the motion events come
so frequently that they bogs down everything. I have
tested whether it was my handling of the events that
was slow by using a switch statement that simply
ignores all the motion events, and processes all the
others, but everything was still slow. Is this a
hardware problem, or can I solve this using SDL?

Eric__________________________________________________

Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

hello!

you have to let your thread, which watches for events,
sleep. you can use SDL_Delay().
here’s some code:------------
void inputThread(){ //
while(1){
SDL_Delay(INPUT_SLEEPTIME);
handleEvents();
}
}

void handleEvents(){
SDL_Event event;

if (SDL_PollEvent(&event)) {
switch (event.type){
case SDL_KEYDOWN: { … }
.
.
case SDL_QUIT: { … }
.
.
}
}

int main(){
SDL_Thread* inThread;
inThread=SDL_CreateThread((void*)inputThread, NULL);
while ( … ) { // main game-loop
.
.
SDL_Delay(MAIN_SLEEPTIME);
}

SDL_KillThread(inThread);
return(1);
}

hope that helps. good luck!
cheers,
Tolga.

Eric Akers wrote (Samstag, 12. Januar 2002 07:54) :

I am using SDL on a RedHat 7.1 linux box with
XFree4.0.2. I am trying to use the Mouse motion
events, but I have found that the motion events come
so frequently that they bogs down everything. I have
tested whether it was my handling of the events that
was slow by using a switch statement that simply
ignores all the motion events, and processes all the
others, but everything was still slow. Is this a
hardware problem, or can I solve this using SDL?


Gesendet von Yahoo! Mail - http://mail.yahoo.de
Ihre E-Mail noch individueller? - http://domains.yahoo.de

I tried this, but the problem seems to be that the
motion events come so fast with even only a small
amount of motion, that I cannot handle them fast
enough. Even ignoring the motion events completely and
only processing the others still causes lag. The same
program with motion events turned off runs fine
though. It seems like my mouse is sending way to many
events. Could this be a hardware setting?

So you know what I am doing, I am writing a scroll bar
as apart of a component. When the slider part is
pressed, I turn on mouse motion events, then process
the motion.

I even printed out the events.
After moving the slider less than an inch on the
screen, I got 15 motion events, each of which only
moved on average 2 pixels from the precious spot.

Eric

— ates x wrote:> hello!

you have to let your thread, which watches for
events,
sleep. you can use SDL_Delay().
here’s some code:

void inputThread(){ //
while(1){
SDL_Delay(INPUT_SLEEPTIME);
handleEvents();
}
}

void handleEvents(){
SDL_Event event;

if (SDL_PollEvent(&event)) {
switch (event.type){
case SDL_KEYDOWN: { … }
.
.
case SDL_QUIT: { … }
.
.
}
}

int main(){
SDL_Thread* inThread;
inThread=SDL_CreateThread((void*)inputThread,
NULL);
while ( … ) { // main game-loop
.
.
SDL_Delay(MAIN_SLEEPTIME);
}

SDL_KillThread(inThread);
return(1);
}

hope that helps. good luck!
cheers,
Tolga.

Eric Akers wrote (Samstag, 12. Januar 2002 07:54) :

I am using SDL on a RedHat 7.1 linux box with
XFree4.0.2. I am trying to use the Mouse motion
events, but I have found that the motion events
come
so frequently that they bogs down everything. I
have
tested whether it was my handling of the events
that
was slow by using a switch statement that simply
ignores all the motion events, and processes all
the
others, but everything was still slow. Is this a
hardware problem, or can I solve this using SDL?


Gesendet von Yahoo! Mail - http://mail.yahoo.de
Ihre E-Mail noch individueller? -
http://domains.yahoo.de


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

Eric Akers wrote:

I am using SDL on a RedHat 7.1 linux box with
XFree4.0.2. I am trying to use the Mouse motion
events, but I have found that the motion events come
so frequently that they bogs down everything. I have
tested whether it was my handling of the events that
was slow by using a switch statement that simply
ignores all the motion events, and processes all the
others, but everything was still slow. Is this a
hardware problem, or can I solve this using SDL?

Eric

why not just keep the x,y position of the mouse and process all the events available before a redraw
you can limit them to like 20 events per proccessing loop, or something higher if needed…
but processing more events before a redraw would reduced the amount of processing that you do…perhaps.
I do this and my event based SDL stuff has never seemed laggy.
somthing like:

int ct=0;
while( ct<20 && ( event=getnextevent() ) )
{
processevent(event);
ct++;
}
redraw();–
-==-
Jon Atkins
http://jonatkins.org/

I even printed out the events.
After moving the slider less than an inch on the
screen, I got 15 motion events, each of which only
moved on average 2 pixels from the precious spot.

That doesn’t sound like incorrect behaviour. It sounds like you are taking
too long to handle each mouse motion event.

I assume you’re doing something like this:

SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_MOUSEMOTION)
redraw_slider(event.motion.x, event.motion.y);

// etc...

}

Do this instead:

int x = -1
int y = -1;
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_MOUSEMOTION)
{
x = event.motion.x;
y = event.motion.y;
}
// etc…
}

if ((x != -1) && (y != -1))
redraw_slider();

That way you get the final mouse position, and only redraw once. Repeat
again to get the next batch of events.

And make sure that redraw_slider() (or whatever) isn’t taking an eternity
to run (converting surface types on the fly, etc…)

–ryan.