Animation by timer

Hello,

  I`m a newbie to SDL library.
  I need help in SDL timing technics (I know the syntax of
  functions, but don`t know how to use them).
  I need to create an animated field (say, 400x400 pix, blitting on the video
  surface) with refreshing at every 150
  millisecs. How do I have to organize my code? How to create the
  timer callback function?
  Can anybody provide a simple example?

  Thank you in advance!

Best regards,
Alexander mailto:Editor at echo.ru

well, there are much better ways to do it than this, but if you do:

while (expression) {

SDL_BlitSurface(…);
SDL_Delay(150);
}

that would blit the surface then wait 150 milliseconds, so, if you were
running a computer that was fast enough to get through the loop in just
a few milliseconds, this would give you the same result, but i’m sure
others on the list can give you a better one. this is just a very simple
way to do it, but it has plenty of flaws. :-)On Thu, 2002-05-02 at 04:35, Alexander Gayevoy wrote:

Hello,

      I`m a newbie to SDL library.
      I need help in SDL timing technics (I know the syntax of
      functions, but don`t know how to use them).
      I need to create an animated field (say, 400x400 pix, blitting on the video
      surface) with refreshing at every 150
      millisecs. How do I have to organize my code? How to create the
      timer callback function?
      Can anybody provide a simple example?

      Thank you in advance!


Best regards,
 Alexander                          mailto:Editor at echo.ru



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

Chris

@Christopher_Thielen

chris.luethy.net
-------------- next part --------------
A non-text attachment was scrubbed…
Name: globe.png
Type: image/png
Size: 3328 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020502/7ce4c0a8/attachment.png
-------------- next part --------------
A non-text attachment was scrubbed…
Name: envelope.png
Type: image/png
Size: 2393 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020502/7ce4c0a8/attachment-0001.png

Hello Chris,

Thursday, May 02, 2002, 14:36:18, you wrote:

C> well, there are much better ways to do it than this, but if you do:

C> while (expression) {
C> …
C> SDL_BlitSurface(…);
C> SDL_Delay(150);
C> }

C> that would blit the surface then wait 150 milliseconds, so, if you were
C> running a computer that was fast enough to get through the loop in just
C> a few milliseconds, this would give you the same result, but i’m sure
C> others on the list can give you a better one. this is just a very simple
C> way to do it, but it has plenty of flaws. :slight_smile:

Thank you, but I cannot stop the application by SDL_Delay() function,
that`s the problem :slight_smile: I need the way it will be updating by time
without pausing the program flaw.

C> On Thu, 2002-05-02 at 04:35, Alexander Gayevoy wrote:

C> Hello,

C> Im a newbie to SDL library. C> I need help in SDL timing technics (I know the syntax of C> functions, but dont know how to use them).
C> I need to create an animated field (say, 400x400 pix, blitting on the video
C> surface) with refreshing at every 150
C> millisecs. How do I have to organize my code? How to create the
C> timer callback function?
C> Can anybody provide a simple example?

C> Thank you in advance!

C> Best regards,
C> Alexander mailto:Editor at echo.ru

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

C> Chris

C> chris at luethy.net

C> chris.luethy.net–
Best regards,
Alexander mailto:Editor at echo.ru

At 03:18 PM 5/2/02 +0100, you wrote:

C> that would blit the surface then wait 150 milliseconds, so, if you were
C> running a computer that was fast enough to get through the loop in just
C> a few milliseconds, this would give you the same result, but i’m sure
C> others on the list can give you a better one. this is just a very simple
C> way to do it, but it has plenty of flaws. :slight_smile:
Thank you, but I cannot stop the application by SDL_Delay() function,
that`s the problem :slight_smile: I need the way it will be updating by time
without pausing the program flaw.

tick = SDL_GetTicks(); // ticks are 1000 x second

