Page 1 of 1

Sprite Engine Problem

Posted: Sat Dec 08, 2018 11:06 pm
by Joe Musashi
Hi,

I'm trying to use the SGDK sprite engine to display large sprites and ran into the problem that some of the hardware sprites are not shown correctly. This could be related to viewtopic.php?f=19&t=2873. But of course it's perfectly possible that I'm doing it wrong.

I made a test program that draws a 288x64 pixel sprite. With SGDK 1.34 the result looks like this:
SGDK.134.png
SGDK.134.png (1.79 KiB) Viewed 5420 times
With the latest SGDK master from GitHub it gets a bit better, but there still seem to be two 32x32 sprites missing:
SGDK.master.png
SGDK.master.png (1.9 KiB) Viewed 5420 times
The source of the test program is attached below.

Flags for SPR_addSpriteEx() that I'm using are SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_SPRITE_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD. I played with other combinations but had no luck.

I also tried to use only the VDP_ sprite functions to generate a big sprite out of hardware sprites manually, and that seemed to work. So in case it's an SGDK bug, it lies probably not within the VDP code.

Any ideas what could be the problem? Thanks in advance for having a look!

Re: Sprite Engine Problem

Posted: Mon Dec 10, 2018 9:22 am
by Stef
Oh it looks like you're just above one of the limit of the sprite engine:
Each (meta) sprite cannot have more than 16 internal hard sprites, this is a limitation so i can fit all visibility bit in a 16 bit variable which make sprite processing a bit faster. So here you need 18 hard sprites (which aim to the 2 missing sprites), i've to admit that 16 was in my mind already "big enough" for almost all cases :p This limitation is described in the rescomp.txt file (but i've to admit i should probably describe it in other places).

Re: Sprite Engine Problem

Posted: Tue Dec 11, 2018 9:37 pm
by Joe Musashi
Ah that explains a lot :) Sorry, I should have read rescomp.txt more carefully. Thanks for looking.

Maybe in a future SGDK version the limit could be made configurable via config.h.

Re: Sprite Engine Problem

Posted: Wed Dec 12, 2018 9:33 am
by Stef
Maybe i should get back to the original limit (it was 20 at first) or even extend to 32 hard sprites but honestly using 32 hard sprites for a single meta sprite is a bit extreme ! At worst you can always use several meta sprite for your giant sprite but i know it somehow defeat the meta sprite feature of the sprite engine here ;)

Re: Sprite Engine Problem

Posted: Thu Dec 13, 2018 2:06 am
by Chilly Willy
Well, you have a hard limit of 80. Of course, doing that would use all the sprites for one meta sprite. :lol:

Hmm - maybe make the limit 80, set up as five words. If you use 16 or less, it uses faster code for speed (the code you have now), and if you use more, it uses more generic code that's not as fast, but handles more sprites.

Re: Sprite Engine Problem

Posted: Thu Dec 13, 2018 9:31 am
by Stef
I eventually could do that but i don't like much having different code (and actually duplicate code) depending situation (sometime you don't really have the choice though), i prefer a more generic code handling as much cases as possible. Well to be honest i think i will try to evaluate how much 16 internal sprites only is such a hurting limitation, in fact i can at least easily up to 32 internal sprites (which will have a small impact on performance).

Re: Sprite Engine Problem

Posted: Sat Dec 15, 2018 9:38 pm
by Joe Musashi
If going up to 32 internal sprites would work with little performance loss, that sounds like a good compromise. That should probably be enough in most situations.

In my current project I'm using the sprites for letters in a title screen. Here, 16 is not enough, 32 would work though. In any case, there is an easy workaround: one can just reduce the resolution in the SPRITE definition in the resource file and use more than one meta sprite for a single large object.