From d7512241d01f322d609082bbd105bbc5fc79ac93 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Dec 2023 21:14:00 -0500 Subject: [PATCH] Draw#discard() --- arc-core/src/arc/graphics/g2d/Batch.java | 5 +++++ arc-core/src/arc/graphics/g2d/Draw.java | 7 ++++++- arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arc-core/src/arc/graphics/g2d/Batch.java b/arc-core/src/arc/graphics/g2d/Batch.java index 6ac693d26..020891498 100644 --- a/arc-core/src/arc/graphics/g2d/Batch.java +++ b/arc-core/src/arc/graphics/g2d/Batch.java @@ -101,6 +101,11 @@ protected void draw(Runnable request){ protected abstract void flush(); + /** Discards any pending sprites. */ + protected void discard(){ + idx = 0; + } + protected void setBlending(Blending blending){ if(this.blending != blending){ flush(); diff --git a/arc-core/src/arc/graphics/g2d/Draw.java b/arc-core/src/arc/graphics/g2d/Draw.java index a30333322..700036215 100644 --- a/arc-core/src/arc/graphics/g2d/Draw.java +++ b/arc-core/src/arc/graphics/g2d/Draw.java @@ -410,7 +410,12 @@ public static void vert(Texture texture, float[] vertices, int offset, int lengt } public static void flush(){ - Core.batch.flush(); + batch.flush(); + } + + /** Discards any pending batched sprites. */ + public static void discard(){ + batch.discard(); } public static void proj(float x, float y, float w, float h){ diff --git a/arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java b/arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java index 1933a0310..f9b7bb3a3 100644 --- a/arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java +++ b/arc-core/src/arc/graphics/g2d/SortedSpriteBatch.java @@ -139,6 +139,14 @@ protected void flush(){ super.flush(); } + @Override + protected void discard(){ + if(!flushing){ + numRequests = 0; + } + super.discard(); + } + protected void flushRequests(){ if(!flushing && numRequests > 0){ flushing = true;