Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Add a deflate function to TextureAtlasTiles. #42

@Possseidon

Description

@Possseidon

If a lot of similar tiles are added to a texture atlas, multiple layers for the same tile size will be created. If a lot of random tiles are removed now, this is going to create a lot of unused space in all layers, which can only be reclaimed by actually using it for newly added tiles.

Therefore a deflate function could try and reclaim all that unused space and shrink down the layer count.

Implementation:

Go through all tiles, call layerForTile to find the smallest layer index and see if it is smaller than the current one, which means an earlier layer has space for this tile. If this is the case, remove it from the current layer and add it to that layer.

The most efficient way here, would be to start with the tiles in the last layer. Otherwise, a lot of tiles might get shifted along as new spaces keeps opening up in lower layers.

The order to process the layer itself in doesn't really matter all that much unless shrink_to_fit is called on the tiles vector. Then back to front is favorable again.

Metadata

Metadata

Assignees

Labels

dang-glenhancementNew feature or requestoptimizationImproves memory usage or performance in general

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions