Strange problem with Win32 Sleep function and SDL

Hello, in my program I have this line:

Sleep(3000);

First, I noticed that during the sleep-time I can still
move the mouse and I see my cursor moving on the screen
(but the rest of the program is “stopped”). Why?

Apart from that, my problem is that if during the sleep-time
I click a mouse button, at the end of the sleep-time my
program enters in this case of the switch:

while (SDL_PollEvent(&event)) {
switch (event.type)


case SDL_QUIT:
return(0);

And the program stops the execution.

Is this normal? Why the event is now “SDL_QUIT”?
Is there a way to solve this problem?

Sorry but I’m new with SDL :wink:

Thanks

Hello !

First, I noticed that during the sleep-time I can still
move the mouse and I see my cursor moving on the screen
(but the rest of the program is “stopped”). Why?

The programm itself stops because you tell it
with the Sleep command to sleep/stop so long.

That the normal mouse cursor is still moveable
is by design of your OS. It would be bad if every crashed
programm would stop your Mouse Cursor.

I don’t know the Sleep command, but with SDL code
you should use SDL_Delay (Nr. of ms) to wait a Nr. of
milliseconds. This is more portable.

CU

Hi,

The operating system ist still running when your program is waiting for
Sleep to complete. And usually Windows is handling the display of the
mouse cursor, except you draw it yourself in your program and disable
the standard mouse cursor.

Maybe you forgot to “break;” the cases above SDL_QUIT?
Like…
switch (event.type)
{
case SDL_MOUSEMOTION:
updateMouse(…);
break; // <-- !!!
case SDL_MOUSEBUTTONDOWN:
clickMouse(…);
break; // <-- !!!
case SDL_QUIT:
return(0);
}

Hope that helps.
Matthias

voidstar schrieb:> Hello, in my program I have this line:

Sleep(3000);

First, I noticed that during the sleep-time I can still
move the mouse and I see my cursor moving on the screen
(but the rest of the program is “stopped”). Why?

Apart from that, my problem is that if during the sleep-time
I click a mouse button, at the end of the sleep-time my
program enters in this case of the switch:

while (SDL_PollEvent(&event)) {
switch (event.type)


case SDL_QUIT:
return(0);

And the program stops the execution.

Is this normal? Why the event is now “SDL_QUIT”?
Is there a way to solve this problem?

Sorry but I’m new with SDL :wink:

Thanks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Maybe you forgot to “break;” the cases above SDL_QUIT?
Like…

Ooops… I forgot it :wink:
Thank you very much for your help!
What do you think it’s better between using the standard
mouse cursor or drawing one by myself? Whick one is
smoother? (I’m coding a point’n’click adventure)

That the normal mouse cursor is still moveable
is by design of your OS. It would be bad if every crashed
programm would stop your Mouse Cursor.

Ah ok, I didn’t know it was the OS cursor.

I don’t know the Sleep command, but with SDL code
you should use SDL_Delay (Nr. of ms) to wait a Nr. of
milliseconds. This is more portable.

Ok, the I will use SDL_Delay.
Thanks for your help!

Hello !

What do you think it’s better between using the standard
mouse cursor or drawing one by myself? Whick one is
smoother? (I’m coding a point’n’click adventure)

The Mouse Cursor of the OS is in general smoother.

But with the OS own Cursor you can only get black&white cursors,
if you want/need colorful Mouse Cursors, you need to implement
them with your own routines.

CU

In all of the applications i wrote, the OS’s mouse cursor had less
latency. So i guess the OS is always more direct in displaying the mouse
cursor. If you don’t want to use special cursor animations or some
special cursor image, there’s no need to draw it yourself.

Matthias

voidstar schrieb:>> Maybe you forgot to “break;” the cases above SDL_QUIT?

Like…

Ooops… I forgot it :wink:
Thank you very much for your help!
What do you think it’s better between using the standard
mouse cursor or drawing one by myself? Whick one is
smoother? (I’m coding a point’n’click adventure)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

In all of the applications i wrote, the OS’s mouse cursor had less
latency. So i guess the OS is always more direct in displaying the mouse
cursor. If you don’t want to use special cursor animations or some
special cursor image, there’s no need to draw it yourself.

Ok thanks to all of you!
One more question: the SDL_QUIT event is when I close the window, right?
So if I have fullscreen mode this event will never happens?

PS: is there a way to post here using my newsreader instead of posting
by the browser?

Hello !

One more question: the SDL_QUIT event is when I close the window, right?
So if I have fullscreen mode this event will never happens?

Yes, it will. SDL_QUIT is a general Quit Message to Quit your programm.
When you hit Alt + F4, when you close your app with the Programm Manager
that comes with Ctrl + Alt + Del and others.

PS: is there a way to post here using my newsreader instead of posting
by the browser?

Yes, look at this webpage :

http://dir.gmane.org/gmane.comp.lib.sdl

CU

Message: 1
Message-ID: <loom.20070606T022959-683 at post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Hello, in my program I have this line:

Sleep(3000);

//First, I noticed that during the sleep-time I can still
//move the mouse and I see my cursor moving on the screen
//(but the rest of the program is “stopped”). Why?

//Apart from that, my problem is that if during the sleep-time
//I click a mouse button, at the end of the sleep-time my
//program enters in this case of the switch:

while (SDL_PollEvent(&event)) {
switch (event.type)


case SDL_QUIT:
return(0);

And the program stops the execution.

//Is this normal? Why the event is now “SDL_QUIT”?
//Is there a way to solve this problem?
//Sorry but I’m new with SDL :wink:

Have you forgotten to put break; before after the other cases, ie the wake
up event? you show the case SDL_QUIT, but it looks like you may have a
problem before the Quit Case, ie no break;

Just a thought!

T> Date: Wed, 6 Jun 2007 00:33:19 +0000 (UTC)

From: voidstar
Subject: [SDL] Strange problem with Win32 Sleep function and SDL
To: sdl at libsdl.org

Yes, it will. SDL_QUIT is a general Quit Message to Quit your programm.
When you hit Alt + F4, when you close your app with the Programm Manager
that comes with Ctrl + Alt + Del and others.

Ok, thanks again!

Do you know a good book (free and/or not free) about SDL programming?
I’m searching a book who also talks about optimizations/tricks in SDL.

I mean things like the ones you told me:

“…OS’s mouse cursor had less latency…”
"…use SDL_Delay instead of SLeep because…"
"…SDL_QUIT is…"

For example I’ve just discovered the function “IMG_Load”.
Is it faster than SDL_LoadBMP? Is there any other way to load
an image with SDL? Etc.

PS: I’m not searching a book about C/C++ programming

Thanks

Hello !

For example I’ve just discovered the function “IMG_Load”.
Is it faster than SDL_LoadBMP? Is there any other way to load
an image with SDL? Etc.

SDL_LoadBMP comes with SDL itself and only loads BMP Files.
IMG_Load comes with SDL_image. An add. library that can be
used with SDL, okay it has SDL as a dependency, to load different
image formats, like PNG, JPG, GIF …

CU

Have you forgotten to put break;

Yes, the mistake was the missing break before the "case SDL_QUIT:"
Thanks!

It also requires libpng, libjpeg and libgif as it’s just a wrapper as in
all cases :op Fortunately, these come with.

I’m currently working on some tutorials which should cover all of this
(and hopefully OpenAL, OpenGL and OGRE) but I make no guarantees as to
when I’ll have them done as my health is somewhat flakey at this point
in time which makes things difficult.On Wed, 2007-06-06 at 16:58 +0200, Torsten Giebl wrote:

Hello !

For example I’ve just discovered the function “IMG_Load”.
Is it faster than SDL_LoadBMP? Is there any other way to load
an image with SDL? Etc.

SDL_LoadBMP comes with SDL itself and only loads BMP Files.
IMG_Load comes with SDL_image. An add. library that can be
used with SDL, okay it has SDL as a dependency, to load different
image formats, like PNG, JPG, GIF …


Try the all-new Yahoo! Mail. “The New Version is radically easier to use” ? The Wall Street Journal
http://uk.docs.yahoo.com/nowyoucan.html