fix possible warnings

pull/2885/head
Kim Kulling 2020-03-30 20:33:43 +02:00
parent 22d6b761e6
commit 4c177ad72e
7 changed files with 222 additions and 222 deletions

View File

@ -322,7 +322,7 @@ struct Face : public FaceWithSmoothingGroup {
}; };
#ifdef _WIN32 #ifdef _WIN32
# pragma warning(disable : 4315) #pragma warning(disable : 4315)
#endif #endif
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -441,30 +441,53 @@ struct Material {
// empty // empty
} }
Material(const Material &other) = default; Material(const Material &other) :
Material &operator=(const Material &other) = default; mName(other.mName),
mDiffuse(other.mDiffuse),
mSpecularExponent(other.mSpecularExponent),
mShininessStrength(other.mShininessStrength),
mSpecular(other.mSpecular),
mAmbient(other.mAmbient),
mShading(other.mShading),
mTransparency(other.mTransparency),
sTexDiffuse(other.sTexDiffuse),
sTexOpacity(other.sTexOpacity),
sTexSpecular(other.sTexSpecular),
sTexReflective(other.sTexReflective),
sTexBump(other.sTexBump),
sTexEmissive(other.sTexEmissive),
sTexShininess(other.sTexShininess),
mBumpHeight(other.mBumpHeight),
mEmissive(other.mEmissive),
sTexAmbient(other.sTexAmbient),
mTwoSided(other.mTwoSided) {
// empty
}
//Material &operator=(const Material &other) = default;
//! Move constructor. This is explicitly written because MSVC doesn't support defaulting it //! Move constructor. This is explicitly written because MSVC doesn't support defaulting it
Material(Material &&other) AI_NO_EXCEPT Material(Material &&other) AI_NO_EXCEPT :
: mName(std::move(other.mName)), mName(std::move(other.mName)),
mDiffuse(std::move(other.mDiffuse)), mDiffuse(std::move(other.mDiffuse)),
mSpecularExponent(std::move(other.mSpecularExponent)), mSpecularExponent(std::move(other.mSpecularExponent)),
mShininessStrength(std::move(other.mShininessStrength)), mShininessStrength(std::move(other.mShininessStrength)),
mSpecular(std::move(other.mSpecular)), mSpecular(std::move(other.mSpecular)),
mAmbient(std::move(other.mAmbient)), mAmbient(std::move(other.mAmbient)),
mShading(std::move(other.mShading)), mShading(std::move(other.mShading)),
mTransparency(std::move(other.mTransparency)), mTransparency(std::move(other.mTransparency)),
sTexDiffuse(std::move(other.sTexDiffuse)), sTexDiffuse(std::move(other.sTexDiffuse)),
sTexOpacity(std::move(other.sTexOpacity)), sTexOpacity(std::move(other.sTexOpacity)),
sTexSpecular(std::move(other.sTexSpecular)), sTexSpecular(std::move(other.sTexSpecular)),
sTexReflective(std::move(other.sTexReflective)), sTexReflective(std::move(other.sTexReflective)),
sTexBump(std::move(other.sTexBump)), sTexBump(std::move(other.sTexBump)),
sTexEmissive(std::move(other.sTexEmissive)), sTexEmissive(std::move(other.sTexEmissive)),
sTexShininess(std::move(other.sTexShininess)), sTexShininess(std::move(other.sTexShininess)),
mBumpHeight(std::move(other.mBumpHeight)), mBumpHeight(std::move(other.mBumpHeight)),
mEmissive(std::move(other.mEmissive)), mEmissive(std::move(other.mEmissive)),
sTexAmbient(std::move(other.sTexAmbient)), sTexAmbient(std::move(other.sTexAmbient)),
mTwoSided(std::move(other.mTwoSided)) { mTwoSided(std::move(other.mTwoSided)) {
// empty
} }
Material &operator=(Material &&other) AI_NO_EXCEPT { Material &operator=(Material &&other) AI_NO_EXCEPT {

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -43,17 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the Terragen importer class */ /** @file Implementation of the Terragen importer class */
#ifndef ASSIMP_BUILD_NO_TERRAGEN_IMPORTER #ifndef ASSIMP_BUILD_NO_TERRAGEN_IMPORTER
#include "TerragenLoader.h" #include "TerragenLoader.h"
#include <assimp/StreamReader.h> #include <assimp/StreamReader.h>
#include <assimp/Importer.hpp> #include <assimp/importerdesc.h>
#include <assimp/IOSystem.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
#include <assimp/importerdesc.h> #include <assimp/IOSystem.hpp>
#include <assimp/Importer.hpp>
using namespace Assimp; using namespace Assimp;
@ -72,78 +68,72 @@ static const aiImporterDesc desc = {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
TerragenImporter::TerragenImporter() TerragenImporter::TerragenImporter() :
: configComputeUVs (false) configComputeUVs(false) {}
{}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor, private as well // Destructor, private as well
TerragenImporter::~TerragenImporter() TerragenImporter::~TerragenImporter() {}
{}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool TerragenImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const bool TerragenImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
{
// check file extension // check file extension
std::string extension = GetExtension(pFile); std::string extension = GetExtension(pFile);
if( extension == "ter") if (extension == "ter")
return true; return true;
if( !extension.length() || checkSig) { if (!extension.length() || checkSig) {
/* If CanRead() is called in order to check whether we /* If CanRead() is called in order to check whether we
* support a specific file extension in general pIOHandler * support a specific file extension in general pIOHandler
* might be NULL and it's our duty to return true here. * might be NULL and it's our duty to return true here.
*/ */
if (!pIOHandler)return true; if (!pIOHandler) return true;
const char* tokens[] = {"terragen"}; const char *tokens[] = { "terragen" };
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1); return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
} }
return false; return false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Build a string of all file extensions supported // Build a string of all file extensions supported
const aiImporterDesc* TerragenImporter::GetInfo () const const aiImporterDesc *TerragenImporter::GetInfo() const {
{
return &desc; return &desc;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Setup import properties // Setup import properties
void TerragenImporter::SetupProperties(const Importer* pImp) void TerragenImporter::SetupProperties(const Importer *pImp) {
{
// AI_CONFIG_IMPORT_TER_MAKE_UVS // AI_CONFIG_IMPORT_TER_MAKE_UVS
configComputeUVs = ( 0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS,0) ); configComputeUVs = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 0));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure. // Imports the given file into the given scene structure.
void TerragenImporter::InternReadFile( const std::string& pFile, void TerragenImporter::InternReadFile(const std::string &pFile,
aiScene* pScene, IOSystem* pIOHandler) aiScene *pScene, IOSystem *pIOHandler) {
{ IOStream *file = pIOHandler->Open(pFile, "rb");
IOStream* file = pIOHandler->Open( pFile, "rb");
// Check whether we can read from the file // Check whether we can read from the file
if( file == NULL) if (file == NULL)
throw DeadlyImportError( "Failed to open TERRAGEN TERRAIN file " + pFile + "."); throw DeadlyImportError("Failed to open TERRAGEN TERRAIN file " + pFile + ".");
// Construct a stream reader to read all data in the correct endianness // Construct a stream reader to read all data in the correct endianness
StreamReaderLE reader(file); StreamReaderLE reader(file);
if(reader.GetRemainingSize() < 16) if (reader.GetRemainingSize() < 16)
throw DeadlyImportError( "TER: file is too small" ); throw DeadlyImportError("TER: file is too small");
// Check for the existence of the two magic strings 'TERRAGEN' and 'TERRAIN ' // Check for the existence of the two magic strings 'TERRAGEN' and 'TERRAIN '
if (::strncmp((const char*)reader.GetPtr(),AI_TERR_BASE_STRING,8)) if (::strncmp((const char *)reader.GetPtr(), AI_TERR_BASE_STRING, 8))
throw DeadlyImportError( "TER: Magic string \'TERRAGEN\' not found" ); throw DeadlyImportError("TER: Magic string \'TERRAGEN\' not found");
if (::strncmp((const char*)reader.GetPtr()+8,AI_TERR_TERRAIN_STRING,8)) if (::strncmp((const char *)reader.GetPtr() + 8, AI_TERR_TERRAIN_STRING, 8))
throw DeadlyImportError( "TER: Magic string \'TERRAIN\' not found" ); throw DeadlyImportError("TER: Magic string \'TERRAIN\' not found");
unsigned int x = 0,y = 0,mode = 0; unsigned int x = 0, y = 0, mode = 0;
aiNode* root = pScene->mRootNode = new aiNode(); aiNode *root = pScene->mRootNode = new aiNode();
root->mName.Set("<TERRAGEN.TERRAIN>"); root->mName.Set("<TERRAGEN.TERRAIN>");
// Default scaling is 30 // Default scaling is 30
@ -151,104 +141,98 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
// Now read all chunks until we're finished or an EOF marker is encountered // Now read all chunks until we're finished or an EOF marker is encountered
reader.IncPtr(16); reader.IncPtr(16);
while (reader.GetRemainingSize() >= 4) while (reader.GetRemainingSize() >= 4) {
{ const char *head = (const char *)reader.GetPtr();
const char* head = (const char*)reader.GetPtr();
reader.IncPtr(4); reader.IncPtr(4);
// EOF, break in every case // EOF, break in every case
if (!::strncmp(head,AI_TERR_EOF_STRING,4)) if (!::strncmp(head, AI_TERR_EOF_STRING, 4))
break; break;
// Number of x-data points // Number of x-data points
if (!::strncmp(head,AI_TERR_CHUNK_XPTS,4)) if (!::strncmp(head, AI_TERR_CHUNK_XPTS, 4)) {
{
x = (uint16_t)reader.GetI2(); x = (uint16_t)reader.GetI2();
} }
// Number of y-data points // Number of y-data points
else if (!::strncmp(head,AI_TERR_CHUNK_YPTS,4)) else if (!::strncmp(head, AI_TERR_CHUNK_YPTS, 4)) {
{
y = (uint16_t)reader.GetI2(); y = (uint16_t)reader.GetI2();
} }
// Squared terrains width-1. // Squared terrains width-1.
else if (!::strncmp(head,AI_TERR_CHUNK_SIZE,4)) else if (!::strncmp(head, AI_TERR_CHUNK_SIZE, 4)) {
{ x = y = (uint16_t)reader.GetI2() + 1;
x = y = (uint16_t)reader.GetI2()+1;
} }
// terrain scaling // terrain scaling
else if (!::strncmp(head,AI_TERR_CHUNK_SCAL,4)) else if (!::strncmp(head, AI_TERR_CHUNK_SCAL, 4)) {
{
root->mTransformation.a1 = reader.GetF4(); root->mTransformation.a1 = reader.GetF4();
root->mTransformation.b2 = reader.GetF4(); root->mTransformation.b2 = reader.GetF4();
root->mTransformation.c3 = reader.GetF4(); root->mTransformation.c3 = reader.GetF4();
} }
// mapping == 1: earth radius // mapping == 1: earth radius
else if (!::strncmp(head,AI_TERR_CHUNK_CRAD,4)) else if (!::strncmp(head, AI_TERR_CHUNK_CRAD, 4)) {
{
reader.GetF4(); reader.GetF4();
} }
// mapping mode // mapping mode
else if (!::strncmp(head,AI_TERR_CHUNK_CRVM,4)) else if (!::strncmp(head, AI_TERR_CHUNK_CRVM, 4)) {
{
mode = reader.GetI1(); mode = reader.GetI1();
if (0 != mode) if (0 != mode)
ASSIMP_LOG_ERROR("TER: Unsupported mapping mode, a flat terrain is returned"); ASSIMP_LOG_ERROR("TER: Unsupported mapping mode, a flat terrain is returned");
} }
// actual terrain data // actual terrain data
else if (!::strncmp(head,AI_TERR_CHUNK_ALTW,4)) else if (!::strncmp(head, AI_TERR_CHUNK_ALTW, 4)) {
{ float hscale = (float)reader.GetI2() / 65536;
float hscale = (float)reader.GetI2() / 65536;
float bheight = (float)reader.GetI2(); float bheight = (float)reader.GetI2();
if (!hscale)hscale = 1; if (!hscale) hscale = 1;
// Ensure we have enough data // Ensure we have enough data
if (reader.GetRemainingSize() < x*y*2) if (reader.GetRemainingSize() < x * y * 2)
throw DeadlyImportError("TER: ALTW chunk is too small"); throw DeadlyImportError("TER: ALTW chunk is too small");
if (x <= 1 || y <= 1) if (x <= 1 || y <= 1)
throw DeadlyImportError("TER: Invalid terrain size"); throw DeadlyImportError("TER: Invalid terrain size");
// Allocate the output mesh // Allocate the output mesh
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes = 1]; pScene->mMeshes = new aiMesh *[pScene->mNumMeshes = 1];
aiMesh* m = pScene->mMeshes[0] = new aiMesh(); aiMesh *m = pScene->mMeshes[0] = new aiMesh();
// We return quads // We return quads
aiFace* f = m->mFaces = new aiFace[m->mNumFaces = (x-1)*(y-1)]; aiFace *f = m->mFaces = new aiFace[m->mNumFaces = (x - 1) * (y - 1)];
aiVector3D* pv = m->mVertices = new aiVector3D[m->mNumVertices = m->mNumFaces*4]; aiVector3D *pv = m->mVertices = new aiVector3D[m->mNumVertices = m->mNumFaces * 4];
aiVector3D *uv( NULL ); aiVector3D *uv(NULL);
float step_y( 0.0f ), step_x( 0.0f ); float step_y(0.0f), step_x(0.0f);
if (configComputeUVs) { if (configComputeUVs) {
uv = m->mTextureCoords[0] = new aiVector3D[m->mNumVertices]; uv = m->mTextureCoords[0] = new aiVector3D[m->mNumVertices];
step_y = 1.f/y; step_y = 1.f / y;
step_x = 1.f/x; step_x = 1.f / x;
} }
const int16_t* data = (const int16_t*)reader.GetPtr(); const int16_t *data = (const int16_t *)reader.GetPtr();
for (unsigned int yy = 0, t = 0; yy < y-1;++yy) { for (unsigned int yy = 0, t = 0; yy < y - 1; ++yy) {
for (unsigned int xx = 0; xx < x-1;++xx,++f) { for (unsigned int xx = 0; xx < x - 1; ++xx, ++f) {
// make verts // make verts
const float fy = (float)yy, fx = (float)xx; const float fy = (float)yy, fx = (float)xx;
unsigned tmp,tmp2; unsigned tmp, tmp2;
*pv++ = aiVector3D(fx,fy, (float)data[(tmp2=x*yy) + xx] * hscale + bheight); *pv++ = aiVector3D(fx, fy, (float)data[(tmp2 = x * yy) + xx] * hscale + bheight);
*pv++ = aiVector3D(fx,fy+1, (float)data[(tmp=x*(yy+1)) + xx] * hscale + bheight); *pv++ = aiVector3D(fx, fy + 1, (float)data[(tmp = x * (yy + 1)) + xx] * hscale + bheight);
*pv++ = aiVector3D(fx+1,fy+1,(float)data[tmp + xx+1] * hscale + bheight); *pv++ = aiVector3D(fx + 1, fy + 1, (float)data[tmp + xx + 1] * hscale + bheight);
*pv++ = aiVector3D(fx+1,fy, (float)data[tmp2 + xx+1] * hscale + bheight); *pv++ = aiVector3D(fx + 1, fy, (float)data[tmp2 + xx + 1] * hscale + bheight);
// also make texture coordinates, if necessary // also make texture coordinates, if necessary
if (configComputeUVs) { if (configComputeUVs) {
*uv++ = aiVector3D( step_x*xx, step_y*yy, 0.f ); *uv++ = aiVector3D(step_x * xx, step_y * yy, 0.f);
*uv++ = aiVector3D( step_x*xx, step_y*(yy+1), 0.f ); *uv++ = aiVector3D(step_x * xx, step_y * (yy + 1), 0.f);
*uv++ = aiVector3D( step_x*(xx+1), step_y*(yy+1), 0.f ); *uv++ = aiVector3D(step_x * (xx + 1), step_y * (yy + 1), 0.f);
*uv++ = aiVector3D( step_x*(xx+1), step_y*yy, 0.f ); *uv++ = aiVector3D(step_x * (xx + 1), step_y * yy, 0.f);
} }
// make indices // make indices
f->mIndices = new unsigned int[f->mNumIndices = 4]; f->mIndices = new unsigned int[f->mNumIndices = 4];
for (unsigned int i = 0; i < 4;++i) for (unsigned int i = 0; i < 4; ++i) {
f->mIndices[i] = t++; f->mIndices[i] = t;
t++;
}
} }
} }

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -47,21 +46,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define INCLUDED_AI_TERRAGEN_TERRAIN_LOADER_H #define INCLUDED_AI_TERRAGEN_TERRAIN_LOADER_H
#include <assimp/BaseImporter.h> #include <assimp/BaseImporter.h>
namespace Assimp { namespace Assimp {
// Magic strings // Magic strings
#define AI_TERR_BASE_STRING "TERRAGEN" #define AI_TERR_BASE_STRING "TERRAGEN"
#define AI_TERR_TERRAIN_STRING "TERRAIN " #define AI_TERR_TERRAIN_STRING "TERRAIN "
#define AI_TERR_EOF_STRING "EOF " #define AI_TERR_EOF_STRING "EOF "
// Chunka // Chunka
#define AI_TERR_CHUNK_XPTS "XPTS" #define AI_TERR_CHUNK_XPTS "XPTS"
#define AI_TERR_CHUNK_YPTS "YPTS" #define AI_TERR_CHUNK_YPTS "YPTS"
#define AI_TERR_CHUNK_SIZE "SIZE" #define AI_TERR_CHUNK_SIZE "SIZE"
#define AI_TERR_CHUNK_SCAL "SCAL" #define AI_TERR_CHUNK_SCAL "SCAL"
#define AI_TERR_CHUNK_CRAD "CRAD" #define AI_TERR_CHUNK_CRAD "CRAD"
#define AI_TERR_CHUNK_CRVM "CRVM" #define AI_TERR_CHUNK_CRVM "CRVM"
#define AI_TERR_CHUNK_ALTW "ALTW" #define AI_TERR_CHUNK_ALTW "ALTW"
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** @brief Importer class to load Terragen (0.9) terrain files. /** @brief Importer class to load Terragen (0.9) terrain files.
@ -69,33 +68,28 @@ namespace Assimp {
* The loader is basing on the information found here: * The loader is basing on the information found here:
* http://www.planetside.co.uk/terragen/dev/tgterrain.html#chunks * http://www.planetside.co.uk/terragen/dev/tgterrain.html#chunks
*/ */
class TerragenImporter : public BaseImporter class TerragenImporter : public BaseImporter {
{
public: public:
TerragenImporter(); TerragenImporter();
~TerragenImporter(); ~TerragenImporter();
public: public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
bool checkSig) const; bool checkSig) const;
protected: protected:
// -------------------------------------------------------------------
const aiImporterDesc *GetInfo() const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
const aiImporterDesc* GetInfo () const; void InternReadFile(const std::string &pFile, aiScene *pScene,
IOSystem *pIOHandler);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void InternReadFile( const std::string& pFile, aiScene* pScene, void SetupProperties(const Importer *pImp);
IOSystem* pIOHandler);
// -------------------------------------------------------------------
void SetupProperties(const Importer* pImp);
private: private:
bool configComputeUVs; bool configComputeUVs;
}; //! class TerragenImporter }; //! class TerragenImporter

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2020, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -49,13 +47,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_STREAMREADER_H_INCLUDED #define AI_STREAMREADER_H_INCLUDED
#ifdef __GNUC__ #ifdef __GNUC__
# pragma GCC system_header #pragma GCC system_header
#endif #endif
#include <assimp/IOStream.hpp>
#include <assimp/Defines.h>
#include <assimp/ByteSwapper.h> #include <assimp/ByteSwapper.h>
#include <assimp/Defines.h>
#include <assimp/Exceptional.h> #include <assimp/Exceptional.h>
#include <assimp/IOStream.hpp>
#include <memory> #include <memory>
@ -74,10 +72,8 @@ namespace Assimp {
template <bool SwapEndianess = false, bool RuntimeSwitch = false> template <bool SwapEndianess = false, bool RuntimeSwitch = false>
class StreamReader { class StreamReader {
public: public:
// FIXME: use these data types throughout the whole library, using diff = size_t;
// then change them to 64 bit values :-) using pos = size_t;
using diff = int;
using pos = unsigned int;
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Construction from a given stream with a well-defined endianness. /** Construction from a given stream with a well-defined endianness.
@ -91,40 +87,45 @@ public:
* stream is in little endian byte order. Otherwise the * stream is in little endian byte order. Otherwise the
* endianness information is contained in the @c SwapEndianess * endianness information is contained in the @c SwapEndianess
* template parameter and this parameter is meaningless. */ * template parameter and this parameter is meaningless. */
StreamReader(std::shared_ptr<IOStream> stream, bool le = false) StreamReader(std::shared_ptr<IOStream> stream, bool le = false) :
: stream(stream) mStream(stream),
, le(le) mBuffer(nullptr),
{ mCurrent(nullptr),
mEnd(nullptr),
mLimit(nullptr),
mLe(le) {
ai_assert(stream); ai_assert(stream);
InternBegin(); InternBegin();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
StreamReader(IOStream* stream, bool le = false) StreamReader(IOStream *stream, bool le = false) :
: stream(std::shared_ptr<IOStream>(stream)) mStream(std::shared_ptr<IOStream>(stream)),
, le(le) mBuffer(nullptr),
{ mCurrent(nullptr),
ai_assert(stream); mEnd(nullptr),
mLimit(nullptr),
mLe(le) {
ai_assert(nullptr != stream);
InternBegin(); InternBegin();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
~StreamReader() { ~StreamReader() {
delete[] buffer; delete[] mBuffer;
} }
// deprecated, use overloaded operator>> instead // deprecated, use overloaded operator>> instead
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a float from the stream */ /// Read a float from the stream.
float GetF4() float GetF4() {
{
return Get<float>(); return Get<float>();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a double from the stream */ /// Read a double from the stream.
double GetF8() { double GetF8() {
return Get<double>(); return Get<double>();
} }
@ -136,7 +137,7 @@ public:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a signed 8 bit integer from the stream */ /** Read a signed 8 bit integer from the stream */
int8_t GetI1() { int8_t GetI1() {
return Get<int8_t>(); return Get<int8_t>();
} }
@ -154,55 +155,55 @@ public:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a unsigned 16 bit integer from the stream */ /** Read a unsigned 16 bit integer from the stream */
uint16_t GetU2() { uint16_t GetU2() {
return Get<uint16_t>(); return Get<uint16_t>();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a unsigned 8 bit integer from the stream */ /// Read a unsigned 8 bit integer from the stream
uint8_t GetU1() { uint8_t GetU1() {
return Get<uint8_t>(); return Get<uint8_t>();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read an unsigned 32 bit integer from the stream */ /// Read an unsigned 32 bit integer from the stream
uint32_t GetU4() { uint32_t GetU4() {
return Get<uint32_t>(); return Get<uint32_t>();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Read a unsigned 64 bit integer from the stream */ /// Read a unsigned 64 bit integer from the stream
uint64_t GetU8() { uint64_t GetU8() {
return Get<uint64_t>(); return Get<uint64_t>();
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Get the remaining stream size (to the end of the stream) */ /// Get the remaining stream size (to the end of the stream)
unsigned int GetRemainingSize() const { size_t GetRemainingSize() const {
return (unsigned int)(end - current); return (unsigned int)(mEnd - mCurrent);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Get the remaining stream size (to the current read limit). The /** Get the remaining stream size (to the current read limit). The
* return value is the remaining size of the stream if no custom * return value is the remaining size of the stream if no custom
* read limit has been set. */ * read limit has been set. */
unsigned int GetRemainingSizeToLimit() const { size_t GetRemainingSizeToLimit() const {
return (unsigned int)(limit - current); return (unsigned int)(mLimit - mCurrent);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Increase the file pointer (relative seeking) */ /** Increase the file pointer (relative seeking) */
void IncPtr(intptr_t plus) { void IncPtr(intptr_t plus) {
current += plus; mCurrent += plus;
if (current > limit) { if (mCurrent > mLimit) {
throw DeadlyImportError("End of file or read limit was reached"); throw DeadlyImportError("End of file or read limit was reached");
} }
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Get the current file pointer */ /** Get the current file pointer */
int8_t* GetPtr() const { int8_t *GetPtr() const {
return current; return mCurrent;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -211,9 +212,9 @@ public:
* large chunks of data at once. * large chunks of data at once.
* @param p The new pointer, which is validated against the size * @param p The new pointer, which is validated against the size
* limit and buffer boundaries. */ * limit and buffer boundaries. */
void SetPtr(int8_t* p) { void SetPtr(int8_t *p) {
current = p; mCurrent = p;
if (current > limit || current < buffer) { if (mCurrent > mLimit || mCurrent < mBuffer) {
throw DeadlyImportError("End of file or read limit was reached"); throw DeadlyImportError("End of file or read limit was reached");
} }
} }
@ -222,21 +223,20 @@ public:
/** Copy n bytes to an external buffer /** Copy n bytes to an external buffer
* @param out Destination for copying * @param out Destination for copying
* @param bytes Number of bytes to copy */ * @param bytes Number of bytes to copy */
void CopyAndAdvance(void* out, size_t bytes) { void CopyAndAdvance(void *out, size_t bytes) {
int8_t* ur = GetPtr(); int8_t *ur = GetPtr();
SetPtr(ur+bytes); // fire exception if eof SetPtr(ur + bytes); // fire exception if eof
::memcpy(out,ur,bytes); ::memcpy(out, ur, bytes);
} }
// --------------------------------------------------------------------- /// @brief Get the current offset from the beginning of the file
/** Get the current offset from the beginning of the file */ int GetCurrentPos() const {
int GetCurrentPos() const { return (unsigned int)(mCurrent - mBuffer);
return (unsigned int)(current - buffer);
} }
void SetCurrentPos(size_t pos) { void SetCurrentPos(size_t pos) {
SetPtr(buffer + pos); SetPtr(mBuffer + pos);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -246,15 +246,15 @@ public:
* the beginning of the file. Specifying UINT_MAX * the beginning of the file. Specifying UINT_MAX
* resets the limit to the original end of the stream. * resets the limit to the original end of the stream.
* Returns the previously set limit. */ * Returns the previously set limit. */
unsigned int SetReadLimit(unsigned int _limit) { unsigned int SetReadLimit(unsigned int _limit) {
unsigned int prev = GetReadLimit(); unsigned int prev = GetReadLimit();
if (UINT_MAX == _limit) { if (UINT_MAX == _limit) {
limit = end; mLimit = mEnd;
return prev; return prev;
} }
limit = buffer + _limit; mLimit = mBuffer + _limit;
if (limit > end) { if (mLimit > mEnd) {
throw DeadlyImportError("StreamReader: Invalid read limit"); throw DeadlyImportError("StreamReader: Invalid read limit");
} }
return prev; return prev;
@ -263,21 +263,21 @@ public:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Get the current read limit in bytes. Reading over this limit /** Get the current read limit in bytes. Reading over this limit
* accidentally raises an exception. */ * accidentally raises an exception. */
unsigned int GetReadLimit() const { unsigned int GetReadLimit() const {
return (unsigned int)(limit - buffer); return (unsigned int)(mLimit - mBuffer);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Skip to the read limit in bytes. Reading over this limit /** Skip to the read limit in bytes. Reading over this limit
* accidentally raises an exception. */ * accidentally raises an exception. */
void SkipToReadLimit() { void SkipToReadLimit() {
current = limit; mCurrent = mLimit;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** overload operator>> and allow chaining of >> ops. */ /** overload operator>> and allow chaining of >> ops. */
template <typename T> template <typename T>
StreamReader& operator >> (T& f) { StreamReader &operator>>(T &f) {
f = Get<T>(); f = Get<T>();
return *this; return *this;
} }
@ -286,14 +286,14 @@ public:
/** Generic read method. ByteSwap::Swap(T*) *must* be defined */ /** Generic read method. ByteSwap::Swap(T*) *must* be defined */
template <typename T> template <typename T>
T Get() { T Get() {
if ( current + sizeof(T) > limit) { if (mCurrent + sizeof(T) > mLimit) {
throw DeadlyImportError("End of file or stream limit was reached"); throw DeadlyImportError("End of file or stream limit was reached");
} }
T f; T f;
::memcpy (&f, current, sizeof(T)); ::memcpy(&f, mCurrent, sizeof(T));
Intern::Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le); Intern::Getter<SwapEndianess, T, RuntimeSwitch>()(&f, mLe);
current += sizeof(T); mCurrent += sizeof(T);
return f; return f;
} }
@ -301,46 +301,44 @@ public:
private: private:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
void InternBegin() { void InternBegin() {
if (!stream) { if (nullptr == mStream) {
// in case someone wonders: StreamReader is frequently invoked with
// no prior validation whether the input stream is valid. Since
// no one bothers changing the error message, this message here
// is passed down to the caller and 'unable to open file'
// simply describes best what happened.
throw DeadlyImportError("StreamReader: Unable to open file"); throw DeadlyImportError("StreamReader: Unable to open file");
} }
const size_t s = stream->FileSize() - stream->Tell(); const size_t filesize = mStream->FileSize() - mStream->Tell();
if (!s) { if (0 == filesize) {
throw DeadlyImportError("StreamReader: File is empty or EOF is already reached"); throw DeadlyImportError("StreamReader: File is empty or EOF is already reached");
} }
current = buffer = new int8_t[s]; mCurrent = mBuffer = new int8_t[filesize];
const size_t read = stream->Read(current,1,s); const size_t read = mStream->Read(mCurrent, 1, filesize);
// (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable // (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable
ai_assert(read <= s); ai_assert(read <= filesize);
end = limit = &buffer[read-1] + 1; mEnd = mLimit = &mBuffer[read - 1] + 1;
} }
private: private:
std::shared_ptr<IOStream> stream; std::shared_ptr<IOStream> mStream;
int8_t *buffer, *current, *end, *limit; int8_t *mBuffer;
bool le; int8_t *mCurrent;
int8_t *mEnd;
int8_t *mLimit;
bool mLe;
}; };
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
// `static` StreamReaders. Their byte order is fixed and they might be a little bit faster. // `static` StreamReaders. Their byte order is fixed and they might be a little bit faster.
#ifdef AI_BUILD_BIG_ENDIAN #ifdef AI_BUILD_BIG_ENDIAN
typedef StreamReader<true> StreamReaderLE; typedef StreamReader<true> StreamReaderLE;
typedef StreamReader<false> StreamReaderBE; typedef StreamReader<false> StreamReaderBE;
#else #else
typedef StreamReader<true> StreamReaderBE; typedef StreamReader<true> StreamReaderBE;
typedef StreamReader<false> StreamReaderLE; typedef StreamReader<false> StreamReaderLE;
#endif #endif
// `dynamic` StreamReader. The byte order of the input data is specified in the // `dynamic` StreamReader. The byte order of the input data is specified in the
// c'tor. This involves runtime branching and might be a little bit slower. // c'tor. This involves runtime branching and might be a little bit slower.
typedef StreamReader<true,true> StreamReaderAny; typedef StreamReader<true, true> StreamReaderAny;
} // end namespace Assimp } // end namespace Assimp

View File

@ -140,6 +140,7 @@ SET( IMPORTERS
unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp
#unit/ImportExport/IRR/utIrrImportExport.cpp #unit/ImportExport/IRR/utIrrImportExport.cpp
unit/ImportExport/RAW/utRAWImportExport.cpp unit/ImportExport/RAW/utRAWImportExport.cpp
unit/ImportExport/Terragen/utTerragenImportExport.cpp
) )
SET( MATERIAL SET( MATERIAL

Binary file not shown.

View File

@ -48,17 +48,17 @@ using namespace Assimp;
class utRAWImportExport : public AbstractImportExportBase { class utRAWImportExport : public AbstractImportExportBase {
public: public:
virtual bool importerTest() { virtual bool importerTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/RAW/Wuson.raw", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/RAW/Wuson.raw", aiProcess_ValidateDataStructure);
#ifndef ASSIMP_BUILD_NO_RAW_IMPORTER #ifndef ASSIMP_BUILD_NO_RAW_IMPORTER
return nullptr != scene; return nullptr != scene;
#else #else
return nullptr == scene; return nullptr == scene;
#endif #endif
} }
}; };
TEST_F(utRAWImportExport, importSimpleRAWTest) { TEST_F(utRAWImportExport, importSimpleRAWTest) {
EXPECT_TRUE(importerTest()); EXPECT_TRUE(importerTest());
} }