blaster/Source/Blaster/PlayerController/BlasterPlayerController.h

145 lines
3.7 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "BlasterPlayerController.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API ABlasterPlayerController : public APlayerController
{
GENERATED_BODY()
public:
virtual void Tick(float DeltaTime) override;
virtual void OnPossess(APawn* InPawn) override;
virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
void SetDebugMsg1(FString Key, FString Value);
void SetDebugMsg2(FString Key, FString Value);
void SetDebugMsg3(FString Key, FString Value);
void SetDebugMsg4(FString Key, FString Value);
void SetDebugMsg5(FString Key, FString Value);
void SetDebugMsg6(FString Key, FString Value);
void SetDebugMsg7(FString Key, FString Value);
void SetHUDHealth(float Health, float MaxHealth);
void SetHUDShield(float Shield, float MaxShield);
void SetHUDScore(float Score);
void SetHUDDefeats(int32 Defeats);
void SetHUDWeaponAmmo(int32 Ammo);
void SetHUDCarriedAmmo(int32 Ammo);
void SetHUDGrenades(int32 Grenades);
void SetHUDMatchCountdown(float CountdownTime);
void SetHUDAnnouncementCountdown(float CountdownTime);
// Synced with server world clock
virtual float GetServerTime();
void OnMatchStateSet(FName State);
void HandleCooldown();
float SingleTripTime = 0.f;
protected:
virtual void BeginPlay() override;
void CheckTimeSync(float DeltaTime);
void HandleMatchHasStarted();
void SetHUDTime();
void PollInit();
// Sync time between client and server
// Requests the current server time, passing in the client's time when the request was sent
UFUNCTION(Server, Reliable)
void ServerRequestServerTime(float TimeOfClientRequest);
// Reports the current server time to the client in response to ServerRequestServerTime
UFUNCTION(Client, Reliable)
void ClientReportServerTime(float TimeOfClientRequest, float TimeServerReceivedClientRequest);
// Difference between client and server time
float ClientServerDelta = 0;
UPROPERTY(EditAnywhere, Category = Time)
float TimeSyncFrequency = 5.f;
float TimeSyncRunningTime = 0.f;
UFUNCTION(Server, Reliable)
void ServerCheckMatchState();
UFUNCTION(Client, Reliable)
void ClientJoinMidgame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
void HighPingWarning();
void StopHighPingWarning();
private:
UPROPERTY()
class UDebugWidget* DebugWidget;
UPROPERTY()
class ABlasterHUD* BlasterHUD;
UPROPERTY()
class ABlasterGameMode* BlasterGameMode;
float LevelStartingTime = 0.f;
float MatchTime = 0.f;
float WarmupTime = 0.f;
float CooldownTime = 0.f;
uint32 CountdownInt = 0;
UPROPERTY(ReplicatedUsing=OnRep_MatchState)
FName MatchState;
UFUNCTION()
void OnRep_MatchState();
UPROPERTY()
class UCharacterOverlay* CharacterOverlay;
bool bInitializeHealth = false;
float HUDHealth;
float HUDMaxHealth;
bool bInitializeShield = false;
float HUDShield;
float HUDMaxShield;
bool bInitializeScore = false;
float HUDScore;
bool bInitializeDefeats = false;
int32 HUDDefeats;
bool bInitializeGrenades = false;
int32 HUDGrenades;
float bInitializeCarriedAmmo = false;
float HUDCarriedAmmo;
float bInitializeHUDWeaponAmmo = false;
float HUDWeaponAmmo;
// High Ping Indicator
void CheckPing(float DeltaTime);
float HighPingRunningTime = 0.f;
UPROPERTY(EditAnywhere)
float HighPingDuration = 5.f;
float PingAnimationRunningTime = 0.f;
UPROPERTY(EditAnywhere)
float CheckPingFrequency = 20.f;
UPROPERTY(EditAnywhere)
float HighPingThreshold = 50.f;
};