From 9f259ed879230157e55f77b56728f1c925a21da2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 26 Mar 2007 02:46:55 +0000 Subject: [PATCH] simplify bindings looping negative rates --- stepmania/src/BeginnerHelper.cpp | 3 +-- stepmania/src/Model.cpp | 20 ++++++++++++++------ stepmania/src/Model.h | 5 +++-- stepmania/src/ScreenHowToPlay.cpp | 3 +-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/stepmania/src/BeginnerHelper.cpp b/stepmania/src/BeginnerHelper.cpp index 338e740e35..604dfca563 100644 --- a/stepmania/src/BeginnerHelper.cpp +++ b/stepmania/src/BeginnerHelper.cpp @@ -203,14 +203,13 @@ bool BeginnerHelper::Initialize( int iDancePadType ) m_pDancer[pl]->LoadMilkshapeAsciiBones( "Step-RIGHT", GetAnimPath(ANIM_RIGHT) ); m_pDancer[pl]->LoadMilkshapeAsciiBones( "Step-JUMPLR", GetAnimPath(ANIM_JUMPLR) ); m_pDancer[pl]->LoadMilkshapeAsciiBones(" rest", Character->GetRestAnimationPath() ); - m_pDancer[pl]->SetDefaultAnimation( "rest" ); + m_pDancer[pl]->SetDefaultAnimation( "rest" ); // Stay bouncing after a step has finished animating m_pDancer[pl]->PlayAnimation( "rest" ); m_pDancer[pl]->SetRotationX( PLAYER_ANGLE ); m_pDancer[pl]->SetX( HELPER_X+PLAYER_X(pl) ); m_pDancer[pl]->SetY( HELPER_Y+10 ); m_pDancer[pl]->SetZoom( 20 ); m_pDancer[pl]->SetCullMode( CULL_NONE ); // many of the models floating around have the vertex order flipped - m_pDancer[pl]->m_bRevertToDefaultAnimation = true; // Stay bouncing after a step has finished animating } m_bInitialized = true; diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 9850461f0a..ba03a2e737 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -26,9 +26,9 @@ Model::Model() SetCullMode( CULL_BACK ); m_pGeometry = NULL; m_pCurAnimation = NULL; - m_bRevertToDefaultAnimation = false; m_fDefaultAnimationRate = 1; m_fCurAnimationRate = 1; + m_bLoop = true; m_pTempGeometry = NULL; } @@ -108,8 +108,6 @@ void Model::LoadPieces( const RString &sMeshesPath, const RString &sMaterialsPat void Model::LoadFromNode( const XNode* pNode ) { - Actor::LoadFromNode( pNode ); - RString s1, s2, s3; ActorUtil::GetAttrPath( pNode, "Meshes", s1 ); ActorUtil::GetAttrPath( pNode, "Materials", s2 ); @@ -119,6 +117,8 @@ void Model::LoadFromNode( const XNode* pNode ) ASSERT( !s1.empty() && !s2.empty() && !s3.empty() ); LoadPieces( s1, s2, s3 ); } + + Actor::LoadFromNode( pNode ); } @@ -576,16 +576,18 @@ void Model::AdvanceFrame( float fDeltaTime ) // LOG->Trace( "m_fCurFrame = %f", m_fCurFrame ); m_fCurFrame += FRAMES_PER_SECOND * fDeltaTime * m_fCurAnimationRate; - if( m_fCurFrame >= m_pCurAnimation->nTotalFrames ) + if( m_fCurFrame < 0 || m_fCurFrame >= m_pCurAnimation->nTotalFrames ) { - if( m_bRevertToDefaultAnimation && m_sDefaultAnimation != "" ) + if( m_sDefaultAnimation != "" ) { this->PlayAnimation( m_sDefaultAnimation, m_fDefaultAnimationRate ); /* XXX: add to m_fCurFrame the wrapover from the previous * m_fCurFrame-m_pCurAnimation->nTotalFrames, so it doesn't skip */ } + else if( m_bLoop ) + wrap( m_fCurFrame, (float) m_pCurAnimation->nTotalFrames ); else - m_fCurFrame -= m_pCurAnimation->nTotalFrames; + m_fCurFrame = clamp( m_fCurFrame, 0, (float) m_pCurAnimation->nTotalFrames ); } SetBones( m_pCurAnimation, m_fCurFrame, m_vpBones ); @@ -776,10 +778,16 @@ class LunaModel: public Luna { public: static int playanimation( T* p, lua_State *L ) { p->PlayAnimation(SArg(1),FArg(2)); return 0; } + static int SetDefaultAnimation( T* p, lua_State *L ) { p->SetDefaultAnimation(SArg(1),FArg(2)); return 0; } + static int loop( T* p, lua_State *L ) { p->SetLoop(BArg(1)); return 0; } + static int rate( T* p, lua_State *L ) { p->SetRate(FArg(1)); return 0; } LunaModel() { ADD_METHOD( playanimation ); + ADD_METHOD( SetDefaultAnimation ); + ADD_METHOD( loop ); + ADD_METHOD( rate ); } }; diff --git a/stepmania/src/Model.h b/stepmania/src/Model.h index 3c029a69b1..4c7deba592 100644 --- a/stepmania/src/Model.h +++ b/stepmania/src/Model.h @@ -30,6 +30,8 @@ public: void LoadFromNode( const XNode* pNode ); void PlayAnimation( const RString &sAniName, float fPlayRate = 1 ); + void SetRate( float fRate ) { m_fCurAnimationRate = fRate; } + void SetLoop( bool b ) { m_bLoop = b; } virtual void Update( float fDelta ); virtual bool EarlyAbortDraw() const; @@ -44,7 +46,6 @@ public: RString GetDefaultAnimation() const { return m_sDefaultAnimation; }; void SetDefaultAnimation( RString sAnimation, float fPlayRate = 1 ); - bool m_bRevertToDefaultAnimation; bool MaterialsNeedNormals() const; @@ -80,7 +81,7 @@ private: RString m_sDefaultAnimation; float m_fDefaultAnimationRate; float m_fCurAnimationRate; - + bool m_bLoop; }; #endif diff --git a/stepmania/src/ScreenHowToPlay.cpp b/stepmania/src/ScreenHowToPlay.cpp index 99a9e51fd7..2f3e2ba6e4 100644 --- a/stepmania/src/ScreenHowToPlay.cpp +++ b/stepmania/src/ScreenHowToPlay.cpp @@ -109,8 +109,7 @@ void ScreenHowToPlay::Init() ASSERT( !sRestFile.empty() ); m_pmCharacter->LoadMilkshapeAsciiBones( "rest",rndchar->GetRestAnimationPath() ); m_pmCharacter->SetDefaultAnimation( "rest" ); - m_pmCharacter->PlayAnimation( "rest" ); - m_pmCharacter->m_bRevertToDefaultAnimation = true; // Stay bouncing after a step has finished animating. + m_pmCharacter->PlayAnimation( "rest" ); // Stay bouncing after a step has finished animating. m_pmCharacter->SetRotationX( 40 ); m_pmCharacter->SetCullMode( CULL_NONE ); // many of the models floating around have the vertex order flipped