Threaded Layered Display

Hello Phuoc Can Hua (which one should we use ? :)),

My idea is to provide a tool for managing multiple “planes”, or “layers” with SDL.
There is currently no implementation of it, I’m still thinking about the functionalities
it will provide. I’ve subscribed to this mailing list to get advices and tips from the
smart guys here :slight_smile: , and the reactivity is really satisfying.

You may have downloaded the draft header “SDL_Layer.h” (if not let me know).

Your problem seems compatible with what I want to do. Honestly I didn’t think about
such a case, because using threads means taking care of concurrent access to the
surfaces of the layered display. Your case is probably not isolated, many other applications
should need such a mechanism and I have to think about it.

If you’re in a hurry for your development, then consider either doing the work by yourself
or find another (possible) existing library doing that kind of job.

I plan to begin the implementation as soon as I have finished setting up the whole set
of functions and the internal structure of the layered display object.

If you have ideas, suggestions, they’re all welcomed.

Thank you for this idea

Julien

----- Message d’origine ----De : Phuoc Can Hua
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Mercredi, 18 Juin 2008, 2h08mn 42s
Objet : Re: [SDL] Re : Layered Display

Hi Julien,
I’m still SDL beginner and looking for an easy implementation of layers. But I’m not sure whether we are talking about the same thing.

I’m doing a karaoke program. Basically, I have to draw the text in realtime on the top layer and I want to have a slide show (with some effect) underneath. I wish to have something which allows me to run two threads on seperate layers and don’t have to worry re-drawing the text on the photo.

Is this what your codes support? If yes, can you give me few sample lines of code which I can start look at?

thanks
Phuoc

— On Tue, 17/6/08, julien CLEMENT <@Julien_Clement1> wrote:

From: julien CLEMENT <@Julien_Clement1>
Subject: [SDL] Re : Layered Display
To: “A list for developers using the SDL library. (includes SDL-announce)”
Received: Tuesday, 17 June, 2008, 7:20 PM
Hi Eddy,

Yes, you can compare to gimp layers, that’s completly
right.
Use cases are multiples, but I’m thinking about 2D
games which
are a good example of RT systems. A tile engine could
easily make
use of such a system. But a GUI system too. I’ve begun
a small
project, a tiny turned-based board strategy game, which
will
use this.

The code you’ve written is a good simplification of
what I want to do.
See the header I’ve written recently at
http://code.google.com/p/sdl-layer/downloads/list
(SDL_Layer.h) to have an idea. Add to your code scrolling
(viewport) with
per-layer scrolling factor, dirty rectangles, global
colorkey,
visibility, color fill of each layer and you reach my goal.

As for the points you’ve mentionned:

  1. Yes, what you say is true, and I propose a viewport
    system to defined
    which portion of the layered display to blit on the
    screen, depending on
    the scrolling factor of each layer.

  2. Again, what you say is true. The first implementation
    will be naive.
    I imagine some optimizations will be possible. But
    correct me if I’m wrong,
    SDL is not designed for performance but rather for
    portability and clarity.
    (well, this is the way I see it).
    Extra blits are necessary if I propose such a tool.
    People wanting performance
    may choose to do their own layer system.

  3. Same remark as for 2.

Thank you

Julien

----- Message d’origine ----
De : Edward Cullen
? : A list for developers using the SDL library. (includes
SDL-announce)
Envoy? le : Samedi, 14 Juin 2008, 17h41mn 09s
Objet : Re: [SDL] Layered Display

Hi,

I’m still not exactly sure what you’re trying to
achieve.

Are you trying to implement ‘layers’ as one would
see them in an image
manipulation program, such as The GIMP?

What would be the use-cases for such a facility in a RT
interactive system?

Your API seems to be proposing something like this:

#define LAYER_BG (0)
#define LAYER_SPRITE (1)
#define LAYER_EFFECTS (2)
#define LAYERS_TOTAL (3)

SDL_Surface* layers[LAYERS_TOTAL];

