소스 검색

The update of the scene graph continues (still cannot compile)
*Rewriting the scene.h and scene.cpp
*Added skel_model_node.*

Panagiotis Christopoulos Charitos 16 년 전
부모
커밋
9572394739
7개의 변경된 파일226개의 추가작업 그리고 118개의 파일을 삭제
  1. 5 2
      src/scene/mesh_node.h
  2. 1 0
      src/scene/node.cpp
  3. 2 1
      src/scene/node.h
  4. 89 10
      src/scene/scene.cpp
  5. 18 105
      src/scene/scene.h
  6. 86 0
      src/scene/skel_model_node.cpp
  7. 25 0
      src/scene/skel_model_node.h

+ 5 - 2
src/scene/mesh_node.h

@@ -18,7 +18,10 @@ class skel_controller_t: public controller_t<mesh_node_t>
 		skel_node_t* skel_node;
 		mesh_node_t* mesh_node;
 
-		skel_controller_t( mesh_node_t* mesh_node_ ): mesh_node(mesh_node_) {}
+		skel_controller_t( skel_node_t* skel_node_, mesh_node_t* mesh_node_ ):
+			skel_node( skel_node_ ),
+			mesh_node( mesh_node_ ) 
+		{}
 		void Update() {}
 };
 
@@ -31,7 +34,7 @@ class mesh_node_t: public node_t
 		material_t* material;
 		skel_controller_t* skel_controller;
 
-		mesh_node_t(): node_t(NT_MESH) {}
+		mesh_node_t(): node_t(NT_MESH), skel_controller(NULL) {}
 
 		void Render();
 		void RenderDepth();

+ 1 - 0
src/scene/node.cpp

@@ -11,6 +11,7 @@ node_t::node_t( type_e type_ )
 {
 	type = type_;
 	parent = NULL;
+	is_group_node = false;
 	translation_lspace = vec3_t( 0.0, 0.0, 0.0 );
 	scale_lspace = 1.0;
 	rotation_lspace = mat3_t::GetIdentity();

+ 2 - 1
src/scene/node.h

@@ -20,7 +20,8 @@ class node_t
 			NT_LIGHT,
 			NT_CAMERA,
 			NT_MESH,
-			NT_SKELETON
+			NT_SKELETON,
+			NT_SKEL_MODEL
 		};
 
 		vec3_t translation_lspace;

+ 89 - 10
src/scene/scene.cpp

@@ -10,18 +10,97 @@ DATA
 */
 skybox_t skybox;
 
-extern container_node_t       nodes;
-extern container_light_t      lights;
-extern container_camera_t     cameras;
-extern container_mesh_node_t  mesh_nodes;
-extern container_skel_node_t  skel_nodes;
+container_node_t       nodes;
+container_light_t      lights;
+container_camera_t     cameras;
+container_mesh_node_t  mesh_nodes;
+container_skel_node_t  skel_nodes;
 
 
-/*
-=======================================================================================================================================
-UpdateAllWorldStuff                                                                                                                   =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// RegisterNode                                                                                                                       =
+//=====================================================================================================================================
+template<container_type_t, type_t> static void RegisterNode( container_type_t& container, type_t* x )
+{
+	DEBUG_ERR( std::find( container.begin(), container.end(), x ) != container.end() );
+	container.push_back( x );
+}
+
+template<container_type_t, type_t> static void UbregisterNode( container_type_t& container, type_t* x )
+{
+	container::iterator it = std::find( container.begin(), container.end(), x );
+	DEBUG_ERR( it == container.end() );
+	container.erase( it );
+}
+
+
+//=====================================================================================================================================
+// RegisterNodeAndChilds                                                                                                              =
+//=====================================================================================================================================
+void RegisterNodeAndChilds( node_t* node )
+{
+	RegisterNode( nodes, node );
+	
+	switch( node->type )
+	{
+		case node_t::NT_LIGHT:
+			RegisterNode( lights, static_cast<light_t*>(node) );
+			break;
+		case node_t::NT_CAMERA:
+			RegisterNode( cameras, static_cast<light_t*>(camera) );
+			break;
+		case node_t::NT_MESH:
+			RegisterNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
+			break;
+		case node_t::NT_SKELETON:
+			RegisterNode( skel_nodes, static_cast<skel_node_t*>(node) );
+			break;
+		case node_t::NT_SKEL_MODEL:
+			// ToDo
+			break;
+	};
+	
+	// now register the childs
+	for( vec_t<node_t*>::iterator it=node->childs.begin(); it!=node->childs.end(); it++ )
+		RegisterNodeAndChilds( it );
+}
+
+
+//=====================================================================================================================================
+// UnregisterNodeAndChilds                                                                                                            =
+//=====================================================================================================================================
+void UnregisterNodeAndChilds( node_t* node )
+{
+	UnregisterNode( nodes, node );
+	
+	switch( node->type )
+	{
+		case node_t::NT_LIGHT:
+			UnregisterNode( lights, static_cast<light_t*>(node) );
+			break;
+		case node_t::NT_CAMERA:
+			UnregisterNode( cameras, static_cast<light_t*>(camera) );
+			break;
+		case node_t::NT_MESH:
+			UnregisterNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
+			break;
+		case node_t::NT_SKELETON:
+			UnregisterNode( skel_nodes, static_cast<skel_node_t*>(node) );
+			break;
+		case node_t::NT_SKEL_MODEL:
+			// ToDo
+			break;
+	};
+	
+	// now register the childs
+	for( vec_t<node_t*>::iterator it=node->childs.begin(); it!=node->childs.end(); it++ )
+		UnregisterNodeAndChilds( it );
+}
+
+
+//=====================================================================================================================================
+// UpdateAllWorldStuff                                                                                                                =
+//=====================================================================================================================================
 void UpdateAllWorldStuff()
 {
 	DEBUG_ERR( nodes.size() > 1024 );

+ 18 - 105
src/scene/scene.h

@@ -13,6 +13,9 @@ namespace scene {
 extern skybox_t skybox;
 inline vec3_t GetAmbientColor() { return vec3_t( 0.1, 0.05, 0.05 )*1; }
 
+
+extern void RegisterNodeAndChilds( node_t* node );
+extern void UnregisterNodeAndChilds( node_t* node );
 extern void UpdateAllWorldStuff();
 extern void UpdateAllSkeletonNodes();
 
@@ -22,126 +25,36 @@ extern void UpdateAllSkeletonNodes();
 template<typename type_t> class container_t: public vec_t<type_t*>
 {
 	protected:
-		typedef typename vector<type_t*>::iterator iterator_t; ///< Just to save me time from typing
-
-		/**
-		 * Register x in this container only. Throw error if its already registered
-		 * @param x pointer to the object we want to register
-		 */
-		void RegisterMe( type_t* x )
-		{
-			DEBUG_ERR( Search( x ) ); // the obj must not be already loaded
+		friend void RegisterNode( node_t* node );
+		friend void UnregisterNode( node_t* node );
+	
+		typedef typename vec_t<type_t*>::iterator iterator_t; ///< Just to save me time from typing
 
-			vec_t<type_t*>::push_back( x );
-		}
-
-
-		/**
-		 * Unregister x from this container only
-		 * @param x pointer to the object we want to unregister
-		 */
-		void UnregisterMe( type_t* x )
+		iterator_t Find( type_t* x ) const
 		{
-			uint i;
-			for( i=0; i<vec_t<type_t*>::size(); i++ )
-			{
-				if( (*this)[i] == x )
-					break;
-			}
-
-			if( i==vec_t<type_t*>::size() )
-			{
-				ERROR( "Entity is unregistered" );
-				return;
-			}
-
-			vec_t<type_t*>::erase( vec_t<type_t*>::begin() + i );
+			return std::find( begin(), end(), x );
 		}
 
 	public:
-		container_t() {};
-		virtual ~container_t() {};
-
+		
 		/**
-		 * Search in container by pointer
-		 * @param x pointer to the object
+		 * Check if a type_t is registered in this container
 		 */
-		bool Search( type_t* x )
+		bool IsRegistered( type_t* x ) const
 		{
-			for( iterator_t it=vec_t<type_t*>::begin(); it<vec_t<type_t*>::end(); it++ )
-			{
-				if( x == *it ) return true;
-			}
-			return false;
+			return Find(x) != end();
 		}
 
-
-		/**
-		 * Search in container by name
-		 * @param name The name of the resource object
-		 */
-		type_t* Search( const char* name )
-		{
-			for( iterator_t it=vec_t<type_t*>::begin(); it<vec_t<type_t*>::end(); it++ )
-			{
-				if( strcmp( name, (*it)->GetName() ) == 0 )
-				return *it;
-			}
-			return NULL;
-		}
-
-
-		/**
-		 * Register x in this container and register it to more containers if needed. Thats why its abstract.
-		 * @param: x pointer to an object
-		 */
-		virtual void Register( type_t* x ) = 0;
-
-		/**
-		 * See Register
-		 * @param: x pointer to an object
-		 */
-		virtual void Unregister( type_t* x ) = 0;
-
 }; // end class container_t
 
 
 
 // conaiteners
