Files
UnrealEngineUWP/Engine/Plugins/Runtime/SmartObjects/Source/SmartObjectsModule/Private/SmartObjectRuntime.cpp
yoan stamant 04214fbc78 [SmartObject] allow custom definitions (FSmartObjectSlotDefinitionData) and transient state data (FSmartObjectSlotStateData) per slot using MassEntity
+ replaced all methods Describe by LexToString
+ unified naming from "*ID" to *Handle
#preflight 61e85d121000e8c59a78c886
#rb mikko.mononen

#ROBOMERGE-AUTHOR: yoan.stamant
#ROBOMERGE-SOURCE: CL 18662203 in //UE5/Release-5.0/... via CL 18662234 via CL 18662264
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v900-18638592)

[CL 18662291 by yoan stamant in ue5-main branch]
2022-01-19 14:16:16 -05:00

69 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)
, SharedOctreeID(MakeShareable(new FSmartObjectOctreeID()))
{
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 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.Reset();
bReleased = true;
}
return bReleased;
}