2017-07-19 14:20:32 -07:00
|
|
|
#pragma once
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2015-04-26 18:14:33 +00:00
|
|
|
#include "lc_context.h"
|
2013-08-09 04:57:18 +00:00
|
|
|
#include "lc_mesh.h"
|
|
|
|
#include "lc_math.h"
|
2013-08-15 23:43:18 +00:00
|
|
|
#include "lc_array.h"
|
2019-07-27 16:31:16 -07:00
|
|
|
#include "lc_meshloader.h"
|
2013-08-09 04:57:18 +00:00
|
|
|
|
|
|
|
class PieceInfo;
|
|
|
|
class lcZipFile;
|
2019-07-27 16:31:16 -07:00
|
|
|
class lcLibraryMeshData;
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2014-05-07 22:58:59 +00:00
|
|
|
enum lcZipFileType
|
|
|
|
{
|
|
|
|
LC_ZIPFILE_OFFICIAL,
|
|
|
|
LC_ZIPFILE_UNOFFICIAL,
|
|
|
|
LC_NUM_ZIPFILES
|
|
|
|
};
|
|
|
|
|
2017-11-26 19:21:54 -08:00
|
|
|
enum lcLibraryFolderType
|
|
|
|
{
|
|
|
|
LC_FOLDER_UNOFFICIAL,
|
|
|
|
LC_FOLDER_OFFICIAL,
|
|
|
|
LC_NUM_FOLDERTYPES
|
|
|
|
};
|
|
|
|
|
2017-11-24 19:45:27 -08:00
|
|
|
enum class lcPrimitiveState
|
|
|
|
{
|
|
|
|
NOT_LOADED,
|
|
|
|
LOADING,
|
|
|
|
LOADED
|
|
|
|
};
|
|
|
|
|
2013-08-09 04:57:18 +00:00
|
|
|
class lcLibraryPrimitive
|
|
|
|
{
|
|
|
|
public:
|
2019-07-27 16:31:16 -07:00
|
|
|
explicit lcLibraryPrimitive(QString&& FileName, const char* Name, lcZipFileType ZipFileType, quint32 ZipFileIndex, bool Stud, bool SubFile)
|
2019-06-03 13:23:04 -07:00
|
|
|
: mFileName(std::move(FileName))
|
2013-08-09 04:57:18 +00:00
|
|
|
{
|
2020-12-19 15:10:10 -05:00
|
|
|
strncpy(mName, Name, sizeof(mName)-1);
|
2013-08-09 04:57:18 +00:00
|
|
|
mName[sizeof(mName) - 1] = 0;
|
|
|
|
|
2014-05-07 22:58:59 +00:00
|
|
|
mZipFileType = ZipFileType;
|
2013-08-09 04:57:18 +00:00
|
|
|
mZipFileIndex = ZipFileIndex;
|
2017-11-24 19:45:27 -08:00
|
|
|
mState = lcPrimitiveState::NOT_LOADED;
|
2013-08-09 04:57:18 +00:00
|
|
|
mStud = Stud;
|
|
|
|
mSubFile = SubFile;
|
|
|
|
}
|
|
|
|
|
2019-06-03 13:23:04 -07:00
|
|
|
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
|
2014-05-07 22:58:59 +00:00
|
|
|
{
|
|
|
|
mZipFileType = ZipFileType;
|
|
|
|
mZipFileIndex = ZipFileIndex;
|
|
|
|
}
|
|
|
|
|
2019-09-23 16:55:24 -07:00
|
|
|
void Unload()
|
|
|
|
{
|
|
|
|
mState = lcPrimitiveState::NOT_LOADED;
|
|
|
|
mMeshData.RemoveAll();
|
|
|
|
}
|
|
|
|
|
2019-06-01 19:54:09 -07:00
|
|
|
QString mFileName;
|
2019-02-28 15:47:09 +01:00
|
|
|
char mName[LC_MAXNAME];
|
2014-05-07 22:58:59 +00:00
|
|
|
lcZipFileType mZipFileType;
|
2017-12-02 12:22:04 -08:00
|
|
|
quint32 mZipFileIndex;
|
2017-11-24 19:45:27 -08:00
|
|
|
lcPrimitiveState mState;
|
2013-08-09 04:57:18 +00:00
|
|
|
bool mStud;
|
|
|
|
bool mSubFile;
|
|
|
|
lcLibraryMeshData mMeshData;
|
|
|
|
};
|
|
|
|
|
2017-01-22 19:28:05 -08:00
|
|
|
class lcPiecesLibrary : public QObject
|
2013-08-09 04:57:18 +00:00
|
|
|
{
|
2017-01-22 19:28:05 -08:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-08-09 04:57:18 +00:00
|
|
|
public:
|
|
|
|
lcPiecesLibrary();
|
|
|
|
~lcPiecesLibrary();
|
|
|
|
|
2020-03-22 15:44:41 -07:00
|
|
|
lcPiecesLibrary(const lcPiecesLibrary&) = delete;
|
|
|
|
lcPiecesLibrary(lcPiecesLibrary&&) = delete;
|
|
|
|
lcPiecesLibrary& operator=(const lcPiecesLibrary&) = delete;
|
|
|
|
lcPiecesLibrary& operator=(lcPiecesLibrary&&) = delete;
|
|
|
|
|
2017-11-24 20:00:16 -08:00
|
|
|
bool Load(const QString& LibraryPath, bool ShowProgress);
|
2013-08-09 04:57:18 +00:00
|
|
|
void Unload();
|
2015-01-07 16:52:42 +00:00
|
|
|
void RemoveTemporaryPieces();
|
2015-02-22 02:39:15 +00:00
|
|
|
void RemovePiece(PieceInfo* Info);
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2017-07-23 19:35:18 -07:00
|
|
|
void RenamePiece(PieceInfo* Info, const char* NewName);
|
2016-11-25 17:12:19 -08:00
|
|
|
PieceInfo* FindPiece(const char* PieceName, Project* Project, bool CreatePlaceholder, bool SearchProjectFolder);
|
2017-01-22 19:28:05 -08:00
|
|
|
void LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority);
|
|
|
|
void ReleasePieceInfo(PieceInfo* Info);
|
2014-09-11 19:55:34 +00:00
|
|
|
bool LoadBuiltinPieces();
|
2017-01-22 19:28:05 -08:00
|
|
|
bool LoadPieceData(PieceInfo* Info);
|
|
|
|
void LoadQueuedPiece();
|
|
|
|
void WaitForLoadQueue();
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2017-07-01 17:12:09 -07:00
|
|
|
lcTexture* FindTexture(const char* TextureName, Project* CurrentProject, bool SearchProjectFolder);
|
2013-08-09 04:57:18 +00:00
|
|
|
bool LoadTexture(lcTexture* Texture);
|
2017-07-01 17:12:09 -07:00
|
|
|
void ReleaseTexture(lcTexture* Texture);
|
2017-12-22 05:42:28 -08:00
|
|
|
void QueueTextureUpload(lcTexture* Texture);
|
2018-09-29 19:45:21 -07:00
|
|
|
void UploadTextures(lcContext* Context);
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2017-02-07 18:55:54 -08:00
|
|
|
bool PieceInCategory(PieceInfo* Info, const char* CategoryKeywords) const;
|
2013-08-15 23:43:18 +00:00
|
|
|
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
2017-02-07 18:55:54 -08:00
|
|
|
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
2013-08-15 23:43:18 +00:00
|
|
|
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
|
2019-12-07 09:52:46 -08:00
|
|
|
void GetParts(lcArray<PieceInfo*>& Parts) const;
|
|
|
|
|
2019-12-08 16:54:12 -08:00
|
|
|
std::vector<PieceInfo*> GetPartsFromSet(const std::vector<std::string>& PartIds) const;
|
|
|
|
std::string GetPartId(const PieceInfo* Info) const;
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2019-07-27 16:31:16 -07:00
|
|
|
void GetPrimitiveFile(lcLibraryPrimitive* Primitive, std::function<void(lcFile& File)> Callback);
|
|
|
|
void GetPieceFile(const char* FileName, std::function<void(lcFile& File)> Callback);
|
|
|
|
|
2015-02-28 20:31:57 +00:00
|
|
|
bool IsPrimitive(const char* Name) const
|
|
|
|
{
|
2017-07-23 16:19:09 -07:00
|
|
|
return mPrimitives.find(Name) != mPrimitives.end();
|
2015-02-28 20:31:57 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 16:31:16 -07:00
|
|
|
lcLibraryPrimitive* FindPrimitive(const char* Name) const
|
|
|
|
{
|
|
|
|
const auto PrimitiveIt = mPrimitives.find(Name);
|
|
|
|
return PrimitiveIt != mPrimitives.end() ? PrimitiveIt->second : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoadPrimitive(lcLibraryPrimitive* Primitive);
|
|
|
|
|
2020-12-12 15:21:30 -08:00
|
|
|
bool SupportsStudLogo() const;
|
2019-09-23 16:55:24 -07:00
|
|
|
void SetStudLogo(int StudLogo, bool Reload);
|
2019-09-21 18:47:33 +02:00
|
|
|
|
2019-09-29 12:58:18 -07:00
|
|
|
int GetStudLogo() const
|
|
|
|
{
|
|
|
|
return mStudLogo;
|
|
|
|
}
|
|
|
|
|
2014-03-07 02:39:28 +00:00
|
|
|
void SetOfficialPieces()
|
|
|
|
{
|
2014-05-07 22:58:59 +00:00
|
|
|
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
2019-03-14 12:18:58 -07:00
|
|
|
mNumOfficialPieces = (int)mPieces.size();
|
2014-03-07 02:39:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 16:31:16 -07:00
|
|
|
bool ShouldCancelLoading() const
|
|
|
|
{
|
|
|
|
return mCancelLoading;
|
|
|
|
}
|
|
|
|
|
2016-12-28 13:30:31 -08:00
|
|
|
void ReleaseBuffers(lcContext* Context);
|
2015-04-26 18:14:33 +00:00
|
|
|
void UpdateBuffers(lcContext* Context);
|
2015-11-16 02:41:16 +00:00
|
|
|
void UnloadUnusedParts();
|
2015-02-23 00:50:37 +00:00
|
|
|
|
2017-07-23 19:35:18 -07:00
|
|
|
std::map<std::string, PieceInfo*> mPieces;
|
2017-07-23 16:19:09 -07:00
|
|
|
std::map<std::string, lcLibraryPrimitive*> mPrimitives;
|
2013-08-09 04:57:18 +00:00
|
|
|
int mNumOfficialPieces;
|
|
|
|
|
2019-07-04 17:06:26 -07:00
|
|
|
std::vector<lcTexture*> mTextures;
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2017-05-29 13:31:24 -07:00
|
|
|
QDir mLibraryDir;
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2015-04-26 18:14:33 +00:00
|
|
|
bool mBuffersDirty;
|
|
|
|
lcVertexBuffer mVertexBuffer;
|
|
|
|
lcIndexBuffer mIndexBuffer;
|
|
|
|
|
2017-01-22 19:28:05 -08:00
|
|
|
signals:
|
|
|
|
void PartLoaded(PieceInfo* Info);
|
|
|
|
|
2013-08-09 04:57:18 +00:00
|
|
|
protected:
|
2017-05-29 13:31:24 -07:00
|
|
|
bool OpenArchive(const QString& FileName, lcZipFileType ZipFileType);
|
2020-12-19 11:12:31 -08:00
|
|
|
bool OpenArchive(std::unique_ptr<lcFile> File, lcZipFileType ZipFileType);
|
2017-11-24 20:00:16 -08:00
|
|
|
bool OpenDirectory(const QDir& LibraryDir, bool ShowProgress);
|
2015-07-22 04:00:47 +00:00
|
|
|
void ReadArchiveDescriptions(const QString& OfficialFileName, const QString& UnofficialFileName);
|
2017-11-26 19:21:54 -08:00
|
|
|
void ReadDirectoryDescriptions(const QFileInfoList (&FileLists)[LC_NUM_FOLDERTYPES], bool ShowProgress);
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2017-11-26 19:21:54 -08:00
|
|
|
bool ReadArchiveCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool WriteArchiveCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
2015-07-22 04:00:47 +00:00
|
|
|
bool LoadCacheIndex(const QString& FileName);
|
2017-11-26 19:21:54 -08:00
|
|
|
bool SaveArchiveCacheIndex(const QString& FileName);
|
2013-08-09 04:57:18 +00:00
|
|
|
bool LoadCachePiece(PieceInfo* Info);
|
2015-07-22 04:00:47 +00:00
|
|
|
bool SaveCachePiece(PieceInfo* Info);
|
2017-11-26 19:21:54 -08:00
|
|
|
bool ReadDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool WriteDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
2013-08-09 04:57:18 +00:00
|
|
|
|
2019-09-29 12:58:18 -07:00
|
|
|
bool GetStudLogoFile(lcMemFile& PrimFile, int StudLogo, bool OpenStud);
|
|
|
|
|
2017-01-22 19:28:05 -08:00
|
|
|
QMutex mLoadMutex;
|
|
|
|
QList<QFuture<void>> mLoadFutures;
|
|
|
|
QList<PieceInfo*> mLoadQueue;
|
|
|
|
|
2017-12-22 05:42:28 -08:00
|
|
|
QMutex mTextureMutex;
|
|
|
|
std::vector<lcTexture*> mTextureUploads;
|
|
|
|
|
2019-09-23 16:55:24 -07:00
|
|
|
int mStudLogo;
|
|
|
|
|
2015-07-22 04:00:47 +00:00
|
|
|
QString mCachePath;
|
|
|
|
qint64 mArchiveCheckSum[4];
|
2020-12-13 17:23:05 +01:00
|
|
|
std::unique_ptr<lcZipFile> mZipFiles[LC_NUM_ZIPFILES];
|
2017-03-19 13:12:24 -07:00
|
|
|
bool mHasUnofficial;
|
2017-11-25 12:57:41 -08:00
|
|
|
bool mCancelLoading;
|
2013-08-09 04:57:18 +00:00
|
|
|
};
|
|
|
|
|