ソースを参照

Scene and optimizing Object

Panagiotis Christopoulos Charitos 13 年 前
コミット
b72a4323bd

+ 2 - 0
include/anki/scene/Frustumable.h

@@ -99,6 +99,8 @@ private:
 	Lights lights;
 };
 
+/// @}
+
 } // end namespace anki
 
 #endif

+ 4 - 3
include/anki/scene/Grid.h

@@ -9,7 +9,7 @@ namespace anki {
 class SceneNode;
 class Frustumable;
 
-/// XXX
+/// Space partitioning container
 class Grid
 {
 public:
@@ -36,8 +36,9 @@ public:
 	/// Place a scene node in the grid
 	Bool placeSceneNode(SceneNode* sn);
 
-	/// Populate the fr with visible scene nodes and go up
-	void doVisibilityTests(Frustumable& fr);
+	/// XXX
+	void getVisible(const Frustumable& cam, 
+		SceneVector<SceneNode*>& nodes);
 
 private:
 	Aabb aabb;

+ 39 - 13
include/anki/util/Object.h

@@ -23,14 +23,12 @@ public:
 	typedef Vector<Value*, Alloc> Container;
 
 	/// Calls addChild if parent is not nullptr
-	Object(Value* self_, Value* parent_, const Alloc& alloc = Alloc())
-		: self(self_), childs(alloc)
+	Object(Value* parent_, const Alloc& alloc = Alloc())
+		: childs(alloc)
 	{
-		ANKI_ASSERT(self != nullptr && "Self can't be nullptr");
-		ANKI_ASSERT(parent_ != this && "Cannot put itself");
 		if(parent_ != nullptr)
 		{
-			parent_->addChild(self);
+			parent_->addChild(getSelf());
 		}
 		parent = parent_;
 	}
@@ -40,7 +38,7 @@ public:
 	{
 		if(parent != nullptr)
 		{
-			parent->removeChild(self);
+			parent->removeChild(getSelf());
 		}
 
 		// Remove all children (fast version)
@@ -88,9 +86,13 @@ public:
 	void addChild(Value* child)
 	{
 		ANKI_ASSERT(child != nullptr && "Null arg");
-		ANKI_ASSERT(child->parent ==  nullptr && "Child already has parent");
+		ANKI_ASSERT(child != getSelf() && "Cannot put itself");
+		ANKI_ASSERT(child->parent == nullptr && "Child already has parent");
+		ANKI_ASSERT(child->findChild(getSelf()) == child->childs.end() 
+			&& "Cyclic add");
+		ANKI_ASSERT(findChild(child) == childs.end() && "Already a child");
 
-		child->parent = self;
+		child->parent = getSelf();
 		childs.push_back(child);
 	}
 
@@ -98,10 +100,9 @@ public:
 	void removeChild(Value* child)
 	{
 		ANKI_ASSERT(child != nullptr && "Null arg");
-		ANKI_ASSERT(child->parent == self);
+		ANKI_ASSERT(child->parent == getSelf() && "Child has other parent");
 
-		typename Container::iterator it =
-			std::find(childs.begin(), childs.end(), child);
+		typename Container::iterator it = findChild(child);
 
 		ANKI_ASSERT(it != childs.end() && "Child not found");
 
@@ -109,10 +110,35 @@ public:
 		child->parent = nullptr;
 	}
 
+	/// Visit
+	template<typename Visitor>
+	void visitTreeDepth(Visitor& vis)
+	{
+		vis(*getSelf());
+
+		for(Value* c : childs)
+		{
+			c->visitTreeDepth(vis);
+		}
+	}
+
 private:
-	Value* self = nullptr;
-	Value* parent = nullptr; ///< May be nullptr
+	Value* parent; ///< May be nullptr
 	Container childs;
+
+	/// Cast the Object to the given type
+	Value* getSelf()
+	{
+		return static_cast<Value*>(this);
+	}
+
+	/// Find the child
+	typename Container::iterator findChild(Value* child)
+	{
+		typename Container::iterator it =
+			std::find(childs.begin(), childs.end(), child);
+		return it;
+	}
 };
 
 /// @}

+ 2 - 2
src/scene/Grid.cpp

@@ -60,9 +60,9 @@ Bool Grid::placeSceneNode(SceneNode* sn)
 }
 
 //==============================================================================
-void doVisibilityTests(Frustumable& fr)
+void getVisible(const Frustumable& /*cam*/, SceneVector<SceneNode*>& nodes)
 {
-
+	nodes.insert(nodes.end(), sceneNodes.begin(), sceneNodes.end());
 }
 
 } // end namespace anki

+ 1 - 1
src/scene/Movable.cpp

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