void JAnmSound::OnPlay() { if (!g_pSoundServer) { return; } if (m_SoundID == -1) { ResInit(); } g_pSoundServer->Play( m_SoundID, IsLooped() ); } // JAnmSound::OnPlay
//------------------------------------------------------------------------------ // bool gosFX::Effect::Execute(ExecuteInfo *info) { Check_Object(this); Check_Pointer(info); Verify(IsExecuted()); gos_PushCurrentHeap(Heap); // //----------------------------------------------------- // If a new seed is provided, override the current seed //----------------------------------------------------- // if (info->m_seed != -1.0f) { Verify(info->m_seed>=0.0f && info->m_seed<1.0f); m_seed = info->m_seed; } // //-------------------------------------------- // Figure out the new age and clear the bounds //-------------------------------------------- // Stuff::Scalar age = m_age + static_cast<Stuff::Scalar>(info->m_time - m_lastRan) * m_ageRate; Verify(age >= 0.0f && age >= m_age); *info->m_bounds = Stuff::OBB::Identity; // //-------------------------------- // Update the effectToWorld matrix //-------------------------------- // Check_Object(info->m_parentToWorld); m_localToWorld.Multiply(m_localToParent, *info->m_parentToWorld); // //-------------------------------------------------- // Check to see if the top event needs to be handled //-------------------------------------------------- // Check_Object(m_specification); Event *event; while ((event = m_event.GetCurrent()) != NULL) { Check_Object(event); if (event->m_time > m_age) break; // //------------------------------------------------------------- // This event needs to go, so spawn and bump the effect pointer //------------------------------------------------------------- // unsigned flags = ExecuteFlag; if ((event->m_flags&SimulationModeMask) == ParentSimulationMode) { Verify((m_flags&SimulationModeMask) != ParentSimulationMode); flags |= m_flags&SimulationModeMask; } else flags |= event->m_flags&SimulationModeMask; Effect* effect = EffectLibrary::Instance->MakeEffect( event->m_effectID, flags ); Register_Object(effect); m_children.Add(effect); m_event.Next(); // //--------------------------------------------- // Now set the info for starting the new effect //--------------------------------------------- // effect->m_localToParent = event->m_localToParent; Stuff::Scalar min_seed = m_specification->m_minimumChildSeed.ComputeValue(m_age, m_seed); Stuff::Scalar seed_range = m_specification->m_maximumChildSeed.ComputeValue(m_age, m_seed) - min_seed; Stuff::Scalar seed = Stuff::Random::GetFraction()*seed_range + min_seed; Clamp(seed, 0.0f, 1.0f); ExecuteInfo local_info( info->m_time, &m_localToWorld, NULL, seed ); effect->Start(&local_info); } // //------------------------------------------------------------ // Execute all the children. If any of them finish, kill them //------------------------------------------------------------ // Stuff::ChainIteratorOf<gosFX::Effect*> children(&m_children); gosFX::Effect *child; Stuff::OBB child_obb = Stuff::OBB::Identity; ExecuteInfo child_info( info->m_time, &m_localToWorld, &child_obb ); child_info.m_bounds = &child_obb; while ((child = children.ReadAndNext()) != NULL) { Check_Object(child); if (!child->Execute(&child_info)) { Unregister_Object(child); delete child; } // //-------------------------------------------------------------- // Merge the bounding sphere of the child into the bounds of the // parent //-------------------------------------------------------------- // Stuff::OBB parent_bounds; parent_bounds.Multiply(child_obb, m_localToParent); info->m_bounds->Union(*info->m_bounds, parent_bounds); } Check_Object(info->m_bounds); // //---------------------------------------------------------------------- // Set the new time, then if we have run the course of the effect, start // over if we loop, otherwise wait for our children to finish before // killing ourselves //---------------------------------------------------------------------- // m_lastRan = info->m_time; m_age = age; if (m_age >= 1.0f) { if (IsLooped()) Start(info); else if (HasFinished()) Kill(); } // //---------------------------------- // Tell our parent if we need to die //---------------------------------- // gos_PopCurrentHeap(); return IsExecuted(); }
// -------------------------------------------------------------------------- // // Sound property functions // -------------------------------------------------------------------------- // void VFmodSoundObject::Play(float fStartTime, bool bAlsoInEditor) { if (m_spResource == NULL || IsPlaying()) return; if (!bAlsoInEditor && !Vision::Editor.IsAnimatingOrPlaying()) return; m_fStartTime = fStartTime; VFmodManager &manager = VFmodManager::GlobalManager(); if (manager.IsInitialized()) { const hkvVec3 &vPos = GetPosition(); // stop old playing if (m_pChannel) m_pChannel->stop(); VFmodSoundResource* pResource = (VFmodSoundResource*)GetResource(); if (pResource->m_pSound == NULL) // sound resource not loaded successfully return; FMOD_WARNINGCHECK(manager.m_pSystem->playSound(FMOD_CHANNEL_FREE, pResource->m_pSound, true, &m_pChannel)); if (!m_pChannel) return; FMOD_WARNINGCHECK(m_pChannel->getFrequency(&m_fInitialFreq)); // if this a music sound object assign it to the music channel group if (IsMusic()) m_pChannel->setChannelGroup(manager.m_pMusicGroup); // set everything m_pChannel->setUserData(this); // ...so that we can get from channel to VSoundObject m_pChannel->setCallback(ChannelCallback); m_pChannel->setMode(IsLooped() ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF); m_pChannel->setPriority(GetPriority()); m_pChannel->set3DMinMaxDistance(Get3DFadeMinDistance(), Get3DFadeMaxDistance()); m_pChannel->set3DAttributes((FMOD_VECTOR *)&vPos, NULL); // no speed (yet) m_pChannel->setVolume(GetVolume()); m_pChannel->setPan(GetPan()); SetPitch(GetPitch()); SetConeAngles(GetConeAngleInside(), GetConeAngleOutside()); // Initially the sound is left paused, then within the first RunTick it is unpaused. This is required since // the 3D listener attributes has to be set prior to playing a sound. Otherwise Fmod would perform // occlusion-raycasts without having initialized listener-attributes, which potentially results in a // wrong occlusion-behavior. m_bUnpause = true; m_bIsPlaying = true; m_bPlayedOnce = true; unsigned int ims = (int)(fStartTime*1000.f); // milliseconds m_pChannel->setPosition(ims,FMOD_TIMEUNIT_MS); m_pChannel->setMute(IsMuted()); } Helper_SetFlag(VFMOD_FLAG_PAUSED, !IsPlaying()); }
void JAnmSound::Render() { if (IsPlaying() && g_pSoundServer) { JAnmContext& ctx = GetContext(); if (ctx.m_bStateOnly) { Stop(); } else if (GetCurTime() >= GetDuration() && g_pSoundServer->IsPlaying( m_SoundID ) && !IsLooped()) { SetDuration( GetCurTime() + c_FltEpsilon ); } g_pSoundServer->Pause( m_SoundID, GetContext().m_TimeDelta == 0.0f || IsPaused() ); } JAnimation::Render(); } // JAnmSound::Render
void CParticlesObject::SetAutoRemove (bool auto_remove) { VERIFY(m_bStopping || !IsLooped()); m_bAutoRemove = auto_remove; }