void init(void)
{
int i;
for (i = 0; i < LAYERS_TOTAL; ++i) {
layers[i] = SDL_CreateRGBSurface(disp_flags,
disp_width disp_height,
… // other params as main display.
);
}
}

void draw_everything(void)
{
SDL_BlitSurface(layers[LAYER_BG], NULL, display, NULL);
SDL_BlitSurface(layers[LAYER_SPRITE], NULL, display,
NULL);
SDL_BlitSurface(layers[LAYER_EFFECTS], NULL, display,
NULL);
}

Here are a list of thoughts:

  1. Unless the background (BG) is actually the same size as
    the display
    (i.e., you aren’t using it for a larger map, with only
    a small part of
    it being copied), then, you’ll have to add an
    additional blit to setup
    the BG. It would be more optimal (performance), but more
    costly (RAM) to
    have a larger ‘BG layer’, with a moving window into
    that layer.

  2. Setting up the sprites in a separate layer just adds an
    additional
    blit, when you could just blit the BG into the display then
    blit the
    sprites in. This would save in memory bandwidth and or CPU
    time, as
    you’re moving less about (blitting the entire surface
    would involve
    alpha testing every pixel). Granted, if sprites aren’t
    moving, then
    you’re going to save in function call overhead, but
    then, sprites are
    generally supposed to be moving, so it’s doubtful
    whether you’d
    actually save anything…

  3. ‘Effect’ implies things that aren’t too
    common / have limited
    lifespan. Again, you’re probably just adding additional
    an additional
    blit, as in 2.

Eddy

julien CLEMENT wrote:

Hi,

Will, you might confuse me with another person,
although I’ve used
IRC in the past :slight_smile:
The first goal is not really to make a parallax
scrolling mechanism,
although I have mentioned it in the previous message.
The main concern is, I have a graphical application
which needs
more than one display layer/plane, and there’re
some sprites/animations
on those layers/planes, and of course, if something
gets modified on a layer
I need to re- “project” all the other layers
on the screen in the right
order for
the modified area. This is a really annoying task for
a game developer I
think,
that’s why I’m proposing this tool.
Z-buffering is a technic aimed at 3D rendering: you
can look at:
http://en.wikipedia.org/wiki/Z-buffer
It is something far easier I want to do, and yet maybe
it can help.

Let me know, I wouldn’t begin a development
without knowing if there is some
kind of interest.

By the way, thank you Edward for your message. You can
help in a simple
manner:
look at the interface I’ve sent and tell me if you
see missing
functionalities, and if
you imagine you can use such functions in your
programs. You can mail me
directly
if you want.

Thank you guys, other comments/suggestions/ideas are
welcome !

Regards

Julien


Envoy? avec Yahoo! Mail

http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html.

Une boite mail plus intelligente.



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


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


Envoyez avec Yahoo! Mail. Une boite mail plus intelligente
http://mail.yahoo.fr_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  Get the name you always wanted with the new y7mail email address.

www.yahoo7.com.au/mail


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

  _____________________________________________________________________________ 

Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr

Received: Wednesday, 18 June, 2008, 6:05 PM
Hello Phuoc Can Hua (which one should we use ? :)),

If you’re in a hurry for your development, then
consider either doing the work by yourself
or find another (possible) existing library doing that kind
of job.
I’m a hobby coder. So, nothing is in hurry. I only found your post accidentally. Even if I had my solution today I might just start doing a prototype. My stuff has been sitting there for long time anyway :slight_smile:

I plan to begin the implementation as soon as I have
finished setting up the whole set
of functions and the internal structure of the layered
display object.
great!

If you have ideas, suggestions, they’re all welcomed.
In my case, there’s also an interactive layer where the user can enter song number while the song is playing, i.e. displaying numbers and the song title found, and other user interactions like… changing volume, key etc.

  Get the name you always wanted with the new y7mail email address.

www.yahoo7.com.au/mail--- On Wed, 18/6/08, julien CLEMENT wrote:

From: julien CLEMENT
Subject: [SDL] Threaded Layered Display
To: “SDL”