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.

Beginners > scrolling, tile strips, metatiles, etc

#34342 - gauauu - Tue Jan 18, 2005 7:35 am

Ok, I've been thinking about the scrolling engine for my next project, and here's what I come up with:

Use "text" or "regular" scrolling background, 512x512, using tile strip copying to allow large maps to be scrolled both horizontally and vertically.

For the map definition, I had planned on using "metatiles" similar to what a lot of old nes games did, where I define blocks of tiles (4x4 tiles) with a metatile number, and build the map out of these.

Now, here's my questions. I'm trying to think through my tile strip copying algorithms before I start, to do things efficiently. In thinking about it, I've realized that using these blocks makes the calculations for copying in a strip significantly more complicated.

1. Instead of copying 1 strip, I could copy a block (metatile) at a time. This would be fine and dandy, but seems harder to deal with when the block straddles the "wraparound" point of the map. Oh...I just had the realization that the 512 pixel background is a factor of 32, meaning the blocks will never straddle that line. Ok, next question.

2. Is it even worth it to use metatiles? My reasons for using them were:


  • To save memory storing the levels
  • To store other locational map data, like collision info, in the same logical place as the tile data
  • It seemed like it could make designing levels easier
  • I spent way too long last year trying to hack the old castlevania NES rom (of course, with no useful results)


But it seems clear that it will take more calculation to copy a row of blocks into place than it will a row of tiles.

Also, I just had the sudden realization that if I don't use a 32x32 pixel block, I can avoid having to use a bigger background (can use 256x256, with 2 tiles off the screen horiztonally at all times for strip copying). This would simplifiy the calculations of where the new tiles should end up.

Edit: I guess you only guarantee 1 tile column off the screen at a time, since you could have a portion of the left one, and a portion of the right onscreen at the same time.

Anyway, I'm confusing myself, but the question is this: does it tend to be worthwhile to use metatile blocks? Do any of you ever use them? Do commercial games tend to use them? If so, what sizes do you use?

Sorry for the rambling.

#34350 - Mucca - Tue Jan 18, 2005 12:45 pm

It could be rather ugly having your screen made of just 40 odd blocks each of a single colour or pattern. Of course it depends on the game. Also, it really only makes sense if the maps are going to be very large, which they wouldnt be for puzzlers or stuff. Plus you'll have to write your own tools for making maps.
Also, you wouldnt be able to specify mirrored tiles within a metatile without providing extra information. And text would likely be a nightmare.

#34352 - gauauu - Tue Jan 18, 2005 2:09 pm

Ok, maybe I wasn't clear enough about what I meant by meta-tile blocks. The block is not just a huge set of the same tile repeated, but a definition of 4x4 tiles, to make a bigger piece of the puzzle. Then, I would use lots of different metatiles to build the map.

For example, in castlevania, one "meta-tile" is 2 squares (like the platform squares you stand on), and the blank space above them. Or 4 squares for making a solid wall, etc. The maps are built from sets of these meta-tiles.

You're right, I would have to build my own level tools, but I just assumed I would be stuck building them myself anyway, to get the specifics that I want. :)

As far as text, I will use a separate background, with separate functions for outputting text.

#34364 - poslundc - Tue Jan 18, 2005 3:30 pm

I think meta-tiles are an optimization, and as such are best left until they prove themselves a necessary one. Also, while they haven't been made entirely obsolete on the GBA, they are definitely less important as optimizations go than they might have been on older platforms.

Unless from the nature of the game it is plainly evident that you will need or benefit from them, use the GBA's default 8x8 tiles and either find or write a map editor that lets you select the larger, repeated combinations of tiles as the "brush" that you paint your map with.

Dan.

#34366 - Mucca - Tue Jan 18, 2005 3:53 pm

Quote:
The block is not just a huge set of the same tile repeated, but a definition of 4x4 tiles, to make a bigger piece of the puzzle. Then, I would use lots of different metatiles to build the map.


Yeah thats what I meant - you define a library of metatiles for each tileset, which is essentially 32 bytes (for 32x32 text-layer metatiles) per metatile, and for your map entries you simply have an index into this array of metatiles. When you copy to VRAM you drag the information from the correct index (and maybe only a subset of the 32 bytes at that index) to the correct position in the VRAM map. Since in your map you can only specify 5 metatiles per screen column, and 7.5 metatiles per screen width, you'll only be able to see around 37.5 or 40 seperate 32x32 'tiles' or patterns on screen at any one time. Lets say you use an unsigned short for metatile index, you save 1920(~93% or obviously 15/16) bytes of space per 256x256 map block, minus 32 bytes for every unique metatile. So if you're using big maps with plenty of repitition (at least ~7% or 1/16 to make any saving ) of metatiles you'll save bags of space, at the cost of appearance as far as Im concerned (repitition is much more noticeable in metatile maps than normal maps), and probably at a slight performance cost. Plus if you're going to write a seperate system for text anyway, Id be inclined to just write a good 8x8 system that you can use for both text and levels, and seperate map and tile information (graphics) from collision information (logic).

#34385 - Miked0801 - Tue Jan 18, 2005 8:30 pm

We've used 4x4s in our engine since DMG (GB Blak and white) days. It made a lot of sense then due to severe char/memory restrictions. Same of GBC. On GBA however, while we still use 4x4s, they don't save nearly as much - especially now that we've switched to a dynamic char loading system basically allows every char on the map to be unique. The good news is our meta map compresses 99.9999% (0,1,2,3,4,5,... compresses to next to nothing), the bad news is that it just isn't needed with this style of map.

Long story short, don't use meta blocks unelss you intend to repeat alot of chars / meta tiles in your maps (and you are using extremely small cart sizes.) They'll slow doen your rendering for a modest to non-existant gain in cart size.