NOGDUS

Articles, Tutorials, and other things. => Pixie Game Programming => Topic started by: Cycl0ne on April 12, 2011, 10:16:25 AM



Title: Setting a transparent color in Pixie
Post by: Cycl0ne on April 12, 2011, 10:16:25 AM
Hi,

its me again, while fiddling around, i stumbled upon the following problem. How do I set a color to be transparent? At first I thought it could be done with SetColor() but this will completly draw the sprite/image in this color ;-)

Any Ideas?


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 12, 2011, 10:41:30 AM
Ohh and while i am at it. is it possible to:

Flip Sprites (draw them mirrored x or mirrored y)
Crop Sprites (draw only parts of the sprite)
Size Sprites (draw them smaller or bigger)

?


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 12, 2011, 12:57:54 PM
Ok i found it perhaps. The Sprite Class cant do the job, so i implemented a "Bob" Class (Blitter OBject):

Code:
#include "Pixie.h"

class Bob:public Sprite
{
public:
Bob();
Bob(SpriteManager* spriteManager);
virtual ~Bob();
virtual void SetSize(float x1, float y1, float x2, float y2);

private:
virtual void Render(Bitmap& bitmap);

private:
float x1_, y1_;
float x2_, y2_;
};

Code:
#include "Bob.h"

Bob::Bob(): x1_(-1),y1_(-1), x2_(-1), y2_(-1)
{
}

Bob::Bob(SpriteManager* spriteManager):Sprite(spriteManager),x1_(-1),y1_(-1), x2_(-1), y2_(-1)
{
}

Bob::~Bob()
{
}

void Bob::SetSize(float x1, float y1, float x2, float y2)
{
x1_ = x1;
y1_ = y1;
x2_ = x2;
y2_ = y2;
}

void Bob::Render(Bitmap& bitmap)
{
if (IsVisible())
{
if (x1_<0 && x2_<0 && y1_<0 && y2_ <0)
{
GetBitmap().Blit((int)GetCel(),bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetColor(),GetAlpha());
} else
{
GetBitmap().Blit((int)GetCel(), (int)x1_, (int)y1_, (int)x2_, (int)y2_, bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetColor(),GetAlpha());
}
}
}

I will extend this class to do some Flipping too. Only "Resizing" seems to be not implemented in the bitmap class.....


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 12, 2011, 01:21:13 PM
Ha, I haven't really needed to be able to crop sprites, so I guess that's why that functionality is missing... It should probable be added, but on the other hand, your "Bob" class is just as good a solution - In Pixie, it is meant to be easy to extend the system with your own Sprite types. Maybe I should work the cropping code into the next release of Pixie... what do you think? Just out of curiosity, what do you need it for?  :)

To make a sprite semi-transparent, you simply need to call SetAlpha. The reason for this is that colours are 16 bits in Pixie, and thus there's no room for an alpha (transparency) component, which is why it has a separate function.

There's currently no way of doing scaling or rotation of sprites. This is quite a limitation, but as I didn't need it at the time, I didn't get around to adding this, as it is quite a non-trivial problem to do efficiently in a software blitter. However, I have plans to add systems for this to the next version of Pixie. A preview can be seen in the project here: http://ccpssolutions.com/nogdusforums/index.php?topic=705.0

The new version is still some way off, so if someone needs the code I have so far, just let me know and I'll share it - but it's not at all integrated to the sprite system properly yet.

Another addition to go into the new release is support for transforms on RLE bitmaps (flip, mirror etc), including easy ways to add custom transforms, as well as support for multiple blending modes (add, multiply, subtract etc), including easy ways to set up custom blend modes. Again, this code is not finished, but I'm happy to supply previews if someone is specifically interested - but it's not quite ready to be used in an actual game yet.



Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 12, 2011, 01:31:35 PM
Ok great to hear.

I need the "Crop" Functions for a small game i write to understand pixie completly. it has a door sprite, which need to slide to the right/left to open (or up). I know i could use lots of sprites for this as an animation. but i was too lazy and thought the pcu could calculate it for me.

