Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize floor drawing (WIP) #7327

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

glebm
Copy link
Collaborator

@glebm glebm commented Aug 11, 2024

No description provided.

@AJenbo
Copy link
Member

AJenbo commented Aug 11, 2024

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?

@glebm
Copy link
Collaborator Author

glebm commented Aug 15, 2024

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.

@AJenbo
Copy link
Member

AJenbo commented Aug 15, 2024

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.

@glebm
Copy link
Collaborator Author

glebm commented Aug 15, 2024

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

const bool foliage = !TileHasAny(tilePosition, TileProperties::Solid);

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

void DrawFloorTile(const Surface &out, Point tilePosition, Point targetBufferPosition)
{
const int lightTableIndex = dLight[tilePosition.x][tilePosition.y];
const uint8_t *tbl = LightTables[lightTableIndex].data();
#ifdef _DEBUG
if (DebugPath && MyPlayer->IsPositionInPath(tilePosition))
tbl = GetPauseTRN();
#endif
const uint16_t levelPieceId = dPiece[tilePosition.x][tilePosition.y];
{
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[0] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition,
levelCelBlock, MaskType::Solid, tbl);
}
}
{
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[1] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 },
levelCelBlock, MaskType::Solid, tbl);
}
}
}

@AJenbo
Copy link
Member

AJenbo commented Aug 15, 2024

😑 We might want to look in to that then

@glebm glebm force-pushed the copy-floor branch 3 times, most recently from 3f66fe0 to b18c957 Compare August 17, 2024 10:01
@glebm
Copy link
Collaborator Author

glebm commented Aug 17, 2024

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.

@AJenbo
Copy link
Member

AJenbo commented Aug 17, 2024

Thanks for investigating that.

glebm added a commit to glebm/devilutionX that referenced this pull request Aug 18, 2024
Makes the connection between `foliage` and floor more obvious,
see
diasurgical#7327 (comment).
glebm added a commit that referenced this pull request Aug 18, 2024
Makes the connection between `foliage` and floor more obvious,
see
#7327 (comment).
artifacts-storage pushed a commit to artifacts-storage/devilutionx-artifacts that referenced this pull request Aug 18, 2024
Makes the connection between `foliage` and floor more obvious,
see
diasurgical/devilutionX#7327 (comment).
artifacts-storage pushed a commit to artifacts-storage/devilutionx-artifacts that referenced this pull request Aug 18, 2024
Makes the connection between `foliage` and floor more obvious,
see
diasurgical/devilutionX#7327 (comment).
@glebm glebm force-pushed the copy-floor branch 7 times, most recently from 3377406 to 9233786 Compare August 26, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants