Added Scripting interface for AudioClips #320

Merged
srishamharan merged 7 commits from AudioScripting into main 2023-01-30 17:08:39 +08:00
2 changed files with 21 additions and 7 deletions
Showing only changes of commit 74b8ee73c5 - Show all commits

View File

@ -125,14 +125,29 @@ namespace SHADE
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
if (listenerTransform)
{
listener.SetPos(listenerTransform->GetLocalPosition());
listener.SetForward({ (listenerTransform->GetLocalScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f });
listener.SetPos(listenerTransform->GetWorldPosition()); // TODO: Clean up listener
listener.SetForward({ (listenerTransform->GetLocalScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f }); //TODO: USE CORRECT FORWARD
FMOD_VECTOR pos = { listener.pos[0] ,listener.pos[1] ,0.f };
FMOD_VECTOR forward = { listener.forward[0] ,listener.forward[1] ,listener.forward[2] };
FMOD_VECTOR up = { listener.up[0] ,listener.up[1] ,listener.up[2] };
fmodSystem->set3DListenerAttributes(0, &pos, nullptr, &forward, &up);
}
}
auto [begin, end] = audioClipLibrary.GetDenseAccess();
for(auto it = begin; it != end; ++it)
{
if(it->instance && (it->transformRef != MAX_EID))
{
if(SHTransformComponent* transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(it->transformRef))
{
FMOD_3D_ATTRIBUTES attribs{}; //TODO: Set other attribs
auto pos = transformComponent->GetWorldPosition();
attribs.position = {pos.x, pos.y, pos.z};
it->instance->set3DAttributes(&attribs);
}
}
}
}
SHAudioSystem::AudioRoutine::AudioRoutine()
@ -372,13 +387,13 @@ namespace SHADE
{
if (auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
{
//handle->transformRef = transform;
handle->transformRef = eid;
}
}
void SHAudioSystem::DetachAudioClipToObject(Handle<AudioClip> handle, EntityID eid)
void SHAudioSystem::DetachAudioClipFromObject(Handle<AudioClip> handle)
{
//handle->transformRef = nullptr;
handle->transformRef = MAX_EID;
}
//AudioClip* SHAudioSystem::CreateAudioClip(const char* path)

View File

@ -26,7 +26,6 @@ namespace SHADE
class SH_API AudioClip
{
public:
//expose to sxripting
void Play();
//void Play(SHVec3 position);
void Stop(bool fadeOut = true);
@ -75,7 +74,7 @@ namespace SHADE
void AddAudioClipToSFXChannelGroup(Handle<AudioClip> handle);
void AttachAudioClipToObject(Handle<AudioClip> handle, EntityID eid);
void DetachAudioClipToObject(Handle<AudioClip> handle, EntityID eid);
void DetachAudioClipFromObject(Handle<AudioClip> handle);
///
float GetBgmVolume();
float GetSfxVolume();