Same goes for the scaling. The door sprites need to be scaled from small to big as the player approaches the door.

and to be even more lazier: I want to take only one sprite for the door and mirror it for the other side. And here comes my next question:
I extended the blit function in the Bob Class to:

Code:
GetBitmap().Blit((int)GetCel(), (int)x1_, (int)y1_, (int)x2_, (int)y2_, bitmap,(int)(GetX()-GetOriginX()),(int)(GetY()-GetOriginY()),GetColor(),GetAlpha(), Bitmap::Mirror_Y);

But this doenst work? Havent you properly implemented this transformation?

As far as I can see these two things: Mirroring and Scaling are the only things I need in my small game which seems to be missing ;-)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 12, 2011, 01:36:26 PM
Quote
To make a sprite semi-transparent, you simply need to call SetAlpha. The reason for this is that colours are 16 bits in Pixie, and thus there's no room for an alpha (transparency) component, which is why it has a separate function.

Ohh you dindt get me on this. I dont want the whole sprite to be transparent. I want to select one color to be transparent.
I know, that i can select with irfanview (saving it as a png file) to select a transparent pixel. And that pixie recognizes this. But what should i do, if i would like to change this transparent pixel on the fly? In SDL you have the Function: SDL_SetColorKey(); With this you can say, that one special kind of color is transparent for the Sprite.


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 18, 2011, 12:58:31 PM
Hmm, using transformations should work with the current code... Mirror_Y should flip the sprite upside down. But it won't work if the bitmap type is any of the RLE formats (but again, next version of pixie will have support for transforms even on RLE bitmaps).

Ah, ok, I hear you on the colour key issue. The reason I don't support color keys, is mostly for efficiency reasons - to do blitting with a colour key means doing a comparison for each pixel. On the other hand, using an alpha channel and .PIX files in RLE format, means that empty pixels will just be skipped - so it will in fact be faster than blitting non-compressed files.

If I were to add colour key support, I would actually add it to PixiePCT, the picture conversion tool, as an option to automatically generate an alpha channel from the specified colour...


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 19, 2011, 06:56:06 AM
MIRROR_Y didnt work.. because it was an RLE .. correct ;-)

Hmm, so you tell me, if i work through the sprite bitmap and set every pixel i find, i wish to be transparent, in the alphachannel, this should work?

then this would be a very easy "colorkey" implementation or?


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 19, 2011, 08:18:24 AM
yes, that should definitely work - but if you put it into the code which generates RLE files, and use them, it will be much faster (but if you don't use many sprites, that's not a problem)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 19, 2011, 01:01:42 PM
Hmm, the problem is, that i have a special sprite with two transparent colors. At first i need to blit it to a wall or door sprite with the outer transparent color set. after that i need to blit both with the inner transparent color to the screen to "see" whats behind it. Thats the "look through wall/door" spell.

To be honest, im working on a Clone of Dungeon Master with new Graphics for mobile devices as tablets in 1280x800x16. Here are some graphics from my gfx artist:

(http://dl.dropbox.com/u/5037811/characterscroll.png)

I think this is a perfect game for tablets/mobile devices and pixie is great for developing under windows and porting it to android.


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 19, 2011, 02:35:02 PM
Hey, that's a *very* cool project :D I've always been a big fan of Dungeon Master, since playing the original on my Atari ST back in the 80:s. A while back, I even started on my own clone (http://mattiasgustavsson.com/Blog/Entries/DungeonMaster-stylegame.php) using Pixie, but I've stopped working on it for now - I have some other games I want to make first :D

Btw, you should check out the Dungeon Master forums (http://www.dungeon-master.com/forum/index.php) - it's full of people who love the game, still play the game and make clones of the game :D

I'm still not sure what you mean with the inner/outer transparent colours... but please, do post an example of what you want to achieve, and I'll be happy to advice on a suitable approach within Pixie - I find these sort of problems very interesting, as it helps me to develop the engine to be more useful for more scenarios :D


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 19, 2011, 05:18:27 PM
Im enlisted in the Forum too :) In the Developer Area you can see my progress on developing the game under android. HAd a really cool engine in java until i got to the point to make the GFX  darker (torchlight and distance from player) .. so i had to darken each color in the bitmap. From 25fps on my HTC Desire Framerate dropped to 2FPS, since in java doing this:

for(pixel in bitmap)
bitmap[pixel] = darkenpixel(bitmap[pixel]);

is very costly in the android java engine since arrays in java are not directly the memory and also boundary checking is done and and and....

Guess what, from the dungeon master forum, i got notice of your clone. This is how i landed at pixie ;-) What would be nice, do you mind doing a screenshot of your source files form your clone? or even publish it? I would be very interessted how you split up the gamestates.

From my "first" aspect, i needed the following functions in pixie:
- Mirror RLE Sprites in X and Y
- Resize RLE Sprites

But after a thought, i just created more on harddisk and resized and mirrored them ;-)

