blaster/Source/Blaster/Components/LagCompensationComponent.h

67 lines
1.5 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Components/ActorComponent.h"
#include "LagCompensationComponent.generated.h"
USTRUCT(BlueprintType)
struct FBoxInformation
{
GENERATED_BODY()
UPROPERTY()
FVector Location;
UPROPERTY()
FRotator Rotation;
UPROPERTY()
FVector BoxExtend;
};
USTRUCT(BlueprintType)
struct FFramePackage
{
GENERATED_BODY()
UPROPERTY()
float Time;
TMap<FName, FBoxInformation> HitBoxInfo;
};
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BLASTER_API ULagCompensationComponent : public UActorComponent
{
GENERATED_BODY()
public:
ULagCompensationComponent();
friend ABlasterCharacter;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
void ShowFramePackage(const FFramePackage& Package, const FColor Color);
void ServerSideRewind(class ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart, const FVector_NetQuantize& HitLocation, float HitTime);
protected:
virtual void BeginPlay() override;
void SaveFramePackage(FFramePackage& Package);
FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime);
private:
UPROPERTY()
ABlasterCharacter* Character;
UPROPERTY()
ABlasterPlayerController* Controller;
TDoubleLinkedList<FFramePackage> FrameHistory;
UPROPERTY(EditAnywhere)
float MaxRecordTime = 4.f;
};