Browse Source

Renaming and refactoring

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
afec2a10e8

File diff suppressed because it is too large
+ 399 - 416
build/debug/Makefile


+ 1 - 1
src/Main.cpp

@@ -25,7 +25,7 @@
 #include "MeshSkelNodeCtrl.h"
 #include "SkelAnimCtrl.h"
 #include "SkelNode.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "Parser.h"
 #include "ParticleEmitter.h"
 #include "PhyCharacter.h"

+ 1 - 1
src/Renderer/Dbg.cpp

@@ -4,7 +4,7 @@
 #include "Scene.h"
 #include "SkelNode.h"
 #include "Camera.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "RendererInitializer.h"
 
 

+ 13 - 13
src/Renderer/Is.cpp

@@ -3,10 +3,10 @@
 #include "Renderer.h"
 #include "Camera.h"
 #include "Light.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "App.h"
 #include "Scene.h"
-#include "LightProps.h"
+#include "LightData.h"
 
 
 //======================================================================================================================
@@ -176,8 +176,8 @@ void Is::pointLightPass(const PointLight& light)
 	Vec3 lightPosEyeSpace = light.getWorldTransform().origin.getTransformed(cam.getViewMatrix());
 	shader.findUniVar("lightPos")->setVec3(&lightPosEyeSpace);
 	shader.findUniVar("lightRadius")->setFloat(light.getRadius());
-	shader.findUniVar("lightDiffuseCol")->setVec3(&light.lightProps->getDiffuseColor());
-	shader.findUniVar("lightSpecularCol")->setVec3(&light.lightProps->getSpecularColor());
+	shader.findUniVar("lightDiffuseCol")->setVec3(&light.lightData->getDiffuseColor());
+	shader.findUniVar("lightSpecularCol")->setVec3(&light.lightData->getSpecularColor());
 
 	// render quad
 	glEnableVertexAttribArray(0);
@@ -222,13 +222,13 @@ void Is::spotLightPass(const SpotLight& light)
 	smo.run(light);
 
 	// set the texture
-	if(light.lightProps->getTexture() == NULL)
+	if(light.lightData->getTexture() == NULL)
 	{
-		ERROR("No texture is attached to the light. lightProps name: " << light.lightProps->getRsrcName());
+		ERROR("No texture is attached to the light. lightProps name: " << light.lightData->getRsrcName());
 		return;
 	}
 
-	light.lightProps->getTexture()->setRepeat(false);
+	light.lightData->getTexture()->setRepeat(false);
 
 	// shader prog
 	const ShaderProg* shdr;
@@ -257,16 +257,16 @@ void Is::spotLightPass(const SpotLight& light)
 	Vec3 lightPosEyeSpace = light.getWorldTransform().origin.getTransformed(cam.getViewMatrix());
 	shdr->findUniVar("lightPos")->setVec3(&lightPosEyeSpace);
 	shdr->findUniVar("lightRadius")->setFloat(light.getDistance());
