Add api to force refresh streaming
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "StreamableResource.h"
|
||||
#include "Streaming.h"
|
||||
|
||||
StreamableResource::StreamableResource(StreamingGroup* group)
|
||||
: _group(group)
|
||||
, _isDynamic(true)
|
||||
, _isStreaming(false)
|
||||
, _streamingQuality(1.0f)
|
||||
{
|
||||
ASSERT(_group != nullptr);
|
||||
}
|
||||
|
||||
StreamableResource::~StreamableResource()
|
||||
{
|
||||
StopStreaming();
|
||||
}
|
||||
|
||||
void StreamableResource::StartStreaming(bool isDynamic)
|
||||
{
|
||||
_isDynamic = isDynamic;
|
||||
|
||||
if (_isStreaming == false)
|
||||
{
|
||||
Streaming::Resources.Add(this);
|
||||
_isStreaming = true;
|
||||
}
|
||||
}
|
||||
|
||||
void StreamableResource::StopStreaming()
|
||||
{
|
||||
if (_isStreaming == true)
|
||||
{
|
||||
Streaming::Resources.Remove(this);
|
||||
Streaming = StreamingCache();
|
||||
_isStreaming = false;
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Platform/CriticalSection.h"
|
||||
|
||||
class StreamableResource;
|
||||
|
||||
/// <summary>
|
||||
/// Container for collection of Streamable Resources.
|
||||
/// </summary>
|
||||
class StreamableResourcesCollection
|
||||
{
|
||||
private:
|
||||
|
||||
CriticalSection _locker;
|
||||
Array<StreamableResource*> _resources;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StreamableResourcesCollection"/> class.
|
||||
/// </summary>
|
||||
StreamableResourcesCollection()
|
||||
: _resources(4096)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Event called on new resource added to the collection.
|
||||
/// </summary>
|
||||
Delegate<StreamableResource*> Added;
|
||||
|
||||
/// <summary>
|
||||
/// Event called on new resource added from the collection.
|
||||
/// </summary>
|
||||
Delegate<StreamableResource*> Removed;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of registered resources.
|
||||
/// </summary>
|
||||
/// <returns>The resources count.</returns>
|
||||
int32 ResourcesCount() const
|
||||
{
|
||||
_locker.Lock();
|
||||
const int32 result = _resources.Count();
|
||||
_locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resource at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index.</param>
|
||||
/// <returns>The resource at the given index.</returns>
|
||||
StreamableResource* operator[](int32 index) const
|
||||
{
|
||||
_locker.Lock();
|
||||
StreamableResource* result = _resources.At(index);
|
||||
_locker.Unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Adds the resource to the collection.
|
||||
/// </summary>
|
||||
/// <param name="resource">The resource to add.</param>
|
||||
void Add(StreamableResource* resource)
|
||||
{
|
||||
ASSERT(resource);
|
||||
|
||||
_locker.Lock();
|
||||
ASSERT(_resources.Contains(resource) == false);
|
||||
_resources.Add(resource);
|
||||
_locker.Unlock();
|
||||
|
||||
Added(resource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes resource from the collection.
|
||||
/// </summary>
|
||||
/// <param name="resource">The resource to remove.</param>
|
||||
void Remove(StreamableResource* resource)
|
||||
{
|
||||
ASSERT(resource);
|
||||
|
||||
_locker.Lock();
|
||||
ASSERT(_resources.Contains(resource) == true);
|
||||
_resources.Remove(resource);
|
||||
_locker.Unlock();
|
||||
|
||||
Removed(resource);
|
||||
}
|
||||
};
|
||||
@@ -14,8 +14,9 @@
|
||||
namespace StreamingManagerImpl
|
||||
{
|
||||
DateTime LastUpdateTime(0);
|
||||
CriticalSection UpdateLocker;
|
||||
int32 LastUpdateResourcesIndex = 0;
|
||||
CriticalSection ResourcesLock;
|
||||
Array<StreamableResource*> Resources;
|
||||
}
|
||||
|
||||
using namespace StreamingManagerImpl;
|
||||
@@ -33,7 +34,6 @@ public:
|
||||
|
||||
StreamingManagerService StreamingManagerServiceInstance;
|
||||
|
||||
StreamableResourcesCollection Streaming::Resources;
|
||||
Array<TextureGroup, InlinedAllocation<32>> Streaming::TextureGroups;
|
||||
|
||||
void StreamingSettings::Apply()
|
||||
@@ -46,6 +46,44 @@ void StreamingSettings::Deserialize(DeserializeStream& stream, ISerializeModifie
|
||||
DESERIALIZE(TextureGroups);
|
||||
}
|
||||
|
||||
StreamableResource::StreamableResource(StreamingGroup* group)
|
||||
: _group(group)
|
||||
, _isDynamic(true)
|
||||
, _isStreaming(false)
|
||||
, _streamingQuality(1.0f)
|
||||
{
|
||||
ASSERT(_group != nullptr);
|
||||
}
|
||||
|
||||
StreamableResource::~StreamableResource()
|
||||
{
|
||||
StopStreaming();
|
||||
}
|
||||
|
||||
void StreamableResource::StartStreaming(bool isDynamic)
|
||||
{
|
||||
_isDynamic = isDynamic;
|
||||
if (!_isStreaming)
|
||||
{
|
||||
_isStreaming = true;
|
||||
ResourcesLock.Lock();
|
||||
Resources.Add(this);
|
||||
ResourcesLock.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void StreamableResource::StopStreaming()
|
||||
{
|
||||
if (_isStreaming)
|
||||
{
|
||||
ResourcesLock.Lock();
|
||||
Resources.Remove(this);
|
||||
ResourcesLock.Unlock();
|
||||
Streaming = StreamingCache();
|
||||
_isStreaming = false;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateResource(StreamableResource* resource, DateTime now)
|
||||
{
|
||||
ASSERT(resource && resource->CanBeUpdated());
|
||||
@@ -143,7 +181,8 @@ void StreamingManagerService::Update()
|
||||
// Check if skip update
|
||||
auto now = DateTime::NowUTC();
|
||||
auto delta = now - LastUpdateTime;
|
||||
int32 resourcesCount = Streaming::Resources.ResourcesCount();
|
||||
ScopeLock lock(ResourcesLock);
|
||||
const int32 resourcesCount = Resources.Count();
|
||||
if (resourcesCount == 0 || delta < ManagerUpdatesInterval || GPUDevice::Instance->GetState() != GPUDevice::DeviceState::Ready)
|
||||
return;
|
||||
LastUpdateTime = now;
|
||||
@@ -151,7 +190,6 @@ void StreamingManagerService::Update()
|
||||
PROFILE_CPU();
|
||||
|
||||
// Start update
|
||||
ScopeLock lock(UpdateLocker);
|
||||
int32 resourcesUpdates = Math::Min(MaxResourcesPerUpdate, resourcesCount);
|
||||
|
||||
// Update high priority queue and then rest of the resources
|
||||
@@ -165,7 +203,7 @@ void StreamingManagerService::Update()
|
||||
LastUpdateResourcesIndex = 0;
|
||||
|
||||
// Peek resource
|
||||
const auto resource = Streaming::Resources[LastUpdateResourcesIndex];
|
||||
const auto resource = Resources[LastUpdateResourcesIndex];
|
||||
|
||||
// Try to update it
|
||||
if (now - resource->Streaming.LastUpdate >= ResourceUpdatesInterval && resource->CanBeUpdated())
|
||||
@@ -177,3 +215,12 @@ void StreamingManagerService::Update()
|
||||
|
||||
// TODO: add StreamingManager stats, update time per frame, updates per frame, etc.
|
||||
}
|
||||
|
||||
void Streaming::RequestStreamingUpdate()
|
||||
{
|
||||
PROFILE_CPU();
|
||||
ResourcesLock.Lock();
|
||||
for (auto e : Resources)
|
||||
e->RequestStreamingUpdate();
|
||||
ResourcesLock.Unlock();
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
#include "TextureGroup.h"
|
||||
#include "StreamableResourcesCollection.h"
|
||||
|
||||
/// <summary>
|
||||
/// The content streaming service.
|
||||
@@ -13,13 +13,13 @@ API_CLASS(Static) class FLAXENGINE_API Streaming
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Streaming);
|
||||
|
||||
/// <summary>
|
||||
/// List with all resources
|
||||
/// </summary>
|
||||
static StreamableResourcesCollection Resources;
|
||||
|
||||
/// <summary>
|
||||
/// Textures streaming configuration (per-group).
|
||||
/// </summary>
|
||||
API_FIELD() static Array<TextureGroup, InlinedAllocation<32>> TextureGroups;
|
||||
|
||||
/// <summary>
|
||||
/// Requests the streaming update for all the loaded resources. Use it to refresh content streaming after changing configuration.
|
||||
/// </summary>
|
||||
API_FUNCTION() static void RequestStreamingUpdate();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user