Skip to content

Commit

Permalink
Add Repeat button to animation mode
Browse files Browse the repository at this point in the history
A repeat button was added so that the loop option doesn't affect
whether a played animation in the editor repeats.
  • Loading branch information
zturtleman committed Jul 20, 2024
1 parent a5f3ca1 commit 7914056
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 19 deletions.
24 changes: 16 additions & 8 deletions doc/html/olh_animwin.htm
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ <h3> FPS Text Box </h3>
<h3> Loop Checkbox </h3>

<p>
The <b>Loop Checkbox</b> will change whether the current animation loops when it
completes or not. If the animation completes and the <b>Loop Checkbox</b>
is checked, the animation will restart from the first frame. If the animation
completes and the <b>Loop Checkbox</b> is not checked, the animation
will stop.
The <b>Loop Checkbox</b> is used to mark that the animation is intend to repeat
and to interpolate skeletal joints around ends of the animation.
However it does not affect playing the animation in Maverick.
The <b> Repeat </b> button is used to view the animation playing continuously.
</p>

<p>
Animations with <b>loop</b> checked are marked as repeating when exported to
MD3 animations.cfg and IQE format.
</p>

<p>
Expand Down Expand Up @@ -163,16 +167,14 @@ <h3> Previous </h3>
<h3> Play / Pause </h3>

<p>
The <b>Play</b> button runs the current animation at its specified
The <b>Play</b> button runs the current animation once at its specified
frame rate. The <b>Play</b> button becomes a <b>Pause</b> during
playback so that you can pause an animation and resume it later.
Paused animations resume from the time at which they were paused.
</p>

<p>
Use the <b>Stop</b> button to stop an animation completely.
Use the <b>Loop Checkbox</b> to control whether the animation should
start from the beginning again when it completes.
</p>

<p>
Expand All @@ -181,6 +183,12 @@ <h3> Play / Pause </h3>
reasons, and may become a configurable option at a later time.
</p>

<h3> Repeat </h3>

<p>
The <b>Repeat</b> button will play the animation and continuously repeat it.
</p>

<h3> Stop </h3>

<p>
Expand Down
24 changes: 23 additions & 1 deletion src/implui/animwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,21 @@ void AnimWidget::nextClicked()

void AnimWidget::playClicked()
{
m_repeating = false;
if ( m_playing )
{
doPause();
}
else
{
doPlay();
}
m_stop->setEnabled( true );
}

void AnimWidget::repeatClicked()
{
m_repeating = true;
if ( m_playing )
{
doPause();
Expand All @@ -635,6 +650,7 @@ void AnimWidget::stopClicked()
m_currentTime = 0;
m_stop->setEnabled( false );
m_play->setEnabled(true);
m_repeat->setEnabled(true);
m_previous->setEnabled(true);
m_next->setEnabled(true);
m_frameCount->setEnabled(true);
Expand Down Expand Up @@ -666,6 +682,7 @@ void AnimWidget::doPlay()
return;
}
m_play->setEnabled(false);
m_repeat->setEnabled(false);
m_previous->setEnabled(false);
m_next->setEnabled(false);
m_frameCount->setEnabled(false);
Expand All @@ -687,6 +704,7 @@ void AnimWidget::doPause()
{
m_playing = false;
m_play->setEnabled(true);
m_repeat->setEnabled(true);
m_animTimer->stop();
}

Expand All @@ -697,7 +715,7 @@ void AnimWidget::timeElapsed()
unsigned t = (tv.tv_sec - m_startTime.tv_sec) * 1000 + (tv.tv_msec - m_startTime.tv_msec);

m_currentTime = ((double) t) / 1000.0;
if ( m_model->setCurrentAnimationTime( m_currentTime ) )
if ( m_model->setCurrentAnimationTime( m_currentTime ) || m_repeating )
{
//log_debug( "animation time: %f (%d)\n", m_currentTime, t );
}
Expand Down Expand Up @@ -812,6 +830,7 @@ void AnimWidget::refreshPage()
m_fps->setEnabled( true );
m_animName->setEnabled( true );
m_play->setEnabled( true );
m_repeat->setEnabled( true );
m_loop->setEnabled( true );

unsigned count = m_model->getAnimFrameCount( mode, index );
Expand Down Expand Up @@ -842,6 +861,7 @@ void AnimWidget::refreshPage()
m_previous->setEnabled( false );
m_next->setEnabled( false );
m_play->setEnabled( false );
m_repeat->setEnabled( false );
m_stop->setEnabled( false );
m_loop->setEnabled( false );

Expand Down Expand Up @@ -879,6 +899,7 @@ void AnimWidget::refreshPage()
}
m_fps->setEnabled( true );
m_play->setEnabled( true );
m_repeat->setEnabled( true );
m_stop->setEnabled( true );
m_loop->setEnabled( true );
}
Expand All @@ -891,6 +912,7 @@ void AnimWidget::refreshPage()
m_previous->setEnabled( false );
m_next->setEnabled( false );
m_play->setEnabled( false );
m_repeat->setEnabled( false );
m_stop->setEnabled( false );
m_loop->setEnabled( false );

Expand Down
2 changes: 2 additions & 0 deletions src/implui/animwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class AnimWidget : public QWidget, public Ui::AnimWidgetBase
void previousClicked();
void nextClicked();
void playClicked();
void repeatClicked();
void stopClicked();
void loopToggled(bool);

Expand All @@ -90,6 +91,7 @@ class AnimWidget : public QWidget, public Ui::AnimWidgetBase

Model * m_model;
bool m_playing;
bool m_repeating;
double m_timeInterval;
double m_currentTime;
unsigned m_skelAnimCount;
Expand Down
17 changes: 7 additions & 10 deletions src/libmm3d/model_anim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1832,17 +1832,15 @@ bool Model::setCurrentAnimationTime( double frameTime )
}

size_t totalFrames = m_frameAnims[m_currentAnim]->m_frameData.size();
bool rtnval = true;

if ( totalFrames > 0 )
{
double spf = 1.0 / m_frameAnims[m_currentAnim]->m_fps;
double totalTime = spf * m_frameAnims[m_currentAnim]->m_frameData.size();
while ( frameTime >= totalTime )
{
if ( !m_frameAnims[m_currentAnim]->m_loop )
{
return false;
}
rtnval = false;
frameTime -= totalTime;
}
m_currentFrame = (unsigned) (frameTime / spf);
Expand All @@ -1856,22 +1854,21 @@ bool Model::setCurrentAnimationTime( double frameTime )
m_currentTime = frameTime;

updateObservers();
return true;
return rtnval;
}
else if ( m_animationMode == ANIMMODE_SKELETAL && m_currentAnim < m_skelAnims.size() && m_skelAnims[m_currentAnim]->m_frameCount > 0 )
{
LOG_PROFILE();

bool rtnval = true;

SkelAnim * sa = m_skelAnims[m_currentAnim];
if ( sa->m_frameCount > 0 )
{
double totalTime = sa->m_spf * sa->m_frameCount;
while ( frameTime > totalTime )
{
if ( !sa->m_loop )
{
return false;
}
rtnval = false;
frameTime -= totalTime;
}
}
Expand Down Expand Up @@ -2161,7 +2158,7 @@ bool Model::setCurrentAnimationTime( double frameTime )
}

updateObservers();
return true;
return rtnval;
}
else
{
Expand Down
23 changes: 23 additions & 0 deletions src/qtui/animwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_repeat">
<property name="text">
<string>Repeat</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_stop">
<property name="text">
Expand Down Expand Up @@ -321,6 +328,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>m_repeat</sender>
<signal>clicked()</signal>
<receiver>AnimWidgetBase</receiver>
<slot>repeatClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_stop</sender>
<signal>clicked()</signal>
Expand Down

0 comments on commit 7914056

Please sign in to comment.