From 6702844314e043f9ecc53e58cfa20cc5454693c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Wed, 15 Mar 2023 15:18:01 -0300 Subject: [PATCH] Minor code simplifications --- src/doc/playback.cpp | 37 +++++++++++++++++++------------------ src/doc/playback.h | 7 +++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/doc/playback.cpp b/src/doc/playback.cpp index 96273cf51..6ca94b055 100644 --- a/src/doc/playback.cpp +++ b/src/doc/playback.cpp @@ -119,10 +119,7 @@ frame_t Playback::nextFrame(frame_t frameDelta) handleMoveFrame(step); handleEnterFrame(step, false); - if (frameDelta > 0) - --frameDelta; - else if (frameDelta < 0) - ++frameDelta; + frameDelta -= step; } PLAY_TRACE(" } =", m_frame, @@ -187,7 +184,7 @@ void Playback::handleEnterFrame(const frame_t frameDelta, const bool firstTime) else { addTag(t, false, forward); if (!firstTime) - goToFirstTagFrame(t, frameDelta); + goToFirstTagFrame(t); } } } @@ -220,17 +217,14 @@ bool Playback::handleExitFrame(const frame_t frameDelta) if ((tag->aniDir() == AniDir::FORWARD || tag->aniDir() == AniDir::REVERSE) - && ((forward > 0 && m_frame == tag->toFrame()) - || - (forward < 0 && m_frame == tag->fromFrame()))) { + && (frameDelta > 0 && m_frame == lastTagFrame(tag))) { decrementRepeat(frameDelta); return false; } // Change ping-pong direction else if ((tag->aniDir() == AniDir::PING_PONG || tag->aniDir() == AniDir::PING_PONG_REVERSE) - && ((m_frame == tag->fromFrame() && forward < 0) - || (m_frame == tag->toFrame() && forward > 0))) { + && m_frame == lastTagFrame(tag)) { PLAY_TRACE(" Changing direction frame=", m_frame, " forward=", forward, "->", -forward); @@ -404,7 +398,7 @@ bool Playback::decrementRepeat(const frame_t frameDelta) if (m_playing.back()->repeat > 1) { --m_playing.back()->repeat; - goToFirstTagFrame(tag, frameDelta); + goToFirstTagFrame(tag); PLAY_TRACE(" Repeat tag", tag->name(), " frame=", m_frame, "repeat=", m_playing.back()->repeat, @@ -431,7 +425,7 @@ bool Playback::decrementRepeat(const frame_t frameDelta) // New frame outside the tag frame_t newFrame; if (rewind) { - newFrame = firstTagFrame(m_playing.back()->tag, frameDelta); + newFrame = firstTagFrame(m_playing.back()->tag); } else { newFrame = (frameDelta * forward < 0 ? tag->fromFrame()-1: tag->toFrame()+1); @@ -486,21 +480,28 @@ bool Playback::decrementRepeat(const frame_t frameDelta) } } -frame_t Playback::firstTagFrame(const Tag* tag, - const frame_t frameDelta) +frame_t Playback::firstTagFrame(const Tag* tag) { ASSERT(tag); ASSERT(!m_playing.empty()); int forward = m_playing.back()->forward; - return (frameDelta * forward < 0 ? tag->toFrame(): + return (forward < 0 ? tag->toFrame(): tag->fromFrame()); } -void Playback::goToFirstTagFrame(const Tag* tag, - const frame_t frameDelta) +frame_t Playback::lastTagFrame(const Tag* tag) { ASSERT(tag); - m_frame = firstTagFrame(tag, frameDelta); + ASSERT(!m_playing.empty()); + int forward = m_playing.back()->forward; + return (forward > 0 ? tag->toFrame(): + tag->fromFrame()); +} + +void Playback::goToFirstTagFrame(const Tag* tag) +{ + ASSERT(tag); + m_frame = firstTagFrame(tag); PLAY_TRACE(" Go to first frame of tag", tag->name(), "frame=", m_frame); } diff --git a/src/doc/playback.h b/src/doc/playback.h index eb4529349..0b8084969 100644 --- a/src/doc/playback.h +++ b/src/doc/playback.h @@ -115,10 +115,9 @@ namespace doc { const int forward); void removeLastTagFromPlayed(); bool decrementRepeat(const frame_t frameDelta); - frame_t firstTagFrame(const Tag* tag, - const frame_t frameDelta); - void goToFirstTagFrame(const Tag* tag, - const frame_t frameDelta); + frame_t firstTagFrame(const Tag* tag); + frame_t lastTagFrame(const Tag* tag); + void goToFirstTagFrame(const Tag* tag); int getParentForward() const; const Sprite* m_sprite;