Browse Source

- Physics and Scene
- Shader prog loading

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
2f93f1a8fc

+ 11 - 11
shaders/ms_mp_generic.glsl → shaders/MsMpGeneric.glsl

@@ -5,14 +5,14 @@
  * in all the buffers
  */
  
-#if defined( _DIFFUSE_MAPPING_ ) || defined( _NORMAL_MAPPING_ ) || defined( _SPECULAR_MAPPING_ )
+#if defined( DIFFUSE_MAPPING ) || defined( NORMAL_MAPPING ) || defined( SPECULAR_MAPPING )
 	#define NEEDS_TEX_MAPPING 1
 #else
 	#define NEEDS_TEX_MAPPING 0
 #endif
 
 
-#if defined( _NORMAL_MAPPING_ ) || defined( _PARALLAX_MAPPING_ )
+#if defined( NORMAL_MAPPING ) || defined( PARALLAX_MAPPING )
 	#define NEEDS_TANGENT 1
 #else
 	#define NEEDS_TANGENT 0
@@ -54,7 +54,7 @@ void main()
 	// calculate the vert pos, normal and tangent
 
 	// if we have hardware skinning then:
-	#if defined( _HARDWARE_SKINNING_ )
+	#if defined( HARDWARE_SKINNING )
 		mat3 _rot;
 		vec3 _tsl;
 
@@ -93,7 +93,7 @@ void main()
 	#endif
 
 
-	#if defined( _ENVIRONMENT_MAPPING_ ) || defined( _PARALLAX_MAPPING_ )
+	#if defined( ENVIRONMENT_MAPPING ) || defined( PARALLAX_MAPPING )
 		vertPosEyeSpace_v2f = vec3( modelViewMat * vec4(position, 1.0) );
 	#endif
 }
@@ -141,7 +141,7 @@ void main()
 	// Paralax Mapping Calculations                                                                                      =
 	// The code below reads the height map, makes some calculations and returns a new texCoords                          =
 	//====================================================================================================================
-	#if defined( _PARALLAX_MAPPING_ )
+	#if defined( PARALLAX_MAPPING )
 		/*const float _scale = 0.04;
 		const float _bias = scale * 0.4;
 
@@ -183,9 +183,9 @@ void main()
 	// Get the color from the diffuse map and discard if grass                                                           =
 	//====================================================================================================================
 	vec3 _diff_color;
-	#if defined( _DIFFUSE_MAPPING_ )
+	#if defined( DIFFUSE_MAPPING )
 
-		#if defined( _GRASS_LIKE_ )
+		#if defined( ALPHA_TESTING )
 			vec4 _diff_color4 = texture2D( diffuseMap, superTexCoords );
 			if( _diff_color4.a == 0.0 ) discard;
 			_diff_color = _diff_color4.rgb;
@@ -203,7 +203,7 @@ void main()
 	// Normal Calculations                                                                                               =
 	// Either use a normap map and make some calculations or use the vertex normal                                       =
 	//====================================================================================================================
-	#if defined( _NORMAL_MAPPING_ )
+	#if defined( NORMAL_MAPPING )
 		vec3 _n = normalize( normal_v2f );
 		vec3 _t = normalize( tangent_v2f );
 		vec3 _b = cross(_n, _t) * w_v2f;
@@ -224,7 +224,7 @@ void main()
 	//====================================================================================================================
 
 	// if SEM enabled make some aditional calculations using the vertPosEyeSpace_v2f, environmentMap and the newNormal
-	#if defined( _ENVIRONMENT_MAPPING_ )
+	#if defined( ENVIRONMENT_MAPPING )
 		vec3 _u = normalize( vertPosEyeSpace_v2f );
 		
 		/**
@@ -247,7 +247,7 @@ void main()
 	//====================================================================================================================
 
 	// has specular map
-	#if defined( _SPECULAR_MAPPING_ )
+	#if defined( SPECULAR_MAPPING )
 		vec4 _specular = vec4(texture2D( specularMap, superTexCoords ).rgb * specularCol, shininess);
 	// no specular map
 	#else
@@ -262,7 +262,7 @@ void main()
 	gl_FragData[1].rgb = _diff_color;
 	gl_FragData[2] = _specular;
 
-	/*#if defined( _HARDWARE_SKINNING_ )
+	/*#if defined( HARDWARE_SKINNING )
 		gl_FragData[1] = gl_Color;
 	#endif*/
 }

