VSlowMoEvent.cpp
Engine/source/Verve/Extension/Director/VSlowMoEvent.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CONOBJECT(VSlowMoEvent )
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#include "Verve/Core/VController.h" 25#include "Verve/Extension/Director/VSlowMoEvent.h" 26 27#include "console/consoleTypes.h" 28 29//----------------------------------------------------------------------------- 30IMPLEMENT_CONOBJECT( VSlowMoEvent ); 31//----------------------------------------------------------------------------- 32 33VSlowMoEvent::VSlowMoEvent( void ) : 34 mTimeScale( 1.f ), 35 mTimeScaleTickDelta( 0.f ) 36{ 37 setLabel( "SlowMoEvent" ); 38} 39 40void VSlowMoEvent::initPersistFields( void ) 41{ 42 Parent::initPersistFields(); 43 44 addField( "TimeScale", TypeF32, Offset( mTimeScale, VSlowMoEvent ), "The Time Scale to be applied to the Root Controller." ); 45} 46 47//----------------------------------------------------------------------------- 48// 49// Controller Methods. 50// 51//----------------------------------------------------------------------------- 52 53//----------------------------------------------------------------------------- 54// 55// VSlowMoEvent::onTrigger( pTime, pDelta ); 56// 57// 58// 59//----------------------------------------------------------------------------- 60void VSlowMoEvent::onTrigger( const S32 &pTime, const S32 &pDelta ) 61{ 62 Parent::onTrigger( pTime, pDelta ); 63 64 VController *controller = getController(); 65 if ( !controller ) 66 { 67 // Invalid Controller. 68 return; 69 } 70 71 // Instant Update? 72 if ( getDuration() == 0 ) 73 { 74 // Apply & Return. 75 controller->setTimeScale( mTimeScale ); 76 return; 77 } 78 79 // Determine the Number of Ticks. 80 const F32 tickCount = ( ( F32 )getDuration() ) / TickMs; 81 82 // Determine the Tick Delta. 83 mTimeScaleTickDelta = ( mTimeScale - controller->getTimeScale() ) / tickCount; 84} 85 86//----------------------------------------------------------------------------- 87// 88// VSlowMoEvent::onUpdate( pTime, pDelta ); 89// 90// 91// 92//----------------------------------------------------------------------------- 93void VSlowMoEvent::onUpdate( const S32 &pTime, const S32 &pDelta ) 94{ 95 Parent::onUpdate( pTime, pDelta ); 96 97 VController *controller = getController(); 98 if ( !controller ) 99 { 100 // Invalid Controller. 101 return; 102 } 103 104 // Fetch Current Time Scale. 105 const F32 timeScale = controller->getTimeScale(); 106 107 // Apply Update. 108 controller->setTimeScale( timeScale + mTimeScaleTickDelta ); 109} 110 111//----------------------------------------------------------------------------- 112// 113// VSlowMoEvent::onComplete( pTime, pDelta ); 114// 115// 116// 117//----------------------------------------------------------------------------- 118void VSlowMoEvent::onComplete( const S32 &pTime, const S32 &pDelta ) 119{ 120 Parent::onComplete( pTime, pDelta ); 121 122 VController *controller = getController(); 123 if ( !controller ) 124 { 125 // Invalid Controller. 126 return; 127 } 128 129 // Tidy Up. 130 controller->setTimeScale( mTimeScale ); 131} 132