Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct AudioEngine::EventInstanceId
- {
- FMOD::Studio::EventInstance* myEventInstance;
- u32 myId;
- };
- struct AudioEngine::Implementation {
- Implementation();
- ~Implementation();
- void Update();
- FMOD::Studio::System* myStudioSystem;
- FMOD::System* mySystem;
- int myNextChannelId = 0;
- typedef std::map<string, FMOD::Sound*> SoundMap;
- /*typedef map<int, FMOD::Channel*> ChannelMap;*/
- typedef std::map<string,FMOD::Studio::EventInstance*> EventMap;
- typedef std::map<string, FMOD::Studio::Bank*> BankMap;
- typedef std::map<string, FMOD::Studio::VCA*> VcaMap;
- typedef std::map<string, Core::Vector<EventInstanceId>> EventMap3D;
- BankMap myBanks;
- EventMap myEvents;
- EventMap3D my3DEvents;
- SoundMap mySounds;
- //ChannelMap myChannels;
- VcaMap myVcas;
- };
- void AudioEngine::Set3DAttributes(const string& aEventName, u32 aId, Vec3f aPos, Vec3f aForward, Vec3f aUp, Vec3f aVel)
- {
- FMOD_VECTOR pos = { aPos.x,aPos.y, aPos.z };
- FMOD_VECTOR vel = { aVel.x,aVel.y, aVel.z };
- FMOD_VECTOR forward = { aForward.x,aForward.y, aForward.z };
- FMOD_VECTOR up = { aUp.x,aUp.y, aUp.z };
- FMOD_3D_ATTRIBUTES atr{ pos,vel,forward,up };
- auto foundIt = myImplementation->my3DEvents.find(aEventName);
- if (foundIt == myImplementation->my3DEvents.end())
- {
- return;
- }
- for (i32 i = 0; i < foundIt->second.Size(); i++)
- {
- if (foundIt->second[i].myId == aId)
- {
- foundIt->second[i].myEventInstance->set3DAttributes(&atr);
- return;
- }
- }
- }
- void AudioEngine::Load3DEvent(const string & aEventName, u32 aId)
- {
- auto foundIt = myImplementation->my3DEvents.find(aEventName);
- i32 size = foundIt->second.Size();
- for (i32 i = 0; i < size; i++)
- {
- if (foundIt->second[i].myId == aId)
- {
- return;
- }
- }
- FMOD::Studio::EventDescription* eventDescription = nullptr;
- AudioEngine::ErrorCheck(myImplementation->myStudioSystem->getEvent(aEventName.c_str(), &eventDescription));
- if (eventDescription)
- {
- FMOD::Studio::EventInstance* eventInstance = nullptr;
- AudioEngine::ErrorCheck(eventDescription->createInstance(&eventInstance));
- if (eventInstance)
- {
- for (i32 i = 0; i < size; i++)
- {
- if (foundIt->second[i].myEventInstance == nullptr)
- {
- myImplementation->my3DEvents[aEventName][i].myEventInstance = eventInstance;
- myImplementation->my3DEvents[aEventName][i].myId = aId;
- return;
- }
- }
- }
- }
- }
- void AudioEngine::Set3DEventVectorSize(const string & aEventName, u32 aSize)
- {
- Core::Vector<EventInstanceId> v;
- v.Resize(aSize);
- for (i32 i = 0; i < v.Size(); i++)
- {
- v[i].myEventInstance = nullptr;
- v[i].myId = 0;
- }
- myImplementation->my3DEvents.insert_or_assign(aEventName, v);
- }
- void AudioEngine::PlayMoving3DEvent(const string & aEventName, float aVolume, Vec3f aPos, Vec3f aForward, Vec3f aUp, u32 aId, Vec3f aVel)
- {
- FMOD_VECTOR pos = { aPos.x,aPos.y, aPos.z };
- FMOD_VECTOR vel = { aVel.x,aVel.y, aVel.z };
- FMOD_VECTOR forward = { aForward.x,aForward.y, aForward.z };
- FMOD_VECTOR up = { aUp.x,aUp.y, aUp.z };
- FMOD_3D_ATTRIBUTES atr{ pos,vel,forward,up };
- auto foundIt = myImplementation->my3DEvents.find(aEventName);
- Load3DEvent(aEventName, aId);
- foundIt = myImplementation->my3DEvents.find(aEventName);
- if (foundIt == myImplementation->my3DEvents.end())
- {
- return;
- }
- for (i32 i = 0; i < foundIt->second.Size(); i++)
- {
- if (foundIt->second[i].myId == aId)
- {
- foundIt->second[i].myEventInstance->set3DAttributes(&atr);
- foundIt->second[i].myEventInstance->start();
- foundIt->second[i].myEventInstance->setVolume(aVolume);
- }
- }
- }
- void AudioEngine::Stop3DEvent(const string & aEventName, bool isImmediate, u32 aId)
- {
- auto foundIt = myImplementation->my3DEvents.find(aEventName);
- if (foundIt == myImplementation->my3DEvents.end())
- {
- return;
- }
- FMOD_STUDIO_STOP_MODE stopMode;
- stopMode = isImmediate ? FMOD_STUDIO_STOP_IMMEDIATE : FMOD_STUDIO_STOP_ALLOWFADEOUT;
- for (i32 i = 0; i < foundIt->second.Size(); i++)
- {
- if (foundIt->second[i].myId == aId)
- {
- AudioEngine::ErrorCheck(foundIt->second[i].myEventInstance->stop(stopMode));
- foundIt->second[i].myEventInstance = nullptr;
- foundIt->second[i].myId = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement