소스 검색

Removing exceptions

Panagiotis Christopoulos Charitos 11 년 전
부모
커밋
4bf6007be5
3개의 변경된 파일69개의 추가작업 그리고 43개의 파일을 삭제
  1. 14 4
      include/anki/scene/InstanceNode.h
  2. 28 24
      include/anki/scene/SceneNode.h
  3. 27 15
      src/scene/SceneNode.cpp

+ 14 - 4
include/anki/scene/InstanceNode.h

@@ -32,13 +32,23 @@ class InstanceNode: public SceneNode,  public MoveComponent,
 	public InstanceComponent
 {
 public:
-	InstanceNode(const CString& name, SceneGraph* scene)
-	:	SceneNode(name, scene), 
+	InstanceNode(SceneGraph* scene)
+	:	SceneNode(scene), 
 		MoveComponent(this, MoveComponent::Flag::IGNORE_PARENT_TRANSFORM),
 		InstanceComponent(this)
+	{}
+
+	ANKI_USE_RESULT Error create(const CString& name)
 	{
-		addComponent(static_cast<MoveComponent*>(this));
-		addComponent(static_cast<InstanceComponent*>(this));
+		Error err = SceneNode::create(name, 2);
+
+		if(!err)
+		{
+			addComponent(static_cast<MoveComponent*>(this));
+			addComponent(static_cast<InstanceComponent*>(this));
+		}
+
+		return err;
 	}
 };
 

+ 28 - 24
include/anki/scene/SceneNode.h

@@ -23,16 +23,18 @@ class SceneNode: public SceneObject
 {
 public:
 	/// The one and only constructor
-	/// @param name The unique name of the node. If it's nullptr the the node
-	///             is not searchable
-	/// @param scene The scene that will register it
-	explicit SceneNode(
-		const CString& name,
-		SceneGraph* scene);
+	SceneNode(SceneGraph* scene);
 
 	/// Unregister node
 	virtual ~SceneNode();
 
+	/// @param name The unique name of the node. If it's nullptr the the node
+	///             is not searchable
+	/// @param scene The scene that will register it
+	ANKI_USE_RESULT Error create(
+		const CString& name, 
+		U32 maxComponents);
+
 	/// Return the name. It may be empty for nodes that we don't want to track
 	CString getName() const
 	{
@@ -43,10 +45,11 @@ public:
 	/// rendering. By default it does nothing
 	/// @param prevUpdateTime Timestamp of the previous update
 	/// @param crntTime Timestamp of this update
-	virtual void frameUpdate(F32 prevUpdateTime, F32 crntTime)
+	virtual ANKI_USE_RESULT Error frameUpdate(F32 prevUpdateTime, F32 crntTime)
 	{
 		(void)prevUpdateTime;
 		(void)crntTime;
+		return ErrorCode::NONE;
 	}
 
 	/// Return the last frame the node was updated. It checks all components
@@ -54,36 +57,36 @@ public:
 
 	/// Iterate all components
 	template<typename Func>
-	void iterateComponents(Func func)
+	ANKI_USE_RESULT Error iterateComponents(Func func) const
 	{
-		for(auto comp : m_components)
+		Error err = ErrorCode::NONE;
+		auto it = m_components.getBegin();
+		auto end = m_components.getEnd();
+		for(; !err && it != end; it++)
 		{
-			func(*comp);
+			err = func(*(*it));
 		}
-	}
 
-	/// Iterate all components. Const version
-	template<typename Func>
-	void iterateComponents(Func func) const
-	{
-		for(auto comp : m_components)
-		{
-			func(*comp);
-		}
+		return err;
 	}
 
 	/// Iterate all components of a specific type
 	template<typename Component, typename Func>
-	void iterateComponentsOfType(Func func)
+	ANKI_USE_RESULT Error iterateComponentsOfType(Func func)
 	{
+		Error err = ErrorCode::NONE;
 		SceneComponent::Type type = Component::getClassType();
-		for(auto comp : m_components)
+		auto it = m_components.getBegin();
+		auto end = m_components.getEnd();
+		for(; !err && it != end; it++)
 		{
-			if(comp->getType() == type)
+			if((*it)->getType() == type)
 			{
-				func(comp->downCast<Component>());
+				err = func(*(*it));
 			}
 		}
+
+		return err;
 	}
 
 	/// Try geting a pointer to the first component of the requested type
@@ -151,7 +154,8 @@ protected:
 
 private:
 	SceneString m_name; ///< A unique name
-	SceneVector<SceneComponent*> m_components;
+	SceneDArray<SceneComponent*> m_components;
+	U8 m_componentsCount = 0;
 };
 
 /// @}

+ 27 - 15
src/scene/SceneNode.cpp

@@ -9,35 +9,49 @@
 namespace anki {
 
 //==============================================================================
-SceneNode::SceneNode(const CString& name, SceneGraph* scene)
-:	SceneObject(Type::SCENE_NODE, nullptr, scene),
-	m_name(getSceneAllocator()),
-	m_components(getSceneAllocator())
-{
-	ANKI_ASSERT(scene);
+SceneNode::SceneNode(SceneGraph* scene)
+:	SceneObject(Type::SCENE_NODE, scene)
+{}
 
-	m_components.reserve(2);
+//==============================================================================
+Error SceneNode::create(const CString& name, U32 maxComponents)
+{
+	Error err = ErrorCode::NONE;
+	
+	if(maxComponents)
+	{
+		err = m_components.create(getSceneAllocator(), maxComponents);
+	}
 
-	if(!name.isEmpty())
+	if(!err && !name.isEmpty())
 	{
-		m_name = name;
+		err = m_name.create(getSceneAllocator(), name);
 	}
+
+	return err;
 }
 
 //==============================================================================
 SceneNode::~SceneNode()
-{}
+{
+	auto alloc = getSceneAllocator();
+	m_name.destroy(alloc);
+	m_components.destroy(alloc);
+}
 
 //==============================================================================
 U32 SceneNode::getLastUpdateFrame() const
 {
 	U32 max = 0;
 
-	iterateComponents([&](const SceneComponent& comp)
+	Error err = iterateComponents([&max](const SceneComponent& comp) -> Error
 	{
 		max = std::max(max, comp.getTimestamp());
+		return ErrorCode::NONE;
 	});
 
+	(void)err;
+
 	return max;
 }
 
@@ -45,15 +59,13 @@ U32 SceneNode::getLastUpdateFrame() const
 void SceneNode::addComponent(SceneComponent* comp)
 {
 	ANKI_ASSERT(comp);
-	m_components.push_back(comp);
+	m_components[m_componentsCount++] = comp;
 }
 
 //==============================================================================
 void SceneNode::removeComponent(SceneComponent* comp)
 {
-	auto it = std::find(m_components.begin(), m_components.end(), comp);
-	ANKI_ASSERT(it != m_components.end());
-	m_components.erase(it);
+	ANKI_ASSERT(0 && "TODO");
 }
 
 //==============================================================================