+ 0 - 2
shaders/ms_mp.glsl

@@ -1,2 +0,0 @@
-
-#pragma anki include "shaders/ms_mp_generic.glsl"

+ 0 - 7
shaders/ms_mp_d.glsl

@@ -1,7 +0,0 @@
-#define _DIFFUSE_MAPPING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"
-
-
-
-

+ 0 - 8
shaders/ms_mp_dn.glsl

@@ -1,8 +0,0 @@
-#define _DIFFUSE_MAPPING_
-#define _NORMAL_MAPPING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"
-
-
-
-

+ 0 - 5
shaders/ms_mp_dne.glsl

@@ -1,5 +0,0 @@
-#define _DIFFUSE_MAPPING_
-#define _NORMAL_MAPPING_
-#define _ENVIRONMENT_MAPPING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"

+ 0 - 5
shaders/ms_mp_dnp.glsl

@@ -1,5 +0,0 @@
-#define _DIFFUSE_MAPPING_
-#define _NORMAL_MAPPING_
-#define _PARALLAX_MAPPING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"

+ 0 - 6
shaders/ms_mp_dnsk.glsl

@@ -1,6 +0,0 @@
-#define _DIFFUSE_MAPPING_
-#define _NORMAL_MAPPING_
-#define _SPECULAR_MAPPING_
-#define _HARDWARE_SKINNING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"

+ 0 - 7
shaders/ms_mp_dnske.glsl

@@ -1,7 +0,0 @@
-#define _DIFFUSE_MAPPING_
-#define _NORMAL_MAPPING_
-#define _SPECULAR_MAPPING_
-#define _HARDWARE_SKINNING_
-#define _ENVIRONMENT_MAPPING_
-
-#pragma anki include "shaders/ms_mp_generic.glsl"

+ 4 - 0
src/Main.cpp