-	shdr->findUniVar("lightDiffuseCol")->setVec3(&light.lightProps->getDiffuseColor());
-	shdr->findUniVar("lightSpecularCol")->setVec3(&light.lightProps->getSpecularColor());
-	shdr->findUniVar("lightTex")->setTexture(*light.lightProps->getTexture(), 4);
+	shdr->findUniVar("lightDiffuseCol")->setVec3(&light.lightData->getDiffuseColor());
+	shdr->findUniVar("lightSpecularCol")->setVec3(&light.lightData->getSpecularColor());
+	shdr->findUniVar("lightTex")->setTexture(*light.lightData->getTexture(), 4);
 
 	// set texture matrix for texture & shadowmap projection
 	// Bias * P_light * V_light * inv(V_cam)
 	static Mat4 biasMat4(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
 	Mat4 texProjectionMat;
-	texProjectionMat = biasMat4 * light.camera.getProjectionMatrix() *
-	                   Mat4::combineTransformations(light.camera.getViewMatrix(), Mat4(cam.getWorldTransform()));
+	texProjectionMat = biasMat4 * light.camera->getProjectionMatrix() *
+	                   Mat4::combineTransformations(light.camera->getViewMatrix(), Mat4(cam.getWorldTransform()));
 	shdr->findUniVar("texProjectionMat")->setMat4(&texProjectionMat);
 
 	// the shadowmap
@@ -320,7 +320,7 @@ void Is::run()
 	for(uint i=0; i<app->getScene().lights.size(); i++)
 	{
 		const Light& light = *app->getScene().lights[i];
-		switch(light.type)
+		switch(light.getType())
 		{
 			case Light::LT_POINT:
 			{

+ 1 - 1
src/Renderer/Sm.cpp

@@ -3,7 +3,7 @@
 #include "App.h"
 #include "Scene.h"
 #include "MeshNode.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "Camera.h"
 #include "RendererInitializer.h"
 

+ 1 - 1
src/Renderer/Smo.cpp

@@ -1,7 +1,7 @@
 #include "Smo.h"
 #include "Renderer.h"
 #include "Light.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "Camera.h"
 
 

+ 2 - 2
src/Resources/Core/RsrcContainers.cpp

@@ -5,7 +5,7 @@
 #include "Mesh.h"
 #include "Skeleton.h"
 #include "SkelAnim.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "ParticleEmitterProps.h"
 #include "Script.h"
 
@@ -18,7 +18,7 @@ RsrcContainer<Material>   materials;
 RsrcContainer<Mesh>       meshes;
 RsrcContainer<Skeleton>   skeletons;
 RsrcContainer<SkelAnim>   skelAnims;
-RsrcContainer<LightProps> lightProps;
+RsrcContainer<LightData> lightProps;
 RsrcContainer<ParticleEmitterProps> particleEmitterProps;
 RsrcContainer<Script> scripts;
 

+ 4 - 4
src/Resources/Core/RsrcPtr.cpp

@@ -6,7 +6,7 @@
 #include "Mesh.h"
 #include "Skeleton.h"
 #include "SkelAnim.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "ParticleEmitterProps.h"
 #include "Script.h"
 
@@ -19,7 +19,7 @@ extern RsrcContainer<Material> materials;
 extern RsrcContainer<Mesh> meshes;
 extern RsrcContainer<Skeleton> skeletons;
 extern RsrcContainer<SkelAnim> skelAnims;
-extern RsrcContainer<LightProps> lightProps;
+extern RsrcContainer<LightData> lightProps;
 extern RsrcContainer<ParticleEmitterProps> particleEmitterProps;
 extern RsrcContainer<Script> scripts;
 
@@ -103,7 +103,7 @@ bool RsrcPtr<SkelAnim>::loadRsrc(const char* filename)
 // loadRsrc <LightProp>                                                                                                =
 //======================================================================================================================
 template<>
-bool RsrcPtr<LightProps>::loadRsrc(const char* filename)
+bool RsrcPtr<LightData>::loadRsrc(const char* filename)
 {
 	LOAD_RSRC(lightProps);
 }
@@ -194,7 +194,7 @@ void RsrcPtr<SkelAnim>::unload()
 // unload <LightProps>                                                                                                 =
 //======================================================================================================================
 template<>
-void RsrcPtr<LightProps>::unload()
+void RsrcPtr<LightData>::unload()
 {
 	UNLOAD_RSRC(lightProps);
 }

+ 18 - 15
src/Resources/LightProps.cpp → src/Resources/LightData.cpp

@@ -1,6 +1,6 @@
 #include <cstring>
 #include <GL/glew.h>
-#include "LightProps.h"
+#include "LightData.h"
 #include "Parser.h"
 #include "Texture.h"
 
@@ -8,7 +8,7 @@
 //======================================================================================================================
 // Constructor                                                                                                         =
 //======================================================================================================================
-LightProps::LightProps():
+LightData::LightData():
 	Resource(RT_LIGHT_PROPS),
 	diffuseCol(0.5),
 	specularCol(0.5),
@@ -19,31 +19,35 @@ LightProps::LightProps():
 	fovY(M::PI/4.0)
 {}
 
+
 //======================================================================================================================
 // load                                                                                                                =
 //======================================================================================================================
-bool LightProps::load(const char* filename)
+bool LightData::load(const char* filename)
 {
 	Scanner scanner;
-	if(!scanner.loadFile(filename)) return false;
+	if(!scanner.loadFile(filename))
+	{
+		return false;
+	}
 
 	const Scanner::Token* token;
 
-	do
+	while(true)
 	{
 		token = &scanner.getNextToken();
 
-		//** DIFFUSE_COL **
+		// DIFFUSE_COL
 		if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DIFFUSE_COLOR"))
 		{
 			Parser::parseArrOfNumbers<float>(scanner, true, true, 3, &diffuseCol[0]);
 		}
-		//** SPECULAR_COL **
+		// SPECULAR_COL
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "SPECULAR_COLOR"))
 		{
 			Parser::parseArrOfNumbers<float>(scanner, true, true, 3, &specularCol[0]);
 		}
-		//** RADIUS **
+		// RADIUS
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "RADIUS"))
 		{
 			token = &scanner.getNextToken();
@@ -56,7 +60,7 @@ bool LightProps::load(const char* filename)
 			radius = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
 			                                                       float(token->getValue().getInt());
 		}
-		//** CASTS_SHADOW **
+		// CASTS_SHADOW
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "CASTS_SHADOW"))
 		{
 			token = &scanner.getNextToken();
@@ -68,7 +72,7 @@ bool LightProps::load(const char* filename)
 
 			castsShadow_ = token->getValue().getInt();
 		}