For the Example look at this:
This is the Wall:
(http://dl.dropbox.com/u/5037811/wall_front_d1-1.png)

This is the "see through wall" sprite:
(http://dl.dropbox.com/u/5037811/wallset_window.png)

as you can see the "see through wall" has two transperency. The black in the outside and the pink in the inside.

at first i have to create a temporary buffer where i blit the wall, then i blit the hole image ontop and then i blit into the screen the temporary buffer with the pink as the transparent part.

i cant make both transparent in the beginning otherwise one couldnt see through the hole :)

The same problem occurs with "bashed" doors. One bitmap descriped the door, the other describes a 2 colored mask: the middle which is now transparent, as the door is bashed and the outer for thelook of the original door. See here:

(http://dl.dropbox.com/u/5037811/door_smashed.png)

and also here a special mask for the door look through:

(http://dl.dropbox.com/u/5037811/door_window.png)

while im typing it, i think of precalculating this with photoshop to a new sprite set. so it wont be needed as a function.. :-P

so a new PCT with an option telling which color is transparent would be nice ;-)


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 21, 2011, 02:15:58 AM
Ah, ok, I'm with you now :D

Well, for a case like that, I would definitely condsider combining the see-through/bashed masks with each image they can go on top of - it might mean more bitmaps, but it will mean that they can be stored in RLE8 format, which means it will be both smaller and much faster to render.

I can't stress enough how beneficial it is to use the RLE8 format. To give you an idea how it works, here's some detail on what it is actually doing:
When you run PixiePCT with the option -rle8, the first thing it does is reduce the colours of the bitmap to 256 (8-bit) and using a 16-bit colour space (this is done using the median cut algorithm, which gives very nice results - comparable to the pro art packages). For most bitmaps, you won't see much of a difference, since each individual bitmap will get its own 256-colour palette. If you find that some bitmaps get a bit too much banding, you can add the -dither flag, which will do floyd-steinberg dithering on the image, giving it somewhat smoother colour transitions.
Next, the PCT tool takes the palettised image, and compress it using RLE compression. This means that instead of storing a pixel per byte, it stores a byte for a count, followed by a byte for the colour - so if you have 12 pixels in a row that are all the same colour, it will store 12 and then the color index. Or, if there's a stretch of pixels where each one is different from the next, it stores one byte for count followed by a byte per pixel (basically storing that run uncompressed).

The nice thing though, is when rendering these RLE bitmaps - they are not decompressed on load, they are stored in RLE form (which means they take less memory), and blitting is done directly from the RLE format. This means, that for a run of pixels, one can do a pretty efficient straight fill of pixels, but more importantly, that any transparent pixels are not processed at all - they simply end up as a adding a value to the destination pointer, making it very efficient.

The actual RLE format is actually a bit more complex - for images that have an alpha channel with varying levels of transparency, it will make two different RLE streams, one for fully opaque pixels, and one for semi-transparent pixels, to make the blitting of each type as efficient as it can be, and avoid expensive test-and-branch in the inner loop.

RLE compressed images are by far the most efficient way of both storing and rendering bitmaps - have a play around with it if you want to get a feel for the difference they make.

Also, I thought I'd point out PixView, a picture viewer included with PIXIE which will display PIX files (including RLE bitmaps), and allow you to cycle through all images in a directory using SPACE and BACKSPACE - On my system, I've associated PIX files with PixView, which makes things quite easy :-) Also, PixView will display animated PIX files (such as you would get by making a "strip" using PixiePCT - bitmapstrips are the easiest way in Pixie to handle animations, as you'll be able to just call SetCel on a sprite to make it animate).


Btw, I made a quick update to the PixiePCT tool - you can download it here:
http://colossusentertainment.com/forumref/PixiePCT_colorkey.zip
This new version will allow you to add a colorkey flag to the command line, to automatically make a specified colour transparent at conversion time - use it like this:
PixiePCT -rle8 -colorkey=FF00FF myBitmap.png

And any questions or problems, just let me know :-)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 21, 2011, 02:58:37 AM
Thanks for the support.
the graphics i showed are the original graphics. i will have to see how the rle8 will work with my graphics from my gfx artist. He is pushing all graphics from 320x200 to 1280x800 and from 16 colors (as the examples) to 16bit. I will have to see how it fits with rle8.

Ok now i have a question about the size. I found the following:
PNG 11Kb
RLE8 54Kb

Now what im thinking about:
- Create all Images mirrored
- or do a mirror blit, when pixie 1.0 arrives

When i creeate all images mirrored, im considering space as crucial. Does your AssetManager (ArchiveManager) also compress the whole package? Because, when i run Winzip/Winrar over the RLE8 Images the size is shrinking incredible.



Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 21, 2011, 02:12:57 PM
When comparing image sizes, it's worth noting that PNG images are stored in a compressed form, but they are decompressed at load time, as you can't blit straight from their compressed form. As pixie RLE images are not decompressed at load time, they will take less memory than the decompressed PNG equivalent.

If you zip the PIX files up, they should become significantly smaller - and in fact, PNG files use a similar, if not identical, compression algorithm as zip files. Currently, the pixie archive format doesn't support compression - I've never needed it, since I always zip my stuff up, and storage space on PC is not exactly limited :P I could see why you'd like to have compression on a mobile device though. It should certainly be possible, maybe even quite easy, to add compression to the archive system though - especially as I already have ZLIB in there (as it is needed by the PNG decoder). In fact, I make use of it in my application Poser Content Manager (http://www.mattiasgustavsson.com/Blog/Features/PoserContentManager.php), to compress and decompress datafiles.

To add compression, all that should be needed is to add compression code to the archive generation tool, PixieAGT, and then add decompression when assets are loaded in PIXIEs asset system. I'm happy to give more pointers if you decide you need to add this - and depending on when it is needed, I might even be able to add it myself :-)


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 21, 2011, 02:22:16 PM
Oh, and one more thing:

What would be nice, do you mind doing a screenshot of your source files form your clone? or even publish it? I would be very interessted how you split up the gamestates.

Yeah, I'd be happy to share the source of what I have so far - but I'm not sure how useful it would be, as I just barely started - I only have one gamestate for walking around - so it's not even a game yet, just a simple walk-around demo. But let me know if you'd like to have a look anyway, and I'll dig out the source.

Oh, and one more thing about the RLE8 format - when blitting them, you may specify a colour, which it modulates the bitmap with, which is useful for making things darker far away. But the nice thing is, that since RLE8 bitmaps are palettised, I only need to modulate the colours of the palette into a temporary palette, rather than having to modulate each pixel - so at most it will darken 256 colours, and then blit the actual bitmap the same way as if it was unmodulated, but using the modulated palette - which is great for speed :D


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 21, 2011, 06:27:09 PM
Wow that sounds really cool, since i need to darken the sprites the farer they are away. Where it wont help me, is to darken the whole DungeonView, since it is already blittet. i will use the transission code perhaps for this effect ;)


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 22, 2011, 05:09:48 AM
Hmm, wouldn't you be able to use this to darken anything? I mean, when you're blitting the dungeon view, you could just modulate each blit?


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 22, 2011, 12:20:33 PM
Yes could be an Idea, a friend of mine said, i should try to blit a black screen and alphablend it.


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 22, 2011, 01:54:21 PM
Well, alphablending in software is slow, so I wouldn't recommend it... But what I was thinking is, that for each bitmap you blit, you give it the right value to modulate with? That way, you'd be able to use the fast way for modulate for everything on screen, even the view of the dungeon (as each bit of the dungeon gets modulated when you blit it...)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 22, 2011, 05:48:01 PM
Ill have to try. At the moment im fiddling with the original graphics around to see how thinks could work best until the new graphics are finished (around november or so). but do you think it is so slow? In Java i did something like this in the graphics drawing routine:

