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.

DS development > Is there a work-around to break the 1024 unique tile limit?

#94913 - thundrestrike - Wed Jul 26, 2006 9:02 pm

Hello,

Is there a work-around for breaking the 1024 unique tile limit [Palib]?

Or do we have to wait for a new release that includes this?
_________________
popcorn

#94929 - Sausage Boy - Wed Jul 26, 2006 10:30 pm

It's a hardware limitation. If you want to work around it, use libnds with some trickery.
_________________
"no offense, but this is the gayest game ever"

#94930 - tepples - Wed Jul 26, 2006 10:36 pm

Only 33x25 = 825 unique tiles can be visible on each layer of each screen at once. Why do you need more than 1,024?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#94935 - LiraNuna - Wed Jul 26, 2006 10:56 pm

There is a workaround that i only planned to code for ToD2...
Here's the basic pseudocode for it:
Wait a sec... are you using PAlib? forget what i said.

Edit: I'm not evil...
Note: this code hadn't been tested, and could get re-written way better.
dynamic tiles pseudocode:
Code:
// revision two

array of 1024 u32's. position represents tile index in RAM, value is the virtual tile

variables:

unsigend number to represent current tile avaliable on VRAM
unsigned number tilearray of size 1024

clear tiles array
for all visable area on screen {
   if tile to be placed is not on array
      copy tile to VRAM in offset current tile on VRAM
      mark current tile on VRAM as used
      increase current tile variable
      
   place tile index to map from array
}

_________________
Private property.
Violators will be shot, survivors will be shot again.

#94959 - dovoto - Thu Jul 27, 2006 12:59 am

First pass (basicaly the method Lira is suggesting i believe):

Code:

Create an array of u16 that is the size of the number of unique tiles in your world and zero it out. (lets say indexLookup[] )

Clear tile memory and map memory in vram.

Load the visable portion of the map as follows:
 
tileCount = 0;

 for(x is left to right) 
      for (y is down to up)
{
   index =  get the index from your map based on current x and y;
   
   if(indexLookup[index] == 0)
   {
       Load tile graphics into background tile graphics memory at an offset  of  tileCount * sizeof(tile);

       vram_map[index by x and y] = tileCount | your tile flags;

       indexLookup[index] = tileCount++;
   }
    else //tile graphics are allready in memory
   {
         vram_map[index by x and y] = indexLookup[index] | your tile flags;
   }
}

Repeate each frame


This method is simple but you will notice you have to copy in tile graphics for every tile every frame (doable if you dont have much else going on in your game).

A bit better approach:

Code:
Create another table called UsageCount of the same dimesions as your index lookup. 

Dont clear the lookup table or memory.

look only at the row and column coming onscreen due to scrolling.  Still use the indexLookup and if it is zero load your tile (but a bit different now) and if it is not zero just set the map index to the lookup value.

To load the tile you will need a stack of available tiles.  There are template classes in the STL or you can just roll your own stack struct.class.  It will simply maintain a list of offsets into tile graphics memory and allow you to pop them off as needed and push them back on when you are done with them.  So:

tileGraphicsPointer = Tilestack.pop();
copy(myTileGraphics[index], tileGraphicsPointer, sizeof(tile));

Every time you add a certain index to the map increment that index?s UsageCount (usageCount[index]++).  This will keep track of how many of any given tile you have on screen.

Now process all the tiles that went off screen and decrement the usageCount[index] for those tiles.  This will actually require you to have another lookup table that maps on screen map index to your own index (inverseIndexLookup[] would be a good name)?

If the usageCount for that index gets down to 0 push its tile graphics slot back onto the stack so it can be reused.


This ensures only the tiles you need are actually loaded into memory, and only the new tiles coming on screen are processed. This of course is quite a bit more complex.

Hope this was not too terribly confusing.
_________________
www.drunkencoders.com

#94967 - thundrestrike - Thu Jul 27, 2006 1:37 am

ok ill let you guys know the reason behind this

If you guys can remember "VGMDS" [Virtual Game Maker DS]
The RPGMaker system for the Nintendo DS developed by Globoeil

It is still progressing, and it is very good so far!
He needs to break the 1024 unique tiles limit in order to achieve working custom chipsets. For more information and to see how its going so far, visit the Main Forum .

The next version is on the verge of releasing.
Just so you know, I am the main tester of VGMDS, not the coder.
The coder is Globoeil!

I will give him a link to this very topic.
Thank you guys!
-Thundrestrike
_________________
popcorn

#94973 - tepples - Thu Jul 27, 2006 3:29 am

You can get 2048 tiles if you use two backgrounds, and then you can just dynamically reload them as you scroll.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#94994 - Valmond - Thu Jul 27, 2006 7:38 am

I'v written a couple of small "libraries" for tiles and sprites that
handles them dynamicly (read streaming data) so I'm no longer
bothered by limits like 128 sprites per level or 1024 tiles per game.

It works okay, some features are missing but I can put em up on
my website if people are interested.


Check out the my signature to see them in work^^

/Valmond
_________________
N?fer & LudLib

#95073 - DynamicStability - Thu Jul 27, 2006 6:39 pm

Cool thread, thanks for the procedures Liran and Dov. I'd like to take a look at that code Valmond! I'll have to try your game too.
_________________
Framebuffer is dead.
DynaStab.DrunkenCoders.com

#95095 - Valmond - Thu Jul 27, 2006 8:49 pm

Added a page for downloads on my "site".

feel free to bug me about stuff that doesn't work^^

/Valmond
_________________
N?fer & LudLib

#95304 - DynamicStability - Fri Jul 28, 2006 5:38 pm

I'll try it out, thanks.
_________________
Framebuffer is dead.
DynaStab.DrunkenCoders.com