From 66bbb8d9de468847203297ef1d67e4ddc941d8f3 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 23 Sep 2019 16:55:24 -0700 Subject: [PATCH] Simpler stud reload. --- common/lc_application.cpp | 10 +++---- common/lc_library.cpp | 61 +++++++++++++++++++++++++-------------- common/lc_library.h | 15 ++++++---- common/lc_meshloader.cpp | 8 ----- common/project.cpp | 2 -- 5 files changed, 53 insertions(+), 43 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index ad003e60..abcbe9d1 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -349,7 +349,7 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& ParseInteger(StudLogo); if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO)) { - lcGetPiecesLibrary()->SetStudLogo(StudLogo); + lcGetPiecesLibrary()->SetStudLogo(StudLogo, false); } } else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront")) @@ -746,12 +746,10 @@ void lcApplication::ShowPreferencesDialog() } } - if (StudLogoChanged) + if (StudLogoChanged) { - lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo); - QString ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1); - if (!ProjectName.isEmpty()) - gMainWindow->OpenProject(ProjectName); + lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo); + lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, true); } // TODO: printing preferences diff --git a/common/lc_library.cpp b/common/lc_library.cpp index e7de721f..27232cc8 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -49,6 +49,7 @@ lcPiecesLibrary::lcPiecesLibrary() mBuffersDirty = false; mHasUnofficial = false; mCancelLoading = false; + mStudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO); } lcPiecesLibrary::~lcPiecesLibrary() @@ -248,8 +249,6 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress) { Unload(); - mReloadStudLogo = false; - auto LoadCustomColors = []() { QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG); @@ -1153,11 +1152,8 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority) } else { - bool ReloadStudLogo = Info->mHasLogoStud && mReloadStudLogo; - if (Info->AddRef() == 1 || ReloadStudLogo) + if (Info->AddRef() == 1) { - if (ReloadStudLogo) - Info->mState = LC_PIECEINFO_UNLOADED; if (Priority) mLoadQueue.prepend(Info); else @@ -1557,18 +1553,42 @@ void lcPiecesLibrary::UploadTextures(lcContext* Context) mTextureUploads.clear(); } -void lcPiecesLibrary::SetStudLogo(int StudLogo) +void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload) { - mReloadStudLogo = true; - lcSetProfileInt(LC_PROFILE_STUD_LOGO, StudLogo); - std::vector Studs { "STUD.DAT", "STUD2.DAT" }; - for (auto const& Stud: Studs) + mStudLogo = StudLogo; + + const std::array Studs { "STUD.DAT", "STUD2.DAT" }; + + mLoadMutex.lock(); + + for (const char* Stud : Studs) { - lcLibraryPrimitive* StudPrim = FindPrimitive(Stud.c_str()); - if (StudPrim) { - StudPrim->mReloadStudLogo = mReloadStudLogo; - mPrimitives[Stud] = StudPrim; + lcLibraryPrimitive* StudPrim = FindPrimitive(Stud); + if (StudPrim) + StudPrim->Unload(); + } + + mLoadMutex.unlock(); + + if (Reload) + { + mLoadMutex.lock(); + + for (const auto& PieceIt : mPieces) + { + PieceInfo* Info = PieceIt.second; + + if (Info->mState == LC_PIECEINFO_LOADED && Info->mHasLogoStud) + { + Info->Unload(); + mLoadQueue.append(Info); + mLoadFutures.append(QtConcurrent::run([this]() { LoadQueuedPiece(); })); + } } + + mLoadMutex.unlock(); + + WaitForLoadQueue(); } } @@ -1620,7 +1640,6 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive) lcMeshLoader MeshLoader(Primitive->mMeshData, true, nullptr, false); bool SetStudLogo = false; - int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO); if (mZipFiles[LC_ZIPFILE_OFFICIAL]) { @@ -1639,13 +1658,12 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive) LowPrimitive = FindPrimitive(Name); } - if (StudLogo) + if (mStudLogo) { bool OpenStud = !strcmp(Primitive->mName,"stud2.dat"); if (OpenStud || !strcmp(Primitive->mName,"stud.dat")) { - Primitive->mReloadStudLogo = false; - SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud); + SetStudLogo = GetStudLogo(PrimFile, mStudLogo, OpenStud); } } } @@ -1672,15 +1690,14 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive) } else { - if (StudLogo && Primitive->mStud) + if (mStudLogo && Primitive->mStud) { lcMemFile PrimFile; bool OpenStud = !strcmp(Primitive->mName,"stud2.dat"); if (OpenStud || !strcmp(Primitive->mName,"stud.dat")) { - Primitive->mReloadStudLogo = false; - if (GetStudLogo(PrimFile,StudLogo,OpenStud)) + if (GetStudLogo(PrimFile, mStudLogo, OpenStud)) SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED); } } diff --git a/common/lc_library.h b/common/lc_library.h index 2d705713..c247055b 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -45,7 +45,6 @@ public: mState = lcPrimitiveState::NOT_LOADED; mStud = Stud; mSubFile = SubFile; - mReloadStudLogo = false; } void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex) @@ -54,6 +53,12 @@ public: mZipFileIndex = ZipFileIndex; } + void Unload() + { + mState = lcPrimitiveState::NOT_LOADED; + mMeshData.RemoveAll(); + } + QString mFileName; char mName[LC_MAXNAME]; lcZipFileType mZipFileType; @@ -61,7 +66,6 @@ public: lcPrimitiveState mState; bool mStud; bool mSubFile; - bool mReloadStudLogo; lcLibraryMeshData mMeshData; }; @@ -115,9 +119,9 @@ public: bool LoadPrimitive(lcLibraryPrimitive* Primitive); - bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false); + bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud); - void SetStudLogo(int StudLogo); + void SetStudLogo(int StudLogo, bool Reload); void SetOfficialPieces() { @@ -142,7 +146,6 @@ public: QDir mLibraryDir; - bool mReloadStudLogo; bool mBuffersDirty; lcVertexBuffer mVertexBuffer; lcIndexBuffer mIndexBuffer; @@ -173,6 +176,8 @@ protected: QMutex mTextureMutex; std::vector mTextureUploads; + int mStudLogo; + QString mCachePath; qint64 mArchiveCheckSum[4]; QString mLibraryFileName; diff --git a/common/lc_meshloader.cpp b/common/lc_meshloader.cpp index bf6abce7..14bd5e31 100644 --- a/common/lc_meshloader.cpp +++ b/common/lc_meshloader.cpp @@ -1623,14 +1623,6 @@ bool lcMeshLoader::ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform if (Primitive) { - if (Primitive->mStud && - Primitive->mReloadStudLogo && - Primitive->mState == lcPrimitiveState::LOADED ) - { - Primitive->mMeshData.RemoveAll(); - Primitive->mState = lcPrimitiveState::NOT_LOADED; - } - if (Primitive->mState != lcPrimitiveState::LOADED && !Library->LoadPrimitive(Primitive)) break; diff --git a/common/project.cpp b/common/project.cpp index a8295fd5..9d18279b 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -453,8 +453,6 @@ bool Project::Load(const QString& FileName) Model->UpdatePieceInfo(UpdatedModels); } - lcGetPiecesLibrary()->mReloadStudLogo = false; - mModified = false; return true;