1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 17:29:23 +01:00

Improve RuntimeTexturePacker performance by checking against packed textures in the same order as packing

This commit is contained in:
Ell 2022-05-27 11:02:33 +02:00
parent 951f4babd5
commit cb496f613f
2 changed files with 5 additions and 1 deletions

View file

@ -58,6 +58,7 @@ Improvements
- Premultiply textures when using RawContentManager
- Allow enumerating all region names of a DataTextureAtlas
- Cache RuntimeTexturePacker texture data while packing to improve performance
- Improve RuntimeTexturePacker performance by checking against packed textures in the same order as packing
Fixes
- Fixed SoundEffectReader incorrectly claiming it could read ogg and mp3 files

View file

@ -152,9 +152,12 @@ namespace MLEM.Data {
if (this.PackedTexture != null)
throw new InvalidOperationException("Cannot pack a texture packer that is already packed");
// we pack larger textures first, so that smaller textures can fit in the gaps that larger ones leave
this.textures.Sort((r1, r2) => (r2.Texture.Width * r2.Texture.Height).CompareTo(r1.Texture.Width * r1.Texture.Height));
// set pack areas for each request
var stopwatch = Stopwatch.StartNew();
foreach (var request in this.textures.OrderByDescending(t => t.Texture.Width * t.Texture.Height))
foreach (var request in this.textures)
request.PackedArea = this.FindFreeArea(request);
stopwatch.Stop();
this.LastCalculationTime = stopwatch.Elapsed;