@@ -424,6 +424,10 @@ int main(int argc, char* argv[])
 {
 	new App(argc, argv);
 
+	RsrcPtr<Material> mtl;
+	mtl.loadRsrc("/users/panoscc/Desktop/temp.txt");
+	return 0;
+
 	init();
 
 	mainLoop();

+ 4 - 4
src/Renderer/Dbg.cpp

@@ -258,14 +258,14 @@ void Renderer::Dbg::run()
 		SceneNode* node = app->getScene()->nodes[i];
 		if
 		(
-			(node->type == SceneNode::NT_LIGHT && showLightsEnabled) ||
-			(node->type == SceneNode::NT_CAMERA && showCamerasEnabled) ||
-			node->type == SceneNode::NT_PARTICLE_EMITTER
+			(node->type == SceneNode::SNT_LIGHT && showLightsEnabled) ||
+			(node->type == SceneNode::SNT_CAMERA && showCamerasEnabled) ||
+			node->type == SceneNode::SNT_PARTICLE_EMITTER
 		)
 		{
 			node->render();
 		}
-		else if(app->getScene()->nodes[i]->type == SceneNode::NT_SKELETON && showSkeletonsEnabled)
+		else if(app->getScene()->nodes[i]->type == SceneNode::SNT_SKELETON && showSkeletonsEnabled)
 		{
 			SkelNode* skelNode = static_cast<SkelNode*>(node);
 			glDisable(GL_DEPTH_TEST);

+ 2 - 2
src/Resources/Core/RsrcContainer.h

@@ -1,5 +1,5 @@
-#ifndef RESOURCECONTAINER_H
-#define RESOURCECONTAINER_H
+#ifndef RSRC_CONTAINER_H
+#define RSRC_CONTAINER_H
 
 #include "Common.h"
 #include "Vec.h"

+ 101 - 5
src/Resources/Material.cpp

@@ -50,9 +50,36 @@ Material::StdVarInfo Material::stdUniVarInfos[SUV_NUM] =
 };
 
 
+//======================================================================================================================
+// Stuff for custom material stage shader prgs                                                                         =
+//======================================================================================================================
+
+struct MsSwitch
+{
+	const char* switchName;
+	const char prefix;
+};
+
+/**
+ * See the docs for info about the switches
+ */
+static MsSwitch msSwitches [] =
+{
+	{"DIFFUSE_MAPPING", 'd'},
+	{"NORMAL_MAPPING", 'n'},
+	{"SPECULAR_MAPPING", 's'},
+	{"PARALLAX_MAPPING", 'p'},
+	{"ENVIRONMENT_MAPPING", 'e'},
+	{"ALPHA_TESTING", 'a'},
+	{"HARDWARE_SKINNING", 'h'},
+	{NULL, NULL}
+};
+
+
 //======================================================================================================================
 // Blending stuff                                                                                                      =
 //======================================================================================================================
+
 struct BlendParam
 {
 	int glEnum;
@@ -100,7 +127,7 @@ bool Material::load(const char* filename)
 
 	const Scanner::Token* token;
 
-	do
+	while(true)
 	{
 		token = &scanner.getNextToken();
 
@@ -108,15 +135,84 @@ bool Material::load(const char* filename)
 		if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "SHADER_PROG"))
 		{
 			if(shaderProg.get())
+			{
 				ERROR("Shader program already loaded");
+				return false;
+			}
 
 			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_STRING)
+			string shaderFilename;
+			if(token->getCode() == Scanner::TC_STRING)
 			{
-				PARSE_ERR_EXPECTED("string");
+				shaderFilename = token->getValue().getString();
+			}
+			// build custom shader
+			else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getString(), "buildMsSProg"))
+			{
+				// paren
+				token = &scanner.getNextToken();
+				if(token->getCode() != Scanner::TC_LPAREN)
+				{
+					PARSE_ERR_EXPECTED("(");
+					return false;
+				}
+
+				// shader prog
+				token = &scanner.getNextToken();
+				if(token->getCode() != Scanner::TC_STRING)
+				{
+					PARSE_ERR_EXPECTED("string");
+					return false;
+				}
+				string sProgFilename = token->getValue().getString();
+
+				// get the switches
+				string source;
+				string prefix;
+				while(true)
+				{
+					token = &scanner.getNextToken();
+
+					if(token->getCode() == Scanner::TC_RPAREN)
+						break;
+
+					if(token->getCode() != Scanner::TC_IDENTIFIER)
+					{
+						PARSE_ERR_EXPECTED("identifier");
+						return false;
+					}
+
+					// check if acceptable value
+					MsSwitch* mss = msSwitches;
+					while(mss->prefix != NULL)
+					{
+						if(!strcmp(mss->switchName, token->getString()))
+							break;
+
+						++mss;
+					}
+
+					if(mss->prefix == NULL)
+					{
+						PARSE_ERR("Incorrect switch " << token->getString());
+						return false;
+					}
+
+					source += string("#define ") + token->getString() + "\n";
+					prefix.push_back(mss->prefix);
+				} // end get the switches
+
+				std::sort(prefix.begin(), prefix.end());
+
+				shaderFilename = ShaderProg::createSrcCodeToCache(sProgFilename.c_str(), source.c_str(), prefix.c_str());
+			}
+			else
+			{
+				PARSE_ERR_EXPECTED("string or buildMsSProg");
 				return false;
 			}
-			shaderProg.loadRsrc(token->getValue().getString());
+
+			shaderProg.loadRsrc(shaderFilename.c_str());
 		}
 		//** DEPTH_MATERIAL **
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DEPTH_PASS_MATERIAL"))
@@ -318,7 +414,7 @@ bool Material::load(const char* filename)
 			return false;
 		}
 
-	}while(true);
+	}
 
 	return initStdShaderVars();
 }

+ 1 - 1
src/Resources/Material.h

@@ -23,7 +23,7 @@
  */
 class Material: public Resource
 {
-	friend class Renderer;
+	friend class Renderer; ///< For the setupMaterial
 	friend class MeshNode;
 
 	private:

+ 10 - 8
src/Resources/ShaderProg.cpp

@@ -271,13 +271,15 @@ bool ShaderProg::load(const char* filename)
 
 	// 1) create and compile the shaders
 	string preprocSource = stdSourceCode;
-	uint vertGlId = createAndCompileShader(pars.getOutput().getVertShaderSource().c_str(), preprocSource.c_str(),
-	                                       GL_VERTEX_SHADER);
-	if(vertGlId == 0) return false;
+	vertShaderGlId = createAndCompileShader(pars.getOutput().getVertShaderSource().c_str(), preprocSource.c_str(),
+	                                        GL_VERTEX_SHADER);
+	if(vertShaderGlId == 0)
+		return false;
 
-	uint fragGlId = createAndCompileShader(pars.getOutput().getFragShaderSource().c_str(), preprocSource.c_str(),
-	                                       GL_FRAGMENT_SHADER);
-	if(fragGlId == 0) return false;
+	fragShaderGlId = createAndCompileShader(pars.getOutput().getFragShaderSource().c_str(), preprocSource.c_str(),
+	                                        GL_FRAGMENT_SHADER);
+	if(fragShaderGlId == 0)
+		return false;
 
 	// 2) create program and attach shaders
 	glId = glCreateProgram();
@@ -286,8 +288,8 @@ bool ShaderProg::load(const char* filename)
 		ERROR("glCreateProgram failed");
 		return false;
 	}
