Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectRuntime.cpp
yoan stamant 4b56d97931 [SmartObject] added support for GameplayTags on runtime instance
+ SmartObjectComponent acts a bridge to sync tags from the RuntimeInstance and the AbilitySystemComponent (if present on the owning actor)
+ Component streamed out and back it will be bound with their persistent counterpart from the simulation and will synchronize their tags
+ RuntimeInstance and Slot now have a dedicated state when they are disabled when the instance tags don't pass the restrictions defined in the SmartObjectDefinition (ObjectTagFilter)
+ Made a pass to improve consistency in error reporting and methods descriptions
+ Added methods to validate if the object/slot associated to a FSmartObjectClaimHandle and FSmartObjectSlotHandle is still valid when those are stored and not used immediately after a call to any of the 'Find' or 'Claim' methods
#rnx
#rb mikko.mononen
#preflight 6230a0b4e65a7e65d68741e4

#ROBOMERGE-AUTHOR: yoan.stamant
#ROBOMERGE-SOURCE: CL 19386803 via CL 19389419 via CL 19398538 via CL 19398590
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v926-19321884)

[CL 19403765 by yoan stamant in ue5-main branch]
2022-03-16 03:47:02 -04:00

68 lines
2.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SmartObjectRuntime.h"
#include "SmartObjectSubsystem.h"
#include "MassEntitySubsystem.h"
const FSmartObjectClaimHandle FSmartObjectClaimHandle::InvalidHandle = {};
//----------------------------------------------------------------------//
// FSmartObjectRuntime
//----------------------------------------------------------------------//
FSmartObjectRuntime::FSmartObjectRuntime(const USmartObjectDefinition& InDefinition)
: Definition(&InDefinition)
{
const int32 NumSlotDefinitions = InDefinition.GetSlots().Num();
SlotHandles.SetNum(NumSlotDefinitions);
}
//----------------------------------------------------------------------//
// FSmartObjectSlotClaimState
//----------------------------------------------------------------------//
bool FSmartObjectSlotClaimState::Claim(const FSmartObjectUserHandle& InUser)
{
if (State == ESmartObjectSlotState::Free)
{
State = ESmartObjectSlotState::Claimed;
User = InUser;
return true;
}
return false;
}
bool FSmartObjectSlotClaimState::Release(const FSmartObjectClaimHandle& ClaimHandle, const ESmartObjectSlotState NewState, 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 = NewState;
User.Reset();
bReleased = true;
}
return bReleased;
}