Explorar o código

Made a lot of Matrix4 parameters pass by const reference to reduce copying. Also made some more accessors const.

Cameron Hart %!s(int64=14) %!d(string=hai) anos
pai
achega
6649ffbfdc

+ 8 - 8
Bindings/Contents/LUA/Include/PolycodeLUAWrappers.h

@@ -1335,7 +1335,7 @@ static int Polycore_Renderer_drawToColorBuffer(lua_State *L) {
 static int Polycore_Renderer_getCameraMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Renderer *inst = (Renderer*)lua_topointer(L, 1);
-	Matrix4 *retInst = new Matrix4();
+	 Matrix4  *retInst = new  Matrix4 ();
 	*retInst = inst->getCameraMatrix();
 	lua_pushlightuserdata(L, retInst);
 	return 1;
@@ -1345,7 +1345,7 @@ static int Polycore_Renderer_setCameraMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Renderer *inst = (Renderer*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Matrix4 matrix = *(Matrix4*)lua_topointer(L, 2);
+	const Matrix4 & matrix = *( Matrix4 *)lua_topointer(L, 2);
 	inst->setCameraMatrix(matrix);
 	return 0;
 }
@@ -3636,7 +3636,7 @@ static int Polycore_Bone_setBoneMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Bone *inst = (Bone*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Matrix4 matrix = *(Matrix4*)lua_topointer(L, 2);
+	const Matrix4 & matrix = *( Matrix4 *)lua_topointer(L, 2);
 	inst->setBoneMatrix(matrix);
 	return 0;
 }
@@ -3681,7 +3681,7 @@ static int Polycore_Bone_setRestMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Bone *inst = (Bone*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Matrix4 matrix = *(Matrix4*)lua_topointer(L, 2);
+	const Matrix4 & matrix = *( Matrix4 *)lua_topointer(L, 2);
 	inst->setRestMatrix(matrix);
 	return 0;
 }
@@ -3690,7 +3690,7 @@ static int Polycore_Bone_setBaseMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Bone *inst = (Bone*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Matrix4 matrix = *(Matrix4*)lua_topointer(L, 2);
+	const Matrix4 & matrix = *( Matrix4 *)lua_topointer(L, 2);
 	inst->setBaseMatrix(matrix);
 	return 0;
 }
@@ -3698,7 +3698,7 @@ static int Polycore_Bone_setBaseMatrix(lua_State *L) {
 static int Polycore_Bone_getBaseMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Bone *inst = (Bone*)lua_topointer(L, 1);
-	Matrix4 *retInst = new Matrix4();
+	 Matrix4  *retInst = new  Matrix4 ();
 	*retInst = inst->getBaseMatrix();
 	lua_pushlightuserdata(L, retInst);
 	return 1;
@@ -5359,7 +5359,7 @@ static int Polycore_Quaternion_createFromMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Quaternion *inst = (Quaternion*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Matrix4 matrix = *(Matrix4*)lua_topointer(L, 2);
+	const Matrix4 & matrix = *( Matrix4 *)lua_topointer(L, 2);
 	inst->createFromMatrix(matrix);
 	return 0;
 }
@@ -10777,7 +10777,7 @@ static int Polycore_SceneLight_Render(lua_State *L) {
 static int Polycore_SceneLight_getLightViewMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	SceneLight *inst = (SceneLight*)lua_topointer(L, 1);
-	Matrix4 *retInst = new Matrix4();
+	 Matrix4  *retInst = new  Matrix4 ();
 	*retInst = inst->getLightViewMatrix();
 	lua_pushlightuserdata(L, retInst);
 	return 1;

+ 10 - 10
Core/Contents/Include/PolyBone.h

@@ -89,60 +89,60 @@ namespace Polycode {
 			* Returns the bone matrix
 			* @return Bone matrix.
 			*/									
-			Matrix4 getBoneMatrix();
+			Matrix4 getBoneMatrix() const;
 			
 			/**
 			* Sets the bone matrix.
 			* @return Bone matrix.
 			*/												
-			void setBoneMatrix(Matrix4 matrix);
+			void setBoneMatrix(const Matrix4& matrix);
 			
 			/**
 			* Returns the rest matrix of this bone.
 			* @return Rest matrix.
 			*/															
-			Matrix4 getRestMatrix();
+			Matrix4 getRestMatrix() const;
 			
 			/**
 			* Returns the full rest matrix of this bone.
 			* @return Full rest matrix.
 			*/																		
-			Matrix4 getFullRestMatrix();
+			Matrix4 getFullRestMatrix() const;
 			
 			/**
 			* Returns the rest matrix of this bone's parent.
 			* @return Rest matrix of the bone's parent.
 			*/																					
-			Matrix4 getParentRestMatrix();
+			Matrix4 getParentRestMatrix() const;
 			
 			/**
 			* @see getBoneMatrix()
 			*/																								
-			Matrix4 getFinalMatrix();
+			Matrix4 getFinalMatrix() const;
 			
 			/**
 			* Sets the rest matrix for this bone.
 			* @param matrix New rest matrix.
 			*/
-			void setRestMatrix(Matrix4 matrix);
+			void setRestMatrix(const Matrix4& matrix);
 			
 			/**
 			* Sets the base matrix for this bone.
 			* @param matrix New base matrix.
 			*/			
-			void setBaseMatrix(Matrix4 matrix);
+			void setBaseMatrix(const Matrix4& matrix);
 			
 			/**
 			* Returns the base matrix of this bone.
 			* @return Base matrix.
 			*/			
-			Matrix4 getBaseMatrix() { return baseMatrix; }
+			const Matrix4& getBaseMatrix() const { return baseMatrix; }
 			
 			/**
 			* Returns the full base matrix of this bone.
 			* @return Full base matrix.
 			*/						
-			Matrix4 getFullBaseMatrix();
+			Matrix4 getFullBaseMatrix() const;
 		
 			/**
 			* Id of the bone.

+ 1 - 0
Core/Contents/Include/PolyMatrix4.h

@@ -124,6 +124,7 @@ namespace Polycode {
 			}			
 			
 			inline Number* operator [] ( int row ) { return m[row];}
+			inline const Number* operator [] ( int row ) const { return m[row];}
 			
 			inline Matrix4 operator + ( const Matrix4 &m2 ) const {
 				Matrix4 r;

+ 3 - 3
Core/Contents/Include/PolyParticleEmitter.h

@@ -119,7 +119,7 @@ namespace Polycode {
 			void setParticleCount(int count);
 		
 			virtual void addParticleBody(Entity *particleBody) {}
-			virtual Matrix4 getBaseMatrix() {Matrix4 m; return m;}
+			virtual Matrix4 getBaseMatrix() const {Matrix4 m; return m;}
 		
 			/**
 			* Particle movement speed multiplier
@@ -255,7 +255,7 @@ namespace Polycode {
 		ParticleEmitter *getEmitter() { return this; }
 		
 		void addParticleBody(Entity *particleBody);
-		Matrix4 getBaseMatrix();
+		Matrix4 getBaseMatrix() const;
 		void Update();
 		
 	protected:
@@ -277,7 +277,7 @@ namespace Polycode {
 		ParticleEmitter *getEmitter() { return this; }		
 		
 		void addParticleBody(Entity *particleBody);
-		Matrix4 getBaseMatrix();
+		Matrix4 getBaseMatrix() const;
 		void Update();
 		
 	protected:

+ 3 - 3
Core/Contents/Include/PolyQuaternion.h

@@ -118,7 +118,7 @@ namespace Polycode {
 			 */
 		}
 		
-		void createFromMatrix(Matrix4 matrix) {
+		void createFromMatrix(const Matrix4& matrix) {
 			Number  tr, s, q[4];
 			int    i, j, k;
 			
@@ -265,7 +265,7 @@ namespace Polycode {
     }			
 			
 			void createFromAxisAngle(Number x, Number y, Number z, Number degrees);
-			Matrix4 createMatrix();
+			Matrix4 createMatrix() const;
 			
 			
 			
@@ -280,4 +280,4 @@ namespace Polycode {
 			
 		protected:
 	};
-}
+}

+ 3 - 3
Core/Contents/Include/PolyRenderer.h

@@ -172,8 +172,8 @@ namespace Polycode {
 		virtual void clearBuffer(bool colorBuffer, bool depthBuffer) = 0;
 		virtual void drawToColorBuffer(bool val) = 0;
 		
-		Matrix4 getCameraMatrix();
-		void setCameraMatrix(Matrix4 matrix);
+		const Matrix4& getCameraMatrix() const;
+		void setCameraMatrix(const Matrix4& matrix);
 		void setCameraPosition(Vector3 pos);
 		
 		virtual void drawScreenQuad(Number qx, Number qy) = 0;
@@ -275,4 +275,4 @@ namespace Polycode {
 		int xRes;
 		int yRes;
 	};
-}
+}

+ 13 - 13
Core/Contents/Include/PolySceneLight.h

@@ -58,7 +58,7 @@ namespace Polycode {
 			/*
 			* Returns the light's intensity.
 			*/
-			Number getIntensity();
+			Number getIntensity() const;
 
 			/**
 			* Sets the light's intensity
@@ -75,25 +75,25 @@ namespace Polycode {
 			*/
 			void setAttenuation(Number constantAttenuation, Number linearAttenuation, Number quadraticAttenuation);			
 						
-			Number getConstantAttenuation() { return constantAttenuation; }
-			Number getLinearAttenuation() { return linearAttenuation; }
-			Number getQuadraticAttenuation() { return quadraticAttenuation; }
+			Number getConstantAttenuation() const { return constantAttenuation; }
+			Number getLinearAttenuation() const { return linearAttenuation; }
+			Number getQuadraticAttenuation() const { return quadraticAttenuation; }
 									
 			/*
 			* Returns the light's type.
 			*/			
-			int getType();
+			int getType() const;
 			
 			void renderDepthMap(Scene *scene);
 			
 			void Render();
 
-			Matrix4 getLightViewMatrix();
+			const Matrix4& getLightViewMatrix() const;
 			
 			static const int AREA_LIGHT = 0;
 			static const int SPOT_LIGHT = 1;
 			
-			Texture *getZBufferTexture();
+			Texture *getZBufferTexture() const;
 			
 			/**
 			* Color of the light.
@@ -152,8 +152,8 @@ namespace Polycode {
 				this->spotlightExponent = cosVal - (0.02*spotlightExponent);				
 			}
 			
-			Number getSpotlightCutoff() { return spotlightCutoff; }
-			Number getSpotlightExponent() { return spotlightExponent; }
+			Number getSpotlightCutoff() const { return spotlightCutoff; }
+			Number getSpotlightExponent() const { return spotlightExponent; }
 						
 			
 			/**
@@ -172,12 +172,12 @@ namespace Polycode {
 			/**
 			* Returns true if shadows are enabled.
 			*/
-			bool areShadowsEnabled();
+			bool areShadowsEnabled() const;
 		
 			/**
 			* Returns the light type.
 			*/
-			int getLightType() { return type; }
+			int getLightType() const { return type; }
 		
 			/**
 			* If set to true, draws a wireframe primitive visualizing the light.
@@ -185,7 +185,7 @@ namespace Polycode {
 			void enableDebugDraw(bool val);
 			
 			void setLightImportance(int newImportance);
-			int getLightImportance();
+			int getLightImportance() const;
 		
 			SceneEntity *lightShape;
 			
@@ -217,4 +217,4 @@ namespace Polycode {
 			Number distance;
 			Mesh *lightMesh;
 	};
-}
+}

+ 9 - 9
Core/Contents/Source/PolyBone.cpp

@@ -65,7 +65,7 @@ Bone *Bone::getChildBone(unsigned int index) {
 	return childBones[index];
 }
 
-Matrix4 Bone::getBoneMatrix() {
+Matrix4 Bone::getBoneMatrix() const {
 	if(parentBone)
 		return boneMatrix * parentBone->getBoneMatrix();
 	else {
@@ -73,7 +73,7 @@ Matrix4 Bone::getBoneMatrix() {
 	}
 }
 
-Matrix4 Bone::getFinalMatrix() {
+Matrix4 Bone::getFinalMatrix() const {
 	Matrix4 final = boneMatrix;
 
 	if(parentBone) {
@@ -83,19 +83,19 @@ Matrix4 Bone::getFinalMatrix() {
 	return final;
 }
 
-void Bone::setBoneMatrix(Matrix4 matrix) {
+void Bone::setBoneMatrix(const Matrix4& matrix) {
 	boneMatrix = matrix;
 }
 
-void Bone::setBaseMatrix(Matrix4 matrix) {
+void Bone::setBaseMatrix(const Matrix4& matrix) {
 	baseMatrix = matrix;
 }
 
-Matrix4 Bone::getRestMatrix() {
+Matrix4 Bone::getRestMatrix() const {
 	return restMatrix;
 }
 
-Matrix4 Bone::getParentRestMatrix() {
+Matrix4 Bone::getParentRestMatrix() const {
 	if(parentBone)
 		return parentBone->getFullRestMatrix();
 	else {
@@ -105,7 +105,7 @@ Matrix4 Bone::getParentRestMatrix() {
 	}
 }
 
-Matrix4 Bone::getFullBaseMatrix() {
+Matrix4 Bone::getFullBaseMatrix() const {
 	if(parentBone)
 		return baseMatrix * parentBone->getFullBaseMatrix();
 	else {
@@ -114,7 +114,7 @@ Matrix4 Bone::getFullBaseMatrix() {
 	
 }
 
-Matrix4 Bone::getFullRestMatrix() {
+Matrix4 Bone::getFullRestMatrix() const {
 	if(parentBone)
 		return restMatrix * parentBone->getFullRestMatrix();
 	else {
@@ -122,7 +122,7 @@ Matrix4 Bone::getFullRestMatrix() {
 	}
 }
 
-void Bone::setRestMatrix(Matrix4 matrix) {
+void Bone::setRestMatrix(const Matrix4& matrix) {
 	restMatrix = matrix;
 }
 

+ 2 - 2
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -42,7 +42,7 @@ void SceneParticleEmitter::addParticleBody(Entity *particleBody) {
 	particleParentScene->addEntity((SceneEntity*)particleBody);	
 }
 
-Matrix4 SceneParticleEmitter::getBaseMatrix() {
+Matrix4 SceneParticleEmitter::getBaseMatrix() const {
 	return getConcatenatedMatrix();	
 }
 
@@ -73,7 +73,7 @@ void ScreenParticleEmitter::addParticleBody(Entity *particleBody) {
 	particleParentScreen->addChild((ScreenEntity*)particleBody);
 }
 
-Matrix4 ScreenParticleEmitter::getBaseMatrix() {
+Matrix4 ScreenParticleEmitter::getBaseMatrix() const {
 	return getConcatenatedMatrix();
 }
 

+ 2 - 2
Core/Contents/Source/PolyQuaternion.cpp

@@ -42,7 +42,7 @@ void Quaternion::createFromAxisAngle(Number ax, Number ay, Number az, Number deg
 	z = Number(az * result);
 }
 
-Matrix4 Quaternion::createMatrix()
+Matrix4 Quaternion::createMatrix() const
 {
 	Matrix4 m;
         Number fTx  = 2.0*x;
@@ -247,4 +247,4 @@ Quaternion Quaternion::operator *(Quaternion q)
 	r.z = w*q.z + z*q.w + x*q.y - y*q.x;
 
 	return r;
-}
+}

+ 3 - 3
Core/Contents/Source/PolyRenderer.cpp

@@ -53,7 +53,7 @@ void Renderer::enableShaders(bool flag) {
 	shadersEnabled = flag;
 }
 
-void Renderer::setCameraMatrix(Matrix4 matrix) {
+void Renderer::setCameraMatrix(const Matrix4& matrix) {
 	cameraMatrix = matrix;
 }
 
@@ -168,7 +168,7 @@ void Renderer::addLight(int lightImportance, Vector3 position, Vector3 direction
 	}
 }
 
-Matrix4 Renderer::getCameraMatrix() {
+const Matrix4& Renderer::getCameraMatrix() const {
 	return cameraMatrix;
 }
 
@@ -249,4 +249,4 @@ void Renderer::setTextureFilteringMode(int mode) {
 
 int Renderer::getRenderMode() {
 	return renderMode;
-}
+}

+ 6 - 6
Core/Contents/Source/PolySceneLight.cpp

@@ -74,7 +74,7 @@ void SceneLight::setLightImportance(int newImportance) {
 	lightImportance = newImportance;
 }
 
-int SceneLight::getLightImportance() {
+int SceneLight::getLightImportance() const {
 	return lightImportance;
 }
 
@@ -102,7 +102,7 @@ void SceneLight::enableShadows(bool val, Number resolution) {
 	}
 }
 
-bool SceneLight::areShadowsEnabled() {
+bool SceneLight::areShadowsEnabled() const {
 	return shadowsEnabled;
 }
 
@@ -141,15 +141,15 @@ void SceneLight::renderDepthMap(Scene *scene) {
 	CoreServices::getInstance()->getRenderer()->setViewportSize(CoreServices::getInstance()->getCore()->getXRes(), CoreServices::getInstance()->getCore()->getYRes(), 45.0f);
 }
 
-Matrix4 SceneLight::getLightViewMatrix() {
+const Matrix4& SceneLight::getLightViewMatrix() const {
 	return lightViewMatrix;
 }
 
-Texture *SceneLight::getZBufferTexture() {
+Texture *SceneLight::getZBufferTexture() const {
 	return zBufferTexture;
 }
 
-Number SceneLight::getIntensity() {
+Number SceneLight::getIntensity() const {
 	return intensity;
 }
 
@@ -164,6 +164,6 @@ void SceneLight::Render() {
 	*/
 }
 
-int SceneLight::getType() {
+int SceneLight::getType() const {
 	return type;
 }