diff --git a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp index a15e594..f34fc0d 100644 --- a/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp +++ b/Source/UnrealFightingFramework/Input/FFInputBufferComponent.cpp @@ -16,6 +16,13 @@ void UFFInputBufferComponent::AddInput(const FFFInputState& InputState) bool UFFInputBufferComponent::CheckInputSequence(const FFFInputSequence& InputSequence) { + if(InputSequence.Sequence.IsEmpty()) + { + UE_LOG(LogTemp, Error, + TEXT("FFInputBufferComponent :: CheckInputSequence - tried to check input sequence but it was empty")); + return false; + } + int CondIdx = InputSequence.Sequence.Num() - 1; int ElapsedFrames = 0; for(int InpIdx = InputBuffer.Num() - 1; InpIdx > 1; InpIdx--) diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp index 679111c..e98b05a 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.cpp @@ -115,12 +115,14 @@ void UFFStateMachineComponent::GoToState(UFFState* NewState) } } + CurrentState->Exit(GetCurrentStateContext()); - CurrentState = NewState; TicksInState = 0; TickStateWasEntered = GetWorld()->GetGameState()->GetCurrentTick(); CurrentSubStateLabel = NAME_None; - CurrentState->Enter(GetCurrentStateContext()); + NewState->Enter(GetCurrentStateContext()); + OnStateTransition.Broadcast(CurrentState, NewState); + CurrentState = NewState; } void UFFStateMachineComponent::GoToEntryState() @@ -251,6 +253,11 @@ void UFFStateMachineComponent::TickComponent(float DeltaTime, ELevelTick TickTyp SMDebugString.Append(FString::Printf(TEXT("Current State: %s\n"), *CurrentState->Name.ToString())); SMDebugString.Append(FString::Printf(TEXT("Current SubState Label: %s\n"), *CurrentSubStateLabel.ToString())); SMDebugString.Append(FString::Printf(TEXT("Ticks In State: %lld\n"), TicksInState)); + SMDebugString.Append(FString::Printf(TEXT("-- States added --\n"))); + for (auto TempState : States) + { + SMDebugString.Append(FString::Printf(TEXT("%s\n"), *TempState->Name.ToString())); + } GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green, SMDebugString); } diff --git a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h index 52b9c54..d6aae42 100644 --- a/Source/UnrealFightingFramework/State/FFStateMachineComponent.h +++ b/Source/UnrealFightingFramework/State/FFStateMachineComponent.h @@ -12,6 +12,9 @@ #include "FFStateMachineComponent.generated.h" +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnStateTransitionSignature, + const UFFState*, PrevState, const UFFState*, NextState); + /** * A state machine is a component that evaluates and controls the transitions for state objects that * are a part of this state machine. @@ -48,6 +51,9 @@ public: * * @return A pointer to the state that was added or nullptr if there was an issue adding or creating the state */ + // TODO: return should probably be a const pointer if this function is public. I don't want + // anything outside of the state machine modifying the state. Really, I want states in general to + // be read only objects that are only modified at edit time when creating state blueprints. UFFState* AddState(TSubclassOf StateClassToAdd); /** @@ -92,12 +98,18 @@ public: UFUNCTION(BlueprintPure) FORCEINLINE int64 GetTickStateWasEntered() const { return TickStateWasEntered; } + UFUNCTION(BlueprintPure) + const UFFState* GetCurrentState() const { return const_cast(CurrentState); } + /** * Returns the name of the current state */ UFUNCTION(BlueprintPure) FORCEINLINE FName GetCurrentStateName() const; + /** + * Returns the name of the current sub state label + */ UFUNCTION(BlueprintPure) FORCEINLINE FName GetCurrentSubStateLabel() const { return CurrentSubStateLabel; } @@ -115,6 +127,8 @@ public: virtual void MovementModeChanged(EMovementMode PrevMovementMode, uint8 PreviousCustomMode, EMovementMode NewMovementMode, uint8 NewCustomMode); + FOnStateTransitionSignature OnStateTransition; + // IFFSystemInterface interface virtual void FixedTick(float OneFrame) override; // End of IFFSystemInterface interface