devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

Optimize floor drawing (WIP)

Open glebm opened this issue 1 year ago • 7 comments

glebm avatar Aug 11 '24 14:08 glebm

Do you check to make sure that the tiles you do this for do not have content drawn on them from other ones and that they do not draw outside of the general rectangular area?

AJenbo avatar Aug 11 '24 17:08 AJenbo

The floor is drawn before everything else and I think floor tiles never overlap with each other

That said, so far I haven't been able to get any performance improvement out of this so far (and I tried quite a few things). The floor drawing gets faster but DrawDungeon, which I haven't change at all, gets slower. It's a mystery.

glebm avatar Aug 15 '24 00:08 glebm

The floor is drawn before everything else and I think floor tiles never overlap with each other

That said, so far I haven't been able to get any performance improvement out of this so far (and I tried quite a few things). The floor drawing gets faster but DrawDungeon, which I haven't change at all, gets slower. It's a mystery.

the foliage part is for tiles that do not limit them selfs to the "tile" shape. I think for floor this is only and issue in town, for the dungeons they all appears to adhere to the shape.

image

I guess you can simply handle it by not applying this optimization to any where foliage is true.

AJenbo avatar Aug 15 '24 00:08 AJenbo

foliage is only checked in DrawCell, which is not used for drawing floor tiles:

https://github.com/diasurgical/devilutionX/blob/7d5bef724dbfadb16cb1e36fb18f136a39929350/Source/engine/render/scrollrt.cpp#L475

Floor tiles are always drawn without mask (MaskType::Solid), doesn't look like our code supports foliage for them:

https://github.com/diasurgical/devilutionX/blob/7d5bef724dbfadb16cb1e36fb18f136a39929350/Source/engine/render/scrollrt.cpp#L572-L597

glebm avatar Aug 15 '24 00:08 glebm

😑 We might want to look in to that then

AJenbo avatar Aug 15 '24 10:08 AJenbo

I think what happens is that foliage is drawn again in DrawCell, after the floor.

The condition for whether something is a floor tile is exactly the same as foliage:

!TileHasAny(tilePosition, TileProperties::Solid); 

Moreover, we only draw foliage for tiles of TransparentSquare type.

So for a transparent square tile, we first draw it fully in DrawFloor. Then, in DrawCell, we draw only the masked part again.

I think the foliage condition is not very precise. Not all TransparentSquare tiles have foliage. However, I don't know of a more precise way to detect whether a tile has foliage.

glebm avatar Aug 17 '24 10:08 glebm

Thanks for investigating that.

AJenbo avatar Aug 17 '24 16:08 AJenbo