keeperfx icon indicating copy to clipboard operation
keeperfx copied to clipboard

Tunnels displaying correctly in low walls mode

Open Spatulade opened this issue 1 year ago • 2 comments

See https://discord.com/channels/480505152806191114/648319840288768000/1305891716133421127

Tunnels (i.e. columns with empty cubes inside but solid cubes above) don't display properly in low walls mode. I want to make them display correctly in low walls mode so they don't look weird and potential spoil secrets.



The aim is (for a standard 5-high column) to put the top of cube 5 onto cube 2, and display cubes 1 and 2.

image image

I've tried to find code for low walls mode but I just can't seem to find it. Wall height seems to be video_cluedo_mode, but I can't find any code, just toggles.

The only thing that seemed to help is find_column_height, which seems to treat the height as "how many solid blocks are there connected to the floor?", so for a cave with a hole in like in the pictures, it treats the height as 1 or 0. Maybe that's why it's not working - it's reading the height of these examples as 0 or 1. I'm going to see if this works, and if not hope someone can point me in the right direction.

Spatulade avatar Nov 18 '24 23:11 Spatulade

Maybe main.cpp#L3097 or main.cpp#L3118 ?

walt253 avatar Nov 19 '24 00:11 walt253

I've been doing a lot of reading and some tests and I'm not sure what I'd need to fix to get this to work - the lines in question we were looking at are fill_in_points_cluedo in engine_render.c:

if ((mask_cur >= 8) && ((mapblk->flags & (SlbAtFlg_IsDoor|SlbAtFlg_IsRoom)) == 0) && ((col->bitfields & CLF_CEILING_MASK) == 0))

The first part checks for cube[3] or higher, the second checks it's not a door or room and the third avoids ceiling mask collision issues. I tried changing the first part to checking if the cubes in any of those positions were nonempty and it made no difference. Removing the third part caused all sort of graphical issues. The second part is what worries me:

Here I've tried all column combinations up to height 5, and the only ones which are affected are the solid columns of height 4 or 5. This tells us either:

  • solidmask isn't pulling data correctly (which I doubt, it checks the ids of each cube and makes a binary representation of whether those cubes are solid or not)
  • Or more likely - it's something built into how the game works at a fundamental level, and the game works off the assumption that all columns are solid. This is why I reckon the middle part ((mapblk->flags & (SlbAtFlg_IsDoor|SlbAtFlg_IsRoom)) == 0) exists: The team were aware that low walls weren't working for columns with gaps in them, and to avoid it looking weird for the two cases of columns with gaps in (Portals and open doors, where the solid columns would shrink and the ones with gaps wouldn't), columns of those types were excluded. Basically every column check looks at the height as the number of solid cubes from the bottom before a gap, where the top of that is the 'floor', and the first nonempty cube above that is the 'ceiling', and so maybe the game is fully coded around the assumption that every column is solid.

I'm hoping this isn't the case, and there's some other piece of code that will just magically fix this, but I don't know. My guess (if it's actually a fundamental issue) is something to do with col->bitfields and how floor and ceiling heights and block heights are stored there.

I've thrown out all sorts of ramblings on Discord about it all, but I'm really not sure what else I can do. I'm hoping someone with more experience can either identify the code that's causing the issue, or suggest ways to probe for the right info (e.g. checking the solidmask for columns or seeing what bitfields looks like for some examples and what CLF_CEILING_MASK looks like).

Edit: The only other idea for how to work with this if it really does only work for solid columns is to make some sort of "dummy air cube" which is treated as solid by some checks and empty by others, i.e. most things consider it solid but creatures can work through it, although I don't know how that would work, as I don't know exactly what causes the issue: solidmask seems to work but I haven't probed the solidmask number for some test columns to see if it gives back what we need, and most checks seem to also be used for drawing the floor etc

Spatulade avatar Nov 21 '24 23:11 Spatulade