109 lines
2.9 KiB
C++
109 lines
2.9 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 SetHUDScore(float Score);
|
|
void SetHUDDefeats(int32 Defeats);
|
|
void SetHUDWeaponAmmo(int32 Ammo);
|
|
void SetHUDCarriedAmmo(int32 Ammo);
|
|
void SetHUDMatchCountdown(float CountdownTime);
|
|
void SetHUDAnnouncementCountdown(float CountdownTime);
|
|
|
|
// Synced with server world clock
|
|
virtual float GetServerTime();
|
|
|
|
void OnMatchStateSet(FName State);
|
|
void HandleCooldown();
|
|
|
|
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);
|
|
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 bInitializeCharacterOverlay = false;
|
|
|
|
float HUDHealth;
|
|
float HUDMaxHealth;
|
|
float HUDScore;
|
|
int32 HUDDefeats;
|
|
|
|
};
|