// 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 DeltaSeconds) override; virtual void OnPossess(APawn* InPawn) override; virtual void ReceivedPlayer() override; // Sync with server clock as soon as possible 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); // Synced with server world clock virtual float GetServerTime(); protected: virtual void BeginPlay() override; void CheckTimeSync(float DeltaSeconds); void SetHUDTime(); // 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; private: UPROPERTY() class ABlasterHUD* BlasterHUD; float MatchTime = 120.f; uint32 CountdownInt = 0; };