if (dirtyflag) drawnewdungeonscreen();
else drawdungeonbuffer();

i seperated everything on screen into smaller "screens" only updating those, which got dirty. the dungeonview can only get dirty by two things:
- Monster AI moving (i think ai was set to move every 1 sek)
- Player moving.

so you should get a decent frame per seconds, since you draw often the buffered image.

The dungeonview itself (which gets darkend) is 896*544. its gets darken by 6 steps down. 100% = normal light, 16.6% with every step.

when using the modulate way, how am i going to calculate the right color for the blit?

here is the example i done for the distance blitting in the java code as c example:

Code:
ui32 distance_lighting(ui32 col,i16 distance)
{
  ui32 ret;
  i16 r,g,b;
  if (col == MASKCOLOR)
    ret = col;
  else
  {
    r = getr32(col);
    g = getg32(col);
    b = getb32(col);
    switch (distance)
    {
      case -1:
      case 0:
        ret = col;
      break;
      case 1:
        r = MAX(0,r-20); g = MAX(0,g-20); b = MAX(0,b-20);
      break;
      case 2:
        r = MAX(0,r-40); g = MAX(0,g-40); b = MAX(0,b-40);
      break;
      case 3:
        r = MAX(0,r-50); g = MAX(0,g-50); b = MAX(0,b-50);
      break;
    }
    ret = makecol32(r,g,b);
  }
  return ret;
}


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 23, 2011, 04:06:34 AM
Ill have to try. At the moment im fiddling with the original graphics around to see how thinks could work best until the new graphics are finished (around november or so). but do you think it is so slow?

Well, doing alpha-blending in software is quite slow - you need to calculate the inverse of the alpha value, read the original colour value, multiply it with alpha, multiply the colour you're blending with the inverse alpha, add the two together, scale it back to the right range, and write it back to the original location. That's a lot of operations to do per pixel, so that's why I wouldn't recommend using an alpha-blended blit to darken the screen...

In Java i did something like this in the graphics drawing routine:

if (dirtyflag) drawnewdungeonscreen();
else drawdungeonbuffer();

i seperated everything on screen into smaller "screens" only updating those, which got dirty.
I know some people get good results using some sort of "dirty rects" scheme, but I usually don't bother with it - it makes things more complicated, and for the kind of things I've been doing so far, it seems that more often than not, I end up redrawing most tiles all the time anyway, because of things changing on screen. So I tend to just redraw everything every frame, but try to make that drawing as efficient as possible. But since you're working on different hardware, the rules you have to play by is probably different...

The dungeonview itself (which gets darkend) is 896*544. its gets darken by 6 steps down. 100% = normal light, 16.6% with every step.

when using the modulate way, how am i going to calculate the right color for the blit?

here is the example i done for the distance blitting in the java code as c example:
Hmm, I'm not quite sure how you're using this... Is this function called per pixel to darken things?

What I was thinking, is that if we take an example where you're drawing a long wall going into the screen... in that case, I would draw it using 6 draw calls, not just one. Where each draw call would use a different modulate value, depending on the distance. The modulate value passed to the blit would just be:

Code:
unsigned short modulate = RGB32TO16( distance_lighting( 0xffffff, distance ) );

Basically, just running your existing lighting calculation on a white colour, with the appropriate distance, and then converting it to a 16-bit colour using one of the Pixie conversion functions. This value is then sent along with the blit and, assuming it is an RLE8 image, each colour of its palette will be multiplied by the value, and then used for the blit - nice and efficient, as it will be, at most, 256 values being multiplied :D


Does this make sense at all, or am I missing something here?


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 23, 2011, 05:13:10 AM
Yes and no. :)
Ok sorry.. the function i gave was for the new color of items and their distance lying away from me. :-) and yes it is in a loop with (for all pixel do this).

for the "dungeon" gets darker, im not sure if this would work too. Since the walls are precalculated sprites. so all walls dran in position 2 are allready darker than on position 1 and 3 at its darkest (this is why i had to use such a function in java, because the items sprites on floor are not precalculated).

ill give it a try with the original graphics and see what happens ;)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 23, 2011, 06:48:43 PM
Ok i builded the rendering engine now. I will see how it will work with the color set to darken the map.

another question i have. how to i "clear" the screen from GameState? I did a workaround and made a screen.clear() in main before sprite update. But there has to be a cleaner way or?


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 01:00:28 AM
First of all, if you draw on the whole screen, you might not even need a clear, as you'd overwrite everything anyway. But if you do need a clear, the easiest way is to create a Rectangle object. This is a type of sprite, which draws a solid or transparent colour as specified, so if you make one which is solid black and the same size as your screen, then it will in fact use the screen.Clear() call. So create a fullscreen Rectangle instance and place it behind all your other sprites :-)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 01:24:30 AM
Im redrawing the whole screen, but, since im using transparency it looks like this without a clear():
(http://dl.dropbox.com/u/5037811/dmpixie.jpg)

its because the black in the distance is not a sprite :) so im nearly ready to implement darkening. my gfx artist needs a new version of the drawing engine for sprite testing, i just have to build a new one with 1280x800 today :-P but after that.....

the wiki server is also ready. SVN is installed. im still thinking between : Trac or MediaWiki+SVN Plugin. I will have to see.


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 02:46:14 AM
Ah, I see - yes, you'd need to clear in that case. But you could probably get away with just creating a black Rectangle covering only the part of the screen that needs to be cleared, which I guess would be this:

(http://www.colossusentertainment.com/forumref/dmpixie_clearrect.png)

That way, you avoid clearing pixels which you will later redraw anyway :-)


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 04:24:44 AM
Yup i did that for performance. only the small recatngle is now cleared.


Title: Re: Setting a transparent color in Pixie
Post by: Richard Marks on April 24, 2011, 04:26:38 AM
the wiki server is also ready. SVN is installed. im still thinking between : Trac or MediaWiki+SVN Plugin. I will have to see.

Trac is the better of the two.
My personal preference is to use the git plugin (http://trac-hacks.org/wiki/GitPlugin) for Trac. I hate SVN with a passion.


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 12:15:07 PM
hmm im still thinking... trac is good for development. but what pixie needs is more on information/documentation. I would like to see somthing like an online documentation which clearly describes every piece of this engine.


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 12:52:49 PM
Does this make sense at all, or am I missing something here?

Hey Mattias, IT WORKS great ! :-) I put up switch() statement with 9 levels of light (from 0xffffff to 0x000000) and it REALY works charming ;-)

(http://dl.dropbox.com/u/5037811/mattias2.png)


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 01:15:44 PM
That's great to hear :D And if you're able to use RLE8 for the art, then it will be most efficient - but even if you can't, I think it should be alright.

Btw, speaking of switch statements to map values, I'm a big fan of using arrays for that instead... so instead of something like:
Code:
switch ( level )
{
    case 0: value = 0x000000;
    case 1: value = 0x1C1C1C;
    case 2: value = 0x383838;
    case 3: value = 0x545454;
    case 4: value = 0x707070;
    case 5: value = 0x8C8C8C;
    case 6: value = 0xA8A8A8;
    case 7: value = 0xC4C4C4;
    case 8: value = 0xE0E0E0;
    case 9: value = 0xFCFCFC;
}


or similar, I will instead do:
Code:
unsigned int valueMap[] = { 0x000000,0x1C1C1C,0x383838,0x545454,0x707070,0x8C8C8C,0xA8A8A8,0xC4C4C4,0xE0E0E0,0xFCFCFC, );

Assert( level < sizeof(valueMap)/sizeof(valueMap[0]) );
value = valueMap[ level ];

Which I think is both easier to read, and can actually give better performance, depending on the compiler :D


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 01:30:51 PM
Yes, this is a really cool idea and i even have another one :)

one could take the unsigned short as a array, so the color hasnt to be constantly recalculated? :-P


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 01:33:21 PM
Yeah, that would work even better :D


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 01:45:32 PM
That's great to hear :D And if you're able to use RLE8 for the art, then it will be most efficient - but even if you can't, I think it should be alright.

Yes I promise i will use RLE8 as soon as all graphics are finished :) until then i stick to PNG ;-) And i promise, i will put all stuff into the Archive, which will be the new Archive that is ZLib compressed ;-)

hmm another thought of me:
can i create lots of sprites, all using the same bitmap?


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 01:53:33 PM
Do you mean doing this?
Code:
mySprite.SetBitmap("myBitmap.pix");
anotherSprite.SetBitmap("myBitmap.pix");

Then yes, absolutely - both sprites will reference the same Resource_Bitmap, and when both sprites have been destroyed (or set to a different bitmap), then the bitmap resource will be freed.

Btw, it is a good idea to call:
Code:
siResourceManager->LoadBitmapStrip("myBitmap.pix");
for all bitmaps you're using in, say, a level before the level starts - otherwise you might get a lot of loading/unloading of resources while the game is running. Calling the Load functions on the resourcemanager makes sure that resources stay in memory until you call
Code:
siResourceManager->UnloadBitmapStrip("myBitmap.pix");
Note though, that if there's still a sprite which uses the bitmap, it will still not get unloaded until that sprites gets removed or has its bitmap changed. Resources are reference counted.


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 24, 2011, 03:41:05 PM
Ok,

im designing the renderengine. And now comes up the next question:
i like it to fix sprites to a coordinate and just switch them on and off.. Do you think it is a performance issue if i got 4000 sprites where 3980 are FALSE in visibility?


Title: Re: Setting a transparent color in Pixie
Post by: Mattias Gustavsson on April 24, 2011, 04:01:57 PM
No, I think that would be fine - it would just be looping through 4000 entries in a contiguous array, and doing a comparison on each - that's stuff  which modern computers are really fast at.

But IF you would later find that it is too slow, there's a couple of options you could do... One alternative is to use multiple sprite managers, and assign sprites to different ones, and then toggle entire managers on/off (look at SpriteSystem.h/cpp for setting up multiple sprite managers).

Another, and maybe better, option, is to call SpriteManager::RemoveSprite and SpriteManager::AddSprite, to change visibility for your sprites - and keep a separate list of all the sprites you have. That way, the spritemanager would not have to care about sprites which aren't visible.


Title: Re: Setting a transparent color in Pixie
Post by: Cycl0ne on April 25, 2011, 01:08:18 PM
Ok another design question. you know the game.
how would you store the asset of the game? You got Wall Ornates and Floor Ornates and Items. Would you store everything in a big array and traverse it everytime the player moves? or would you split it into level arrays? or would you split it to every place the player could be?

Im thinking of a big level array where i will look into it, if the player has something in sight or the player activated something. What do you think?

Oh here is a demo of the wall render engine:
http://dl.dropbox.com/u/5037811/Test.rar
 (http://dl.dropbox.com/u/5037811/Test.rar)
You can walk with cursor keys. (no turning at the moment).  And you can switch the light by pressing X and C.. (from 8 to 0 and back).

Oh and no collision detection. if you move out of map, you will allways see walls ;-)