Changing order of meta sprites per frame

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: Changing order of meta sprites per frame

Post by Vectrex2809 »

tokumaru wrote:The main problem with simply inverting the order is that the sprites in the middle of the list are always disfavored, never having a chance to be at the top of OAM, meaning they'll flicker more than the others, or even disappear completely, if more than 16 sprites are lined up.
That's exactly why I mentioned the "appeal" of RNG-based flickering, but there aren't many cases where there are more than 16 sprites per scanline in the game I'm doing. I don't think those happen in other games either, except maybe games that can have huge or long sprites (Like Godzilla and Adventure Island)
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Changing order of meta sprites per frame

Post by tepples »

DRW wrote:With tepples' method, I see this as the problem:
if objid >= 6: continue
This means that the loop might go longer than necessary, doing steps where nothing is processed at all.
But those steps should complete much faster than steps where something is drawn. So yes, there's some overhead but not too much.
Is there one that gives the best results and is also the fastest? Or do I have to do a comrpomise between speed and equal distribution of the sprite entries in the various frames?
Premature optimization is a root cause of all kinds of evil. Make it work, then make it fast.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Changing order of meta sprites per frame

Post by rainwarrior »

DRW wrote:The problem though in this case is: The index increment uses a modulo. But this is only fast if you have 2, 4, 8, 16 etc. items, right?
But this isn't necessarily a given in my case. What if I have five characters?
i = (i+p) % 5
I did address this exact case in my earlier post:
rainwarrior wrote:Any modulo will work, the key word is relatively prime. Any number relatively prime to the modulo can be used for the increment. For 5 that is: 1,2,3,4.

Powers of 2 are convenient for modulo, but non-power of 2 can work OK:

Code: Select all

i += p;
if (i >= 5) i-= 5;
This only takes 3-6 more cycles than a bitwise AND, probably not a deal-breaker.
User avatar
DRW
Posts: 2070
Joined: Sat Sep 07, 2013 2:59 pm

Re: Changing order of meta sprites per frame

Post by DRW »

rainwarrior wrote:I did address this exact case in my earlier post:
Oops. Sorry, I've overlooked this. Yeah, you're right. This one would work.

Alright, thanks for your help. I guess I'll try it all out a bit and then I decide which version I take for my game.
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg
Post Reply