From 63382bdb2ba0cb86ad19cfbb7bd07d4d5b9c4a66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 23 Jun 2017 00:08:06 -0400 Subject: [PATCH] gamnit: cache the last sprite added to `sprites_to_update` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/flat.nit | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/gamnit/flat.nit b/lib/gamnit/flat.nit index f9710ab..85c702c 100644 --- a/lib/gamnit/flat.nit +++ b/lib/gamnit/flat.nit @@ -235,7 +235,10 @@ class Sprite fun needs_update do var c = context - if c != null then c.sprites_to_update.add self + if c == null then return + if c.last_sprite_to_update == self then return + c.sprites_to_update.add self + c.last_sprite_to_update = self end # Request a resorting of this sprite in its sprite list @@ -696,6 +699,7 @@ private class SpriteSet context.sprites.add sprite context.sprites_to_update.add sprite + context.last_sprite_to_update = sprite sprite.context = context sprite.sprite_set = self @@ -776,6 +780,9 @@ private class SpriteContext # Sprites to update since last `draw` var sprites_to_update = new Set[Sprite] + # Cache of the last `Sprite` added to `sprites_to_update` since the last call to `draw` + var last_sprite_to_update: nullable Sprite = null + # Sprites that have been update and for which `needs_update` can be set to false var updated_sprites = new Array[Sprite] @@ -1010,6 +1017,7 @@ private class SpriteContext for sprite in sprites_to_update do update_sprite(sprite) sprites_to_update.clear + last_sprite_to_update = null sys.perfs["gamnit flat gpu update"].add app.perf_clock_sprites.lapse end -- 1.7.9.5