Simpler stud reload.

This commit is contained in:
Leonardo Zide 2019-09-23 16:55:24 -07:00
parent f91da8a7ce
commit 66bbb8d9de
5 changed files with 53 additions and 43 deletions

View file

@ -349,7 +349,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
ParseInteger(StudLogo); ParseInteger(StudLogo);
if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO)) if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
{ {
lcGetPiecesLibrary()->SetStudLogo(StudLogo); lcGetPiecesLibrary()->SetStudLogo(StudLogo, false);
} }
} }
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront")) else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront"))
@ -748,10 +748,8 @@ void lcApplication::ShowPreferencesDialog()
if (StudLogoChanged) if (StudLogoChanged)
{ {
lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo); lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
QString ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1); lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, true);
if (!ProjectName.isEmpty())
gMainWindow->OpenProject(ProjectName);
} }
// TODO: printing preferences // TODO: printing preferences

View file

@ -49,6 +49,7 @@ lcPiecesLibrary::lcPiecesLibrary()
mBuffersDirty = false; mBuffersDirty = false;
mHasUnofficial = false; mHasUnofficial = false;
mCancelLoading = false; mCancelLoading = false;
mStudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
} }
lcPiecesLibrary::~lcPiecesLibrary() lcPiecesLibrary::~lcPiecesLibrary()
@ -248,8 +249,6 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
{ {
Unload(); Unload();
mReloadStudLogo = false;
auto LoadCustomColors = []() auto LoadCustomColors = []()
{ {
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG); QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
@ -1153,11 +1152,8 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority)
} }
else else
{ {
bool ReloadStudLogo = Info->mHasLogoStud && mReloadStudLogo; if (Info->AddRef() == 1)
if (Info->AddRef() == 1 || ReloadStudLogo)
{ {
if (ReloadStudLogo)
Info->mState = LC_PIECEINFO_UNLOADED;
if (Priority) if (Priority)
mLoadQueue.prepend(Info); mLoadQueue.prepend(Info);
else else
@ -1557,18 +1553,42 @@ void lcPiecesLibrary::UploadTextures(lcContext* Context)
mTextureUploads.clear(); mTextureUploads.clear();
} }
void lcPiecesLibrary::SetStudLogo(int StudLogo) void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload)
{ {
mReloadStudLogo = true; mStudLogo = StudLogo;
lcSetProfileInt(LC_PROFILE_STUD_LOGO, StudLogo);
std::vector<std::string> Studs { "STUD.DAT", "STUD2.DAT" }; const std::array<const char*, 2> Studs { "STUD.DAT", "STUD2.DAT" };
for (auto const& Stud: Studs)
mLoadMutex.lock();
for (const char* Stud : Studs)
{ {
lcLibraryPrimitive* StudPrim = FindPrimitive(Stud.c_str()); lcLibraryPrimitive* StudPrim = FindPrimitive(Stud);
if (StudPrim) { if (StudPrim)
StudPrim->mReloadStudLogo = mReloadStudLogo; StudPrim->Unload();
mPrimitives[Stud] = StudPrim; }
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); lcMeshLoader MeshLoader(Primitive->mMeshData, true, nullptr, false);
bool SetStudLogo = false; bool SetStudLogo = false;
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
if (mZipFiles[LC_ZIPFILE_OFFICIAL]) if (mZipFiles[LC_ZIPFILE_OFFICIAL])
{ {
@ -1639,13 +1658,12 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
LowPrimitive = FindPrimitive(Name); LowPrimitive = FindPrimitive(Name);
} }
if (StudLogo) if (mStudLogo)
{ {
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat"); bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if (OpenStud || !strcmp(Primitive->mName,"stud.dat")) if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
{ {
Primitive->mReloadStudLogo = false; SetStudLogo = GetStudLogo(PrimFile, mStudLogo, OpenStud);
SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud);
} }
} }
} }
@ -1672,15 +1690,14 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
} }
else else
{ {
if (StudLogo && Primitive->mStud) if (mStudLogo && Primitive->mStud)
{ {
lcMemFile PrimFile; lcMemFile PrimFile;
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat"); bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if (OpenStud || !strcmp(Primitive->mName,"stud.dat")) if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
{ {
Primitive->mReloadStudLogo = false; if (GetStudLogo(PrimFile, mStudLogo, OpenStud))
if (GetStudLogo(PrimFile,StudLogo,OpenStud))
SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED); SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED);
} }
} }

View file

@ -45,7 +45,6 @@ public:
mState = lcPrimitiveState::NOT_LOADED; mState = lcPrimitiveState::NOT_LOADED;
mStud = Stud; mStud = Stud;
mSubFile = SubFile; mSubFile = SubFile;
mReloadStudLogo = false;
} }
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex) void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
@ -54,6 +53,12 @@ public:
mZipFileIndex = ZipFileIndex; mZipFileIndex = ZipFileIndex;
} }
void Unload()
{
mState = lcPrimitiveState::NOT_LOADED;
mMeshData.RemoveAll();
}
QString mFileName; QString mFileName;
char mName[LC_MAXNAME]; char mName[LC_MAXNAME];
lcZipFileType mZipFileType; lcZipFileType mZipFileType;
@ -61,7 +66,6 @@ public:
lcPrimitiveState mState; lcPrimitiveState mState;
bool mStud; bool mStud;
bool mSubFile; bool mSubFile;
bool mReloadStudLogo;
lcLibraryMeshData mMeshData; lcLibraryMeshData mMeshData;
}; };
@ -115,9 +119,9 @@ public:
bool LoadPrimitive(lcLibraryPrimitive* Primitive); 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() void SetOfficialPieces()
{ {
@ -142,7 +146,6 @@ public:
QDir mLibraryDir; QDir mLibraryDir;
bool mReloadStudLogo;
bool mBuffersDirty; bool mBuffersDirty;
lcVertexBuffer mVertexBuffer; lcVertexBuffer mVertexBuffer;
lcIndexBuffer mIndexBuffer; lcIndexBuffer mIndexBuffer;
@ -173,6 +176,8 @@ protected:
QMutex mTextureMutex; QMutex mTextureMutex;
std::vector<lcTexture*> mTextureUploads; std::vector<lcTexture*> mTextureUploads;
int mStudLogo;
QString mCachePath; QString mCachePath;
qint64 mArchiveCheckSum[4]; qint64 mArchiveCheckSum[4];
QString mLibraryFileName; QString mLibraryFileName;

View file

@ -1623,14 +1623,6 @@ bool lcMeshLoader::ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform
if (Primitive) 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)) if (Primitive->mState != lcPrimitiveState::LOADED && !Library->LoadPrimitive(Primitive))
break; break;

View file

@ -453,8 +453,6 @@ bool Project::Load(const QString& FileName)
Model->UpdatePieceInfo(UpdatedModels); Model->UpdatePieceInfo(UpdatedModels);
} }
lcGetPiecesLibrary()->mReloadStudLogo = false;
mModified = false; mModified = false;
return true; return true;