123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- //-----------------------------------------------------------------------------
- // Verve
- // Copyright (C) 2014 - Violent Tulip
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "VActorAnimationController.h"
- #include "VActor.h"
- #include "VActorData.h"
- #include "VActorAnimationStates.h"
- //-----------------------------------------------------------------------------
- VActorAnimationController::VActorAnimationController( void ) :
- mObject( NULL )
- {
- // Void.
- }
- VActorAnimationController::~VActorAnimationController( void )
- {
- // Clear Table.
- mAnimationTable.clear();
- }
- //-----------------------------------------------------------------------------
- //
- // Initialisation Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::initAnimationTable();
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::initAnimationTable( void )
- {
- // Valid Object?
- if ( !isValidObject() )
- {
- // No, Quit Now.
- return false;
- }
- // Clear the Table.
- mAnimationTable.clear();
- // Fetch Sequence List.
- VActorData::tAnimationSequenceVector *sequenceList = getObject()->getDataBlock()->getAnimationList();
- // Initialise the Animation States.
- for ( VActorData::tAnimationSequenceVector::iterator itr = sequenceList->begin();
- itr != sequenceList->end();
- itr++ )
- {
- // Fetch Sequence Definition.
- const VActorData::sAnimationSequence &animSequence = ( *itr );
- // Valid State?
- if ( animSequence.State )
- {
- // Register Animation.
- mAnimationTable.registerState( animSequence.State, animSequence.Priority );
- }
- }
- // Sort the Table.
- mAnimationTable.sort();
- // Valid.
- return true;
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::initAnimation( pThread, pIndex, pPosition, pTimeScale );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::initAnimation( sAnimationRef &pAnimation, const U32 &pIndex, const F32 &pPosition, const F32 &pTimeScale )
- {
- // Valid Object & Sequence?
- if ( !isValidObject() || !isAnimationSequence( pIndex ) )
- {
- // No, Quit Now.
- return false;
- }
- // Store as Current Animation.
- pAnimation.Index = pIndex;
- // Initialise Thread.
- return initAnimationThread( pAnimation.Thread, pAnimation.Index, pPosition, pTimeScale );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::initAnimationThread( pThread, pIndex, pPosition, pTimeScale );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::initAnimationThread( TSThread *&pThread, const U32 &pIndex, const F32 &pPosition, const F32 &pTimeScale )
- {
- // Valid Object & Sequence?
- if ( !isValidObject() || !isAnimationSequence( pIndex ) )
- {
- // No, Quit Now.
- return false;
- }
- // Valid Thread?
- if ( !pThread )
- {
- // Create a Thread.
- pThread = getShapeInstance()->addThread();
- }
- // Init the Sequence.
- getShapeInstance()->setSequence( pThread, getAnimationSequence( pIndex ), pPosition );
- // Set Initial Time Scale.
- getShapeInstance()->setTimeScale( pThread, pTimeScale );
- // Valid.
- return true;
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::initBaseAnimation( pThread, pIndex, pPosition, pTimeScale );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::initBaseAnimation( const U32 &pIndex, const F32 &pPosition, const F32 &pTimeScale )
- {
- return initAnimation( mBaseAnimation, pIndex, pPosition, pTimeScale );
- }
- //-----------------------------------------------------------------------------
- //
- // Accessor Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::isValidObject();
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::isValidObject( void )
- {
- return ( mObject != NULL && mObject->getDataBlock() != NULL );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::getObject();
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- VActor *VActorAnimationController::getObject( void )
- {
- return mObject;
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::setObject( pObject );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- void VActorAnimationController::setObject( VActor *pObject )
- {
- // Set Object.
- mObject = pObject;
- // Set Table's Reference.
- mAnimationTable.setObject( pObject );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::getShape();
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- const TSShape *VActorAnimationController::getShape( void )
- {
- if ( !isValidObject() )
- {
- return NULL;
- }
- return mObject->getShape();
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::getShapeInstance();
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- TSShapeInstance *VActorAnimationController::getShapeInstance( void )
- {
- if ( !isValidObject() )
- {
- return NULL;
- }
- return mObject->getShapeInstance();
- }
- //-----------------------------------------------------------------------------
- //
- // Animation Methods
- //
- //-----------------------------------------------------------------------------
- void VActorAnimationController::update( const F32 &pDelta )
- {
- // Valid Objects?
- if ( !isValidObject() )
- {
- // No, Quit Now.
- return;
- }
- // Update Animation State.
- mAnimationTable.execute();
- // Advance Threads.
- getShapeInstance()->advanceTime( pDelta, mBaseAnimation.Thread );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::isAnimationSequence( pIndex );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- bool VActorAnimationController::isAnimationSequence( const U32 &pIndex )
- {
- return ( getAnimationSequence( pIndex ) != -1 );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::getAnimationSequence( pIndex );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- S32 VActorAnimationController::getAnimationSequence( const U32 &pIndex )
- {
- // Valid Object?
- if ( !mObject || !mObject->getDataBlock() )
- {
- // No, Invalid Sequence.
- return -1;
- }
- // Return Sequence.
- return mObject->getDataBlock()->getAnimationSequence( pIndex );
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::getAnimation( pIndex );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- U32 VActorAnimationController::getAnimation( void )
- {
- // Base Animation Initialised?
- if ( !mBaseAnimation.Thread )
- {
- // Null.
- return U32_MAX;
- }
- // Return Current Animation.
- return mBaseAnimation.Index;
- }
- //-----------------------------------------------------------------------------
- //
- // VActorAnimationController::setAnimation( pIndex );
- //
- // ...
- //
- //-----------------------------------------------------------------------------
- void VActorAnimationController::setAnimation( const U32 &pIndex )
- {
- // Base Animation Initialised?
- if ( !mBaseAnimation.Thread || mBaseAnimation.Index == pIndex )
- {
- // Don't Update.
- return;
- }
- // Store as Current Animation.
- mBaseAnimation.Index = pIndex;
- // Fetch the Sequence.
- const S32 &sequence = getAnimationSequence( pIndex );
- // Valid?
- if ( sequence != -1 )
- {
- // Play the Sequence.
- getShapeInstance()->transitionToSequence( mBaseAnimation.Thread, sequence, 0.f, 0.15f, true );
- //getShapeInstance()->setSequence( mBaseAnimation.Thread, sequence, 0.f );
- }
- }
|