Cache retrieved items via an original index map
parent
47c7c3cf50
commit
4d59dee5ea
|
@ -382,6 +382,7 @@ namespace glTF2
|
||||||
struct Object
|
struct Object
|
||||||
{
|
{
|
||||||
int index; //!< The index of this object within its property container
|
int index; //!< The index of this object within its property container
|
||||||
|
int oIndex; //!< The original index of this object defined in the JSON
|
||||||
std::string id; //!< The globally unique ID used to reference this object
|
std::string id; //!< The globally unique ID used to reference this object
|
||||||
std::string name; //!< The user-defined name of this object
|
std::string name; //!< The user-defined name of this object
|
||||||
|
|
||||||
|
@ -1025,14 +1026,14 @@ namespace glTF2
|
||||||
friend class Asset;
|
friend class Asset;
|
||||||
friend class AssetWriter;
|
friend class AssetWriter;
|
||||||
|
|
||||||
typedef typename std::gltf_unordered_map< std::string, unsigned int > Dict;
|
typedef typename std::gltf_unordered_map< unsigned int, unsigned int > Dict;
|
||||||
|
|
||||||
std::vector<T*> mObjs; //! The read objects
|
std::vector<T*> mObjs; //! The read objects
|
||||||
Dict mObjsById; //! The read objects accessible by id
|
Dict mObjsByOIndex; //! The read objects accessible by original index
|
||||||
const char* mDictId; //! ID of the dictionary object
|
const char* mDictId; //! ID of the dictionary object
|
||||||
const char* mExtId; //! ID of the extension defining the dictionary
|
const char* mExtId; //! ID of the extension defining the dictionary
|
||||||
Value* mDict; //! JSON dictionary object
|
Value* mDict; //! JSON dictionary object
|
||||||
Asset& mAsset; //! The asset instance
|
Asset& mAsset; //! The asset instance
|
||||||
|
|
||||||
void AttachToDocument(Document& doc);
|
void AttachToDocument(Document& doc);
|
||||||
void DetachFromDocument();
|
void DetachFromDocument();
|
||||||
|
|
|
@ -204,10 +204,8 @@ template<class T>
|
||||||
Ref<T> LazyDict<T>::Retrieve(unsigned int i)
|
Ref<T> LazyDict<T>::Retrieve(unsigned int i)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string id = std::string(mDictId) + "[" + std::to_string(i) + "]";
|
typename Dict::iterator it = mObjsByOIndex.find(i);
|
||||||
|
if (it != mObjsByOIndex.end()) {// already created?
|
||||||
typename Dict::iterator it = mObjsById.find(id);
|
|
||||||
if (it != mObjsById.end()) { // already created?
|
|
||||||
return Ref<T>(mObjs, it->second);
|
return Ref<T>(mObjs, it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +225,8 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i)
|
||||||
}
|
}
|
||||||
|
|
||||||
T* inst = new T();
|
T* inst = new T();
|
||||||
inst->id = id;
|
inst->id = std::string(mDictId) + "[" + std::to_string(i) + "]";
|
||||||
|
inst->oIndex = i;
|
||||||
ReadMember(obj, "name", inst->name);
|
ReadMember(obj, "name", inst->name);
|
||||||
inst->Read(obj, mAsset);
|
inst->Read(obj, mAsset);
|
||||||
|
|
||||||
|
@ -239,7 +238,7 @@ Ref<T> LazyDict<T>::Add(T* obj)
|
||||||
{
|
{
|
||||||
unsigned int idx = unsigned(mObjs.size());
|
unsigned int idx = unsigned(mObjs.size());
|
||||||
mObjs.push_back(obj);
|
mObjs.push_back(obj);
|
||||||
mObjsById[obj->id] = idx;
|
mObjsByOIndex[obj->oIndex] = idx;
|
||||||
mAsset.mUsedIds[obj->id] = true;
|
mAsset.mUsedIds[obj->id] = true;
|
||||||
return Ref<T>(mObjs, idx);
|
return Ref<T>(mObjs, idx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue