Search the current path for submodels when opening files.

This commit is contained in:
leo 2016-05-28 17:35:13 +00:00
parent fd225d33d6
commit 61006184d1
5 changed files with 52 additions and 20 deletions

View file

@ -871,6 +871,9 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
lcLibraryMeshData MeshData; lcLibraryMeshData MeshData;
lcArray<lcLibraryTextureMap> TextureStack; lcArray<lcLibraryTextureMap> TextureStack;
bool Loaded = false;
bool SaveCache = false;
if (Info->mZipFileType != LC_NUM_ZIPFILES && mZipFiles[Info->mZipFileType]) if (Info->mZipFileType != LC_NUM_ZIPFILES && mZipFiles[Info->mZipFileType])
{ {
if (LoadCachePiece(Info)) if (LoadCachePiece(Info))
@ -878,15 +881,14 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
lcMemFile PieceFile; lcMemFile PieceFile;
if (!mZipFiles[Info->mZipFileType]->ExtractFile(Info->mZipFileIndex, PieceFile)) if (mZipFiles[Info->mZipFileType]->ExtractFile(Info->mZipFileIndex, PieceFile))
return false; {
const char* OldLocale = setlocale(LC_NUMERIC, "C");
Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
setlocale(LC_NUMERIC, OldLocale);
}
const char* OldLocale = setlocale(LC_NUMERIC, "C"); SaveCache = Loaded && (Info->mZipFileType == LC_ZIPFILE_OFFICIAL);
bool Ret = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
setlocale(LC_NUMERIC, OldLocale);
if (!Ret)
return false;
} }
else else
{ {
@ -899,20 +901,33 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
sprintf(FileName, "%sparts/%s.dat", mLibraryPath, Name); sprintf(FileName, "%sparts/%s.dat", mLibraryPath, Name);
if (!PieceFile.Open(FileName, "rt")) if (PieceFile.Open(FileName, "rt"))
return false; {
const char* OldLocale = setlocale(LC_NUMERIC, "C");
const char* OldLocale = setlocale(LC_NUMERIC, "C"); Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
bool Ret = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true); setlocale(LC_NUMERIC, OldLocale);
setlocale(LC_NUMERIC, OldLocale); }
if (!Ret)
return false;
} }
if (!Loaded && !mCurrentModelPath.isEmpty())
{
QFileInfo FileInfo(QDir(mCurrentModelPath), Info->m_strName);
lcDiskFile PieceFile;
if (PieceFile.Open(FileInfo.absoluteFilePath().toLatin1().constData(), "rt")) // todo: qstring
{
const char* OldLocale = setlocale(LC_NUMERIC, "C");
Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
setlocale(LC_NUMERIC, OldLocale);
}
}
if (!Loaded)
return false;
CreateMesh(Info, MeshData); CreateMesh(Info, MeshData);
if (mZipFiles[LC_ZIPFILE_OFFICIAL]) if (SaveCache)
SaveCachePiece(Info); SaveCachePiece(Info);
return true; return true;

View file

@ -158,6 +158,11 @@ public:
mNumOfficialPieces = mPieces.GetSize(); mNumOfficialPieces = mPieces.GetSize();
} }
void SetCurrentModelPath(const QString& ModelPath)
{
mCurrentModelPath = ModelPath;
}
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, lcuint32 CurrentColorCode, lcArray<lcLibraryTextureMap>& TextureStack, lcLibraryMeshData& MeshData, lcMeshDataType MeshDataType, bool Optimize); bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, lcuint32 CurrentColorCode, lcArray<lcLibraryTextureMap>& TextureStack, lcLibraryMeshData& MeshData, lcMeshDataType MeshDataType, bool Optimize);
lcMesh* CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData); lcMesh* CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData);
void UpdateBuffers(lcContext* Context); void UpdateBuffers(lcContext* Context);
@ -192,6 +197,7 @@ protected:
bool LoadPrimitive(int PrimitiveIndex); bool LoadPrimitive(int PrimitiveIndex);
QString mCachePath; QString mCachePath;
QString mCurrentModelPath;
qint64 mArchiveCheckSum[4]; qint64 mArchiveCheckSum[4];
char mLibraryFileName[LC_MAXPATH]; char mLibraryFileName[LC_MAXPATH];
char mUnofficialFileName[LC_MAXPATH]; char mUnofficialFileName[LC_MAXPATH];

View file

@ -1848,6 +1848,8 @@ void lcMainWindow::NewProject()
if (!SaveProjectIfModified()) if (!SaveProjectIfModified())
return; return;
lcGetPiecesLibrary()->SetCurrentModelPath(QString());
Project* NewProject = new Project(); Project* NewProject = new Project();
g_App->SetProject(NewProject); g_App->SetProject(NewProject);
lcGetPiecesLibrary()->UnloadUnusedParts(); lcGetPiecesLibrary()->UnloadUnusedParts();

View file

@ -122,8 +122,13 @@ void PieceInfo::Load()
return; return;
else if (mFlags & LC_PIECE_PLACEHOLDER) else if (mFlags & LC_PIECE_PLACEHOLDER)
{ {
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES; if (lcGetPiecesLibrary()->LoadPiece(this))
mBoundingBox = gPlaceholderMesh->mBoundingBox; mFlags &= ~LC_PIECE_PLACEHOLDER;
else
{
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
mBoundingBox = gPlaceholderMesh->mBoundingBox;
}
} }
else else
{ {

View file

@ -210,6 +210,8 @@ bool Project::Load(const QString& FileName)
QFileInfo FileInfo(FileName); QFileInfo FileInfo(FileName);
QString Extension = FileInfo.suffix().toLower(); QString Extension = FileInfo.suffix().toLower();
lcGetPiecesLibrary()->SetCurrentModelPath(FileInfo.absolutePath());
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd")) if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
{ {
QByteArray FileData = File.readAll(); QByteArray FileData = File.readAll();
@ -284,6 +286,8 @@ bool Project::Save(const QString& FileName)
return false; return false;
} }
lcGetPiecesLibrary()->SetCurrentModelPath(QFileInfo(FileName).absolutePath());
QTextStream Stream(&File); QTextStream Stream(&File);
bool MPD = mModels.GetSize() > 1; bool MPD = mModels.GetSize() > 1;