Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectRuntime.cpp
yoan stamant adf6cb0a20 [SmartObjects]
- Added new methods to the API to filter a list of request results or slot handles by evaluating the selection preconditions
- Filter methods can accept external data as a struct with properties which name and type match the WolrdConditionContext.
- FSmartObjectUserContext has been introduced to cover the common case of passing in a user actor to the context.
- Stored UserDescriptor as instanced struct in the runtime slot
- Claim methods now receive a user descriptor
- Removed slot event delegate and reuse the runtime instance one instead. Listeners can filter for a given slot using 'Event.SlotHandle'
- Removed UserTags from the SmartObjectWorldConditionSchema. The user tags are part of the query filter. Conditions requiring user tags could fetch them from the actors passed in the context.
#rb mikko.mononen
#jira UE-157763
#preflight 63dbe99f797b029c0add9806

[CL 23984054 by yoan stamant in ue5-main branch]
2023-02-02 18:43:13 -05:00

79 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SmartObjectRuntime.h"
#include "SmartObjectComponent.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(SmartObjectRuntime)
const FSmartObjectClaimHandle FSmartObjectClaimHandle::InvalidHandle = {};
//----------------------------------------------------------------------//
// FSmartObjectRuntime
//----------------------------------------------------------------------//
FSmartObjectRuntime::FSmartObjectRuntime(const USmartObjectDefinition& InDefinition)
: Definition(&InDefinition)
, bEnabled(true)
{
const int32 NumSlotDefinitions = InDefinition.GetSlots().Num();
SlotHandles.SetNum(NumSlotDefinitions);
}
AActor* FSmartObjectRuntime::GetOwnerActor() const
{
USmartObjectComponent* Component = OwnerComponent.Get();
return Component != nullptr ? Component->GetOwner() : nullptr;
}
//----------------------------------------------------------------------//
// FSmartObjectRuntimeSlot
//----------------------------------------------------------------------//
bool FSmartObjectRuntimeSlot::Claim(const FSmartObjectUserHandle& InUser)
{
if (CanBeClaimed())
{
State = ESmartObjectSlotState::Claimed;
User = InUser;
return true;
}
return false;
}
bool FSmartObjectRuntimeSlot::Release(const FSmartObjectClaimHandle& ClaimHandle, const bool bAborted)
{
if (!ensureMsgf(ClaimHandle.IsValid(), TEXT("Attempting to release a slot using an invalid handle: %s"), *LexToString(ClaimHandle)))
{
return false;
}
bool bReleased = false;
if (State != ESmartObjectSlotState::Claimed && State != ESmartObjectSlotState::Occupied)
{
UE_LOG(LogSmartObject, Error, TEXT("Expected slot state is 'Claimed' or 'Occupied' but current state is '%s'. Slot will not be released"),
*UEnum::GetValueAsString(State));
}
else if (ClaimHandle.UserHandle != User)
{
UE_LOG(LogSmartObject, Error, TEXT("User '%s' is trying to release slot claimed or used by other user '%s'. Slot will not be released"),
*LexToString(ClaimHandle.UserHandle), *LexToString(User));
}
else
{
if (bAborted)
{
const bool bFunctionWasExecuted = OnSlotInvalidatedDelegate.ExecuteIfBound(ClaimHandle, State);
UE_LOG(LogSmartObject, Verbose, TEXT("Slot invalidated callback was%scalled for %s"), bFunctionWasExecuted ? TEXT(" ") : TEXT(" not "), *LexToString(ClaimHandle));
}
State = ESmartObjectSlotState::Free;
User.Invalidate();
UserData.Reset();
bReleased = true;
}
return bReleased;
}