4 bytes can pack a whole lot.
Posted: Fri Mar 26, 2010 12:38 pm
So after I saw Falco talk about having his tile just be a char that indicates what the texture was, I started to think how much data can you actually pack into a small package.
At first i used a short (thats 2 Bytes), but felt I didn't give me everything I needed, so I used an int. (4 Bytes.)
Okay, so lets see what we would like out tile to have. (I'm not worried about location because you should be able to deduce that depending on your tile size and position in your array)
- texture info
:I'm gonna take a page from Falco and give it 1 byte, that give me 256 possible textures.
- collision info
:there are the two simple cases of solid or no collision, then there are 6 other possible one, each edge of the tile, and two diagonal.
so 3 bits are enough to represent this.
- elevation info - (like stairs and ramps)
if a tile is a stair or a incline, it will go up in one of 3 direction, left,right or up, (down would be hard to make a tile that looked good, or even to spot stairs, so im going to omit that on)
so 2 bits for this 00 no ele, 01 left, 10 right, 11 up.
- height info - (how high above the bottom a tile is)
for this i would give it 5 bits, thats 32 levels, but they way i would make it is that each level is 64 pixels, (cause your character is probably 32*64), but each height level is only 32, this just makes the transition on stairs not so abrupt. so we only end up with 16 real levels, which is still plenty.
- lighting data
5 bits will give you 32 levels of lighting.
- indoors or outdoors - (if you are indoors you don;t wanna draw any layers above, like the roof or floors above you..)
only 1 bit needed for this.
so out total comes out to 24 bits for that, leaving us with 8 bits or a byte that can still be used for something else. lighting color, or teleport info.
You would have to know a bit about how to work with bit wise operators but its not to hard. (for most systems this really is not necessary, but i still think a pretty good thing to learn about)
At first i used a short (thats 2 Bytes), but felt I didn't give me everything I needed, so I used an int. (4 Bytes.)
Okay, so lets see what we would like out tile to have. (I'm not worried about location because you should be able to deduce that depending on your tile size and position in your array)
- texture info
:I'm gonna take a page from Falco and give it 1 byte, that give me 256 possible textures.
- collision info
:there are the two simple cases of solid or no collision, then there are 6 other possible one, each edge of the tile, and two diagonal.
so 3 bits are enough to represent this.
- elevation info - (like stairs and ramps)
if a tile is a stair or a incline, it will go up in one of 3 direction, left,right or up, (down would be hard to make a tile that looked good, or even to spot stairs, so im going to omit that on)
so 2 bits for this 00 no ele, 01 left, 10 right, 11 up.
- height info - (how high above the bottom a tile is)
for this i would give it 5 bits, thats 32 levels, but they way i would make it is that each level is 64 pixels, (cause your character is probably 32*64), but each height level is only 32, this just makes the transition on stairs not so abrupt. so we only end up with 16 real levels, which is still plenty.
- lighting data
5 bits will give you 32 levels of lighting.
- indoors or outdoors - (if you are indoors you don;t wanna draw any layers above, like the roof or floors above you..)
only 1 bit needed for this.
so out total comes out to 24 bits for that, leaving us with 8 bits or a byte that can still be used for something else. lighting color, or teleport info.
You would have to know a bit about how to work with bit wise operators but its not to hard. (for most systems this really is not necessary, but i still think a pretty good thing to learn about)