mirror of
https://github.com/leozide/leocad.git
synced 2026-10-27 06:20:55 +00:00
Simplify streaming asset priorities to promotion only
Keep each pending mesh and texture request at its highest requested priority until it completes or is cancelled. Use one promotion helper for visible requests and synchronous waits, propagating promotions to pending textures without lowering priorities required by shared work. Remove outgoing-project demotion and restoration during file opening and LDD import. Existing reference counts continue to cancel unused queued work and preserve assets shared with the incoming project or other views. Validation: macOS Debug build, git diff --check, 16 priority/cancellation checks, and 199 bounds, external-project undo, and output regression checks.
This commit is contained in:
1 parent
669467d305
commit
622774f254
5 files changed
+12
-100
No files matched your search
@@ -40,7 +40,7 @@ bool lcAssetLoader::LoadPieceInfo(PieceInfo* Info, lcPieceLoadFlags Flags)
|
||||
mQueueMutex.lock();
|
||||
const auto It = mRequests.find(Info);
|
||||
if (It != mRequests.end())
|
||||
SetRequestPriorityLocked(It->second, Priority::Visible);
|
||||
PromoteRequestPriorityLocked(It->second, Priority::Visible);
|
||||
mQueueMutex.unlock();
|
||||
}
|
||||
|
||||
@@ -218,52 +218,9 @@ void lcAssetLoader::ReloadSynthMeshes()
|
||||
Piece->RefreshGeneratedMesh();
|
||||
}
|
||||
|
||||
void lcAssetLoader::SetPieceRequestsVisible(const std::vector<PieceInfo*>& Parts, bool Visible)
|
||||
void lcAssetLoader::PromoteRequestPriorityLocked(const std::shared_ptr<Request>& RequestedPart, Priority LoadPriority)
|
||||
{
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
|
||||
const Priority LoadPriority = Visible ? Priority::Visible : Priority::Background;
|
||||
const std::unordered_set<PieceInfo*> Included(Parts.begin(), Parts.end());
|
||||
|
||||
mQueueMutex.lock();
|
||||
|
||||
for (PieceInfo* Info : Parts)
|
||||
{
|
||||
const auto It = mRequests.find(Info);
|
||||
|
||||
if (It != mRequests.end())
|
||||
SetRequestPriorityLocked(It->second, LoadPriority);
|
||||
}
|
||||
|
||||
for (const SynthRequestMap::value_type& Entry : mSynthRequests)
|
||||
{
|
||||
const std::shared_ptr<SynthRequest>& RequestedSynth = Entry.second;
|
||||
|
||||
if (Included.find(RequestedSynth->Piece->mPieceInfo) == Included.end() || RequestedSynth->LoadPriority == Priority::Blocking)
|
||||
continue;
|
||||
|
||||
RequestedSynth->LoadPriority = LoadPriority;
|
||||
|
||||
if (RequestedSynth->StagedMesh)
|
||||
for (const lcMeshLod& Lod : RequestedSynth->StagedMesh->mLods)
|
||||
for (int SectionIdx = 0; SectionIdx < Lod.NumSections; SectionIdx++)
|
||||
{
|
||||
const TextureRequestMap::iterator TextureIt = mTextureRequests.find(Lod.Sections[SectionIdx].Texture);
|
||||
|
||||
if (TextureIt != mTextureRequests.end() && TextureIt->second->LoadPriority != Priority::Blocking)
|
||||
TextureIt->second->LoadPriority = LoadPriority;
|
||||
}
|
||||
}
|
||||
|
||||
mQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void lcAssetLoader::SetRequestPriorityLocked(const std::shared_ptr<Request>& RequestedPart, Priority LoadPriority)
|
||||
{
|
||||
if (RequestedPart->LoadPriority == Priority::Blocking && LoadPriority != Priority::Blocking)
|
||||
return;
|
||||
|
||||
RequestedPart->LoadPriority = LoadPriority;
|
||||
RequestedPart->LoadPriority = std::max(RequestedPart->LoadPriority, LoadPriority);
|
||||
|
||||
if (!RequestedPart->StagedMesh)
|
||||
return;
|
||||
@@ -274,8 +231,8 @@ void lcAssetLoader::SetRequestPriorityLocked(const std::shared_ptr<Request>& Req
|
||||
{
|
||||
const auto It = mTextureRequests.find(Lod.Sections[SectionIdx].Texture);
|
||||
|
||||
if (It != mTextureRequests.end() && (It->second->LoadPriority != Priority::Blocking || LoadPriority == Priority::Blocking))
|
||||
It->second->LoadPriority = LoadPriority;
|
||||
if (It != mTextureRequests.end())
|
||||
It->second->LoadPriority = std::max(It->second->LoadPriority, RequestedPart->LoadPriority);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,8 +297,7 @@ void lcAssetLoader::QueuePieceLocked(PieceInfo* Info, Priority LoadPriority)
|
||||
|
||||
if (Existing != mRequests.end())
|
||||
{
|
||||
if (Existing->second->LoadPriority < LoadPriority)
|
||||
Existing->second->LoadPriority = LoadPriority;
|
||||
PromoteRequestPriorityLocked(Existing->second, LoadPriority);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1366,21 +1322,7 @@ bool lcAssetLoader::WaitForRequest(PieceInfo* Info)
|
||||
{
|
||||
RequestedPart = It->second;
|
||||
|
||||
It->second->LoadPriority = Priority::Blocking;
|
||||
|
||||
if (It->second->StagedMesh)
|
||||
{
|
||||
for (const lcMeshLod& Lod : It->second->StagedMesh->mLods)
|
||||
{
|
||||
for (int SectionIdx = 0; SectionIdx < Lod.NumSections; SectionIdx++)
|
||||
{
|
||||
const auto TextureIt = mTextureRequests.find(Lod.Sections[SectionIdx].Texture);
|
||||
|
||||
if (TextureIt != mTextureRequests.end())
|
||||
TextureIt->second->LoadPriority = Priority::Blocking;
|
||||
}
|
||||
}
|
||||
}
|
||||
PromoteRequestPriorityLocked(RequestedPart, Priority::Blocking);
|
||||
}
|
||||
StartWorkersLocked();
|
||||
}
|
||||
@@ -1450,21 +1392,7 @@ bool lcAssetLoader::EnsurePiecesReady(const std::vector<PieceInfo*>& Parts)
|
||||
if (It == mRequests.end())
|
||||
continue;
|
||||
|
||||
It->second->LoadPriority = Priority::Blocking;
|
||||
|
||||
if (It->second->StagedMesh)
|
||||
{
|
||||
for (const lcMeshLod& Lod : It->second->StagedMesh->mLods)
|
||||
{
|
||||
for (int SectionIdx = 0; SectionIdx < Lod.NumSections; SectionIdx++)
|
||||
{
|
||||
const auto TextureIt = mTextureRequests.find(Lod.Sections[SectionIdx].Texture);
|
||||
|
||||
if (TextureIt != mTextureRequests.end())
|
||||
TextureIt->second->LoadPriority = Priority::Blocking;
|
||||
}
|
||||
}
|
||||
}
|
||||
PromoteRequestPriorityLocked(It->second, Priority::Blocking);
|
||||
}
|
||||
|
||||
StartWorkersLocked();
|
||||
|
||||
@@ -84,7 +84,6 @@ public:
|
||||
void ReloadSynthMeshes();
|
||||
void QueueModelPiece(PieceInfo* Info);
|
||||
void InvalidatePiece(PieceInfo* Info);
|
||||
void SetPieceRequestsVisible(const std::vector<PieceInfo*>& Parts, bool Visible);
|
||||
bool EnsureTextureReady(lcTexture* Texture);
|
||||
void WaitForLoadQueue();
|
||||
void CancelAndDrain();
|
||||
@@ -96,6 +95,7 @@ public:
|
||||
private:
|
||||
enum class Priority
|
||||
{
|
||||
// Requests only promote; the priority lasts until completion or cancellation.
|
||||
Background, // Ordinary queued asset work.
|
||||
Visible, // Assets requested for the visible model.
|
||||
Blocking // Assets needed by a synchronous wait.
|
||||
@@ -183,7 +183,7 @@ private:
|
||||
};
|
||||
|
||||
void QueuePieceLocked(PieceInfo* Info, Priority LoadPriority);
|
||||
void SetRequestPriorityLocked(const std::shared_ptr<Request>& RequestedPart, Priority LoadPriority);
|
||||
void PromoteRequestPriorityLocked(const std::shared_ptr<Request>& RequestedPart, Priority LoadPriority);
|
||||
void QueueTexture(lcTexture* Texture, Priority LoadPriority);
|
||||
static QString TextureFailureMessage(const lcTexture* Texture);
|
||||
void CancelUnusedTextureRequests();
|
||||
|
||||
@@ -1662,11 +1662,6 @@ void lcPiecesLibrary::InvalidatePiece(PieceInfo* Info)
|
||||
}
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::SetPieceRequestsVisible(const std::vector<PieceInfo*>& Parts, bool Visible)
|
||||
{
|
||||
mAssetLoader->SetPieceRequestsVisible(Parts, Visible);
|
||||
}
|
||||
|
||||
bool lcPiecesLibrary::EnsureTextureReady(lcTexture* Texture)
|
||||
{
|
||||
return mAssetLoader->EnsureTextureReady(Texture);
|
||||
|
||||
@@ -192,7 +192,6 @@ public:
|
||||
QString GetSynthMeshError(const lcPiece* Piece) const;
|
||||
void QueueModelPiece(PieceInfo* Info);
|
||||
void InvalidatePiece(PieceInfo* Info);
|
||||
void SetPieceRequestsVisible(const std::vector<PieceInfo*>& Parts, bool Visible);
|
||||
bool EnsureTextureReady(lcTexture* Texture);
|
||||
void ReleasePieceInfo(PieceInfo* Info);
|
||||
void AddPieceReference(PieceInfo* Info);
|
||||
|
||||
@@ -2641,10 +2641,6 @@ void lcMainWindow::OpenRecentProject(int RecentFileIndex)
|
||||
|
||||
bool lcMainWindow::OpenProjectFile(const QString& FileName)
|
||||
{
|
||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
const std::vector<PieceInfo*> PreviousParts = lcGetActiveProject()->GetRequiredPieces();
|
||||
Library->SetPieceRequestsVisible(PreviousParts, false);
|
||||
|
||||
Project* NewProject = new Project();
|
||||
|
||||
if (NewProject->Load(FileName, true))
|
||||
@@ -2657,8 +2653,7 @@ bool lcMainWindow::OpenProjectFile(const QString& FileName)
|
||||
}
|
||||
|
||||
delete NewProject;
|
||||
Library->RemoveTemporaryPieces();
|
||||
Library->SetPieceRequestsVisible(PreviousParts, true);
|
||||
lcGetPiecesLibrary()->RemoveTemporaryPieces();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2723,10 +2718,6 @@ void lcMainWindow::ImportLDD()
|
||||
if (LoadFileName.isEmpty())
|
||||
return;
|
||||
|
||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
const std::vector<PieceInfo*> PreviousParts = lcGetActiveProject()->GetRequiredPieces();
|
||||
Library->SetPieceRequestsVisible(PreviousParts, false);
|
||||
|
||||
Project* NewProject = new Project();
|
||||
|
||||
if (NewProject->ImportLDD(LoadFileName))
|
||||
@@ -2737,8 +2728,7 @@ void lcMainWindow::ImportLDD()
|
||||
else
|
||||
{
|
||||
delete NewProject;
|
||||
Library->RemoveTemporaryPieces();
|
||||
Library->SetPieceRequestsVisible(PreviousParts, true);
|
||||
lcGetPiecesLibrary()->RemoveTemporaryPieces();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user