Skip to content

Commit

Permalink
conversation participant or observer
Browse files Browse the repository at this point in the history
Add ability to configure if player is in conversation or not while targeting characters
cleanup unused struct
update naming to Add/Remove instead of Set/Clear to better indicate a list over single
  • Loading branch information
Matt-Carey committed May 29, 2024
1 parent 3324ec6 commit e867e36
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 33 deletions.
19 changes: 16 additions & 3 deletions InworldAI/Source/InworldAIIntegration/Private/InworldPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void UInworldPlayer::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLi
}

DOREPLIFETIME(UInworldPlayer, Session);
DOREPLIFETIME(UInworldPlayer, bConversationParticipant);
DOREPLIFETIME(UInworldPlayer, TargetCharacters);
}

Expand Down Expand Up @@ -99,7 +100,7 @@ void UInworldPlayer::SendAudioSessionStartToConversation(EInworldMicrophoneMode
NO_SESSION_RETURN(void())
EMPTY_ARG_RETURN(ConversationId, void())

if (bHasAudioSession)
if (bHasAudioSession || !bConversationParticipant)
{
return;
}
Expand Down Expand Up @@ -130,7 +131,7 @@ void UInworldPlayer::SendSoundMessageToConversation(const TArray<uint8>& Input,
EMPTY_ARG_RETURN(ConversationId, void())
EMPTY_ARG_RETURN(Input, void())

if (!bHasAudioSession)
if (!bHasAudioSession || !bConversationParticipant)
{
return;
}
Expand All @@ -146,6 +147,18 @@ TScriptInterface<IInworldPlayerOwnerInterface> UInworldPlayer::GetInworldPlayerO
return TScriptInterface<IInworldPlayerOwnerInterface>(GetOuter());
}

void UInworldPlayer::SetConversationParticipation(bool bParticipate)
{
if (bConversationParticipant != bParticipate)
{
bConversationParticipant = bParticipate;
if (!ConversationId.IsEmpty())
{
UpdateConversation();
}
}
}

void UInworldPlayer::AddTargetCharacter(UInworldCharacter* TargetCharacter)
{
if (TargetCharacter && TargetCharacter->IsPossessed() && TargetCharacter->GetTargetPlayer() == nullptr)
Expand Down Expand Up @@ -215,7 +228,7 @@ void UInworldPlayer::UpdateConversation()
{
NO_SESSION_RETURN(void())

FString NextConversationId = Session->GetClient()->UpdateConversation(ConversationId, Inworld::CharactersToAgentIds(TargetCharacters), true);
FString NextConversationId = Session->GetClient()->UpdateConversation(ConversationId, Inworld::CharactersToAgentIds(TargetCharacters), bConversationParticipant);
const bool bHadAudioSession = bHasAudioSession;
if (bHasAudioSession)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,13 @@ void UInworldPlayerAudioCaptureComponent::EvaluateVoiceCapture()
{
const bool bIsMicHot = !bMuted;
const bool bIsWorldPlaying = !GetWorld()->IsPaused();
const bool bIsParticipating = InworldPlayer->IsConversationParticipant();
const bool bHasConversation = !InworldPlayer->GetConversationId().IsEmpty();
UInworldSession* InworldSession = InworldPlayer->GetSession();
const EInworldConnectionState ConnectionState = InworldSession ? InworldSession->GetConnectionState() : EInworldConnectionState::Idle;
const bool bHasActiveInworldSession = InworldSession && InworldSession->IsLoaded() && (ConnectionState == EInworldConnectionState::Connected || ConnectionState == EInworldConnectionState::Reconnecting);

const bool bShouldCaptureVoice = bIsMicHot && bIsWorldPlaying && bHasConversation && bHasActiveInworldSession;
const bool bShouldCaptureVoice = bIsMicHot && bIsWorldPlaying && bIsParticipating && bHasConversation && bHasActiveInworldSession;

if (bShouldCaptureVoice != bServerCapturingVoice)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ void UInworldPlayerComponent::UninitializeComponent()
}
}

void UInworldPlayerComponent::BeginPlay()
{
Super::BeginPlay();

if (GetOwnerRole() == ROLE_Authority)
{
InworldPlayer->SetConversationParticipation(bConversationParticipant);
}
}

void UInworldPlayerComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
Expand All @@ -102,6 +112,22 @@ bool UInworldPlayerComponent::ReplicateSubobjects(UActorChannel* Channel, FOutBu
#endif
}

void UInworldPlayerComponent::SetConversationParticipation(bool bParticipating)
{
if (InworldPlayer->IsConversationParticipant() != bParticipating)
{
InworldPlayer->SetConversationParticipation(bParticipating);
}
bConversationParticipant = InworldPlayer->IsConversationParticipant();
}

void UInworldPlayerComponent::ContinueConversation()
{
NO_PLAYER_RETURN(void())

InworldPlayer->SendTriggerToConversation(TEXT("inworld.conversation.next_turn"), {});
}

UInworldCharacterComponent* UInworldPlayerComponent::GetTargetInworldCharacter()
{
TArray<UInworldCharacterComponent*> TargetCharacters = GetTargetInworldCharacters();
Expand All @@ -126,21 +152,14 @@ TArray<UInworldCharacterComponent*> UInworldPlayerComponent::GetTargetInworldCha
return InworldCharacterComponents;
}

void UInworldPlayerComponent::ContinueMultiAgentConversation()
{
NO_PLAYER_RETURN(void())

InworldPlayer->SendTriggerToConversation(TEXT("inworld.conversation.next_turn"), {});
}

void UInworldPlayerComponent::SetTargetInworldCharacter(UInworldCharacterComponent* Character)
void UInworldPlayerComponent::AddTargetInworldCharacter(UInworldCharacterComponent* Character)
{
NO_PLAYER_RETURN(void())

InworldPlayer->AddTargetCharacter(IInworldCharacterOwnerInterface::Execute_GetInworldCharacter(Character));
}

void UInworldPlayerComponent::ClearTargetInworldCharacter(UInworldCharacterComponent* Character)
void UInworldPlayerComponent::RemoveTargetInworldCharacter(UInworldCharacterComponent* Character)
{
NO_PLAYER_RETURN(void())

Expand Down
10 changes: 9 additions & 1 deletion InworldAI/Source/InworldAIIntegration/Public/InworldPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ class INWORLDAIINTEGRATION_API UInworldPlayer : public UObject
UFUNCTION(BlueprintCallable, Category = "Player")
TScriptInterface<IInworldPlayerOwnerInterface> GetInworldPlayerOwner();

UFUNCTION(BlueprintCallable, Category = "Target")
UFUNCTION(BlueprintCallable, Category = "Participation")
void SetConversationParticipation(bool bParticipate);
UFUNCTION(BlueprintPure, Category = "Participation")
bool IsConversationParticipant() const { return bConversationParticipant; }

UFUNCTION(BlueprintPure, Category = "Target")
const TArray<UInworldCharacter*>& GetTargetCharacters() const { return TargetCharacters; }

UFUNCTION(BlueprintCallable, Category = "Target")
Expand Down Expand Up @@ -101,6 +106,9 @@ class INWORLDAIINTEGRATION_API UInworldPlayer : public UObject
UPROPERTY(Replicated)
UInworldSession* Session;

UPROPERTY(Replicated)
bool bConversationParticipant = true;

UPROPERTY(Replicated)
TArray<UInworldCharacter*> TargetCharacters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
class UInworldApiSubsystem;
class UInworldCharacterComponent;

USTRUCT()
struct FInworldPlayerTargetCharacter
{
GENERATED_BODY()

FDelegateHandle UnpossessedHandle;

UPROPERTY()
FString AgentId;
};

UCLASS(ClassGroup = (Inworld), meta = (BlueprintSpawnableComponent))
class INWORLDAIINTEGRATION_API UInworldPlayerComponent : public UActorComponent, public IInworldPlayerOwnerInterface
{
Expand All @@ -44,24 +33,33 @@ class INWORLDAIINTEGRATION_API UInworldPlayerComponent : public UActorComponent,
virtual void InitializeComponent() override;
virtual void UninitializeComponent() override;

virtual void BeginPlay() override;

virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
virtual bool ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags) override;

UFUNCTION(BlueprintCallable, Category = "Interaction")
void SetConversationParticipation(bool bParticipant);

UFUNCTION(BlueprintCallable, Category = "Interaction")
void ContinueConversation();

UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "GetTargetCharacter"))
UInworldCharacterComponent* GetTargetInworldCharacter();
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "GetTargetCharacters"))
TArray<UInworldCharacterComponent*> GetTargetInworldCharacters();

UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (DeprecatedFunction, DeprecationMessage = "Will be removed in next release."))
void ContinueMultiAgentConversation();

UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "SetTargetCharacter"))
void SetTargetInworldCharacter(UInworldCharacterComponent* Character);
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "SetTargetCharacter", DeprecatedFunction, DeprecationMessage="Please use AddTargetCharacter"))
void SetTargetInworldCharacter(UInworldCharacterComponent* Character) { AddTargetInworldCharacter(Character); }
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "AddTargetCharacter"))
void AddTargetInworldCharacter(UInworldCharacterComponent* Character);

UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "ClearTargetCharacter"))
void ClearTargetInworldCharacter(UInworldCharacterComponent* Character);
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "ClearTargetCharacter", DeprecatedFunction, DeprecationMessage = "Please use RemoveTargetCharacter"))
void ClearTargetInworldCharacter(UInworldCharacterComponent* Character) { RemoveTargetInworldCharacter(Character); }
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "RemoveTargetCharacter"))
void RemoveTargetInworldCharacter(UInworldCharacterComponent* Character);

UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "ClearTargetCharacter"))
UFUNCTION(BlueprintCallable, Category = "Interaction", meta = (Displayname = "ClearAllTargetCharacters"))
void ClearAllTargetInworldCharacters();

UFUNCTION(BlueprintCallable, Category = "Interaction")
Expand Down Expand Up @@ -91,6 +89,9 @@ class INWORLDAIINTEGRATION_API UInworldPlayerComponent : public UActorComponent,
UPROPERTY(Replicated)
UInworldPlayer* InworldPlayer;

UPROPERTY(EditDefaultsOnly, Category = "Conversation")
bool bConversationParticipant = true;

#if defined(WITH_GAMEPLAY_DEBUGGER) && WITH_GAMEPLAY_DEBUGGER
friend class FInworldGameplayDebuggerCategory;
#endif
Expand Down

0 comments on commit e867e36

Please sign in to comment.