Enable coveralls for export tests.

pull/2153/head
Kim Kulling 2018-09-25 20:15:48 +02:00
parent 9f6238f3af
commit 6146ff818c
2 changed files with 65 additions and 99 deletions

View File

@ -51,7 +51,8 @@ matrix:
env: ANALYZE=ON env: ANALYZE=ON
- os: linux - os: linux
compiler: gcc compiler: gcc
env: DISABLE_EXPORTERS=YES ENABLE_COVERALLS=ON # env: DISABLE_EXPORTERS=YES ENABLE_COVERALLS=ON
env: ENABLE_COVERALLS=ON
- os: linux - os: linux
compiler: gcc compiler: gcc
env: SHARED_BUILD=ON env: SHARED_BUILD=ON

View File

@ -137,12 +137,10 @@ static void normalizePathName( const std::string &rPath, std::string &normalized
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor. // Constructor.
Q3BSPFileImporter::Q3BSPFileImporter() Q3BSPFileImporter::Q3BSPFileImporter()
: : m_pCurrentMesh( nullptr )
m_pCurrentMesh( nullptr ), , m_pCurrentFace(nullptr)
m_pCurrentFace(nullptr), , m_MaterialLookupMap()
m_MaterialLookupMap(), , mTextures() {
mTextures()
{
// empty // empty
} }
@ -164,48 +162,41 @@ Q3BSPFileImporter::~Q3BSPFileImporter() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns true, if the loader can read this. // Returns true, if the loader can read this.
bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* /*pIOHandler*/, bool checkSig ) const bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* /*pIOHandler*/, bool checkSig ) const {
{
if(!checkSig) { if(!checkSig) {
return SimpleExtensionCheck( rFile, "pk3", "bsp" ); return SimpleExtensionCheck( rFile, "pk3", "bsp" );
} }
// TODO perhaps add keyword based detection
return false; return false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Adds extensions. // Adds extensions.
const aiImporterDesc* Q3BSPFileImporter::GetInfo () const const aiImporterDesc* Q3BSPFileImporter::GetInfo () const {
{
return &desc; return &desc;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Import method. // Import method.
void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* pScene, IOSystem* pIOHandler) void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* scene, IOSystem* ioHandler) {
{ Q3BSPZipArchive Archive( ioHandler, rFile );
Q3BSPZipArchive Archive( pIOHandler, rFile ); if ( !Archive.isOpen() ) {
if ( !Archive.isOpen() )
{
throw DeadlyImportError( "Failed to open file " + rFile + "." ); throw DeadlyImportError( "Failed to open file " + rFile + "." );
} }
std::string archiveName( "" ), mapName( "" ); std::string archiveName( "" ), mapName( "" );
separateMapName( rFile, archiveName, mapName ); separateMapName( rFile, archiveName, mapName );
if ( mapName.empty() ) if ( mapName.empty() ) {
{ if ( !findFirstMapInArchive( Archive, mapName ) ) {
if ( !findFirstMapInArchive( Archive, mapName ) )
{
return; return;
} }
} }
Q3BSPFileParser fileParser( mapName, &Archive ); Q3BSPFileParser fileParser( mapName, &Archive );
Q3BSPModel *pBSPModel = fileParser.getModel(); Q3BSPModel *pBSPModel = fileParser.getModel();
if ( NULL != pBSPModel ) if ( nullptr != pBSPModel ) {
{ CreateDataFromImport( pBSPModel, scene, &Archive );
CreateDataFromImport( pBSPModel, pScene, &Archive );
} }
} }
@ -405,64 +396,50 @@ aiNode *Q3BSPFileImporter::CreateTopology( const Q3BSP::Q3BSPModel *pModel,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Creates the triangle topology from a face array. // Creates the triangle topology from a face array.
void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, sQ3BSPFace *pQ3BSPFace,
Q3BSP::sQ3BSPFace *pQ3BSPFace, aiMesh* pMesh, unsigned int &faceIdx, unsigned int &vertIdx ) {
aiMesh* pMesh, ai_assert( faceIdx < pMesh->mNumFaces );
unsigned int &rFaceIdx,
unsigned int &rVertIdx )
{
ai_assert( rFaceIdx < pMesh->mNumFaces );
m_pCurrentFace = getNextFace( pMesh, rFaceIdx ); m_pCurrentFace = getNextFace( pMesh, faceIdx );
ai_assert( NULL != m_pCurrentFace ); if ( nullptr == m_pCurrentFace ) {
if ( NULL == m_pCurrentFace )
{
return; return;
} }
m_pCurrentFace->mNumIndices = 3; m_pCurrentFace->mNumIndices = 3;
m_pCurrentFace->mIndices = new unsigned int[ m_pCurrentFace->mNumIndices ]; m_pCurrentFace->mIndices = new unsigned int[ m_pCurrentFace->mNumIndices ];
size_t idx = 0; size_t idx( 0 );
for ( size_t i = 0; i < (size_t) pQ3BSPFace->iNumOfFaceVerts; i++ ) for ( size_t i = 0; i < (size_t) pQ3BSPFace->iNumOfFaceVerts; ++i ) {
{
const size_t index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[ pQ3BSPFace->iFaceVertexIndex + i ]; const size_t index = pQ3BSPFace->iVertexIndex + pModel->m_Indices[ pQ3BSPFace->iFaceVertexIndex + i ];
ai_assert( index < pModel->m_Vertices.size() ); if ( index >= pModel->m_Vertices.size() ) {
if ( index >= pModel->m_Vertices.size() )
{
continue; continue;
} }
sQ3BSPVertex *pVertex = pModel->m_Vertices[ index ]; sQ3BSPVertex *pVertex = pModel->m_Vertices[ index ];
ai_assert( NULL != pVertex ); if ( nullptr == pVertex ) {
if ( NULL == pVertex )
{
continue; continue;
} }
pMesh->mVertices[ rVertIdx ].Set( pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z ); pMesh->mVertices[ vertIdx ].Set( pVertex->vPosition.x, pVertex->vPosition.y, pVertex->vPosition.z );
pMesh->mNormals[ rVertIdx ].Set( pVertex->vNormal.x, pVertex->vNormal.y, pVertex->vNormal.z ); pMesh->mNormals[ vertIdx ].Set( pVertex->vNormal.x, pVertex->vNormal.y, pVertex->vNormal.z );
pMesh->mTextureCoords[ 0 ][ rVertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f ); pMesh->mTextureCoords[ 0 ][ vertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f );
pMesh->mTextureCoords[ 1 ][ rVertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f ); pMesh->mTextureCoords[ 1 ][ vertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f );
ai_assert( m_pCurrentFace ); m_pCurrentFace->mIndices[ idx ] = vertIdx;
m_pCurrentFace->mIndices[ idx ] = rVertIdx; vertIdx++;
rVertIdx++;
idx++; idx++;
if ( idx > 2 ) if ( idx > 2 ) {
{
idx = 0; idx = 0;
m_pCurrentFace = getNextFace( pMesh, rFaceIdx ); m_pCurrentFace = getNextFace( pMesh, faceIdx );
if ( NULL != m_pCurrentFace ) if ( nullptr != m_pCurrentFace ) {
{
m_pCurrentFace->mNumIndices = 3; m_pCurrentFace->mNumIndices = 3;
m_pCurrentFace->mIndices = new unsigned int[ 3 ]; m_pCurrentFace->mIndices = new unsigned int[ 3 ];
} }
} }
} }
rFaceIdx--; //faceIdx--;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -470,8 +447,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
Q3BSPZipArchive *pArchive ) Q3BSPZipArchive *pArchive )
{ {
if ( m_MaterialLookupMap.empty() ) if ( m_MaterialLookupMap.empty() ) {
{
return; return;
} }
@ -479,11 +455,9 @@ void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScen
aiString aiMatName; aiString aiMatName;
int textureId( -1 ), lightmapId( -1 ); int textureId( -1 ), lightmapId( -1 );
for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
++it ) ++it ) {
{ const std::string matName( it->first );
const std::string matName = (*it).first; if ( matName.empty() ) {
if ( matName.empty() )
{
continue; continue;
} }
@ -524,17 +498,16 @@ void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScen
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Counts the number of referenced vertices. // Counts the number of referenced vertices.
size_t Q3BSPFileImporter::countData( const std::vector<sQ3BSPFace*> &rArray ) const size_t Q3BSPFileImporter::countData( const std::vector<sQ3BSPFace*> &faceArray ) const {
{ size_t numVerts( 0 );
size_t numVerts = 0; for ( std::vector<sQ3BSPFace*>::const_iterator it = faceArray.begin(); it != faceArray.end();
for ( std::vector<sQ3BSPFace*>::const_iterator it = rArray.begin(); it != rArray.end();
++it ) ++it )
{ {
sQ3BSPFace *pQ3BSPFace = *it; sQ3BSPFace *pQ3BSPFace = *it;
if ( pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh ) if ( pQ3BSPFace->iType == Polygon || pQ3BSPFace->iType == TriangleMesh )
{ {
Q3BSP::sQ3BSPFace *pQ3BSPFace = *it; Q3BSP::sQ3BSPFace *pQ3BSPFace = *it;
ai_assert( NULL != pQ3BSPFace ); ai_assert( nullptr != pQ3BSPFace );
numVerts += pQ3BSPFace->iNumOfFaceVerts; numVerts += pQ3BSPFace->iNumOfFaceVerts;
} }
} }
@ -580,8 +553,7 @@ size_t Q3BSPFileImporter::countTriangles( const std::vector<Q3BSP::sQ3BSPFace*>
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Creates the faces-to-material map. // Creates the faces-to-material map.
void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel ) void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel ) {
{
std::string key( "" ); std::string key( "" );
std::vector<sQ3BSPFace*> *pCurFaceArray = NULL; std::vector<sQ3BSPFace*> *pCurFaceArray = NULL;
for ( size_t idx = 0; idx < pModel->m_Faces.size(); idx++ ) for ( size_t idx = 0; idx < pModel->m_Faces.size(); idx++ )
@ -591,8 +563,7 @@ void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel )
const int lightMapId = pQ3BSPFace->iLightmapID; const int lightMapId = pQ3BSPFace->iLightmapID;
createKey( texId, lightMapId, key ); createKey( texId, lightMapId, key );
FaceMapIt it = m_MaterialLookupMap.find( key ); FaceMapIt it = m_MaterialLookupMap.find( key );
if ( m_MaterialLookupMap.end() == it ) if ( m_MaterialLookupMap.end() == it ) {
{
pCurFaceArray = new std::vector<Q3BSP::sQ3BSPFace*>; pCurFaceArray = new std::vector<Q3BSP::sQ3BSPFace*>;
m_MaterialLookupMap[ key ] = pCurFaceArray; m_MaterialLookupMap[ key ] = pCurFaceArray;
} }
@ -600,8 +571,8 @@ void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel )
{ {
pCurFaceArray = (*it).second; pCurFaceArray = (*it).second;
} }
ai_assert( NULL != pCurFaceArray ); ai_assert( nullptr != pCurFaceArray );
if ( NULL != pCurFaceArray ) if (nullptr != pCurFaceArray )
{ {
pCurFaceArray->push_back( pQ3BSPFace ); pCurFaceArray->push_back( pQ3BSPFace );
} }
@ -610,32 +581,31 @@ void Q3BSPFileImporter::createMaterialMap( const Q3BSP::Q3BSPModel *pModel )
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns the next face. // Returns the next face.
aiFace *Q3BSPFileImporter::getNextFace( aiMesh *pMesh, unsigned int &rFaceIdx ) aiFace *Q3BSPFileImporter::getNextFace( aiMesh *mesh, unsigned int &faceIdx ) {
{ aiFace *face( nullptr );
aiFace *pFace( NULL ); if ( faceIdx < mesh->mNumFaces ) {
if ( rFaceIdx < pMesh->mNumFaces ) { face = &mesh->mFaces[ faceIdx ];
pFace = &pMesh->mFaces[ rFaceIdx ]; ++faceIdx;
rFaceIdx++;
} }
return pFace; return face;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Imports a texture file. // Imports a texture file.
bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pModel, bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *model,
Q3BSP::Q3BSPZipArchive *pArchive, aiScene*, Q3BSP::Q3BSPZipArchive *archive, aiScene*,
aiMaterial *pMatHelper, int textureId ) { aiMaterial *pMatHelper, int textureId ) {
if ( NULL == pArchive || NULL == pMatHelper ) { if (nullptr == archive || nullptr == pMatHelper ) {
return false; return false;
} }
if ( textureId < 0 || textureId >= static_cast<int>( pModel->m_Textures.size() ) ) { if ( textureId < 0 || textureId >= static_cast<int>( model->m_Textures.size() ) ) {
return false; return false;
} }
bool res = true; bool res = true;
sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ]; sQ3BSPTexture *pTexture = model->m_Textures[ textureId ];
if ( !pTexture ) { if ( !pTexture ) {
return false; return false;
} }
@ -645,8 +615,8 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
supportedExtensions.push_back( ".png" ); supportedExtensions.push_back( ".png" );
supportedExtensions.push_back( ".tga" ); supportedExtensions.push_back( ".tga" );
std::string textureName, ext; std::string textureName, ext;
if ( expandFile( pArchive, pTexture->strName, supportedExtensions, textureName, ext ) ) { if ( expandFile( archive, pTexture->strName, supportedExtensions, textureName, ext ) ) {
IOStream *pTextureStream = pArchive->Open( textureName.c_str() ); IOStream *pTextureStream = archive->Open( textureName.c_str() );
if ( pTextureStream ) { if ( pTextureStream ) {
size_t texSize = pTextureStream->FileSize(); size_t texSize = pTextureStream->FileSize();
aiTexture *pTexture = new aiTexture; aiTexture *pTexture = new aiTexture;
@ -667,7 +637,7 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
name.data[ 0 ] = '*'; name.data[ 0 ] = '*';
name.length = 1 + ASSIMP_itoa10( name.data + 1, static_cast<unsigned int>(MAXLEN-1), static_cast<int32_t>(mTextures.size()) ); name.length = 1 + ASSIMP_itoa10( name.data + 1, static_cast<unsigned int>(MAXLEN-1), static_cast<int32_t>(mTextures.size()) );
pArchive->Close( pTextureStream ); archive->Close( pTextureStream );
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
mTextures.push_back( pTexture ); mTextures.push_back( pTexture );
@ -689,19 +659,16 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *pMode
bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene, bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
aiMaterial *pMatHelper, int lightmapId ) aiMaterial *pMatHelper, int lightmapId )
{ {
if ( NULL == pModel || NULL == pScene || NULL == pMatHelper ) if (nullptr == pModel || nullptr == pScene || nullptr == pMatHelper ) {
{
return false; return false;
} }
if ( lightmapId < 0 || lightmapId >= static_cast<int>( pModel->m_Lightmaps.size() ) ) if ( lightmapId < 0 || lightmapId >= static_cast<int>( pModel->m_Lightmaps.size() ) ) {
{
return false; return false;
} }
sQ3BSPLightmap *pLightMap = pModel->m_Lightmaps[ lightmapId ]; sQ3BSPLightmap *pLightMap = pModel->m_Lightmaps[ lightmapId ];
if ( NULL == pLightMap ) if (nullptr == pLightMap ) {
{
return false; return false;
} }
@ -713,8 +680,7 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
::memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth ); ::memcpy( pTexture->pcData, pLightMap->bLMapData, pTexture->mWidth );
size_t p = 0; size_t p = 0;
for ( size_t i = 0; i < CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT; ++i ) for ( size_t i = 0; i < CE_BSP_LIGHTMAPWIDTH * CE_BSP_LIGHTMAPHEIGHT; ++i ) {
{
pTexture->pcData[ i ].r = pLightMap->bLMapData[ p++ ]; pTexture->pcData[ i ].r = pLightMap->bLMapData[ p++ ];
pTexture->pcData[ i ].g = pLightMap->bLMapData[ p++ ]; pTexture->pcData[ i ].g = pLightMap->bLMapData[ p++ ];
pTexture->pcData[ i ].b = pLightMap->bLMapData[ p++ ]; pTexture->pcData[ i ].b = pLightMap->bLMapData[ p++ ];
@ -731,7 +697,6 @@ bool Q3BSPFileImporter::importLightmap( const Q3BSP::Q3BSPModel *pModel, aiScene
return true; return true;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Will search for a supported extension. // Will search for a supported extension.
bool Q3BSPFileImporter::expandFile( Q3BSP::Q3BSPZipArchive *pArchive, const std::string &rFilename, bool Q3BSPFileImporter::expandFile( Q3BSP::Q3BSPZipArchive *pArchive, const std::string &rFilename,