There was one question on that, that died.
So my question does anyone use it? and are there examples on how to use it?
Thanx
There was one question on that, that died.
So my question does anyone use it? and are there examples on how to use it?
Thanx
I’ve never had a use for it, but in the UE5.01 source code, in ImagePlateFileSequence.cpp line 279, that bit of code looks like a good example:
namespace ImagePlateFrameCache
{
struct FPendingFrame;
struct FCachedFrame
{
/** The frame number to which this frame relates */
int32 FrameNumber;
/** Optional promise that has been made to the data (stores the loaded result) */
TOptional<TPromise<FImagePlateSourceFrame>> FrameData;
/** Future that can be supplied to clients who wish to use this frame. Always valid where FrameData is */
TSharedFuture<FImagePlateSourceFrame> Future;
FCachedFrame(int32 InFrameNumber) : FrameNumber(InFrameNumber) {}
~FCachedFrame()
{
// If something was waiting on this cached frame, we have to fulfil it with some empty data
if (Future.IsValid() && !Future.IsReady())
{
FrameData->SetValue(FImagePlateSourceFrame());
}
}
// non-copyable
FCachedFrame(const FCachedFrame&)=delete;
FCachedFrame& operator=(const FCachedFrame&)=delete;
// moveable
FCachedFrame(FCachedFrame&&)=default;
FCachedFrame& operator=(FCachedFrame&&)=default;
/** Get a future to this frame's data */
TSharedFuture<FImagePlateSourceFrame> GetFrameData()
{
if (!FrameData.IsSet())
{
FrameData.Emplace();
Future = FrameData->GetFuture().Share();
}
return Future;
}
/** Set this frame's data */
void SetFrameData(FImagePlateSourceFrame In)
{
if (!FrameData.IsSet())
{
FrameData.Emplace();
Future = FrameData->GetFuture().Share();
}
if (ensureAlways(!Future.IsReady()))
{
FrameData->SetValue(In);
}
}
};
/** Implementation of a simple frame cache */
struct FImagePlateSequenceCache : TSharedFromThis<FImagePlateSequenceCache, ESPMode::ThreadSafe>
{
FImagePlateSequenceCache(const FString& InSequencePath, const FString& InWildcard, float Framerate);
/** Set the current cached frame range, and return a future to the current frame's data */
TSharedFuture<FImagePlateSourceFrame> GetPrecachedFrame(float Time, int32 LeadingPrecacheFrames, int32 TrailingPrecacheFrames);
/** Set the frame data for the specified frame number */
void SetFrameData(int32 FrameNumber, FImagePlateSourceFrame SourceData);
/** Query for uncached frames that need to be loaded */
void GetUncachedFrames(TArray<FPendingFrame>& OutFrames, int32 MaxToAdd);
/** Return how many total frames there are in the sequence */
int32 GetNumFrames() const;
/** Specify that the supplied frame number is going to be loaded */
void OnPreloadFrame(int32 FrameNumber);
private:
/** Array of frames that are pending load - only ever manipulated and read by the loader thread */
TArray<int32> OutstandingFrameNumbers;
// Critical section to guard against any threaded access to the class
mutable FCriticalSection CriticalSection;
/** Contiguous array of cached frames for the current range */
TArray<FCachedFrame> CachedFrames;
/** The frame number we're currently interested in */
int32 CurrentFrameNumber;
/** Cache range bounds */
int32 MinCacheRange, MaxCacheRange;
/** Contiguous array of frame filenames */
TArray<FString> FrameFilenames;
/** Framerate at which to display the above frames */
float Framerate;
};
Thank you, let me investigate that code.