VSpawnSphereSpawnTargetTrack.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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/Extension/Game/VSpawnSphereSpawnTargetTrack.h"
  24. #include "Verve/Torque/TSpawnSphere.h"
  25. //-----------------------------------------------------------------------------
  26. IMPLEMENT_CONOBJECT( VSpawnSphereSpawnTargetTrack );
  27. //-----------------------------------------------------------------------------
  28. VSpawnSphereSpawnTargetTrack::VSpawnSphereSpawnTargetTrack( void )
  29. {
  30. mDespawnOnStop = false;
  31. mDespawnOnLoop = false;
  32. setLabel( "SpawnTargetTrack" );
  33. }
  34. void VSpawnSphereSpawnTargetTrack::initPersistFields( void )
  35. {
  36. // Parent Call.
  37. Parent::initPersistFields();
  38. addField( "DespawnOnLoop", TypeBool, Offset( mDespawnOnLoop, VSpawnSphereSpawnTargetTrack ), "Despawn all targets when the Controller loops?" );
  39. addField( "DespawnOnStop", TypeBool, Offset( mDespawnOnStop, VSpawnSphereSpawnTargetTrack ), "Despawn all targets when the Controller stops playing?" );
  40. }
  41. //-----------------------------------------------------------------------------
  42. //
  43. // Controller Methods.
  44. //
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. //
  48. // VSpawnSphereSpawnTargetTrack::onControllerEvent( pEvent );
  49. //
  50. // For a full list of possible events, see the 'eControllerEventType'
  51. // declaration in VController.h.
  52. //
  53. //-----------------------------------------------------------------------------
  54. bool VSpawnSphereSpawnTargetTrack::onControllerEvent( VController::eControllerEventType pEvent )
  55. {
  56. if ( !Parent::onControllerEvent( pEvent ) )
  57. {
  58. // Skip.
  59. return false;
  60. }
  61. // Enabled?
  62. if ( !isEnabled() )
  63. {
  64. // Continue Processing Events.
  65. return true;
  66. }
  67. switch ( pEvent )
  68. {
  69. case VController::k_EventLoop :
  70. {
  71. if ( mDespawnOnLoop )
  72. {
  73. despawnTargets();
  74. }
  75. } break;
  76. case VController::k_EventStop :
  77. {
  78. if ( mDespawnOnStop )
  79. {
  80. despawnTargets();
  81. }
  82. } break;
  83. }
  84. return true;
  85. }
  86. //-----------------------------------------------------------------------------
  87. //
  88. // Spawn Methods.
  89. //
  90. //-----------------------------------------------------------------------------
  91. //-----------------------------------------------------------------------------
  92. //
  93. // VSpawnSphereSpawnTargetTrack::spawnTarget( pTime, pForward );
  94. //
  95. // Spawn an Object.
  96. //
  97. //-----------------------------------------------------------------------------
  98. void VSpawnSphereSpawnTargetTrack::spawnTarget( void )
  99. {
  100. VTorque::SpawnSphereType *object;
  101. if ( !getSceneObject( object ) )
  102. {
  103. return;
  104. }
  105. // Spawn the Object.
  106. SimObject *spawnedObject = object->spawnObject();
  107. // Scene Object?
  108. VTorque::SceneObjectType *sceneObject = dynamic_cast<VTorque::SceneObjectType*>( spawnedObject );
  109. if ( sceneObject )
  110. {
  111. sceneObject->setPosition( object->getPosition() );
  112. }
  113. // Valid?
  114. if ( spawnedObject )
  115. {
  116. // Add Reference.
  117. mSpawnList.addObject( spawnedObject );
  118. }
  119. }
  120. //-----------------------------------------------------------------------------
  121. //
  122. // VSpawnSphereSpawnTargetTrack::despawnTargets();
  123. //
  124. // Despawn all of the objects spawned by this track.
  125. //
  126. //-----------------------------------------------------------------------------
  127. void VSpawnSphereSpawnTargetTrack::despawnTargets( void )
  128. {
  129. while( mSpawnList.size() > 0 )
  130. {
  131. // Fetch the Last Object
  132. SimObject *object = mSpawnList.last();
  133. // Remove it.
  134. mSpawnList.popObject();
  135. // Delete the Object.
  136. object->deleteObject();
  137. }
  138. }