-class container_node_t: public container_t<node_t>
-{
-	public:
-		void Register( node_t* x );
-		void Unregister( node_t* x );
-};
-
-class container_light_t: public container_t<light_t>
-{
-	public:
-		void Register( light_t* x );
-		void Unregister( light_t* x );
-};
-
-class container_camera_t: public container_t<camera_t>
-{
-	public:
-		void Register( camera_t* x );
-		void Unregister( camera_t* x );
-};
-
-class container_mesh_node_t: public container_t<mesh_node_t>
-{
-	public:
-		void Register( mesh_node_t* x );
-		void Unregister( mesh_node_t* x );
-};
-
-class container_skel_node_t: public container_t<skel_node_t>
-{
-	public:
-		void Register( skel_node_t* x );
-		void Unregister( skel_node_t* x );
-};
+typedef container_t<node_t> container_node_t;
+typedef container_t<light_t> container_light_t;
+typedef container_t<camera_t> container_camera_t;
+typedef container_t<mesh_node_t> container_mesh_node_t;
+typedef container_t<skel_node_t> container_skel_node_t;
 
 
 extern container_node_t       nodes;

+ 86 - 0
src/scene/skel_model_node.cpp

@@ -0,0 +1,86 @@
+#include "skel_model_node.h"
+#include "scanner.h"
+#include "parser.h"
+
+
+void skel_model_node_t::Init( const char* filename )
+{
+	scanner_t scanner;
+	if( !scanner.LoadFile( filename ) ) return false;
+
+	const scanner_t::token_t* token;
+
+	do
+	{
+		token = &scanner.GetNextToken();
+
+		//** MESHES **
+		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "MESHES_NUM" ) )
+		{
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_NUMBER || token->code != scanner_t::DT_INTEGER )
+			{
+				PARSE_ERR_EXPECTED( "integer" );
+				return false;
+			}
+			
+			mesh_nodes.resize( token->value.int_ );
+			
+			for( uint i=0; i<mesh_nodes.size(); ++i )
+			{
+				token = &scanner.GetNextToken();
+				if( token->code != scanner_t::TC_STRING )
+				{
+					PARSE_ERR_EXPECTED( "string" );
+					return false;
+				}
+				
+				mesh_nodes[i] = new mesh_node_t;
+				mesh_nodes[i]->Init( token->value.string );
+			}			
+		}
+
+		//** SKELETON **
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SKELETON" ) )
+		{
+			if( skel_node )
+			{
+				PARSE_ERR( "skel_node allready set" );
+				return false;
+			}
+
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_STRING )
+			{
+				PARSE_ERR_EXPECTED( "string" );
+				return false;
+			}
+			
+			skel_node = new skel_node;
+			skel_node->Init( token->value.string );
+		}
+
+		//** EOF **
+		else if( token->code == scanner_t::TC_EOF )
+		{
+			break;
+		}
+
+		//** other crap **
+		else
+		{
+			PARSE_ERR_UNEXPECTED();
+			return false;
+		}
+	}while( true ); // end do
+
+
+	AddChild( skel_node );
+	for( uint i=0; i<mesh_nodes.size(); ++i )
+	{
+		skel_node->AddChild( mesh_nodes[i] );
+		mesh_nodes[i]->skel_controller = new skel_controller( skel_node, mesh_nodes[i] );
+	}
+	
+	return true;
+}

+ 25 - 0
src/scene/skel_model_node.h

@@ -0,0 +1,25 @@
+#ifndef _SKEL_MODEL_NODE_H_
+#define _SKEL_MODEL_NODE_H_
+
+#include "common.h"
+#include "mesh_node.h" 
+
+
+class mesh_node_t;
+class skel_node
+
+
+/// Skeleton model scene node
+class skel_model_node_t: public node_t
+{
+	public:
+		vec_t<mesh_node_t*> mesh_nodes;
+		skel_node_t* skel_node;
+		
+		skel_model_node_t(): node_t(NT_SKEL_MODEL), skel_node(NULL) { is_group_node = true; }
+		void Init( const char* filename );
+		void Deinit() {} ///< Do nothing because it loads no resources
+		void Render() {}
+};
+
+#endif