fix possible warnings
parent
22d6b761e6
commit
4c177ad72e
|
@ -441,12 +441,34 @@ 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)),
|
||||||
|
@ -465,6 +487,7 @@ struct Material {
|
||||||
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 {
|
||||||
|
|
|
@ -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,19 +68,16 @@ 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);
|
||||||
|
|
||||||
|
@ -105,15 +98,13 @@ bool TerragenImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
|
@ -121,8 +112,7 @@ void TerragenImporter::SetupProperties(const Importer* pImp)
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// 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
|
||||||
|
@ -151,8 +141,7 @@ 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);
|
||||||
|
|
||||||
|
@ -161,42 +150,35 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
|
||||||
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();
|
||||||
|
|
||||||
|
@ -247,8 +229,10 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
|
||||||
|
|
||||||
// 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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -69,21 +68,17 @@ 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;
|
||||||
|
|
||||||
|
@ -95,7 +90,6 @@ protected:
|
||||||
void SetupProperties(const Importer *pImp);
|
void SetupProperties(const Importer *pImp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool configComputeUVs;
|
bool configComputeUVs;
|
||||||
|
|
||||||
}; //! class TerragenImporter
|
}; //! class TerragenImporter
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -52,10 +50,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#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,39 +87,44 @@ 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>();
|
||||||
}
|
}
|
||||||
|
@ -159,42 +160,42 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +203,7 @@ public:
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Get the current file pointer */
|
/** Get the current file pointer */
|
||||||
int8_t *GetPtr() const {
|
int8_t *GetPtr() const {
|
||||||
return current;
|
return mCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -212,8 +213,8 @@ public:
|
||||||
* @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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,14 +230,13 @@ public:
|
||||||
::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)(current - buffer);
|
return (unsigned int)(mCurrent - mBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCurrentPos(size_t pos) {
|
void SetCurrentPos(size_t pos) {
|
||||||
SetPtr(buffer + pos);
|
SetPtr(mBuffer + pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -249,12 +249,12 @@ public:
|
||||||
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;
|
||||||
|
@ -264,14 +264,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -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,31 +301,29 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -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.
Loading…
Reference in New Issue