2013-08-09 06:57:18 +02:00
|
|
|
#ifndef _LC_LIBRARY_H_
|
|
|
|
#define _LC_LIBRARY_H_
|
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
#include "lc_context.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_mesh.h"
|
|
|
|
#include "lc_math.h"
|
2013-08-16 01:43:18 +02:00
|
|
|
#include "lc_array.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "str.h"
|
|
|
|
|
|
|
|
class PieceInfo;
|
|
|
|
class lcZipFile;
|
|
|
|
|
|
|
|
enum LC_MESH_PRIMITIVE_TYPE
|
|
|
|
{
|
|
|
|
LC_MESH_LINES,
|
|
|
|
LC_MESH_TRIANGLES,
|
|
|
|
LC_MESH_TEXTURED_LINES,
|
|
|
|
LC_MESH_TEXTURED_TRIANGLES,
|
|
|
|
LC_MESH_NUM_PRIMITIVE_TYPES
|
|
|
|
};
|
|
|
|
|
2014-05-08 00:58:59 +02:00
|
|
|
enum lcZipFileType
|
|
|
|
{
|
|
|
|
LC_ZIPFILE_OFFICIAL,
|
|
|
|
LC_ZIPFILE_UNOFFICIAL,
|
|
|
|
LC_NUM_ZIPFILES
|
|
|
|
};
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
class lcLibraryMeshSection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcLibraryMeshSection(LC_MESH_PRIMITIVE_TYPE PrimitiveType, lcuint32 Color, lcTexture* Texture)
|
|
|
|
: mIndices(1024, 1024)
|
|
|
|
{
|
|
|
|
mPrimitiveType = PrimitiveType;
|
|
|
|
mColor = Color;
|
|
|
|
mTexture = Texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
~lcLibraryMeshSection()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LC_MESH_PRIMITIVE_TYPE mPrimitiveType;
|
|
|
|
lcuint32 mColor;
|
|
|
|
lcTexture* mTexture;
|
2013-08-16 01:43:18 +02:00
|
|
|
lcArray<lcuint32> mIndices;
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lcLibraryTextureMap
|
|
|
|
{
|
|
|
|
lcVector4 Params[2];
|
|
|
|
lcTexture* Texture;
|
|
|
|
bool Fallback;
|
|
|
|
bool Next;
|
|
|
|
};
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
enum lcMeshDataType
|
|
|
|
{
|
|
|
|
LC_MESHDATA_HIGH,
|
|
|
|
LC_MESHDATA_LOW,
|
|
|
|
LC_MESHDATA_SHARED,
|
|
|
|
LC_NUM_MESHDATA_TYPES
|
|
|
|
};
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
class lcLibraryMeshData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcLibraryMeshData()
|
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
|
|
|
mVertices[MeshDataIdx].SetGrow(1024);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~lcLibraryMeshData()
|
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
|
|
|
mSections[MeshDataIdx].DeleteAll();
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
void AddLine(lcMeshDataType MeshDataType, int LineType, lcuint32 ColorCode, const lcVector3* Vertices);
|
|
|
|
void AddTexturedLine(lcMeshDataType MeshDataType, int LineType, lcuint32 ColorCode, const lcLibraryTextureMap& Map, const lcVector3* Vertices);
|
|
|
|
void AddMeshData(const lcLibraryMeshData& Data, const lcMatrix44& Transform, lcuint32 CurrentColorCode, lcLibraryTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
|
|
|
void AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Data, const lcMatrix44& Transform, lcuint32 CurrentColorCode, lcLibraryTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
2015-02-23 01:50:37 +01:00
|
|
|
void TestQuad(int* QuadIndices, const lcVector3* Vertices);
|
|
|
|
void ResequenceQuad(int* QuadIndices, int a, int b, int c, int d);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
lcArray<lcLibraryMeshSection*> mSections[LC_NUM_MESHDATA_TYPES];
|
|
|
|
lcArray<lcVertex> mVertices[LC_NUM_MESHDATA_TYPES];
|
|
|
|
lcArray<lcVertexTextured> mTexturedVertices[LC_NUM_MESHDATA_TYPES];
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class lcLibraryPrimitive
|
|
|
|
{
|
|
|
|
public:
|
2014-05-08 00:58:59 +02:00
|
|
|
lcLibraryPrimitive(const char* Name, lcZipFileType ZipFileType,lcuint32 ZipFileIndex, bool Stud, bool SubFile)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
strncpy(mName, Name, sizeof(mName));
|
|
|
|
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;
|
|
|
|
mLoaded = false;
|
|
|
|
mStud = Stud;
|
|
|
|
mSubFile = SubFile;
|
|
|
|
}
|
|
|
|
|
2014-05-08 00:58:59 +02:00
|
|
|
void SetZipFile(lcZipFileType ZipFileType,lcuint32 ZipFileIndex)
|
|
|
|
{
|
|
|
|
mZipFileType = ZipFileType;
|
|
|
|
mZipFileIndex = ZipFileIndex;
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
char mName[LC_MAXPATH];
|
2014-05-08 00:58:59 +02:00
|
|
|
lcZipFileType mZipFileType;
|
2013-08-09 06:57:18 +02:00
|
|
|
lcuint32 mZipFileIndex;
|
|
|
|
bool mLoaded;
|
|
|
|
bool mStud;
|
|
|
|
bool mSubFile;
|
|
|
|
lcLibraryMeshData mMeshData;
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcPiecesLibrary
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcPiecesLibrary();
|
|
|
|
~lcPiecesLibrary();
|
|
|
|
|
2015-07-22 06:00:47 +02:00
|
|
|
bool Load(const char* LibraryPath);
|
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
|
|
|
|
2015-02-22 03:39:15 +01:00
|
|
|
PieceInfo* FindPiece(const char* PieceName, Project* Project, bool CreatePlaceholder);
|
2013-08-09 06:57:18 +02:00
|
|
|
bool LoadPiece(PieceInfo* Info);
|
2014-09-11 21:55:34 +02:00
|
|
|
bool LoadBuiltinPieces();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
lcTexture* FindTexture(const char* TextureName);
|
|
|
|
bool LoadTexture(lcTexture* Texture);
|
|
|
|
|
|
|
|
bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const;
|
2015-01-06 16:17:29 +01:00
|
|
|
void SearchPieces(const char* Keyword, lcArray<PieceInfo*>& Pieces) const;
|
2013-08-16 01:43:18 +02:00
|
|
|
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
2015-01-06 16:17:29 +01:00
|
|
|
void GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
2013-08-16 01:43:18 +02:00
|
|
|
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-02-28 21:31:57 +01:00
|
|
|
bool IsPrimitive(const char* Name) const
|
|
|
|
{
|
|
|
|
return FindPrimitiveIndex(Name) != -1;
|
|
|
|
}
|
|
|
|
|
2014-03-07 03:39:28 +01:00
|
|
|
void SetOfficialPieces()
|
|
|
|
{
|
2014-05-08 00:58:59 +02:00
|
|
|
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
2014-03-07 03:39:28 +01:00
|
|
|
mNumOfficialPieces = mPieces.GetSize();
|
|
|
|
}
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, lcuint32 CurrentColorCode, lcArray<lcLibraryTextureMap>& TextureStack, lcLibraryMeshData& MeshData, lcMeshDataType MeshDataType);
|
2015-02-23 01:50:37 +01:00
|
|
|
void CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData);
|
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
|
|
|
|
2013-08-16 01:43:18 +02:00
|
|
|
lcArray<PieceInfo*> mPieces;
|
|
|
|
lcArray<lcLibraryPrimitive*> mPrimitives;
|
2013-08-09 06:57:18 +02:00
|
|
|
int mNumOfficialPieces;
|
|
|
|
|
2013-08-16 01:43:18 +02:00
|
|
|
lcArray<lcTexture*> mTextures;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
char mLibraryPath[LC_MAXPATH];
|
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
bool mBuffersDirty;
|
|
|
|
lcVertexBuffer mVertexBuffer;
|
|
|
|
lcIndexBuffer mIndexBuffer;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
protected:
|
2014-05-08 00:58:59 +02:00
|
|
|
bool OpenArchive(const char* FileName, lcZipFileType ZipFileType);
|
2014-09-11 21:55:34 +02:00
|
|
|
bool OpenArchive(lcFile* File, const char* FileName, lcZipFileType ZipFileType);
|
2013-08-09 06:57:18 +02:00
|
|
|
bool OpenDirectory(const char* Path);
|
2015-07-22 06:00:47 +02:00
|
|
|
void ReadArchiveDescriptions(const QString& OfficialFileName, const QString& UnofficialFileName);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-07-22 06:00:47 +02:00
|
|
|
bool ReadCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool WriteCacheFile(const QString& FileName, lcMemFile& CacheFile);
|
|
|
|
bool LoadCacheIndex(const QString& FileName);
|
|
|
|
bool SaveCacheIndex(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);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2015-02-28 21:31:57 +01:00
|
|
|
int FindPrimitiveIndex(const char* Name) const;
|
2013-08-09 06:57:18 +02:00
|
|
|
bool LoadPrimitive(int PrimitiveIndex);
|
|
|
|
|
2015-07-22 06:00:47 +02:00
|
|
|
QString mCachePath;
|
|
|
|
qint64 mArchiveCheckSum[4];
|
2013-08-09 06:57:18 +02:00
|
|
|
char mLibraryFileName[LC_MAXPATH];
|
2014-05-08 00:58:59 +02:00
|
|
|
char mUnofficialFileName[LC_MAXPATH];
|
|
|
|
lcZipFile* mZipFiles[LC_NUM_ZIPFILES];
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _LC_LIBRARY_H_
|