#45168 - SmileyDude - Wed Jun 08, 2005 5:24 am
hello,
I'm playing around with some larger images implemented using sprites on the GBA. I'm currently trying to figure out a way to calculate the optimal sprite sizes to use to cover the entire image. I want to use the least possible amount of OAM entries for each image, and the image can have multiple areas where it is transparent for an whole tile. Being that it's transparent, I really don't want to have it be a part of a sprite.
So, basically, what I am looking for is an algorithm that can take a tilemap, and spit out a set of sprite sized rects (64x64, 64x32, 32x32, 32x16, etc, etc, etc) that are optimally packed into that area while working around the transparent tiles.
As an example, lets say I have the following tilemap:
The XX marks the transparent tiles. If I wanted to break these up into OAM entries, I could make a 32x32 chunk that would take up this space:
Then, I could use a 32x16 chunk:
and a 16x16 chunk:
followed by a 6 8x16/16x8 chunks to fill in the rest:
That would use 9 OAM entries to display that entire image. I don't know if that's the most efficient way to set those tiles up in OAM, but it certainly would work. Hopefully, a computer would be able to try other combinations out to find possibly more efficient ways to pack them.
What I am trying to accomplish is that I want to conserver OAM entries, because there will be multiple images on the display at once, and it's possible that I might get really close to the 128 limit. I also want to avoid having to copy transparent tiles into VRAM just to fit them into the sprite for two reasons. One is the overhead in copying an empty tile. The other is to conserve space in VRAM. Otherwise, I would just simply make the sprites 64x64, and make some multiple to cover the entire image. Basically, I want to be able to copy as little as possible from the cart to VRAM when I change the image.
I plan to do this processing when building the program -- not at runtime. The pre-processing would basically build a tileset, and OAM entries ready to load (well, mostly ready -- only minor tweaks at runtime, like different tile numbers to reflect where the tiles actually loaded into VRAM, etc, etc). The runtime would load the tiles required for the image, load the OAM entries, and be done.
I did some google searching on optimal rectangle placement algorithm. There might be something there, but I'm still digging through it. Any suggestions would be appreciated.
_________________
dennis
I'm playing around with some larger images implemented using sprites on the GBA. I'm currently trying to figure out a way to calculate the optimal sprite sizes to use to cover the entire image. I want to use the least possible amount of OAM entries for each image, and the image can have multiple areas where it is transparent for an whole tile. Being that it's transparent, I really don't want to have it be a part of a sprite.
So, basically, what I am looking for is an algorithm that can take a tilemap, and spit out a set of sprite sized rects (64x64, 64x32, 32x32, 32x16, etc, etc, etc) that are optimally packed into that area while working around the transparent tiles.
As an example, lets say I have the following tilemap:
Code: |
+--+--+--+--+--+--+--+--+--+
| | | | | | | | |XX| +--+--+--+--+--+--+--+--+--+ | | | | | | | | |XX| +--+--+--+--+--+--+--+--+--+ | | |XX|XX| | | | | | +--+--+--+--+--+--+--+--+--+ | | | |XX| | | | | | +--+--+--+--+--+--+--+--+--+ | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ |
The XX marks the transparent tiles. If I wanted to break these up into OAM entries, I could make a 32x32 chunk that would take up this space:
Code: |
+--+--+--+--+--+--+--+--+--+
| | | | |OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ | | | | |OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ | | |XX|XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ | | | |XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ |
Then, I could use a 32x16 chunk:
Code: |
+--+--+--+--+--+--+--+--+--+
|AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ |AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ | | |XX|XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ | | | |XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ |
and a 16x16 chunk:
Code: |
+--+--+--+--+--+--+--+--+--+
|AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ |AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ |BB|BB|XX|XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ |BB|BB| |XX|OO|OO|OO|OO| | +--+--+--+--+--+--+--+--+--+ | | | | | | | | | | +--+--+--+--+--+--+--+--+--+ |
followed by a 6 8x16/16x8 chunks to fill in the rest:
Code: |
+--+--+--+--+--+--+--+--+--+
|AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ |AA|AA|AA|AA|OO|OO|OO|OO|XX| +--+--+--+--+--+--+--+--+--+ |BB|BB|XX|XX|OO|OO|OO|OO|HH| +--+--+--+--+--+--+--+--+--+ |BB|BB|DD|XX|OO|OO|OO|OO|HH| +--+--+--+--+--+--+--+--+--+ |CC|CC|DD|EE|EE|FF|FF|GG|GG| +--+--+--+--+--+--+--+--+--+ |
That would use 9 OAM entries to display that entire image. I don't know if that's the most efficient way to set those tiles up in OAM, but it certainly would work. Hopefully, a computer would be able to try other combinations out to find possibly more efficient ways to pack them.
What I am trying to accomplish is that I want to conserver OAM entries, because there will be multiple images on the display at once, and it's possible that I might get really close to the 128 limit. I also want to avoid having to copy transparent tiles into VRAM just to fit them into the sprite for two reasons. One is the overhead in copying an empty tile. The other is to conserve space in VRAM. Otherwise, I would just simply make the sprites 64x64, and make some multiple to cover the entire image. Basically, I want to be able to copy as little as possible from the cart to VRAM when I change the image.
I plan to do this processing when building the program -- not at runtime. The pre-processing would basically build a tileset, and OAM entries ready to load (well, mostly ready -- only minor tweaks at runtime, like different tile numbers to reflect where the tiles actually loaded into VRAM, etc, etc). The runtime would load the tiles required for the image, load the OAM entries, and be done.
I did some google searching on optimal rectangle placement algorithm. There might be something there, but I'm still digging through it. Any suggestions would be appreciated.
_________________
dennis