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);
if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
{
lcGetPiecesLibrary()->SetStudLogo(StudLogo);
lcGetPiecesLibrary()->SetStudLogo(StudLogo, false);
}
}
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront"))
@ -748,10 +748,8 @@ void lcApplication::ShowPreferencesDialog()
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

View file

@ -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<std::string> Studs { "STUD.DAT", "STUD2.DAT" };
for (auto const& Stud: Studs)
mStudLogo = StudLogo;
const std::array<const char*, 2> 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);
}
}

View file

@ -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<lcTexture*> mTextureUploads;
int mStudLogo;
QString mCachePath;
qint64 mArchiveCheckSum[4];
QString mLibraryFileName;

View file

@ -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;

View file

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