Browse Source

Removed SerializableObject::OnLoaded callback, it was unused and took nearly half of the loading time

Jorrit Rouwe 3 năm trước cách đây
mục cha
commit
388d47254a

+ 0 - 9
Jolt/ObjectStream/ObjectStreamIn.cpp

@@ -178,15 +178,6 @@ void *ObjectStreamIn::Read(const RTTI *inRTTI)
 			}
 		}
 
-		// Call OnLoaded callback
-		unordered_set<SerializableObject *> visited_set;
-		OSVisitCompounds(main_object, inRTTI, [&visited_set](const void *inObject, const RTTI *inType) 
-			{ 
-				SerializableObject *so = const_cast<SerializableObject *>(reinterpret_cast<const SerializableObject *>(inType->CastTo(inObject, JPH_RTTI(SerializableObject))));
-				if (so != nullptr && visited_set.insert(so).second)
-					so->OnLoaded(); 
-			});
-
 		return main_object;
 	}
 	else

+ 0 - 1
Jolt/ObjectStream/SerializableAttribute.h

@@ -23,7 +23,6 @@ public:
 	virtual bool				ReadData(ObjectStreamIn &ioStream, void *inObject) const = 0;
 	virtual void				WriteData(ObjectStreamOut &ioStream, const void *inObject) const = 0;
 	virtual void				WriteDataType(ObjectStreamOut &ioStream) const = 0;
-	virtual void				VisitCompounds(const void *inObject, const CompoundVisitor &inVisitor) const = 0;
 };
 
 JPH_NAMESPACE_END

+ 0 - 5
Jolt/ObjectStream/SerializableAttributeEnum.h

@@ -50,11 +50,6 @@ public:
 		ioStream.WriteDataType(ObjectStream::EDataType::T_uint32);
 	}
 
-	virtual void				VisitCompounds(const void *inObject, const CompoundVisitor &inVisitor) const override
-	{
-		// An enum is not a compound, do nothing
-	}
-
 private:
 	T Class::*					mMember;
 };

+ 0 - 5
Jolt/ObjectStream/SerializableAttributeTyped.h

@@ -47,11 +47,6 @@ public:
 		OSWriteDataType(ioStream, (T *)nullptr);
 	}
 
-	virtual void				VisitCompounds(const void *inObject, const CompoundVisitor &inVisitor) const override
-	{
-		OSVisitCompounds(((const Class *)inObject)->*mMember, inVisitor);
-	}
-
 private:
 	T Class::*					mMember;
 };

+ 0 - 16
Jolt/ObjectStream/SerializableObject.cpp

@@ -11,20 +11,4 @@ JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT(SerializableObject)
 {
 }
 
-void OSVisitCompounds(const void *inObject, const RTTI *inRTTI, const CompoundVisitor &inVisitor)
-{
-	JPH_ASSERT(inObject != nullptr);
-
-	// Visit attributes
-	for (int i = 0; i < inRTTI->GetAttributeCount(); ++i)
-	{
-		const SerializableAttribute *attr = DynamicCast<SerializableAttribute>(inRTTI->GetAttribute(i));
-		if (attr != nullptr)
-			attr->VisitCompounds(inObject, inVisitor);
-	}
-
-	// Call visitor
-	inVisitor(inObject, inRTTI);
-}
-
 JPH_NAMESPACE_END

+ 2 - 69
Jolt/ObjectStream/SerializableObject.h

@@ -20,9 +20,7 @@ JPH_NAMESPACE_BEGIN
 	prefix void			OSWriteData(ObjectStreamOut &ioStream, const class_name &inInstance);						\
 	prefix void			OSWriteData(ObjectStreamOut &ioStream, class_name *const &inPointer);						\
 	prefix void			OSWriteDataType(ObjectStreamOut &ioStream, class_name *);									\
