Переглянути джерело

*Now the tokenizer supports the generic iostream as an input
*Continue working on scenegraph

Panagiotis Christopoulos Charitos 16 роки тому
батько
коміт
6b3dbfc0b4

+ 37 - 125
src/main.cpp

@@ -29,52 +29,15 @@
 #include "mesh_node.h"
 #include "mesh_node.h"
 #include "skel_anim.h"
 #include "skel_anim.h"
 
 
-camera_t main_cam;
-
-mesh_node_t imp, mcube, floor__, sarge;
-
-smodel_t mdl;
+// map (hard coded)
+camera_t* main_cam;
+mesh_node_t* floor__,* sarge,* horse;
+skel_model_node_t* imp;
+point_light_t* point_lights[10];
+spot_light_t* projlights[2];
 
 
 skel_anim_t walk_anim;
 skel_anim_t walk_anim;
 
 
-point_light_t point_lights[10];
-spot_light_t projlights[2];
-
-map_t map;
-
-class sphere_t: public mesh_node_t
-{
-	public:
-		sphere_t()
-		{
-			translation_lspace = vec3_t( 0.0, 0.0, 0.0 );
-			scale_lspace = 2.5;
-		}
-
-		void Render()
-		{
-			glPushMatrix();
-			r::MultMatrix( transformation_wspace );
-
-			//r::dbg::RenderSphere( 1.0, 16.0 );
-			r::dbg::RenderCube( false, 1.0 );
-
-			glPopMatrix();
-		}
-
-		void RenderDepth()
-		{
-			glPushMatrix();
-			r::MultMatrix( transformation_wspace );
-
-			//r::dbg::RenderSphere( 1.0, 16.0 );
-			r::dbg::RenderCube( false, 1.0 );
-
-			glPopMatrix();
-		}
-} sphere;
-
-//lala
 
 
 /*
 /*
 =======================================================================================================================================
 =======================================================================================================================================
@@ -97,92 +60,41 @@ void Init()
 	r::Init();
 	r::Init();
 	hud::Init();
 	hud::Init();
 
 
-
-	main_cam = camera_t( r::aspect_ratio*ToRad(60.0), ToRad(60.0), 0.5, 100.0 );
+	// camera
+	main_cam = new camera_t( r::aspect_ratio*ToRad(60.0), ToRad(60.0), 0.5, 100.0 );
 	main_cam.MoveLocalY( 3.0 );
 	main_cam.MoveLocalY( 3.0 );
 	main_cam.MoveLocalZ( 5.7 );
 	main_cam.MoveLocalZ( 5.7 );
 	main_cam.MoveLocalX( -0.3 );
 	main_cam.MoveLocalX( -0.3 );
-//	main_cam.translation_lspace = vec3_t(2.0, 2.0, 0.0);
-//	main_cam.RotateLocalY( ToRad(75) );
-//	main_cam.RotateLocalX( ToRad(-30) );
-	main_cam.camera_data_user_class_t::SetName("main_cam");
-
-	point_lights[0].SetSpecularColor( vec3_t( 0.4, 0.4, 0.4) );
-	point_lights[0].SetDiffuseColor( vec3_t( 1.0, 0.0, 0.0)*1 );
-	point_lights[0].translation_lspace = vec3_t( -1.0, 2.4, 1.0 );
-	point_lights[0].radius = 2.0;
-	point_lights[1].SetSpecularColor( vec3_t( 0.0, 1.0, 0.0)*1 );
-	point_lights[1].SetDiffuseColor( vec3_t( 3.0, 0.1, 0.1) );
-	point_lights[1].translation_lspace = vec3_t( 2.5, 1.4, 1.0 );
-	point_lights[1].radius = 3.0;
-	projlights[0].camera.SetAll( ToRad(60), ToRad(60), 0.1, 20.0 );
-	projlights[0].texture = rsrc::textures.Load( "gfx/lights/flashlight.tga" );
-	projlights[0].texture->TexParameter( GL_TEXTURE_MAX_ANISOTROPY_EXT, 0 );
-	projlights[0].SetSpecularColor( vec3_t( 1.0, 1.0, 1.0) );
-	projlights[0].SetDiffuseColor( vec3_t( 1.0, 1.0, 1.0)*4.0 );
-	projlights[0].translation_lspace = vec3_t( 1.3, 4.3, 3.0 );
-	projlights[0].rotation_lspace.RotateYAxis(ToRad(20));
-	projlights[0].rotation_lspace.RotateXAxis(ToRad(-30));
-	projlights[0].casts_shadow = true;
-
-//	projlights[0].translation_lspace = vec3_t( 2.36, 1.14, 9.70 );
-//	projlights[0].rotation_lspace = euler_t( ToRad(-27.13), ToRad(38.13), ToRad(18.28) );
-
-	projlights[1].camera.SetAll( ToRad(60), ToRad(60), 0.1, 20.0 );
-	projlights[1].texture = rsrc::textures.Load( "gfx/lights/impflash.tga" );
-	projlights[1].SetSpecularColor( vec3_t( 1.0, 1.0, 0.0) );
-	projlights[1].SetDiffuseColor( vec3_t( 1.0, 1.0, 1.0) );
-	projlights[1].translation_lspace = vec3_t( -2.3, 6.3, 2.9 );
-	projlights[1].rotation_lspace.RotateYAxis(ToRad(-20));
-	projlights[1].rotation_lspace.RotateXAxis(ToRad(-70));
-	projlights[1].casts_shadow = true;
-
-	/*imp.Load( "models/imp/imp.mesh" );
-	//imp.Load( "maps/temple/column.mesh" );
-	imp.translation_lspace = vec3_t( 0.0, 2.11, 0.0 );
-	imp.scale_lspace = 0.7;
-	imp.rotation_lspace.RotateXAxis( -PI/2 );*/
-
-	mcube.Load( "meshes/horse/horse.mesh" );
-	mcube.translation_lspace = vec3_t( -2, 0, 1 );
-	mcube.scale_lspace = 0.5;
-	mcube.rotation_lspace.RotateXAxis(ToRad(-90));
-
-	/*floor__.Load( "maps/temple/floor.mesh" );
-	floor__.translation_lspace = vec3_t(0.0, -0.2, 0.0);*/
-
-	sarge.Load( "meshes/sarge/sarge.mesh" );
-	sarge.scale_lspace = 0.1;
-	sarge.RotateLocalX(ToRad(-90));
-	sarge.translation_lspace = vec3_t(0, -2.8, 1.0);
-
-	mdl.Init( rsrc::model.Load( "models/imp/imp.smdl" ) );
-	mdl.translation_lspace = vec3_t( 0.0, 2.11, 0.0 );
-	mdl.scale_lspace = 0.7;
-	mdl.rotation_lspace.RotateXAxis( -PI/2 );
-	walk_anim.Load( "models/imp/walk.imp.anim" );
-	mdl.Play( &walk_anim, 0, 0.8, smodel_t::START_IMMEDIATELY );
-
-	sphere.material = rsrc::materials.Load( "materials/volfog.mtl" );
 
 
+	// lights
+	point_lights[0] = new point_light_t();
+	point_lights[0]->light_mtl = rsrc::light_mtls.Load( "maps/temple/light0.lmtl" );
+	point_lights[0]->SetLocatTransformation( vec3_t( -1.0, 2.4, 1.0 ), mat3_t::GetIdentity(), 1.0 );
+	point_lights[0]->radius = 2.0;
+
+	// horse
+	horse = new mesh_node_t();
+	horse->Init( "meshes/horse/horse.mesh" );
+	horst->SetLocalTransformation( vec3_t( -2, 0, 1 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.5 );
+	
+	// sarge
+	sarge = new mesh_node_t();
+	sarge->Init( "meshes/sarge/sarge.mesh" );
+	sarge->SetLocalTransformation( vec3_t( 0, -2.8, 1.0 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.1 );
+	
+	// imp	
+	imp = new skel_model_node_t();
+	imp->Init( "models/imp/imp.smdl" );
+	imp->SetLocalTransformation( vec3_t( 0.0, 2.11, 0.0 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.7 );
+	imp->mesh_nodes[0]->skel_controller = new mesh_node_t::skel_controller_t();
+	imp->mesh_nodes[0]->skel_controller->skel_node->skel_anim_controller->skel_anim = rsrc::skel_anims.Load( "models/imp/walk.imp.anim" );
+	imp->mesh_nodes[0]->skel_controller->skel_node->skel_anim_controller->step = 0.8;
 
 
-	// floor
-	floor__.Load( "maps/temple/Cube.019.mesh" );
-	floor__.rotation_lspace.RotateXAxis( ToRad(-90.0) );
-	floor__.translation_lspace.y -= 0.2;
 
 
-
-	scene::smodels.Register( &mdl );
-	scene::meshes.Register( &sarge );
-	//scene::meshes.Register( &sphere );
-	//scene::Register( &imp );
-	scene::meshes.Register( &floor__ );
-	scene::meshes.Register( &mcube );
-	scene::cameras.Register( &main_cam );
-	scene::lights.Register( &point_lights[0] );
-	scene::lights.Register( &point_lights[1] );
-	scene::lights.Register( &projlights[0] );
-	scene::lights.Register( &projlights[1] );
+	// floor
+	floor__ = new mesh_node_t();
+	floor__->Init( "maps/temple/Cube.019.mesh" );
+	floor__->SetLocalTransformation( vec3_t(0.0), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.8 );
 
 
 
 
 	const char* skybox_fnames [] = { "textures/env/hellsky4_forward.tga", "textures/env/hellsky4_back.tga", "textures/env/hellsky4_left.tga",
 	const char* skybox_fnames [] = { "textures/env/hellsky4_forward.tga", "textures/env/hellsky4_back.tga", "textures/env/hellsky4_left.tga",
@@ -218,7 +130,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		float scale = 0.01;
 		float scale = 0.01;
 
 
 		// move the camera
 		// move the camera
-		static object_t* mover = &main_cam;
+		static node_t* mover = &main_cam;
 
 
 		if( i::keys[ SDLK_1 ] ) mover = &main_cam;
 		if( i::keys[ SDLK_1 ] ) mover = &main_cam;
 		if( i::keys[ SDLK_2 ] ) mover = &point_lights[0];
 		if( i::keys[ SDLK_2 ] ) mover = &point_lights[0];
@@ -256,7 +168,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		mover->rotation_lspace.Reorthogonalize();
 		mover->rotation_lspace.Reorthogonalize();
 
 
 
 
-		scene::InterpolateAllModels();
+		scene::UpdateAllSkeletonNodes();
 		scene::UpdateAllWorldStuff();
 		scene::UpdateAllWorldStuff();
 
 
 		r::Render( main_cam );
 		r::Render( main_cam );

+ 15 - 4
src/scene/controller.h

@@ -4,14 +4,25 @@
 #include "common.h"
 #include "common.h"
 
 
 
 
-template<typename type_t> class controller_t
+/// Scenegraph node controller (A)
+class controller_t
 {
 {
 	public:
 	public:
-		enum type_e { CT_SKEL_ANIM, CT_SKEL };
+		enum type_e
+		{ 
+			CT_SKEL_ANIM, 
+			CT_SKEL,
+			CT_MATERIAL,
+			CT_LIGHT_MTL,
+			CT_TRF
+		};
+	
+	PROPERTY_R( type_e, type, GetType ) ///< Once the type is set nothing can change it
 
 
-		controller_t() {}
+	public:
+		controller_t( type_e type_ ): type(type_) {}
 		virtual ~controller_t() {}
 		virtual ~controller_t() {}
-		virtual void Update() = 0;
+		virtual void Update( float time ) = 0;
 };
 };
 
 
 
 

+ 1 - 1
src/scene/light.cpp

@@ -7,7 +7,7 @@
 //=====================================================================================================================================
 //=====================================================================================================================================
 // Init                                                                                                                               =
 // Init                                                                                                                               =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void light_t::Init( const char* filename )
+void light_t::Init( iostream* iostream_ )
 {
 {
 	light_mtl = rsrc::light_mtls.Load( filename );
 	light_mtl = rsrc::light_mtls.Load( filename );
 }
 }

+ 1 - 1
src/scene/light.h

@@ -40,7 +40,7 @@ class light_t: public node_t
 		light_mtl_t* light_mtl;
 		light_mtl_t* light_mtl;
 	
 	
 		light_t( types_e type_ ): node_t(NT_LIGHT), type(type_) {}
 		light_t( types_e type_ ): node_t(NT_LIGHT), type(type_) {}
-		void Init( const char* filename );
+		void Init( const char* );
 		void Deinit();
 		void Deinit();
 };
 };
 
 

+ 7 - 5
src/scene/node.cpp

@@ -2,23 +2,25 @@
 #include "node.h"
 #include "node.h"
 #include "renderer.h"
 #include "renderer.h"
 #include "collision.h"
 #include "collision.h"
+#include "scene.h"
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// Constructor                                                                                                                        =
+// CommonConstructorCode                                                                                                              =
 //=====================================================================================================================================
 //=====================================================================================================================================
-node_t::node_t( type_e type_ )
+void node_t::CommonConstructorCode()
 {
 {
-	type = type_;
 	parent = NULL;
 	parent = NULL;
 	is_group_node = false;
 	is_group_node = false;
-	translation_lspace = vec3_t( 0.0, 0.0, 0.0 );
+	translation_lspace = vec3_t( 0.0 );
 	scale_lspace = 1.0;
 	scale_lspace = 1.0;
 	rotation_lspace = mat3_t::GetIdentity();
 	rotation_lspace = mat3_t::GetIdentity();
-	translation_wspace = vec3_t( 0.0, 0.0, 0.0 );
+	translation_wspace = vec3_t( 0.0 );
 	scale_wspace = 1.0;
 	scale_wspace = 1.0;
 	rotation_wspace = mat3_t::GetIdentity();
 	rotation_wspace = mat3_t::GetIdentity();
 	bvolume_lspace = NULL;
 	bvolume_lspace = NULL;
+
+	scene::RegisterNode( this );
 }
 }
 
 
 
 

+ 15 - 6
src/scene/node.h

@@ -9,11 +9,13 @@
 
 
 class bvolume_t;
 class bvolume_t;
 class material_t;
 class material_t;
+class controller_t;
 
 
 
 
 /// Scene Node
 /// Scene Node
 class node_t
 class node_t
 {
 {
+	// data
 	public:
 	public:
 		enum type_e
 		enum type_e
 		{
 		{
@@ -25,12 +27,12 @@ class node_t
 		};
 		};
 
 
 		vec3_t translation_lspace;
 		vec3_t translation_lspace;
-		float  scale_lspace;
 		mat3_t rotation_lspace;
 		mat3_t rotation_lspace;
+		float  scale_lspace;
 
 
 		vec3_t translation_wspace;
 		vec3_t translation_wspace;
-		float  scale_wspace;
 		mat3_t rotation_wspace;
 		mat3_t rotation_wspace;
+		float  scale_wspace;
 
 
 		mat4_t transformation_wspace;
 		mat4_t transformation_wspace;
 
 
@@ -43,12 +45,18 @@ class node_t
 		bvolume_t* bvolume_wspace;
 		bvolume_t* bvolume_wspace;
 
 
 		bool is_group_node;
 		bool is_group_node;
+		
+		vec_t<controller_t*> controllers;
 
 
-		// funcs
-		 node_t( type_e type_ );
-		~node_t() {};
+	// funcs
+	private:
+		void CommonConstructorCode(); ///< Cause we cannot call constructor from other constructor
+		
+	public:
+		node_t( type_e type_ ): type(type_) { CommonConstructorCode(); }
+		virtual ~node_t() { /* ToDo */ };
 		virtual void Render() = 0;
 		virtual void Render() = 0;
-		virtual void Init( const char* filename ) = 0;
+		virtual void Init( const char* ) = 0; ///< Init using a script
 		virtual void Deinit() = 0;
 		virtual void Deinit() = 0;
 		virtual void UpdateWorldStuff() { UpdateWorldTransform(); } ///< This update happens only when the object gets moved. Override it if you want more
 		virtual void UpdateWorldStuff() { UpdateWorldTransform(); } ///< This update happens only when the object gets moved. Override it if you want more
 		void UpdateWorldTransform();
 		void UpdateWorldTransform();
@@ -60,6 +68,7 @@ class node_t
 		void MoveLocalZ( float distance );
 		void MoveLocalZ( float distance );
 		void AddChild( node_t* node );
 		void AddChild( node_t* node );
 		void RemoveChild( node_t* node );
 		void RemoveChild( node_t* node );
+		void SetLocalTransformation( const vec3_t& t, const mat3_t& r, float s ) { translation_lspace=t; rotation_lspace=r; scale_lspace=s; }
 };
 };
 
 
 
 

+ 17 - 25
src/scene/scene.cpp

@@ -20,15 +20,15 @@ container_skel_node_t  skel_nodes;
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// RegisterNode                                                                                                                       =
+// Static template funcs                                                                                                              =
 //=====================================================================================================================================
 //=====================================================================================================================================
-template<typename container_type_t, typename type_t> static void RegisterNode( container_type_t& container, type_t* x )
+template<typename container_type_t, typename type_t> static void PutBackNode( container_type_t& container, type_t* x )
 {
 {
 	DEBUG_ERR( std::find( container.begin(), container.end(), x ) != container.end() );
 	DEBUG_ERR( std::find( container.begin(), container.end(), x ) != container.end() );
 	container.push_back( x );
 	container.push_back( x );
 }
 }
 
 
-template<typename container_type_t, typename type_t> static void UnregisterNode( container_type_t& container, type_t* x )
+template<typename container_type_t, typename type_t> static void EraseNode( container_type_t& container, type_t* x )
 {
 {
 	typename container_type_t::iterator it = std::find( container.begin(), container.end(), x );
 	typename container_type_t::iterator it = std::find( container.begin(), container.end(), x );
 	DEBUG_ERR( it == container.end() );
 	DEBUG_ERR( it == container.end() );
@@ -37,66 +37,58 @@ template<typename container_type_t, typename type_t> static void UnregisterNode(
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// RegisterNodeAndChilds                                                                                                              =
+// RegisterNode                                                                                                                       =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void RegisterNodeAndChilds( node_t* node )
+void RegisterNode( node_t* node )
 {
 {
-	RegisterNode( nodes, node );
+	PutBackNode( nodes, node );
 	
 	
 	switch( node->type )
 	switch( node->type )
 	{
 	{
 		case node_t::NT_LIGHT:
 		case node_t::NT_LIGHT:
-			RegisterNode( lights, static_cast<light_t*>(node) );
+			PutBackNode( lights, static_cast<light_t*>(node) );
 			break;
 			break;
 		case node_t::NT_CAMERA:
 		case node_t::NT_CAMERA:
-			RegisterNode( cameras, static_cast<camera_t*>(node) );
+			PutBackNode( cameras, static_cast<camera_t*>(node) );
 			break;
 			break;
 		case node_t::NT_MESH:
 		case node_t::NT_MESH:
-			RegisterNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
+			PutBackNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
 			break;
 			break;
 		case node_t::NT_SKELETON:
 		case node_t::NT_SKELETON:
-			RegisterNode( skel_nodes, static_cast<skel_node_t*>(node) );
+			PutBackNode( skel_nodes, static_cast<skel_node_t*>(node) );
 			break;
 			break;
 		case node_t::NT_SKEL_MODEL:
 		case node_t::NT_SKEL_MODEL:
 			// ToDo
 			// ToDo
 			break;
 			break;
 	};
 	};
-	
-	// now register the childs
-	for( vec_t<node_t*>::iterator it=node->childs.begin(); it!=node->childs.end(); it++ )
-		RegisterNodeAndChilds( *it );
 }
 }
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// UnregisterNodeAndChilds                                                                                                            =
+// UnregisterNode                                                                                                                     =
 //=====================================================================================================================================
 //=====================================================================================================================================
-void UnregisterNodeAndChilds( node_t* node )
+void UnregisterNode( node_t* node )
 {
 {
-	UnregisterNode( nodes, node );
+	EraseNode( nodes, node );
 	
 	
 	switch( node->type )
 	switch( node->type )
 	{
 	{
 		case node_t::NT_LIGHT:
 		case node_t::NT_LIGHT:
-			UnregisterNode( lights, static_cast<light_t*>(node) );
+			EraseNode( lights, static_cast<light_t*>(node) );
 			break;
 			break;
 		case node_t::NT_CAMERA:
 		case node_t::NT_CAMERA:
-			UnregisterNode( cameras, static_cast<camera_t*>(node) );
+			EraseNode( cameras, static_cast<camera_t*>(node) );
 			break;
 			break;
 		case node_t::NT_MESH:
 		case node_t::NT_MESH:
-			UnregisterNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
+			EraseNode( mesh_nodes, static_cast<mesh_node_t*>(node) );
 			break;
 			break;
 		case node_t::NT_SKELETON:
 		case node_t::NT_SKELETON:
-			UnregisterNode( skel_nodes, static_cast<skel_node_t*>(node) );
+			EraseNode( skel_nodes, static_cast<skel_node_t*>(node) );
 			break;
 			break;
 		case node_t::NT_SKEL_MODEL:
 		case node_t::NT_SKEL_MODEL:
 			// ToDo
 			// ToDo
 			break;
 			break;
 	};
 	};
-	
-	// now register the childs
-	for( vec_t<node_t*>::iterator it=node->childs.begin(); it!=node->childs.end(); it++ )
-		UnregisterNodeAndChilds( *it );
 }
 }
 
 
 
 

+ 5 - 5
src/scene/scene.h

@@ -13,9 +13,9 @@ namespace scene {
 extern skybox_t skybox;
 extern skybox_t skybox;
 inline vec3_t GetAmbientColor() { return vec3_t( 0.1, 0.05, 0.05 )*1; }
 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 );
+// funcs
+extern void RegisterNode( node_t* node );
+extern void UnregisterNode( node_t* node );
 extern void UpdateAllWorldStuff();
 extern void UpdateAllWorldStuff();
 extern void UpdateAllSkeletonNodes();
 extern void UpdateAllSkeletonNodes();
 
 
@@ -28,14 +28,14 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 
 
 
 
 
-// conaiteners
+// typedefs
 typedef container_t<node_t> container_node_t;
 typedef container_t<node_t> container_node_t;
 typedef container_t<light_t> container_light_t;
 typedef container_t<light_t> container_light_t;
 typedef container_t<camera_t> container_camera_t;
 typedef container_t<camera_t> container_camera_t;
 typedef container_t<mesh_node_t> container_mesh_node_t;
 typedef container_t<mesh_node_t> container_mesh_node_t;
 typedef container_t<skel_node_t> container_skel_node_t;
 typedef container_t<skel_node_t> container_skel_node_t;
 
 
-
+// containers
 extern container_node_t       nodes;
 extern container_node_t       nodes;
 extern container_light_t      lights;
 extern container_light_t      lights;
 extern container_camera_t     cameras;
 extern container_camera_t     cameras;

+ 4 - 1
src/scene/skel_model_node.h

@@ -9,7 +9,10 @@ class mesh_node_t;
 class skel_node
 class skel_node
 
 
 
 
-/// Skeleton model scene node
+/** 
+ * Skeleton model scene node
+ * It is just a group node with a derived Init
+ */
 class skel_model_node_t: public node_t
 class skel_model_node_t: public node_t
 {
 {
 	public:
 	public:

+ 0 - 147
src/scene/skel_node.cpp

@@ -4,153 +4,6 @@
 #include "skeleton.h"
 #include "skeleton.h"
 
 
 
 
-//=====================================================================================================================================
-// Interpolate                                                                                                                        =
-//=====================================================================================================================================
-void skel_anim_controller_t::Interpolate( skel_anim_t* animation, float frame )
-{
-	DEBUG_ERR( frame >= skel_anim->frames_num );
-
-	// calculate the t (used in slerp and lerp) and
-	// calc the l_pose and r_pose witch indicate the pose ids in witch the frame lies between
-	const vec_t<uint>& keyframes = skel_anim->keyframes;
-	float t = 0.0;
-	uint l_pose = 0, r_pose = 0;
-	for( uint j=0; j<keyframes.size(); j++ )
-	{
-		if( (float)keyframes[j] == frame )
-		{
-			l_pose = r_pose = j;
-			t = 0.0;
-			break;
-		}
-		else if( (float)keyframes[j] > frame )
-		{
-			l_pose = j-1;
-			r_pose = j;
-			t = ( frame - (float)keyframes[l_pose] ) / float( keyframes[r_pose] - keyframes[l_pose] );
-			break;
-		}
-	}
-
-
-	// now for all bones update bone's poses
-	for( uint i=0; i<bone_rotations.size(); i++ )
-	{
-		const skel_anim_t::bone_anim_t& banim = skel_anim->bones[i];
-
-		mat3_t& local_rot = bone_rotations[i];
-		vec3_t& local_transl = bone_translations[i];
-
-		// if the bone has animations then slerp and lerp to find the rotation and translation
-		if( banim.keyframes.size() != 0 )
-		{
-			const skel_anim_t::bone_pose_t& l_bpose = banim.keyframes[l_pose];
-			const skel_anim_t::bone_pose_t& r_bpose = banim.keyframes[r_pose];
-
-			// rotation
-			const quat_t& q0 = l_bpose.rotation;
-			const quat_t& q1 = r_bpose.rotation;
-			local_rot = mat3_t( q0.Slerp(q1, t) );
-
-			// translation
-			const vec3_t& v0 = l_bpose.translation;
-			const vec3_t& v1 = r_bpose.translation;
-			local_transl = v0.Lerp( v1, t );
-		}
-		// else put the idents
-		else
-		{
-			local_rot = mat3_t::GetIdentity();
-			local_transl = vec3_t( 0.0, 0.0, 0.0 );
-		}
-	}
-}
-
-
-//=====================================================================================================================================
-// UpdateBoneTransforms                                                                                                               =
-//=====================================================================================================================================
-void skel_anim_controller_t::UpdateBoneTransforms()
-{
-	uint queue[ 128 ];
-	uint head = 0, tail = 0;
-
-	// put the roots
-	for( uint i=0; i<skel_node->skeleton->bones.size(); i++ )
-		if( skel_node->skeleton->bones[i].parent == NULL )
-			queue[tail++] = i; // queue push
-
-	// loop
-	while( head != tail ) // while queue not empty
-	{
-		uint bone_id = queue[head++]; // queue pop
-		const skeleton_t::bone_t& boned = skel_node->skeleton->bones[bone_id];
-
-		// bone.final_transform = MA * ANIM * MAi
-		// where MA is bone matrix at armature space and ANIM the interpolated transformation.
-		CombineTransformations( bone_translations[bone_id], bone_rotations[bone_id],
-		                        boned.tsl_skel_space_inv, boned.rot_skel_space_inv,
-		                        bone_translations[bone_id], bone_rotations[bone_id] );
-
-		CombineTransformations( boned.tsl_skel_space, boned.rot_skel_space,
-		                        bone_translations[bone_id], bone_rotations[bone_id],
-		                        bone_translations[bone_id], bone_rotations[bone_id] );
-
-		// and finaly add the parent's transform
-		if( boned.parent )
-		{
-			// bone.final_final_transform = parent.transf * bone.final_transform
-			CombineTransformations( bone_translations[boned.parent->id], bone_rotations[boned.parent->id],
-		                          bone_translations[bone_id], bone_rotations[bone_id],
-		                          bone_translations[bone_id], bone_rotations[bone_id] );
-		}
-
-		// now add the bone's childes
-		for( uint i=0; i<boned.childs_num; i++ )
-			queue[tail++] = boned.childs[i]->id;
-	}
-}
-
-
-//=====================================================================================================================================
-// Deform                                                                                                                             =
-//=====================================================================================================================================
-void skel_anim_controller_t::Deform()
-{
-	skeleton_t* skeleton = skel_node->skeleton;
-
-	for( uint i=0; i<skeleton->bones.size(); i++ )
-	{
-		const mat3_t& rot = bone_rotations[ i ];
-		const vec3_t& transl = bone_translations[ i ];
-
-		heads[i] = skeleton->bones[i].head.GetTransformed( transl, rot );
-		tails[i] = skeleton->bones[i].tail.GetTransformed( transl, rot );
-	}
-}
-
-
-//=====================================================================================================================================
-// Update                                                                                                                             =
-//=====================================================================================================================================
-void skel_anim_controller_t::Update()
-{
-	frame += step;
-	if( frame > skel_anim->frames_num ) // if the crnt is finished then play the next or loop the crnt
-	{
-		frame = 0.0;
-	}
-
-	Interpolate( skel_anim, frame );
-	UpdateBoneTransforms();
-	if( r::dbg::show_skeletons )
-	{
-		Deform();
-	}
-}
-
-
 //=====================================================================================================================================
 //=====================================================================================================================================
 // Init                                                                                                                               =
 // Init                                                                                                                               =
 //=====================================================================================================================================
 //=====================================================================================================================================

+ 0 - 28
src/scene/skel_node.h

@@ -7,34 +7,6 @@
 #include "gmath.h"
 #include "gmath.h"
 
 
 
 
-class skeleton_t;
-class skel_anim_t;
-class skel_node_t;
-
-
-/// Skeleton animation controller
-class skel_anim_controller_t: public controller_t<skel_node_t>
-{
-	private:
-		void Interpolate( skel_anim_t* animation, float frame );
-		void UpdateBoneTransforms();
-		void Deform();
-
-	public:
-		skel_anim_t*  skel_anim; ///< Skeleton animation resource
-		skel_node_t*  skel_node;
-		vec_t<vec3_t> heads;
-		vec_t<vec3_t> tails;
-		vec_t<mat3_t> bone_rotations;
-		vec_t<vec3_t> bone_translations;
-		float step;
-		float frame;
-
-		skel_anim_controller_t( skel_node_t* skel_node_ ): skel_node( skel_node_ ) {}
-		void Update();
-};
-
-
 /// Skeleton node
 /// Skeleton node
 class skel_node_t: public node_t
 class skel_node_t: public node_t
 {
 {

+ 7 - 27
src/tokenizer/scanner.cpp

@@ -158,7 +158,6 @@ void scanner_t::GetLine()
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
 // GetNextChar                                                                                                                        =
 // GetNextChar                                                                                                                        =
-// get the next char from the line_txt. If line_txt empty then get new line. It returns '\0' if we are in the end of the line         =
 //=====================================================================================================================================
 //=====================================================================================================================================
 char scanner_t::GetNextChar()
 char scanner_t::GetNextChar()
 {
 {
@@ -253,51 +252,32 @@ void scanner_t::GetAllPrintAll()
 //=====================================================================================================================================
 //=====================================================================================================================================
 bool scanner_t::LoadFile( const char* filename_ )
 bool scanner_t::LoadFile( const char* filename_ )
 {
 {
-	DEBUG_ERR( strlen(filename_) > sizeof(script_name)/sizeof(char) - 1 ); // Too big name
-	
-	if( in_stream != NULL )
-	{
-		ERROR( "Tokenizer already initialized" );
-		return false;
-	}
-
-	in_stream = &in_fstream;
-
 	in_fstream.open( filename_, ios::in );
 	in_fstream.open( filename_, ios::in );
-
 	if( !in_fstream.good() )
 	if( !in_fstream.good() )
 	{
 	{
 		ERROR( "Cannot open file \"" << filename_ << '\"' );
 		ERROR( "Cannot open file \"" << filename_ << '\"' );
 		return false;
 		return false;
 	}
 	}
-
-	// init globals
-	crnt_token.code = TC_ERROR;
-	line_nmbr = 0;
-	strcpy( script_name, filename_ );
-
-	GetLine();
-	return true;
+	
+	return LoadIoStream( &in_fstream, filename_ );
 }
 }
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// LoadString                                                                                                                         =
+// LoadIoStream                                                                                                                       =
 //=====================================================================================================================================
 //=====================================================================================================================================
-bool scanner_t::LoadString( const string& str, const char* script_name_ )
+bool scanner_t::LoadIoStream( iostream* iostream_, const char* script_name_ )
 {
 {
-	DEBUG_ERR( strlen(script_name_) > sizeof(script_name)/sizeof(char) - 1 ) // Too big name
-	
 	if( in_stream != NULL )
 	if( in_stream != NULL )
 	{
 	{
 		ERROR( "Tokenizer already initialized" );
 		ERROR( "Tokenizer already initialized" );
 		return false;
 		return false;
 	}
 	}
 
 
-	in_sstream.str( str );
-	in_stream = &in_sstream;
+	in_stream = iostream_;
 
 
 	// init globals
 	// init globals
+	DEBUG_ERR( strlen(script_name_) > sizeof(script_name)/sizeof(char) - 1 ) // Too big name
 	crnt_token.code = TC_ERROR;
 	crnt_token.code = TC_ERROR;
 	line_nmbr = 0;
 	line_nmbr = 0;
 	strcpy( script_name, script_name_ );
 	strcpy( script_name, script_name_ );
@@ -318,7 +298,7 @@ void scanner_t::Unload()
 
 
 
 
 //=====================================================================================================================================
 //=====================================================================================================================================
-// GetNextToken                                                                                                                          =
+// GetNextToken                                                                                                                       =
 //=====================================================================================================================================
 //=====================================================================================================================================
 const scanner_t::token_t& scanner_t::GetNextToken()
 const scanner_t::token_t& scanner_t::GetNextToken()
 {
 {

+ 4 - 5
src/tokenizer/scanner.h

@@ -30,7 +30,7 @@ class scanner_t
 		bool CheckSpecial();
 		bool CheckSpecial();
 
 
 		void GetLine(); ///< Reads a line from the script file
 		void GetLine(); ///< Reads a line from the script file
-		char GetNextChar(); ///< Gets a char from the current script line
+		char GetNextChar(); ///< Get the next char from the line_txt. If line_txt empty then get new line. It returns '\0' if we are in the end of the line
 		char PutBackChar(); ///< Put the char that scanner_t::GetNextChar got back to the current line
 		char PutBackChar(); ///< Put the char that scanner_t::GetNextChar got back to the current line
 
 
 	//===================================================================================================================================
 	//===================================================================================================================================
@@ -141,7 +141,7 @@ class scanner_t
 		char    line_txt [MAX_SCRIPT_LINE_LEN]; ///< In contains the current line's text
 		char    line_txt [MAX_SCRIPT_LINE_LEN]; ///< In contains the current line's text
 		char*   pchar; ///< Points to line_txt
 		char*   pchar; ///< Points to line_txt
 		int     line_nmbr; ///< The number of the current line
 		int     line_nmbr; ///< The number of the current line
-		bool    newlines_as_whitespace; ///< Treat newlines as whitespace
+		bool    newlines_as_whitespace; ///< Treat newlines as whitespace. This means that we extract new token for every line
 		/*
 		/*
 		 * Used to keep track of the newlines in multiline comments so we can return the correct number of newlines in case of 
 		 * Used to keep track of the newlines in multiline comments so we can return the correct number of newlines in case of 
 		 * newlines_as_whitespace is false
 		 * newlines_as_whitespace is false
@@ -149,9 +149,8 @@ class scanner_t
 		int     commented_lines;  
 		int     commented_lines;  
 
 
 		// input
 		// input
-		stringstream in_sstream;
 		fstream      in_fstream;
 		fstream      in_fstream;
-		iostream*    in_stream; ///< points to either in_fstream or in_sstream
+		iostream*    in_stream; ///< Points to either in_fstream or an external std::iostream
 		char         script_name[64]; ///< The name of the input stream. Mostly used for error handling
 		char         script_name[64]; ///< The name of the input stream. Mostly used for error handling
 
 
 	//===================================================================================================================================
 	//===================================================================================================================================
@@ -162,7 +161,7 @@ class scanner_t
 		~scanner_t() { /* The destructor does NOTHING. The class does not make any mem allocations */ }
 		~scanner_t() { /* The destructor does NOTHING. The class does not make any mem allocations */ }
 
 
 		bool LoadFile( const char* filename ); ///< Load a file to extract tokens
 		bool LoadFile( const char* filename ); ///< Load a file to extract tokens
-		bool LoadString( const string& str, const char* script_name_ = "*string*" );
+		bool LoadIoStream( iostream* iostream_, const char* script_name_ = "unamed-iostream" ); ///< Load a STL iostream to extract tokens
 		void Unload();
 		void Unload();
 
 
 		static void   PrintTokenInfo( const token_t& token ); ///< Print info of the given token
 		static void   PrintTokenInfo( const token_t& token ); ///< Print info of the given token