void AudioDevice::playSound2D(const std::string& soundfile, SoundType type) { if ((m_engine != NULL) && ! soundfile.empty()) { FileSystem::markFileUsed(soundfile); const bool loop = (type == MUSIC); ISound* sound = m_engine->play2D(soundfile.c_str(), loop, START_PAUSED, RETURN_REFERENCE); switch (type) { case MUSIC: sound->setVolume(m_musicVolume * MUSIC_VOLUME_CONSTANT); if (m_music) { // Stop the previous music and replace it with this m_music->stop(); m_music->drop(); } m_music = sound; sound->setIsPaused(false); break; case UI: sound->setVolume(m_uiVolume * UI_VOLUME_CONSTANT); sound->setIsPaused(false); sound->drop(); break; case EFFECT: sound->setVolume(m_effectVolume * EFFECT_VOLUME_CONSTANT); sound->setPlaybackSpeed(speedAdjust(m_timeScaleAtListener)); sound->setIsPaused(false); sound->drop(); break; } } }
float CCE3SoundWrapper::GetPosition() { ISound* sound = GetPreferredSound(); if ( sound ) { unsigned int nSoundPos = sound->GetInterfaceExtended()->GetCurrentSamplePos( true ); if ( nSoundPos ) { // successfully got a position float fSoundPos = float( nSoundPos ) / MILLISECOND; // make loops possible so use float modulo with sync target end (loops in this FMOD integration don't reset position) float fEnd = m_pSyncTimesource->GetEnd(); if ( fEnd >= VIDEO_EPSILON ) { bool bSeek = fSoundPos > fEnd; fSoundPos = fmod( fSoundPos, fEnd ); if ( bSeek ) { // if soundpos is beyond end then seek to normal starting position again fSoundPos += m_pSyncTimesource->GetStart(); Seek( fSoundPos ); } } return fSoundPos; } } return -1; }
void MusicPlayer::AddSound(string filename) { IStreamingSoundResourcePtr resource = ResourceManager<IStreamingSoundResource>::Create(filename); // ISoundResourcePtr resource = // ResourceManager<ISoundResource>::Create(filename); ISound* sound = system->CreateSound(resource); // @todo: ugly cast only for testing if (sound->IsStereoSound()) { IMonoSound* left = ((IStereoSound*)sound)->GetLeft(); left->SetRelativePosition(true); left->SetPosition(Vector<3,float>(-10.0,0.0,0.0)); IMonoSound* right = ((IStereoSound*)sound)->GetRight(); right->SetRelativePosition(true); right->SetPosition(Vector<3,float>(10.0,0.0,0.0)); } else if (sound->IsMonoSound()) { IMonoSound* mono = ((IMonoSound*)sound); mono->SetRelativePosition(true); mono->SetPosition(Vector<3,float>(0.0,0.0,0.0)); } playlist.push_back((ISound*) sound); sound->SetGain(gain); // if we are playing the last number and insert a new // one, then update which number should be next nextTrackNumber = NextNumber(); //@todo: set the sound to be relative to the listener i openal }
//------------------------------------------------------------------------ void CProjectile::WhizSound(bool enable, const Vec3 &pos, const Vec3 &dir) { if(enable) { if(!m_pAmmoParams->pWhiz) return; ISound *pSound=gEnv->pSoundSystem->CreateSound(m_pAmmoParams->pWhiz->sound, FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_SELFMOVING); if(pSound) { m_whizSoundId = pSound->GetId(); pSound->SetSemantic(eSoundSemantic_Projectile); pSound->SetPosition(pos); pSound->SetDirection(dir*m_pAmmoParams->pWhiz->speed); pSound->Play(); } } else if(m_whizSoundId!=INVALID_SOUNDID) { ISound *pSound = gEnv->pSoundSystem->GetSound(m_whizSoundId); // only stop looping sounds and oneshots does not get cut when hitting a surface if(pSound && pSound->GetFlags() & FLAG_SOUND_LOOP) pSound->Stop(); m_whizSoundId=INVALID_SOUNDID; } }
ISound* CCE3SoundWrapper::GetPreferredSound() { // Return last preferred sound if he is still consistent, else search a new one ISound* pPreferredSound = NULL; ISound* pFallbackSound = NULL; // better then nothing... // last preferred source still there? if ( gEnv && gEnv->pSoundSystem ) { pPreferredSound = gEnv->pSoundSystem->GetSound( m_nPreferredDataSource ); } // is his playback state still consistent? if ( pPreferredSound && pPreferredSound->IsLoaded() && pPreferredSound->IsInitialized() && PLAYSTATE_CONSISTENT( pPreferredSound ) ) { goto success; } // If not the check the 2d sound if ( Is2DSoundActive() && PLAYSTATE_CONSISTENT( m_p2DSound ) ) { m_nPreferredDataSource = m_p2DSound->GetId(); pPreferredSound = m_p2DSound; goto success; } pFallbackSound = m_p2DSound; // better then nothing... // Or one from the proxies for ( tEntitySoundProxyMap::iterator iterSound = m_SoundProxies.begin(); iterSound != m_SoundProxies.end(); ++iterSound ) { if ( iterSound->second.IsActive() && PLAYSTATE_CONSISTENT( iterSound->second.GetSound() ) ) { pPreferredSound = iterSound->second.GetSound(); m_nPreferredDataSource = pPreferredSound->GetId(); goto success; } // better then nothing... if ( !pFallbackSound && iterSound->second.IsExisting() ) { pFallbackSound = iterSound->second.GetSound(); } } // if nothing reliable was found m_nPreferredDataSource = INVALID_SOUNDID; if ( pFallbackSound ) { return pFallbackSound; } return NULL; success: // RefreshMaxDuration( pPreferredSound ); return pPreferredSound; }
void Game::applyRocketsMoves() { // Fly thier ways rockets->fly(timer.delta); effects->drawRocketUpEffect(timer.delta); effects->drawRocketDownEffect(timer.delta); // Getting all nodes rockets hited & indecies for rockets array<u32> *Findecies, *Eindecies; Findecies = new array<u32>(); Eindecies = new array<u32>(); array<ISceneNode *> nodes = rockets->checkRockets(Findecies, Eindecies); effects->deleteRocketUp(Findecies); effects->deleteRocketDown(Eindecies); for (u32 i = 0; i < nodes.size(); i++) { vector3df pos = IDLE_VECTOR; // Checking fot fighter damage and death if (nodes[i] == fighter->getNode()) { fighter->damage(FIGHTER_DAMAGE); if (fighter->isDead()) { if (soundPlay) { ISound *bang = sound->play2D("sounds/bang.wav", false, true); bang->setVolume(0.1f); bang->setIsPaused(false); bang->drop(); } state = OVER; engine->hideCursor(false); drop(); gui->lose(engine->getGUI(), texManager); return; } } // Checking for enemies damage and death else if (enemies->checkNode(nodes[i], engine->getManager(), &score, sound, soundPlay, &pos)) { state = OVER; engine->hideCursor(false); drop(); gui->win(engine->getGUI(), texManager); return; } if (pos != vector3df(IDLE_VECTOR)) effects->addDeath(engine->getManager(), texManager->getEffectsTexture()[0], pos); } // Refrashing score and health gui->setScore(score); if (!fighter->isDead()) gui->setHealth(fighter->getHealth()); }
//------------------------------------------------------------------------ void CScan::Update(float frameTime, uint32 frameId) { if (m_scanning && m_pWeapon->IsClient()) { if (m_delayTimer>0.0f) { m_delayTimer -= frameTime; if (m_delayTimer>0.0f) return; m_delayTimer = 0.0f; int slot = m_pWeapon->GetStats().fp ? eIGS_FirstPerson : eIGS_ThirdPerson; int id = m_pWeapon->GetStats().fp ? 0 : 1; m_scanLoopId=m_pWeapon->PlayAction(m_scanactions.scan, 0, true, CItem::eIPAF_Default|CItem::eIPAF_CleanBlending); ISound *pSound = m_pWeapon->GetSoundProxy()->GetSound(m_scanLoopId); if (pSound) pSound->GetInterfaceDeprecated()->SetLoopMode(true); } if(m_delayTimer==0.0f) { if(m_tagEntitiesDelay>0.0f) { m_tagEntitiesDelay-=frameTime; if(m_tagEntitiesDelay<=0.0f) { m_tagEntitiesDelay = 0.0f; //Here is when entities are displayed on Radar if(gEnv->pGame->GetIGameFramework()->GetClientActor() == m_pWeapon->GetOwnerActor()) { if(gEnv->bServer) NetShoot(ZERO, 0); else m_pWeapon->RequestShoot(0, ZERO, ZERO, ZERO, ZERO, 1.0f, 0, false); } } } if (m_durationTimer>0.0f) { m_durationTimer-=frameTime; if (m_durationTimer<=0.0f) { m_durationTimer=0.0f; StopFire(); //m_pWeapon->RequestShoot(0, ZERO, ZERO, ZERO, ZERO, 1.0f, 0, false); } } } m_pWeapon->RequireUpdate(eIUS_FireMode); } }
//------------------------------------------------------------------------ void CScan::NetStartFire() { if (!m_pWeapon->IsClient()) return; m_scanLoopId=m_pWeapon->PlayAction(m_scanactions.scan); ISound *pSound = m_pWeapon->GetSoundProxy()->GetSound(m_scanLoopId); if (pSound) pSound->GetInterfaceDeprecated()->SetLoopMode(true); }
//------------------------------------------------------------------------ void CRapid::UpdateSound(float frameTime) { if (m_speed >= 0.00001f) { if (m_soundId == INVALID_SOUNDID) { m_soundId = m_pWeapon->PlayAction(m_pShared->rapidactions.rapid_fire, 0, true, CItem::eIPAF_Default & (~CItem::eIPAF_Animation)); } if (m_soundId != INVALID_SOUNDID) { float rpm_scale = m_speed / m_pShared->rapidparams.min_speed; float ammo = 0; if (!OutOfAmmo()) { ammo = 1.0f; } ISound *pSound = m_pWeapon->GetISound(m_soundId); if (pSound) { if (g_pGameCVars->i_debug_sounds) { float color[] = {1, 1, 1, 0.5}; gEnv->pRenderer->Draw2dLabel(150, 500, 1.3f, color, false, "%s rpm_scale: %.2f", m_pWeapon->GetEntity()->GetName(), rpm_scale); } pSound->SetParam("rpm_scale", rpm_scale, false); pSound->SetParam("ammo", ammo, false); //Sound variations for FY71 (AI most common weapon) if(m_pShared->fireparams.sound_variation && !m_pWeapon->IsOwnerFP()) { pSound->SetParam("variations", m_soundVariationParam, true); } } if (m_speed >= m_pShared->rapidparams.min_speed) { m_spinUpSoundId = INVALID_SOUNDID; } } } else if (m_soundId != INVALID_SOUNDID) { m_pWeapon->StopSound(m_soundId); m_soundId = INVALID_SOUNDID; } }
void Entity::Knockback(Vector3 dir) { kbVelocity.x += dir.x; if (velocity.y <= 0) velocity.y += 5; kbVelocity.z += dir.z; vector<char*> soundFileName; if (entityID == HORSE) { soundFileName.push_back("Assets/Media/Damage/horseCry1.mp3"); soundFileName.push_back("Assets/Media/Damage/horseCry2.mp3"); soundFileName.push_back("Assets/Media/Damage/horseCry3.mp3"); soundFileName.push_back("Assets/Media/Damage/horseCry4.mp3"); } //else if (entityID == SENTRY || entityID == ENEMY_2 || entityID == ENEMY_3) //{ // // Enemy Kenna Hit Sound // soundFileName.push_back("Assets/Media/Damage/enemyCry1.mp3"); // soundFileName.push_back("Assets/Media/Damage/enemyCry2.mp3"); // soundFileName.push_back("Assets/Media/Damage/enemyCry3.mp3"); //} else if (entityID == WOLF) { // Wolf Kenna Hit Sound soundFileName.push_back("Assets/Media/Damage/wolfCry1.mp3"); soundFileName.push_back("Assets/Media/Damage/wolfCry2.mp3"); soundFileName.push_back("Assets/Media/Damage/wolfCry3.mp3"); } else { soundFileName.push_back("Assets/Media/Damage/hit1.mp3"); soundFileName.push_back("Assets/Media/Damage/hit2.mp3"); soundFileName.push_back("Assets/Media/Damage/hit3.mp3"); } ISound* sound = engine->play3D(soundFileName[rand() % soundFileName.size()], vec3df(position.x, position.y, position.z), false, true); if (sound) { sound->setVolume(1.f); sound->setIsPaused(false); } health -= dir.LengthSquared() * 0.01f; if (health < 1) health = 0; }
void AudioDevice::playSound3D(const std::string& soundfile, const Point3& wsPosition, const Vector3& wsVelocity, const float timeScale) { if ((m_engine != NULL) && ! soundfile.empty()) { FileSystem::markFileUsed(soundfile); ISound* sound = m_engine->play3D(soundfile.c_str(), g3dToirrKlang(wsPosition), ! PLAY_LOOPED, START_PAUSED, RETURN_REFERENCE); if (sound) { // Distance at which the sound plays at "full" volume sound->setMinDistance(200.0f); sound->setVelocity(g3dToirrKlang(wsVelocity * timeScale)); sound->setVolume(m_effectVolume * EFFECT_3D_VOLUME_CONSTANT); m_active3D.append(sound); if (timeScale != 1.0f) { sound->setPlaybackSpeed(speedAdjust(m_timeScaleAtListener)); } // Start playing the sound sound->setIsPaused(false); // Don't drop the reference; we're holding it in m_active3D } } }
int CScriptBind_HUD::TacWarning(IFunctionHandler *pH) { CHUD *pHUD = g_pGame->GetHUD(); if (!pHUD) return pH->EndFunction(); std::vector<CHUDRadar::RadarEntity> buildings = *(pHUD->GetRadar()->GetBuildings()); for(int i = 0; i < buildings.size(); ++i) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(buildings[i].m_id); if(!stricmp(pEntity->GetClass()->GetName(), "HQ")) { Vec3 pos = pEntity->GetWorldPos(); pos.z += 10; ISound *pSound = gEnv->pSoundSystem->CreateSound("sounds/interface:multiplayer_interface:mp_tac_alarm_ambience", FLAG_SOUND_3D); if(pSound) { pSound->SetPosition(pos); pSound->Play(); } } } return pH->EndFunction(); }
void AudioDevice::simulate (const float dt, const float timeScaleAtListener, const CFrame& wsListenerFrame, const Vector3& wsListenerVelocity) { m_listenerPosition = wsListenerFrame.translation; if (m_engine) { m_engine->setListenerPosition (g3dToirrKlang(wsListenerFrame.translation), g3dToirrKlang(wsListenerFrame.lookVector()), g3dToirrKlang(wsListenerVelocity), g3dToirrKlang(wsListenerFrame.upVector())); } m_timeScaleAtListener = timeScaleAtListener; if (m_music) { m_music->setPlaybackSpeed(speedAdjust(timeScaleAtListener)); if (m_music->isFinished()) { m_music->drop(); m_music = NULL; } } // Update already-playing 3D sounds for (int s = 0; s < m_active3D.size(); ++s) { ISound* sound = m_active3D[s]; if (sound->isFinished()) { // End m_active3D.fastRemove(s); --s; } else { sound->setPosition(sound->getPosition() + dt * sound->getVelocity()); } } }
//------------------------------------------------------------------------ void CProjectile::RicochetSound(const Vec3 &pos, const Vec3 &dir) { if (!m_pAmmoParams->pRicochet) return; ISound *pSound = gEnv->pSoundSystem->CreateSound(m_pAmmoParams->pRicochet->sound, FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_SELFMOVING); if (pSound) { pSound->GetId(); pSound->SetSemantic(eSoundSemantic_Projectile); pSound->SetPosition(pos); pSound->SetDirection(dir*m_pAmmoParams->pRicochet->speed); pSound->Play(); } }
// add enum of sound you want to play, and add command to game code at appropiate spot void CGameAudio::PlaySound(EGameAudioSounds eSound, IEntity *pEntity, float param, bool stopSound) { int soundFlag = 0; //localActor will get 2D sounds ESoundSemantic eSemantic = eSoundSemantic_None; ISound *pSound = NULL; bool setParam = false; static string soundName; soundName.resize(0); switch(eSound) { case EGameAudioSound_NOSOUND: break; case EGameAudioSound_LAST: break; default: break; } //if(!force3DSound && m_pOwner == m_pGameFramework->GetClientActor() && !m_pOwner->IsThirdPerson() && soundName.size()) //{ // if (bAppendPostfix) // soundName.append("_fp"); //} IEntitySoundProxy *pSoundProxy = pEntity ? (IEntitySoundProxy *)pEntity->CreateProxy(ENTITY_PROXY_SOUND) : NULL; if(soundName.size() && eSound < EGameAudioSound_LAST) //get / create or stop sound { if(m_sounds[eSound].ID != INVALID_SOUNDID) { if(pSoundProxy) pSound = pSoundProxy->GetSound(m_sounds[eSound].ID); else pSound = gEnv->pSoundSystem->GetSound(m_sounds[eSound].ID); if(stopSound) { if(pSound) pSound->Stop(); m_sounds[eSound].ID = INVALID_SOUNDID; return; } } if(!pSound && !stopSound) { pSound = gEnv->pSoundSystem->CreateSound(soundName, soundFlag); if(pSound) { pSound->SetSemantic(eSemantic); //float fTemp = 0.0f; m_sounds[eSound].ID = pSound->GetId(); m_sounds[eSound].bLooping = (pSound->GetFlags() & FLAG_SOUND_LOOP) != 0; m_sounds[eSound].b3D = (pSound->GetFlags() & FLAG_SOUND_3D) != 0; //m_sounds[eSound].nMassIndex = pSound->GetParam("mass", &fTemp, false); //m_sounds[eSound].nSpeedIndex = pSound->GetParam("speed", &fTemp, false); //m_sounds[eSound].nStrengthIndex = pSound->GetParam("strength", &fTemp, false); } } } if(pSound) //set params and play { //pSound->SetPosition(m_pOwner->GetEntity()->GetWorldPos()); if(setParam) { //if (m_sounds[eSound].nMassIndex != -1) // pSound->SetParam(m_sounds[sound].nMassIndex, param); //if (m_sounds[eSound].nSpeedIndex != -1) // pSound->SetParam(m_sounds[sound].nSpeedIndex, param); //if (m_sounds[eSound].nStrengthIndex != -1) // pSound->SetParam(m_sounds[sound].nStrengthIndex, param); } if(!(m_sounds[eSound].bLooping && pSound->IsPlaying())) { if(pSoundProxy) pSoundProxy->PlaySound(pSound); else pSound->Play(); } } }
//------------------------------------------------------------------------ tSoundID CItem::PlayAction(const ItemString &actionName, int layer, bool loop, uint32 flags, float speedOverride) { if(!m_enableAnimations || !IsOwnerInGame()) return (tSoundID)-1; TActionMap::iterator it = m_sharedparams->actions.find(CONST_TEMPITEM_STRING(actionName)); if(it == m_sharedparams->actions.end()) { // GameWarning("Action '%s' not found on item '%s'!", actionName, GetEntity()->GetName()); for(int i=0; i<eIGS_Last; i++) { m_animationTime[i]=0; m_animationSpeed[i]=1.0f; m_animationEnd[i]=0; } return 0; } bool fp = m_stats.fp; if(m_parentId) { CItem *pParent=static_cast<CItem *>(m_pItemSystem->GetItem(m_parentId)); if(pParent) fp=pParent->GetStats().fp; } if(flags&eIPAF_ForceFirstPerson) fp = true; if(flags&eIPAF_ForceThirdPerson) fp = false; int sid=fp?eIGS_FirstPerson:eIGS_ThirdPerson; SAction &action = it->second; tSoundID result = INVALID_SOUNDID; if((flags&eIPAF_Sound) && !action.sound[sid].name.empty() && IsSoundEnabled() && g_pGameCVars->i_soundeffects) { int nSoundFlags = FLAG_SOUND_DEFAULT_3D; nSoundFlags |= flags&eIPAF_SoundStartPaused?FLAG_SOUND_START_PAUSED:0; IEntitySoundProxy *pSoundProxy = GetSoundProxy(true); //GetSound proxy from dualwield master if neccesary if(IsDualWieldSlave()) { CItem *pMaster = static_cast<CItem *>(GetDualWieldMaster()); if(pMaster) { pSoundProxy = pMaster->GetSoundProxy(true); } } EntityId pSkipEnts[3]; int nSkipEnts = 0; // TODO for Marcio :) // check code changes // Skip the Item pSkipEnts[nSkipEnts] = GetEntity()->GetId(); ++nSkipEnts; // Skip the Owner if(GetOwner()) { pSkipEnts[nSkipEnts] = GetOwner()->GetId(); ++nSkipEnts; } if(pSoundProxy) { TempResourceName name; FixResourceName(action.sound[sid].name, name, flags); //nSoundFlags = nSoundFlags | (fp?FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_RELATIVE:FLAG_SOUND_DEFAULT_3D); Vec3 vOffset(0,0,0); if(fp) vOffset.x = 0.3f; // offset for first person weapon to the front if(!g_pGameCVars->i_staticfiresounds) { result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts); ISound *pSound = pSoundProxy->GetSound(result); if(pSound && action.sound[sid].sphere>0.0f) pSound->SetSphereSpec(action.sound[sid].sphere); } else { SInstanceAudio *pInstanceAudio=0; if(action.sound[sid].isstatic) { TInstanceActionMap::iterator iit = m_instanceActions.find(CONST_TEMPITEM_STRING(actionName)); if(iit == m_instanceActions.end()) { std::pair<TInstanceActionMap::iterator, bool> insertion=m_instanceActions.insert(TInstanceActionMap::value_type(actionName, SInstanceAction())); pInstanceAudio=&insertion.first->second.sound[sid]; } else pInstanceAudio=&iit->second.sound[sid]; } if(pInstanceAudio && (pInstanceAudio->id != INVALID_SOUNDID) && (name != pInstanceAudio->static_name)) ReleaseStaticSound(pInstanceAudio); if(!pInstanceAudio || pInstanceAudio->id == INVALID_SOUNDID) { result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts); ISound *pSound = pSoundProxy->GetSound(result); if(pSound && action.sound[sid].sphere>0.0f) pSound->SetSphereSpec(action.sound[sid].sphere); } if(action.sound[sid].isstatic) { if(pInstanceAudio->id == INVALID_SOUNDID) { if(pSoundProxy->SetStaticSound(result, true)) { pInstanceAudio->id = result; pInstanceAudio->static_name = name; pInstanceAudio->synch = action.sound[sid].issynched; } } else { ISound *pSound = pSoundProxy->GetSound(pInstanceAudio->id); if(pSound) pSound->Play(1.0, true, true, pSoundProxy); } } } if(gEnv->pAISystem && action.sound[sid].airadius > 0.0f) { EntityId ownerId = GetOwner() ? GetOwner()->GetId() : 0; // associate sound event with vehicle if the shooter is in a vehicle (tank cannon shot, etc) if(CActor *pOwnerActor = GetOwnerActor()) { IVehicle *pOwnerVehicle = pOwnerActor->GetLinkedVehicle(); if(pOwnerVehicle && pOwnerVehicle->GetEntityId()) ownerId = pOwnerVehicle->GetEntityId(); } SAIStimulus stim(AISTIM_SOUND, AISOUND_WEAPON, ownerId?ownerId:GetEntityId() , 0, GetEntity()->GetWorldPos(), ZERO, action.sound[sid].airadius); gEnv->pAISystem->RegisterStimulus(stim); } } } if(flags&eIPAF_Animation) { TempResourceName name; // generate random number only once per call to allow animations to // match across geometry slots (like first person and third person) float randomNumber = Random(); for(int i=0; i<eIGS_Last; i++) { if(!(flags&(1<<i))) continue; int nanimations=action.animation[i].size(); if(nanimations <= 0) continue; int anim = int(randomNumber * float(nanimations)); if(action.animation[i][anim].name.empty()) continue; FixResourceName(action.animation[i][anim].name, name, flags); if((i == eIGS_Owner) || (i == eIGS_OwnerLooped)) { if(!action.animation[i][anim].name.empty()) { bool looping=(eIGS_OwnerLooped==i); CActor *pOwner = GetOwnerActor(); if(pOwner) { if(IsDualWield() && !m_sharedparams->params.dual_wield_pose.empty()) pOwner->PlayAction(name, m_sharedparams->params.dual_wield_pose.c_str(), looping); else pOwner->PlayAction(name, m_sharedparams->params.pose.c_str(), looping); } } continue; } else if(i == eIGS_OffHand) { if(!action.animation[eIGS_OffHand][anim].name.empty()) { CActor *pOwner = GetOwnerActor(); if(pOwner) { CItem *pOffHand = pOwner->GetItemByClass(CItem::sOffHandClass); if(pOffHand && pOffHand!=this) { uint32 ohflags=eIPAF_Default; if(action.animation[eIGS_OffHand][anim].blend==0.0f) ohflags|=eIPAF_NoBlend; pOffHand->PlayAction(action.animation[eIGS_OffHand][anim].name, 0, false, ohflags); } } } continue; } SAnimation &animation=action.animation[i][anim]; if(!animation.name.empty()) { float blend = animation.blend; if(flags&eIPAF_NoBlend) blend = 0.0f; if(speedOverride > 0.0f) PlayAnimationEx(name, i, layer, loop, blend, speedOverride, flags); else PlayAnimationEx(name, i, layer, loop, blend, animation.speed, flags); } if((m_stats.fp || m_stats.viewmode&eIVM_FirstPerson) && i==eIGS_FirstPerson && !animation.camera_helper.empty()) { m_camerastats.animating=true; m_camerastats.helper=animation.camera_helper; m_camerastats.position=animation.camera_pos; m_camerastats.rotation=animation.camera_rot; m_camerastats.follow=animation.camera_follow; m_camerastats.reorient=animation.camera_reorient; } else if(m_camerastats.animating) m_camerastats=SCameraAnimationStats(); } } if(flags&eIPAF_Effect && !action.effect[sid].name.empty()) { // change this to attach, if needed SpawnEffect(sid, action.effect[sid].name.c_str(), action.effect[sid].helper.c_str()); } if(action.children) { for(TAccessoryMap::iterator ait=m_accessories.begin(); ait!=m_accessories.end(); ait++) { EntityId aId=(EntityId)ait->second; CItem *pAccessory=static_cast<CItem *>(m_pItemSystem->GetItem(aId)); if(pAccessory) pAccessory->PlayAction(actionName, layer, loop, flags, speedOverride); } } return result; }
void SoundSystem::Play2D(Sound2D* media){ if(Instance().CheckSoundPlaying(media)){//if playing ISound* temp = Instance().currPlayingLoopedSounds[media]; if(!temp->getIsPaused()){ temp->setPlayPosition(0.0f);//set back to beginning } temp->setIsLooped(false); temp->setSoundStopEventReceiver (Instance().sndEndReceiver,media); temp->setVolume(media->volume); temp->setIsPaused(false); }else{ //creates a new sound instance ISound* temp = Instance().soundEngine->play2D(media->mySoundSource,false,false,true); Instance().currPlayingLoopedSounds.insert(std::pair<Sound*,ISound*>(media,temp)); temp->setSoundStopEventReceiver(Instance().sndEndReceiver,media); temp->setVolume(media->volume); temp->setIsPaused(false); } }
void SoundSystem::Play3D(Sound3D* media){ if(Instance().CheckSoundPlaying(media)){//if playing ISound* temp = Instance().currPlayingLoopedSounds[media]; if(!temp->getIsPaused()){ temp->setPlayPosition(0.0f);//set back to beginning } temp->setIsLooped(false); temp->setSoundStopEventReceiver (Instance().sndEndReceiver,media); temp->setVolume(media->volume); temp->setMinDistance(media->minSoundDist); temp->setMaxDistance(FLT_MAX); // max attenuation distance temp->setIsPaused(false); }else{ //creates a new sound instance ISound* temp = Instance().soundEngine->play3D(media->mySoundSource,vec3df(media->GetSoundPosition()[x],media->GetSoundPosition()[y],media->GetSoundPosition()[z]),false,false,true); //ISound* temp = Instance().soundEngine->play3D(media->mySoundSource,media->GetPosition(),false,true); Instance().currPlayingLoopedSounds.insert(std::pair<Sound*,ISound*>(media,temp)); temp->setSoundStopEventReceiver(Instance().sndEndReceiver,media); temp->setVolume(media->volume); temp->setMinDistance(media->minSoundDist); temp->setMaxDistance(FLT_MAX); // max attenuation distance temp->setIsPaused(false); } }
int main () { // Main device // IrrlichtDevice * pMainDevice = createDevice ( video::EDT_OPENGL , core::dimension2d < u32 > ( X_SIDE, Y_SIDE ), 16, false, false, false ); if ( ! pMainDevice ) return EXIT_FAILURE; // Main audio device // ISoundEngine * pSoundEngine = createIrrKlangDevice (); if ( ! pSoundEngine ) return EXIT_FAILURE; // Initializing application context structure // sApplicationContext context; context.m_pMainDevice = pMainDevice; context.m_counter = 0; context.isInGame = false; // Initializing receiver // Global::myEventReceiver = new MyEventReceiver(&context); pMainDevice->setEventReceiver ( Global::myEventReceiver ); // Adding receiver to device pMainDevice->setWindowCaption ( L"Space Battle" ); // Text on the top of the application pMainDevice->setResizable ( false ); // Disabling window resizing // Getting all main controll componets // // Static part // Global::spVideoDriver = pMainDevice->getVideoDriver (); // Other part // scene::ISceneManager * pSceneManager = pMainDevice->getSceneManager (); scene::ICameraSceneNode * pCamera = pSceneManager->addCameraSceneNode (); gui::IGUIEnvironment * pGUIEnvironment = pMainDevice->getGUIEnvironment(); // Vector for controling all animators // std::vector < scene::ISceneNodeAnimator * > pAnimators; // Setting the main menu audio // //pSoundEngine->play2D ( "audio\\ophelia.mp3", true ); // Random number for choosing an enemie texture // srand ( time ( NULL ) ); // Camera positioning and targeting // pCamera->setPosition ( core::vector3df ( 0, 0, 200 ) ); pCamera->setTarget ( core::vector3df ( 0, 0, 0 ) ); ////////////////////////////// f32 fov = pCamera->getFOV (); leftBorder = pCamera->getPosition ().Z * tan ( fov / 2 ); rightBorder = - leftBorder; ////////////////////////////// // Background cube // scene::IMeshSceneNode * pCube = pSceneManager->addCubeSceneNode ( 1, nullptr, -1, core::vector3df ( 0, 0, -15 ) ); pCube->setScale ( core::vector3df ( X_SIDE / 2, Y_SIDE / 2, 0.1f ) ); pCube->setMaterialFlag ( video::EMF_LIGHTING, false ); video::ITexture * pTexture = Global::spVideoDriver->getTexture ( "export\\background.tga" ); pCube->setMaterialTexture ( 0, pTexture ); // Border for rockets // // for fighter scene::IMeshSceneNode * pWorldBorder = pSceneManager->addCubeSceneNode ( X_SIDE, nullptr, -1, irr::core::vector3df ( 0, 220, 0 ), irr::core::vector3df ( 0, 0, 0 ), irr::core::vector3df ( X_SIDE, 0.001f, 2 ) ); // For enemies scene::IMeshSceneNode * pWorldBorderEnemieRockets = pSceneManager->addCubeSceneNode ( X_SIDE , nullptr, -1 , irr::core::vector3df ( 0, -220, 0 ) , irr::core::vector3df ( 0, 0, 0 ) , irr::core::vector3df ( X_SIDE, 0.001f, 2 ) ); // Rockets manager set // // for fighter rockets cRocketManager rockets ( pSceneManager, pMainDevice, "export\\rocket.X", pWorldBorder ); // for enemies rockets cRocketManager enemieRockets ( pSceneManager, pMainDevice, "export\\rocket.X" , pWorldBorderEnemieRockets, false ); // Fighter set // cFighterSceneNode * pFighter = new cFighterSceneNode ( pSceneManager, "export\\fighter.X", 3, MOVEMENT_SPEED, core::vector3df ( 0, downBorder, 0 ), // Position core::vector3df ( 0, 180, 0 ), // Rotation core::vector3df ( 1.0f, 1.0f, 1.0f ) ); // Scale pFighter->setTexture ( "export\\fighter.tga", Global::spVideoDriver ); // Enemie set // cEnemieNodeManager enemieManager ( pMainDevice ); enemieManager.addEnemieType ( "export\\enemies_01" ); enemieManager.addEnemieType ( "export\\enemies_02" ); enemieManager.addEnemieType ( "export\\enemies_03" ); enemieManager.addEnemieType ( "export\\enemies_04" ); // For statisctic. Font, billboard text // gui::IGUIFont * pFont = pGUIEnvironment->getFont ( "export\\fonthaettenschweiler.bmp" ); scene::IBillboardTextSceneNode * pTextVictory = pSceneManager->addBillboardTextSceneNode ( pFont , L"You won!" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 40, 10 ) ); scene::IBillboardTextSceneNode * pTextToExit = pSceneManager->addBillboardTextSceneNode ( pFont , L"Press ESCAPE to exit" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, -20, 10 ) ); scene::IBillboardTextSceneNode * pTextEnemiesKilled = pSceneManager->addBillboardTextSceneNode ( pFont , L"temp" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 20, 10 ) ); scene::IBillboardTextSceneNode * pTextRocketsLaunched = pSceneManager->addBillboardTextSceneNode ( pFont , L"temp" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 0, 10 ) ); pTextVictory->setVisible ( false ); pTextToExit->setVisible ( false ); pTextEnemiesKilled->setVisible ( false ); pTextRocketsLaunched->setVisible ( false ); // Createing the main menu // MainMenu* mainMenu = new MainMenu(pGUIEnvironment); // Before the main loop starts // bool isPressed = false; bool isLaunched = false; // for rocket bool isEnemieRocketLauched = false; // for enemie rockets bool isEnd = false; // For drawing stats bool isThrusterSoundActive = false; unsigned int currentSelectedGameLevel = 0; bool isLevelFinished = false; bool isEnemiesCreated = false; // Cheking if enemies creation, to avoid multiple creation of enemies group int rocketsCount = 0; int rocketsArraySize = rockets.getArraySize(); wchar_t buf [25]; cTimer timer ( pMainDevice ); // Prepearing sound source // ISound * pSoundThruster = nullptr; enemieRockets.cleareRocketsAnimators (); enemieRockets.addAnimatorsToRockets ( pFighter, pWorldBorderEnemieRockets ); /////////////// Main loop /////////////// while ( pMainDevice->run () ) { //if ( pMainDevice->isWindowActive () ) { if ( context.isInGame ) // is game started { #if !defined(_DEBUG) // Start playing the thrusters sound // if ( ! isThrusterSoundActive ) { pSoundThruster = nullptr; pSoundThruster = pSoundEngine->play2D ( "audio\\140582__lg__a320-engines-running-111228.wav" , true, false, true ); isThrusterSoundActive = true; } #endif isEnemiesCreated = (currentSelectedGameLevel == context.currentLevel) && !isLevelFinished; if ( ! isEnemiesCreated && ! isEnd ) { enemieManager.clearEnemiesVector (); setEnemiesFleeet ( & pAnimators, & enemieManager, pSceneManager, &context ); rockets.cleareRocketsAnimators (); rockets.addAnimatorsToRockets ( & enemieManager, pWorldBorder ); currentSelectedGameLevel = context.currentLevel; isLevelFinished = false; } // Cheking if victory and showing stats if ( enemieManager.getVectorSize () == 0 ) { rockets.reload (); if ( ! isEnd ) { isEnd = true; isLevelFinished = true; pTextVictory->setText ( L"You won!!!" ); pTextToExit->setText ( L"Press ESCAPE to exit" ); // enemie killed count swprintf ( buf, 20, L"Enemies killed: %d" , enemieManager.getNEnemiesKilled () ); pTextEnemiesKilled->setText ( buf ); * buf = '\0'; // String clear // rockets launched count swprintf ( buf, 25, L"Rockrets launched: %d" , pFighter->getNRocketsLaunched () ); pTextRocketsLaunched->setText ( buf ); * buf = '\0'; // String clear enemieManager.reloadNEnemiesKilled (); pFighter->reloadNRocketsLaunched (); pTextVictory->setVisible ( true ); pTextToExit->setVisible ( true ); pTextEnemiesKilled->setVisible ( true ); pTextRocketsLaunched->setVisible ( true ); } } // If exiting make all invisible // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_ESCAPE ) && isEnd ) { context.isInGame = false; isLevelFinished = true; isEnd = false; pTextVictory->setText ( L"" ); pTextToExit->setText ( L"" ); pTextEnemiesKilled->setText ( L"" ); pTextRocketsLaunched->setText ( L"" ); pTextVictory->setVisible ( false ); pTextToExit->setVisible ( false ); pTextEnemiesKilled->setVisible ( false ); pTextRocketsLaunched->setVisible ( false ); pFighter->getMeshSceneNode ()->setPosition ( core::vector3df ( 0, downBorder, 0 ) ); for ( int i = 0; i < rockets.getArraySize (); i++ ) rockets.getRockets()->at ( i )->getMeshSceneNode ()->setPosition ( core::vector3df ( 0, upBorder + 100, 0 ) ); // Pausing thrusters sound // if(pSoundThruster) { pSoundThruster->stop (); pSoundThruster->drop (); pSoundThruster = nullptr; } isThrusterSoundActive = false; continue; } if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_ESCAPE ) && ! isEnd ) { context.isInGame = false; #if !defined(_DEBUG) // Pausing thrusters sound // pSoundThruster->stop (); pSoundThruster->drop (); pSoundThruster = nullptr; isThrusterSoundActive = false; #endif } float currentSpeed = pFighter->getSpeed (); // getting the cuurrent speed of the fighter // Ghange!!! core::vector3df nodePosition = pFighter->getMeshSceneNode ()->getPosition (); // getting fighter position // Side movement // if ( ! isEnd ) { float deltaTime = (f32)timer.getDeltaTime() / 100; if ( Global::myEventReceiver->IsKeyDown(irr::KEY_KEY_A) || Global::myEventReceiver->IsKeyDown(irr::KEY_LEFT) ) { nodePosition.X += currentSpeed * deltaTime; } if ( Global::myEventReceiver->IsKeyDown(irr::KEY_KEY_D) || Global::myEventReceiver->IsKeyDown(irr::KEY_RIGHT)) { nodePosition.X -= currentSpeed * deltaTime; } if ( nodePosition.X < leftBorder && nodePosition.X > rightBorder ) pFighter->getMeshSceneNode ()->setPosition ( nodePosition ); // Collison cheking // int animatorCount = collisionChek ( & rockets ); if (!(animatorCount == -1 || animatorCount == 0 )) { enemieManager.increaseNEnemiesKilled (); core::vector3df collisionPosition = enemieManager.getEnemie ( animatorCount - 1 )-> getMeshSceneNode ()->getPosition (); addExplosion ( collisionPosition, core::vector3df ( 0, 0, 0 ) , 10, pSceneManager, core::plane3df ( 1, 0, 0, 0, 0, 0 ), nullptr ); pSoundEngine->play2D ( "audio\\explosion.flac", false ); enemieManager.getEnemie ( animatorCount - 1 )->getMeshSceneNode ()->setVisible ( false ); enemieManager.getEnemie ( animatorCount - 1 )->drop (); enemieManager.getVector()->erase ( enemieManager.getVector ()->begin () + animatorCount - 1 ); rockets.cleareRocketsAnimators (); rockets.addAnimatorsToRockets ( & enemieManager, pWorldBorder ); } animatorCount = collisionChek ( & enemieRockets ); if (!( animatorCount == 0 || animatorCount == -1 )) { addExplosion ( pFighter->getMeshSceneNode()->getPosition () , core::vector3df ( 0, 0, 0 ), 10 , pSceneManager, core::plane3df ( 1, 0, 0, 0, 0, 0 ), nullptr ); pSoundEngine->play2D ( "audio\\explosion.flac", false ); pTextVictory->setText ( L"You Lose!!!" ); isEnd = true; isEnemiesCreated = true; // enemie killed count swprintf ( buf, 20, L"Enemies killed: %d" , enemieManager.getNEnemiesKilled () ); pTextEnemiesKilled->setText ( buf ); * buf = '\0'; // String clear // rockets launched count swprintf ( buf, 25, L"Rockrets launched: %d" , pFighter->getNRocketsLaunched () ); pTextRocketsLaunched->setText ( buf ); * buf = '\0'; // String clear enemieManager.reloadNEnemiesKilled (); pFighter->reloadNRocketsLaunched (); pTextToExit->setText ( L"Press ESCAPE to exit" ); pTextVictory->setVisible ( true ); pTextToExit->setVisible ( true ); pTextEnemiesKilled->setVisible ( true ); pTextRocketsLaunched->setVisible ( true ); } // Fire // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && ! isLaunched ) { isLaunched = true; printf ( "Fighter: rocket %d launched on %f, %f, %f\n", rocketsCount++, pFighter->getMeshSceneNode()->getPosition ().X, pFighter->getMeshSceneNode()->getPosition ().Y, pFighter->getMeshSceneNode()->getPosition ().Z ); pFighter->launch ( & rockets, Global::spVideoDriver ); pSoundEngine->play2D ( "audio\\rocket_launch.mp3" ); } else if ( ! Global::myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && isLaunched ) isLaunched = false; /*if ( myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && ! isLaunched ) { isLaunched = true; printf ( "Fighter: rocket %d launched on %f, %f, %f\n", rocketsCount++, pFighter->getMeshSceneNode()->getPosition ().X, pFighter->getMeshSceneNode()->getPosition ().Y, pFighter->getMeshSceneNode()->getPosition ().Z ); pFighter->launch ( & rockets, pVideoDriver ); } else if ( ! myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && isLaunched ) isLaunched = false;*/ if ( rockets.getUsed () == rocketsArraySize ) { rockets.reload (); //rocketsCount = 0; } if ( timer.calculateDeltaTime () > 1000 && enemieManager.getVectorSize () != 0 ) { /*if ( myEventReceiver->IsKeyDown ( irr::KEY_KEY_Q ) ) printf ( "DEBUG: debugin stop\n" );*/ timer.calculateTime (); int i = rand () % enemieManager.getVectorSize (); // misstake enemieManager.getEnemie ( i )->launch ( & enemieRockets, Global::spVideoDriver ); } else if ( enemieManager.getVectorSize () == 0 ) printf ( "DEBUG: vector size = %d\n", enemieManager.getVectorSize () ); } } // is game started // DEBUG // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_KEY_G ) && ! isPressed ) { isPressed = true; printf ( "DEBUG: Fighter position - %f\n", pFighter->getMeshSceneNode()->getPosition().X ); } if ( ! Global::myEventReceiver->IsKeyDown ( irr::KEY_KEY_G ) && isPressed ) isPressed = false; // Drawing // Global::spVideoDriver->beginScene ( true, true, video::SColor ( 0, 255, 255, 255 ) ); if ( context.isInGame ) { pSceneManager->drawAll (); } else { pGUIEnvironment->drawAll (); } // Drawing stoped // Global::spVideoDriver->endScene (); } } /////////////// Main loop /////////////// delete mainMenu; // Clrearing // pFighter->drop (); pSoundEngine->drop (); pMainDevice->drop (); /// ------- /// return EXIT_SUCCESS; }
void MusicPlayer::Handle(ProcessEventArg arg) { if (!playlist.empty() && !stalled) { ISound* currentSound = playlist.at(current); // logger.info << "time left: " << // currentSound->GetTimeLeft().ToString() << logger.end; if(currentSound->GetTimeLeft() <= tran->GetInTime()) { if (switchToNextNumber == false) Next(); switchToNextNumber = true; } if (switchToNextNumber) { tran->InitFade(currentSound, playlist.at(nextTrackNumber)); tran->Start(); current = nextTrackNumber; switchToNextNumber = false; } if (!tran->IsDone()) { tran->Process(); } /* Vector<3, float> pos = cam->GetPosition(); //set the position of the current if (monoreftype && (typeid(*currentsound).name() == typeid(*monoreftype).name())) { IMonoSound* cursound = (IMonoSound*) currentsound; cursound->SetPosition(pos); } else { IStereoSound* cursound = (IStereoSound*) currentsound; IMonoSound* left = cursound->GetLeft(); IMonoSound* right = cursound->GetRight(); pos[0] = pos[0] - 1; left->SetPosition(pos); pos[0] = pos[0] + 1; right->SetPosition(pos); } //set the position of the old if initialize if (monoreftype && (typeid(*previoussound).name() == typeid(*monoreftype).name())) { IMonoSound* presound = (IMonoSound*) previoussound; presound->SetPosition(pos); } else { IStereoSound* presound = (IStereoSound*) previoussound; IMonoSound* left = presound->GetLeft(); IMonoSound* right = presound->GetRight(); pos[0] = pos[0] - 1; left->SetPosition(pos); pos[0] = pos[0] + 1; right->SetPosition(pos); } */ } }