gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > FIFO

#531 - lordmetroid - Wed Jan 08, 2003 2:47 pm

I'm in the middle of creating my dynamic tile engine.

And thought that it would be smart not to overwrite a just rescently used tile from VRAM, in case it will be reused in a small amount of time...

So I decided to have a FIFO array, that keep track of what phys tile is representing the logic tile, together with a lock counter...

The array needs of course to overwrite itself or else it would go throught the whole memory destroying all other data in it's path.

The problem is I never done any FIFO system before, so how do one do?
_________________
*Spam*
Open Solutions for an open mind, www.areta.org

Areta is an organization of coders codeing mostly open source project, but there is alot of sections like GBA dev, Language learning communities, RPG communities, etc...

#538 - Touchstone - Wed Jan 08, 2003 3:11 pm

Just think of your FIFO buffer as a circular buffer.
Code:
const int g_FIFOSize = 10;
char g_pFIFO[g_FIFOSize];
int g_FIFOCurrentPos;

void FIFOInit()
{
   g_FIFOCurrentPos = 0;
}

void FIFOAddEntry(char _Entry)
{
   if (++g_FIFOCurrentPos == g_FIFOSize)
      g_FIFOCurrentPos = 0;

   g_pFIFO[g_FIFOCurrentPos] = _Entry;
}


Obviously it can be implemented differently but the idea is that a FIFO buffer is just a circular buffer.
_________________
You can't beat our meat

#541 - Splam - Wed Jan 08, 2003 4:35 pm

FIFO isn't really the best way to do this as you could throw a load of tiles out when they hit the end of the buffer then suddenly need them again. One thing I've always done is allow some space for tiles that are there a large amount of the time and they never get changed, then you can do things like read ahead slightly as you're drawing the new row/column to see whats coming up or even have an extra part of your map data thats predefined (in the map editor or wherever) that has the frequency of the tiles being used, then they're less likely to get kicked out of vram if they're on screen 90% of the time (or however often).

I had to do one of these for a playstation game a while ago, if I can find my source I'll have a look at exactly how I did it.

If you want to get really crazy you can use processor time when no new tiles are needed in vram for that frame to jiggle some of the others around so the next time you have to copy some in you only need 1 dma instead of lots of small ones.