blaster/Source/Blaster/PlayerController/BlasterPlayerController.h

165 lines
4.1 KiB
C
Raw Normal View History

2022-05-05 15:57:57 +00:00
// 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"
2022-05-28 09:16:42 +00:00
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHighPingDelegate, bool, bPingTooHigh);
2022-05-05 15:57:57 +00:00
/**
*
*/
UCLASS()
class BLASTER_API ABlasterPlayerController : public APlayerController
{
GENERATED_BODY()
2022-05-07 10:03:33 +00:00
public:
2022-05-12 13:37:49 +00:00
virtual void Tick(float DeltaTime) override;
2022-05-10 08:40:23 +00:00
virtual void OnPossess(APawn* InPawn) override;
2022-05-10 09:14:54 +00:00
virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible
2022-05-10 10:42:09 +00:00
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
2022-05-12 15:05:30 +00:00
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);
2022-05-22 13:21:17 +00:00
2022-05-07 10:03:33 +00:00
void SetHUDHealth(float Health, float MaxHealth);
2022-05-23 09:27:12 +00:00
void SetHUDShield(float Shield, float MaxShield);
2022-05-09 14:33:48 +00:00
void SetHUDScore(float Score);
2022-05-09 15:16:41 +00:00
void SetHUDDefeats(int32 Defeats);
2022-05-09 16:39:41 +00:00
void SetHUDWeaponAmmo(int32 Ammo);
2022-05-09 17:35:28 +00:00
void SetHUDCarriedAmmo(int32 Ammo);
2022-05-22 13:21:17 +00:00
void SetHUDGrenades(int32 Grenades);
2022-05-10 08:40:23 +00:00
void SetHUDMatchCountdown(float CountdownTime);
2022-05-10 12:23:23 +00:00
void SetHUDAnnouncementCountdown(float CountdownTime);
2022-05-10 09:14:54 +00:00
// Synced with server world clock
virtual float GetServerTime();
2022-05-10 10:42:09 +00:00
void OnMatchStateSet(FName State);
2022-05-10 12:55:02 +00:00
void HandleCooldown();
2022-05-27 16:36:56 +00:00
float SingleTripTime = 0.f;
2022-05-28 09:16:42 +00:00
FHighPingDelegate HighPingDelegate;
2022-05-07 10:03:33 +00:00
protected:
2022-05-28 13:29:15 +00:00
virtual void SetupInputComponent() override;
2022-05-07 10:03:33 +00:00
virtual void BeginPlay() override;
2022-05-12 13:37:49 +00:00
void CheckTimeSync(float DeltaTime);
2022-05-10 11:31:39 +00:00
void HandleMatchHasStarted();
2022-05-10 08:40:23 +00:00
void SetHUDTime();
2022-05-10 10:42:09 +00:00
void PollInit();
2022-05-10 09:14:54 +00:00
// 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)
2022-05-10 10:15:22 +00:00
float TimeSyncFrequency = 5.f;
2022-05-10 09:14:54 +00:00
float TimeSyncRunningTime = 0.f;
2022-05-10 12:23:23 +00:00
UFUNCTION(Server, Reliable)
void ServerCheckMatchState();
UFUNCTION(Client, Reliable)
2022-05-12 13:37:49 +00:00
void ClientJoinMidgame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
2022-05-26 11:06:33 +00:00
void HighPingWarning();
void StopHighPingWarning();
2022-05-07 10:03:33 +00:00
2022-05-28 13:29:15 +00:00
void ShowReturnToMainMenu();
private:
2022-05-12 15:05:30 +00:00
UPROPERTY()
class UDebugWidget* DebugWidget;
2022-05-09 15:16:41 +00:00
UPROPERTY()
2022-05-07 10:03:33 +00:00
class ABlasterHUD* BlasterHUD;
2022-05-10 08:40:23 +00:00
2022-05-28 13:29:15 +00:00
// Return to main menu
UPROPERTY(EditAnywhere, Category = HUD)
TSubclassOf<class UUserWidget> ReturnToMainMenuWidget;
UPROPERTY()
class UReturnToMainMenu* ReturnToMainMenu;
bool bReturnToMainMenuOpen = false;
2022-05-10 13:29:00 +00:00
UPROPERTY()
class ABlasterGameMode* BlasterGameMode;
2022-05-10 12:23:23 +00:00
float LevelStartingTime = 0.f;
float MatchTime = 0.f;
float WarmupTime = 0.f;
2022-05-10 13:29:00 +00:00
float CooldownTime = 0.f;
2022-05-10 08:40:23 +00:00
uint32 CountdownInt = 0;
2022-05-10 10:42:09 +00:00
UPROPERTY(ReplicatedUsing=OnRep_MatchState)
FName MatchState;
UFUNCTION()
void OnRep_MatchState();
UPROPERTY()
class UCharacterOverlay* CharacterOverlay;
2022-05-23 09:47:49 +00:00
bool bInitializeHealth = false;
2022-05-10 10:42:09 +00:00
float HUDHealth;
float HUDMaxHealth;
2022-05-23 09:47:49 +00:00
bool bInitializeShield = false;
2022-05-23 09:27:12 +00:00
float HUDShield;
float HUDMaxShield;
2022-05-23 09:47:49 +00:00
bool bInitializeScore = false;
2022-05-10 10:42:09 +00:00
float HUDScore;
2022-05-23 09:47:49 +00:00
bool bInitializeDefeats = false;
2022-05-10 10:42:09 +00:00
int32 HUDDefeats;
2022-05-23 09:47:49 +00:00
bool bInitializeGrenades = false;
2022-05-22 13:21:17 +00:00
int32 HUDGrenades;
2022-05-10 10:42:09 +00:00
2022-05-23 23:16:06 +00:00
float bInitializeCarriedAmmo = false;
float HUDCarriedAmmo;
2022-05-29 09:59:15 +00:00
float bInitializeWeaponAmmo = false;
2022-05-23 23:16:06 +00:00
float HUDWeaponAmmo;
2022-05-26 11:06:33 +00:00
// 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;
2022-05-28 09:16:42 +00:00
UFUNCTION(Server, Reliable)
void ServerReportPingStatus(bool bHighPing);
2022-05-26 11:06:33 +00:00
UPROPERTY(EditAnywhere)
float HighPingThreshold = 50.f;
2022-05-05 15:57:57 +00:00
};