Animations etc

hiya, i was wondering if anyone had any links or information on how to do animation that updates based on time intervals instead of numbers of frames to make sure different speed computers each see the same thing. Do you just use a timer and update things to make them animate when the timer is called or what? Im wonder what the tried and true way of doing this is…

thanx (>’.’)>

An embedded and charset-unspecified text was scrubbed…
Name: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020917/f0bf599c/attachment.txt

An embedded and charset-unspecified text was scrubbed…
Name: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020917/11289d75/attachment.asc

Alan Wolfe:

Do you just use a timer and update things to make them
animate when the timer is called or what?

Do not use the timer callback to animate the whole thing.
Just insert in your main loop:

if(actual_time() - last_frame_update_time >= X seconds)
{
last frame update = actual_time();
update_all_frames();
}

This is just pseudo code, but should give you an idea.

See ya,
Francesco Orsenigo, Xarvh Project
http://freeweb.lombardiacom.it/xarvh/

You have an event loop that you’ll be iterating through quite
frequently, and you have a function to get a number which increases at
a constant rate in real time (as opposed to CPU time).

All you need is a sorted list of happenings[1] and specified times - for
example, when you want a bomb to explode five seconds from now, add a
new happening to the list with the time ‘SDL_GetTicks() + 5000’ (because
SDL_GetTicks measures 1000 ticks per second).

Then every time through your event loop, get the current value of
SDL_GetTicks and look through the list-of-happenings. Each time you
see a happening whose target time is less than the current time, then
do whatever it wants and remove it from the list.

hint: if your list-of-happenings is a C array, the library function
qsort is likely to be helpful. If you’re using C++, I think the STL
has a sorted queue class.

[1] Traditionally this things are called ‘events’, but SDL already has
things called ‘events’ that work in a rather different fashion. To
avoid confusion, I’ve called them 'happenings’On Mon, Sep 16, 2002 at 11:36:43PM -0700, Alan Wolfe wrote:

hiya, i was wondering if anyone had any links or information on how to do
animation that updates based on time intervals instead of numbers of
frames to make sure different speed computers each see the same thing. Do
you just use a timer and update things to make them animate when the timer
is called or what? Im wonder what the tried and true way of doing this
is…


| Screwtape | Reply-To: munged on Usenet |________ ______ ____ __ _ _ _
|
| “Why fall in love when there’s better things to do?” – DEVO
|

This is a simple routine to call every frame update. It also handles a
pause time:

void UpdateTime()
{
if(!g_pause) // Pause status
{
// Store old time
Uint32 oldtime = g_currtime;

	// Get current timer
	// pauseTotal is a Uint32 counter of the total pause

time which is incremented
// every frame during pause
g_currtime = SDL_GetTicks() - pauseTotal;

	// Calculate time delta
	g_deltatime = (float)(g_currtime - oldtime);
	g_deltatime /= 1000;

	// Clamp if too much time has passed
	if(g_deltatime >= 0.3f)
		g_deltatime = 0.3f;
}
else
{
	g_deltatime = 0;
} 

}

The obtained deltatime must be used to calculate the animation frame
index like this:
obj->frame += anm.speed * g_deltatime;

So that, you have also a frame skipping method :slight_smile: Hope this helps,

Marco Pacifico----------------------
Lead Programmer
Product Manager

Prograph Research S.r.l.
Longarone (BL) - Italy
www.prograph.it

-----Messaggio originale-----
Da: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] Per conto di Alan
Wolfe
Inviato: marted? 17 settembre 2002 8.37
A: sdl at libsdl.org
Oggetto: [SDL] animations etc

hiya, i was wondering if anyone had any links or information on how to
do animation that updates based on time intervals instead of numbers of
frames to make sure different speed computers each see the same thing.
Do you just use a timer and update things to make them animate when the
timer is called or what? Im wonder what the tried and true way of doing
this is…

thanx (>’.’)>

[…]

hint: if your list-of-happenings is a C array, the library function
qsort is likely to be helpful.

I’d suggest using something more lightweight, or rather, something that’s
optimized for the job. Of course, we probably aren’t talking about
thousands of objects here, but inserting + qsort()ing all the time might
still turn out to be expensive, especially if it turns out that you have
to sort more than once per video (or logic) frame.

If you’re using C++, I think the STL
has a sorted queue class.

That’s probably more suitable.

If you don’t have large numbers of events queued up at any time, you can
just use a linked list (“queue”), which is scanned for the right position
when inserting each new event. “Sort while inserting” rather than “mix,
then sort”.

The next stage is to optimize the seach pattern when adding events to the
queue. Read up on sorting in general, and priority queues in particular,
unless you feel like doing some serious wheel reinvention here! :slight_smile:

[1] Traditionally this things are called ‘events’, but SDL already has
things called ‘events’ that work in a rather different fashion. To
avoid confusion, I’ve called them ‘happenings’

How about game_event_t? :wink:

//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 Tuesday 17 September 2002 10:17, screwtape at froup.com wrote:

screwtape at froup.com wrote:

