VSpawnSphereSpawnTargetTrack.cpp 4.9 KB

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