Re : Layered display

Gabry,

That’s right, the #define 's are quite dirty. I wanted to simplify the prototypes and
avoid an if()…else() in the implementation. Also using a parameter for the layer number
would lead to dynamic memory allocation I guess. But finally, thinking about it twice,
it would not slow down because the LayeredDisplay object would be allocated once at the
begining of a scene or even at the begining of a whole program, and freed at the end so I guess
you’re right.
An average method to keep the prototypes simple would be to add a method for defining the
blit method:

SDL_SetLayeredDisplayBlitMethod (Uint32 flip_or_dirty);

One drawback is that with the #define solution, I can shrink the size of the data structure
if the Flip method is choosen. Now I have either to store the dirty rectangle list in both cases
or separate in 2 disctinct structures and cast properly, or store the dirty rectangle list info as
global variables. (or maybe another solution)

As for the number of layers, I would add a parameter to:

SDL_CreateRGBLayeredDisplay (… int width, int height, int n_layers, …)

as you suggested, and replace the static array “layers” accordingly.

To finish, my main question, before any comment on the code itself, is,
do you think such a tool is useful, is it worth doing the implementation, or
is it pointless ?

Thank you for your interest !

Julien

----- Message d’origine ----De : Gabriele Greco <gabriele.greco at darts.it>
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Jeudi, 12 Juin 2008, 15h00mn 06s
Objet : Re: [SDL] Layered display

On Wed, Jun 11, 2008 at 4:32 PM, julien CLEMENT <@Julien_Clement1> wrote:

Hi all,

I’ve quickly written an interface header defining a very basic and generic
system to support multiple layers in SDL, in the form of an SDL_Surface array.

I don’t like the #define method for determine layers number and blit method, why not to use a parameter in the create API for the first and a boolean flag in the display method for the second?


Bye,
Gabry

  _____________________________________________________________________________ 

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

Jonny,

It’s my intention not to provide any accessors on the structure, inviting the developer to
use the public interface defined by the set of functions. It’s a black-box paradigm, maybe
it’s not the best choice because SDL doesn’t work this way.

What you say confirms my intention to change the storage of layers as a dynamic array,
passing the number of layers as a parameter of the constructor:
SDL_CreateRGBLayeredDisplay

I do not approve what you said concerning the possibility of using layers “as sprites”.
I imagine what you say is, one sprite per layer, correct me if I’m wrong.
If it is what you wanted to say, then it’s not the purpose of the tool I want to make.
A layer is nothing but a “plane”, allowing to store multiple level of sprites or images,
belonging for instance to the background or the foreground (clouds, fog,
other effects).
The idea is that a developer can then forget about overlapping of graphics and focus
only on what is happening on a given layer. For example, if you move a sprite,
you just have to blit a mask to “erase” its old position and reblit it to the new position,
using the SDL_BlitSurfaceOnLayeredDisplay(). Then, you don’t have to bother with
reblitting the portion of “cloud” which is right upper the sprite, or the portion of floor
the sprite is walking on, because the Layered Display will do it automatically for you.

Hope I am clear on the objectives, thank you for your remarks.

Julien

----- Message d’origine ----De : Jonathan Dearborn
? : A list for developers using the SDL library. (includes SDL-announce)
Envoy? le : Jeudi, 12 Juin 2008, 17h39mn 00s
Objet : Re: [SDL] Layered display

I think it’s pretty useful. I don’t see any accessor functions, though. What kind of design are you going for? That is, are you expecting the programmer to use your struct manually or through functions that you provide? You should go dynamic on all your options, since you shouldn’t force the programmer to use only one layered display nor to have each one with the same settings. Also, I would suggest that the 255 layer limit be adjustable. Sure, a Uint8 would be nice, but if you’re using the layers as sprites, you might need more. I suggest adding a #define for using Uint16 or Uint32 instead. Then you could write your function signatures like ‘void fn(UintXX layerNum)’, where the UintXX is defined to be whatever you want. You would probably want to rename UintXX as something more unique, though.

Jonny D


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

Hmm… That’s what I meant. I guess I didn’t fully grasp it. So all the layers are the same size as the display surface? And there’s no way to add/remove individual layers? I think I see it. So it’s just a replacement for the display surface, but with multiple layers. In that case, I still see the utility and wouldn’t see a reason to have more than 255 layers. A ‘black box’ is perfectly reasonable as long as you have certain functionality. You should probably be able to control the properties of the layers (like using alpha blending or colorkeying) and fill the layers with a given color and alpha value (and per-surface alpha too).

Jonny D