From eadabf391937b5e95c420d62be145cac6c393bcf Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 12 Sep 2022 23:09:36 +0200 Subject: [PATCH] use SortedDictionary for StaticSpriteBatch --- MLEM/Graphics/StaticSpriteBatch.cs | 2 +- Sandbox/GameImpl.cs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/MLEM/Graphics/StaticSpriteBatch.cs b/MLEM/Graphics/StaticSpriteBatch.cs index daf437b..fec80ac 100644 --- a/MLEM/Graphics/StaticSpriteBatch.cs +++ b/MLEM/Graphics/StaticSpriteBatch.cs @@ -43,7 +43,7 @@ namespace MLEM.Graphics { private readonly SpriteEffect spriteEffect; private readonly List vertexBuffers = new List(); private readonly List textures = new List(); - private readonly SortedList> items = new SortedList>(); + private readonly SortedDictionary> items = new SortedDictionary>(); private IndexBuffer indices; private bool batching; diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index f8e79c3..7b51c96 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -355,15 +355,24 @@ public class GameImpl : MlemGame { this.UiSystem.Add("WidthTest", widthPanel); var batch = new StaticSpriteBatch(this.GraphicsDevice); - batch.BeginBatch(SpriteSortMode.Deferred); + batch.BeginBatch(); var depth = 0F; var items = new List(); foreach (var r in atlas.Regions) items.Add(batch.Add(r, new Vector2(50 + r.GetHashCode() % 200, 50), ColorHelper.FromHexRgb(r.GetHashCode()), 0, Vector2.Zero, 1, SpriteEffects.None, depth += 0.0001F)); batch.Remove(items[5]); batch.EndBatch(); - batch.BeginBatch(SpriteSortMode.BackToFront); - batch.EndBatch(); + var sortMode = SpriteSortMode.Deferred; + this.OnUpdate += (_, _) => { + if (MlemGame.Input.IsPressed(Keys.S)) { + do { + sortMode = (SpriteSortMode) (((int) sortMode + 1) % 5); + } while (sortMode == SpriteSortMode.Immediate); + Console.WriteLine(sortMode); + batch.BeginBatch(sortMode); + batch.EndBatch(); + } + }; this.OnDraw += (_, _) => batch.Draw(null, SamplerState.PointClamp, null, null, null, Matrix.CreateScale(3)); }