Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Queue RPCs by Worker_EntityId (#1138)
Browse files Browse the repository at this point in the history
* Queue RPCs by Worker_EntityId

* Apply suggestions from code review

Co-Authored-By: improbable-valentyn <32096431+improbable-valentyn@users.noreply.github.com>

* Changed Worker_EntityId to Worker_EntityId_Key for Linux compilation. Fixed function signature

* Moved initialisation inside if statements
  • Loading branch information
aleximprobable authored Jul 9, 2019
1 parent 4cc2d1e commit 9396e73
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ void USpatialReceiver::HandleRPC(const Worker_ComponentUpdateOp& Op)
UFunction* Function = ClassInfo.RPCs[Payload.Index];
const FRPCInfo& RPCInfo = ClassInfoManager->GetRPCInfo(TargetObject, Function);

if (!IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef, RPCInfo.Type)
&& !IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef, ESchemaComponentType::SCHEMA_Invalid))
if (!IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef.Entity, RPCInfo.Type)
&& !IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef.Entity, ESchemaComponentType::SCHEMA_Invalid))
{
// Apply if possible, queue otherwise
if (ApplyRPC(*Params))
Expand Down Expand Up @@ -1642,8 +1642,8 @@ void USpatialReceiver::ProcessQueuedActorRPCsOnEntityCreation(AActor* Actor, RPC
const FUnrealObjectRef ObjectRef = PackageMap->GetUnrealObjectRefFromObject(Actor);
check(ObjectRef != FUnrealObjectRef::UNRESOLVED_OBJECT_REF);

if (!IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef, RPCInfo.Type)
&& !IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef, ESchemaComponentType::SCHEMA_Invalid))
if (!IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef.Entity, RPCInfo.Type)
&& !IncomingRPCs.ObjectHasRPCsQueuedOfType(ObjectRef.Entity, ESchemaComponentType::SCHEMA_Invalid))
{
if (ApplyRPC(Actor, Function, RPC, FString()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ void USpatialSender::ProcessRPC(FPendingRPCParamsPtr Params)
const FRPCInfo& RPCInfo = ClassInfoManager->GetRPCInfo(TargetObject.Get(), Function);

bool bRPCProcessed = false;
if (!OutgoingRPCs.ObjectHasRPCsQueuedOfType(Params->ObjectRef, RPCInfo.Type))
if (!OutgoingRPCs.ObjectHasRPCsQueuedOfType(Params->ObjectRef.Entity, RPCInfo.Type))
{
if (SendRPC(*Params))
{
Expand Down
10 changes: 4 additions & 6 deletions SpatialGDK/Source/SpatialGDK/Private/Utils/RPCContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FPendingRPCParams::FPendingRPCParams(const FUnrealObjectRef& InTargetObjectRef,

void FRPCContainer::QueueRPC(FPendingRPCParamsPtr Params, ESchemaComponentType Type)
{
FArrayOfParams& ArrayOfParams = QueuedRPCs.FindOrAdd(Type).FindOrAdd(Params->ObjectRef);
FArrayOfParams& ArrayOfParams = QueuedRPCs.FindOrAdd(Type).FindOrAdd(Params->ObjectRef.Entity);
ArrayOfParams.Push(MoveTemp(Params));
}

Expand Down Expand Up @@ -54,13 +54,11 @@ void FRPCContainer::ProcessRPCs(const FProcessRPCDelegate& FunctionToApply)
}
}

bool FRPCContainer::ObjectHasRPCsQueuedOfType(const FUnrealObjectRef& TargetObjectRef, ESchemaComponentType Type) const
bool FRPCContainer::ObjectHasRPCsQueuedOfType(const Worker_EntityId& EntityId, ESchemaComponentType Type) const
{
const FRPCMap* MapOfQueues = QueuedRPCs.Find(Type);
if(MapOfQueues)
if(const FRPCMap* MapOfQueues = QueuedRPCs.Find(Type))
{
const FArrayOfParams* RPCList = MapOfQueues->Find(TargetObjectRef);
if(RPCList)
if(const FArrayOfParams* RPCList = MapOfQueues->Find(EntityId))
{
return (RPCList->Num() > 0);
}
Expand Down
4 changes: 2 additions & 2 deletions SpatialGDK/Source/SpatialGDK/Public/Utils/RPCContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class FRPCContainer
public:
void QueueRPC(FPendingRPCParamsPtr Params, ESchemaComponentType Type);
void ProcessRPCs(const FProcessRPCDelegate& FunctionToApply);
bool ObjectHasRPCsQueuedOfType(const FUnrealObjectRef& TargetObjectRef, ESchemaComponentType Type) const;
bool ObjectHasRPCsQueuedOfType(const Worker_EntityId& EntityId, ESchemaComponentType Type) const;

private:
using FArrayOfParams = TArray<FPendingRPCParamsPtr>;
using FRPCMap = TMap<FUnrealObjectRef, FArrayOfParams>;
using FRPCMap = TMap<Worker_EntityId_Key, FArrayOfParams>;
using RPCContainerType = TMap<ESchemaComponentType, FRPCMap>;

void ProcessRPCs(const FProcessRPCDelegate& FunctionToApply, FArrayOfParams& RPCList);
Expand Down

0 comments on commit 9396e73

Please sign in to comment.