Skip to content

Various potential merges to cherry pick. #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.02-UE5.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FMODStudio/Source/FMODStudio/Classes/FMODAudioComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class FMODSTUDIO_API UFMODAudioComponent : public USceneComponent
/** Called when the event has finished stopping. */
void OnPlaybackCompleted();

protected:
// Begin ActorComponent interface.
/** Called when a component is registered, after Scene is set, but before CreateRenderState_Concurrent or OnCreatePhysicsState are called. */
virtual void OnRegister() override;
Expand All @@ -340,6 +341,8 @@ class FMODSTUDIO_API UFMODAudioComponent : public USceneComponent
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
// End ActorComponent interface.

private:

#if WITH_EDITORONLY_DATA
void UpdateSpriteTexture();
#endif
Expand Down
8 changes: 6 additions & 2 deletions FMODStudio/Source/FMODStudio/Classes/FMODBlueprintStatics.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ class FMODSTUDIO_API UFMODBlueprintStatics : public UBlueprintFunctionLibrary
* @param LocationType - Specifies whether Location is a relative offset or an absolute world position
* @param bStopWhenAttachedToDestroyed - Specifies whether the sound should stop playing when the owner of the attach to component is destroyed.
* @param bAutoPlay - Start the event automatically.
* @param bAutoDestroy - Automatically destroy the audio component when the sound is stopped.
* @param bAutoDestroy - Automatically destroy the audio component when the sound is stopped.
* @param bEnableOcclusion - Whether to enable occlusion for event.
* @param OcclusionTraceChannel - If occlusion is enabled, which collision channel should be used for determining occlusion.
* @param bUseComplexCollisionForOcclusion - If occlusion is enabled, should the simple or complex collision of objects be used to determine occlusion.
*/
UFUNCTION(BlueprintCallable, Category = "Audio|FMOD",
meta = (AdvancedDisplay = "2", UnsafeDuringActorConstruction = "true", bAutoPlay = "true", bAutoDestroy = "true"))
static class UFMODAudioComponent *PlayEventAttached(UFMODEvent *Event, USceneComponent *AttachToComponent, FName AttachPointName,
FVector Location, EAttachLocation::Type LocationType, bool bStopWhenAttachedToDestroyed, bool bAutoPlay, bool bAutoDestroy);
FVector Location, EAttachLocation::Type LocationType, bool bStopWhenAttachedToDestroyed, bool bAutoPlay, bool bAutoDestroy,
bool bEnableOcclusion = false, ECollisionChannel OcclusionTraceChannel = ECollisionChannel::ECC_Visibility, bool bUseComplexCollisionForOcclusion = false);

