god knows whats diff but audio is sort of working ish
This commit is contained in:
parent
3c3b6a285b
commit
7fcac5e0eb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -79,12 +79,13 @@ namespace SHADE
|
||||||
|
|
||||||
LoadBank("../../Assets/Audio/Master.bank");
|
LoadBank("../../Assets/Audio/Master.bank");
|
||||||
LoadBank("../../Assets/Audio/Master.strings.bank");
|
LoadBank("../../Assets/Audio/Master.strings.bank");
|
||||||
//LoadBank("resources/audio/banks/Music.bank");
|
LoadBank("../../Assets/Audio/Music.bank");
|
||||||
//LoadBank("resources/audio/banks/SFX.bank");
|
LoadBank("../../Assets/Audio/SFX.bank");
|
||||||
|
|
||||||
//auto clip = CreateAudioClip("event:/SFX/Dawn/Dawn_Attack");
|
//auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human");
|
||||||
//clip->Play();
|
//clip->Play();
|
||||||
//PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
|
//PlayEventOnce("event:/Characters/sfx_footsteps_human");
|
||||||
|
PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHADE::SHAudioSystem::Run(float dt)
|
void SHADE::SHAudioSystem::Run(float dt)
|
||||||
|
@ -147,7 +148,7 @@ namespace SHADE
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system)
|
if (fmodStudioSystem)
|
||||||
{
|
{
|
||||||
result = fmodStudioSystem->release();
|
result = fmodStudioSystem->release();
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
|
@ -160,41 +161,41 @@ namespace SHADE
|
||||||
std::cerr << "Audio system error: " << FMOD_ErrorString(result) << std::endl;
|
std::cerr << "Audio system error: " << FMOD_ErrorString(result) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::PlayEventOnce(const char* path, bool isSFX, EntityID eid, bool spatial)
|
void SHAudioSystem::PlayEventOnce(const char* path, bool isSFX, EntityID eid, bool spatial)
|
||||||
{
|
{
|
||||||
if (paused)
|
if (paused)
|
||||||
return;
|
return;
|
||||||
auto it = eventMap.find(path);
|
auto it = eventMap.find(path);
|
||||||
if (it != eventMap.end())
|
if (it != eventMap.end())
|
||||||
{
|
|
||||||
FMOD::Studio::EventInstance* event = nullptr;
|
|
||||||
it->second->createInstance(&event);
|
|
||||||
if (event)
|
|
||||||
{
|
{
|
||||||
|
FMOD::Studio::EventInstance* event = nullptr;
|
||||||
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
|
it->second->createInstance(&event);
|
||||||
if (spatial)
|
if (event)
|
||||||
{
|
|
||||||
if (SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
|
||||||
{
|
{
|
||||||
FMOD_3D_ATTRIBUTES attributes{ {} };
|
|
||||||
attributes.forward.z = 1.0f;
|
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
|
||||||
attributes.up.y = 1.0f;
|
if (spatial)
|
||||||
SHAudioListenerComponent& listener = denseListener->at(0);
|
{
|
||||||
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
|
if (SHTransformComponent* audioTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
||||||
if (listenerTransform)
|
{
|
||||||
{
|
FMOD_3D_ATTRIBUTES attributes{ {} };
|
||||||
attributes.position.z = listenerTransform->GetLocalPosition()[2];
|
attributes.forward.z = 1.0f;
|
||||||
}
|
attributes.up.y = 1.0f;
|
||||||
attributes.position.x = audioTransform->GetLocalPosition()[0];
|
SHAudioListenerComponent& listener = denseListener->at(0);
|
||||||
attributes.position.y = audioTransform->GetLocalPosition()[1];
|
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
|
||||||
event->set3DAttributes(&attributes);
|
if (listenerTransform)
|
||||||
|
{
|
||||||
|
attributes.position.z = listenerTransform->GetLocalPosition()[2];
|
||||||
|
}
|
||||||
|
attributes.position.x = audioTransform->GetLocalPosition()[0];
|
||||||
|
attributes.position.y = audioTransform->GetLocalPosition()[1];
|
||||||
|
event->set3DAttributes(&attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event->start();
|
||||||
|
event->release();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
event->start();
|
|
||||||
event->release();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAudioSystem::PlaySFX(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min, float max)
|
void SHAudioSystem::PlaySFX(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min, float max)
|
||||||
|
@ -437,27 +438,27 @@ namespace SHADE
|
||||||
|
|
||||||
void SHAudioSystem::LoadBank(const char* path)
|
void SHAudioSystem::LoadBank(const char* path)
|
||||||
{
|
{
|
||||||
FMOD::Studio::Bank* bank = nullptr;
|
FMOD::Studio::Bank* bank = nullptr;
|
||||||
result = fmodStudioSystem->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank);
|
result = fmodStudioSystem->loadBankFile(path, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank);
|
||||||
ErrorCheck();
|
ErrorCheck();
|
||||||
if (result != FMOD_OK)
|
if (result != FMOD_OK)
|
||||||
return;
|
return;
|
||||||
bankMap.emplace(path, bank);
|
bankMap.emplace(path, bank);
|
||||||
bank->loadSampleData();
|
bank->loadSampleData();
|
||||||
int numOfEvents;
|
int numOfEvents;
|
||||||
bank->getEventCount(&numOfEvents);
|
bank->getEventCount(&numOfEvents);
|
||||||
if (numOfEvents > 0)
|
if (numOfEvents > 0)
|
||||||
{
|
|
||||||
std::vector<FMOD::Studio::EventDescription*> events(numOfEvents);
|
|
||||||
bank->getEventList(events.data(), numOfEvents, &numOfEvents);
|
|
||||||
char eventName[512];
|
|
||||||
for (int i{}; i < numOfEvents; ++i)
|
|
||||||
{
|
{
|
||||||
FMOD::Studio::EventDescription* event = events[i];
|
std::vector<FMOD::Studio::EventDescription*> events(numOfEvents);
|
||||||
event->getPath(eventName, 512, nullptr);
|
bank->getEventList(events.data(), numOfEvents, &numOfEvents);
|
||||||
eventMap.emplace(eventName, event);
|
char eventName[512];
|
||||||
|
for (int i{}; i < numOfEvents; ++i)
|
||||||
|
{
|
||||||
|
FMOD::Studio::EventDescription* event = events[i];
|
||||||
|
event->getPath(eventName, 512, nullptr);
|
||||||
|
eventMap.emplace(eventName, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioClip::AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst)
|
AudioClip::AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst)
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#include "SHEditorComponentView.hpp"
|
#include "SHEditorComponentView.hpp"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
|
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "AudioSystem/SHAudioSystem.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
||||||
|
@ -50,6 +53,14 @@ namespace SHADE
|
||||||
|
|
||||||
ImGui::InputText("##EntityName", &entity->name);
|
ImGui::InputText("##EntityName", &entity->name);
|
||||||
|
|
||||||
|
if (ImGui::Button("AUDIO"))
|
||||||
|
{
|
||||||
|
if (auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>())
|
||||||
|
{
|
||||||
|
audioSystem->PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (auto transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
if (auto transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
||||||
{
|
{
|
||||||
DrawComponent(transformComponent);
|
DrawComponent(transformComponent);
|
||||||
|
|
Loading…
Reference in New Issue