Added EOS and some time sync adjustments

This commit is contained in:
Kingsmedia 2022-05-16 23:51:15 +02:00
parent 5775df5ec1
commit 884caf9974
14 changed files with 220 additions and 50 deletions

3
.gitignore vendored
View File

@ -76,3 +76,6 @@ Plugins/*/Intermediate/*
# Cache files for the editor to use # Cache files for the editor to use
DerivedDataCache/* DerivedDataCache/*
#Config files
Config/User*.ini

View File

@ -22,6 +22,14 @@
"Editor" "Editor"
] ]
}, },
{
"Name": "OnlineSubsystemSteam",
"Enabled": true
},
{
"Name": "OnlineSubsystemEOS",
"Enabled": true
},
{ {
"Name": "Bridge", "Name": "Bridge",
"Enabled": true, "Enabled": true,

View File

@ -45,19 +45,25 @@ bUseManualIPAddress=False
ManualIPAddress= ManualIPAddress=
[/Script/Engine.GameEngine] [/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver") +NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemEOS.NetDriverEOS",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
[OnlineSubsystem] [OnlineSubsystem]
DefaultPlatformService=Steam DefaultPlatformService=EOS
[OnlineSubsystemSteam] [OnlineSubsystemSteam]
bEnabled=true bEnabled=false
SteamDevAppId=480 SteamDevAppId=480
bInitServerOnClient=true bInitServerOnClient=true
[/Script/OnlineSubsystemSteam.SteamNetDriver] [/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection" NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
[OnlineSubsystemEOS]
bEnabled=true
[/Script/OnlineSubsystemEOS.NetDriverEOS]
bIsUsingP2PSockets=true
[/Script/OnlineSubsystemUtils.IpNetDriver] [/Script/OnlineSubsystemUtils.IpNetDriver]
NetServerMaxTickRate=120 NetServerMaxTickRate=120
@ -118,3 +124,18 @@ NetServerMaxTickRate=120
+CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") +CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn") +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

Binary file not shown.

View File

@ -29,6 +29,10 @@
{ {
"Name": "OnlineSubsystemSteam", "Name": "OnlineSubsystemSteam",
"Enabled": true "Enabled": true
},
{
"Name": "OnlineSubsystemEOS",
"Enabled": true
} }
] ]
} }

View File

@ -28,6 +28,7 @@ public class MultiplayerSessions : ModuleRules
"Core", "Core",
"OnlineSubsystem", "OnlineSubsystem",
"OnlineSubsystemSteam", "OnlineSubsystemSteam",
"OnlineSubsystemEOS",
"UMG", "UMG",
"Slate", "Slate",
"SlateCore" "SlateCore"

View File

@ -32,7 +32,7 @@ void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FStr
} }
UGameInstance* GameInstance = GetGameInstance(); UGameInstance* GameInstance = GetGameInstance();
if (GetGameInstance()) if (GameInstance)
{ {
MultiplayerSessionsSubsystem = GameInstance->GetSubsystem<UMultiplayerSessionsSubsystem>(); MultiplayerSessionsSubsystem = GameInstance->GetSubsystem<UMultiplayerSessionsSubsystem>();
} }
@ -44,6 +44,20 @@ void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FStr
MultiplayerSessionsSubsystem->MultiplayerOnJoinSessionComplete.AddUObject(this, &ThisClass::OnJoinSession); MultiplayerSessionsSubsystem->MultiplayerOnJoinSessionComplete.AddUObject(this, &ThisClass::OnJoinSession);
MultiplayerSessionsSubsystem->MultiplayerOnDestroySessionComplete.AddDynamic(this, &ThisClass::OnDestroySession); MultiplayerSessionsSubsystem->MultiplayerOnDestroySessionComplete.AddDynamic(this, &ThisClass::OnDestroySession);
MultiplayerSessionsSubsystem->MultiplayerOnStartSessionComplete.AddDynamic(this, &ThisClass::OnStartSession); 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); JoinButton->OnClicked.AddDynamic(this, &UMenu::JoinButtonClicked);
} }
if (LoginButton)
{
LoginButton->OnClicked.AddDynamic(this, &UMenu::LoginButtonClicked);
}
return true; 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() void UMenu::HostButtonClicked()
{ {
HostButton->SetIsEnabled(false); HostButton->SetIsEnabled(false);
@ -184,6 +210,16 @@ void UMenu::JoinButtonClicked()
} }
} }
void UMenu::LoginButtonClicked()
{
LoginButton->SetIsEnabled(false);
if (MultiplayerSessionsSubsystem)
{
MultiplayerSessionsSubsystem->Login();
}
}
void UMenu::MenuTearDown() void UMenu::MenuTearDown()
{ {
RemoveFromParent(); RemoveFromParent();

View File

@ -13,15 +13,74 @@ UMultiplayerSessionsSubsystem::UMultiplayerSessionsSubsystem():
DestroySessionCompleteDelegate(FOnDestroySessionCompleteDelegate::CreateUObject(this, &ThisClass::OnDestroySessionComplete)), DestroySessionCompleteDelegate(FOnDestroySessionCompleteDelegate::CreateUObject(this, &ThisClass::OnDestroySessionComplete)),
StartSessionCompleteDelegate(FOnStartSessionCompleteDelegate::CreateUObject(this, &ThisClass::OnStartSessionComplete)) StartSessionCompleteDelegate(FOnStartSessionCompleteDelegate::CreateUObject(this, &ThisClass::OnStartSessionComplete))
{ {
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(); Subsystem = IOnlineSubsystem::Get();
if (Subsystem) if (Subsystem)
{ {
Identity = Subsystem->GetIdentityInterface();
SessionInterface = Subsystem->GetSessionInterface(); 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) void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FString MatchType)
{ {
if (!IsLoggedIn()) return;
DesiredNumPublicConnections = NumPublicConnections; DesiredNumPublicConnections = NumPublicConnections;
DesiredMatchType = MatchType; DesiredMatchType = MatchType;
if (!SessionInterface.IsValid()) if (!SessionInterface.IsValid())
@ -43,12 +102,14 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS
CreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate); CreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate);
LastSessionSettings = MakeShareable(new FOnlineSessionSettings()); 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->NumPublicConnections = NumPublicConnections;
LastSessionSettings->bAllowJoinInProgress = true; LastSessionSettings->bAllowJoinInProgress = true;
LastSessionSettings->bAllowJoinViaPresence = true; LastSessionSettings->bAllowJoinViaPresence = true;
LastSessionSettings->bShouldAdvertise = true; LastSessionSettings->bShouldAdvertise = true;
LastSessionSettings->bUsesPresence = true; LastSessionSettings->bUsesPresence = true;
LastSessionSettings->Set(SEARCH_KEYWORDS, FString("BlasterLobby"), EOnlineDataAdvertisementType::ViaOnlineService);
LastSessionSettings->Set(FName("MatchType"), MatchType, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing); LastSessionSettings->Set(FName("MatchType"), MatchType, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
LastSessionSettings->BuildUniqueId = 1; LastSessionSettings->BuildUniqueId = 1;
LastSessionSettings->bUseLobbiesIfAvailable = true; LastSessionSettings->bUseLobbiesIfAvailable = true;
@ -65,6 +126,11 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS
void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults) void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults)
{ {
if (!IsLoggedIn())
{
return;
}
if (!SessionInterface.IsValid()) if (!SessionInterface.IsValid())
{ {
return; return;
@ -75,6 +141,8 @@ void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults)
LastSessionSearch = MakeShareable(new FOnlineSessionSearch()); LastSessionSearch = MakeShareable(new FOnlineSessionSearch());
LastSessionSearch->MaxSearchResults = MaxSearchResults; LastSessionSearch->MaxSearchResults = MaxSearchResults;
LastSessionSearch->bIsLanQuery = IOnlineSubsystem::Get()->GetSubsystemName() == "NULL" ? true : false; 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); LastSessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController(); const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
@ -88,6 +156,8 @@ void UMultiplayerSessionsSubsystem::FindSessions(int32 MaxSearchResults)
void UMultiplayerSessionsSubsystem::JoinSession(const FOnlineSessionSearchResult& SessionResult) void UMultiplayerSessionsSubsystem::JoinSession(const FOnlineSessionSearchResult& SessionResult)
{ {
if (!IsLoggedIn()) return;
if (!SessionInterface.IsValid()) if (!SessionInterface.IsValid())
{ {
MultiplayerOnJoinSessionComplete.Broadcast(EOnJoinSessionCompleteResult::UnknownError); MultiplayerOnJoinSessionComplete.Broadcast(EOnJoinSessionCompleteResult::UnknownError);
@ -124,19 +194,19 @@ void UMultiplayerSessionsSubsystem::DestroySession()
void UMultiplayerSessionsSubsystem::StartSession() void UMultiplayerSessionsSubsystem::StartSession()
{ {
// if (!SessionInterface.IsValid()) if (!SessionInterface.IsValid())
// { {
// return; return;
// } }
//
// StartSessionCompleteDelegateHandle = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate); StartSessionCompleteDelegateHandle = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate);
//
// if (!SessionInterface->StartSession(NAME_GameSession)) if (!SessionInterface->StartSession(NAME_GameSession))
// { {
// SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle);
//
// MultiplayerOnStartSessionComplete.Broadcast(false); MultiplayerOnStartSessionComplete.Broadcast(false);
// } }
} }
void UMultiplayerSessionsSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful) void UMultiplayerSessionsSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
@ -191,10 +261,10 @@ void UMultiplayerSessionsSubsystem::OnDestroySessionComplete(FName SessionName,
void UMultiplayerSessionsSubsystem::OnStartSessionComplete(FName SessionName, bool bWasSuccessful) void UMultiplayerSessionsSubsystem::OnStartSessionComplete(FName SessionName, bool bWasSuccessful)
{ {
// if (SessionInterface) if (SessionInterface)
// { {
// SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle);
// } }
//
// MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful); MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful);
} }

View File

@ -18,7 +18,7 @@ class MULTIPLAYERSESSIONS_API UMenu : public UUserWidget
public: public:
UFUNCTION(BlueprintCallable) 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: protected:
@ -36,6 +36,8 @@ protected:
void OnDestroySession(bool bWasSuccessful); void OnDestroySession(bool bWasSuccessful);
UFUNCTION() UFUNCTION()
void OnStartSession(bool bWasSuccessful); void OnStartSession(bool bWasSuccessful);
UFUNCTION()
void OnLoginComplete(bool bWasSuccessful);
private: private:
@ -45,15 +47,22 @@ private:
UPROPERTY(meta=(BindWidget)) UPROPERTY(meta=(BindWidget))
UButton* JoinButton; UButton* JoinButton;
UPROPERTY(meta=(BindWidget))
UButton* LoginButton;
UFUNCTION() UFUNCTION()
void HostButtonClicked(); void HostButtonClicked();
UFUNCTION() UFUNCTION()
void JoinButtonClicked(); void JoinButtonClicked();
UFUNCTION()
void LoginButtonClicked();
void MenuTearDown(); void MenuTearDown();
// The subsystem designed to handle all online session functionality // The subsystem designed to handle all online session functionality
UPROPERTY()
class UMultiplayerSessionsSubsystem* MultiplayerSessionsSubsystem; class UMultiplayerSessionsSubsystem* MultiplayerSessionsSubsystem;
int32 NumPublicConnections {4}; int32 NumPublicConnections {4};

View File

@ -4,18 +4,21 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "OnlineSessionSettings.h" #include "OnlineSessionSettings.h"
#include "OnlineSubsystem.h"
#include "Interfaces/OnlineIdentityInterface.h"
#include "Subsystems/GameInstanceSubsystem.h" #include "Subsystems/GameInstanceSubsystem.h"
#include "Interfaces/OnlineSessionInterface.h" #include "Interfaces/OnlineSessionInterface.h"
#include "MultiplayerSessionsSubsystem.generated.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_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnCreateSessionComplete, bool, bWasSuccessful);
DECLARE_MULTICAST_DELEGATE_TwoParams(FMultiplayerOnFindSessionsComplete, const TArray<FOnlineSessionSearchResult>& SessionResults, bool bWasSuccessful); DECLARE_MULTICAST_DELEGATE_TwoParams(FMultiplayerOnFindSessionsComplete, const TArray<FOnlineSessionSearchResult>& SessionResults, bool bWasSuccessful);
DECLARE_MULTICAST_DELEGATE_OneParam(FMultiplayerOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type Result) DECLARE_MULTICAST_DELEGATE_OneParam(FMultiplayerOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type Result)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnDestroySessionComplete, bool, bWasSuccessful); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnDestroySessionComplete, bool, bWasSuccessful);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnStartSessionComplete, bool, bWasSuccessful); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnStartSessionComplete, bool, bWasSuccessful);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiplayerOnLoginComplete, bool, bWasSuccessful);
/** /**
* *
@ -28,6 +31,8 @@ class MULTIPLAYERSESSIONS_API UMultiplayerSessionsSubsystem : public UGameInstan
public: public:
UMultiplayerSessionsSubsystem(); UMultiplayerSessionsSubsystem();
void Login();
FORCEINLINE bool IsLoggedIn() const { return bIsLoggedIn; }
/* /*
* To handle session functionality. The Menu class will call these * To handle session functionality. The Menu class will call these
@ -46,6 +51,7 @@ public:
FMultiplayerOnJoinSessionComplete MultiplayerOnJoinSessionComplete; FMultiplayerOnJoinSessionComplete MultiplayerOnJoinSessionComplete;
FMultiplayerOnDestroySessionComplete MultiplayerOnDestroySessionComplete; FMultiplayerOnDestroySessionComplete MultiplayerOnDestroySessionComplete;
FMultiplayerOnStartSessionComplete MultiplayerOnStartSessionComplete; FMultiplayerOnStartSessionComplete MultiplayerOnStartSessionComplete;
FMultiplayerOnLoginComplete MultiplayerOnLoginComplete;
int32 DesiredNumPublicConnections{}; int32 DesiredNumPublicConnections{};
FString DesiredMatchType{}; FString DesiredMatchType{};
@ -62,6 +68,8 @@ protected:
void OnStartSessionComplete(FName SessionName, bool bWasSuccessful); void OnStartSessionComplete(FName SessionName, bool bWasSuccessful);
private: private:
IOnlineSubsystem* Subsystem;
IOnlineIdentityPtr Identity;
IOnlineSessionPtr SessionInterface; IOnlineSessionPtr SessionInterface;
TSharedPtr<FOnlineSessionSettings> LastSessionSettings; TSharedPtr<FOnlineSessionSettings> LastSessionSettings;
@ -85,4 +93,12 @@ private:
bool bCreateSessionOnDestroy { false }; bool bCreateSessionOnDestroy { false };
int32 LastNumPublicConnections; int32 LastNumPublicConnections;
FString LastMatchType; FString LastMatchType;
void EOSLogin();
FDelegateHandle LoginDelegateHandle;
void HandleLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error);
FName GetSubsystemName();
bool bIsLoggedIn = false;
}; };

View File

@ -33,7 +33,7 @@ void ABlasterGameMode::Tick(float DeltaTime)
if (MatchState == MatchState::WaitingToStart) if (MatchState == MatchState::WaitingToStart)
{ {
CountdownTime = WarmupTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; CountdownTime = WarmupTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime;
if (CountdownTime <= 0.f) if (CountdownTime <= 0.f)
{ {
StartMatch(); StartMatch();
@ -41,7 +41,7 @@ void ABlasterGameMode::Tick(float DeltaTime)
} }
else if (MatchState == MatchState::InProgress) else if (MatchState == MatchState::InProgress)
{ {
CountdownTime = WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; CountdownTime = WarmupTime + MatchTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime;
if (CountdownTime <= 0.f) if (CountdownTime <= 0.f)
{ {
SetMatchState(MatchState::Cooldown); SetMatchState(MatchState::Cooldown);
@ -49,7 +49,7 @@ void ABlasterGameMode::Tick(float DeltaTime)
} }
else if (MatchState == MatchState::Cooldown) else if (MatchState == MatchState::Cooldown)
{ {
CountdownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; CountdownTime = WarmupTime + MatchTime + CooldownTime - GetWorld()->GetTimeSeconds(); // + LevelStartingTime;
if (CountdownTime <= 0.f) if (CountdownTime <= 0.f)
{ {
RestartGame(); RestartGame();

View File

@ -42,13 +42,11 @@ void ABlasterPlayerController::Tick(float DeltaTime)
if (DebugWidget) if (DebugWidget)
{ {
SetDebugMsg1(TEXT("GetServerTime(): "), FString::Printf(TEXT("%02f"), GetServerTime())); SetDebugMsg1(TEXT("GetWorld()->GetTimeSeconds(): "), FString::Printf(TEXT("%02f"), GetWorld()->GetTimeSeconds()));
SetDebugMsg2(TEXT("ClientServerDelta: "), FString::Printf(TEXT("%f"), ClientServerDelta)); SetDebugMsg2(TEXT("GetServerTime(): "), FString::Printf(TEXT("%02f"), GetServerTime()));
SetDebugMsg3(TEXT("LevelStartingTime: "), FString::Printf(TEXT("%f"), LevelStartingTime)); SetDebugMsg3(TEXT("ClientServerDelta: "), FString::Printf(TEXT("%f"), ClientServerDelta));
SetDebugMsg4(TEXT("WarmupTime: "), FString::Printf(TEXT("%f"), WarmupTime)); SetDebugMsg4(TEXT("LevelStartingTime: "), FString::Printf(TEXT("%f"), LevelStartingTime));
SetDebugMsg5(TEXT("MatchTime: "), FString::Printf(TEXT("%f"), MatchTime)); SetDebugMsg5(TEXT("CountdownInt: "), FString::Printf(TEXT("%d"), CountdownInt));
SetDebugMsg6(TEXT("CooldownTime: "), FString::Printf(TEXT("%f"), CooldownTime));
SetDebugMsg7(TEXT("CountdownInt: "), FString::Printf(TEXT("%d"), CountdownInt));
} }
} }
@ -128,7 +126,6 @@ void ABlasterPlayerController::ClientJoinMidgame_Implementation(FName StateOfMat
OnMatchStateSet(MatchState); OnMatchStateSet(MatchState);
if (BlasterHUD && MatchState == MatchState::WaitingToStart) if (BlasterHUD && MatchState == MatchState::WaitingToStart)
{ {
BlasterHUD->AddDebugWidget();
BlasterHUD->AddAnnouncementOverlay(); BlasterHUD->AddAnnouncementOverlay();
} }
} }
@ -275,9 +272,9 @@ void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime)
void ABlasterPlayerController::SetHUDTime() void ABlasterPlayerController::SetHUDTime()
{ {
float TimeLeft = 0.f; float TimeLeft = 0.f;
if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime; if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime(); // + LevelStartingTime;
else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime(); // + LevelStartingTime;
else if (MatchState == MatchState::Cooldown) TimeLeft = CooldownTime +WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime(); // + LevelStartingTime;
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
@ -286,7 +283,7 @@ void ABlasterPlayerController::SetHUDTime()
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode; BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
if (BlasterGameMode) if (BlasterGameMode)
{ {
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime); SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime());
} }
} }
@ -307,9 +304,10 @@ void ABlasterPlayerController::SetHUDTime()
void ABlasterPlayerController::PollInit() void ABlasterPlayerController::PollInit()
{ {
if (DebugWidget == nullptr) if (BlasterHUD && BlasterHUD->DebugWidget == nullptr)
{ {
if (BlasterHUD && BlasterHUD->DebugWidget) BlasterHUD->AddDebugWidget();
if (BlasterHUD->DebugWidget)
{ {
DebugWidget = BlasterHUD->DebugWidget; DebugWidget = BlasterHUD->DebugWidget;
} }
@ -401,8 +399,12 @@ void ABlasterPlayerController::HandleCooldown()
{ {
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD; BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
if (BlasterHUD) if (BlasterHUD)
{
if (BlasterHUD->CharacterOverlay)
{ {
BlasterHUD->CharacterOverlay->RemoveFromParent(); BlasterHUD->CharacterOverlay->RemoveFromParent();
}
bool bHUDValid = BlasterHUD->Announcement && bool bHUDValid = BlasterHUD->Announcement &&
BlasterHUD->Announcement->AnnouncementText && BlasterHUD->Announcement->AnnouncementText &&
BlasterHUD->Announcement->AnnouncementMessage; BlasterHUD->Announcement->AnnouncementMessage;