for(;:wink: {
/*
… mystuff …
*/

     while(SDL_GetTicks()>ticks) {

             ticks+=150;

             update_starfield();
     }

}

The while cover the point where we lost a frame, in such case, with this
code, we render the starfield twice in a row, obviously if it’s the case
with your code you can also send the starfield once if you have more than
150ms of delay.

Bye,
Gabry (gabrielegreco at tin.it)

Thank you, but I cannot stop the application by SDL_Delay() function,
that`s the problem :slight_smile: I need the way it will be updating by time
without pausing the program flaw.

if(SDL_ticks()%150 == 0)
{
// Do stuff
}

Thomas Skovsende

if(SDL_ticks()%150 == 0)
{
// Do stuff
}

This works correctly only if you are able to do 1000 iteration of your loop
every second :slight_smile:

Bye,
Gabry (gabrielegreco at tin.it)

…and not even then, if you occasionally finish “Do stuff” in less than
1 ms. (Which is pretty likely if you’re running on an accelerated target
with an asynchcronous “command queue”.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Thursday 02 May 2002 18:44, Gabriele Greco wrote:

if(SDL_ticks()%150 == 0)
{
// Do stuff
}

This works correctly only if you are able to do 1000 iteration of your
loop every second :slight_smile:

This should work without slipping… enjoy…

-Loren

enum {FRAME_LENGTH = 150}; // in milliseconds

Uint32 frame_start_time = SDL_ticks() -
FRAME_LENGTH;

while(in_big_loop)
{
Uint32 now = SDL_ticks();

if(now > (frame_start_time + FRAME_LENGTH) )
{
Uint32 elapsed_frames =
(now - frame_start_time) / FRAME_LENGTH;
frame_start_time +=
(elapsed_frames * FRAME_LENGTH);

// Do stuff

}

// do outer loop stuff
}

— gabrielegreco at tin.it wrote:
Message: 16Date: Thu, 02 May 2002 18:44:49 +0200
To: sdl at libsdl.org
From: gabrielegreco@tin.it (Gabriele Greco)
Subject: Re: Re[2]: [SDL] Animation by timer
Reply-To: sdl at libsdl.org

if(SDL_ticks()%150 == 0)
{
// Do stuff
}

This works correctly only if you are able to do 1000
iteration of your
loop
every second :slight_smile:

Bye,
Gabry (gabrielegreco at tin.it)


Do You Yahoo!?
Yahoo! Health - your guide to health and wellness

Ahh… cmon! Was on my way out the door! ;o)
Thomas SkovsendeOn Thursday 02 May 2002 18:44, Gabriele Greco wrote:

if(SDL_ticks()%150 == 0)
{
// Do stuff
}
This works correctly only if you are able to do 1000 iteration of your
loop every second :slight_smile:
…and not even then, if you occasionally finish “Do stuff” in less than
1 ms. (Which is pretty likely if you’re running on an accelerated target
with an asynchcronous “command queue”.)

| Ahh… cmon! Was on my way out the door! ;o)

Why’s your mailer put DOS linefeed characters on the end of everything?On Thu, May 02, 2002 at 11:33:53PM +0200, Thomas Skovsende wrote:


I will not show off

6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc
E4C4 DEEA 7D08 D511 E149 | www.piku.org.uk wnzrf at cvxh.bet.hx (rot13’d)

…and what will happen when update_starfield() will take more than 150 ticks?
Application will stop on slow computers?On Thu, May 02, 2002 at 04:50:12PM +0200, Gabriele Greco wrote:

    while(SDL_GetTicks()>ticks) {

            ticks+=150;

            update_starfield();
    }

At 07:15 AM 5/3/02 +0200, you wrote:>On Thu, May 02, 2002 at 04:50:12PM +0200, Gabriele Greco wrote:

    while(SDL_GetTicks()>ticks) {

            ticks+=150;

            update_starfield();
    }

…and what will happen when update_starfield() will take more than 150 ticks?
Application will stop on slow computers?

I wrote that this doesn’t handle the frameskips, you can also easily modify
it to handle them:

if(SDL_GetTicks()>ticks) {
update_starfield();

     do {
             ticks+=150;
     }
     while(SDL_GetTicks()>ticks);

}

… anyway if you are unable to update the starfield in a so big time I
don’t think you are able to run the game anyway :slight_smile:

Bye,
Gabry (gabrielegreco at tin.it)

Hello

 Is it possible to create SDL window without the caption and
 systems buttons on the Windows platform (or any other platform)?

 For instance, if I want to have my own skins for my audio player
 with 3D visualization?

 What should I do?

Best regards,
Alexander mailto:Editor at echo.ru

Hi,

Dont know if this works or not, but I just rechecked the documentation for
SDL_SetVideoMode, and one of the flaghs is SDL_NOFRAME. The text for it says
"If possible, SDL_NOFRAME causes SDL to create a window with no title bar or
frame decoration. Fullscreen modes automatically have this flag set."

Let us know if this works… (sorry, just did a quick test… dit not work,
so anyone know why ?)

best,

Sam> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alexander Gayevoy
Sent: Friday, May 03, 2002 1:44 PM
To: sdl at libsdl.org
Subject: [SDL] SDL window without the caption

Hello

 Is it possible to create SDL window without the caption and
 systems buttons on the Windows platform (or any other platform)?

 For instance, if I want to have my own skins for my audio player
 with 3D visualization?

 What should I do?

Best regards,
Alexander mailto:Editor at echo.ru


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

Works fine, just tried it (WinXP).

-Lars> ----- Original Message -----

From: sam@novalicious.com (Sam Nova)
To:
Sent: Friday, May 03, 2002 5:05 AM
Subject: RE: [SDL] SDL window without the caption

Hi,

Dont know if this works or not, but I just rechecked the documentation for
SDL_SetVideoMode, and one of the flaghs is SDL_NOFRAME. The text for it
says
"If possible, SDL_NOFRAME causes SDL to create a window with no title bar
or
frame decoration. Fullscreen modes automatically have this flag set."

Let us know if this works… (sorry, just did a quick test… dit not
work,
so anyone know why ?)

best,

Sam

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alexander Gayevoy
Sent: Friday, May 03, 2002 1:44 PM
To: sdl at libsdl.org
Subject: [SDL] SDL window without the caption

Hello

 Is it possible to create SDL window without the caption and
 systems buttons on the Windows platform (or any other platform)?

 For instance, if I want to have my own skins for my audio player
 with 3D visualization?

 What should I do?

Best regards,
Alexander mailto:Editor at echo.ru


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


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

Embarrassing :slight_smile: I had two times SDL_SetVideoMode in my small test code, and
I only changed the first one…

So I agree with Lars, it works :wink:

-Sam> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Lars Laukamm
Sent: Friday, May 03, 2002 2:47 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL window without the caption

Works fine, just tried it (WinXP).

-Lars

----- Original Message -----
From: “Sam Nova” <@Sam_Nova>
To:
Sent: Friday, May 03, 2002 5:05 AM
Subject: RE: [SDL] SDL window without the caption

Hi,

Dont know if this works or not, but I just rechecked the
documentation for
SDL_SetVideoMode, and one of the flaghs is SDL_NOFRAME. The text for it
says
"If possible, SDL_NOFRAME causes SDL to create a window with no
title bar
or
frame decoration. Fullscreen modes automatically have this flag set."

Let us know if this works… (sorry, just did a quick test… dit not
work,
so anyone know why ?)

best,

Sam

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Alexander Gayevoy
Sent: Friday, May 03, 2002 1:44 PM
To: sdl at libsdl.org
Subject: [SDL] SDL window without the caption

Hello

 Is it possible to create SDL window without the caption and
 systems buttons on the Windows platform (or any other platform)?

 For instance, if I want to have my own skins for my audio player
 with 3D visualization?

 What should I do?

Best regards,
Alexander mailto:Editor at echo.ru


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


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


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

Hello Sam,

Friday, May 03, 2002, 13:57:47, you wrote:

SN> Embarrassing :slight_smile: I had two times SDL_SetVideoMode in my small test code, and
SN> I only changed the first one…

SN> So I agree with Lars, it works :wink:

Sam, Lars, thanks for the ideas
You just install flag SDL_NOFRAME and it works? I didnt try it yet, Im on my work :slight_smile: but as soon as I will be at home, I will

Best regards,
Alexander mailto:Editor at echo.ru

Jacek Pop?awski wrote:

   while(SDL_GetTicks()>ticks) {

           ticks+=150;

           update_starfield();
   }

…and what will happen when update_starfield() will take more than 150 ticks?
Application will stop on slow computers?

If update_starfield() takes longer than 150 ticks then SDL_GetTicks()
will always be greater than ticks and so the program will run as fast as
it can. But, it won’t generate an update every 150 ticks. This kind of
code can cause some weird effects when update_starfield takes 150 ticks
plus/minus a few ticks depending on the complexity of the update. In
that case it updates as fast as it can while it is catching up to the
ticks counter.

		Bob Pendleton> On Thu, May 02, 2002 at 04:50:12PM +0200, Gabriele Greco wrote:

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


±-----------------------------------------+

  • Bob Pendleton, an experienced C/C++/Java +
  • UNIX/Linux programmer, researcher, and +
  • system architect, is seeking full time, +
  • consulting, or contract employment. +
  • Resume: http://www.jump.net/~bobp +
  • Email: @Bob_Pendleton +
    ±-----------------------------------------+

Or, using the event queue… not quite as obvious, but
nice none-the-less.
#define MY_TIMER_EVENT (SDL_USEREVENT + 0)

static Uint32
timer_callback(
Uint32 interval,
void *param
)
{
SDL_Event event;

event.user.type = MY_TIMER_EVENT;
event.user.code = 0;
event.user.data1 = param;
event.user.data2 = 0;

SDL_PushEvent(&event);

return(interval);
}

main()
{

SDL_InitSubSystem(SDL_INIT_TIMER);

SDL_AddTimer(150, (SDL_NewTimerCallback) timer_callback,
(void *) 0);

while (!quit) {
SDL_Event events;
Uint8 *keys;

while (SDL_WaitEvent(&events) > 0) {

… other event handling …

if (events.type == (MY_TIMER_EVENT)) {
// Do some stuff
}
}

// do some other stuff
}

}

Alexander Gayevoy wrote:>Hello,

 I`m a newbie to SDL library.
 I need help in SDL timing technics (I know the syntax of
 functions, but don`t know how to use them).
 I need to create an animated field (say, 400x400 pix, blitting on the video
 surface) with refreshing at every 150
 millisecs. How do I have to organize my code? How to create the
 timer callback function?
 Can anybody provide a simple example?

 Thank you in advance!

Best regards,
Alexander mailto:Editor at echo.ru


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