RealtimeStyleTransferRuntime/Source/LyraGame/Replays/AsyncAction_QueryReplays.cpp

73 lines
2.2 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
2022-09-13 07:18:28 +00:00
#include "Replays/AsyncAction_QueryReplays.h"
#include "Containers/Array.h"
#include "Containers/UnrealString.h"
#include "CoreTypes.h"
2022-05-23 18:41:30 +00:00
#include "GameFramework/PlayerController.h"
2022-09-13 07:18:28 +00:00
#include "LyraReplaySubsystem.h"
#include "Misc/DateTime.h"
#include "Misc/NetworkVersion.h"
#include "NetworkReplayStreaming.h"
#include "Templates/Sorting.h"
#include "UObject/WeakObjectPtr.h"
2022-05-23 18:41:30 +00:00
UAsyncAction_QueryReplays::UAsyncAction_QueryReplays(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
UAsyncAction_QueryReplays* UAsyncAction_QueryReplays::QueryReplays(APlayerController* InPlayerController)
{
UAsyncAction_QueryReplays* Action = nullptr;
if (InPlayerController != nullptr)
{
Action = NewObject<UAsyncAction_QueryReplays>();
Action->PlayerController = InPlayerController;
}
return Action;
}
void UAsyncAction_QueryReplays::Activate()
{
ReplayStreamer = FNetworkReplayStreaming::Get().GetFactory().CreateReplayStreamer();
ResultList = NewObject<ULyraReplayList>();
if (ReplayStreamer.IsValid())
{
FNetworkReplayVersion EnumerateStreamsVersion = FNetworkVersion::GetReplayVersion();
ReplayStreamer->EnumerateStreams(EnumerateStreamsVersion, INDEX_NONE, FString(), TArray<FString>(), FEnumerateStreamsCallback::CreateUObject(this, &ThisClass::OnEnumerateStreamsComplete));
}
else
{
QueryComplete.Broadcast(ResultList);
}
}
void UAsyncAction_QueryReplays::OnEnumerateStreamsComplete(const FEnumerateStreamsResult& Result)
{
for (const FNetworkReplayStreamInfo& StreamInfo : Result.FoundStreams)
{
ULyraReplayListEntry* NewReplayEntry = NewObject<ULyraReplayListEntry>(ResultList);
NewReplayEntry->StreamInfo = StreamInfo;
ResultList->Results.Add(NewReplayEntry);
}
// Sort demo names by date
struct FCompareDateTime
{
FORCEINLINE bool operator()(const ULyraReplayListEntry& A, const ULyraReplayListEntry& B) const
{
return A.StreamInfo.Timestamp.GetTicks() > B.StreamInfo.Timestamp.GetTicks();
}
};
Sort(ResultList->Results.GetData(), ResultList->Results.Num(), FCompareDateTime());
QueryComplete.Broadcast(ResultList);
}