186 - Rewinding Time

This commit is contained in:
Kingsmedia 2022-05-27 16:06:23 +02:00
parent 61501fc27c
commit bd20b76da7
3 changed files with 57 additions and 0 deletions

View File

@ -301,4 +301,5 @@ public:
FORCEINLINE UAnimMontage* GetReloadMontage() const { return ReloadMontage; }
FORCEINLINE UStaticMeshComponent* GetAttachedGrenade() const { return AttachedGrenade; }
bool IsLocallyReloading();
FORCEINLINE ULagCompensationComponent* GetLagCompensation() const { return LagCompensation; }
};

View File

@ -50,6 +50,61 @@ void ULagCompensationComponent::ShowFramePackage(const FFramePackage& Package, c
}
}
void ULagCompensationComponent::ServerSideRewind(ABlasterCharacter* HitCharacter, const FVector_NetQuantize& TraceStart, const FVector_NetQuantize& HitLocation,
float HitTime)
{
bool bReturn = HitCharacter == nullptr ||
HitCharacter->GetLagCompensation() == nullptr ||
HitCharacter->GetLagCompensation()->FrameHistory.GetHead() == nullptr ||
HitCharacter->GetLagCompensation()->FrameHistory.GetTail() == nullptr;
if (bReturn) return;
// Frame package that we check to verify a hit
FFramePackage FrameToSheck;
bool bShouldInterpolate = true;
const TDoubleLinkedList<FFramePackage>& History = HitCharacter->GetLagCompensation()->FrameHistory;
const float OldestHistoryTime = History.GetTail()->GetValue().Time;
const float NewestHistoryTime = History.GetHead()->GetValue().Time;
if (OldestHistoryTime > HitTime)
{
// Too far back, too laggy to do SSR
return;
}
if (OldestHistoryTime == HitTime)
{
FrameToSheck = History.GetTail()->GetValue();
bShouldInterpolate = false;
}
if (NewestHistoryTime <= HitTime)
{
FrameToSheck = History.GetHead()->GetValue();
bShouldInterpolate = false;
}
auto Younger = History.GetHead();
auto Older = History.GetHead();
while (Older->GetValue().Time > HitTime)
{
if (Older->GetNextNode() == nullptr) break;
Older = Older->GetNextNode();
if (Older->GetValue().Time > HitTime)
{
Younger = Older;
}
}
if (Older->GetValue().Time == HitTime)
{
FrameToSheck = Older->GetValue();
bShouldInterpolate = false;
}
if (bShouldInterpolate) // Why not just check if FrameToCheck == nullptr?
{
// Interpolate between Younger and Older
}
}
void ULagCompensationComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

View File

@ -43,6 +43,7 @@ public:
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;