184 - Saving a Frame Package

This commit is contained in:
Kingsmedia 2022-05-27 11:29:32 +02:00
parent a52dc24cdf
commit ac378b01da
5 changed files with 90 additions and 30 deletions

View File

@ -73,74 +73,92 @@ ABlasterCharacter::ABlasterCharacter()
head = CreateDefaultSubobject<UBoxComponent>(TEXT("head"));
head->SetupAttachment(GetMesh(), FName("head"));
head->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("head"), head);
pelvis = CreateDefaultSubobject<UBoxComponent>(TEXT("pelvis"));
pelvis->SetupAttachment(GetMesh(), FName("pelvis"));
pelvis->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("pelvis"), pelvis);
spine_02 = CreateDefaultSubobject<UBoxComponent>(TEXT("spine_02"));
spine_02->SetupAttachment(GetMesh(), FName("spine_02"));
spine_02->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("spine_02"), spine_02);
spine_03 = CreateDefaultSubobject<UBoxComponent>(TEXT("spine_03"));
spine_03->SetupAttachment(GetMesh(), FName("spine_03"));
spine_03->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("spine_03"), spine_03);
upperarm_l = CreateDefaultSubobject<UBoxComponent>(TEXT("upperarm_l"));
upperarm_l->SetupAttachment(GetMesh(), FName("upperarm_l"));
upperarm_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("upperarm_l"), upperarm_l);
upperarm_r = CreateDefaultSubobject<UBoxComponent>(TEXT("upperarm_r"));
upperarm_r->SetupAttachment(GetMesh(), FName("upperarm_r"));
upperarm_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("upperarm_r"), upperarm_r);
lowerarm_l = CreateDefaultSubobject<UBoxComponent>(TEXT("lowerarm_l"));
lowerarm_l->SetupAttachment(GetMesh(), FName("lowerarm_l"));
lowerarm_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("lowerarm_l"), lowerarm_l);
lowerarm_r = CreateDefaultSubobject<UBoxComponent>(TEXT("lowerarm_r"));
lowerarm_r->SetupAttachment(GetMesh(), FName("lowerarm_r"));
lowerarm_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("lowerarm_r"), lowerarm_r);
hand_l = CreateDefaultSubobject<UBoxComponent>(TEXT("hand_l"));
hand_l->SetupAttachment(GetMesh(), FName("hand_l"));
hand_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("hand_l"), hand_l);
hand_r = CreateDefaultSubobject<UBoxComponent>(TEXT("hand_r"));
hand_r->SetupAttachment(GetMesh(), FName("hand_r"));
hand_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("hand_r"), hand_r);
backpack = CreateDefaultSubobject<UBoxComponent>(TEXT("backpack"));
backpack->SetupAttachment(GetMesh(), FName("backpack"));
backpack->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("backpack"), backpack);
blanket = CreateDefaultSubobject<UBoxComponent>(TEXT("blanket"));
blanket->SetupAttachment(GetMesh(), FName("backpack"));
blanket->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("blanket"), blanket);
thigh_l = CreateDefaultSubobject<UBoxComponent>(TEXT("thigh_l"));
thigh_l->SetupAttachment(GetMesh(), FName("thigh_l"));
thigh_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("thigh_l"), thigh_l);
thigh_r = CreateDefaultSubobject<UBoxComponent>(TEXT("thigh_r"));
thigh_r->SetupAttachment(GetMesh(), FName("thigh_r"));
thigh_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("thigh_r"), thigh_r);
calf_l = CreateDefaultSubobject<UBoxComponent>(TEXT("calf_l"));
calf_l->SetupAttachment(GetMesh(), FName("calf_l"));
calf_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("calf_l"), calf_l);
calf_r = CreateDefaultSubobject<UBoxComponent>(TEXT("calf_r"));
calf_r->SetupAttachment(GetMesh(), FName("calf_r"));
calf_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("calf_r"), calf_r);
foot_l = CreateDefaultSubobject<UBoxComponent>(TEXT("foot_l"));
foot_l->SetupAttachment(GetMesh(), FName("foot_l"));
foot_l->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("foot_l"), foot_l);
foot_r = CreateDefaultSubobject<UBoxComponent>(TEXT("foot_r"));
foot_r->SetupAttachment(GetMesh(), FName("foot_r"));
foot_r->SetCollisionEnabled(ECollisionEnabled::NoCollision);
HitCollisionBoxes.Add(FName("foot_r"), foot_r);
}
void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const

View File

@ -46,6 +46,35 @@ public:
void UpdateHUDAmmo();
void SpawnDefaultWeapon();
UPROPERTY()
TMap<FName, class UBoxComponent*> HitCollisionBoxes;
protected:
virtual void BeginPlay() override;
void MoveForward(float Value);
void MoveRight(float Value);
void Turn(float Value);
void LookUp(float Value);
void EquipButtonPressed();
void ReloadButtonPressed();
void CrouchButtonPressed();
void AimButtonPressed();
void AimButtonReleased();
void GrenadeButtonPressed();
void CalculateAO_Pitch();
void AimOffset(float DeltaTime);
void SimProxiesTurn();
virtual void Jump() override;
void FireButtonPressed();
void FireButtonReleased();
void PlayHitReactMontage();
UFUNCTION()
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
// Poll for any relevant classes and initialize them
void PollInit();
// Hit boxes used for server-side rewind
@ -103,33 +132,6 @@ public:
UPROPERTY(EditAnywhere)
UBoxComponent* foot_r;
protected:
virtual void BeginPlay() override;
void MoveForward(float Value);
void MoveRight(float Value);
void Turn(float Value);
void LookUp(float Value);
void EquipButtonPressed();
void ReloadButtonPressed();
void CrouchButtonPressed();
void AimButtonPressed();
void AimButtonReleased();
void GrenadeButtonPressed();
void CalculateAO_Pitch();
void AimOffset(float DeltaTime);
void SimProxiesTurn();
virtual void Jump() override;
void FireButtonPressed();
void FireButtonReleased();
void PlayHitReactMontage();
UFUNCTION()
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
// Poll for any relevant classes and initialize them
void PollInit();
private:
UPROPERTY()

View File

@ -3,6 +3,8 @@
#include "LagCompensationComponent.h"
#include "Components/BoxComponent.h"
ULagCompensationComponent::ULagCompensationComponent()
{
PrimaryComponentTick.bCanEverTick = true;
@ -11,6 +13,43 @@ ULagCompensationComponent::ULagCompensationComponent()
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)

View File

@ -41,11 +41,12 @@ class BLASTER_API ULagCompensationComponent : public UActorComponent
public:
ULagCompensationComponent();
friend ABlasterCharacter;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
void ShowFramePackage(const FFramePackage& Package, const FColor Color);
protected:
virtual void BeginPlay() override;
void SaveFramePackage(FFramePackage& Package);
private: