From c7803c8d096371e295e891fcc8733d616a9f6b62 Mon Sep 17 00:00:00 2001 From: Struma Date: Wed, 5 May 2021 04:30:11 -0400 Subject: [PATCH] Hook bitmaps into prepareDraw --- src/display/bitmap.cpp | 32 +++++++++++++++++++------------- src/display/bitmap.h | 2 -- src/display/sprite.cpp | 2 -- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index d0d5d6b9..ee8facfc 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -49,6 +49,8 @@ #include "debugwriter.h" +#include + #include #include @@ -199,17 +201,20 @@ struct BitmapPrivate void updateTimer() { if (needsReset) { + lastFrame = currentFrameI(); playTime = 0; - startTime = shState->graphics().lastUpdate(); + startTime = shState->runTime(); needsReset = false; return; } - playTime = shState->graphics().lastUpdate() - startTime; + playTime = shState->runTime() - startTime; return; } } animation; + sigc::connection prepareCon; + TEXFBO gl; Font *font; @@ -250,6 +255,8 @@ struct BitmapPrivate animation.startTime = 0; animation.fps = 0; animation.lastFrame = 0; + + prepareCon = shState->prepareDraw.connect(sigc::mem_fun(this, &BitmapPrivate::prepare)); font = &shState->defaultFont(); pixman_region_init(&tainted); @@ -257,9 +264,17 @@ struct BitmapPrivate ~BitmapPrivate() { + prepareCon.disconnect(); SDL_FreeFormat(format); pixman_region_fini(&tainted); } + + void prepare() + { + if (!animation.enabled || !animation.playing) return; + + animation.updateTimer(); + } void allocSurface() { @@ -2058,17 +2073,6 @@ bool Bitmap::getLooping() const return p->animation.loop; } - -// Called when a sprite attached to this Bitmap is being drawn -// Makes sure the bitmap begins its animation on time, on top of -// making sure that the bitmap doesn't begin actually moving until -// Graphics.update is called once -void Bitmap::syncAnimationTimer() -{ - if (!p->animation.enabled || isDisposed()) return; - p->animation.updateTimer(); -} - void Bitmap::bindTex(ShaderBase &shader) { p->bindTexture(shader); @@ -2088,6 +2092,8 @@ void Bitmap::releaseResources() if (p->megaSurface) SDL_FreeSurface(p->megaSurface); else if (p->animation.enabled) { + p->animation.enabled = false; + p->animation.playing = false; for (TEXFBO &tex : p->animation.frames) shState->texPool().release(tex); } diff --git a/src/display/bitmap.h b/src/display/bitmap.h index 8d4f848a..70c7443a 100644 --- a/src/display/bitmap.h +++ b/src/display/bitmap.h @@ -146,8 +146,6 @@ public: bool getLooping() const; void ensureNotPlaying() const; - - void syncAnimationTimer(); // ---------- /* Binds the backing texture and sets the correct diff --git a/src/display/sprite.cpp b/src/display/sprite.cpp index 24fc242a..991d62f9 100644 --- a/src/display/sprite.cpp +++ b/src/display/sprite.cpp @@ -579,8 +579,6 @@ void Sprite::draw() p->wave.qArray.draw(); else p->quad.draw(); - - p->bitmap->syncAnimationTimer(); glState.blendMode.pop(); }