diff --git a/.gitignore b/.gitignore index 917aee4..a7ed43d 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,7 @@ Intermediate/* Plugins/*/Intermediate/* # Cache files for the editor to use -DerivedDataCache/* \ No newline at end of file +DerivedDataCache/* + +#Config files +Config/User*.ini \ No newline at end of file diff --git a/Blaster.uproject b/Blaster.uproject index 673f04d..a1b61fd 100644 --- a/Blaster.uproject +++ b/Blaster.uproject @@ -22,6 +22,14 @@ "Editor" ] }, + { + "Name": "OnlineSubsystemSteam", + "Enabled": true + }, + { + "Name": "OnlineSubsystemEOS", + "Enabled": true + }, { "Name": "Bridge", "Enabled": true, diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index d7bf3e8..6e1fcf4 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -45,19 +45,25 @@ bUseManualIPAddress=False ManualIPAddress= [/Script/Engine.GameEngine] -+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver") ++NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemEOS.NetDriverEOS",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver") [OnlineSubsystem] -DefaultPlatformService=Steam +DefaultPlatformService=EOS [OnlineSubsystemSteam] -bEnabled=true +bEnabled=false SteamDevAppId=480 bInitServerOnClient=true [/Script/OnlineSubsystemSteam.SteamNetDriver] NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection" +[OnlineSubsystemEOS] +bEnabled=true + +[/Script/OnlineSubsystemEOS.NetDriverEOS] +bIsUsingP2PSockets=true + [/Script/OnlineSubsystemUtils.IpNetDriver] NetServerMaxTickRate=120 @@ -118,3 +124,18 @@ NetServerMaxTickRate=120 +CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") +CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn") +[/Script/OnlineSubsystemEOS.EOSSettings] +CacheDir=CacheDir +DefaultArtifactName=Blaster +TickBudgetInMilliseconds=0 +bEnableOverlay=True +bEnableSocialOverlay=True +bShouldEnforceBeingLaunchedByEGS=False +TitleStorageReadChunkLength=0 +bUseEAS=False +bUseEOSConnect=False +bMirrorStatsToEOS=False +bMirrorAchievementsToEOS=False +bUseEOSSessions=False +bMirrorPresenceToEAS=False + diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 15b9ff2..55ad2cb 100644 Binary files a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset and b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index fe90ccd..bee7114 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Plugins/MultiplayerSessions/Content/WBP_Menu.uasset b/Plugins/MultiplayerSessions/Content/WBP_Menu.uasset index 22c4fa6..f5888d9 100644 Binary files a/Plugins/MultiplayerSessions/Content/WBP_Menu.uasset and b/Plugins/MultiplayerSessions/Content/WBP_Menu.uasset differ diff --git a/Plugins/MultiplayerSessions/MultiplayerSessions.uplugin b/Plugins/MultiplayerSessions/MultiplayerSessions.uplugin index 6c4eb6f..a2ea13f 100644 --- a/Plugins/MultiplayerSessions/MultiplayerSessions.uplugin +++ b/Plugins/MultiplayerSessions/MultiplayerSessions.uplugin @@ -29,6 +29,10 @@ { "Name": "OnlineSubsystemSteam", "Enabled": true + }, + { + "Name": "OnlineSubsystemEOS", + "Enabled": true } ] } \ No newline at end of file diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/MultiplayerSessions.Build.cs b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/MultiplayerSessions.Build.cs index 2a4fa9f..a8c1dc3 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/MultiplayerSessions.Build.cs +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/MultiplayerSessions.Build.cs @@ -28,6 +28,7 @@ public class MultiplayerSessions : ModuleRules "Core", "OnlineSubsystem", "OnlineSubsystemSteam", + "OnlineSubsystemEOS", "UMG", "Slate", "SlateCore" diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp index bef43c3..e24016f 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp @@ -32,7 +32,7 @@ void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FStr } UGameInstance* GameInstance = GetGameInstance(); - if (GetGameInstance()) + if (GameInstance) { MultiplayerSessionsSubsystem = GameInstance->GetSubsystem(); } @@ -44,6 +44,20 @@ void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FStr MultiplayerSessionsSubsystem->MultiplayerOnJoinSessionComplete.AddUObject(this, &ThisClass::OnJoinSession); MultiplayerSessionsSubsystem->MultiplayerOnDestroySessionComplete.AddDynamic(this, &ThisClass::OnDestroySession); MultiplayerSessionsSubsystem->MultiplayerOnStartSessionComplete.AddDynamic(this, &ThisClass::OnStartSession); + MultiplayerSessionsSubsystem->MultiplayerOnLoginComplete.AddDynamic(this, &ThisClass::OnLoginComplete); + + if (!MultiplayerSessionsSubsystem->IsLoggedIn()) + { + LoginButton->SetIsEnabled(true); + HostButton->SetIsEnabled(false); + JoinButton->SetIsEnabled(false); + } + else + { + LoginButton->SetIsEnabled(false); + HostButton->SetIsEnabled(true); + JoinButton->SetIsEnabled(true); + } } } @@ -64,6 +78,11 @@ bool UMenu::Initialize() JoinButton->OnClicked.AddDynamic(this, &UMenu::JoinButtonClicked); } + if (LoginButton) + { + LoginButton->OnClicked.AddDynamic(this, &UMenu::LoginButtonClicked); + } + return true; } @@ -164,6 +183,13 @@ void UMenu::OnStartSession(bool bWasSuccessful) { } +void UMenu::OnLoginComplete(bool bWasSuccessful) +{ + JoinButton->SetIsEnabled(!bWasSuccessful); + HostButton->SetIsEnabled(bWasSuccessful); + JoinButton->SetIsEnabled(bWasSuccessful); +} + void UMenu::HostButtonClicked() { HostButton->SetIsEnabled(false); @@ -184,6 +210,16 @@ void UMenu::JoinButtonClicked() } } +void UMenu::LoginButtonClicked() +{ + LoginButton->SetIsEnabled(false); + + if (MultiplayerSessionsSubsystem) + { + MultiplayerSessionsSubsystem->Login(); + } +} + void UMenu::MenuTearDown() { RemoveFromParent(); diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp index 0dfd851..66cf9fd 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp @@ -13,15 +13,74 @@ UMultiplayerSessionsSubsystem::UMultiplayerSessionsSubsystem(): DestroySessionCompleteDelegate(FOnDestroySessionCompleteDelegate::CreateUObject(this, &ThisClass::OnDestroySessionComplete)), StartSessionCompleteDelegate(FOnStartSessionCompleteDelegate::CreateUObject(this, &ThisClass::OnStartSessionComplete)) { - IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(); + Subsystem = IOnlineSubsystem::Get(); if (Subsystem) { + Identity = Subsystem->GetIdentityInterface(); SessionInterface = Subsystem->GetSessionInterface(); + if (GetSubsystemName() != EOS_SUBSYSTEM) // Non EOS OSS don't need to login + { + bIsLoggedIn = true; + } } } +FName UMultiplayerSessionsSubsystem::GetSubsystemName() +{ + return Subsystem ? Subsystem->GetSubsystemName() : FName("NULL"); +} + +void UMultiplayerSessionsSubsystem::Login() +{ + if (IsLoggedIn()) + { + MultiplayerOnLoginComplete.Broadcast(true); + return; + } + + EOSLogin(); +} + +void UMultiplayerSessionsSubsystem::EOSLogin() +{ + if (!Identity.IsValid()) return; + + LoginDelegateHandle = Identity->OnLoginCompleteDelegates->AddUObject(this, &UMultiplayerSessionsSubsystem::HandleLoginComplete); + + FOnlineAccountCredentials Credentials; + Credentials.Id = FString(); + Credentials.Token = FString(); + Credentials.Type = FString("accountportal"); + + if (!Identity->Login(0, Credentials)) + { + UE_LOG(LogTemp, Error, TEXT("Unable to perform EOS Login")); + } + else + { + UE_LOG(LogTemp, Display, TEXT("Performed EOS Login successful")); + } +} + +void UMultiplayerSessionsSubsystem::HandleLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error) +{ + bIsLoggedIn = bWasSuccessful; + + if (Identity) + { + // Deregister the event handler. + Identity->ClearOnLoginCompleteDelegate_Handle(LocalUserNum, LoginDelegateHandle); + LoginDelegateHandle.Reset(); + } + + // Broadcast our own custom delegate + MultiplayerOnLoginComplete.Broadcast(bWasSuccessful); +} + void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FString MatchType) { + if (!IsLoggedIn()) return; + DesiredNumPublicConnections = NumPublicConnections; DesiredMatchType = MatchType; if (!SessionInterface.IsValid()) @@ -43,12 +102,14 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS CreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate); LastSessionSettings = MakeShareable(new FOnlineSessionSettings()); - LastSessionSettings->bIsLANMatch = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false; + LastSessionSettings->bIsDedicated = false; + LastSessionSettings->bIsLANMatch = GetSubsystemName() == "NULL" || GetSubsystemName() == "LAN" ? true : false; LastSessionSettings->NumPublicConnections = NumPublicConnections; LastSessionSettings->bAllowJoinInProgress = true; LastSessionSettings->bAllowJoinViaPresence = true; LastSessionSettings->bShouldAdvertise = true; LastSessionSettings->bUsesPresence = true; + LastSessionSettings->Set(SEARCH_KEYWORDS, FString("BlasterLobby"), EOnlineDataAdvertisementType::ViaOnlineService); LastSessionSettings->Set(FName("MatchType"), MatchType, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing); LastSessionSettings->BuildUniqueId = 1; LastSessionSettings->bUseLobbiesIfAvailable = true; @@ -65,6 +126,11 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults) { + if (!IsLoggedIn()) + { + return; + } + if (!SessionInterface.IsValid()) { return; @@ -75,6 +141,8 @@ void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults) LastSessionSearch = MakeShareable(new FOnlineSessionSearch()); LastSessionSearch->MaxSearchResults = MaxSearchResults; LastSessionSearch->bIsLanQuery = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false; + LastSessionSearch->QuerySettings.Set(SEARCH_KEYWORDS, FString("BlasterLobby"), EOnlineComparisonOp::Equals); + LastSessionSearch->QuerySettings.Set(SEARCH_LOBBIES, true, EOnlineComparisonOp::Equals); LastSessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals); const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController(); @@ -88,6 +156,8 @@ void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults) void UMultiplayerSessionsSubsystem::JoinSession(const FOnlineSessionSearchResult& SessionResult) { + if (!IsLoggedIn()) return; + if (!SessionInterface.IsValid()) { MultiplayerOnJoinSessionComplete.Broadcast(EOnJoinSessionCompleteResult::UnknownError); @@ -124,19 +194,19 @@ void UMultiplayerSessionsSubsystem::DestroySession() void UMultiplayerSessionsSubsystem::StartSession() { - // if (!SessionInterface.IsValid()) - // { - // return; - // } - // - // StartSessionCompleteDelegateHandle = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate); - // - // if (!SessionInterface->StartSession(NAME_GameSession)) - // { - // SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); - // - // MultiplayerOnStartSessionComplete.Broadcast(false); - // } + if (!SessionInterface.IsValid()) + { + return; + } + + StartSessionCompleteDelegateHandle = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate); + + if (!SessionInterface->StartSession(NAME_GameSession)) + { + SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); + + MultiplayerOnStartSessionComplete.Broadcast(false); + } } void UMultiplayerSessionsSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful) @@ -191,10 +261,10 @@ void UMultiplayerSessionsSubsystem::OnDestroySessionComplete(FName SessionName, void UMultiplayerSessionsSubsystem::OnStartSessionComplete(FName SessionName, bool bWasSuccessful) { - // if (SessionInterface) - // { - // SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); - // } - // - // MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful); + if (SessionInterface) + { + SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); + } + + MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful); } diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h index 93359b7..2845556 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h @@ -18,7 +18,7 @@ class MULTIPLAYERSESSIONS_API UMenu : public UUserWidget public: UFUNCTION(BlueprintCallable) - void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll")), FString LobbyPath = FString(TEXT("/Game/ThirdPerson/Maps/Lobby"))); + void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll")), FString LobbyPath = FString(TEXT("/Game/Maps/Lobby"))); protected: @@ -36,6 +36,8 @@ protected: void OnDestroySession(bool bWasSuccessful); UFUNCTION() void OnStartSession(bool bWasSuccessful); + UFUNCTION() + void OnLoginComplete(bool bWasSuccessful); private: @@ -44,6 +46,9 @@ private: UPROPERTY(meta=(BindWidget)) UButton* JoinButton; + + UPROPERTY(meta=(BindWidget)) + UButton* LoginButton; UFUNCTION() void HostButtonClicked(); @@ -51,9 +56,13 @@ private: UFUNCTION() void JoinButtonClicked(); + UFUNCTION() + void LoginButtonClicked(); + void MenuTearDown(); // The subsystem designed to handle all online session functionality + UPROPERTY() class UMultiplayerSessionsSubsystem* MultiplayerSessionsSubsystem; int32 NumPublicConnections {4}; diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h index 11deff0..28eddff 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h @@ -4,18 +4,21 @@ #include "CoreMinimal.h" #include "OnlineSessionSettings.h" +#include "OnlineSubsystem.h" +#include "Interfaces/OnlineIdentityInterface.h" #include "Subsystems/GameInstanceSubsystem.h" #include "Interfaces/OnlineSessionInterface.h" #include "MultiplayerSessionsSubsystem.generated.h" // -// Delcaring our own custom delegates for the Menu class to bind callbacks to +// Declaring our own custom delegates for the Menu class to bind callbacks to // DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnCreateSessionComplete, bool, bWasSuccessful); DECLARE_MULTICAST_DELEGATE_TwoParams(FMultiplayerOnFindSessionsComplete, const TArray& SessionResults, bool bWasSuccessful); DECLARE_MULTICAST_DELEGATE_OneParam(FMultiplayerOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type Result) DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnDestroySessionComplete, bool, bWasSuccessful); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnStartSessionComplete, bool, bWasSuccessful); +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnLoginComplete, bool, bWasSuccessful); /** * @@ -28,7 +31,9 @@ class MULTIPLAYERSESSIONS_API UMultiplayerSessionsSubsystem : public UGameInstan public: UMultiplayerSessionsSubsystem(); - + void Login(); + FORCEINLINE bool IsLoggedIn() const { return bIsLoggedIn; } + /* * To handle session functionality. The Menu class will call these */ @@ -46,6 +51,7 @@ public: FMultiplayerOnJoinSessionComplete MultiplayerOnJoinSessionComplete; FMultiplayerOnDestroySessionComplete MultiplayerOnDestroySessionComplete; FMultiplayerOnStartSessionComplete MultiplayerOnStartSessionComplete; + FMultiplayerOnLoginComplete MultiplayerOnLoginComplete; int32 DesiredNumPublicConnections{}; FString DesiredMatchType{}; @@ -62,7 +68,9 @@ protected: void OnStartSessionComplete(FName SessionName, bool bWasSuccessful); private: - + IOnlineSubsystem* Subsystem; + IOnlineIdentityPtr Identity; + IOnlineSessionPtr SessionInterface; TSharedPtr LastSessionSettings; TSharedPtr LastSessionSearch; @@ -85,4 +93,12 @@ private: bool bCreateSessionOnDestroy { false }; int32 LastNumPublicConnections; FString LastMatchType; + + void EOSLogin(); + + FDelegateHandle LoginDelegateHandle; + void HandleLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error); + + FName GetSubsystemName(); + bool bIsLoggedIn = false; }; diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 315b502..8660896 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -33,7 +33,7 @@ void ABlasterGameMode::Tick(float DeltaTime) if (MatchState == MatchState::WaitingToStart) { - CountdownTime = WarmupTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + CountdownTime = WarmupTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime; if (CountdownTime <= 0.f) { StartMatch(); @@ -41,7 +41,7 @@ void ABlasterGameMode::Tick(float DeltaTime) } else if (MatchState == MatchState::InProgress) { - CountdownTime = WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + CountdownTime = WarmupTime + MatchTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime; if (CountdownTime <= 0.f) { SetMatchState(MatchState::Cooldown); @@ -49,7 +49,7 @@ void ABlasterGameMode::Tick(float DeltaTime) } else if (MatchState == MatchState::Cooldown) { - CountdownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + CountdownTime = WarmupTime + MatchTime + CooldownTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime; if (CountdownTime <= 0.f) { RestartGame(); diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index f222fd0..8e494ed 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -42,13 +42,11 @@ void ABlasterPlayerController::Tick(float DeltaTime) if (DebugWidget) { - SetDebugMsg1(TEXT("GetServerTime(): "), FString::Printf(TEXT("%02f"), GetServerTime())); - SetDebugMsg2(TEXT("ClientServerDelta: "), FString::Printf(TEXT("%f"), ClientServerDelta)); - SetDebugMsg3(TEXT("LevelStartingTime: "), FString::Printf(TEXT("%f"), LevelStartingTime)); - SetDebugMsg4(TEXT("WarmupTime: "), FString::Printf(TEXT("%f"), WarmupTime)); - SetDebugMsg5(TEXT("MatchTime: "), FString::Printf(TEXT("%f"), MatchTime)); - SetDebugMsg6(TEXT("CooldownTime: "), FString::Printf(TEXT("%f"), CooldownTime)); - SetDebugMsg7(TEXT("CountdownInt: "), FString::Printf(TEXT("%d"), CountdownInt)); + SetDebugMsg1(TEXT("GetWorld()->GetTimeSeconds(): "), FString::Printf(TEXT("%02f"), GetWorld()->GetTimeSeconds())); + SetDebugMsg2(TEXT("GetServerTime(): "), FString::Printf(TEXT("%02f"), GetServerTime())); + SetDebugMsg3(TEXT("ClientServerDelta: "), FString::Printf(TEXT("%f"), ClientServerDelta)); + SetDebugMsg4(TEXT("LevelStartingTime: "), FString::Printf(TEXT("%f"), LevelStartingTime)); + SetDebugMsg5(TEXT("CountdownInt: "), FString::Printf(TEXT("%d"), CountdownInt)); } } @@ -128,7 +126,6 @@ void ABlasterPlayerController::ClientJoinMidgame_Implementation(FName StateOfMat OnMatchStateSet(MatchState); if (BlasterHUD && MatchState == MatchState::WaitingToStart) { - BlasterHUD->AddDebugWidget(); BlasterHUD->AddAnnouncementOverlay(); } } @@ -275,9 +272,9 @@ void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime) void ABlasterPlayerController::SetHUDTime() { float TimeLeft = 0.f; - if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime; - else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; - else if (MatchState == MatchState::Cooldown) TimeLeft = CooldownTime +WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; + if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime(); // + LevelStartingTime; + else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime(); // + LevelStartingTime; + else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime(); // + LevelStartingTime; uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); @@ -286,7 +283,7 @@ void ABlasterPlayerController::SetHUDTime() BlasterGameMode = BlasterGameMode == nullptr ? Cast(UGameplayStatics::GetGameMode(this)) : BlasterGameMode; if (BlasterGameMode) { - SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime); + SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime()); } } @@ -307,14 +304,15 @@ void ABlasterPlayerController::SetHUDTime() void ABlasterPlayerController::PollInit() { - if (DebugWidget == nullptr) + if (BlasterHUD && BlasterHUD->DebugWidget == nullptr) { - if (BlasterHUD && BlasterHUD->DebugWidget) + BlasterHUD->AddDebugWidget(); + if (BlasterHUD->DebugWidget) { DebugWidget = BlasterHUD->DebugWidget; } } - + if (CharacterOverlay == nullptr) { if (BlasterHUD && BlasterHUD->CharacterOverlay) @@ -402,8 +400,12 @@ void ABlasterPlayerController::HandleCooldown() BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; if (BlasterHUD) { - BlasterHUD->CharacterOverlay->RemoveFromParent(); - bool bHUDValid =BlasterHUD->Announcement && + if (BlasterHUD->CharacterOverlay) + { + BlasterHUD->CharacterOverlay->RemoveFromParent(); + } + + bool bHUDValid = BlasterHUD->Announcement && BlasterHUD->Announcement->AnnouncementText && BlasterHUD->Announcement->AnnouncementMessage;