2022-05-26 15:32:23 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2022-05-27 09:06:39 +00:00
|
|
|
#include "Blaster/Character/BlasterCharacter.h"
|
2022-05-26 15:32:23 +00:00
|
|
|
#include "Components/ActorComponent.h"
|
|
|
|
#include "LagCompensationComponent.generated.h"
|
|
|
|
|
2022-05-27 09:06:39 +00:00
|
|
|
USTRUCT(BlueprintType)
|
|
|
|
struct FBoxInformation
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
FVector Location;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
FRotator Rotation;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
FVector BoxExtend;
|
|
|
|
};
|
|
|
|
|
|
|
|
USTRUCT(BlueprintType)
|
|
|
|
struct FFramePackage
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
float Time;
|
|
|
|
|
2022-05-27 17:13:59 +00:00
|
|
|
UPROPERTY()
|
2022-05-27 09:06:39 +00:00
|
|
|
TMap<FName, FBoxInformation> HitBoxInfo;
|
2022-05-27 17:13:59 +00:00
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
ABlasterCharacter* Character;
|
2022-05-27 09:06:39 +00:00
|
|
|
};
|
2022-05-26 15:32:23 +00:00
|
|
|
|
2022-05-27 15:42:34 +00:00
|
|
|
USTRUCT(BlueprintType)
|
|
|
|
struct FServerSideRewindResult
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
bool bHitConfirmed;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
bool bHeadShot;
|
|
|
|
};
|
|
|
|
|
2022-05-27 17:13:59 +00:00
|
|
|
USTRUCT(BlueprintType)
|
|
|
|
struct FShotgunServerSideRewindResult
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
TMap<ABlasterCharacter*, uint32> Headshots;
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
TMap<ABlasterCharacter*, uint32> BodyShots;
|
|
|
|
};
|
|
|
|
|
|
|
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
2022-05-26 15:32:23 +00:00
|
|
|
class BLASTER_API ULagCompensationComponent : public UActorComponent
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
2022-05-27 17:13:59 +00:00
|
|
|
public:
|
2022-05-26 15:32:23 +00:00
|
|
|
ULagCompensationComponent();
|
2022-05-27 09:06:39 +00:00
|
|
|
friend ABlasterCharacter;
|
2022-05-26 15:32:23 +00:00
|
|
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
2022-05-27 09:29:32 +00:00
|
|
|
void ShowFramePackage(const FFramePackage& Package, const FColor Color);
|
2022-05-27 22:28:02 +00:00
|
|
|
|
|
|
|
// Hitscan
|
2022-05-27 17:13:59 +00:00
|
|
|
FServerSideRewindResult ServerSideRewind(
|
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const FVector_NetQuantize& HitLocation,
|
|
|
|
float HitTime
|
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
2022-05-27 22:28:02 +00:00
|
|
|
// Projectiles
|
|
|
|
FServerSideRewindResult ProjectilServerSideRewind(
|
2022-05-27 16:36:56 +00:00
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
2022-05-27 22:28:02 +00:00
|
|
|
const FVector_NetQuantize100& InitialVelocity,
|
|
|
|
float HitTime
|
2022-05-27 16:36:56 +00:00
|
|
|
);
|
2022-05-27 22:28:02 +00:00
|
|
|
|
|
|
|
// Shotgun
|
2022-05-27 19:29:25 +00:00
|
|
|
UFUNCTION(Server, Reliable)
|
|
|
|
void ShotgunServerScoreRequest(
|
|
|
|
const TArray<ABlasterCharacter*>& HitCharacters,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const TArray<FVector_NetQuantize>& HitLocations,
|
2022-05-27 19:57:52 +00:00
|
|
|
float HitTime
|
2022-05-27 19:29:25 +00:00
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
2022-05-27 22:28:02 +00:00
|
|
|
UFUNCTION(Server, Reliable)
|
|
|
|
void ServerScoreRequest(
|
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const FVector_NetQuantize& HitLocation,
|
|
|
|
float HitTime,
|
|
|
|
AWeapon* DamageCauser
|
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
|
|
|
UFUNCTION(Server, Reliable)
|
|
|
|
void ProjectileServerScoreRequest(
|
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const FVector_NetQuantize100& InitialVelocity,
|
|
|
|
float HitTime
|
|
|
|
);
|
|
|
|
|
2022-05-27 19:29:25 +00:00
|
|
|
FShotgunServerSideRewindResult ShotgunServerSideRewind(
|
|
|
|
const TArray<ABlasterCharacter*>& HitCharacters,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const TArray<FVector_NetQuantize>& HitLocations,
|
|
|
|
float HitTime
|
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
2022-05-26 15:32:23 +00:00
|
|
|
protected:
|
|
|
|
virtual void BeginPlay() override;
|
2022-05-27 16:36:56 +00:00
|
|
|
void SaveFramePackage();
|
2022-05-27 09:29:32 +00:00
|
|
|
void SaveFramePackage(FFramePackage& Package);
|
2022-05-27 15:05:07 +00:00
|
|
|
FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime);
|
2022-05-27 22:28:02 +00:00
|
|
|
|
|
|
|
void CacheBoxPositions(ABlasterCharacter* HitCharacter, FFramePackage& OutFramePackage);
|
|
|
|
void MoveBoxes(ABlasterCharacter* HitCharacter, const FFramePackage& Package);
|
|
|
|
void ResetHitBoxes(ABlasterCharacter* HitCharacter, const FFramePackage& Package);
|
|
|
|
void EnableCharacterMeshCollision(ABlasterCharacter* HitCharacter, ECollisionEnabled::Type CollisionEnabled);
|
|
|
|
FFramePackage GetFrameToCheck(ABlasterCharacter* HitCharacter, float HitTime);
|
|
|
|
|
|
|
|
// Hitscan
|
2022-05-27 17:13:59 +00:00
|
|
|
FServerSideRewindResult ConfirmHit(
|
|
|
|
const FFramePackage& Package,
|
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const FVector_NetQuantize HitLocation
|
|
|
|
);
|
|
|
|
|
2022-05-27 22:28:02 +00:00
|
|
|
// Projectile
|
|
|
|
FServerSideRewindResult ProjectileConfirmHit(
|
|
|
|
const FFramePackage& Package,
|
|
|
|
ABlasterCharacter* HitCharacter,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const FVector_NetQuantize100& InitialVelocity,
|
|
|
|
float HitTime
|
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
2022-05-27 22:28:02 +00:00
|
|
|
// Shotgun
|
2022-05-27 17:13:59 +00:00
|
|
|
FShotgunServerSideRewindResult ShotgunConfirmHit(
|
|
|
|
const TArray<FFramePackage>& FramePackages,
|
|
|
|
const FVector_NetQuantize& TraceStart,
|
|
|
|
const TArray<FVector_NetQuantize>& HitLocations
|
|
|
|
);
|
2022-05-28 08:30:24 +00:00
|
|
|
|
2022-05-27 17:13:59 +00:00
|
|
|
private:
|
2022-05-27 09:06:39 +00:00
|
|
|
UPROPERTY()
|
|
|
|
ABlasterCharacter* Character;
|
2022-05-26 15:32:23 +00:00
|
|
|
|
2022-05-27 09:06:39 +00:00
|
|
|
UPROPERTY()
|
|
|
|
ABlasterPlayerController* Controller;
|
2022-05-27 13:36:32 +00:00
|
|
|
|
|
|
|
TDoubleLinkedList<FFramePackage> FrameHistory;
|
|
|
|
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
|
|
float MaxRecordTime = 4.f;
|
2022-05-26 15:32:23 +00:00
|
|
|
};
|