This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Fix player movement when on zoned servers #1235
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -769,6 +769,13 @@ int32 USpatialNetDriver::ServerReplicateActors_PrepConnections(const float Delta | |
|
||
int32 USpatialNetDriver::ServerReplicateActors_PrioritizeActors(UNetConnection* InConnection, const TArray<FNetViewer>& ConnectionViewers, const TArray<FNetworkObjectInfo*> ConsiderList, const bool bCPUSaturated, FActorPriority*& OutPriorityList, FActorPriority**& OutPriorityActors) | ||
{ | ||
// Since this function signature is copied from NetworkDriver.cpp, I don't want to change the signature. But we expect | ||
// that the input connection will be the SpatialOS server connection to the runtime (the first client connection), | ||
// so let's make sure that assumption continues to hold. | ||
check(InConnection != nullptr); | ||
check(GetSpatialOSNetConnection() != nullptr); | ||
check(InConnection == GetSpatialOSNetConnection()); | ||
|
||
// Get list of visible/relevant actors. | ||
|
||
NetTag++; | ||
|
@@ -865,6 +872,13 @@ int32 USpatialNetDriver::ServerReplicateActors_PrioritizeActors(UNetConnection* | |
|
||
void USpatialNetDriver::ServerReplicateActors_ProcessPrioritizedActors(UNetConnection* InConnection, const TArray<FNetViewer>& ConnectionViewers, FActorPriority** PriorityActors, const int32 FinalSortedCount, int32& OutUpdated) | ||
{ | ||
// Since this function signature is copied from NetworkDriver.cpp, I don't want to change the signature. But we expect | ||
// that the input connection will be the SpatialOS server connection to the runtime (the first client connection), | ||
// so let's make sure that assumption continues to hold. | ||
check(InConnection != nullptr); | ||
check(GetSpatialOSNetConnection() != nullptr); | ||
check(InConnection == GetSpatialOSNetConnection()); | ||
|
||
// SpatialGDK - Here Unreal would check if the InConnection was saturated (!IsNetReady) and early out. Removed this as we do not currently use channel saturation. | ||
|
||
int32 ActorUpdatesThisConnection = 0; | ||
|
@@ -977,7 +991,7 @@ void USpatialNetDriver::ServerReplicateActors_ProcessPrioritizedActors(UNetConne | |
continue; | ||
} | ||
|
||
Channel = CreateSpatialActorChannel(Actor, Cast<USpatialNetConnection>(InConnection)); | ||
Channel = GetOrCreateSpatialActorChannel(Actor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the change that fixes the root cause. |
||
if ((Channel == nullptr) && (Actor->NetUpdateFrequency < 1.0f)) | ||
{ | ||
UE_LOG(LogNetTraffic, Log, TEXT("Unable to replicate %s"), *Actor->GetName()); | ||
|
@@ -1096,11 +1110,14 @@ int32 USpatialNetDriver::ServerReplicateActors(float DeltaSeconds) | |
SCOPE_CYCLE_COUNTER(STAT_SpatialServerReplicateActors); | ||
|
||
#if WITH_SERVER_CODE | ||
if (ClientConnections.Num() == 0) | ||
// Only process the stand-in client connection, which is the connection to the runtime itself. | ||
// It will be responsible for replicating all actors, regardless of whether they're owned by a client. | ||
USpatialNetConnection* SpatialConnection = GetSpatialOSNetConnection(); | ||
if (SpatialConnection == nullptr) | ||
{ | ||
return 0; | ||
} | ||
|
||
check(SpatialConnection && SpatialConnection->bReliableSpatialConnection); | ||
check(World); | ||
|
||
int32 Updated = 0; | ||
|
@@ -1143,10 +1160,6 @@ int32 USpatialNetDriver::ServerReplicateActors(float DeltaSeconds) | |
|
||
FMemMark Mark(FMemStack::Get()); | ||
|
||
// Only process the fake spatial connection. It will be responsible for replicating all actors, regardless of whether they're owned by a client. | ||
USpatialNetConnection* SpatialConnection = Cast<USpatialNetConnection>(ClientConnections[0]); | ||
check(SpatialConnection && SpatialConnection->bReliableSpatialConnection); | ||
|
||
// Make a list of viewers this connection should consider | ||
TArray<FNetViewer>& ConnectionViewers = WorldSettings->ReplicationViewers; | ||
|
||
|
@@ -1327,7 +1340,7 @@ void USpatialNetDriver::TickFlush(float DeltaTime) | |
double ServerReplicateActorsTimeMs = 0.0f; | ||
#endif // USE_SERVER_PERF_COUNTERS | ||
|
||
if (IsServer() && ClientConnections.Num() > 0 && EntityPool->IsReady()) | ||
if (IsServer() && GetSpatialOSNetConnection() != nullptr && EntityPool->IsReady()) | ||
{ | ||
// Update all clients. | ||
#if WITH_SERVER_CODE | ||
|
@@ -1673,7 +1686,7 @@ USpatialActorChannel* USpatialNetDriver::GetOrCreateSpatialActorChannel(UObject* | |
TargetActor = Cast<AActor>(TargetObject->GetOuter()); | ||
} | ||
check(TargetActor); | ||
Channel = CreateSpatialActorChannel(TargetActor, GetSpatialOSNetConnection()); | ||
Channel = CreateSpatialActorChannel(TargetActor); | ||
} | ||
return Channel; | ||
} | ||
|
@@ -1683,27 +1696,34 @@ USpatialActorChannel* USpatialNetDriver::GetActorChannelByEntityId(Worker_Entity | |
return EntityToActorChannel.FindRef(EntityId); | ||
} | ||
|
||
USpatialActorChannel* USpatialNetDriver::CreateSpatialActorChannel(AActor* Actor, USpatialNetConnection* InConnection) | ||
USpatialActorChannel* USpatialNetDriver::CreateSpatialActorChannel(AActor* Actor) | ||
{ | ||
if (InConnection == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
// This should only be called from GetOrCreateSpatialActorChannel, otherwise we could end up clobbering an existing channel. | ||
m-samiec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
USpatialActorChannel* Channel = nullptr; | ||
check(Actor != nullptr); | ||
check(PackageMap != nullptr); | ||
check(GetActorChannelByEntityId(PackageMap->GetEntityIdFromObject(Actor)) == nullptr); | ||
|
||
USpatialNetConnection* NetConnection = GetSpatialOSNetConnection(); | ||
check(NetConnection != nullptr); | ||
|
||
USpatialActorChannel* Channel = nullptr; | ||
if (Actor->GetClass()->HasAnySpatialClassFlags(SPATIALCLASS_Singleton)) | ||
{ | ||
Channel = GlobalStateManager->AddSingleton(Actor); | ||
} | ||
else | ||
{ | ||
#if ENGINE_MINOR_VERSION <= 20 | ||
Channel = static_cast<USpatialActorChannel*>(InConnection->CreateChannel(CHTYPE_Actor, 1)); | ||
Channel = static_cast<USpatialActorChannel*>(NetConnection->CreateChannel(CHTYPE_Actor, 1)); | ||
#else | ||
Channel = static_cast<USpatialActorChannel*>(InConnection->CreateChannelByName(NAME_Actor, EChannelCreateFlags::OpenedLocally)); | ||
Channel = static_cast<USpatialActorChannel*>(NetConnection->CreateChannelByName(NAME_Actor, EChannelCreateFlags::OpenedLocally)); | ||
#endif | ||
if (Channel != nullptr) | ||
if (Channel == nullptr) | ||
{ | ||
UE_LOG(LogSpatialOSNetDriver, Warning, TEXT("Failed to create a channel for actor %s."), *GetNameSafe(Actor)); | ||
} | ||
else | ||
{ | ||
Channel->SetChannelActor(Actor); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