-	glAttachShader(glId, vertGlId);
-	glAttachShader(glId, fragGlId);
+	glAttachShader(glId, vertShaderGlId);
+	glAttachShader(glId, fragShaderGlId);
 
 	// 3) bind the custom attrib locs
 	if(!bindCustomAttribLocs(pars)) return false;

+ 1 - 1
src/Resources/ShaderProg.h

@@ -138,7 +138,7 @@ class ShaderProg: public Resource
 		bool attribVarExists(const char* varName) const;
 
 		/**
-		 * @todo
+		 * Used by @ref Material and @ref Renderer to create custom shaders in the cache
 		 * @param sProgFPathName The file pathname of the shader prog
 		 * @param preAppendedSrcCode The source code we want to write on top of the shader prog
 		 * @param newFNamePrefix The prefix of the new shader prog

+ 2 - 3
src/Scene/Camera.cpp

@@ -205,11 +205,10 @@ void Camera::updateViewMatrix()
 
 
 //======================================================================================================================
-// updateWorldStuff                                                                                                    =
+// updateTrf                                                                                                           =
 //======================================================================================================================
-void Camera::updateWorldStuff()
+void Camera::updateTrf()
 {
-	updateWorldTransform();
 	updateViewMatrix();
 	updateWSpaceFrustumPlanes();
 }

+ 23 - 12
src/Scene/Camera.h

@@ -54,17 +54,14 @@ class Camera: public SceneNode
 
 	public:
 		// constructors and destuctors
-		Camera(float fovx_, float fovy_, float znear_, float zfar_): SceneNode(NT_CAMERA), fovX(fovx_), fovY(fovy_), zNear(znear_), zFar(zfar_)
-		{
-			calcLSpaceFrustumPlanes();
-			updateWSpaceFrustumPlanes();
-			calcProjectionMatrix();
-		}
-		Camera(const Camera& c): SceneNode(NT_CAMERA) { memcpy(this, &c, sizeof(Camera)); }
-		Camera(): SceneNode(NT_CAMERA) {}
+		Camera(float fovx_, float fovy_, float znear_, float zfar_);
+		Camera(): SceneNode(SNT_CAMERA) {}
 		~Camera() {}
 
-		// Sets & Gets
+		/**
+		 * @name Accessors
+		 */
+		/**@{*/
 		void setFovX (float fovx_)  { fovX=fovx_; calcProjectionMatrix(); calcLSpaceFrustumPlanes(); }
 		void setFovY (float fovy_)  { fovY=fovy_; calcProjectionMatrix(); calcLSpaceFrustumPlanes(); }
 		void setZNear(float znear_) { zNear=znear_; calcProjectionMatrix(); calcLSpaceFrustumPlanes(); }
@@ -77,18 +74,19 @@ class Camera: public SceneNode
 		const Mat4& getProjectionMatrix() const { return projectionMat; }
 		const Mat4& getViewMatrix() const { return viewMat; }
 		const Mat4& getInvProjectionMatrix() const { return invProjectionMat; } ///< See the declaration of invProjectionMat for info
+		/**@}*/
 
 		// misc
 		void lookAtPoint(const Vec3& point);
-		void updateWorldStuff();
+		void updateTrf();
 		void render();
 		void init(const char*) {}
-		void deinit() {}
 
 		// frustum stuff
 
 		/**
-		 * Check if the given camera is inside the frustum clipping planes. This is used mainly to test if the projected lights are visible
+		 * Check if the given camera is inside the frustum clipping planes. This is used mainly to test if the projected
+		 * lights are visible
 		 */
 		bool insideFrustum(const bvolume_t& vol) const;
 
@@ -99,4 +97,17 @@ class Camera: public SceneNode
 };
 
 
+inline Camera::Camera(float fovx_, float fovy_, float znear_, float zfar_):
+	SceneNode(SNT_CAMERA),
+	fovX(fovx_),
+	fovY(fovy_),
+	zNear(znear_),
+	zFar(zfar_)
+{
+	calcLSpaceFrustumPlanes();
+	updateWSpaceFrustumPlanes();
+	calcProjectionMatrix();
+}
+
+
 #endif

+ 1 - 2
src/Scene/GhostNode.h

@@ -10,10 +10,9 @@
 class GhostNode: public SceneNode
 {
 	public:
-		GhostNode(): SceneNode(NT_GHOST) { }
+		GhostNode(): SceneNode(SNT_GHOST) { }
 		void init(const char*) {}
 		void render() {}
-		void deinit() {}
 };
 
 

+ 1 - 9
src/Scene/Light.cpp

@@ -23,6 +23,7 @@ void SpotLight::init(const char* filename)
 	lightProps.loadRsrc(filename);
 	camera.setAll(lightProps->getFovX(), lightProps->getFovY(), 0.2, lightProps->getDistance());
 	castsShadow = lightProps->castsShadow();
+
 	if(lightProps->getTexture() == NULL)
 	{
 		ERROR("Light properties \"" << lightProps->getRsrcName() << "\" do not have a texture");
@@ -31,15 +32,6 @@ void SpotLight::init(const char* filename)
 }
 
 
-//======================================================================================================================
-// deinit                                                                                                              =
-//======================================================================================================================
-void Light::deinit()
-{
-	//RsrcMngr::lightProps.unload(lightProps);
-}
-
-
 //======================================================================================================================
 // render                                                                                                              =
 //======================================================================================================================

+ 1 - 2
src/Scene/Light.h

@@ -39,7 +39,6 @@ class Light: public SceneNode
 		RsrcPtr<LightProps> lightProps; ///< Later we will add a controller
 	
 		Light(Type type_);
-		void deinit();
 		void render();
 };
 
@@ -74,7 +73,7 @@ class SpotLight: public Light
 //======================================================================================================================
 
 inline Light::Light(Type type_):
-	SceneNode(NT_LIGHT),
+	SceneNode(SNT_LIGHT),
 	type(type_)
 {}
 

+ 0 - 10
src/Scene/MeshNode.cpp

@@ -28,16 +28,6 @@ void MeshNode::init(const char* filename)
 }
 
 
-//======================================================================================================================
-// deinit                                                                                                              =
-//======================================================================================================================
-void MeshNode::deinit()
-{
-	//RsrcMngr::meshes.unload(mesh);
-	//RsrcMngr::materials.unload(material);
-}
-
-
 //======================================================================================================================
 // render                                                                                                              =
 //======================================================================================================================

+ 1 - 2
src/Scene/MeshNode.h

@@ -27,12 +27,11 @@ class MeshNode: public SceneNode
 		virtual void render() { render(material.get()); }
 		virtual void renderDepth() { render(material->dpMtl.get()); }
 		void init(const char* filename);
-		void deinit();
 };
 
 
 inline MeshNode::MeshNode():
-	SceneNode(NT_MESH),
+	SceneNode(SNT_MESH),
 	meshSkelCtrl(NULL)
 {}
 

+ 0 - 10
src/Scene/ParticleEmitter.cpp

@@ -57,16 +57,6 @@ void ParticleEmitter::init(const char* filename)
 }
 
 
-//======================================================================================================================
-// updateWorldStuff                                                                                                    =
-//======================================================================================================================
-void ParticleEmitter::updateWorldStuff()
-{
-	updateWorldTransform();
-	update();
-}
-
-
 //======================================================================================================================
 // update                                                                                                              =
 //======================================================================================================================

+ 1 - 3
src/Scene/ParticleEmitter.h

@@ -33,8 +33,6 @@ class ParticleEmitter: public SceneNode, public ParticleEmitterPropsStruct
 		ParticleEmitter();
 		void render();
 		void init(const char* filename);
-		void deinit() {}
-		void updateWorldStuff();
 
 	private:
 		auto_ptr<btCollisionShape> collShape;
@@ -53,7 +51,7 @@ inline ParticleEmitter::Particle::Particle():
 
 
 inline ParticleEmitter::ParticleEmitter():
-	SceneNode(NT_PARTICLE_EMITTER)
+	SceneNode(SNT_PARTICLE_EMITTER)
 {}
 
 

+ 14 - 13
src/Scene/Scene.cpp

@@ -30,22 +30,22 @@ void Scene::registerNode(SceneNode* node)
 	
 	switch(node->type)
 	{
-		case SceneNode::NT_LIGHT:
+		case SceneNode::SNT_LIGHT:
 			putBackNode(lights, static_cast<Light*>(node));
 			break;
-		case SceneNode::NT_CAMERA:
+		case SceneNode::SNT_CAMERA:
 			putBackNode(cameras, static_cast<Camera*>(node));
 			break;
-		case SceneNode::NT_MESH:
+		case SceneNode::SNT_MESH:
 			putBackNode(meshNodes, static_cast<MeshNode*>(node));
 			break;
-		case SceneNode::NT_SKELETON:
+		case SceneNode::SNT_SKELETON:
 			putBackNode(skelNodes, static_cast<SkelNode*>(node));
 			break;
-		case SceneNode::NT_SKEL_MODEL:
+		case SceneNode::SNT_SKEL_MODEL:
 			// ToDo
 			break;
-		case SceneNode::NT_PARTICLE_EMITTER:
+		case SceneNode::SNT_PARTICLE_EMITTER:
 			putBackNode(particleEmitters, static_cast<ParticleEmitter*>(node));
 			break;
 	};
@@ -61,22 +61,22 @@ void Scene::unregisterNode(SceneNode* node)
 	
 	switch(node->type)
 	{
-		case SceneNode::NT_LIGHT:
+		case SceneNode::SNT_LIGHT:
 			eraseNode(lights, static_cast<Light*>(node));
 			break;
-		case SceneNode::NT_CAMERA:
+		case SceneNode::SNT_CAMERA:
 			eraseNode(cameras, static_cast<Camera*>(node));
 			break;
-		case SceneNode::NT_MESH:
+		case SceneNode::SNT_MESH:
 			eraseNode(meshNodes, static_cast<MeshNode*>(node));
 			break;
-		case SceneNode::NT_SKELETON:
+		case SceneNode::SNT_SKELETON:
 			eraseNode(skelNodes, static_cast<SkelNode*>(node));
 			break;
-		case SceneNode::NT_SKEL_MODEL:
+		case SceneNode::SNT_SKEL_MODEL:
 			// ToDo
 			break;
-		case SceneNode::NT_PARTICLE_EMITTER:
+		case SceneNode::SNT_PARTICLE_EMITTER:
 			eraseNode(particleEmitters, static_cast<ParticleEmitter*>(node));
 			break;
 	};
@@ -121,7 +121,8 @@ void Scene::updateAllWorldStuff()
 	{
 		SceneNode* obj = queue[head++]; // queue pop
 
-		obj->updateWorldStuff();
+		obj->updateWorldTransform();
+		obj->update();
 		++num;
 
 		for(uint i=0; i<obj->childs.size(); i++)

+ 23 - 13
src/Scene/Scene.h

@@ -55,23 +55,33 @@ class Scene
 
 	private:
 		/**
-		 * @brief Adds a node in a container
+		 * Adds a node in a container
 		 */
-		template<typename ContainerType, typename Type> void putBackNode(ContainerType& container, Type* x)
-		{
-			DEBUG_ERR(std::find(container.begin(), container.end(), x) != container.end());
-			container.push_back(x);
-		}
+		template<typename ContainerType, typename Type>
+		void putBackNode(ContainerType& container, Type* x);
 
 		/**
-		 * @brief Removes a node from a container
+		 * Removes a node from a container
 		 */
-		template<typename ContainerType, typename Type> void eraseNode(ContainerType& container, Type* x)
-		{
-			typename ContainerType::iterator it = std::find(container.begin(), container.end(), x);
-			DEBUG_ERR(it == container.end());
-			container.erase(it);
-		}
+		template<typename ContainerType, typename Type>
+		void eraseNode(ContainerType& container, Type* x);
 };
 
+
+template<typename ContainerType, typename Type>
+inline void Scene::putBackNode(ContainerType& container, Type* x)
+{
+	DEBUG_ERR(std::find(container.begin(), container.end(), x) != container.end());
+	container.push_back(x);
+}
+
+
+template<typename ContainerType, typename Type>
+inline void Scene::eraseNode(ContainerType& container, Type* x)
+{
+	typename ContainerType::iterator it = std::find(container.begin(), container.end(), x);
+	DEBUG_ERR(it == container.end());
+	container.erase(it);
+}
+
 #endif

+ 27 - 17
src/Scene/SceneNode.h

@@ -17,16 +17,18 @@ class Controller;
  */
 class SceneNode
 {
+	friend class Scene;
+
 	public:
-		enum Type
+		enum SceneNodeType
 		{
-			NT_GHOST,
-			NT_LIGHT,
-			NT_CAMERA,
-			NT_MESH,
-			NT_SKELETON,
-			NT_SKEL_MODEL,
-			NT_PARTICLE_EMITTER
+			SNT_GHOST,
+			SNT_LIGHT,
+			SNT_CAMERA,
+			SNT_MESH,
+			SNT_SKELETON,
+			SNT_SKEL_MODEL,
+			SNT_PARTICLE_EMITTER
 		};
 
 	PROPERTY_RW(Transform, localTransform, setLocalTransform, getLocalTransform); ///< The transformation in local space
@@ -35,22 +37,29 @@ class SceneNode
 	public:
 		SceneNode* parent;
 		Vec<SceneNode*> childs;
-		Type type;
+		SceneNodeType type;
 		bvolume_t* bvolumeLspace;
 		bvolume_t* bvolumeWspace;
 		bool isCompound;
 		
-		SceneNode(Type type_);
-		SceneNode(Type type_, SceneNode* parent);
+		SceneNode(SceneNodeType type_);
+		SceneNode(SceneNodeType type_, SceneNode* parent);
 		virtual ~SceneNode();
 		virtual void render() = 0;
 		virtual void init(const char*) = 0; ///< init using a script
-		virtual void deinit() = 0;
-		virtual void updateWorldStuff() { updateWorldTransform(); } ///< This update happens only when the object gets moved. Override it if you want more
-		void updateWorldTransform();
 
 		/**
-		 * @name Local transform
+		 * @name Updates
+		 * Two separate updates happen every loop. The update happens anyway and the updateTrf only when the node is being
+		 * moved
+		 */
+		/**@{*/
+		virtual void update() {};
+		virtual void updateTrf() {};
+		/**@}*/
+
+		/**
+		 * @name Mess with the local transform
 		 */
 		/**@{*/
 		void rotateLocalX(float angDegrees);
@@ -66,17 +75,18 @@ class SceneNode
 
 	private:
 		void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
+		void updateWorldTransform(); ///< This update happens only when the object gets moved
 };
 
 
-inline SceneNode::SceneNode(Type type_):
+inline SceneNode::SceneNode(SceneNodeType type_):
 	type(type_)
 {
 	commonConstructorCode();
 }
 
 
-inline SceneNode::SceneNode(Type type_, SceneNode* parent):
+inline SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
 	type(type_)
 {
 	commonConstructorCode();

+ 1 - 2
src/Scene/SkelModelNode.h

@@ -19,9 +19,8 @@ class SkelModelNode: public SceneNode
 		Vec<MeshNode*> meshNodes;
 		SkelNode* skelNode;
 		
-		SkelModelNode(): SceneNode(NT_SKEL_MODEL), skelNode(NULL) { isCompound = true; }
+		SkelModelNode(): SceneNode(SNT_SKEL_MODEL), skelNode(NULL) { isCompound = true; }
 		void init(const char* filename);
-		void deinit() {} ///< Do nothing because it loads no resources
 		void render() {} ///< Do nothing
 };
 

+ 1 - 10
src/Scene/SkelNode.cpp

@@ -10,7 +10,7 @@
 // SkelNode                                                                                                         =
 //======================================================================================================================
 SkelNode::SkelNode(): 
-	SceneNode(NT_SKELETON),
+	SceneNode(SNT_SKELETON),
 	skelAnimCtrl(NULL)
 {
 }
@@ -26,15 +26,6 @@ void SkelNode::init(const char* filename)
 }
 
 
-//======================================================================================================================
-// deinit                                                                                                              =
-//======================================================================================================================
-void SkelNode::deinit()
-{
-	//RsrcMngr::skeletons.unload(skeleton);
-}
-
-
 //======================================================================================================================
 // render                                                                                                              =
 //======================================================================================================================

+ 1 - 2
src/Scene/SkelNode.h

@@ -9,7 +9,7 @@
 
 
 /**
- * Scene node that extends the @ref Skeleton resource
+ * Scene node that extends the Skeleton resource
  */
 class SkelNode: public SceneNode
 {
@@ -20,7 +20,6 @@ class SkelNode: public SceneNode
 		SkelNode();
 		void render();
 		void init(const char* filename);
-		void deinit();
 };