12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160 |
- //-----------------------------------------------------------------------------
- // 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 "Verve/Core/VController.h"
- #include "Verve/Core/VObject.h"
- #include "Verve/Core/VGroup.h"
- #include "Verve/Core/VTrack.h"
- #include "Verve/Extension/Director/VDirectorGroup.h"
- #include "console/consoleObject.h"
- #include "console/consoleTypes.h"
- #include "math/mMathFn.h"
- //-----------------------------------------------------------------------------
- IMPLEMENT_CONOBJECT( VController );
- //-----------------------------------------------------------------------------
- VController::VController( void ) :
- mStatus( ( k_StatusInit | k_StatusStopped ) ),
- mTime( 0 ),
- mLastTime( 0 ),
- mTimeScale( 1.f ),
- mDuration( 5000 ),
- mLoop( false ),
- mLoopBackwards( false ),
- mLoopCount( -1 ),
- mLoopIndex( 0 ),
- mLoopDelay( 0 ),
- mLoopDelayTime( 0 ),
- mJump( k_JumpInvalid ),
- mJumpTime( 0 ),
- mResetOnCompletion( true )
- {
- // Don't Process Ticks.
- setProcessTicks( false );
- }
- VController::~VController( void )
- {
- // Void.
- }
- void VController::initPersistFields( void )
- {
- addGroup( "Controller" );
- addProtectedField( "Time", TypeS32, Offset( mTime, VController ), &setTime, &defaultProtectedGetFn, "Current position of the Controller (in milliseconds)." );
- addProtectedField( "Duration", TypeS32, Offset( mDuration, VController ), &setDuration, &defaultProtectedGetFn, "Total length of the sequence (in milliseconds)." );
- addProtectedField( "TimeScale", TypeF32, Offset( mTimeScale, VController ), &setTimeScale, &defaultProtectedGetFn, "Speed of playback. A value > 0.0 will enable the Controller to play forwards, while a value < 0.0 will play backwards. If |TimeScale| > 1.0, then playback will be faster than normal, while |TimeScale| < 1.0 will be slower." );
- addField( "Loop", TypeBool, Offset( mLoop, VController ), "Instead of stopping once playback is complete, the Controller will reset and resume play." );
- addField( "LoopBackwards", TypeBool, Offset( mLoopBackwards, VController ), "When the sequence loops, reverse the direction of play." );
- addField( "LoopCount", TypeS32, Offset( mLoopCount, VController ), "The number of times the sequence loops before stopping. -1 will cause the sequence to loop indefinitely." );
- addField( "LoopDelay", TypeS32, Offset( mLoopDelay, VController ), "When the sequence loops, delay playback by this value (in milliseconds)." );
- addField( "ResetOnCompletion", TypeBool, Offset( mResetOnCompletion, VController ), "When the sequence is completed, reset the state of the Controller." );
- endGroup( "Controller" );
- // Parent Call.
- Parent::initPersistFields();
- }
- //-----------------------------------------------------------------------------
- //
- // ITickable Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::processTick();
- //
- // This method controls the playback of the entire sequence. It integrates all
- // of the groups and handles sequence looping and jumping.
- //
- //-----------------------------------------------------------------------------
- void VController::processTick( void )
- {
- if ( mTimeScale == 0.f )
- {
- // Pause.
- pause();
- // Exit.
- return;
- }
- // Calculate Delta.
- const S32 time = Sim::getCurrentTime();
- S32 delta = ( time - mLastTime );
- mLastTime = time;
- // Reverse?
- if ( mTimeScale < 0.f )
- {
- // Negative Delta.
- delta *= -1;
- }
- if ( mLoopDelayTime > 0 )
- {
- // Update Delay Time.
- mLoopDelayTime -= getMin( mAbs( delta ), mLoopDelayTime );
- // Exit.
- return;
- }
- // Jump Delta?
- if ( mJump == k_JumpDelta )
- {
- // Jump.
- delta = mJumpTime;
- // Clear.
- mJump = k_JumpInvalid;
- mJumpTime = 0;
- }
- if ( ( isPlayingForward() && ( mTime + delta ) > mDuration )
- || ( !isPlayingForward() && ( mTime + delta ) < 0 ) )
- {
- // Clamp Delta.
- delta = ( ( mTimeScale > 0.f ) * mDuration ) - mTime;
- // Note: If we are playing forwards, we're at the end of the
- // sequence and we want to loop/reset the Controller, then we
- // need to handle that now.
- if ( delta == 0 )
- {
- onPostTick();
- }
- }
- // Valid Delta?
- if ( delta == 0 )
- {
- // Exit.
- return;
- }
- // Trigger Update.
- mControllerUpdateSignal.trigger( mTime, delta );
- // Update Time.
- mTime += delta;
- // Perform Post Tick.
- onPostTick();
- }
- //-----------------------------------------------------------------------------
- //
- // VController::onPostTick();
- //
- // This method is called onces a tick has been processed. It will perform the
- // the right checks to see if the Controller has finished playing. It also
- // handles special cases like Looping or Resetting the Controller.
- //
- //-----------------------------------------------------------------------------
- void VController::onPostTick( void )
- {
- // Jump Time?
- if ( mJump == k_JumpTime )
- {
- // Jump Post Update.
- reset( mJumpTime );
- // Clear.
- mJump = k_JumpInvalid;
- mJumpTime = 0;
- }
- // Sequence Completed?
- if ( isPlayingForward() && mTime >= mDuration
- || !isPlayingForward() && mTime <= 0 )
- {
- bool stopPlaying = true;
- if ( mLoop )
- {
- // Don't Stop.
- stopPlaying = false;
- if ( mLoopBackwards )
- {
- // Change Direction.
- setTimeScale( -1.f * mTimeScale );
- }
- else
- {
- // Reset Time.
- reset();
- }
- if ( mLoopDelay > 0 )
- {
- // Resume After Delay.
- mLoopDelayTime = mLoopDelay;
- }
- // At the Start of the Sequence?
- if ( mTime <= 0 && mLoopCount >= 0 )
- {
- // Stop Looping?
- stopPlaying = ( ++mLoopIndex >= mLoopCount );
- }
- // Callback.
- Con::executef( this, "onLoop" );
- // Loop Signal.
- postEvent( k_EventLoop );
- }
- // Stop?
- if ( stopPlaying )
- {
- // Stop Only.
- stop( mResetOnCompletion );
- }
- }
- }
- //-----------------------------------------------------------------------------
- //
- // Controller Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::reset();
- //
- // Reset the Controller to the start of the sequence.
- //
- //-----------------------------------------------------------------------------
- void VController::reset( void )
- {
- // Reset.
- reset( ( isPlayingForward() ) ? 0 : mDuration );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::reset( pTime );
- //
- // Reset the Controller to the target time. This is a very important method as
- // it allows tracks and events to reset their state as well as prepare
- // themselves for playback.
- //
- //-----------------------------------------------------------------------------
- void VController::reset( const S32 &pTime )
- {
- // Reset Time.
- mTime = pTime;
- mLastTime = Sim::getCurrentTime();
- // Reset Delay Time.
- mLoopDelayTime = 0;
- // Post Event.
- postEvent( k_EventReset );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::play();
- //
- // Start playing the sequence from the current time and execute a number of
- // callbacks.
- //
- //-----------------------------------------------------------------------------
- void VController::play( void )
- {
- if ( isPlaying() || mTime < 0 || mTime > mDuration )
- {
- // Sanity!
- return;
- }
- // Reset Time.
- mLastTime = Sim::getCurrentTime();
- // Start Updating.
- setProcessTicks( true );
- if ( mStatus & k_StatusInit )
- {
- // Init Signal.
- postEvent( k_EventInit );
- // Clear Init Status.
- mStatus &= ~k_StatusInit;
- }
- // Update Status.
- updateStatus( k_StatusPlaying );
- // Play Signal.
- postEvent( k_EventPlay );
- // Callback.
- Con::executef( this, "onPlay" );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::play( pTime );
- //
- // Start playing the sequence from the desired time.
- //
- //-----------------------------------------------------------------------------
- void VController::play( const S32 &pTime )
- {
- // Reset.
- reset( pTime );
- // Play.
- play();
- }
- //-----------------------------------------------------------------------------
- //
- // VController::pause();
- //
- // Cease playback of the sequence, but maintain the current time.
- //
- //-----------------------------------------------------------------------------
- void VController::pause( void )
- {
- // Stop Updating.
- setProcessTicks( false );
- // Update Status.
- updateStatus( k_StatusPaused );
- // Pause Signal.
- postEvent( k_EventPause );
- // Callback.
- Con::executef( this, "onPause" );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::stop( pReset );
- //
- // Stop playback altogether and reset the Controller to the start of the
- // sequence.
- //
- //-----------------------------------------------------------------------------
- void VController::stop( const bool &pReset )
- {
- // Stop Updating.
- setProcessTicks( false );
- // Reset Loop Index.
- mLoopIndex = 0;
- // Update Status.
- updateStatus( ( k_StatusInit | k_StatusStopped ) );
- // Reset?
- if ( pReset )
- {
- // Reset.
- reset();
- }
- // Stop Signal.
- postEvent( k_EventStop );
- // Callback.
- Con::executef( this, "onStop" );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::jump();
- //
- // Jump the Controller time forward 1 tick (32ms).
- //
- //-----------------------------------------------------------------------------
- void VController::jump( void )
- {
- // Jump 1 tick.
- jump( k_JumpDelta, ( isPlayingForward() ) ? TickMs : -TickMs );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::jump( pType, pDelta );
- //
- // Jump the Controller time by the target Delta.
- //
- //-----------------------------------------------------------------------------
- void VController::jump( const eControllerJumpType &pType, const S32 &pDelta )
- {
- // Jump.
- mJump = pType;
- mJumpTime = pDelta;
- }
- //-----------------------------------------------------------------------------
- //
- // VController::updateStatus( pStatus );
- //
- // Clear the regular playback states and add the updated state.
- //
- //-----------------------------------------------------------------------------
- void VController::updateStatus( const S32 &pStatus )
- {
- // Clear Playback Status.
- mStatus &= ~( k_StatusPlaying | k_StatusPaused | k_StatusStopped );
- // Add New Status.
- mStatus |= pStatus;
- }
- //-----------------------------------------------------------------------------
- //
- // Reference Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::getObject( pLabel );
- //
- // Returns the group with the given name. If no group belongs to the Controller
- // with that name, then a NULL value is returned.
- //
- //-----------------------------------------------------------------------------
- VGroup *VController::getObject( const String &pLabel )
- {
- VGroup *node = ( VGroup* )mChildNode;
- while ( node )
- {
- // Compare Names.
- if ( node->getLabel().equal( pLabel, String::NoCase ) )
- {
- // Valid.
- return node;
- }
- // Next Sibling.
- node = ( VGroup* )node->mSiblingNextNode;
- }
- // Invalid.
- return NULL;
- }
- //-----------------------------------------------------------------------------
- //
- // VController::getDirectorGroup();
- //
- // Returns the DirectorGroup reference if the Controller has a one.
- //
- //-----------------------------------------------------------------------------
- VDirectorGroup *VController::getDirectorGroup( void )
- {
- for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
- {
- if ( VDirectorGroup *group = dynamic_cast<VDirectorGroup*>( node ) )
- {
- // Return Group.
- return group;
- }
- }
- // Invalid Group.
- return NULL;
- }
- //-----------------------------------------------------------------------------
- //
- // VController::getDirectorTrack();
- //
- // Returns the DirectorTrack reference if the DirectorGroup has one.
- //
- //-----------------------------------------------------------------------------
- VDirectorTrack *VController::getDirectorTrack( void )
- {
- VDirectorGroup *group = getDirectorGroup();
- if ( !group )
- {
- // Invalid Track.
- return NULL;
- }
- // Return Track.
- return group->getDirectorTrack();
- }
- //-----------------------------------------------------------------------------
- //
- // VController::getDataValue( pFieldName, *pValue );
- //
- // Returns true if the field is a DataTable member and can be correctly
- // evaluated. If this is the case, then pValue will contain the result.
- //
- //-----------------------------------------------------------------------------
- bool VController::getDataValue( const String &pFieldName, String &pValue )
- {
- return mDataTable.getValue( this, pFieldName, pValue );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::clearData();
- //
- // Clear the contents of the DataTable entirely.
- //
- //-----------------------------------------------------------------------------
- void VController::clearData( void )
- {
- while ( mDataTable.getCount() > 0 )
- {
- // Clear Item.
- clearData( 0 );
- }
- }
- //-----------------------------------------------------------------------------
- //
- // VController::clearData( pIndex );
- //
- // Clear the DataTable entry with the given index.
- //
- //-----------------------------------------------------------------------------
- void VController::clearData( const S32 &pIndex )
- {
- VDataTable::sDataItem data;
- if ( mDataTable.getItem( pIndex, &data ) )
- {
- // Clear Data.
- clearData( data.FieldName );
- }
- }
- //-----------------------------------------------------------------------------
- //
- // VController::clearData( pIndex );
- //
- // Clear the DataTable entry with the given field name.
- //
- //-----------------------------------------------------------------------------
- void VController::clearData( const String &pFieldName )
- {
- // Clear Dynamic Field.
- setDataField( pFieldName, NULL, "" );
- // Clear Item.
- mDataTable.clear( pFieldName );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::sort();
- //
- // Sort each track in each of the child groups.
- //
- //-----------------------------------------------------------------------------
- void VController::sort( void )
- {
- for ( ITreeNode *group = mChildNode; group != NULL; group = group->mSiblingNextNode )
- {
- for ( ITreeNode *track = group->mChildNode; track != NULL; track = track->mSiblingNextNode )
- {
- // Sort Track.
- ( ( VTrack* )track )->sort();
- }
- }
- }
- //-----------------------------------------------------------------------------
- //
- // Write Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::writeDataTable( pElement );
- //
- // Write the DataTable out to a TinyXML document.
- //
- //-----------------------------------------------------------------------------
- bool VController::writeDataTable( tinyxml2::XMLElement *pElement )
- {
- // Create Data Table Root.
- tinyxml2::XMLElement *dataTableRoot = pElement->GetDocument()->NewElement( "DataTable" );
- pElement->LinkEndChild( dataTableRoot );
- for ( VDataTable::VDataMap::Iterator itr = mDataTable.mDataMap.begin(); itr != mDataTable.mDataMap.end(); ++itr )
- {
- // Fetch Data.
- VDataTable::sDataItem *data = &itr->value;
- // Create Element.
- tinyxml2::XMLElement* dataElement = pElement->GetDocument()->NewElement( "DataItem" );
- // Apply Attributes.
- dataElement->SetAttribute( "Type", VDataTable::getDataTypeDescription( data->Type ) );
- dataElement->SetAttribute( "Name", data->FieldName.c_str() );
- dataElement->SetAttribute( "Value", getDataField( StringTable->insert( data->FieldName.c_str() ), NULL ) );
- // Add.
- dataTableRoot->LinkEndChild( dataElement );
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- //
- // Read Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::readDataTable( pElement );
- //
- // Read the DataTable from a TinyXML document.
- //
- //-----------------------------------------------------------------------------
- bool VController::readDataTable( tinyxml2::XMLElement *pElement )
- {
- tinyxml2::XMLElement *dataTableRoot = pElement->FirstChildElement( "DataTable" );
- if ( dataTableRoot )
- {
- for ( tinyxml2::XMLElement *child = dataTableRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() )
- {
- // Get Field Data.
- const char *fieldType = child->Attribute( "Type" );
- const char *fieldName = child->Attribute( "Name" );
- const char *fieldValue = child->Attribute( "Value" );
- // Add Data Item.
- mDataTable.insert( VDataTable::getDataTypeEnum( fieldType ), fieldName );
- // Set Field Value.
- setDataField( StringTable->insert( fieldName ), NULL, fieldValue );
- }
- }
-
- // Valid Read.
- return true;
- }
- //-----------------------------------------------------------------------------
- //
- // Property Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VController::postEvent( pEvent );
- //
- // Process an event signal to all event subscribers. This method is used to
- // signal changes in the Controller's status.
- //
- // For a full list of possible events, see the 'eControllerEventType'
- // declaration in VController.h.
- //
- //-----------------------------------------------------------------------------
- void VController::postEvent( const eControllerEventType &pEvent )
- {
- // Signal Event.
- mControllerEventSignal.trigger( pEvent );
- }
- //-----------------------------------------------------------------------------
- //
- // VController::setTimeScale( pTimeScale );
- //
- // Set the speed of playback. In effect, a value of 0.5 will double the real
- // time taken to complete the playback of the sequence, while a value of 2.0
- // will halve the time needed.
- //
- //-----------------------------------------------------------------------------
- void VController::setTimeScale( const F32 &pTimeScale )
- {
- // Need an Update?
- const bool update = ( pTimeScale != 0.f && ( mTimeScale == 0.f || ( ( mTimeScale > 0.f ) != ( pTimeScale > 0.f ) ) ) );
- // Store.
- mTimeScale = pTimeScale;
- // Update $timeScale Variable.
- Con::setFloatVariable( "timeScale", mFabs( mTimeScale ) );
- if ( update )
- {
- // Reset.
- reset( mTime );
- }
- }
- //-----------------------------------------------------------------------------
- //
- // Console Methods.
- //
- //-----------------------------------------------------------------------------
- DefineEngineMethod( VController, readFile, bool, (String fileName), (""), "( string pFileName ) - Clears the object and loads the new data from the given filename.\n"
- "@param pFileName The target file to read from.\n"
- "@return Returns true if the read was successful." )
- {
- // Clear Sequence Lists.
- object->clear();
- // Clear Data Table.
- object->clearData();
- // Read Target File.
- if ( !VPersistence::readFile( fileName, object ) )
- {
- // Re-Clear.
- object->clear();
- // Invalid Read.
- return false;
- }
- // Initial Sort.
- object->sort();
- // Reset.
- object->reset();
- // Valid Read.
- return true;
- }
- DefineEngineMethod( VController, clear, void, (), , "( void ) - Detaches and deletes all of the child objects.\n"
- "@return No return value." )
- {
- // Clear Sequence Lists.
- object->clear();
- // Clear Data Table.
- object->clearData();
- }
- DefineEngineMethod( VController, reset, void, (S32 time), (-1), "( [int pTime] ) - Reset the Controller's and child object's state.\n"
- "@param pTime The target time to reset to.\n"
- "@return No return value." )
- {
- if (time != -1)
- {
- // Reset Sequence.
- object->reset(time);
- return;
- }
- // Default Reset.
- object->reset();
- }
- DefineEngineMethod( VController, isPlaying, bool, (), , "( void ) - Is the sequence currently playing?\n"
- "@return Returns true if the Controller is playing." )
- {
- // Is Playing?
- return ( object->isPlaying() );
- }
- DefineEngineMethod( VController, play, void, (S32 time), (-1), "( [int pTime] ) - Play the sequence. If a value for pTime is specified, the Controller is reset and played from that time.\n"
- "@param pTime The time to start playing the sequence from.\n"
- "@return No return value." )
- {
- S32 startTime = object->getTime();
- if (time != -1)
- {
- startTime = time;
- }
- // Play From Specified Time.
- object->play( startTime );
- }
- DefineEngineMethod( VController, step, void, (),, "( void ) - Step forward one frame.\n"
- "@return No return value." )
- {
- if ( object->isPlaying() )
- {
- // Sanity!
- return;
- }
- // Play.
- object->play( object->getTime() );
- // Jump.
- object->jump();
- // Step Forward One Frame.
- object->processTick();
- // Stop.
- object->stop( false );
- }
- DefineEngineMethod( VController, isPaused, bool, (), , "( void ) - Is the sequence currently paused?\n"
- "@return Returns true if the Controller is paused." )
- {
- // Is Paused?
- return ( object->isPaused() );
- }
- DefineEngineMethod( VController, pause, void, (), , "( void ) - Pause the sequence. Playback can resume by calling VController::play().\n"
- "@return No return value." )
- {
- // Pause Sequence.
- object->pause();
- }
- DefineEngineMethod( VController, isStopped, bool, (), , "( void ) - Is the sequence currently stopped?\n"
- "@return Returns true if the Controller is stopped." )
- {
- // Is Stopped?
- return ( object->isStopped() );
- }
- DefineEngineMethod( VController, stop, void, (bool reset), (true), "( [bool pReset] ) - Stop the sequence and optionally reset it.\n"
- "@param pReset Reset the Controller after stopping.\n"
- "@return No return value." )
- {
- // Stop Sequence.
- object->stop(reset);
- }
- DefineEngineMethod( VController, getTimeScale, F32, (), , "( void ) - Get the playback speed. A value > 0.0 will enable the Controller to play forwards, while a value < 0.0 will play backwards.\n"
- "@return Playback Speed." )
- {
- // Get Time Scale.
- return object->getTimeScale();
- }
- DefineEngineMethod( VController, setTimeScale, void, (float timeScale), (1), "( float pTimeScale ) - Set the playback speed. A value > 0.0 will enable the Controller to play forwards, while a value < 0.0 will play backwards. If |pTimeScale| > 1.0, then playback will be faster than normal, while |pTimeScale| < 1.0 will be slower.\n"
- "@param pTimeScale Playback speed.\n"
- "@return No return value." )
- {
- // Set Time Scale.
- object->setTimeScale(timeScale);
- }
- DefineEngineMethod( VController, isDataField, bool, (String fieldName), (""), "( string pFieldName ) - Is the field a member of the Data Table?\n"
- "@param pFieldName The name of the dynamic field you wish to check.\n"
- "@return Returns true if the field is a member of the Data Table." )
- {
- if (fieldName.isEmpty())
- {
- return false;
- }
- // Is Field.
- return object->getDataTable().getItem(fieldName);
- }
- DefineEngineMethod( VController, getDataFieldCount, S32, (), , "( void ) - Get the number of data elements in the Data Table.\n"
- "@return Returns the size of the Data Table." )
- {
- // Return Count.
- return object->getDataTable().getCount();
- }
- DefineEngineMethod( VController, getDataFieldName, const char *, (S32 index), (0), "( int pIndex ) - Get the name of the field given by the passed index.\n"
- "@param pIndex The index of the data field you wish to check.\n"
- "@return Returns the name of the field corresponding to the given index." )
- {
- VDataTable::sDataItem data;
- if ( !object->getDataTable().getItem(index, &data ) || data.Type == VDataTable::k_TypeInvalid )
- {
- // Invalid Field.
- return "";
- }
- // Return Field Name.
- return data.FieldName;
- }
- DefineEngineMethod( VController, getDataFieldValue, const char *, (String fieldName), (""), "( string pFieldName ) - Get the evaluated data from the data field.\n"
- "@param pFieldName The name of the field you wish to evaluate.\n"
- "@return Returns the evaluated data from the field." )
- {
- String fieldValue;
- if ( object->getDataValue(fieldName, fieldValue ) )
- {
- // Create Buffer.
- char *buffer = Con::getReturnBuffer( 256 );
- dStrcpy( buffer, fieldValue.c_str(), 256 );
- // Return Value.
- return buffer;
- }
- // Return NULL.
- return "0";
- }
- DefineEngineMethod( VController, getDataFieldType, const char *, (String fieldName), (""), "( string pFieldName ) - Get the type of data for the given field.\n"
- "@param pFieldName The name of the field you wish to check.\n"
- "@return Returns the data type." )
- {
- VDataTable::sDataItem data;
- if ( !object->getDataTable().getItem(fieldName, &data ) || data.Type == VDataTable::k_TypeInvalid )
- {
- // Invalid Field.
- return "";
- }
- // Return Field Type.
- return VDataTable::getDataTypeDescription( data.Type );
- }
- #ifdef VT_EDITOR
- //-----------------------------------------------------------------------------
- //
- // Debug Methods.
- //
- //-----------------------------------------------------------------------------
- DefineEngineMethod( VController, writeFile, bool, (String fileName), (""), "( string pFileName ) - Save to a given filename.\n"
- "@param pFileName The target file to write to.\n"
- "@return Returns true if the write was successful." )
- {
- // Write Target File.
- return VPersistence::writeFile(fileName.c_str(), object );
- }
- DefineEngineMethod( VController, readTemplate, bool, (String fileName), (""), "( string pFileName ) - Load data from given filename.\n"
- "@param pFileName The target file to read from.\n"
- "@return Returns true if the read was successful." )
- {
- // Read Target File.
- return VPersistence::readFile(fileName.c_str(), object );
- }
- DefineEngineMethod( VController, getCount, S32, (),, "( void ) - Get the number of child objects.\n"
- "@return Returns the number of child objects." )
- {
- // Size.
- return object->size();
- }
- DefineEngineMethod( VController, getObject, S32, (S32 index), (0), "( int pIndex ) - Get the object corresponding to the given index.\n"
- "@param pIndex The index of the object you wish to retrieve.\n"
- "@return Returns the SimObjectID for the object." )
- {
- // Fetch Object.
- VObject *objectRef = ( VObject* )object->at(index);
- // Return Group ID.
- return ( objectRef ) ? objectRef->getId() : 0;
- }
- DefineEngineMethod( VController, addObject, void, (SimObject* simObj), (nullAsType<SimObject*>()), "( SimObject pObject ) - Add a child object to this node.\n"
- "@param pObject The SimObjectID of the object to be added to this node.\n"
- "@return No return value." )
- {
- if (simObj == nullptr)
- return;
- VObject *child = dynamic_cast<VObject*>(simObj);
- if ( child )
- {
- // Add Child.
- child->addTo( object );
- }
- }
- DefineEngineMethod( VController, removeObject, void, (SimObject* simObj), (nullAsType<SimObject*>()), "( SimObject pObject ) - Remove the target object from this node.\n"
- "@param pObject The SimObjectID of the object to be removed from this node.\n"
- "@return No return value." )
- {
- if (simObj == nullptr)
- return;
- VObject *child = dynamic_cast<VObject*>(simObj);
- if ( child && child->getParent() == object )
- {
- child->remove();
- }
- }
- DefineEngineMethod( VController, sortGroups, void, (),, "( void ) - Sort Groups by their Labels.\n"
- "@return No return value." )
- {
- // Ensure that the Director Group is the First Group.
- VDirectorGroup *directorGroup = object->getDirectorGroup();
- if ( directorGroup && directorGroup != object->mChildNode )
- {
- // Detach.
- directorGroup->remove();
- // Add to the Front of the Controller.
- directorGroup->addToFront( object );
- }
- const S32 count = object->size();
- for ( S32 j = 0; j < count; j++ )
- {
- ITreeNode *node = object->mChildNode;
- if ( dynamic_cast<VDirectorGroup*>( node ) != NULL )
- {
- // Skip Director Group.
- node = node->mSiblingNextNode;
- }
- for ( ; node != NULL; node = node->mSiblingNextNode )
- {
- VGroup *groupA = ( VGroup* )node;
- VGroup *groupB = ( VGroup* )node->mSiblingNextNode;
- if ( !groupB )
- {
- // No Node.
- break;
- }
- // Swap?
- if ( groupA->getLabel().compare(groupB->getLabel()) > 0 )
- {
- // Get Outer Siblings.
- ITreeNode *prevNode = groupA->mSiblingPrevNode;
- ITreeNode *nextNode = groupB->mSiblingNextNode;
-
- if ( groupA->mParentNode && groupA->mParentNode->mChildNode == groupA )
- {
- // New Child Node.
- groupA->mParentNode->mChildNode = groupB;
- }
- //
- // Move A.
- groupA->mSiblingPrevNode = groupB;
- groupA->mSiblingNextNode = nextNode;
- if ( nextNode )
- {
- // Update Outer Sibling.
- nextNode->mSiblingPrevNode = groupA;
- }
- //
- // Move B.
- groupB->mSiblingPrevNode = prevNode;
- groupB->mSiblingNextNode = groupA;
- if ( prevNode )
- {
- // Update Outer Sibling.
- prevNode->mSiblingNextNode = groupB;
- }
- }
- }
- }
- }
- DefineEngineMethod( VController, sortTracks, void, (),, "( void ) - Sort Tracks by their Labels.\n"
- "@return No return value." )
- {
- for ( ITreeNode *group = object->mChildNode; group != NULL; group = group->mSiblingNextNode )
- {
- const S32 count = ( ( VGroup* )group )->size();
- for ( S32 j = 0; j < count; j++ )
- {
- for ( ITreeNode *node = group->mChildNode; node != NULL; node = node->mSiblingNextNode )
- {
- VTrack *trackA = ( VTrack* )node;
- VTrack *trackB = ( VTrack* )node->mSiblingNextNode;
- if ( !trackB )
- {
- // No Node.
- break;
- }
- // Swap?
- if ( trackA->getLabel().compare(trackB->getLabel()) > 0 )
- {
- // Get Outer Siblings.
- ITreeNode *prevNode = trackA->mSiblingPrevNode;
- ITreeNode *nextNode = trackB->mSiblingNextNode;
-
- if ( trackA->mParentNode && trackA->mParentNode->mChildNode == trackA )
- {
- // New Child Node.
- trackA->mParentNode->mChildNode = trackB;
- }
- //
- // Move A.
- trackA->mSiblingPrevNode = trackB;
- trackA->mSiblingNextNode = nextNode;
- if ( nextNode )
- {
- // Update Outer Sibling.
- nextNode->mSiblingPrevNode = trackA;
- }
- //
- // Move B.
- trackB->mSiblingPrevNode = prevNode;
- trackB->mSiblingNextNode = trackA;
- if ( prevNode )
- {
- // Update Outer Sibling.
- prevNode->mSiblingNextNode = trackB;
- }
- }
- }
- }
- }
- }
- DefineEngineMethod( VController, addDataField, void, (String fieldType, String fieldName), ("", ""), "( string pFieldType, string pFieldName ) - Add a new data entry to the Data Table.\n"
- "@param pFieldType The method of evaluating the field's data.\n"
- "@param pFieldName The name of the field to be added to the Data Table.\n"
- "@return No return value." )
- {
- // Insert Data.
- object->getDataTable().insert( VDataTable::getDataTypeEnum(fieldType), fieldName);
- }
- DefineEngineMethod( VController, removeDataField, void, (String fieldName), (""), "( string pFieldName ) - Remove a data entry from the Data Table.\n"
- "@param pFieldName The name of the field to be removed from the Data Table.\n"
- "@return No return value." )
- {
- // Clear Data Item.
- object->clearData(fieldName);
- }
- #endif
|