From dfadd7cf3cd69cefe941b5acc11eab2c3d7d9c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Thu, 25 Apr 2024 17:50:57 +0200 Subject: [PATCH 01/15] setup input buffer --- .../GBFAnimNotifyState_InputBuffer.cpp | 42 +++++++++++++++++++ .../GBFAbilityInputBufferComponent.cpp | 20 +++++++++ .../GBFAnimNotifyState_InputBuffer.h | 26 ++++++++++++ .../GBFAbilityInputBufferComponent.h | 26 ++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp create mode 100644 Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp create mode 100644 Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h create mode 100644 Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp new file mode 100644 index 00000000..63071a5c --- /dev/null +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp @@ -0,0 +1,42 @@ +#include "Animation/GBFAnimNotifyState_InputBuffer.h" +#include "Characters/Components/GBFAbilityInputBufferComponent.h" + +#include + +void UGBFAnimNotifyState_InputBuffer::NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) +{ + Super::NotifyBegin( mesh_component, animation, total_duration, event_reference ); + + if ( auto * aibc = GetAbilityInputBufferComponent( mesh_component ) ) + { + aibc->StartMonitoring( InputTagContainer ); + } +} + +void UGBFAnimNotifyState_InputBuffer::NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) +{ + Super::NotifyEnd( mesh_component, animation, event_reference ); + + if ( auto * aibc = GetAbilityInputBufferComponent( mesh_component ) ) + { + aibc->StopMonitoring(); + } +} + +UGBFAbilityInputBufferComponent * UGBFAnimNotifyState_InputBuffer::GetAbilityInputBufferComponent_Implementation( const USkeletalMeshComponent * mesh_component ) const +{ + if ( mesh_component == nullptr ) + { + return nullptr; + } + + if ( const auto * owner = mesh_component->GetOwner() ) + { + if ( auto * aibc = owner->FindComponentByClass< UGBFAbilityInputBufferComponent >() ) + { + return aibc; + } + } + + return nullptr; +} diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp new file mode 100644 index 00000000..1390dfb0 --- /dev/null +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -0,0 +1,20 @@ +#include "Characters/Components/GBFAbilityInputBufferComponent.h" + +void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tag_container ) +{ + //Find action + //Bind actions +} + +void UGBFAbilityInputBufferComponent::StopMonitoring() +{ + //TryToActivateAction + //Unbind all actions +} + +void UGBFAbilityInputBufferComponent::Input_AbilityInputTagPressed( FGameplayTag input_tag ) +{ + //Add to buffer +} + + diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h new file mode 100644 index 00000000..d2703475 --- /dev/null +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "GBFAnimNotifyState_InputBuffer.generated.h" + +class UGBFAbilityInputBufferComponent; + +UCLASS( DisplayName = "Input Buffer Window" ) +class GAMEBASEFRAMEWORK_API UGBFAnimNotifyState_InputBuffer : public UAnimNotifyState +{ + GENERATED_BODY() + +public: + void NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) override; + void NotifyEnd( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, const FAnimNotifyEventReference & event_reference ) override; + +protected: + UFUNCTION( BlueprintNativeEvent ) + UGBFAbilityInputBufferComponent * GetAbilityInputBufferComponent( const USkeletalMeshComponent * mesh_component ) const; + +private: + UPROPERTY( EditAnywhere, Meta = ( Categories = "Input" ) ) + FGameplayTagContainer InputTagContainer; +}; diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h new file mode 100644 index 00000000..d54bd0f6 --- /dev/null +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Characters/Components/GBFPawnComponent.h" + +#include + +#include "GBFAbilityInputBufferComponent.generated.h" + +//Enum + +UCLASS() +class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UGBFPawnComponent +{ + GENERATED_BODY() +public: + void StartMonitoring( FGameplayTagContainer input_tag_container ); + void StopMonitoring(); + +protected: + UFUNCTION( BlueprintCallable ) + //void GetInputMapping(); + //void FindInputConfig( FGameplayTag input_tag ); + //void AddInputConfig( const UGBFInputConfig * input_config ); + //TQueue or TMap AbilityBuffer + void Input_AbilityInputTagPressed( FGameplayTag input_tag ); +}; From 6390933eb547b102950ccb5ede2ecfa27688c788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Fri, 26 Apr 2024 17:27:34 +0200 Subject: [PATCH 02/15] wip register triggered actions --- .../GBFAbilityInputBufferComponent.cpp | 76 +++++++++++++++++-- .../Components/GBFHeroComponent.cpp | 5 ++ .../GBFAbilityInputBufferComponent.h | 15 ++-- .../Characters/Components/GBFHeroComponent.h | 2 + 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 1390dfb0..dbd809bd 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -1,20 +1,80 @@ #include "Characters/Components/GBFAbilityInputBufferComponent.h" +#include "Characters/Components/GBFHeroComponent.h" +#include "Characters/Components/GBFPawnExtensionComponent.h" +#include "Characters/GBFPawnData.h" +#include "Engine/GBFLocalPlayer.h" + +#include +#include + void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tag_container ) { - //Find action - //Bind actions + if ( input_tag_container.IsEmpty() ) + { + return; + } + + auto * pawn = GetPawn< APawn >(); + if ( pawn == nullptr ) + { + return; + } + + if ( const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ) ) + { + TMap< const UGBFInputConfig *, TArray< uint32 > > input_configs = hero_component->GetBoundActionsByInputconfig(); + for ( auto & input_config : input_configs ) + { + + if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) + { + for ( auto & tag : input_tag_container ) + { + if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) + { + BindHandles.Add( + input_component->BindAction( + input_action, + ETriggerEvent::Triggered, + this, + &ThisClass::AbilityInputTagPressed ) + .GetHandle() ); + } + } + } + } + } } void UGBFAbilityInputBufferComponent::StopMonitoring() { - //TryToActivateAction - //Unbind all actions + int t = TriggeredInputCount; + TriggeredInputCount = 0; + + auto * pawn = GetPawn< APawn >(); + if ( pawn == nullptr ) + { + return; + } + + if ( const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ) ) + { + if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) + { + for ( auto & handle : BindHandles ) + { + input_component->RemoveBindingByHandle( handle ); + } + } + } + + //TryToActivateAction + //Unbind all actions } -void UGBFAbilityInputBufferComponent::Input_AbilityInputTagPressed( FGameplayTag input_tag ) +//TODO : need to figure out which action has been pressed +void UGBFAbilityInputBufferComponent::AbilityInputTagPressed() { - //Add to buffer + TriggeredInputCount++; } - - diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp index d02cb689..021158f0 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp @@ -224,6 +224,11 @@ void UGBFHeroComponent::ClearAbilityCameraMode( const FGameplayAbilitySpecHandle } } +TMap< const UGBFInputConfig *, TArray< uint32 > > UGBFHeroComponent::GetBoundActionsByInputconfig() const +{ + return BoundActionsByInputConfig; +} + void UGBFHeroComponent::OnRegister() { Super::OnRegister(); diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index d54bd0f6..55fd3834 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -3,13 +3,14 @@ #include "Characters/Components/GBFPawnComponent.h" #include +#include "Input/GBFInputComponent.h" #include "GBFAbilityInputBufferComponent.generated.h" //Enum -UCLASS() -class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UGBFPawnComponent +UCLASS(Blueprintable) +class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnComponent { GENERATED_BODY() public: @@ -17,10 +18,8 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UGBFPawnCom void StopMonitoring(); protected: - UFUNCTION( BlueprintCallable ) - //void GetInputMapping(); - //void FindInputConfig( FGameplayTag input_tag ); - //void AddInputConfig( const UGBFInputConfig * input_config ); - //TQueue or TMap AbilityBuffer - void Input_AbilityInputTagPressed( FGameplayTag input_tag ); + void AbilityInputTagPressed(); + + int TriggeredInputCount = 0; + TArray< uint32 > BindHandles; }; diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h index 69c94232..53a92b9d 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h @@ -48,6 +48,8 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent /** Clears the camera override if it is set */ void ClearAbilityCameraMode( const FGameplayAbilitySpecHandle & owning_spec_handle ); + TMap< const UGBFInputConfig *, TArray< uint32 > > GetBoundActionsByInputconfig() const; + protected: void OnRegister() override; void BindToRequiredOnActorInitStateChanged() override; From 4f17a396882722c46a16033eb3005db53637445c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 29 Apr 2024 10:30:14 +0200 Subject: [PATCH 03/15] input buffer working with one ability --- .../GBFAbilityInputBufferComponent.cpp | 30 ++++++++++++++----- .../Components/GBFAbilitySystemComponent.cpp | 18 +++++++++++ .../GBFAbilityInputBufferComponent.h | 3 +- .../Components/GBFAbilitySystemComponent.h | 2 ++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index dbd809bd..4dbb651f 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -4,6 +4,7 @@ #include "Characters/Components/GBFPawnExtensionComponent.h" #include "Characters/GBFPawnData.h" #include "Engine/GBFLocalPlayer.h" +#include "GAS/Components/GBFAbilitySystemComponent.h" #include #include @@ -38,7 +39,8 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp input_action, ETriggerEvent::Triggered, this, - &ThisClass::AbilityInputTagPressed ) + &ThisClass::AbilityInputTagPressed, + tag ) .GetHandle() ); } } @@ -49,8 +51,6 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp void UGBFAbilityInputBufferComponent::StopMonitoring() { - int t = TriggeredInputCount; - TriggeredInputCount = 0; auto * pawn = GetPawn< APawn >(); if ( pawn == nullptr ) @@ -68,13 +68,27 @@ void UGBFAbilityInputBufferComponent::StopMonitoring() } } } + if ( AddedTags.IsEmpty() ) + { + return; + } - //TryToActivateAction - //Unbind all actions + if ( const auto * pawn_ext_comp = UGBFPawnExtensionComponent::FindPawnExtensionComponent( pawn ) ) + { + if ( auto * asc = pawn_ext_comp->GetGBFAbilitySystemComponent() ) + { + FGameplayTag tag = AddedTags[ 0 ]; + if ( auto* ability = asc->FindAbilityClassWithInputTag(tag)) { + + asc->CancelAbility( ability ); + asc->TryActivateAbilityByClass( ability->GetClass() ); + } + AddedTags.Reset(); + } + } } -//TODO : need to figure out which action has been pressed -void UGBFAbilityInputBufferComponent::AbilityInputTagPressed() +void UGBFAbilityInputBufferComponent::AbilityInputTagPressed( FGameplayTag input_tag ) { - TriggeredInputCount++; + AddedTags.Add( input_tag ); } diff --git a/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp b/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp index 83c8b143..adeba622 100644 --- a/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp +++ b/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp @@ -379,6 +379,24 @@ FGameplayAbilitySpecHandle UGBFAbilitySystemComponent::FindAbilitySpecHandleForC return FGameplayAbilitySpecHandle(); } +UGameplayAbility * UGBFAbilitySystemComponent::FindAbilityClassWithInputTag( FGameplayTag input_tag ) +{ + if ( !input_tag.IsValid() ) + { + return nullptr; + } + + for ( const auto & ability_spec : ActivatableAbilities.Items ) + { + if ( ability_spec.Ability && ability_spec.DynamicAbilityTags.HasTagExact( input_tag ) ) + { + return ability_spec.Ability; + } + } + + return nullptr; +} + void UGBFAbilitySystemComponent::OurCancelAllAbilities() { static const auto GameplayTagContainer = FGameplayTagContainer::CreateFromArray( diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 55fd3834..4fbe9461 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -18,8 +18,9 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon void StopMonitoring(); protected: - void AbilityInputTagPressed(); + void AbilityInputTagPressed( FGameplayTag input_tag ); int TriggeredInputCount = 0; TArray< uint32 > BindHandles; + TArray< FGameplayTag > AddedTags; }; diff --git a/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h b/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h index 86b5b319..a2de1342 100644 --- a/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h +++ b/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h @@ -112,6 +112,8 @@ class GAMEBASEFRAMEWORK_API UGBFAbilitySystemComponent : public UAbilitySystemCo UFUNCTION( BlueprintPure ) FGameplayAbilitySpecHandle FindAbilitySpecHandleForClass( const TSubclassOf< UGameplayAbility > & ability_class ); + UFUNCTION( BlueprintPure ) + UGameplayAbility * FindAbilityClassWithInputTag( FGameplayTag input_tag ); UFUNCTION( BlueprintCallable ) void OurCancelAllAbilities(); From 726a2425d2b7e86073edb4da816fcf79b21cfd05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 29 Apr 2024 11:59:40 +0200 Subject: [PATCH 04/15] code cleanup + trigger priority --- .../GBFAnimNotifyState_InputBuffer.cpp | 3 +- .../GBFAbilityInputBufferComponent.cpp | 101 ++++++++++++------ .../GBFAnimNotifyState_InputBuffer.h | 6 +- .../GBFAbilityInputBufferComponent.h | 20 ++-- 4 files changed, 91 insertions(+), 39 deletions(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp index 63071a5c..410b9165 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp @@ -1,5 +1,4 @@ #include "Animation/GBFAnimNotifyState_InputBuffer.h" -#include "Characters/Components/GBFAbilityInputBufferComponent.h" #include @@ -9,7 +8,7 @@ void UGBFAnimNotifyState_InputBuffer::NotifyBegin( USkeletalMeshComponent * mesh if ( auto * aibc = GetAbilityInputBufferComponent( mesh_component ) ) { - aibc->StartMonitoring( InputTagContainer ); + aibc->StartMonitoring( InputTagsToCheck, TriggerPriority ); } } diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 4dbb651f..a35abbe1 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -2,16 +2,30 @@ #include "Characters/Components/GBFHeroComponent.h" #include "Characters/Components/GBFPawnExtensionComponent.h" -#include "Characters/GBFPawnData.h" -#include "Engine/GBFLocalPlayer.h" #include "GAS/Components/GBFAbilitySystemComponent.h" +#include "Input/GBFInputComponent.h" -#include -#include +void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ) +{ + if ( input_tags_to_check.IsEmpty() ) + { + return; + } + + TriggerPriority = trigger_priority; + BindActions( input_tags_to_check ); +} + +void UGBFAbilityInputBufferComponent::StopMonitoring() +{ + RemoveBinds(); + TryToTriggerAbility(); + TriggeredTags.Reset(); +} -void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tag_container ) +void UGBFAbilityInputBufferComponent::BindActions( FGameplayTagContainer input_tags_to_check ) { - if ( input_tag_container.IsEmpty() ) + if ( input_tags_to_check.IsEmpty() ) { return; } @@ -24,24 +38,15 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp if ( const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ) ) { - TMap< const UGBFInputConfig *, TArray< uint32 > > input_configs = hero_component->GetBoundActionsByInputconfig(); - for ( auto & input_config : input_configs ) + for ( auto & input_config : hero_component->GetBoundActionsByInputconfig() ) { - if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) { - for ( auto & tag : input_tag_container ) + for ( auto & tag : input_tags_to_check ) { if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) { - BindHandles.Add( - input_component->BindAction( - input_action, - ETriggerEvent::Triggered, - this, - &ThisClass::AbilityInputTagPressed, - tag ) - .GetHandle() ); + BindHandles.Add( input_component->BindAction( input_action, ETriggerEvent::Triggered, this, &ThisClass::AbilityInputTagPressed, tag ).GetHandle() ); } } } @@ -49,9 +54,8 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp } } -void UGBFAbilityInputBufferComponent::StopMonitoring() +void UGBFAbilityInputBufferComponent::RemoveBinds() { - auto * pawn = GetPawn< APawn >(); if ( pawn == nullptr ) { @@ -68,27 +72,64 @@ void UGBFAbilityInputBufferComponent::StopMonitoring() } } } - if ( AddedTags.IsEmpty() ) +} + +void UGBFAbilityInputBufferComponent::AbilityInputTagPressed( FGameplayTag input_tag ) +{ + TriggeredTags.Add( input_tag ); +} + +bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() +{ + if ( TriggeredTags.IsEmpty() ) { - return; + return false; + } + + auto * pawn = GetPawn< APawn >(); + if ( pawn == nullptr ) + { + return false; } if ( const auto * pawn_ext_comp = UGBFPawnExtensionComponent::FindPawnExtensionComponent( pawn ) ) { if ( auto * asc = pawn_ext_comp->GetGBFAbilitySystemComponent() ) { - FGameplayTag tag = AddedTags[ 0 ]; - if ( auto* ability = asc->FindAbilityClassWithInputTag(tag)) { - - asc->CancelAbility( ability ); - asc->TryActivateAbilityByClass( ability->GetClass() ); + FGameplayTag tag = TryToGetInputTagWithPriority(); + if ( tag.IsValid() ) + { + if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) + { + asc->CancelAbility( ability ); + bool activated = asc->TryActivateAbilityByClass( ability->GetClass() ); + if ( activated ) + { + return true; + } + } } - AddedTags.Reset(); } } + + return false; } -void UGBFAbilityInputBufferComponent::AbilityInputTagPressed( FGameplayTag input_tag ) +FGameplayTag UGBFAbilityInputBufferComponent::TryToGetInputTagWithPriority() { - AddedTags.Add( input_tag ); + if ( TriggeredTags.IsEmpty() ) + { + return FGameplayTag::EmptyTag; + } + + switch ( TriggerPriority ) + { + case ETriggerPriority::LastTriggeredInput: + return TriggeredTags[ 0 ]; + case ETriggerPriority::MostTriggeredInput: + //TO DO + return FGameplayTag::EmptyTag; + default: + return FGameplayTag::EmptyTag; + } } diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h index d2703475..5f1e6e7f 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h @@ -1,5 +1,7 @@ #pragma once +#include "Characters/Components/GBFAbilityInputBufferComponent.h" + #include #include @@ -21,6 +23,8 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotifyState_InputBuffer : public UAnimNotify UGBFAbilityInputBufferComponent * GetAbilityInputBufferComponent( const USkeletalMeshComponent * mesh_component ) const; private: + UPROPERTY( EditAnywhere ) + ETriggerPriority TriggerPriority; UPROPERTY( EditAnywhere, Meta = ( Categories = "Input" ) ) - FGameplayTagContainer InputTagContainer; + FGameplayTagContainer InputTagsToCheck; }; diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 4fbe9461..2b07680b 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -3,24 +3,32 @@ #include "Characters/Components/GBFPawnComponent.h" #include -#include "Input/GBFInputComponent.h" #include "GBFAbilityInputBufferComponent.generated.h" -//Enum +UENUM( BlueprintType ) +enum class ETriggerPriority : uint8 +{ + LastTriggeredInput = 0 UMETA( DisplayName = "Last Triggered Input" ), + MostTriggeredInput = 1 UMETA( DisplayName = "Most Triggered Input" ) +}; -UCLASS(Blueprintable) +UCLASS( Blueprintable ) class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnComponent { GENERATED_BODY() public: - void StartMonitoring( FGameplayTagContainer input_tag_container ); + void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); void StopMonitoring(); protected: + void BindActions( FGameplayTagContainer input_tags_to_check ); + void RemoveBinds(); void AbilityInputTagPressed( FGameplayTag input_tag ); + bool TryToTriggerAbility(); + FGameplayTag TryToGetInputTagWithPriority(); - int TriggeredInputCount = 0; TArray< uint32 > BindHandles; - TArray< FGameplayTag > AddedTags; + TArray< FGameplayTag > TriggeredTags; + ETriggerPriority TriggerPriority; }; From 83458a822c079304887227a8868d64a182719e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 29 Apr 2024 14:55:05 +0200 Subject: [PATCH 05/15] add new priority --- .../GBFAbilityInputBufferComponent.cpp | 78 +++++++++++++++++-- .../GBFAbilityInputBufferComponent.h | 9 ++- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index a35abbe1..b3e83964 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -13,7 +13,8 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp } TriggerPriority = trigger_priority; - BindActions( input_tags_to_check ); + InputTagsToCheck = input_tags_to_check; + BindActions(); } void UGBFAbilityInputBufferComponent::StopMonitoring() @@ -21,11 +22,12 @@ void UGBFAbilityInputBufferComponent::StopMonitoring() RemoveBinds(); TryToTriggerAbility(); TriggeredTags.Reset(); + InputTagsToCheck.Reset(); } -void UGBFAbilityInputBufferComponent::BindActions( FGameplayTagContainer input_tags_to_check ) +void UGBFAbilityInputBufferComponent::BindActions() { - if ( input_tags_to_check.IsEmpty() ) + if ( InputTagsToCheck.IsEmpty() ) { return; } @@ -42,7 +44,7 @@ void UGBFAbilityInputBufferComponent::BindActions( FGameplayTagContainer input_t { if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) { - for ( auto & tag : input_tags_to_check ) + for ( auto & tag : InputTagsToCheck ) { if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) { @@ -96,8 +98,16 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() { if ( auto * asc = pawn_ext_comp->GetGBFAbilitySystemComponent() ) { + for ( auto & tagged_ability_tag : InputTagsToCheck ) + { + auto * tagged_ability = asc->FindAbilityClassWithInputTag( tagged_ability_tag ); + asc->CancelAbility( tagged_ability ); + } + + //Try to activate ability in priority order FGameplayTag tag = TryToGetInputTagWithPriority(); - if ( tag.IsValid() ) + + while ( tag.IsValid() ) { if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) { @@ -108,6 +118,9 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() return true; } } + + //Try to go next + tag = TryToGetInputTagWithPriority(); } } } @@ -125,11 +138,60 @@ FGameplayTag UGBFAbilityInputBufferComponent::TryToGetInputTagWithPriority() switch ( TriggerPriority ) { case ETriggerPriority::LastTriggeredInput: - return TriggeredTags[ 0 ]; + return GetLastTriggeredInput(); + case ETriggerPriority::MostTriggeredInput: - //TO DO - return FGameplayTag::EmptyTag; + return GetMostTriggeredInput(); + default: return FGameplayTag::EmptyTag; } } + +FGameplayTag UGBFAbilityInputBufferComponent::GetLastTriggeredInput() +{ + FGameplayTag first_tag = TriggeredTags[ 0 ]; + TriggeredTags.RemoveAll( + [ & ]( FGameplayTag & tag ) { + return tag.MatchesTagExact( first_tag ); + } ); + return first_tag; +} + +FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() +{ + TMap< int, FGameplayTag > triggered_tag_map; + + //remove all to get count easily + for ( auto & tag_to_remove : InputTagsToCheck ) + { + int count = TriggeredTags.RemoveAll( + [ & ]( FGameplayTag & tag ) { + return tag.MatchesTagExact( tag_to_remove ); + } ); + triggered_tag_map.Add( count, tag_to_remove ); + } + int max = -1; + for ( auto & i : triggered_tag_map ) + { + if ( i.Key > max ) + { + max = i.Key; + } + } + + FGameplayTag most_triggered_tag = triggered_tag_map.FindAndRemoveChecked( max ); + + //sort if first ability fails + triggered_tag_map.Remove( 0 ); + triggered_tag_map.KeySort( + []( const int & a, const int & b ) { + return a > b; + } ); + for ( auto & i : triggered_tag_map ) + { + TriggeredTags.Add( i.Value ); + } + + return most_triggered_tag; +} diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 2b07680b..110286d7 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -22,13 +22,16 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon void StopMonitoring(); protected: - void BindActions( FGameplayTagContainer input_tags_to_check ); + void BindActions(); void RemoveBinds(); void AbilityInputTagPressed( FGameplayTag input_tag ); bool TryToTriggerAbility(); FGameplayTag TryToGetInputTagWithPriority(); + FGameplayTag GetLastTriggeredInput(); + FGameplayTag GetMostTriggeredInput(); - TArray< uint32 > BindHandles; - TArray< FGameplayTag > TriggeredTags; ETriggerPriority TriggerPriority; + FGameplayTagContainer InputTagsToCheck; + TArray< FGameplayTag > TriggeredTags; + TArray< uint32 > BindHandles; }; From df0db85dd1c9b6837cc401fe15bebffa316b04dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 29 Apr 2024 16:59:38 +0200 Subject: [PATCH 06/15] fix find input buffer component --- .../GBFAnimNotifyState_InputBuffer.cpp | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp index 410b9165..86c33918 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp @@ -1,5 +1,7 @@ #include "Animation/GBFAnimNotifyState_InputBuffer.h" +#include "GBFLog.h" + #include void UGBFAnimNotifyState_InputBuffer::NotifyBegin( USkeletalMeshComponent * mesh_component, UAnimSequenceBase * animation, float total_duration, const FAnimNotifyEventReference & event_reference ) @@ -29,13 +31,44 @@ UGBFAbilityInputBufferComponent * UGBFAnimNotifyState_InputBuffer::GetAbilityInp return nullptr; } + UGBFAbilityInputBufferComponent * aibc = nullptr; + if ( const auto * owner = mesh_component->GetOwner() ) { - if ( auto * aibc = owner->FindComponentByClass< UGBFAbilityInputBufferComponent >() ) + aibc = owner->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + + if ( aibc != nullptr ) { return aibc; } + //check all parent + auto * parent = owner->GetParentActor(); + while ( parent ) + { + aibc = parent->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + if ( aibc != nullptr ) + { + return aibc; + } + parent = parent->GetParentActor(); + } + + // Check all attached actors + TArray< AActor * > actors; + owner->GetAttachedActors( actors, true, true ); + actors.RemoveAll( []( AActor * actor ) { + return !Cast< APawn >( actor ); + } ); + for ( auto & child : actors ) + { + aibc = child->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + if ( aibc != nullptr ) + { + return aibc; + } + } } + UE_LOG( LogGBF, Error, TEXT( "No Ability Input Buffer Component found" ) ); return nullptr; } From 72edbd48b6e39ec6e355576958747658c5b16712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 29 Apr 2024 17:14:46 +0200 Subject: [PATCH 07/15] cleanup code --- .../GBFAbilityInputBufferComponent.cpp | 80 +++++++++++-------- .../GBFAbilityInputBufferComponent.h | 1 + 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index b3e83964..451a1c33 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -12,6 +12,7 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp return; } + Reset(); TriggerPriority = trigger_priority; InputTagsToCheck = input_tags_to_check; BindActions(); @@ -21,6 +22,11 @@ void UGBFAbilityInputBufferComponent::StopMonitoring() { RemoveBinds(); TryToTriggerAbility(); + Reset(); +} + +void UGBFAbilityInputBufferComponent::Reset() +{ TriggeredTags.Reset(); InputTagsToCheck.Reset(); } @@ -38,19 +44,24 @@ void UGBFAbilityInputBufferComponent::BindActions() return; } - if ( const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ) ) + const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ); + if ( hero_component == nullptr ) + { + return; + } + + for ( auto & input_config : hero_component->GetBoundActionsByInputconfig() ) { - for ( auto & input_config : hero_component->GetBoundActionsByInputconfig() ) + auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >(); + if ( input_component == nullptr ) + { + continue; + } + for ( auto & tag : InputTagsToCheck ) { - if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) + if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) { - for ( auto & tag : InputTagsToCheck ) - { - if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) - { - BindHandles.Add( input_component->BindAction( input_action, ETriggerEvent::Triggered, this, &ThisClass::AbilityInputTagPressed, tag ).GetHandle() ); - } - } + BindHandles.Add( input_component->BindAction( input_action, ETriggerEvent::Triggered, this, &ThisClass::AbilityInputTagPressed, tag ).GetHandle() ); } } } @@ -94,37 +105,38 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() return false; } - if ( const auto * pawn_ext_comp = UGBFPawnExtensionComponent::FindPawnExtensionComponent( pawn ) ) + const auto * pawn_ext_comp = UGBFPawnExtensionComponent::FindPawnExtensionComponent( pawn ); + if ( pawn_ext_comp == nullptr ) { - if ( auto * asc = pawn_ext_comp->GetGBFAbilitySystemComponent() ) + return false; + } + + if ( auto * asc = pawn_ext_comp->GetGBFAbilitySystemComponent() ) + { + for ( auto & tagged_ability_tag : InputTagsToCheck ) { - for ( auto & tagged_ability_tag : InputTagsToCheck ) - { - auto * tagged_ability = asc->FindAbilityClassWithInputTag( tagged_ability_tag ); - asc->CancelAbility( tagged_ability ); - } + auto * tagged_ability = asc->FindAbilityClassWithInputTag( tagged_ability_tag ); + asc->CancelAbility( tagged_ability ); + } - //Try to activate ability in priority order - FGameplayTag tag = TryToGetInputTagWithPriority(); + // Try to activate ability in priority order + FGameplayTag tag = TryToGetInputTagWithPriority(); - while ( tag.IsValid() ) + while ( tag.IsValid() ) + { + if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) { - if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) + asc->CancelAbility( ability ); + bool activated = asc->TryActivateAbilityByClass( ability->GetClass() ); + if ( activated ) { - asc->CancelAbility( ability ); - bool activated = asc->TryActivateAbilityByClass( ability->GetClass() ); - if ( activated ) - { - return true; - } + return true; } - - //Try to go next - tag = TryToGetInputTagWithPriority(); } + + tag = TryToGetInputTagWithPriority(); } } - return false; } @@ -162,7 +174,7 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() { TMap< int, FGameplayTag > triggered_tag_map; - //remove all to get count easily + // Remove all to get count easily for ( auto & tag_to_remove : InputTagsToCheck ) { int count = TriggeredTags.RemoveAll( @@ -171,6 +183,8 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() } ); triggered_tag_map.Add( count, tag_to_remove ); } + + // Get most triggered input int max = -1; for ( auto & i : triggered_tag_map ) { @@ -182,7 +196,7 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() FGameplayTag most_triggered_tag = triggered_tag_map.FindAndRemoveChecked( max ); - //sort if first ability fails + // Sort to keep order if first ability fails triggered_tag_map.Remove( 0 ); triggered_tag_map.KeySort( []( const int & a, const int & b ) { diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 110286d7..ec357273 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -22,6 +22,7 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon void StopMonitoring(); protected: + void Reset(); void BindActions(); void RemoveBinds(); void AbilityInputTagPressed( FGameplayTag input_tag ); From ddd7262645b74a9435c1413dc20bed0c83a136c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Deiber?= Date: Mon, 29 Apr 2024 18:43:36 +0200 Subject: [PATCH 08/15] reset + clang format --- .../Private/Animation/GBFAnimNotifyState_InputBuffer.cpp | 2 +- .../Characters/Components/GBFAbilityInputBufferComponent.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp index 86c33918..fb116e67 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp @@ -41,7 +41,7 @@ UGBFAbilityInputBufferComponent * UGBFAnimNotifyState_InputBuffer::GetAbilityInp { return aibc; } - //check all parent + // Check all parent auto * parent = owner->GetParentActor(); while ( parent ) { diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 451a1c33..f7256400 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -29,6 +29,7 @@ void UGBFAbilityInputBufferComponent::Reset() { TriggeredTags.Reset(); InputTagsToCheck.Reset(); + BindHandles.Reset(); } void UGBFAbilityInputBufferComponent::BindActions() From 528ecbc4ec9e1f394efc2b26fe5ec70162469503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Deiber?= Date: Mon, 29 Apr 2024 20:20:12 +0200 Subject: [PATCH 09/15] add blueprint callable --- .../Public/Animation/GBFAnimNotifyState_InputBuffer.h | 2 +- .../Characters/Components/GBFAbilityInputBufferComponent.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h index 5f1e6e7f..6dd873da 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h @@ -9,7 +9,7 @@ class UGBFAbilityInputBufferComponent; -UCLASS( DisplayName = "Input Buffer Window" ) +UCLASS( DisplayName = "Ability Input Buffer Window" ) class GAMEBASEFRAMEWORK_API UGBFAnimNotifyState_InputBuffer : public UAnimNotifyState { GENERATED_BODY() diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index ec357273..6d46d7c7 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -18,7 +18,10 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon { GENERATED_BODY() public: + UFUNCTION( BlueprintCallable ) void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); + + UFUNCTION( BlueprintCallable ) void StopMonitoring(); protected: From d872059c45953500b3c955a3af097a19157878f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Tue, 30 Apr 2024 17:17:34 +0200 Subject: [PATCH 10/15] review --- .../GBFAnimNotifyState_InputBuffer.cpp | 67 ++++++++++--------- .../GBFAbilityInputBufferComponent.cpp | 39 +++++------ 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp index fb116e67..45d8363f 100644 --- a/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp +++ b/Source/GameBaseFramework/Private/Animation/GBFAnimNotifyState_InputBuffer.cpp @@ -8,9 +8,9 @@ void UGBFAnimNotifyState_InputBuffer::NotifyBegin( USkeletalMeshComponent * mesh { Super::NotifyBegin( mesh_component, animation, total_duration, event_reference ); - if ( auto * aibc = GetAbilityInputBufferComponent( mesh_component ) ) + if ( auto * ability_input_buffer_component = GetAbilityInputBufferComponent( mesh_component ) ) { - aibc->StartMonitoring( InputTagsToCheck, TriggerPriority ); + ability_input_buffer_component->StartMonitoring( InputTagsToCheck, TriggerPriority ); } } @@ -18,9 +18,9 @@ void UGBFAnimNotifyState_InputBuffer::NotifyEnd( USkeletalMeshComponent * mesh_c { Super::NotifyEnd( mesh_component, animation, event_reference ); - if ( auto * aibc = GetAbilityInputBufferComponent( mesh_component ) ) + if ( auto * ability_input_buffer_component = GetAbilityInputBufferComponent( mesh_component ) ) { - aibc->StopMonitoring(); + ability_input_buffer_component->StopMonitoring(); } } @@ -31,41 +31,44 @@ UGBFAbilityInputBufferComponent * UGBFAnimNotifyState_InputBuffer::GetAbilityInp return nullptr; } - UGBFAbilityInputBufferComponent * aibc = nullptr; + const auto * owner = mesh_component->GetOwner(); + if ( owner == nullptr ) + { + UE_LOG( LogGBF, Error, TEXT( "Ability Input Buffer Notify : No Owner found" ) ); + return nullptr; + } - if ( const auto * owner = mesh_component->GetOwner() ) + auto * ability_input_buffer_component = owner->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + + if ( ability_input_buffer_component != nullptr ) { - aibc = owner->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + return ability_input_buffer_component; + } - if ( aibc != nullptr ) - { - return aibc; - } - // Check all parent - auto * parent = owner->GetParentActor(); - while ( parent ) + // Check all parent + auto * parent = owner->GetParentActor(); + while ( parent ) + { + ability_input_buffer_component = parent->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + if ( ability_input_buffer_component != nullptr ) { - aibc = parent->FindComponentByClass< UGBFAbilityInputBufferComponent >(); - if ( aibc != nullptr ) - { - return aibc; - } - parent = parent->GetParentActor(); + return ability_input_buffer_component; } + parent = parent->GetParentActor(); + } - // Check all attached actors - TArray< AActor * > actors; - owner->GetAttachedActors( actors, true, true ); - actors.RemoveAll( []( AActor * actor ) { - return !Cast< APawn >( actor ); - } ); - for ( auto & child : actors ) + // Check all attached actors + TArray< AActor * > actors; + owner->GetAttachedActors( actors, true, true ); + actors.RemoveAll( []( AActor * actor ) { + return !Cast< APawn >( actor ); + } ); + for ( auto & child : actors ) + { + ability_input_buffer_component = child->FindComponentByClass< UGBFAbilityInputBufferComponent >(); + if ( ability_input_buffer_component != nullptr ) { - aibc = child->FindComponentByClass< UGBFAbilityInputBufferComponent >(); - if ( aibc != nullptr ) - { - return aibc; - } + return ability_input_buffer_component; } } diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index f7256400..79431969 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -45,6 +45,12 @@ void UGBFAbilityInputBufferComponent::BindActions() return; } + auto * input_component = Cast< UEnhancedInputComponent >( pawn->InputComponent ); + if ( input_component == nullptr ) + { + return; + } + const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ); if ( hero_component == nullptr ) { @@ -53,11 +59,6 @@ void UGBFAbilityInputBufferComponent::BindActions() for ( auto & input_config : hero_component->GetBoundActionsByInputconfig() ) { - auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >(); - if ( input_component == nullptr ) - { - continue; - } for ( auto & tag : InputTagsToCheck ) { if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) ) @@ -76,14 +77,11 @@ void UGBFAbilityInputBufferComponent::RemoveBinds() return; } - if ( const auto * hero_component = UGBFHeroComponent::FindHeroComponent( pawn ) ) + if ( auto * input_component = Cast< UEnhancedInputComponent >( pawn->InputComponent ) ) { - if ( auto * input_component = pawn->FindComponentByClass< UGBFInputComponent >() ) + for ( auto & handle : BindHandles ) { - for ( auto & handle : BindHandles ) - { - input_component->RemoveBindingByHandle( handle ); - } + input_component->RemoveBindingByHandle( handle ); } } } @@ -128,8 +126,7 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) { asc->CancelAbility( ability ); - bool activated = asc->TryActivateAbilityByClass( ability->GetClass() ); - if ( activated ) + if ( asc->TryActivateAbilityByClass( ability->GetClass() ) ) { return true; } @@ -164,10 +161,7 @@ FGameplayTag UGBFAbilityInputBufferComponent::TryToGetInputTagWithPriority() FGameplayTag UGBFAbilityInputBufferComponent::GetLastTriggeredInput() { FGameplayTag first_tag = TriggeredTags[ 0 ]; - TriggeredTags.RemoveAll( - [ & ]( FGameplayTag & tag ) { - return tag.MatchesTagExact( first_tag ); - } ); + TriggeredTags.Remove( first_tag ); return first_tag; } @@ -178,20 +172,17 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() // Remove all to get count easily for ( auto & tag_to_remove : InputTagsToCheck ) { - int count = TriggeredTags.RemoveAll( - [ & ]( FGameplayTag & tag ) { - return tag.MatchesTagExact( tag_to_remove ); - } ); + int count = TriggeredTags.Remove( tag_to_remove ); triggered_tag_map.Add( count, tag_to_remove ); } // Get most triggered input int max = -1; - for ( auto & i : triggered_tag_map ) + for ( auto & input : triggered_tag_map ) { - if ( i.Key > max ) + if ( input.Key > max ) { - max = i.Key; + max = input.Key; } } From b1c1266605f4486e111a3c73fc4969cccce945e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 6 May 2024 12:52:37 +0200 Subject: [PATCH 11/15] add monitoring time verification --- .../GBFAbilityInputBufferComponent.cpp | 29 ++++++++++++++++++- .../GBFAbilityInputBufferComponent.h | 9 +++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 79431969..ae60c2d6 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -5,6 +5,24 @@ #include "GAS/Components/GBFAbilitySystemComponent.h" #include "Input/GBFInputComponent.h" +UGBFAbilityInputBufferComponent::UGBFAbilityInputBufferComponent( const FObjectInitializer & ObjectInitializer ) : + Super( ObjectInitializer ) +{ + TriggerPriority = ETriggerPriority::LastTriggeredInput; + this->PrimaryComponentTick.bStartWithTickEnabled = false; + this->PrimaryComponentTick.bCanEverTick = true; +} + +void UGBFAbilityInputBufferComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction ) +{ + Super::TickComponent( DeltaTime, TickType, ThisTickFunction ); + MonitoringTime += DeltaTime; + if ( !ensureAlwaysMsgf( MonitoringTime <= MaxMonitoringTime, TEXT( "Ability Input Buffer didn't call Stop Monitor 5 secs after activation, please call it manually !" ) ) ) + { + StopMonitoring(); + } +} + void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ) { if ( input_tags_to_check.IsEmpty() ) @@ -16,6 +34,10 @@ void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer inp TriggerPriority = trigger_priority; InputTagsToCheck = input_tags_to_check; BindActions(); + +#if !UE_BUILD_SHIPPING + SetComponentTickEnabled( true ); +#endif } void UGBFAbilityInputBufferComponent::StopMonitoring() @@ -30,6 +52,11 @@ void UGBFAbilityInputBufferComponent::Reset() TriggeredTags.Reset(); InputTagsToCheck.Reset(); BindHandles.Reset(); + MonitoringTime = 0.0f; + +#if !UE_BUILD_SHIPPING + SetComponentTickEnabled( false ); +#endif } void UGBFAbilityInputBufferComponent::BindActions() @@ -200,4 +227,4 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() } return most_triggered_tag; -} +} \ No newline at end of file diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 6d46d7c7..062b36b8 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -17,7 +17,10 @@ UCLASS( Blueprintable ) class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnComponent { GENERATED_BODY() + public: + UGBFAbilityInputBufferComponent( const FObjectInitializer & ObjectInitializer ); + void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction ) override; UFUNCTION( BlueprintCallable ) void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); @@ -38,4 +41,8 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon FGameplayTagContainer InputTagsToCheck; TArray< FGameplayTag > TriggeredTags; TArray< uint32 > BindHandles; -}; + + UPROPERTY( EditDefaultsOnly ) + float MaxMonitoringTime = 5.0f; + float MonitoringTime = 0.0f; +}; \ No newline at end of file From a9b11b02d273a7a8eea56a1f01c8c934f3395d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 13 May 2024 09:48:13 +0200 Subject: [PATCH 12/15] review standards --- .../GBFAbilityInputBufferComponent.cpp | 18 +++++----- .../Components/GBFAbilitySystemComponent.cpp | 2 +- .../GBFAnimNotifyState_InputBuffer.h | 1 + .../GBFAbilityInputBufferComponent.h | 34 +++++++++++++++++-- .../Components/GBFAbilitySystemComponent.h | 3 +- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index ae60c2d6..26de4a96 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -5,23 +5,25 @@ #include "GAS/Components/GBFAbilitySystemComponent.h" #include "Input/GBFInputComponent.h" -UGBFAbilityInputBufferComponent::UGBFAbilityInputBufferComponent( const FObjectInitializer & ObjectInitializer ) : - Super( ObjectInitializer ) +UGBFAbilityInputBufferComponent::UGBFAbilityInputBufferComponent( const FObjectInitializer & object_initializer ) : + Super( object_initializer ) { TriggerPriority = ETriggerPriority::LastTriggeredInput; this->PrimaryComponentTick.bStartWithTickEnabled = false; this->PrimaryComponentTick.bCanEverTick = true; } -void UGBFAbilityInputBufferComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction ) +#if !UE_BUILD_SHIPPING +void UGBFAbilityInputBufferComponent::TickComponent( float delta_time, ELevelTick tick_type, FActorComponentTickFunction * this_tick_function ) { - Super::TickComponent( DeltaTime, TickType, ThisTickFunction ); - MonitoringTime += DeltaTime; - if ( !ensureAlwaysMsgf( MonitoringTime <= MaxMonitoringTime, TEXT( "Ability Input Buffer didn't call Stop Monitor 5 secs after activation, please call it manually !" ) ) ) + Super::TickComponent( delta_time, tick_type, this_tick_function ); + MonitoringTime += delta_time; + if ( !ensureAlwaysMsgf( MonitoringTime <= MaxMonitoringTime, TEXT( "Ability Input Buffer didn't call Stop Monitor %f secs after activation, please call it manually !" ), MaxMonitoringTime ) ) { StopMonitoring(); } } +#endif void UGBFAbilityInputBufferComponent::StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ) { @@ -141,7 +143,7 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() { for ( auto & tagged_ability_tag : InputTagsToCheck ) { - auto * tagged_ability = asc->FindAbilityClassWithInputTag( tagged_ability_tag ); + auto * tagged_ability = asc->FindAbilityByInputTag( tagged_ability_tag ); asc->CancelAbility( tagged_ability ); } @@ -150,7 +152,7 @@ bool UGBFAbilityInputBufferComponent::TryToTriggerAbility() while ( tag.IsValid() ) { - if ( auto * ability = asc->FindAbilityClassWithInputTag( tag ) ) + if ( auto * ability = asc->FindAbilityByInputTag( tag ) ) { asc->CancelAbility( ability ); if ( asc->TryActivateAbilityByClass( ability->GetClass() ) ) diff --git a/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp b/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp index adeba622..453ebf8c 100644 --- a/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp +++ b/Source/GameBaseFramework/Private/GAS/Components/GBFAbilitySystemComponent.cpp @@ -379,7 +379,7 @@ FGameplayAbilitySpecHandle UGBFAbilitySystemComponent::FindAbilitySpecHandleForC return FGameplayAbilitySpecHandle(); } -UGameplayAbility * UGBFAbilitySystemComponent::FindAbilityClassWithInputTag( FGameplayTag input_tag ) +UGameplayAbility * UGBFAbilitySystemComponent::FindAbilityByInputTag( const FGameplayTag input_tag ) const { if ( !input_tag.IsValid() ) { diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h index 6dd873da..4c834b29 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h @@ -25,6 +25,7 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotifyState_InputBuffer : public UAnimNotify private: UPROPERTY( EditAnywhere ) ETriggerPriority TriggerPriority; + UPROPERTY( EditAnywhere, Meta = ( Categories = "Input" ) ) FGameplayTagContainer InputTagsToCheck; }; diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 062b36b8..d8c5e2cf 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -14,13 +14,17 @@ enum class ETriggerPriority : uint8 }; UCLASS( Blueprintable ) -class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnComponent +class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent final : public UPawnComponent { GENERATED_BODY() public: - UGBFAbilityInputBufferComponent( const FObjectInitializer & ObjectInitializer ); - void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction ) override; + UGBFAbilityInputBufferComponent( const FObjectInitializer & object_initializer ); + +#if !UE_BUILD_SHIPPING + void TickComponent( float delta_time, ELevelTick tick_type, FActorComponentTickFunction * this_tick_function ) override; +#endif + UFUNCTION( BlueprintCallable ) void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); @@ -28,21 +32,45 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent : public UPawnCompon void StopMonitoring(); protected: + UFUNCTION() void Reset(); + + UFUNCTION() void BindActions(); + + UFUNCTION() void RemoveBinds(); + + UFUNCTION() void AbilityInputTagPressed( FGameplayTag input_tag ); + + UFUNCTION() bool TryToTriggerAbility(); + + UFUNCTION() FGameplayTag TryToGetInputTagWithPriority(); + + UFUNCTION() FGameplayTag GetLastTriggeredInput(); + + UFUNCTION() FGameplayTag GetMostTriggeredInput(); + UPROPERTY() ETriggerPriority TriggerPriority; + + UPROPERTY() FGameplayTagContainer InputTagsToCheck; + + UPROPERTY() TArray< FGameplayTag > TriggeredTags; + + UPROPERTY() TArray< uint32 > BindHandles; UPROPERTY( EditDefaultsOnly ) float MaxMonitoringTime = 5.0f; + + UPROPERTY() float MonitoringTime = 0.0f; }; \ No newline at end of file diff --git a/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h b/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h index a2de1342..4f156865 100644 --- a/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h +++ b/Source/GameBaseFramework/Public/GAS/Components/GBFAbilitySystemComponent.h @@ -112,8 +112,9 @@ class GAMEBASEFRAMEWORK_API UGBFAbilitySystemComponent : public UAbilitySystemCo UFUNCTION( BlueprintPure ) FGameplayAbilitySpecHandle FindAbilitySpecHandleForClass( const TSubclassOf< UGameplayAbility > & ability_class ); + UFUNCTION( BlueprintPure ) - UGameplayAbility * FindAbilityClassWithInputTag( FGameplayTag input_tag ); + UGameplayAbility * FindAbilityByInputTag( const FGameplayTag input_tag ) const; UFUNCTION( BlueprintCallable ) void OurCancelAllAbilities(); From 0b3e85476f5f8b0d834c4b3abb8f008c4997b445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 13 May 2024 11:27:31 +0200 Subject: [PATCH 13/15] sorted map --- .../GBFAbilityInputBufferComponent.cpp | 26 ++++++------------- .../Components/GBFHeroComponent.cpp | 2 +- .../Characters/Components/GBFHeroComponent.h | 2 +- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 26de4a96..7dbadb34 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -196,7 +196,7 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetLastTriggeredInput() FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() { - TMap< int, FGameplayTag > triggered_tag_map; + TSortedMap< int, FGameplayTag > triggered_tag_map; // Remove all to get count easily for ( auto & tag_to_remove : InputTagsToCheck ) @@ -206,26 +206,16 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() } // Get most triggered input - int max = -1; - for ( auto & input : triggered_tag_map ) - { - if ( input.Key > max ) - { - max = input.Key; - } - } - + TArray triggered_tag_keys; + triggered_tag_map.GetKeys(triggered_tag_keys); + int max = triggered_tag_keys[triggered_tag_map.GetMaxIndex()]; + FGameplayTag most_triggered_tag = triggered_tag_map.FindAndRemoveChecked( max ); - - // Sort to keep order if first ability fails + triggered_tag_map.Remove( 0 ); - triggered_tag_map.KeySort( - []( const int & a, const int & b ) { - return a > b; - } ); - for ( auto & i : triggered_tag_map ) + for ( auto & input : triggered_tag_map ) { - TriggeredTags.Add( i.Value ); + TriggeredTags.Add( input.Value ); } return most_triggered_tag; diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp index 021158f0..127f9dd5 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp @@ -224,7 +224,7 @@ void UGBFHeroComponent::ClearAbilityCameraMode( const FGameplayAbilitySpecHandle } } -TMap< const UGBFInputConfig *, TArray< uint32 > > UGBFHeroComponent::GetBoundActionsByInputconfig() const +const TMap< const UGBFInputConfig *, TArray< uint32 > >& UGBFHeroComponent::GetBoundActionsByInputconfig() const { return BoundActionsByInputConfig; } diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h index 53a92b9d..243eec86 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h @@ -48,7 +48,7 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent /** Clears the camera override if it is set */ void ClearAbilityCameraMode( const FGameplayAbilitySpecHandle & owning_spec_handle ); - TMap< const UGBFInputConfig *, TArray< uint32 > > GetBoundActionsByInputconfig() const; + const TMap< const UGBFInputConfig *, TArray< uint32 > >& GetBoundActionsByInputconfig() const; protected: void OnRegister() override; From 261a2438133b872cd33b5d91ce44724f8994e0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 13 May 2024 11:30:26 +0200 Subject: [PATCH 14/15] remove uproperty and ufunction --- .../GBFAbilityInputBufferComponent.h | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index d8c5e2cf..1ab0122d 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -21,56 +21,35 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent final : public UPawn public: UGBFAbilityInputBufferComponent( const FObjectInitializer & object_initializer ); -#if !UE_BUILD_SHIPPING - void TickComponent( float delta_time, ELevelTick tick_type, FActorComponentTickFunction * this_tick_function ) override; -#endif - UFUNCTION( BlueprintCallable ) void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); UFUNCTION( BlueprintCallable ) void StopMonitoring(); + +#if !UE_BUILD_SHIPPING + void TickComponent( float delta_time, ELevelTick tick_type, FActorComponentTickFunction * this_tick_function ) override; +#endif protected: - UFUNCTION() - void Reset(); + UPROPERTY( EditDefaultsOnly ) + float MaxMonitoringTime = 5.0f; - UFUNCTION() + void Reset(); void BindActions(); - - UFUNCTION() void RemoveBinds(); - - UFUNCTION() void AbilityInputTagPressed( FGameplayTag input_tag ); - - UFUNCTION() bool TryToTriggerAbility(); - - UFUNCTION() - FGameplayTag TryToGetInputTagWithPriority(); - UFUNCTION() + FGameplayTag TryToGetInputTagWithPriority(); FGameplayTag GetLastTriggeredInput(); - - UFUNCTION() FGameplayTag GetMostTriggeredInput(); - UPROPERTY() ETriggerPriority TriggerPriority; - - UPROPERTY() FGameplayTagContainer InputTagsToCheck; - UPROPERTY() TArray< FGameplayTag > TriggeredTags; - - UPROPERTY() TArray< uint32 > BindHandles; - - UPROPERTY( EditDefaultsOnly ) - float MaxMonitoringTime = 5.0f; - UPROPERTY() float MonitoringTime = 0.0f; }; \ No newline at end of file From de401d778396606ea40ade61f76e82802680a130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric?= Date: Mon, 13 May 2024 11:36:08 +0200 Subject: [PATCH 15/15] clang format --- .../Components/GBFAbilityInputBufferComponent.cpp | 10 +++++----- .../Characters/Components/GBFHeroComponent.cpp | 2 +- .../Animation/GBFAnimNotifyState_InputBuffer.h | 2 +- .../Components/GBFAbilityInputBufferComponent.h | 12 ++++++------ .../Public/Characters/Components/GBFHeroComponent.h | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp index 7dbadb34..205d5a61 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFAbilityInputBufferComponent.cpp @@ -206,12 +206,12 @@ FGameplayTag UGBFAbilityInputBufferComponent::GetMostTriggeredInput() } // Get most triggered input - TArray triggered_tag_keys; - triggered_tag_map.GetKeys(triggered_tag_keys); - int max = triggered_tag_keys[triggered_tag_map.GetMaxIndex()]; - + TArray< int > triggered_tag_keys; + triggered_tag_map.GetKeys( triggered_tag_keys ); + int max = triggered_tag_keys[ triggered_tag_map.GetMaxIndex() ]; + FGameplayTag most_triggered_tag = triggered_tag_map.FindAndRemoveChecked( max ); - + triggered_tag_map.Remove( 0 ); for ( auto & input : triggered_tag_map ) { diff --git a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp index 127f9dd5..3a858610 100644 --- a/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp +++ b/Source/GameBaseFramework/Private/Characters/Components/GBFHeroComponent.cpp @@ -224,7 +224,7 @@ void UGBFHeroComponent::ClearAbilityCameraMode( const FGameplayAbilitySpecHandle } } -const TMap< const UGBFInputConfig *, TArray< uint32 > >& UGBFHeroComponent::GetBoundActionsByInputconfig() const +const TMap< const UGBFInputConfig *, TArray< uint32 > > & UGBFHeroComponent::GetBoundActionsByInputconfig() const { return BoundActionsByInputConfig; } diff --git a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h index 4c834b29..3ab32764 100644 --- a/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h +++ b/Source/GameBaseFramework/Public/Animation/GBFAnimNotifyState_InputBuffer.h @@ -25,7 +25,7 @@ class GAMEBASEFRAMEWORK_API UGBFAnimNotifyState_InputBuffer : public UAnimNotify private: UPROPERTY( EditAnywhere ) ETriggerPriority TriggerPriority; - + UPROPERTY( EditAnywhere, Meta = ( Categories = "Input" ) ) FGameplayTagContainer InputTagsToCheck; }; diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h index 1ab0122d..9b3ca45e 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFAbilityInputBufferComponent.h @@ -20,13 +20,13 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent final : public UPawn public: UGBFAbilityInputBufferComponent( const FObjectInitializer & object_initializer ); - + UFUNCTION( BlueprintCallable ) void StartMonitoring( FGameplayTagContainer input_tags_to_check, ETriggerPriority trigger_priority ); UFUNCTION( BlueprintCallable ) void StopMonitoring(); - + #if !UE_BUILD_SHIPPING void TickComponent( float delta_time, ELevelTick tick_type, FActorComponentTickFunction * this_tick_function ) override; #endif @@ -34,22 +34,22 @@ class GAMEBASEFRAMEWORK_API UGBFAbilityInputBufferComponent final : public UPawn protected: UPROPERTY( EditDefaultsOnly ) float MaxMonitoringTime = 5.0f; - + void Reset(); void BindActions(); void RemoveBinds(); void AbilityInputTagPressed( FGameplayTag input_tag ); bool TryToTriggerAbility(); - + FGameplayTag TryToGetInputTagWithPriority(); FGameplayTag GetLastTriggeredInput(); FGameplayTag GetMostTriggeredInput(); ETriggerPriority TriggerPriority; FGameplayTagContainer InputTagsToCheck; - + TArray< FGameplayTag > TriggeredTags; TArray< uint32 > BindHandles; - + float MonitoringTime = 0.0f; }; \ No newline at end of file diff --git a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h index 243eec86..667dafdd 100644 --- a/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h +++ b/Source/GameBaseFramework/Public/Characters/Components/GBFHeroComponent.h @@ -48,7 +48,7 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent /** Clears the camera override if it is set */ void ClearAbilityCameraMode( const FGameplayAbilitySpecHandle & owning_spec_handle ); - const TMap< const UGBFInputConfig *, TArray< uint32 > >& GetBoundActionsByInputconfig() const; + const TMap< const UGBFInputConfig *, TArray< uint32 > > & GetBoundActionsByInputconfig() const; protected: void OnRegister() override;