leocad/common/lc_library.h

199 lines
5.4 KiB
C
Raw Normal View History

2013-08-09 06:57:18 +02:00
#ifndef _LC_LIBRARY_H_
#define _LC_LIBRARY_H_
#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
};
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);
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:
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;
mZipFileType = ZipFileType;
2013-08-09 06:57:18 +02:00
mZipFileIndex = ZipFileIndex;
mLoaded = false;
mStud = Stud;
mSubFile = SubFile;
}
void SetZipFile(lcZipFileType ZipFileType,lcuint32 ZipFileIndex)
{
mZipFileType = ZipFileType;
mZipFileIndex = ZipFileIndex;
}
2013-08-09 06:57:18 +02:00
char mName[LC_MAXPATH];
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();
bool Load(const char* LibraryPath);
2013-08-09 06:57:18 +02:00
void Unload();
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;
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);
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
bool IsPrimitive(const char* Name) const
{
return FindPrimitiveIndex(Name) != -1;
}
void SetOfficialPieces()
{
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
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);
void CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData);
void UpdateBuffers(lcContext* Context);
void UnloadUnusedParts();
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];
bool mBuffersDirty;
lcVertexBuffer mVertexBuffer;
lcIndexBuffer mIndexBuffer;
2013-08-09 06:57:18 +02:00
protected:
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);
void ReadArchiveDescriptions(const QString& OfficialFileName, const QString& UnofficialFileName);
2013-08-09 06:57:18 +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);
bool SaveCachePiece(PieceInfo* Info);
2013-08-09 06:57:18 +02:00
int FindPrimitiveIndex(const char* Name) const;
2013-08-09 06:57:18 +02:00
bool LoadPrimitive(int PrimitiveIndex);
QString mCachePath;
qint64 mArchiveCheckSum[4];
2013-08-09 06:57:18 +02:00
char mLibraryFileName[LC_MAXPATH];
char mUnofficialFileName[LC_MAXPATH];
lcZipFile* mZipFiles[LC_NUM_ZIPFILES];
2013-08-09 06:57:18 +02:00
};
#endif // _LC_LIBRARY_H_