127 - Restart Game
This commit is contained in:
parent
cdca489c56
commit
68ef1dd118
|
@ -49,7 +49,7 @@ void ABlasterGameMode::Tick(float DeltaSeconds)
|
||||||
}
|
}
|
||||||
else if (MatchState == MatchState::Cooldown)
|
else if (MatchState == MatchState::Cooldown)
|
||||||
{
|
{
|
||||||
CountDownTime = WarmupTime + MatchTime + CooldownTime - GetWorld()->GetTimeSeconds() + LevelStartingTime;
|
CountDownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime;
|
||||||
if (CountDownTime <= 0.f)
|
if (CountDownTime <= 0.f)
|
||||||
{
|
{
|
||||||
RestartGame();
|
RestartGame();
|
||||||
|
|
|
@ -73,7 +73,6 @@ void ABlasterPlayerController::CheckTimeSync(float DeltaSeconds)
|
||||||
float ABlasterPlayerController::GetServerTime()
|
float ABlasterPlayerController::GetServerTime()
|
||||||
{
|
{
|
||||||
if (HasAuthority()) return GetWorld()->GetTimeSeconds();
|
if (HasAuthority()) return GetWorld()->GetTimeSeconds();
|
||||||
|
|
||||||
return GetWorld()->GetTimeSeconds() + ClientServerDelta;
|
return GetWorld()->GetTimeSeconds() + ClientServerDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +157,6 @@ void ABlasterPlayerController::ServerCheckMatchState_Implementation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime)
|
void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime)
|
||||||
{
|
{
|
||||||
LevelStartingTime = StartingTime;
|
LevelStartingTime = StartingTime;
|
||||||
|
@ -184,7 +182,6 @@ void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeO
|
||||||
{
|
{
|
||||||
const float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest;
|
const float RoundTripTime = GetWorld()->GetTimeSeconds() - TimeOfClientRequest;
|
||||||
const float CurrentServerTime = TimeServerReceivedClientRequest + (0.5f * RoundTripTime);
|
const float CurrentServerTime = TimeServerReceivedClientRequest + (0.5f * RoundTripTime);
|
||||||
|
|
||||||
ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds();
|
ClientServerDelta = CurrentServerTime - GetWorld()->GetTimeSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,22 +190,19 @@ 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 = WarmupTime + MatchTime + CooldownTime - GetServerTime() + LevelStartingTime;
|
else if (MatchState == MatchState::Cooldown) TimeLeft = CooldownTime + WarmupTime + MatchTime - GetServerTime() + LevelStartingTime;
|
||||||
|
|
||||||
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
|
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
|
||||||
|
|
||||||
if (HasAuthority())
|
|
||||||
{
|
|
||||||
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
|
|
||||||
if (BlasterGameMode)
|
|
||||||
{
|
|
||||||
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CountdownInt != SecondsLeft)
|
if (CountdownInt != SecondsLeft)
|
||||||
{
|
{
|
||||||
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown) SetHUDAnnouncementCountdown(TimeLeft);
|
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown)
|
||||||
if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft);
|
{
|
||||||
|
SetHUDAnnouncementCountdown(TimeLeft);
|
||||||
|
}
|
||||||
|
if (MatchState == MatchState::InProgress)
|
||||||
|
{
|
||||||
|
SetHUDMatchCountdown(TimeLeft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CountdownInt = SecondsLeft;
|
CountdownInt = SecondsLeft;
|
||||||
|
|
|
@ -15,7 +15,6 @@ class BLASTER_API ABlasterPlayerController : public APlayerController
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Tick(float DeltaSeconds) override;
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
virtual void OnPossess(APawn* InPawn) override;
|
virtual void OnPossess(APawn* InPawn) override;
|
||||||
virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible
|
virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible
|
||||||
|
@ -36,7 +35,6 @@ public:
|
||||||
void HandleCooldown();
|
void HandleCooldown();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
void CheckTimeSync(float DeltaSeconds);
|
void CheckTimeSync(float DeltaSeconds);
|
||||||
void HandleMatchHasStarted();
|
void HandleMatchHasStarted();
|
||||||
|
@ -54,7 +52,7 @@ protected:
|
||||||
void ClientReportServerTime(float TimeOfClientRequest, float TimeServerReceivedClientRequest);
|
void ClientReportServerTime(float TimeOfClientRequest, float TimeServerReceivedClientRequest);
|
||||||
|
|
||||||
// Difference between client and server time
|
// Difference between client and server time
|
||||||
float ClientServerDelta = 0;
|
float ClientServerDelta = 0.f;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = Time)
|
UPROPERTY(EditAnywhere, Category = Time)
|
||||||
float TimeSyncFrequency = 5.f;
|
float TimeSyncFrequency = 5.f;
|
||||||
|
@ -66,8 +64,8 @@ protected:
|
||||||
|
|
||||||
UFUNCTION(Client, Reliable)
|
UFUNCTION(Client, Reliable)
|
||||||
void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
|
void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class ABlasterHUD* BlasterHUD;
|
class ABlasterHUD* BlasterHUD;
|
||||||
|
|
||||||
|
@ -80,7 +78,7 @@ private:
|
||||||
float CooldownTime = 0.f;
|
float CooldownTime = 0.f;
|
||||||
uint32 CountdownInt = 0;
|
uint32 CountdownInt = 0;
|
||||||
|
|
||||||
UPROPERTY(ReplicatedUsing=OnRep_MatchState)
|
UPROPERTY(ReplicatedUsing = OnRep_MatchState)
|
||||||
FName MatchState;
|
FName MatchState;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
@ -94,5 +92,4 @@ private:
|
||||||
float HUDMaxHealth;
|
float HUDMaxHealth;
|
||||||
float HUDScore;
|
float HUDScore;
|
||||||
int32 HUDDefeats;
|
int32 HUDDefeats;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue