Jelajahi Sumber

Scene allocator

Panagiotis Christopoulos Charitos 13 tahun lalu
induk
melakukan
e34477d2a9

+ 2 - 5
include/anki/scene/Camera.h

@@ -29,11 +29,8 @@ public:
 	/// @{
 	Camera(CameraType type_,
 		const char* name, Scene* scene, // SceneNode
-		uint movableFlags, Movable* movParent, // Movable
-		Frustum* frustum) // Spatial & Frustumable
-		: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
-			Spatial(this, frustum), Frustumable(frustum, this), type(type_)
-	{}
+		U32 movableFlags, Movable* movParent, // Movable
+		Frustum* frustum); // Spatial & Frustumable
 
 	virtual ~Camera();
 	/// @}

+ 6 - 3
include/anki/scene/Movable.h

@@ -5,6 +5,7 @@
 #include "anki/util/Flags.h"
 #include "anki/math/Math.h"
 #include "anki/core/Timestamp.h"
+#include "anki/scene/Common.h"
 
 namespace anki {
 
@@ -14,10 +15,11 @@ class PropertyMap;
 /// @{
 
 /// Interface for movable scene nodes
-class Movable: public Object<Movable>, public Flags<U32>
+class Movable: public Object<Movable, SceneAllocator<Movable>>,
+	public Flags<U32>
 {
 public:
-	typedef Object<Movable> Base;
+	typedef Object<Movable, SceneAllocator<Movable>> Base;
 
 	enum MovableFlag
 	{
@@ -35,7 +37,8 @@ public:
 	/// @param flags The flags
 	/// @param parent The parent. It can be nullptr
 	/// @param pmap Property map to add a few variables
-	Movable(U32 flags, Movable* parent, PropertyMap& pmap);
+	Movable(U32 flags, Movable* parent, PropertyMap& pmap,
+		const SceneAllocator<Movable>& alloc);
 
 	~Movable();
 	/// @}

+ 1 - 1
include/anki/scene/ParticleEmitter.h

@@ -244,7 +244,7 @@ public:
 private:
 	ParticleEmitterResourcePointer particleEmitterResource;
 	std::unique_ptr<btCollisionShape> collShape;
-	PtrVector<ParticleBase> particles;
+	Vector<ParticleBase*> particles;
 	F32 timeLeftForNextEmission;
 	/// The resource
 	Aabb aabb;

+ 2 - 2
include/anki/scene/Renderable.h

@@ -146,7 +146,7 @@ private:
 class Renderable
 {
 public:
-	typedef PtrVector<RenderableVariable> RenderableVariables;
+	typedef Vector<RenderableVariable*> RenderableVariables;
 
 	Renderable()
 	{}
@@ -171,7 +171,7 @@ public:
 		return 1;
 	}
 
-	/// XXX
+	/// Get the center of the renderable. Used in sorting
 	virtual Vec3 getRenderableOrigin() const = 0;
 
 	/// @name Accessors

+ 11 - 10
include/anki/scene/SkinNode.h

@@ -85,6 +85,7 @@ public:
 	/// @name Constructors/Destructor
 	/// @{
 	SkinModelPatch(const ModelPatch* mpatch_);
+	~SkinModelPatch();
 	/// @}
 
 	/// @name Accessors
@@ -230,7 +231,7 @@ public:
 	}
 
 	/// Update the animation stuff
-	void frameUpdate(float prevUpdateTime, float crntTime, int frame);
+	void frameUpdate(F32 prevUpdateTime, F32 crntTime, int frame);
 	/// @}
 
 	/// @name Movable virtuals
@@ -263,7 +264,7 @@ public:
 		return boneTranslations;
 	}
 
-	const PtrVector<SkinPatchNode>& getPatchNodes() const
+	const Vector<SkinPatchNode*>& getPatchNodes() const
 	{
 		return patches;
 	}
@@ -273,28 +274,28 @@ public:
 		return *skin;
 	}
 
-	float getStep() const
+	F32 getStep() const
 	{
 		return step;
 	}
-	float& getStep()
+	F32& getStep()
 	{
 		return step;
 	}
-	void setStep(const float x)
+	void setStep(const F32 x)
 	{
 		step = x;
 	}
 
-	float getFrame() const
+	F32 getFrame() const
 	{
 		return frame;
 	}
-	float& getFrame()
+	F32& getFrame()
 	{
 		return frame;
 	}
-	void setFrame(const float x)
+	void setFrame(const F32 x)
 	{
 		frame = x;
 	}
@@ -311,7 +312,7 @@ public:
 
 private:
 	SkinResourcePointer skin; ///< The resource
-	PtrVector<SkinPatchNode> patches;
+	Vector<SkinPatchNode*> patches;
 	Obb visibilityShapeWSpace;
 
 	/// @name Animation stuff
@@ -334,7 +335,7 @@ private:
 	/// @param[in] frame Frame
 	/// @param[out] translations Translations vector
 	/// @param[out] rotations Rotations vector
-	static void interpolate(const SkelAnim& animation, float frame,
+	static void interpolate(const SkelAnim& animation, F32 frame,
 		Vector<Vec3>& translations, Vector<Mat3>& rotations);
 
 	/// Calculate the global pose

+ 1 - 0
include/anki/util/Memory.h

@@ -38,6 +38,7 @@ public:
 		return memsize;
 	}
 
+	/// Get the allocated size
 	PtrSize getAllocatedSize() const;
 
 	/// Allocate memory