You have an event loop that you’ll be iterating through quite
frequently, and you have a function to get a number which increases at
a constant rate in real time (as opposed to CPU time).

All you need is a sorted list of happenings[1] and specified times -
for example, when you want a bomb to explode five seconds from now,
add a new happening to the list with the time ‘SDL_GetTicks() + 5000’
(because SDL_GetTicks measures 1000 ticks per second).

This can be awkward if you allow the player to pause the game. In such a
situation, you will need to do something like time how long the game is
paused (and add that to all the event times when the player unpauses) or
time the events in frames instead.–
Kylotan
http://pages.eidosnet.co.uk/kylotan

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

screwtape at froup.com wrote:

You have an event loop that you’ll be iterating through quite
frequently, and you have a function to get a number which increases at
a constant rate in real time (as opposed to CPU time).

All you need is a sorted list of happenings[1] and specified times -
for example, when you want a bomb to explode five seconds from now,
add a new happening to the list with the time ‘SDL_GetTicks() + 5000’
(because SDL_GetTicks measures 1000 ticks per second).

This can be awkward if you allow the player to pause the game. In such a
situation, you will need to do something like time how long the game is
paused (and add that to all the event times when the player unpauses) or
time the events in frames instead.

Or you do it the simple way: just replace SDL_GetTicks with a function that
only advances when the game is unpaused.
The outlined technique is very efficient and flexible, and when used
correctly, it can guarantuee that a game is framerate-independent. Of
course it’s only suitable for some types of games, especially those that
don’t use a continuous world. For example, real-time tile-based games are
perfectly suitable for this technique, using events like: Unit U finishes
walking onto tile X/Y at time T (the exact position of the unit for drawing
and accounting for hits in combat can be obtained via interpolation).


Kylotan

cu,
Nicolai
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9hzZXsxPozBga0lwRAs0OAJ4lm4oATT4SCZJbtvsKNrciaOaS4gCgm99I
nDd1O5ge6UuGssNZnmSQo1Q=
=I8Uv
-----END PGP SIGNATURE-----On Tuesday 17 September 2002 15:33, Kylotan wrote:

In Kobo Deluxe, I’m using “logic frames” as the time base. Game logic is
called at 33.33 Hz (on average - work is actually done once per video
frame; no timers) regardless of rendering frame rate. Logic time is
incremeted by 1.0 for every logic frame.

When the game is paused, I just stop advancing logic time, and as a
result, the graphics/timing engine stops calling the game logic callback.

//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 Tuesday 17 September 2002 15:33, Kylotan wrote:

screwtape at froup.com wrote:

You have an event loop that you’ll be iterating through quite
frequently, and you have a function to get a number which increases
at a constant rate in real time (as opposed to CPU time).

All you need is a sorted list of happenings[1] and specified times -
for example, when you want a bomb to explode five seconds from now,
add a new happening to the list with the time ‘SDL_GetTicks() + 5000’
(because SDL_GetTicks measures 1000 ticks per second).

This can be awkward if you allow the player to pause the game. In such
a situation, you will need to do something like time how long the game
is paused (and add that to all the event times when the player
unpauses) or time the events in frames instead.

i know this is an old one but i just noticed what you said…

“Of course it’s only suitable for some types of games, especially those that
don’t use a continuous world”

by continuos do you mean large? Im aiming for a multiplayer (networked of
course) 3d environment.> ----- Original Message -----

From: prefect_@gmx.net (Nicolai Haehnle)
To:
Sent: Tuesday, September 17, 2002 7:04 AM
Subject: Re: [SDL] animations etc

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 17 September 2002 15:33, Kylotan wrote:

screwtape at froup.com wrote:

You have an event loop that you’ll be iterating through quite
frequently, and you have a function to get a number which increases at
a constant rate in real time (as opposed to CPU time).

All you need is a sorted list of happenings[1] and specified times -
for example, when you want a bomb to explode five seconds from now,
add a new happening to the list with the time ‘SDL_GetTicks() + 5000’
(because SDL_GetTicks measures 1000 ticks per second).

This can be awkward if you allow the player to pause the game. In such a
situation, you will need to do something like time how long the game is
paused (and add that to all the event times when the player unpauses) or
time the events in frames instead.

Or you do it the simple way: just replace SDL_GetTicks with a function
that
only advances when the game is unpaused.
The outlined technique is very efficient and flexible, and when used
correctly, it can guarantuee that a game is framerate-independent. Of
course it’s only suitable for some types of games, especially those that
don’t use a continuous world. For example, real-time tile-based games are
perfectly suitable for this technique, using events like: Unit U finishes
walking onto tile X/Y at time T (the exact position of the unit for
drawing
and accounting for hits in combat can be obtained via interpolation).


Kylotan

cu,
Nicolai
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9hzZXsxPozBga0lwRAs0OAJ4lm4oATT4SCZJbtvsKNrciaOaS4gCgm99I
nDd1O5ge6UuGssNZnmSQo1Q=
=I8Uv
-----END PGP SIGNATURE-----


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