INtroduce unittests.
This commit is contained in:
@@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define ASSIMP_Q3BSPFILEDATA_H_INC
|
||||
|
||||
#include <vector>
|
||||
#include <string.h> //memset
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace Assimp {
|
||||
@@ -77,25 +77,21 @@ struct sQ3BSPHeader {
|
||||
};
|
||||
|
||||
/// Describes an entry.
|
||||
struct sQ3BSPLump
|
||||
{
|
||||
struct sQ3BSPLump {
|
||||
int iOffset; ///< Offset from start pointer of file
|
||||
int iSize; ///< Size of part
|
||||
};
|
||||
|
||||
struct vec2f
|
||||
{
|
||||
struct vec2f {
|
||||
float x,y;
|
||||
};
|
||||
|
||||
struct vec3f
|
||||
{
|
||||
struct vec3f {
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
/// Vertex of a Q3 level
|
||||
struct sQ3BSPVertex
|
||||
{
|
||||
struct sQ3BSPVertex {
|
||||
vec3f vPosition; ///< Position of vertex
|
||||
vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture
|
||||
vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap
|
||||
@@ -104,8 +100,7 @@ struct sQ3BSPVertex
|
||||
};
|
||||
|
||||
/// A face in bsp format info
|
||||
struct sQ3BSPFace
|
||||
{
|
||||
struct sQ3BSPFace {
|
||||
int iTextureID; ///< Index in texture array
|
||||
int iEffect; ///< Index in effect array (-1 = no effect)
|
||||
int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
|
||||
|
||||
@@ -82,39 +82,39 @@ using namespace Q3BSP;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Local function to create a material key name.
|
||||
static void createKey( int id1, int id2, std::string &rKey )
|
||||
{
|
||||
static void createKey( int id1, int id2, std::string &key ) {
|
||||
std::ostringstream str;
|
||||
str << id1 << "." << id2;
|
||||
rKey = str.str();
|
||||
key = str.str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Local function to extract the texture ids from a material key-name.
|
||||
static void extractIds( const std::string &rKey, int &rId1, int &rId2 )
|
||||
{
|
||||
rId1 = -1;
|
||||
rId2 = -1;
|
||||
if ( rKey.empty() )
|
||||
static void extractIds( const std::string &key, int &id1, int &id2 ) {
|
||||
id1 = -1;
|
||||
id2 = -1;
|
||||
if (key.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string::size_type pos = rKey.find( "." );
|
||||
if ( std::string::npos == pos )
|
||||
const std::string::size_type pos = key.find( "." );
|
||||
if (std::string::npos == pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string tmp1 = rKey.substr( 0, pos );
|
||||
std::string tmp2 = rKey.substr( pos + 1, rKey.size() - pos - 1 );
|
||||
rId1 = atoi( tmp1.c_str() );
|
||||
rId2 = atoi( tmp2.c_str() );
|
||||
std::string tmp1 = key.substr( 0, pos );
|
||||
std::string tmp2 = key.substr( pos + 1, key.size() - pos - 1 );
|
||||
id1 = atoi( tmp1.c_str() );
|
||||
id2 = atoi( tmp2.c_str() );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Local helper function to normalize filenames.
|
||||
static void normalizePathName( const std::string &rPath, std::string &rNormalizedPath )
|
||||
{
|
||||
rNormalizedPath = "";
|
||||
if ( rPath.empty() )
|
||||
static void normalizePathName( const std::string &rPath, std::string &normalizedPath ) {
|
||||
normalizedPath = "";
|
||||
if (rPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string sep = "\\";
|
||||
@@ -124,14 +124,11 @@ static void normalizePathName( const std::string &rPath, std::string &rNormalize
|
||||
|
||||
static const unsigned int numDelimiters = 2;
|
||||
const char delimiters[ numDelimiters ] = { '/', '\\' };
|
||||
rNormalizedPath = rPath;
|
||||
for (const char delimiter : delimiters)
|
||||
{
|
||||
for ( size_t j=0; j<rNormalizedPath.size(); j++ )
|
||||
{
|
||||
if ( rNormalizedPath[j] == delimiter )
|
||||
{
|
||||
rNormalizedPath[ j ] = sep[ 0 ];
|
||||
normalizedPath = rPath;
|
||||
for (const char delimiter : delimiters) {
|
||||
for ( size_t j=0; j<normalizedPath.size(); ++j ) {
|
||||
if ( normalizedPath[j] == delimiter ) {
|
||||
normalizedPath[ j ] = sep[ 0 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,9 +136,10 @@ static void normalizePathName( const std::string &rPath, std::string &rNormalize
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
Q3BSPFileImporter::Q3BSPFileImporter() :
|
||||
m_pCurrentMesh( NULL ),
|
||||
m_pCurrentFace( NULL ),
|
||||
Q3BSPFileImporter::Q3BSPFileImporter()
|
||||
:
|
||||
m_pCurrentMesh( nullptr ),
|
||||
m_pCurrentFace(nullptr),
|
||||
m_MaterialLookupMap(),
|
||||
mTextures()
|
||||
{
|
||||
@@ -151,8 +149,8 @@ Q3BSPFileImporter::Q3BSPFileImporter() :
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor.
|
||||
Q3BSPFileImporter::~Q3BSPFileImporter() {
|
||||
m_pCurrentMesh = NULL;
|
||||
m_pCurrentFace = NULL;
|
||||
m_pCurrentMesh = nullptr;
|
||||
m_pCurrentFace = nullptr;
|
||||
|
||||
// Clear face-to-material map
|
||||
for ( FaceMap::iterator it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end(); ++it ) {
|
||||
|
||||
@@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/BaseImporter.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct aiMesh;
|
||||
struct aiNode;
|
||||
@@ -53,6 +54,7 @@ struct aiMaterial;
|
||||
struct aiTexture;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
namespace Q3BSP {
|
||||
class Q3BSPZipArchive;
|
||||
struct Q3BSPModel;
|
||||
@@ -71,12 +73,11 @@ public:
|
||||
/// @brief Destructor.
|
||||
~Q3BSPFileImporter();
|
||||
|
||||
public:
|
||||
/// @brief Returns whether the class can handle the format of the given file.
|
||||
/// @remark See BaseImporter::CanRead() for details.
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
typedef std::map<std::string, std::vector<Q3BSP::sQ3BSPFace*>*> FaceMap;
|
||||
typedef std::map<std::string, std::vector<Q3BSP::sQ3BSPFace*>* >::iterator FaceMapIt;
|
||||
typedef std::map<std::string, std::vector<Q3BSP::sQ3BSPFace*>*>::const_iterator FaceMapConstIt;
|
||||
@@ -115,5 +116,4 @@ private:
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
|
||||
#endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC
|
||||
|
||||
@@ -103,8 +103,7 @@ bool Q3BSPFileParser::readData( const std::string &rMapName )
|
||||
m_Data.resize( size );
|
||||
|
||||
const size_t readSize = pMapFile->Read( &m_Data[0], sizeof( char ), size );
|
||||
if ( readSize != size )
|
||||
{
|
||||
if ( readSize != size ) {
|
||||
m_Data.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user