Torque3D Documentation / _generateds / VSpawnSphereSpawnTargetTrack.cpp

VSpawnSphereSpawnTargetTrack.cpp

Engine/source/Verve/Extension/Game/VSpawnSphereSpawnTargetTrack.cpp

More...

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(VSpawnSphereSpawnTargetTrack )

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