+ 11 - 0
src/scene/Camera.cpp

@@ -6,6 +6,17 @@ namespace anki {
 // Camera                                                                      =
 //==============================================================================
 
+//==============================================================================
+Camera::Camera(CameraType type_,
+	const char* name, Scene* scene, // SceneNode
+	U32 movableFlags, Movable* movParent, // Movable
+	Frustum* frustum) // Spatial & Frustumable
+	:	SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator()),
+		Spatial(this, frustum),
+		Frustumable(frustum, this), type(type_)
+{}
+
 //==============================================================================
 Camera::~Camera()
 {}

+ 1 - 1
src/scene/Light.cpp

@@ -12,7 +12,7 @@ Light::Light(LightType t, // Light
 	U32 movableFlags, Movable* movParent, // Movable
 	CollisionShape* cs) // Spatial
 	: SceneNode(name, scene),
-		Movable(movableFlags, movParent, *this),
+		Movable(movableFlags, movParent, *this, getSceneAllocator()),
 		Spatial(this, cs), type(t)
 {
 	addNewProperty(new ReadWritePointerProperty<Vec4>("color", &color));

+ 4 - 2
src/scene/ModelNode.cpp

@@ -12,7 +12,8 @@ namespace anki {
 ModelPatchNode::ModelPatchNode(const ModelPatch* modelPatch_,
 	const char* name, Scene* scene,
 	uint movableFlags, Movable* movParent)
-	: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator()),
 		Spatial(this, &obb), modelPatch(modelPatch_)
 {
 	Renderable::init(*this);
@@ -26,7 +27,8 @@ ModelPatchNode::ModelPatchNode(const ModelPatch* modelPatch_,
 ModelNode::ModelNode(const char* modelFname,
 	const char* name, Scene* scene,
 	uint movableFlags, Movable* movParent)
-	: SceneNode(name, scene), Movable(movableFlags, movParent, *this)
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator())
 {
 	model.load(modelFname);
 

+ 3 - 2
src/scene/Movable.cpp

@@ -4,8 +4,9 @@
 namespace anki {
 
 //==============================================================================
-Movable::Movable(U32 flags_, Movable* parent, PropertyMap& pmap)
-	: Base(this, parent), Flags(flags_)
+Movable::Movable(U32 flags_, Movable* parent, PropertyMap& pmap,
+	const SceneAllocator<Movable>& alloc)
+	: Base(this, parent, alloc), Flags(flags_)
 {
 	pmap.addNewProperty(
 		new ReadWritePointerProperty<Transform>("localTransform", &lTrf));

+ 11 - 4
src/scene/ParticleEmitter.cpp

@@ -47,7 +47,8 @@ ParticleBase::ParticleBase(
 	const char* name, Scene* scene, 
 	// Movable
 	U32 movableFlags, Movable* movParent)
-	: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator()),
 		type(type_)
 {}
 
@@ -222,8 +223,9 @@ ParticleEmitter::ParticleEmitter(
 	const char* name, Scene* scene, 
 	// Movable
 	U32 movableFlags, Movable* movParent)
-	: SceneNode(name, scene), Spatial(this, &aabb),
-		Movable(movableFlags, movParent, *this)
+	:	SceneNode(name, scene),
+		Spatial(this, &aabb),
+		Movable(movableFlags, movParent, *this, getSceneAllocator())
 {
 	// Load resource
 	particleEmitterResource.load(filename);
@@ -260,7 +262,12 @@ ParticleEmitter::ParticleEmitter(
 
 //==============================================================================
 ParticleEmitter::~ParticleEmitter()
-{}
+{
+	for(ParticleBase* part : particles)
+	{
+		delete part;
+	}
+}
 
 //==============================================================================
 const ModelPatchBase& ParticleEmitter::getRenderableModelPatchBase() const

+ 6 - 1
src/scene/Renderable.cpp

@@ -78,7 +78,12 @@ RenderableVariable::~RenderableVariable()
 
 //==============================================================================
 Renderable::~Renderable()
-{}
+{
+	for(RenderableVariable* var : vars)
+	{
+		delete var;
+	}
+}
 
 //==============================================================================
 void Renderable::init(PropertyMap& pmap)

+ 10 - 3
src/scene/SkinNode.cpp

@@ -125,7 +125,8 @@ SkinPatchNode::SkinPatchNode(const ModelPatch* modelPatch_,
 	const char* name, Scene* scene,
 	uint movableFlags, Movable* movParent,
 	CollisionShape* spatialCs)
-	: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator()),
 		Spatial(this, spatialCs)
 {
 	skinModelPatch.reset(new SkinModelPatch(modelPatch_));
@@ -140,7 +141,8 @@ SkinPatchNode::SkinPatchNode(const ModelPatch* modelPatch_,
 SkinNode::SkinNode(const char* skinFname,
 	const char* name, Scene* scene, // SceneNode
 	uint movableFlags, Movable* movParent) // Movable
-	: SceneNode(name, scene), Movable(movableFlags, movParent, *this)
+	: SceneNode(name, scene),
+		Movable(movableFlags, movParent, *this, getSceneAllocator())
 {
 	skin.load(skinFname);
 
@@ -165,7 +167,12 @@ SkinNode::SkinNode(const char* skinFname,
 
 //==============================================================================
 SkinNode::~SkinNode()
-{}
+{
+	for(SkinPatchNode* patch : patches)
+	{
+		delete patch;
+	}
+}
 
 //==============================================================================
 void SkinNode::movableUpdate()