1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 02:09:24 +01:00

use SortedDictionary for StaticSpriteBatch

This commit is contained in:
Ell 2022-09-12 23:09:36 +02:00
parent 856d67b6cf
commit eadabf3919
2 changed files with 13 additions and 4 deletions

View file

@ -43,7 +43,7 @@ namespace MLEM.Graphics {
private readonly SpriteEffect spriteEffect;
private readonly List<DynamicVertexBuffer> vertexBuffers = new List<DynamicVertexBuffer>();
private readonly List<Texture2D> textures = new List<Texture2D>();
private readonly SortedList<float, ISet<Item>> items = new SortedList<float, ISet<Item>>();
private readonly SortedDictionary<float, ISet<Item>> items = new SortedDictionary<float, ISet<Item>>();
private IndexBuffer indices;
private bool batching;

View file

@ -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<StaticSpriteBatch.Item>();
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));
}