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

Commit

Permalink
Actor Replication Net Relevancy (#1348)
Browse files Browse the repository at this point in the history
* Added Net Relevancy check to actor replication prioritization

* Addressing PR Comments

* Update Comments

* Update CHANGELOG.md

* PR Comments

* Update SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h

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

* Update SpatialNetDriver.cpp
  • Loading branch information
jnicholas-io authored Sep 17, 2019
1 parent 54e669c commit 7d101df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Visual Studio 2019 is now supported.
- Added toolbar and commandlet options to delete the schema database.
- Added a check for schema and snapshot before attempting to start a local deployment. If either are missing then an error message will be displayed.
- Added optional net relevancy check in replication prioritization. If enabled, an actor will only be replicated if IsNetRelevantFor is true for one of the connected client's views.

### Bug fixes:
- Fixed an issue that could cause multiple Channels to be created for an Actor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,24 @@ void USpatialNetDriver::OnOwnerUpdated(AActor* Actor)
#if WITH_SERVER_CODE

// Returns true if this actor should replicate to *any* of the passed in connections
static FORCEINLINE_DEBUGGABLE bool IsActorRelevantToConnection(const AActor* Actor, const TArray<FNetViewer>& ConnectionViewers)
static FORCEINLINE_DEBUGGABLE bool IsActorRelevantToConnection(const AActor* Actor, UActorChannel* ActorChannel, const TArray<FNetViewer>& ConnectionViewers)
{
// SpatialGDK: Currently we're just returning true as a worker replicates all the known actors in our design.
// We might make some exceptions in the future, so keeping this function.
// TODO: UNR-837 Start using IsNetRelevantFor again for relevancy checks rather than returning true.
return true;
// An actor without a channel yet will need to be replicated at least
// once to have a channel and entity created for it
if (ActorChannel == nullptr)
{
return true;
}

for (const auto& Viewer : ConnectionViewers)
{
if (Actor->IsNetRelevantFor(Viewer.InViewer, Viewer.ViewTarget, Viewer.ViewLocation))
{
return true;
}
}

return false;
}

// Returns true if this actor is considered dormant (and all properties caught up) to the current connection
Expand Down Expand Up @@ -803,6 +815,8 @@ int32 USpatialNetDriver::ServerReplicateActors_PrioritizeActors(UNetConnection*
AGameNetworkManager* const NetworkManager = World->NetworkManager;
const bool bLowNetBandwidth = NetworkManager ? NetworkManager->IsInLowBandwidthMode() : false;

const bool bNetRelevancyEnabled = GetDefault<USpatialGDKSettings>()->UseIsActorRelevantForConnection;

for (FNetworkObjectInfo* ActorInfo : ConsiderList)
{
AActor* Actor = ActorInfo->Actor;
Expand All @@ -826,12 +840,10 @@ int32 USpatialNetDriver::ServerReplicateActors_PrioritizeActors(UNetConnection*

UE_LOG(LogSpatialOSNetDriver, Verbose, TEXT("Actor %s will be replicated on the catch-all connection"), *Actor->GetName());

// SpatialGDK: Here, Unreal does initial relevancy checking and level load checking.
// We have removed the level load check because it doesn't apply.
// Relevancy checking is also mostly just a pass through, might be removed later.
if (!IsActorRelevantToConnection(Actor, ConnectionViewers))
// Check actor relevancy if Net Relevancy is enabled in the GDK settings
if (bNetRelevancyEnabled && !IsActorRelevantToConnection(Actor, Channel, ConnectionViewers))
{
// If not relevant (and we don't have a channel), skip
// Early out and do not replicate if actor is not relevant
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ USpatialGDKSettings::USpatialGDKSettings(const FObjectInitializer& ObjectInitial
, HeartbeatTimeoutSeconds(10.0f)
, ActorReplicationRateLimit(0)
, EntityCreationRateLimit(0)
, UseIsActorRelevantForConnection(false)
, OpsUpdateRate(1000.0f)
, bEnableHandover(true)
, MaxNetCullDistanceSquared(900000000.0f) // Set to twice the default Actor NetCullDistanceSquared (300m)
Expand Down
7 changes: 7 additions & 0 deletions SpatialGDK/Source/SpatialGDK/Public/SpatialGDKSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class SPATIALGDK_API USpatialGDKSettings : public UObject
UPROPERTY(EditAnywhere, config, Category = "Replication", meta = (ConfigRestartRequired = false, DisplayName = "Maximum entities created per tick"))
uint32 EntityCreationRateLimit;

/**
* When enabled, only entities which are in the net relevancy range of player controllers will be replicated to SpatialOS.
* This should only be used in single server configurations. The state of the world in the inspector will no longer be up to date.
*/
UPROPERTY(EditAnywhere, config, Category = "Replication", meta = (ConfigRestartRequired = false, DisplayName = "Only Replicate Net Relevant Actors"))
bool UseIsActorRelevantForConnection;

/**
* Specifies the rate, in number of times per second, at which server-worker instance updates are sent to and received from the SpatialOS Runtime.
* Default:1000/s
Expand Down

0 comments on commit 7d101df

Please sign in to comment.