8x16 and whatever else unreg wants to know

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Post by Kasumi »

I have 5 torches. Each torch gives me two hours of light when lit. I light them all at once. I get only two hours of light. What gives? I should have got ten!

Yes, if your file format demands that each metatile definition is six bytes, each metatile defintion MUST use six bytes.

Metatiles save space because they store that information only once, as opposed to every time it's needed.

Let's ignore collision data and attribute data. You just want to store tiles. You have a screen that's entirely the same tile. It takes (256/8)*(240/8) = 960 bytes to define that screen.

So you decide to use a 16x16 metatile. The definition of it takes 4 bytes. But to define that same screen takes (256/16)*(240/16)=240 bytes. PLUS FOUR! Because of the metatile definition. All that data technically takes 244 bytes. But metatiles only help you as long as they can be reused.

Let's do a situation where every 16x16 area is different on the screen. With no metatiles, it still takes 960 bytes. With 16x16 metatiles it takes 240 bytes. PLUS 240*4 bytes for the metatiles definitions. 240*4+240 = 1,200 bytes. Even more than just storing the tiles.

The way you decide whether or not you need another metatile level is by figuring out if you'll be able to effectively reuse that size metatile. Else you're wasting space, not saving it. Although even in that extreme case, if you made a few more screens with those same metatiles, you would begin to save space over just storing the tiles uncompressed.

I don't even get your second thing. Yes, 64 is different than 240. It has to be the same, why? Let's say you use tokumaru's 6 byte metatile plan. The attributes are defined already. So is the collision data. The metatile exists so that stuff never takes up extra space beyond the actual metatile definitions. So when you're storing a screen, it takes 240 bytes. The metatiles themselves only take up space for each unique one created. It could be exactly one, and you only add 6 to the 240. You could even define each 16x16 tile with a format that stores info for speed manipulation and other stuff where each metatile takes up 8 bytes. Each screen by itself would still only take 240 bytes.

Edit: tl;dr The metatile definition takes up X bytes. In this case 6. After that, each time the metatile is used in a structure (be it in a larger metatile or a screen or whatever) takes one. That one is the byte that refers to the metatile.

So if the metatile is used more than X times, you save space for that metatile.

I tell you this, because I'm not sure you understand all of this. Though, honestly I doubt we're doing you favors by offering so much help. I truly believe you can figure a lot of this out, if you think about it. It's a decision. If you "invest" in metatiles do you "save money" in the long run? If you don't know the answer, you may be able to figure it out with a calculator and some logical thought. I also think you are progressing too quickly, without fully understanding what you're actually doing. If the stuff we're talking about is going over your head, you need to go back to more basic things until you fully understand those.

It has been mentioned before, but I also find your mentions of God unnecessary. It's wonderful that you believe. But it could be off putting to Hindus or atheists or agnostics or whoever else may want to offer you help. Especially when you mention God actually speaking to you in your mind as was mentioned earlier in this topic which might even make fellow Christians do a double take. I would say it would make some less willing to help, and it certainly doesn't encourage help in those who would have already helped you. So since it's definitely not related to the topic at hand, and mentioning it probably lowers rather than raises the amount of help you get, does it really need to be mentioned?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

I agree with everything Kasumi said.

unregistered, you seem to be very confused. It appears that you are trying to define all that data for each individual screen, which would require a lot of memory and result in no compression at all... in fact it would just make the screen need even more memory.

Metatiles work kinda like LEGOs. Every time the company needs to create a new kind of brick, they have to design it, make molds for it, etc. That's analogous to defining a metatile. After created, the new type of brick has a code (like the metatile has an index), and based on this code the company can easily create new bricks of that kind using the molds that were previously made, so the only expense is the plastic needed for the new piece. If you ask them "hey, make me a XFYZ54KV brick", they know which brick you're talking about, and they can make one for you at any time. Without that code it would be much harder, you'd have to describe the shape, dimensions, color, etc. of the brick, and they'd have to build an assembly line for it. Can you imagine how freaking expensive LEGOs would be if they had to go through all this process for each individual brick?

Metatiles are just like that. The initial definition takes up a lot of resources (memory), but once you have your dictionary of metatiles ready, you can reference them using very little memory (just a byte with a metatile index).
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Thank you both Kasumi and tokumaru! :D I've read each of yall's posts more than 11 times... over these days.

Kasumi, now I understand everything you talked about! :)
Kasumi wrote:But, metatiles only help you as long as they can be reused.
We have decided to make a metatile dictionary for each level in our game. Is that normally what people have done in the past? ...It'd be quite hard for us to make just one large metatile dictionary for all of our levels. My sister has created 190 metatiles for most parts of level 1. We figured we'd store each level's metatile dictionary in a separate file.

tokumaru, I have been scared to define 5 parts of a metatile cause it seems that with each new part, beyond the first 4, would be making the metatile more complicated... and so it would take more metatiles to meet the immensley detailed needs of the game. More metatiles woould be, not good, and awful, I think. But, now I'm hoping that, after defining a palette part of a metatile, we could use the palette part independent of our use of the first 4 definitions... so the index number would mean different things depending on how it is used. Does that make sense?

Kasumi, I was worrying about only having 64 palette entries... much fewer compared with the rest of our metatile definition. Well, maybe it, using a max index of 64 for the palette part and having a larger maximum index of 240 for the remaining parts of the metatile definition, would be ok? :)

tokumaru, your lego analogy is awesome and easy to understand! Thanks for introducing me to these ideas! :)
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Post by Kasumi »

That sounds like a lot of metatiles for just one level. I'm actually restricted to sixty-four 16x16 metatiles per set so I can just store the palette for each one in the two high bits.

8x8 tile $00 is a solid square. My 16x16 metatiles are defined in 5 bytes.

For 16x16 tile 0, the bytes are $00, $00, $00, $00, $00. (The fifth byte deals with its collision, but I won't go into how my collision works. Very game specific)

When I want to use that metatile, I can use 4 different numbers. $00, $40, $80, or $C0. They all refer to metatile 0, but will change what color it's displayed as. If a lot of your 190 metatiles are just the same 8x8 tiles with different palettes, you can save a bunch of bytes by not storing the repeats of ones that store the exact same 4 8x8 tiles and just change the palette information. Best case scenario savings for you would be 143 metatiles (3/4 of them) * 6 bytes (since those definitions aren't needed anymore, if they're just alternate palettes). And then you can save another 143 bytes because the palette information no longer needs to be defined with the metatile.

Of course that only works if less than 65 of your 16x16 metatiles are unique except for palette information. Just something to think about it.

Edit: And making a metatile dictionary for EVERY level is probably not wise. You have 190 metatiles for level one. That's 1,140 bytes, or more than a kilobyte. If that's the average for your levels, JUST for metatile definitions that seems pretty big.

Sonic games have two acts that (appear to) share the same tileset. And say... Mario Bros. 3 has the grass one it uses for sloped levels, and a generic overworld etc. It's good to have variety, but a different one for every level seems extreme, especially considering how little NES can even hold in CHR data.

tl;dr: Making a few for different areas is great, but one for every level is definitely extreme.

Edit 2: I have no idea what you mean by "only 64 palette entries". If you have 190 metatiles, you have 190 bytes that define the palette of the metatile using tokumaru's format. My format uses no bytes for palettes, since there are only four possibilities at any one time and I can afford to not have more than 64 different 16x16 metatiles per level.

There are 64 colors you can put in the 4 slots each palette set. But that shouldn't affect your metatile definition or anything else, since your metatiles can only choose the set, not the colors.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Kasumi wrote:That sounds like a lot of metatiles for just one level.
I don't think that's too much. It really depends on the look you're going for... If you want to make the metatile grid less obvious to the player, you can end up with a fairly big amount of metatiles, especially on the NES, that doesn't allow flipping of background tiles.

Maybe we could circumvent the lack of background tile flipping by allowing the metatiles to be flipped anyway, and automatically adding a fixed offset to the tiles' indexes to locate the flipped versions. When designing the CHR you'd have to place the flipped tiles at the correct places, but the ability to flip metatiles would probably reduce the total amount in games with more complex geography.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tokumaru wrote:
Kasumi wrote:That sounds like a lot of metatiles for just one level.
I don't think that's too much. It really depends on the look you're going for... If you want to make the metatile grid less obvious to the player, you can end up with a fairly big amount of metatiles, especially on the NES, that doesn't allow flipping of background tiles.

Maybe we could circumvent the lack of background tile flipping by allowing the metatiles to be flipped anyway, and automatically adding a fixed offset to the tiles' indexes to locate the flipped versions. When designing the CHR you'd have to place the flipped tiles at the correct places, but the ability to flip metatiles would probably reduce the total amount in games with more complex geography.
We just had a long great conversation about only having basic metatiles and 2 bit VH flipping. She is going through level 1's 190 metatiles and discarding all the flipped tiles... we are seeing how many metatiles we could save. We don't understand your way of redesigning the CHR cause the CHR uses 8x8 tiles; we think :) we are dealing with flipping 16x16 metatiles.--
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

unregistered wrote:We don't understand your way of redesigning the CHR cause the CHR uses 8x8 tiles; we think :) we are dealing with flipping 16x16 metatiles.--
Well, if you're gonna flip the metatiles, you have to flip all 4 of its tiles, right? Say that you used a bit to indicate that a metatile is flipped horizontally. You'll put the two tiles from the left half in the right side and vice-versa. But you also need to flip the pattern, something that the NES can't do. My solution was to place the flipped tiles a constant number of tiles ahead of the original tile, so that you can simply add this number to the tile indexes in order to find the indexes of the flipped tiles.

