2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
#include "lc_context.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_math.h"
|
2019-07-28 01:31:16 +02:00
|
|
|
#include "lc_meshloader.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
class PieceInfo;
|
|
|
|
class lcZipFile;
|
2019-07-28 01:31:16 +02:00
|
|
|
class lcLibraryMeshData;
|
2024-07-12 00:04:07 +02:00
|
|
|
class lcThumbnailManager;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-22 23:16:28 +01:00
|
|
|
enum class lcStudStyle
|
|
|
|
{
|
|
|
|
Plain,
|
|
|
|
ThinLinesLogo,
|
|
|
|
OutlineLogo,
|
|
|
|
SharpTopLogo,
|
|
|
|
RoundedTopLogo,
|
|
|
|
FlattenedLogo,
|
|
|
|
HighContrast,
|
|
|
|
HighContrastLogo,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2021-11-15 03:34:24 +01:00
|
|
|
constexpr bool lcIsHighContrast(lcStudStyle StudStyle)
|
2021-01-26 23:58:02 +01:00
|
|
|
{
|
|
|
|
return StudStyle == lcStudStyle::HighContrast || StudStyle == lcStudStyle::HighContrastLogo;
|
|
|
|
}
|
|
|
|
|
2021-01-18 21:09:33 +01:00
|
|
|
enum class lcZipFileType
|
2014-05-08 00:58:59 +02:00
|
|
|
{
|
2021-01-18 21:09:33 +01:00
|
|
|
Official,
|
|
|
|
Unofficial,
|
2021-01-20 13:19:29 +01:00
|
|
|
StudStyle,
|
2021-01-18 21:09:33 +01:00
|
|
|
Count
|
2014-05-08 00:58:59 +02:00
|
|
|
};
|
|
|
|
|
2021-03-13 19:51:35 +01:00
|
|
|
enum class lcLibraryFolderType
|
2017-11-27 04:21:54 +01:00
|
|
|
{
|
2021-03-13 19:51:35 +01:00
|
|
|
Official,
|
|
|
|
Unofficial,
|
|
|
|
Count
|
2017-11-27 04:21:54 +01:00
|
|
|
};
|
|
|
|
|
2017-11-25 04:45:27 +01:00
|
|
|
enum class lcPrimitiveState
|
|
|
|
{
|
2021-01-18 22:38:17 +01:00
|
|
|
NotLoaded,
|
|
|
|
Loading,
|
|
|
|
Loaded
|
2017-11-25 04:45:27 +01:00
|
|
|
};
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
class lcLibraryPrimitive
|
|
|
|
{
|
|
|
|
public:
|
2021-01-23 20:43:57 +01:00
|
|
|
explicit lcLibraryPrimitive(QString&& FileName, const char* Name, lcZipFileType ZipFileType, quint32 ZipFileIndex, bool Stud, bool StudStyle, bool SubFile)
|
2019-06-03 22:23:04 +02:00
|
|
|
: mFileName(std::move(FileName))
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2020-12-19 21:10:10 +01:00
|
|
|
strncpy(mName, Name, sizeof(mName)-1);
|
2013-08-09 06:57:18 +02:00
|
|
|
mName[sizeof(mName) - 1] = 0;
|
|
|
|
|
2014-05-08 00:58:59 +02:00
|
|
|
mZipFileType = ZipFileType;
|
2013-08-09 06:57:18 +02:00
|
|
|
mZipFileIndex = ZipFileIndex;
|
2021-01-18 22:38:17 +01:00
|
|
|
mState = lcPrimitiveState::NotLoaded;
|
2013-08-09 06:57:18 +02:00
|
|
|
mStud = Stud;
|
2021-01-23 20:43:57 +01:00
|
|
|
mStudStyle = StudStyle;
|
2013-08-09 06:57:18 +02:00
|
|
|
mSubFile = SubFile;
|
|
|
|
}
|
|
|
|
|
2019-06-03 22:23:04 +02:00
|
|
|
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
|
2014-05-08 00:58:59 +02:00
|
|
|
{
|
|
|
|
mZipFileType = ZipFileType;
|
|
|
|
mZipFileIndex = ZipFileIndex;
|
|
|
|
}
|
|
|
|
|
2019-09-24 01:55:24 +02:00
|
|
|
void Unload()
|
|
|
|
{
|
2021-01-18 22:38:17 +01:00
|
|
|
mState = lcPrimitiveState::NotLoaded;
|
2021-03-07 03:54:24 +01:00
|
|
|
mMeshData.Clear();
|
2019-09-24 01:55:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-02 04:54:09 +02:00
|
|
|
QString mFileName;
|
2019-02-28 15:47:09 +01:00
|
|
|
char mName[LC_MAXNAME];
|
2014-05-08 00:58:59 +02:00
|
|
|
lcZipFileType mZipFileType;
|
2017-12-02 21:22:04 +01:00
|
|
|
quint32 mZipFileIndex;
|
2017-11-25 04:45:27 +01:00
|
|
|
lcPrimitiveState mState;
|
2013-08-09 06:57:18 +02:00
|
|
|
bool mStud;
|
2021-01-23 20:43:57 +01:00
|
|
|
bool mStudStyle;
|
2013-08-09 06:57:18 +02:00
|
|
|
bool mSubFile;
|
|
|
|
lcLibraryMeshData mMeshData;
|
|
|
|
};
|
|
|
|
|
2021-01-19 00:23:13 +01:00
|
|
|
enum class lcLibrarySourceType
|
|
|
|
{
|
|
|
|
Library,
|
2021-01-20 13:19:29 +01:00
|
|
|
StudStyle
|
2021-01-19 00:23:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lcLibrarySource
|
|
|
|
{
|
2021-11-15 03:34:24 +01:00
|
|
|
lcLibrarySource() = default;
|
|
|
|
|
2021-01-19 00:23:13 +01:00
|
|
|
~lcLibrarySource()
|
|
|
|
{
|
|
|
|
for (const auto& PrimitiveIt : Primitives)
|
|
|
|
delete PrimitiveIt.second;
|
|
|
|
}
|
|
|
|
|
2021-11-15 03:34:24 +01:00
|
|
|
lcLibrarySource(const lcLibrarySource&) = delete;
|
|
|
|
lcLibrarySource(lcLibrarySource&&) = delete;
|
|
|
|
lcLibrarySource& operator=(const lcLibrarySource&) = delete;
|
|
|
|
lcLibrarySource& operator=(lcLibrarySource&&) = delete;
|
|
|
|
|
2021-01-19 00:23:13 +01:00
|
|
|
lcLibrarySourceType Type;
|
|
|
|
std::map<std::string, lcLibraryPrimitive*> Primitives;
|
|
|
|
};
|
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
class lcPiecesLibrary : public QObject
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
public:
|
|
|
|
lcPiecesLibrary();
|
|
|
|
~lcPiecesLibrary();
|
|
|
|
|
2020-03-22 23:44:41 +01:00
|
|
|
lcPiecesLibrary(const lcPiecesLibrary&) = delete;
|
2021-11-15 03:34:24 +01:00
|
|
|
lcPiecesLibrary(lcPiecesLibrary&&) = delete;
|
2020-03-22 23:44:41 +01:00
|
|
|
lcPiecesLibrary& operator=(const lcPiecesLibrary&) = delete;
|
2021-11-15 03:34:24 +01:00
|
|
|
lcPiecesLibrary& operator=(lcPiecesLibrary&&) = delete;
|
2020-03-22 23:44:41 +01:00
|
|
|
|
2024-07-12 00:04:07 +02:00
|
|
|
lcThumbnailManager* GetThumbnailManager() const
|
|
|
|
{
|
|
|
|
return mThumbnailManager.get();
|
|
|
|
}
|
|
|
|
|
2017-11-25 05:00:16 +01:00
|
|
|
bool Load(const QString& LibraryPath, bool ShowProgress);
|
2021-01-22 22:40:16 +01:00
|
|
|
void LoadColors();
|
2013-08-09 06:57:18 +02:00
|
|
|
void Unload();
|
2015-01-07 17:52:42 +01:00
|
|
|
void RemoveTemporaryPieces();
|
2015-02-22 03:39:15 +01:00
|
|
|
void RemovePiece(PieceInfo* Info);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-07-24 04:35:18 +02:00
|
|
|
void RenamePiece(PieceInfo* Info, const char* NewName);
|
2016-11-26 02:12:19 +01:00
|
|
|
PieceInfo* FindPiece(const char* PieceName, Project* Project, bool CreatePlaceholder, bool SearchProjectFolder);
|
2017-01-23 04:28:05 +01:00
|
|
|
void LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority);
|
|
|
|
void ReleasePieceInfo(PieceInfo* Info);
|
2014-09-11 21:55:34 +02:00
|
|
|
bool LoadBuiltinPieces();
|
2017-01-23 04:28:05 +01:00
|
|
|
bool LoadPieceData(PieceInfo* Info);
|
|
|
|
void LoadQueuedPiece();
|
|
|
|
void WaitForLoadQueue();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
lcTexture* FindTexture(const char* TextureName, Project* CurrentProject, bool SearchProjectFolder);
|
2013-08-09 06:57:18 +02:00
|
|
|
bool LoadTexture(lcTexture* Texture);
|
2017-07-02 02:12:09 +02:00
|
|
|
void ReleaseTexture(lcTexture* Texture);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-02-08 03:55:54 +01:00
|
|
|
bool PieceInCategory(PieceInfo* Info, const char* CategoryKeywords) const;
|
2024-05-25 04:26:01 +02:00
|
|
|
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
|
|
|
|
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
|
|
|
|
void GetParts(std::vector<PieceInfo*>& Parts) const;
|
2019-12-07 18:52:46 +01:00
|
|
|
|
2019-12-09 01:54:12 +01:00
|
|
|
std::vector<PieceInfo*> GetPartsFromSet(const std::vector<std::string>& PartIds) const;
|
|
|
|
std::string GetPartId(const PieceInfo* Info) const;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-07-28 01:31:16 +02:00
|
|
|
void GetPrimitiveFile(lcLibraryPrimitive* Primitive, std::function<void(lcFile& File)> Callback);
|
|
|
|
void GetPieceFile(const char* FileName, std::function<void(lcFile& File)> Callback);
|
|
|
|
|
2021-01-19 00:23:13 +01:00
|
|
|
bool IsPrimitive(const char* Name) const;
|
|
|
|
lcLibraryPrimitive* FindPrimitive(const char* Name) const;
|
2019-07-28 01:31:16 +02:00
|
|
|
bool LoadPrimitive(lcLibraryPrimitive* Primitive);
|
|
|
|
|
2021-01-20 13:19:29 +01:00
|
|
|
bool SupportsStudStyle() const;
|
2023-04-17 18:37:56 +02:00
|
|
|
void SetStudStyle(lcStudStyle StudStyle, bool Reload, bool StudCylinderColorEnabled);
|
2019-09-21 18:47:33 +02:00
|
|
|
|
2021-01-22 23:16:28 +01:00
|
|
|
lcStudStyle GetStudStyle() const
|
2019-09-29 21:58:18 +02:00
|
|
|
{
|
2021-01-20 13:19:29 +01:00
|
|
|
return mStudStyle;
|
2019-09-29 21:58:18 +02:00
|
|
|
}
|
|
|
|
|
2014-03-07 03:39:28 +01:00
|
|
|
void SetOfficialPieces()
|
|
|
|
{
|
2021-01-18 21:09:33 +01:00
|
|
|
if (mZipFiles[static_cast<int>(lcZipFileType::Official)])
|
2019-03-14 20:18:58 +01:00
|
|
|
mNumOfficialPieces = (int)mPieces.size();
|
2014-03-07 03:39:28 +01:00
|
|
|
}
|
|
|
|
|
2019-07-28 01:31:16 +02:00
|
|
|
bool ShouldCancelLoading() const
|
|
|
|
{
|
|
|
|
return mCancelLoading;
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
void UpdateBuffers(lcContext* Context);
|
2015-11-16 03:41:16 +01:00
|
|
|
void UnloadUnusedParts();
|
2015-02-23 01:50:37 +01:00
|
|
|
|
2017-07-24 04:35:18 +02:00
|
|
|
std::map<std::string, PieceInfo*> mPieces;
|
2013-08-09 06:57:18 +02:00
|
|
|
int mNumOfficialPieces;
|
|
|
|
|
2019-07-05 02:06:26 +02:00
|
|
|
std::vector<lcTexture*> mTextures;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
QDir mLibraryDir;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
bool mBuffersDirty;
|
|
|
|
lcVertexBuffer mVertexBuffer;
|
|
|
|
lcIndexBuffer mIndexBuffer;
|
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
signals:
|
|
|
|
void PartLoaded(PieceInfo* Info);
|
2021-01-22 22:40:16 +01:00
|
|
|
void ColorsLoaded();
|
2017-01-23 04:28:05 +01:00
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
protected:
|
2017-05-29 22:31:24 +02:00
|
|
|
bool OpenArchive(const QString& FileName, lcZipFileType ZipFileType);
|
2020-12-19 20:12:31 +01:00
|
|
|
bool OpenArchive(std::unique_ptr<lcFile> File, lcZipFileType ZipFileType);
|
2017-11-25 05:00:16 +01:00
|
|
|
bool OpenDirectory(const QDir& LibraryDir, bool ShowProgress);
|
2015-07-22 06:00:47 +02:00
|
|
|
void ReadArchiveDescriptions(const QString& OfficialFileName, const QString& UnofficialFileName);
|
2021-03-13 19:51:35 +01:00
|
|
|
void ReadDirectoryDescriptions(const QFileInfoList (&FileLists)[static_cast<int>(lcLibraryFolderType::Count)], bool ShowProgress);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-11-27 04:21:54 +01:00
|
|
|
bool ReadArchiveCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool WriteArchiveCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
2015-07-22 06:00:47 +02:00
|
|
|
bool LoadCacheIndex(const QString& FileName);
|
2017-11-27 04:21:54 +01:00
|
|
|
bool SaveArchiveCacheIndex(const QString& FileName);
|
2013-08-09 06:57:18 +02:00
|
|
|
bool LoadCachePiece(PieceInfo* Info);
|
2015-07-22 06:00:47 +02:00
|
|
|
bool SaveCachePiece(PieceInfo* Info);
|
2017-11-27 04:21:54 +01:00
|
|
|
bool ReadDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool WriteDirectoryCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2021-01-23 20:43:57 +01:00
|
|
|
static bool IsStudPrimitive(const char* FileName);
|
|
|
|
static bool IsStudStylePrimitive(const char* FileName);
|
2021-01-20 13:19:29 +01:00
|
|
|
void UpdateStudStyleSource();
|
2021-01-19 00:23:13 +01:00
|
|
|
|
2021-03-11 06:21:47 +01:00
|
|
|
void ReleaseBuffers();
|
|
|
|
|
2021-01-19 00:23:13 +01:00
|
|
|
std::vector<std::unique_ptr<lcLibrarySource>> mSources;
|
2019-09-29 21:58:18 +02:00
|
|
|
|
2021-07-06 02:00:41 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
QRecursiveMutex mLoadMutex;
|
|
|
|
#else
|
2017-01-23 04:28:05 +01:00
|
|
|
QMutex mLoadMutex;
|
2021-07-06 02:00:41 +02:00
|
|
|
#endif
|
2017-01-23 04:28:05 +01:00
|
|
|
QList<QFuture<void>> mLoadFutures;
|
|
|
|
QList<PieceInfo*> mLoadQueue;
|
|
|
|
|
2017-12-22 14:42:28 +01:00
|
|
|
QMutex mTextureMutex;
|
|
|
|
|
2021-01-22 23:16:28 +01:00
|
|
|
lcStudStyle mStudStyle;
|
2023-04-17 18:37:56 +02:00
|
|
|
bool mStudCylinderColorEnabled;
|
2019-09-24 01:55:24 +02:00
|
|
|
|
2024-07-12 00:04:07 +02:00
|
|
|
std::unique_ptr<lcThumbnailManager> mThumbnailManager;
|
2015-07-22 06:00:47 +02:00
|
|
|
QString mCachePath;
|
|
|
|
qint64 mArchiveCheckSum[4];
|
2021-01-18 21:09:33 +01:00
|
|
|
std::unique_ptr<lcZipFile> mZipFiles[static_cast<int>(lcZipFileType::Count)];
|
2017-03-19 21:12:24 +01:00
|
|
|
bool mHasUnofficial;
|
2017-11-25 21:57:41 +01:00
|
|
|
bool mCancelLoading;
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|