Sprite Engine Problem

SGDK only sub forum

Moderator: Stef

Post Reply
Joe Musashi
Interested
Posts: 17
Joined: Sat Oct 13, 2018 10:08 pm

Sprite Engine Problem

Post by Joe Musashi » Sat Dec 08, 2018 11:06 pm

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 5255 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 5255 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!
Attachments
SGDK_SpriteTest.zip
(6.36 KiB) Downloaded 185 times

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Sprite Engine Problem

Post by Stef » Mon Dec 10, 2018 9:22 am

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).

Joe Musashi
Interested
Posts: 17
Joined: Sat Oct 13, 2018 10:08 pm

Re: Sprite Engine Problem

Post by Joe Musashi » Tue Dec 11, 2018 9:37 pm

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.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Sprite Engine Problem

Post by Stef » Wed Dec 12, 2018 9:33 am

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 ;)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Sprite Engine Problem

Post by Chilly Willy » Thu Dec 13, 2018 2:06 am

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.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Sprite Engine Problem

Post by Stef » Thu Dec 13, 2018 9:31 am

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).

Joe Musashi
Interested
Posts: 17
Joined: Sat Oct 13, 2018 10:08 pm

Re: Sprite Engine Problem

Post by Joe Musashi » Sat Dec 15, 2018 9:38 pm

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.

Post Reply