/** Find an asset by name.
* @param EventName - The asset name
Expand Down
11 changes: 10 additions & 1 deletion FMODStudio/Source/FMODStudio/Private/FMODBlueprintStatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ FFMODEventInstance UFMODBlueprintStatics::PlayEventAtLocation(
}

class UFMODAudioComponent *UFMODBlueprintStatics::PlayEventAttached(class UFMODEvent *Event, class USceneComponent *AttachToComponent,
FName AttachPointName, FVector Location, EAttachLocation::Type LocationType, bool bStopWhenAttachedToDestroyed, bool bAutoPlay, bool bAutoDestroy)
FName AttachPointName, FVector Location, EAttachLocation::Type LocationType, bool bStopWhenAttachedToDestroyed, bool bAutoPlay, bool bAutoDestroy,
bool bEnableOcclusion /* = false */, ECollisionChannel OcclusionTraceChannel /* ECollisionChannel:: ECC_Visibility */, bool bUseComplexCollisionForOcclusion /* = false*/)
{
if (!IFMODStudioModule::Get().UseSound())
{
Expand Down Expand Up @@ -103,6 +104,14 @@ class UFMODAudioComponent *UFMODBlueprintStatics::PlayEventAttached(class UFMODE
#if WITH_EDITORONLY_DATA
AudioComponent->bVisualizeComponent = false;
#endif

// Create and apply Occlusion details.
FFMODOcclusionDetails OcclusionDetails = FFMODOcclusionDetails();
OcclusionDetails.bEnableOcclusion = bEnableOcclusion;
OcclusionDetails.bUseComplexCollisionForOcclusion = bUseComplexCollisionForOcclusion;
OcclusionDetails.OcclusionTraceChannel = OcclusionTraceChannel;
AudioComponent->OcclusionDetails = OcclusionDetails;

AudioComponent->RegisterComponentWithWorld(AttachToComponent->GetWorld());

AudioComponent->AttachToComponent(AttachToComponent, FAttachmentTransformRules::KeepRelativeTransform, AttachPointName);
Expand Down
45 changes: 41 additions & 4 deletions FMODStudio/Source/FMODStudio/Private/FMODStudioModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include <AVFoundation/AVAudioSession.h>
#endif

#if WITH_EDITOR
#include "LevelEditorViewport.h"
#endif

#define LOCTEXT_NAMESPACE "FMODStudio"

DEFINE_LOG_CATEGORY(LogFMOD);
Expand Down Expand Up @@ -212,7 +216,7 @@ class FFMODStudioModule : public IFMODStudioModule
virtual FMOD::Studio::EventInstance *CreateAuditioningInstance(const UFMODEvent *Event) override;
virtual void StopAuditioningInstance() override;

virtual void SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, float DeltaSeconds) override;
virtual void SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, const FTransform &listenerAttenuationTransform, float DeltaSeconds) override;
virtual void FinishSetListenerPosition(int ListenerCount) override;

virtual const FFMODListener &GetNearestListener(const FVector &Location) override;
Expand Down Expand Up @@ -876,6 +880,11 @@ void FFMODStudioModule::UpdateListeners()
#if WITH_EDITOR
if (bSimulating)
{
if (GEngine && GEngine->GameViewport)
{
UpdateWorldListeners(GEngine->GameViewport->GetWorld(), &ListenerIndex);
}

return;
}

Expand Down Expand Up @@ -934,7 +943,32 @@ void FFMODStudioModule::UpdateWorldListeners(UWorld *World, int *ListenerIndex)
ListenerTransform.SetTranslation(Location);
ListenerTransform.NormalizeRotation();

SetListenerPosition(*ListenerIndex, World, ListenerTransform, DeltaSeconds);
APawn* ControlledPawn = PlayerController->GetPawn();
FTransform ListenerAttenuationTransform(FTransform::Identity);
if (IsValid(ControlledPawn))
{
ListenerAttenuationTransform = ControlledPawn->GetActorTransform(); // actor
ListenerAttenuationTransform.SetLocation(ControlledPawn->GetPawnViewLocation()); // head
}

#if WITH_EDITOR
if (bSimulating)
{
for (FLevelEditorViewportClient* LevelVC : GEditor->GetLevelViewportClients())
{
if (LevelVC && LevelVC->IsPerspective())
{
ListenerTransform.SetLocation(LevelVC->GetViewLocation());
ListenerTransform.SetRotation(LevelVC->GetViewRotation().Quaternion());
break;
}
}

ListenerAttenuationTransform = ListenerTransform;
}
#endif

SetListenerPosition(*ListenerIndex, World, ListenerTransform, ListenerAttenuationTransform, DeltaSeconds);

(*ListenerIndex)++;
}
Expand Down Expand Up @@ -971,7 +1005,7 @@ const FFMODListener &FFMODStudioModule::GetNearestListener(const FVector &Locati
}

// Partially copied from FAudioDevice::SetListener
void FFMODStudioModule::SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, float DeltaSeconds)
void FFMODStudioModule::SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, const FTransform &ListenerAttenuationTransform, float DeltaSeconds)
{
FMOD::Studio::System *System = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
if (System && ListenerIndex < MAX_LISTENERS)
Expand Down Expand Up @@ -1009,7 +1043,10 @@ void FFMODStudioModule::SetListenerPosition(int ListenerIndex, UWorld *World, co
Attributes.forward = FMODUtils::ConvertUnitVector(Forward);
Attributes.up = FMODUtils::ConvertUnitVector(Up);
Attributes.velocity = FMODUtils::ConvertWorldVector(Listeners[ListenerIndex].Velocity);
verifyfmod(System->setListenerAttributes(ListenerIndex, &Attributes));

FMOD_VECTOR AttenuationLocation = FMODUtils::ConvertWorldVector(ListenerAttenuationTransform.GetTranslation());

verifyfmod(System->setListenerAttributes(ListenerIndex, &Attributes, &AttenuationLocation));
bListenerMoved = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion FMODStudio/Source/FMODStudio/Public/FMODStudioModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class IFMODStudioModule : public IModuleInterface
/**
* Called to change the listener position for editor mode
*/
virtual void SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, float DeltaSeconds) = 0;
virtual void SetListenerPosition(int ListenerIndex, UWorld *World, const FTransform &ListenerTransform, const FTransform& ListenerAttenuationTransform, float DeltaSeconds) = 0;

/**
* Called to change the listener position for editor mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ void FFMODStudioEditorModule::ViewportDraw(UCanvas *Canvas, APlayerController *)
ListenerTransform.SetTranslation(ViewLocation);
ListenerTransform.NormalizeRotation();

IFMODStudioModule::Get().SetListenerPosition(0, World, ListenerTransform, 0.0f);
IFMODStudioModule::Get().SetListenerPosition(0, World, ListenerTransform, FTransform::Identity, 0.0f);
IFMODStudioModule::Get().FinishSetListenerPosition(1);
}
}
Expand Down