Having Another Jab at a Camera System

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
tokumaru
Posts: 12645
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Having Another Jab at a Camera System

Post by tokumaru »

Sogona wrote:I already asked about this in another thread, but from what others have said it seems to be more involved when there's scrolling. After thinking about it for a bit, though, isn't the only difference really that you're working with 16-bit values instead of 8-bit?
Yeah, the size of the level shouldn't matter much, you just have to know WHERE to find the collision data for any given block, based on level coordinates. As long as you can manipulate level coordinates in a way that allows you to traverse the data structures you need to in order to find the collision attributes for the block under those coordinates, it'll work.
I think I want to try and have collision data work like attribute data, where there can be four different types of collisions (Nothing, solid, death, something else) and 4 16x16 pixel blocks can be packed into one byte.
Could "something else" be water? Personally, I think that 4 types is too little. What if in the future you decide to add ice, lava, conveyor belts, spikes (only one side hurts), slopes, and so on? I'd reserve AT LEAST 4 bits for the type. You can get by with 2 bits in a basic game, but it's not very expansible.
So for each room there could be a pointer table for the collision data for each screen.
Here's another thing I'd do differently... I'd much rather have the collision information be an attribute of the metatile. Think about it: a metatile is likely to ALWAYS have the same solidity ANYWHERE it's used. If it has rocks on the bottom and grass on the top, it'll probably ALWAYS be solid, so think about all the ROM space you'll waste specifying that - EVERY - SINGLE - INSTANCE - of that metatile is solid. Each time you use any metatile, anywhere, BAM, 2 bits lost. Use the same metatile 4 times and you already wasted 8 bits on it, enough to specify 256 different types if you stored that information in the metatile itself rather than in a separate map. And I bet that most metatiles will be used way more than just 4 times!

If you actually needed a metatile to be solid in some places but not others for some reason, you'd waste much less space by creating a duplicate metatile that looks the same but has different collision information, but I honestly doubt that would happen much. For consistence, you generally want things that look the same to behave the same, otherwise you'll confuse the player.

Another advantage of making the solidity an attribute of the metatile, besides not having to painstakingly draw/type an overlay collision map for every room of every level, is that you can reuse the code you already wrote to fetch tiles for scrolling. You already have the working logic to locate metatiles in the level map, so you can use the exact same logic (if not the exact same routine(s), depending on how exactly you implemented the scrolling) to find them, the only difference is that when you do, you'll not read its tiles or palette information, but its collision information.
User avatar
Sogona
Posts: 186
Joined: Thu Jul 23, 2015 7:54 pm
Location: USA

Re: Having Another Jab at a Camera System

Post by Sogona »

I guess this means I'll have yo get rid of my RLE format :|
User avatar
tokumaru
Posts: 12645
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Having Another Jab at a Camera System

Post by tokumaru »

It was just a suggestion, you shouldn't do anything you're not comfortable doing. :) I didn't realize you were using RLE for the level data... Are you decompressing the RLE on the fly to fill the tile and attribute buffers without buffering small sections of the level first? Still, independent collision maps for the whole game would take so much space that giving up on the RLE might still result in lower ROM consumption overall... You'd have to check how much ROM the RLE compression is saving you versus how much ROM the raw collision maps take.
tepples
Posts: 22915
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Having Another Jab at a Camera System

Post by tepples »

Haunted: Halloween '85 ended up using separate collision maps consisting of a floor heightmap and a horizontally sorted list of rectangular slabs, both at 8x4 pixel resolution, and there isn't really a concept of "metatiles" because of the desire to hide the grid David Crane-style. Instead of capturing spatial correlation using metatiles, its map compression instead predicts the most common tile below each tile with a table that changes for each map. I'd have to check, but I doubt that the collision maps are larger than 8 KiB, compared to close to 384 KiB for compressed tiles and compressed maps combined. I seem to remember seeing a screenshot of some of the tools used to make Braid, which builds the floor with rotated rectangles.

But I agree that a more traditional metatile-based approach would have collision as a property of the metatile for the sake of normalization, just as the top left, top right, bottom left, and bottom right tiles are.
User avatar
za909
Posts: 264
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

Re: Having Another Jab at a Camera System

Post by za909 »

I don't think 2 bits per block is THAT restrictive if you can select from sets of four meanings based on the current stage or whatever. You'd only be restricted to using 4 block types at a time, but you could switch to a set of "Nothing/Solid/Death/Ice" when you need those, and switch to a set of "Nothing/Solid/Conveyor Belt Right/Conveyor Belt Left" for another level, and so on... I did the same thing with my controller routine to be able to select different button masks so that I can require certain buttons to be released before they count as being pressed again, because you don't want the player to be able to hold the D-pad to move a menu cursor, but during gameplay they should be able to.
User avatar
tokumaru
Posts: 12645
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Having Another Jab at a Camera System

Post by tokumaru »

za909 wrote:I don't think 2 bits per block is THAT restrictive if you can select from sets of four meanings based on the current stage or whatever. You'd only be restricted to using 4 block types at a time, but you could switch to a set of "Nothing/Solid/Death/Ice" when you need those, and switch to a set of "Nothing/Solid/Conveyor Belt Right/Conveyor Belt Left" for another level, and so on...
I think that's still pretty restrictive, considering that "nothing" and "solid" are mandatory for every level, so you actually only have 2 dynamic slots. And it makes the engine needlessly complicated by requiring it to indirectly look up the correct response to each type of block instead of reacting right away. It's not bad to the point of being prohibitive, but hardly justifiable if you can save space through other means.
I did the same thing with my controller routine to be able to select different button masks so that I can require certain buttons to be released before they count as being pressed again, because you don't want the player to be able to hold the D-pad to move a menu cursor, but during gameplay they should be able to.
That's... not the same thing at all. For the controller you just need a couple of bitwise operations to interpret button presses differently, while configurable collision responses would need a much more complex system, with jump tables and the like. In fact, interpreting button presses differently is so quick that most games I checked just read the controllers all possible ways all the time: there's a byte indicating the buttons that are currently pressed, another indicating which were just pressed, and yet another indicating which were just released. This is useful because even during gameplay you want some buttons to work continuously, like the arrows that move left and right, and others to work only on transitions, such as the action buttons for jumping and shooting. If you have all the different states available, it's just a matter of having the code that handles each action check the appropriate byte.
User avatar
Sogona
Posts: 186
Joined: Thu Jul 23, 2015 7:54 pm
Location: USA

Re: Having Another Jab at a Camera System

Post by Sogona »

Thank you all so much for your help, I really do appreciate it. The engine's certainly come a long way from what it originally was. :wink:

I've gotten background collision detection to work with scrolling, but I decided "screw it" and made it so that objects can only have a maximum hitbox width or height of 32 pixels (For objects that have background collision, that is.), so I can just check both corners and have a hard-coded midpoint by adding both corners and dividing by two. I know, not the most versatile decision, but it's just easy. Maybe one day I'll try working with bigger, weirder hitboxes, but for now, this'll work fine.

Now it's time to work on graphics and music!
Post Reply