VSpawnSphereSpawnTargetTrack.cpp 5.0 KB

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