-		//** DISTANCE **
+		// DISTANCE
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "DISTANCE"))
 		{
 			token = &scanner.getNextToken();
@@ -81,7 +85,7 @@ bool LightProps::load(const char* filename)
 			distance = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
 			                                                         float(token->getValue().getInt());
 		}
-		//** FOV_X **
+		// FOV_X
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "FOV_X"))
 		{
 			token = &scanner.getNextToken();
@@ -94,7 +98,7 @@ bool LightProps::load(const char* filename)
 			fovX = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
 			                                                     float(token->getValue().getInt());
 		}
-		//** FOV_Y **
+		// FOV_Y
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "FOV_Y"))
 		{
 			token = &scanner.getNextToken();
@@ -107,7 +111,7 @@ bool LightProps::load(const char* filename)
 			fovY = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
 			                                                     float(token->getValue().getInt());
 		}
-		//** TEXTURE **
+		// TEXTURE
 		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "TEXTURE"))
 		{
 			token = &scanner.getNextToken();
@@ -134,8 +138,7 @@ bool LightProps::load(const char* filename)
 			PARSE_ERR_UNEXPECTED();
 			return false;
 		}
-
-	}while(true);
+	}
 	
 	return true;
 }

+ 4 - 4
src/Resources/LightProps.h → src/Resources/LightData.h

@@ -9,7 +9,7 @@
 
 
 /// Light properties Resource
-class LightProps: public Resource
+class LightData: public Resource
 {
 	PROPERTY_R(Vec3, diffuseCol, getDiffuseColor)
 	PROPERTY_R(Vec3, specularCol, getSpecularColor)
@@ -20,8 +20,8 @@ class LightProps: public Resource
 	PROPERTY_R(float, fovY, getFovY) ///< For spot lights
 		
 	public:
-		LightProps();
-		virtual ~LightProps() {}
+		LightData();
+		~LightData() {}
 		bool load(const char* filename);
 		const Texture* getTexture() const;
 
@@ -30,7 +30,7 @@ class LightProps: public Resource
 };
 
 
