But in the case of a BomberMan clone and/or a
final fantasy game, I can’t keep a piece of
not-updated section of screen ! If all is moving
on the screen ? Or can I have a way to blit what
is already on the screen (Take all, move by 2 pixel left
and then just update the 2 missings pixel at the right ?)
Well, you can do that, and it’ll work very well on systems with h/w
accelerated screen->screen blitting - but it’ll be very, very slow when
SDL has to do it with the software blitters.
For somes games like Gnibbles or like that I can
understand, but for a scrolling game…
Consider a slow to medium speed parallax scrolling shooter, like
Project-X on the Amiga. (Can’t remember any others that I know for sure
do parallax!
In most such games, the “action” parallax level (where the player is) is
scrolling at around 30 pixels/second, and it contains only some "edges"
and occasional obstacles that you’re supposed to avoid. The rest of the
screen area is occupied by parallax layers that are further away from the
viewer, and thus moving slower.
Now, unless you’re using sub-pixel accurate rendering, you’ll find that
it’s actually only some of the sprites that make use of the full frame
rate on a 60+ Hz display. Even the “action” level parallax layer moves to
a new pixel position only every other frame, and the further away layers
move even slower!
So, if you actively keep track of whether or not a parallax really moved
since the last frame, and the areas of the screen they occupy, you can
get away with refreshing only a fraction of the screen area every frame,
while still giving the illusion of full frame rate, full screen
scrolling.
Obviously, you’ll have to offset the initial sub-pixel scroll offsets of
the layers to avoid having all of them move at once every N’th frame. For
example, if you have two layers; one moving one pixel every other frame,
and one moving one pixel every fourth frame, offset the second one so
that it will move in the frames between the frames where the first
layer moves. That is, during 4 frames, first layer 1 moves, then layer 2,
then layer 1 again and finally no layer at all. Repeat forever.
Hovever, you should also consider the rather serious problem that these
days, you can’t reliably select a suitable video refresh for your game.
You have to accept that you can’t always get 60 Hz or whatever, but you
have to make your game run at the right speed regardless of what you get.
This pretty much screws up the example I’m giving above - but then again,
since you can’t achieve absolutely smooth scrolling anyway, it’s no big
deal if you make things easier by just aiming for a reduced average per
frame update area.
That is, just look at the parallax layer coordinates, and whenever one
changes, add the visible areas covered by that layer to the “refresh
list”. (Of course, you need to “merge” overlapping refresh rectangles, as
it’s a total waste of time to update the same area more than once per
frame!)
did I MUST
use doublebuff instead of updateRect ? Or it is possible
to use updaterect anyway !? ThX
Uhm, well… SDL_UpdateRects() doesn’t make sense with double buffering,
as your graphics already is in VRAM after you’ve rendered it. Just
SDL_FlipSurface() (which is basically just a matter of swapping around
some pointers - no gfx copying), and it’ll be visible.
Indeed, you can use a partial updating scheme with double buffering
(Kobo Deluxe does in the SemiTriple buffering mode), but you have to be
careful! In theory, there’s no guarantee that the graphics will still be
there after two flips, but I have yet to see a system where this is not
the case. (Erasing the buffer would just mean extra overhead, so why
would anyone do it?) This applies to OpenGL as well.
//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 Monday 07 January 2002 20:01, Gerard wrote: