blaster/Source/Blaster/Components/LagCompensationComponent.cpp

60 lines
1.5 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "LagCompensationComponent.h"
#include "Components/BoxComponent.h"
ULagCompensationComponent::ULagCompensationComponent()
{
PrimaryComponentTick.bCanEverTick = true;
}
void ULagCompensationComponent::BeginPlay()
{
Super::BeginPlay();
FFramePackage Package;
SaveFramePackage(Package);
ShowFramePackage(Package, FColor::Orange);
}
void ULagCompensationComponent::SaveFramePackage(FFramePackage& Package)
{
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetOwner()) : Character;
if (Character)
{
Package.Time = GetWorld()->GetTimeSeconds();
for (auto& BoxPair : Character->HitCollisionBoxes)
{
FBoxInformation BoxInformation;
BoxInformation.Location = BoxPair.Value->GetComponentLocation();
BoxInformation.Rotation = BoxPair.Value->GetComponentRotation();
BoxInformation.BoxExtend = BoxPair.Value->GetScaledBoxExtent();
Package.HitBoxInfo.Add(BoxPair.Key, BoxInformation);
}
}
}
void ULagCompensationComponent::ShowFramePackage(const FFramePackage& Package, const FColor Color)
{
for (auto& BoxInfo : Package.HitBoxInfo)
{
DrawDebugBox(
GetWorld(),
BoxInfo.Value.Location,
BoxInfo.Value.BoxExtend,
FQuat(BoxInfo.Value.Rotation),
Color,
true
);
}
}
void ULagCompensationComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}