You should do this only for the tiles you'll actually want to flip, because if you do it for all of them you'll waste a lot of CHR space.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tokumaru, thank you for helping us! :D

And thank you for helping us Kasumi! :D The 64 metatile limit you introduced us to is too low for our game right now.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

After much discussion we have concluded that level 1 will require about 190 * 4 == 760 metatiles; we have to multiply our first value by 4 because there are 4 different palettes. You can't choose a lego and then choose its color... you have to choose a blue lego or a red one, right? And if so, is that because it would require a much larger amount of bytes?
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Post by Kasumi »

Maybe tokumaru was right in that 190 metatiles isn't too much for one level. I am just neurotic about saving bytes anywhere and everywhere I can.

But 760? I think anyone can agree that's way too much. (Since this is still just for one level, right?)

Keep in mind, you don't actually need a new metatile for all the palettes if you aren't going to USE them.

Let's say you have a metatile that represents a tuft of grass or the top of a tree. You'd want a definition of it that uses the palette with green colors, but there's no need to have one for say... a rock palette or a water palette.

Are you really going to USE all 190 * 4 of them? Because you do not seem to be doing a good job of designing around your limitations. If you want to make an NES game, you must deal with its limitations or you would be better off making a game for something that does not limit you.

Let's pretend these (bad) example tiles are detailed grass and leaf flooring: Image

Here are some metatiles you might need:

Image

Here are some metatiles you DON'T need, if you just design your levels around it.

Image

Edit: I realize $06 and $13 are identical, so the count of these would be $14. My mistake.

See how quickly things get out of control when you try to have 8x8 pixel precision with metatiles? Now let's imagine I wanted extra metatiles for all four palettes despite the fact that these are grass tiles that would look weird with other colors. (We're pretending they're detailed :) ) That's all unnecessary, they'll never be used in a level. It's okay to have SOME metatiles like $09-$15 to break the 16x16 grid sometimes. But I guarantee you don't need as many metatiles as you think.

Image

If shifting an object 8 pixels north, south, east or west in one of my levels was going to save me 6, 12, 18, or 24 bytes I would do it 98% of the time. That's room for an entire SCREEN in my game.
Last edited by Kasumi on Wed Nov 02, 2011 2:46 pm, edited 2 times in total.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

With 760 metatiles you would need to use two bytes per map cell, which increases it size twice and decreases processing speed. It makes sense to fit metatile index in a byte, thus 256 max.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Yah, 760 is too freaking much. I can't even think of a 16-bit game that needs this many metatiles, so there's obviously something wrong here.

Most metatiles can't be used with all 4 palettes. Like Kasumi said, there's no point in offering a blue variation of a grass tile, since you'll never be using that.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Kasumi wrote:(Since this is still just for one level, right?)
Yes one level... level 1.
Kasumi wrote:Are you really going to USE all 190 * 4 of them? Because you do not seem to be doing a good job of designing around your limitations. If you want to make an NES game, you must deal with its limitations...
Shiru wrote:With 760 metatiles you would need to use two bytes per map cell, which increases it size twice and decreases processing speed. It makes sense to fit metatile index in a byte, thus 256 max.
tokumaru wrote:Yah, 760 is too freaking much. I can't even think of a 16-bit game that needs this many metatiles, so there's obviously something wrong here.
No we are not going to use all 190*4 of them. Thank you Shiru, now my sister realizes that we are limited to 256 metatiles per level. :) And after a time of rethinking she has said that level 1 will really be needing a little less than 256 metatiles without changing anything. So level 1 should work, if I could get it to... 8) <-- sarcastic| She said other levels will need to be changed to meet the 256 metatile limit. Sorry yall... it took us some time to learn that we might have to multiply by 4. I made a mistake... :oops: we don't need most of those 760 metatiles for level 1.
Thank yall for answering all of my questions! :D
edit: Extra thanks to Kasumi! : )
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Read my psuedocode:

Code: Select all

1.) read list of metatiles
2.) read "start" screen
3.) display '    '
#1 isnt required because it is already listed as .db statements so all I have to do is include it.
#2 isnt required for the same reason.. i think.

So my question is about line #3. I'm worrying about changing the label names inside each list of metatiles. Is there a way to include each file without making label-name changes?
...Um that was about line #1... sorry (could you answer it though? :) )
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

What are you trying to do? Is this for selecting on the main menu "Start" or then "Continue" or something, or trying to add it to the screen like "Level one!" then a little later "Go!" or something on the screen?
Post Reply