Minor code simplifications

This commit is contained in:
Martín Capello 2023-03-15 15:18:01 -03:00
parent e6cd13d7e1
commit 6702844314
2 changed files with 22 additions and 22 deletions

View File

@ -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);
}

View File

@ -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;