Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectRuntime.cpp
bob tellez 09e68111e3 [Backout] - CL23741166
[FYI] Yoan.StAmant
Original CL Desc
-----------------------------------------------------------------
[SmartObjects]
- Removed synchronization logic between ability system component and smartobject instance tags.
- Added SmartObject subsystem to the SmartObjectWorldConditionSchema to help fixing unit tests where we use a derived subsystem. Updated existing SmartObject world conditions to use it.
- Added support for world conditions to the main smart object instance (in addition to those in each slot). Slots could be also disabled by their parent conditions.
- Removed object tags filter from the definition and replaced it by the newly added condition (FWorldCondition_SmartObjectActorTagQuery)
#rb mikko.mononen
#preflight 63c6c3530b358b97d198a121

[CL 23752170 by bob tellez in ue5-main branch]
2023-01-18 01:06:45 -05:00

72 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SmartObjectRuntime.h"
#include "SmartObjectSubsystem.h"
#include "MassEntityManager.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);
}
//----------------------------------------------------------------------//
// FSmartObjectRuntimeSlot
//----------------------------------------------------------------------//
bool FSmartObjectRuntimeSlot::Claim(const FSmartObjectUserHandle& InUser)
{
if (bEnabled && State == ESmartObjectSlotState::Free)
{
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();
bReleased = true;
}
return bReleased;
}