Added: #1440 CStorageArray template

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent a4654cdf28
commit c037ac9334

@ -88,7 +88,16 @@ void CAnimatable::build(uint16 version)
CSceneClass::build(version); CSceneClass::build(version);
if (m_AppData) if (m_AppData)
{ {
putChunk(PMBS_APP_DATA_CHUNK_ID, m_AppData); if (m_AppData->entries().size() == 0)
{
// Discard appdata if it has no entries
delete m_AppData;
m_AppData = NULL;
}
else
{
putChunk(PMBS_APP_DATA_CHUNK_ID, m_AppData);
}
} }
} }
@ -117,13 +126,24 @@ const ISceneClassDesc *CAnimatable::classDesc() const
void CAnimatable::toStringLocal(std::ostream &ostream, const std::string &pad) const void CAnimatable::toStringLocal(std::ostream &ostream, const std::string &pad) const
{ {
CSceneClass::toStringLocal(ostream, pad); CSceneClass::toStringLocal(ostream, pad);
if (m_AppData) if (m_AppData && m_AppData->entries().size() != 0)
{ {
ostream << "\n" << pad << "AppData: "; ostream << "\n" << pad << "AppData: ";
m_AppData->toString(ostream, pad + "\t"); m_AppData->toString(ostream, pad + "\t");
} }
} }
STORAGE::CAppData *CAnimatable::appData()
{
if (m_ChunksOwnsPointers) { nlerror("Not parsed"); return NULL; }
if (!m_AppData)
{
m_AppData = new STORAGE::CAppData();
m_AppData->init();
}
return m_AppData;
}
IStorageObject *CAnimatable::createChunkById(uint16 id, bool container) IStorageObject *CAnimatable::createChunkById(uint16 id, bool container)
{ {
switch (id) switch (id)

@ -76,7 +76,7 @@ public:
virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const; virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const;
// public // public
inline STORAGE::CAppData *appData() const { return m_AppData; } STORAGE::CAppData *appData();
protected: protected:
// inherited // inherited

@ -42,6 +42,27 @@ namespace PIPELINE {
namespace MAX { namespace MAX {
namespace BUILTIN { namespace BUILTIN {
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Elevate warnings to errors in this file for stricter reading
#undef nlwarning
#define nlwarning nlerror
// Elevate debug to error in this file for debugging
// #undef nldebug
// #define nldebug nlerror
// Chunk identifiers
#define PMB_REFERENCES_2034_CHUNK_ID 0x2034
#define PMB_REFERENCES_2035_CHUNK_ID 0x2034
#define PMB_204B_EQUALS_2E_CHUNK_ID 0x204B
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CReferenceMaker::CReferenceMaker() CReferenceMaker::CReferenceMaker()
{ {
@ -101,6 +122,20 @@ void CReferenceMaker::toStringLocal(std::ostream &ostream, const std::string &pa
CAnimatable::toStringLocal(ostream, pad); CAnimatable::toStringLocal(ostream, pad);
} }
IStorageObject *CReferenceMaker::createChunkById(uint16 id, bool container)
{
switch (id)
{
case PMB_204B_EQUALS_2E_CHUNK_ID:
return new CStorageValue<uint8>();
}
return CAnimatable::createChunkById(id, container);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
} /* namespace BUILTIN */ } /* namespace BUILTIN */
} /* namespace MAX */ } /* namespace MAX */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -69,6 +69,10 @@ public:
virtual const ISceneClassDesc *classDesc() const; virtual const ISceneClassDesc *classDesc() const;
virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const; virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const;
protected:
// inherited
virtual IStorageObject *createChunkById(uint16 id, bool container);
}; /* class CReferenceMaker */ }; /* class CReferenceMaker */
typedef CSceneClassDesc<CReferenceMaker> CReferenceMakerClassDesc; typedef CSceneClassDesc<CReferenceMaker> CReferenceMakerClassDesc;

@ -101,6 +101,11 @@ void CReferenceTarget::toStringLocal(std::ostream &ostream, const std::string &p
CReferenceMaker::toStringLocal(ostream, pad); CReferenceMaker::toStringLocal(ostream, pad);
} }
IStorageObject *CReferenceTarget::createChunkById(uint16 id, bool container)
{
return CReferenceMaker::createChunkById(id, container);
}
} /* namespace BUILTIN */ } /* namespace BUILTIN */
} /* namespace MAX */ } /* namespace MAX */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -77,6 +77,10 @@ public:
virtual const ISceneClassDesc *classDesc() const; virtual const ISceneClassDesc *classDesc() const;
virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const; virtual void toStringLocal(std::ostream &ostream, const std::string &pad = "") const;
protected:
// inherited
virtual IStorageObject *createChunkById(uint16 id, bool container);
}; /* class CReferenceTarget */ }; /* class CReferenceTarget */
typedef CSceneClassDesc<CReferenceTarget> CReferenceTargetClassDesc; typedef CSceneClassDesc<CReferenceTarget> CReferenceTargetClassDesc;

@ -0,0 +1,49 @@
/**
* \file storage_array.cpp
* \brief CStorageArray
* \date 2012-08-21 11:33GMT
* \author Jan Boon (Kaetemi)
* CStorageArray
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE PIPELINE.
* RYZOM CORE PIPELINE is free software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* RYZOM CORE PIPELINE is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE PIPELINE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <nel/misc/types_nl.h>
#include "storage_array.h"
// STL includes
// NeL includes
// #include <nel/misc/debug.h>
// Project includes
using namespace std;
// using namespace NLMISC;
namespace PIPELINE {
namespace MAX {
void blahblahblah() { }
} /* namespace MAX */
} /* namespace PIPELINE */
/* end of file */

@ -0,0 +1,122 @@
/**
* \file storage_array.h
* \brief CStorageArray
* \date 2012-08-21 11:33GMT
* \author Jan Boon (Kaetemi)
* CStorageArray
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE PIPELINE.
* RYZOM CORE PIPELINE is free software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* RYZOM CORE PIPELINE is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE PIPELINE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef PIPELINE_STORAGE_ARRAY_H
#define PIPELINE_STORAGE_ARRAY_H
#include <nel/misc/types_nl.h>
// STL includes
#include <vector>
// NeL includes
#include <nel/misc/ucstring.h>
#include <nel/misc/string_common.h>
// Project includes
#include "storage_object.h"
namespace PIPELINE {
namespace MAX {
/**
* \brief CStorageArray
* \date 2012-08-21 11:33GMT
* \author Jan Boon (Kaetemi)
* WARNING: sizeof(TType) should match the serialized size,
* otherwise you must specialize the getSize and setSize functions!
*/
template <typename T>
class CStorageArray : public IStorageObject
{
public:
// public data
typedef T TType;
typedef std::vector<TType> TTypeArray;
TTypeArray Value;
// inherited
virtual std::string className() const;
virtual void serial(NLMISC::IStream &stream);
virtual void toString(std::ostream &ostream, const std::string &pad = "") const;
public: // should be protected but that doesn't compile, nice c++!
// Sets size when reading
virtual void setSize(sint32 size);
// Gets the size when writing, return false if unknown
virtual bool getSize(sint32 &size) const;
}; /* class CStorageArray */
template <typename T>
std::string CStorageArray<T>::className() const
{
return "StorageArray";
}
template <typename T>
void CStorageArray<T>::serial(NLMISC::IStream &stream)
{
for (typename TTypeArray::const_iterator it = Value.begin(), end = Value.end(); it != end; ++it)
{
stream.serial(*it);
}
}
template <typename T>
void CStorageArray<T>::toString(std::ostream &ostream, const std::string &pad) const
{
ostream << "(" << className() << ") { "; // << s << " } ";
uint i = 0;
for (typename TTypeArray::const_iterator it = Value.begin(), end = Value.end(); it != end; ++it)
{
std::string s = NLMISC::toString(*it);
ostream << "\n" << pad << i << ": " << s;
++i;
}
ostream << " } ";
}
template <typename T>
void CStorageArray<T>::setSize(sint32 size)
{
if ((sizeof(TType) % size) != 0)
nlerror("Size does not match value type");
Value.resize(size / sizeof(TType));
}
template <typename T>
bool CStorageArray<T>::getSize(sint32 &size) const
{
size = Value.size() * sizeof(TType);
return true;
}
} /* namespace MAX */
} /* namespace PIPELINE */
#endif /* #ifndef PIPELINE_STORAGE_ARRAY_H */
/* end of file */

@ -39,7 +39,8 @@
namespace PIPELINE { namespace PIPELINE {
namespace MAX { namespace MAX {
class CStorageChunks;
class CStorageChunks;
struct EStorage : public NLMISC::Exception struct EStorage : public NLMISC::Exception
{ {

@ -33,8 +33,8 @@
//static const char *filename = "/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max"; //static const char *filename = "/srv/work/database/interfaces/anims_max/cp_fy_hof_species.max";
//static const char *filename = "/home/kaetemi/source/minimax/GE_Acc_MikotoBaniere.max"; //static const char *filename = "/home/kaetemi/source/minimax/GE_Acc_MikotoBaniere.max";
//static const char *filename = "/home/kaetemi/3dsMax/scenes/test2008.max"; static const char *filename = "/home/kaetemi/3dsMax/scenes/test2008.max";
static const char *filename = "/home/kaetemi/3dsMax/scenes/teapot_test_scene.max"; //static const char *filename = "/home/kaetemi/3dsMax/scenes/teapot_test_scene.max";
static const char *streamname = "Scene"; static const char *streamname = "Scene";
// int __stdcall WinMain(void *, void *, void *, int) // int __stdcall WinMain(void *, void *, void *, int)

Loading…
Cancel
Save