-	prefix void			OSWriteDataType(ObjectStreamOut &ioStream, class_name **);									\
-	prefix void			OSVisitCompounds(const class_name &inObject, const CompoundVisitor &inVisitor);				\
-	prefix void			OSVisitCompounds(const class_name *inObject, const CompoundVisitor &inVisitor);
+	prefix void			OSWriteDataType(ObjectStreamOut &ioStream, class_name **);
 
 // JPH_IMPLEMENT_SERIALIZATION_FUNCTIONS
 #define JPH_IMPLEMENT_SERIALIZATION_FUNCTIONS(class_name)															\
@@ -62,15 +60,6 @@ JPH_NAMESPACE_BEGIN
 	{																												\
 		ioStream.WriteDataType(ObjectStream::EDataType::Pointer);													\
 		ioStream.WriteName(#class_name);																			\
-	}																												\
-	void				OSVisitCompounds(const class_name &inObject, const CompoundVisitor &inVisitor)				\
-	{																												\
-		OSVisitCompounds(&inObject, JPH_RTTI(class_name), inVisitor);												\
-	}																												\
-	void				OSVisitCompounds(const class_name *inObject, const CompoundVisitor &inVisitor)				\
-	{																												\
-		if (inObject != nullptr)																					\
-			OSVisitCompounds(inObject, GetRTTI(inObject), inVisitor);												\
 	}
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -148,59 +137,7 @@ public:																												\
 // JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT_BASE
 #define JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT_BASE(class_name)														\
 	JPH_IMPLEMENT_SERIALIZATION_FUNCTIONS(class_name)																\
-	JPH_IMPLEMENT_RTTI_ABSTRACT_BASE(class_name)																	\
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// OSVisitCompounds
-//
-// Allows recursively visiting an object and all of its children depth first
-//////////////////////////////////////////////////////////////////////////////////////////
-
-/// Basic visitor that recurses to all attributes
-void OSVisitCompounds(const void *inObject, const RTTI *inRTTI, const CompoundVisitor &inVisitor);
-
-// Dummy implementation for OSVisitCompounds for all primitive types
-#define JPH_DECLARE_PRIMITIVE(name)																					\
-	inline void OSVisitCompounds(const name &inObject, const CompoundVisitor &inVisitor) { }
-
-// This file uses the JPH_DECLARE_PRIMITIVE macro to define all types
-#include <Jolt/ObjectStream/ObjectStreamTypes.h>
-
-/// Define visitor templates
-template <class T>
-void OSVisitCompounds(const Ref<T> &inObject, const CompoundVisitor &inVisitor)	
-{
-	if (inObject != nullptr)
-		OSVisitCompounds(inObject.GetPtr(), inVisitor);
-}
-
-template <class T>
-void OSVisitCompounds(const RefConst<T> &inObject, const CompoundVisitor &inVisitor)	
-{
-	if (inObject != nullptr)
-		OSVisitCompounds(inObject.GetPtr(), inVisitor);
-}
-
-template <class T>
-void OSVisitCompounds(const vector<T> &inObject, const CompoundVisitor &inVisitor)	
-{ 
-	for (const T &v : inObject)
-		OSVisitCompounds(v, inVisitor);
-}
-
-template <class T, uint N>
-void OSVisitCompounds(const StaticArray<T, N> &inObject, const CompoundVisitor &inVisitor)	
-{ 
-	for (const T &v : inObject)
-		OSVisitCompounds(v, inVisitor);
-}
-
-template <class T, uint N>
-void OSVisitCompounds(const T (&inObject)[N], const CompoundVisitor &inVisitor)	
-{ 
-	for (const T &v : inObject)
-		OSVisitCompounds(v, inVisitor);
-}
+	JPH_IMPLEMENT_RTTI_ABSTRACT_BASE(class_name)
 
 /// Classes must be derived from SerializableObject if you want to be able to save pointers or
 /// reference counting pointers to objects of this or derived classes. The type will automatically
@@ -212,10 +149,6 @@ class SerializableObject
 public:
 	/// Constructor
 	virtual						~SerializableObject() = default;
-
-	/// Callback given when object has been loaded from an object stream
-	/// This is called when all links have been resolved. Objects that this object point to have already received their OnLoaded callback.
-	virtual void				OnLoaded()																			{ /* Do nothing */ }
 };
 
 JPH_NAMESPACE_END