-inline const Texture* LightProps::getTexture() const
+inline const Texture* LightData::getTexture() const
 {
 	DEBUG_ERR(texture.get() == NULL);
 	return texture.get();

+ 4 - 4
src/Scene/Camera.h

@@ -54,8 +54,8 @@ class Camera: public SceneNode
 
 	public:
 		// constructors and destuctors
-		Camera(float fovx_, float fovy_, float znear_, float zfar_);
-		Camera(): SceneNode(SNT_CAMERA) {}
+		Camera(float fovx_, float fovy_, float znear_, float zfar_, SceneNode* parent = NULL);
+		Camera(SceneNode* parent = NULL): SceneNode(SNT_CAMERA, parent) {}
 		~Camera() {}
 
 		/**
@@ -97,8 +97,8 @@ class Camera: public SceneNode
 };
 
 
-inline Camera::Camera(float fovx_, float fovy_, float znear_, float zfar_):
-	SceneNode(SNT_CAMERA),
+inline Camera::Camera(float fovx_, float fovy_, float znear_, float zfar_, SceneNode* parent):
+	SceneNode(SNT_CAMERA, parent),
 	fovX(fovx_),
 	fovY(fovy_),
 	zNear(znear_),

+ 9 - 9
src/Scene/Light.cpp

@@ -1,6 +1,6 @@
 #include "Light.h"
 #include "collision.h"
-#include "LightProps.h"
+#include "LightData.h"
 #include "App.h"
 #include "MainRenderer.h"
 
@@ -10,8 +10,8 @@
 //======================================================================================================================
 void PointLight::init(const char* filename)
 {
-	lightProps.loadRsrc(filename);
-	radius = lightProps->getRadius();
+	lightData.loadRsrc(filename);
+	radius = lightData->getRadius();
 }
 
 
@@ -20,13 +20,13 @@ void PointLight::init(const char* filename)
 //======================================================================================================================
 void SpotLight::init(const char* filename)
 {
-	lightProps.loadRsrc(filename);
-	camera.setAll(lightProps->getFovX(), lightProps->getFovY(), 0.2, lightProps->getDistance());
-	castsShadow = lightProps->castsShadow();
+	lightData.loadRsrc(filename);
+	camera->setAll(lightData->getFovX(), lightData->getFovY(), 0.2, lightData->getDistance());
+	castsShadow = lightData->castsShadow();
 
-	if(lightProps->getTexture() == NULL)
+	if(lightData->getTexture() == NULL)
 	{
-		ERROR("Light properties \"" << lightProps->getRsrcName() << "\" do not have a texture");
+		ERROR("Light properties \"" << lightData->getRsrcName() << "\" do not have a texture");
 		return;
 	}
 }
@@ -37,7 +37,7 @@ void SpotLight::init(const char* filename)
 //======================================================================================================================
 void Light::render()
 {
-	app->getMainRenderer().dbg.drawSphere(0.1, getWorldTransform(), Vec4(lightProps->getDiffuseColor(), 1.0));
+	app->getMainRenderer().dbg.drawSphere(0.1, getWorldTransform(), Vec4(lightData->getDiffuseColor(), 1.0));
 	//Dbg::drawSphere(0.1, Transform::getIdentity(), Vec4(lightProps->getDiffuseColor(), 1.0));
 }
 

+ 16 - 12
src/Scene/Light.h

@@ -22,24 +22,29 @@ Specular intensity of material: Sm
 #include "SceneNode.h"
 #include "Camera.h"
 #include "RsrcPtr.h"
-#include "LightProps.h"
+#include "LightData.h"
 
 
 /// Light scene node (Abstract)
 class Light: public SceneNode
 {
 	public:
-		enum Type
+		enum LightType
 		{
 			LT_POINT,
 			LT_SPOT
 		};
 
-		Type type;
-		RsrcPtr<LightProps> lightProps; ///< Later we will add a controller
+	PROPERTY_R(LightType, type, getType) ///< Light type
+
+	public:
+		RsrcPtr<LightData> lightData;
 	
-		Light(Type type_);
+		Light(LightType type_);
 		void render();
+
+	private:
+
 };
 
 
@@ -58,7 +63,7 @@ class PointLight: public Light
 class SpotLight: public Light
 {
 	public:
-		Camera camera;
+		Camera* camera;
 		bool castsShadow;
 
 		SpotLight();
@@ -72,7 +77,7 @@ class SpotLight: public Light
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-inline Light::Light(Type type_):
+inline Light::Light(LightType type_):
 	SceneNode(SNT_LIGHT),
 	type(type_)
 {}
@@ -85,21 +90,20 @@ inline PointLight::PointLight():
 
 inline SpotLight::SpotLight():
 	Light(LT_SPOT),
+	camera(new Camera(this)),
 	castsShadow(false)
-{
-	addChild(&camera);
-}
+{}
 
 
 inline float SpotLight::getDistance() const
 {
-	return camera.getZFar();
+	return camera->getZFar();
 }
 
 
 inline void SpotLight::setDistance(float d)
 {
-	camera.setZFar(d);
+	camera->setZFar(d);
 }
 
 #endif

+ 17 - 26
src/Scene/SceneNode.h

@@ -5,6 +5,7 @@
 #include "Common.h"
 #include "Vec.h"
 #include "Math.h"
+#include "Object.h"
 
 
 class bvolume_t;
@@ -12,10 +13,8 @@ class Material;
 class Controller;
 
 
-/**
- * The backbone of scene
- */
-class SceneNode
+/// The backbone of scene. It is also an Object for memory management reasons
+class SceneNode: public Object
 {
 	friend class Scene;
 
@@ -42,33 +41,28 @@ class SceneNode
 		bvolume_t* bvolumeWspace;
 		bool isCompound;
 		
-		SceneNode(SceneNodeType type_);
-		SceneNode(SceneNodeType type_, SceneNode* parent);
+		SceneNode(SceneNodeType type_, SceneNode* parent = NULL);
 		virtual ~SceneNode();
 		virtual void render() = 0;
 		virtual void init(const char*) = 0; ///< init using a script
 
-		/**
-		 * @name Updates
-		 * Two separate updates happen every loop. The update happens anyway and the updateTrf only when the node is being
-		 * moved
-		 */
-		/**@{*/
+		/// @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
-		 */
-		/**@{*/
+		/// @name Mess with the local transform
+		/// @{
 		void rotateLocalX(float angDegrees);
 		void rotateLocalY(float angDegrees);
 		void rotateLocalZ(float angDegrees);
 		void moveLocalX(float distance);
 		void moveLocalY(float distance);
 		void moveLocalZ(float distance);
-		/**@}*/
+		/// @}
 
 		void addChild(SceneNode* node);
 		void removeChild(SceneNode* node);
@@ -79,18 +73,15 @@ class SceneNode
 };
 
 
-inline SceneNode::SceneNode(SceneNodeType type_):
-	type(type_)
-{
-	commonConstructorCode();
-}
-
-
 inline SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
+	Object(parent),
 	type(type_)
 {
 	commonConstructorCode();
-	parent->addChild(this);
+	if(parent != NULL)
+	{
+		parent->addChild(this);
+	}
 }
 
 

+ 29 - 15
src/Util/Object.h

@@ -5,33 +5,22 @@
 #include "Vec.h"
 
 
-/**
- * A class for automatic garbage collection. Cause we -the programmers- get bored when it comes to deallocation. Dont
- * even think to put as a parent an object that has not created dynamically
- */
+/// A class for automatic garbage collection. Cause we -the programmers- get bored when it comes to deallocation. Dont
+/// even think to put as a parent an object that has not created dynamically
 class Object
 {
 	public:
 		Object(Object* parent = NULL);
 
-		/**
-		 * Delete childs from the last entered to the first
-		 */
+		/// Delete childs from the last entered to the first and update parent
 		virtual ~Object();
 
-		/**
-		 * @name Accessors
-		 */
-		/**@{*/
-		const Object* getObjParent() const {return objParent;}
-		const Vec<Object*> getObjChilds() const {return objChilds;} ///< Get the childs Vec
-		/**@}*/
-
 	private:
 		Object* objParent;
 		Vec<Object*> objChilds;
 
 		void addChild(Object* child);
+		void removeChild(Object* child);
 };
 
 
@@ -43,12 +32,20 @@ inline Object::Object(Object* parent):
 	objParent(NULL)
 {
 	if(parent != NULL)
+	{
 		parent->addChild(this);
+	}
 }
 
 
 inline Object::~Object()
 {
+	if(objParent != NULL)
+	{
+		objParent->removeChild(this);
+	}
+
+	// delete all children
 	for(Vec<Object*>::reverse_iterator it=objChilds.rbegin(); it!=objChilds.rend(); it++)
 	{
 		delete *it;
@@ -66,4 +63,21 @@ inline void Object::addChild(Object* child)
 }
 
 
+inline void Object::removeChild(Object* child)
+{
+	DEBUG_ERR(child == NULL);
+
+	Vec<Object*>::iterator it = find(objChilds.begin(), objChilds.end(), child);
+
+	if(it == objChilds.end())
+	{
+		ERROR("Internal error");
+		return;
+	}
+
+	objChilds.erase(it);
+	child->objParent = NULL;
+}
+
+
 #endif

Some files were not shown because too many files changed in this diff