From 901ac37cacb4cd1415926d7390548a2f50036485 Mon Sep 17 00:00:00 2001 From: Ben Naccarato Date: Mon, 13 May 2019 18:50:07 +0100 Subject: [PATCH 01/10] Uncomment out build linux worker --- BuildProject.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BuildProject.bat b/BuildProject.bat index f27b65b6..57b129aa 100644 --- a/BuildProject.bat +++ b/BuildProject.bat @@ -1,6 +1,6 @@ @echo off call "%~dp0ProjectPaths.bat" -:: call %~dp0%PROJECT_PATH%\"Plugins/UnrealGDK/SpatialGDK/Build/Scripts/BuildWorker.bat" %GAME_NAME%Server Linux Development %GAME_NAME%.uproject || goto :error +call %~dp0%PROJECT_PATH%\"Plugins/UnrealGDK/SpatialGDK/Build/Scripts/BuildWorker.bat" %GAME_NAME%Server Linux Development %GAME_NAME%.uproject || goto :error call %~dp0%PROJECT_PATH%\"Plugins/UnrealGDK/SpatialGDK/Build/Scripts/BuildWorker.bat" %GAME_NAME% Win64 Development %GAME_NAME%.uproject || goto :error echo All builds succeeded. From 79c79936d594558d8759fb837bba1275553e079f Mon Sep 17 00:00:00 2001 From: Michael Samiec Date: Fri, 17 May 2019 12:23:30 +0200 Subject: [PATCH 02/10] Feature/zoned worker spike (#6) * Fixes for zoned workers * Removed hardcoded path from DefaultSpatialGDKEditorSettings * Switch replicated to handover * Switch chunk interest off --- Game/Config/DefaultSpatialGDKEditorSettings.ini | 9 +++++++++ .../GDKShooter/Private/Characters/Core/GDKCharacter.cpp | 9 +++++---- .../Private/Characters/Core/GDKShooterCharacter.cpp | 6 +++++- Game/Source/GDKShooter/Private/Weapons/Projectile.cpp | 8 ++++---- Game/Source/GDKShooter/Public/Weapons/Projectile.h | 2 ++ 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 Game/Config/DefaultSpatialGDKEditorSettings.ini diff --git a/Game/Config/DefaultSpatialGDKEditorSettings.ini b/Game/Config/DefaultSpatialGDKEditorSettings.ini new file mode 100644 index 00000000..020d6761 --- /dev/null +++ b/Game/Config/DefaultSpatialGDKEditorSettings.ini @@ -0,0 +1,9 @@ + +[/Script/SpatialGDKEditor.SpatialGDKEditorSettings] +bDeleteDynamicEntities=True +bGenerateDefaultLaunchConfig=True +bStopSpatialOnExit=False +SpatialOSSnapshotFile=default.snapshot +LaunchConfigDesc=(Template="small",World=(Dimensions=(X=2000,Y=2000),ChunkEdgeLengthMeters=5,StreamingQueryIntervalSeconds=4,SnapshotWritePeriodSeconds=0,LegacyFlags=(("bridge_qos_max_timeout", "0"),("bridge_soft_handover_enabled", "false"),("enable_chunk_interest", "false")),LegacyJavaParams=()),Workers=((WorkerTypeName="UnrealWorker",Columns=2))) +bGeneratePlaceholderEntitiesInSnapshot=True + diff --git a/Game/Source/GDKShooter/Private/Characters/Core/GDKCharacter.cpp b/Game/Source/GDKShooter/Private/Characters/Core/GDKCharacter.cpp index 9380bb7e..2cac8ed5 100644 --- a/Game/Source/GDKShooter/Private/Characters/Core/GDKCharacter.cpp +++ b/Game/Source/GDKShooter/Private/Characters/Core/GDKCharacter.cpp @@ -195,10 +195,7 @@ void AGDKCharacter::RegenerateHealth() float AGDKCharacter::TakeDamage(float Damage, const FDamageEvent& DamageEvent, AController* EventInstigator, AActor* DamageCauser) { - - float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); - - TakeDamageCrossServer(ActualDamage, DamageEvent, EventInstigator, DamageCauser); + TakeDamageCrossServer(Damage, DamageEvent, EventInstigator, DamageCauser); return Damage; } @@ -210,6 +207,10 @@ void AGDKCharacter::TakeDamageCrossServer_Implementation(float Damage, const FDa return; } + check(DamageCauser); + + Damage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); + const AWeapon* DamageSourceWeapon = Cast(DamageCauser); const AGDKCharacter* Killer = Cast(DamageSourceWeapon->GetWeilder()); diff --git a/Game/Source/GDKShooter/Private/Characters/Core/GDKShooterCharacter.cpp b/Game/Source/GDKShooter/Private/Characters/Core/GDKShooterCharacter.cpp index 37d59ee1..ab650d01 100644 --- a/Game/Source/GDKShooter/Private/Characters/Core/GDKShooterCharacter.cpp +++ b/Game/Source/GDKShooter/Private/Characters/Core/GDKShooterCharacter.cpp @@ -248,7 +248,11 @@ void AGDKShooterCharacter::EquipWeapon_Implementation(int32 WeaponId) EquippedWeapon->SetIsActive(false); EquippedWeapon = AvailableWeapons[WeaponId]; - EquippedWeapon->SetIsActive(true); + + if (EquippedWeapon != nullptr) + { + EquippedWeapon->SetIsActive(true); + } } diff --git a/Game/Source/GDKShooter/Private/Weapons/Projectile.cpp b/Game/Source/GDKShooter/Private/Weapons/Projectile.cpp index c8cd1ad6..f252bf1d 100644 --- a/Game/Source/GDKShooter/Private/Weapons/Projectile.cpp +++ b/Game/Source/GDKShooter/Private/Weapons/Projectile.cpp @@ -80,7 +80,7 @@ void AProjectile::OnRep_MetaData() void AProjectile::Tick(float DeltaTime) { - if (GetNetMode() == NM_Client) + if (!HasAuthority()) { return; } @@ -95,7 +95,7 @@ void AProjectile::Tick(float DeltaTime) void AProjectile::OnStop(const FHitResult& ImpactResult) { - if (GetNetMode() == NM_Client) + if (!HasAuthority()) { return; } @@ -108,7 +108,7 @@ void AProjectile::OnStop(const FHitResult& ImpactResult) void AProjectile::OnBounce(const FHitResult& ImpactResult, const FVector& ImpactVelocity) { - if (GetNetMode() == NM_Client) + if (!HasAuthority()) { return; } @@ -133,7 +133,7 @@ void AProjectile::ExplosionVisuals_Implementation() void AProjectile::Explode() { - if (GetNetMode() == NM_Client) + if (!HasAuthority()) { return; } diff --git a/Game/Source/GDKShooter/Public/Weapons/Projectile.h b/Game/Source/GDKShooter/Public/Weapons/Projectile.h index 74ee0937..3cec7f88 100644 --- a/Game/Source/GDKShooter/Public/Weapons/Projectile.h +++ b/Game/Source/GDKShooter/Public/Weapons/Projectile.h @@ -75,8 +75,10 @@ class GDKSHOOTER_API AProjectile : public AActor UFUNCTION(BlueprintNativeEvent) void ExplosionVisuals(); + UPROPERTY(Handover) AController* InstigatingController; + UPROPERTY(Handover) AWeapon* InstigatingWeapon; UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = Projectile) From 6181182fb4d7b7b6822cc553b33613906f07e428 Mon Sep 17 00:00:00 2001 From: Ieva Vasiljeva Date: Wed, 29 May 2019 17:09:52 +0100 Subject: [PATCH 03/10] Check authority before making session state updates. --- .../Private/Game/GDKSessionGameState.cpp | 39 +++++++++++++++---- .../Public/Game/GDKSessionGameState.h | 6 +++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index 0ca88a0f..ba970331 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -6,6 +6,7 @@ #include "UnrealNetwork.h" #include "SpatialNetDriver.h" #include "SpatialWorkerConnection.h" +#include "Interop/SpatialStaticComponentView.h" #include "c_worker.h" #include "c_schema.h" @@ -44,6 +45,15 @@ void AGDKSessionGameState::RemovePlayerState(APlayerState* PlayerState) void AGDKSessionGameState::OnRep_SessionProgress() { + USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); + bool AuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + + if (AuthoritativeOverSessionEntity) + { + // There's an offset of 1 between the corresponding states of session progress and session state. + int SessionState = (int)SessionProgress + 1; + SendStateUpdate(SessionState); + } TimerEvent.Broadcast(SessionProgress, SessionTimer); } @@ -64,29 +74,43 @@ void AGDKSessionGameState::BeginTimer() void AGDKSessionGameState::TickGameTimer() { - if (GetNetMode() != NM_Client) + bool AuthoritativeOverSessionProgress = Role == ROLE_Authority; + + if (GetNetMode() != NM_Client && AuthoritativeOverSessionProgress) { SessionTimer--; + USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); + bool AuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + if (SessionProgress == EGDKSessionProgress::Lobby && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Running")); SessionProgress = EGDKSessionProgress::Running; - SendStateUpdate(2); + if (AuthoritativeOverSessionEntity) + { + SendStateUpdate(2); + } SessionTimer = GameSessionLength; } if (SessionProgress == EGDKSessionProgress::Running && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Results")); SessionProgress = EGDKSessionProgress::Results; - SendStateUpdate(3); + if (AuthoritativeOverSessionEntity) + { + SendStateUpdate(3); + } SessionTimer = ResultsSessionLength; } if (SessionProgress == EGDKSessionProgress::Results && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Finished")); SessionProgress = EGDKSessionProgress::Finished; - SendStateUpdate(4); + if (AuthoritativeOverSessionEntity) + { + SendStateUpdate(4); + } } } } @@ -98,13 +122,14 @@ void AGDKSessionGameState::SendStateUpdate(int NewState) return; } - Worker_EntityId target_entity_id = 39; + Worker_EntityId target_entity_id = SessionEntityId; Worker_ComponentUpdate component_update = {}; - component_update.component_id = 1000; - component_update.schema_type = Schema_CreateComponentUpdate(1000); + component_update.component_id = SessionComponentId; + component_update.schema_type = Schema_CreateComponentUpdate(SessionComponentId); Schema_Object* fields_object = Schema_GetComponentUpdateFields(component_update.schema_type); Schema_AddInt32(fields_object, 1, NewState); Cast(GetWorld()->GetNetDriver())->Connection->SendComponentUpdate(target_entity_id, &component_update); + UE_LOG(LogGDK, Warning, TEXT("Sending update for session component. State: %i; worker authority: %i"), NewState, Role.GetValue()); } diff --git a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h index ff8f80e2..e243f23b 100644 --- a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h +++ b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h @@ -6,6 +6,9 @@ #include "GDKLogging.h" #include "Game/GDKGameState.h" #include "GDKSessionProgress.h" + +#include + #include "GDKSessionGameState.generated.h" DECLARE_EVENT_TwoParams(AGDKGameState, FSessionTimerEvent, EGDKSessionProgress, int); @@ -42,6 +45,9 @@ class GDKSHOOTER_API AGDKSessionGameState : public AGDKGameState UPROPERTY(EditAnywhere, Category = "Timers") int ResultsSessionLength = 60; + + Worker_EntityId SessionEntityId = 39; + Worker_ComponentId SessionComponentId = 1000; FTimerHandle TickTimer; From 3243f98a8a40a7b0f34fa7e70ed1ef620cbc717b Mon Sep 17 00:00:00 2001 From: Ieva Vasiljeva Date: Fri, 31 May 2019 13:47:08 +0100 Subject: [PATCH 04/10] Clean up imports and variable names. --- .../Private/Game/GDKSessionGameState.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index ba970331..0bb1877c 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -2,14 +2,14 @@ #include "GDKSessionGameState.h" +#include "Interop/SpatialStaticComponentView.h" #include "TimerManager.h" #include "UnrealNetwork.h" #include "SpatialNetDriver.h" #include "SpatialWorkerConnection.h" -#include "Interop/SpatialStaticComponentView.h" -#include "c_worker.h" -#include "c_schema.h" +#include +#include void AGDKSessionGameState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { @@ -46,9 +46,9 @@ void AGDKSessionGameState::RemovePlayerState(APlayerState* PlayerState) void AGDKSessionGameState::OnRep_SessionProgress() { USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); - bool AuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); - if (AuthoritativeOverSessionEntity) + if (bAuthoritativeOverSessionEntity) { // There's an offset of 1 between the corresponding states of session progress and session state. int SessionState = (int)SessionProgress + 1; @@ -74,20 +74,20 @@ void AGDKSessionGameState::BeginTimer() void AGDKSessionGameState::TickGameTimer() { - bool AuthoritativeOverSessionProgress = Role == ROLE_Authority; + const bool bAuthoritativeOverSessionProgress = HasAuthority(); - if (GetNetMode() != NM_Client && AuthoritativeOverSessionProgress) + if (GetNetMode() != NM_Client && bAuthoritativeOverSessionProgress) { SessionTimer--; USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); - bool AuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); if (SessionProgress == EGDKSessionProgress::Lobby && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Running")); SessionProgress = EGDKSessionProgress::Running; - if (AuthoritativeOverSessionEntity) + if (bAuthoritativeOverSessionEntity) { SendStateUpdate(2); } @@ -97,7 +97,7 @@ void AGDKSessionGameState::TickGameTimer() { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Results")); SessionProgress = EGDKSessionProgress::Results; - if (AuthoritativeOverSessionEntity) + if (bAuthoritativeOverSessionEntity) { SendStateUpdate(3); } @@ -107,7 +107,7 @@ void AGDKSessionGameState::TickGameTimer() { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Finished")); SessionProgress = EGDKSessionProgress::Finished; - if (AuthoritativeOverSessionEntity) + if (bAuthoritativeOverSessionEntity) { SendStateUpdate(4); } From eab326798c8e353856b86d65937e4bebda7627ce Mon Sep 17 00:00:00 2001 From: Ieva Vasiljeva Date: Fri, 31 May 2019 14:23:09 +0100 Subject: [PATCH 05/10] Slight refactor to when the offset between session progress and session game state is applied. --- .../Private/Game/GDKSessionGameState.cpp | 18 +++++++++--------- .../Public/Game/GDKSessionGameState.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index 0bb1877c..6e9f989c 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -50,9 +50,7 @@ void AGDKSessionGameState::OnRep_SessionProgress() if (bAuthoritativeOverSessionEntity) { - // There's an offset of 1 between the corresponding states of session progress and session state. - int SessionState = (int)SessionProgress + 1; - SendStateUpdate(SessionState); + SendStateUpdate(SessionProgress); } TimerEvent.Broadcast(SessionProgress, SessionTimer); } @@ -89,7 +87,7 @@ void AGDKSessionGameState::TickGameTimer() SessionProgress = EGDKSessionProgress::Running; if (bAuthoritativeOverSessionEntity) { - SendStateUpdate(2); + SendStateUpdate(SessionProgress); } SessionTimer = GameSessionLength; } @@ -99,7 +97,7 @@ void AGDKSessionGameState::TickGameTimer() SessionProgress = EGDKSessionProgress::Results; if (bAuthoritativeOverSessionEntity) { - SendStateUpdate(3); + SendStateUpdate(SessionProgress); } SessionTimer = ResultsSessionLength; } @@ -109,27 +107,29 @@ void AGDKSessionGameState::TickGameTimer() SessionProgress = EGDKSessionProgress::Finished; if (bAuthoritativeOverSessionEntity) { - SendStateUpdate(4); + SendStateUpdate(SessionProgress); } } } } -void AGDKSessionGameState::SendStateUpdate(int NewState) +void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgress) { if (!GetWorld()->GetNetDriver() || !GetWorld()->GetNetDriver()->IsA()) { return; } + // There's an offset of 1 between the corresponding states of session progress and session state. + int SessionState = (int)SessionProgress + 1; + Worker_EntityId target_entity_id = SessionEntityId; Worker_ComponentUpdate component_update = {}; component_update.component_id = SessionComponentId; component_update.schema_type = Schema_CreateComponentUpdate(SessionComponentId); Schema_Object* fields_object = Schema_GetComponentUpdateFields(component_update.schema_type); - Schema_AddInt32(fields_object, 1, NewState); + Schema_AddInt32(fields_object, 1, SessionState); Cast(GetWorld()->GetNetDriver())->Connection->SendComponentUpdate(target_entity_id, &component_update); - UE_LOG(LogGDK, Warning, TEXT("Sending update for session component. State: %i; worker authority: %i"), NewState, Role.GetValue()); } diff --git a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h index e243f23b..375d9e35 100644 --- a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h +++ b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h @@ -61,7 +61,7 @@ class GDKSHOOTER_API AGDKSessionGameState : public AGDKGameState void TickGameTimer(); // Send a component update to the session manager entity to be picked up by the deployment manager - void SendStateUpdate(int NewState); + void SendStateUpdate(EGDKSessionProgress SessionProgress); // Begin progressing through the different stages of game session, if not already started void BeginTimer(); From d53c948a99ca3be29c83f6beeba80c0b49fa1a04 Mon Sep 17 00:00:00 2001 From: Ieva <33751053+ieva-improbable@users.noreply.github.com> Date: Wed, 5 Jun 2019 16:15:26 +0100 Subject: [PATCH 06/10] Change cast to be static. Co-Authored-By: Michael Samiec --- Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index 6e9f989c..9385adc0 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -121,7 +121,7 @@ void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgress) } // There's an offset of 1 between the corresponding states of session progress and session state. - int SessionState = (int)SessionProgress + 1; + int SessionState = static_cast(SessionProgress) + 1; Worker_EntityId target_entity_id = SessionEntityId; Worker_ComponentUpdate component_update = {}; From 8c069adf642594ffdf657069e6b3cfd625fa85ee Mon Sep 17 00:00:00 2001 From: ieva-improbable Date: Wed, 5 Jun 2019 16:43:18 +0100 Subject: [PATCH 07/10] Updating variable names. --- Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp | 4 ++-- Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index 9385adc0..aa13789c 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -113,7 +113,7 @@ void AGDKSessionGameState::TickGameTimer() } } -void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgress) +void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgressState) { if (!GetWorld()->GetNetDriver() || !GetWorld()->GetNetDriver()->IsA()) { @@ -121,7 +121,7 @@ void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgress) } // There's an offset of 1 between the corresponding states of session progress and session state. - int SessionState = static_cast(SessionProgress) + 1; + int SessionState = static_cast(SessionProgressState) + 1; Worker_EntityId target_entity_id = SessionEntityId; Worker_ComponentUpdate component_update = {}; diff --git a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h index 375d9e35..990d2ea6 100644 --- a/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h +++ b/Game/Source/GDKShooter/Public/Game/GDKSessionGameState.h @@ -61,7 +61,7 @@ class GDKSHOOTER_API AGDKSessionGameState : public AGDKGameState void TickGameTimer(); // Send a component update to the session manager entity to be picked up by the deployment manager - void SendStateUpdate(EGDKSessionProgress SessionProgress); + void SendStateUpdate(EGDKSessionProgress SessionProgressState); // Begin progressing through the different stages of game session, if not already started void BeginTimer(); From c42c82bb6412abe97e2e54c9dd8fca6760766e86 Mon Sep 17 00:00:00 2001 From: Ieva Vasiljeva Date: Thu, 6 Jun 2019 17:23:52 +0100 Subject: [PATCH 08/10] Fix an issue where native launch would crash due to assuming that we have a Spatial net driver. --- .../Private/Game/GDKSessionGameState.cpp | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index aa13789c..e408be95 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -45,13 +45,7 @@ void AGDKSessionGameState::RemovePlayerState(APlayerState* PlayerState) void AGDKSessionGameState::OnRep_SessionProgress() { - USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); - bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); - - if (bAuthoritativeOverSessionEntity) - { - SendStateUpdate(SessionProgress); - } + SendStateUpdate(SessionProgress); TimerEvent.Broadcast(SessionProgress, SessionTimer); } @@ -78,47 +72,45 @@ void AGDKSessionGameState::TickGameTimer() { SessionTimer--; - USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); - bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); - if (SessionProgress == EGDKSessionProgress::Lobby && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Running")); SessionProgress = EGDKSessionProgress::Running; - if (bAuthoritativeOverSessionEntity) - { - SendStateUpdate(SessionProgress); - } + SendStateUpdate(SessionProgress); SessionTimer = GameSessionLength; } if (SessionProgress == EGDKSessionProgress::Running && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Results")); SessionProgress = EGDKSessionProgress::Results; - if (bAuthoritativeOverSessionEntity) - { - SendStateUpdate(SessionProgress); - } + SendStateUpdate(SessionProgress); SessionTimer = ResultsSessionLength; } if (SessionProgress == EGDKSessionProgress::Results && SessionTimer <= 0) { UE_LOG(LogGDK, Log, TEXT("Advance GameState to Finished")); SessionProgress = EGDKSessionProgress::Finished; - if (bAuthoritativeOverSessionEntity) - { - SendStateUpdate(SessionProgress); - } + SendStateUpdate(SessionProgress); } } } void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgressState) { + // Only send the state update if we're using Spatial networking and if we have authority over the session entity. if (!GetWorld()->GetNetDriver() || !GetWorld()->GetNetDriver()->IsA()) { return; } + else + { + USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); + bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + if (!bAuthoritativeOverSessionEntity) + { + return; + } + } // There's an offset of 1 between the corresponding states of session progress and session state. int SessionState = static_cast(SessionProgressState) + 1; From 8633e5ddf83dca4c45bea3f914424fb2f97b9530 Mon Sep 17 00:00:00 2001 From: Ieva Vasiljeva Date: Fri, 7 Jun 2019 12:26:20 +0100 Subject: [PATCH 09/10] Refactor to make code cleaner. --- .../Private/Game/GDKSessionGameState.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp index e408be95..62419446 100644 --- a/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp +++ b/Game/Source/GDKShooter/Private/Game/GDKSessionGameState.cpp @@ -98,18 +98,17 @@ void AGDKSessionGameState::TickGameTimer() void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgressState) { // Only send the state update if we're using Spatial networking and if we have authority over the session entity. - if (!GetWorld()->GetNetDriver() || !GetWorld()->GetNetDriver()->IsA()) + UNetDriver* NetDriver = GetWorld()->GetNetDriver(); + if (NetDriver == nullptr || !NetDriver->IsA()) { return; } - else + + USpatialNetDriver* SpatialNetDriver = Cast(NetDriver); + bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); + if (!bAuthoritativeOverSessionEntity) { - USpatialNetDriver* SpatialNetDriver = Cast(GetWorld()->GetNetDriver()); - bool bAuthoritativeOverSessionEntity = SpatialNetDriver->StaticComponentView->HasAuthority(SessionEntityId, SessionComponentId); - if (!bAuthoritativeOverSessionEntity) - { - return; - } + return; } // There's an offset of 1 between the corresponding states of session progress and session state. @@ -121,7 +120,7 @@ void AGDKSessionGameState::SendStateUpdate(EGDKSessionProgress SessionProgressSt component_update.schema_type = Schema_CreateComponentUpdate(SessionComponentId); Schema_Object* fields_object = Schema_GetComponentUpdateFields(component_update.schema_type); Schema_AddInt32(fields_object, 1, SessionState); - Cast(GetWorld()->GetNetDriver())->Connection->SendComponentUpdate(target_entity_id, &component_update); + SpatialNetDriver->Connection->SendComponentUpdate(target_entity_id, &component_update); } From 24f34718b4163540ec9a32966490c60e59f76c00 Mon Sep 17 00:00:00 2001 From: Alex Moroz Date: Fri, 14 Jun 2019 12:11:16 +0100 Subject: [PATCH 10/10] * Changed Columns value in DefaultEditorPerProjectUserSettings.ini --- Game/Config/DefaultSpatialGDKEditorSettings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game/Config/DefaultSpatialGDKEditorSettings.ini b/Game/Config/DefaultSpatialGDKEditorSettings.ini index 020d6761..ba37e33e 100644 --- a/Game/Config/DefaultSpatialGDKEditorSettings.ini +++ b/Game/Config/DefaultSpatialGDKEditorSettings.ini @@ -4,6 +4,6 @@ bDeleteDynamicEntities=True bGenerateDefaultLaunchConfig=True bStopSpatialOnExit=False SpatialOSSnapshotFile=default.snapshot -LaunchConfigDesc=(Template="small",World=(Dimensions=(X=2000,Y=2000),ChunkEdgeLengthMeters=5,StreamingQueryIntervalSeconds=4,SnapshotWritePeriodSeconds=0,LegacyFlags=(("bridge_qos_max_timeout", "0"),("bridge_soft_handover_enabled", "false"),("enable_chunk_interest", "false")),LegacyJavaParams=()),Workers=((WorkerTypeName="UnrealWorker",Columns=2))) +LaunchConfigDesc=(Template="small",World=(Dimensions=(X=2000,Y=2000),ChunkEdgeLengthMeters=5,StreamingQueryIntervalSeconds=4,SnapshotWritePeriodSeconds=0,LegacyFlags=(("bridge_qos_max_timeout", "0"),("bridge_soft_handover_enabled", "false"),("enable_chunk_interest", "false")),LegacyJavaParams=()),Workers=((WorkerTypeName="UnrealWorker",Columns=1))) bGeneratePlaceholderEntitiesInSnapshot=True