VSlowMoEvent.cpp 4.1 KB

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