Просмотр исходного кода

Made a lot of read only methods const and parameters const reference where possible to avoid copies.

Cameron Hart 14 лет назад
Родитель
Сommit
7fe8f5c173

+ 1 - 1
Bindings/Contents/LUA/API/Polycode/Entity.lua

@@ -465,7 +465,7 @@ function Entity:getChildCenter()
 end
 
 function Entity:getEntityProp(propName)
-	local retVal = Polycore.Entity_getEntityProp(self.__ptr, propName)
+	local retVal = Polycore.Entity_getEntityProp(self.__ptr, propName.__ptr)
 	return retVal
 end
 

+ 8 - 1
Bindings/Contents/LUA/API/Polycode/Event.lua

@@ -49,7 +49,14 @@ end
 
 function Event:getEventType()
 	local retVal =  Polycore.Event_getEventType(self.__ptr)
-	return retVal
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = String("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
 end
 
 

+ 11 - 9
Bindings/Contents/LUA/Include/PolycodeLUAWrappers.h

@@ -430,7 +430,9 @@ static int Polycore_Event_setDispatcher(lua_State *L) {
 static int Polycore_Event_getEventType(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Event *inst = (Event*)lua_topointer(L, 1);
-	lua_pushstring(L, inst->getEventType().c_str());
+	 String  *retInst = new  String ();
+	*retInst = inst->getEventType();
+	lua_pushlightuserdata(L, retInst);
 	return 1;
 }
 
@@ -1840,7 +1842,7 @@ static int Polycore_Vector3_dot(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Vector3 *inst = (Vector3*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	Vector3 & u = *(Vector3 *)lua_topointer(L, 2);
+	const Vector3 & u = *( Vector3 *)lua_topointer(L, 2);
 	lua_pushnumber(L, inst->dot(u));
 	return 1;
 }
@@ -5691,7 +5693,7 @@ static int Polycore_String_length(lua_State *L) {
 static int Polycore_String_getSTLString(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	String *inst = (String*)lua_topointer(L, 1);
-	string *retInst = new string();
+	 string  *retInst = new  string ();
 	*retInst = inst->getSTLString();
 	lua_pushlightuserdata(L, retInst);
 	return 1;
@@ -5700,7 +5702,7 @@ static int Polycore_String_getSTLString(lua_State *L) {
 static int Polycore_String_getSTLWString(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	String *inst = (String*)lua_topointer(L, 1);
-	wstring *retInst = new wstring();
+	 wstring  *retInst = new  wstring ();
 	*retInst = inst->getSTLWString();
 	lua_pushlightuserdata(L, retInst);
 	return 1;
@@ -9100,7 +9102,7 @@ static int Polycore_Entity_updateEntityMatrix(lua_State *L) {
 static int Polycore_Entity_getTransformMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Entity *inst = (Entity*)lua_topointer(L, 1);
-	Matrix4 *retInst = new Matrix4();
+	 Matrix4  *retInst = new  Matrix4 ();
 	*retInst = inst->getTransformMatrix();
 	lua_pushlightuserdata(L, retInst);
 	return 1;
@@ -9128,7 +9130,7 @@ static int Polycore_Entity_setTransformByMatrix(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Entity *inst = (Entity*)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->setTransformByMatrix(matrix);
 	return 0;
 }
@@ -9137,7 +9139,7 @@ static int Polycore_Entity_setTransformByMatrixPure(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Entity *inst = (Entity*)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->setTransformByMatrixPure(matrix);
 	return 0;
 }
@@ -9600,8 +9602,8 @@ static int Polycore_Entity_getChildCenter(lua_State *L) {
 static int Polycore_Entity_getEntityProp(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Entity *inst = (Entity*)lua_topointer(L, 1);
-	luaL_checktype(L, 2, LUA_TSTRING);
-	String propName = String(lua_tostring(L, 2));
+	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
+	const String & propName = *( String *)lua_topointer(L, 2);
 	lua_pushstring(L, inst->getEntityProp(propName).c_str());
 	return 1;
 }

+ 6 - 6
Core/Contents/Include/PolyColor.h

@@ -62,7 +62,7 @@ namespace Polycode {
 			* Create from another color.
 			* @param color The color to create from.
 			*/												
-			Color(Color *color);
+			Color(const Color *color);
 			
 			/**
 			* Create from integer color.
@@ -75,7 +75,7 @@ namespace Polycode {
 			/** 
 			* Multiplies the color with another color.
 			*/
-			inline Color operator * ( const Color& v2)  {
+			inline Color operator * ( const Color& v2) const {
 				Number nr = r * v2.r;
 				Number ng = g * v2.g;
 				Number nb = b * v2.b;
@@ -133,7 +133,7 @@ namespace Polycode {
 			* Set from another color.
 			* @param color The color to set from.
 			*/															
-			void setColor(Color *color);
+			void setColor(const Color *color);
 			
 			/**
 			* Sets the color to a random color. This does not affect alpha.
@@ -144,13 +144,13 @@ namespace Polycode {
 			* Retuns the brightness of the color
 			* @return Brightness.
 			*/
-			Number getBrightness();
+			Number getBrightness() const;
 			
 			/**
 			* Returns the color as a 32-bit usigned integer.
 			* @return Color as a single 32-bit unsigned integer.
 			*/
-			unsigned int getUint();
+			unsigned int getUint() const;
 			
 			/**
 			* Red value.
@@ -175,4 +175,4 @@ namespace Polycode {
 	
 	};
 
-}
+}

+ 23 - 23
Core/Contents/Include/PolyEntity.h

@@ -88,32 +88,32 @@ namespace Polycode {
 			* Returns the entity's transform matrix.
 			@return Transform matrix.
 			*/
-			Matrix4 getTransformMatrix();
+			const Matrix4& getTransformMatrix() const;
 			
 			/** 
 			* Returns the entity's matrix multiplied by its parent's concatenated matrix. This, in effect, returns the entity's actual world transformation.
 			@return Entity's concatenated matrix.
 			*/
-			Matrix4 getConcatenatedMatrix();
+			Matrix4 getConcatenatedMatrix() const;
 			
 			/** 
 			* Returns Same as getConcatenatedMatrix(), but contains only roll information for rotation. Used internally for billboards.
 			@return Entity's concatenated roll matrix.
 			@see getConcatenatedMatrix()
 			*/			
-			Matrix4 getConcatenatedRollMatrix();				
+			Matrix4 getConcatenatedRollMatrix() const;
 			
 			/**
 			* Sets all of the individual transform properties from the matrix and rebuilds the transform matrix.
 			@param matrix 4x4 transform matrix to apply.
 			*/			
-			void setTransformByMatrix(Matrix4 matrix);	
+			void setTransformByMatrix(const Matrix4& matrix);
 			
 			/**
 			* Sets the transform matrix directly, without setting all of the individual transfrom properties of the entity.
 			@param matrix 4x4 transform matrix to apply.
 			*/						
-			void setTransformByMatrixPure(Matrix4 matrix);	
+			void setTransformByMatrixPure(const Matrix4& matrix);
 			
 			/** Returns the matrix for the entity looking at a location based on a location and an up vector.
 			* @param loc Location to look at.
@@ -158,7 +158,7 @@ namespace Polycode {
 			* Returns the parent entity of the entity.
 			@return Parent entity of this entity.
 			*/
-			Entity *getParentEntity();
+			Entity *getParentEntity() const;
 				
 			//@}
 			// ----------------------------------------------------------------------------------------------------------------
@@ -173,14 +173,14 @@ namespace Polycode {
 			* Returns the entity's position.
 			@return Entity's position as a vector.
 			*/			
-			Vector3 getPosition();
+			Vector3 getPosition() const;
 			
 			/**
 			* Returns the entity's position added to the combined position of its parent. This method is here only for convenience of calculating certain properties and should not be used to get an entity's actual position in the world. To get the actual world position of the entity, use the entity's concatendated matrix.
 			@see getConcatenatedMatrix()
 			@return Entity's position as a vector.
 			*/			
-			Vector3 getCombinedPosition();			
+			Vector3 getCombinedPosition() const;
 
 			/**
 			* Sets the entity's position.
@@ -267,31 +267,31 @@ namespace Polycode {
 			* Returns the entity's scale multiplied by its parent's compound scale.
 			* @return Compound scale as vector.
 			*/			
-			Vector3 getCompoundScale();			
+			Vector3 getCompoundScale() const;
 			
 			/**
 			* Returns the entity's scale.
 			@return Entity's scale as a vector.
 			*/						
-			Vector3 getScale();		
+			Vector3 getScale() const;
 		
 			/**
 			* Returns the entity's pitch combined with the combined pitch of its parent.
 			@return Entity's combined pitch.
 			*/									
-			Number getCombinedPitch();
+			Number getCombinedPitch() const;
 			
 			/**
 			* Returns the entity's yaw combined with the combined yaw of its parent.
 			@return Entity's combined yaw.
 			*/									
-			Number getCombinedYaw();
+			Number getCombinedYaw() const;
 			
 			/**
 			* Returns the entity's roll combined with the combined roll of its parent.
 			@return Entity's combined roll.
 			*/												
-			Number getCombinedRoll();
+			Number getCombinedRoll() const;
 			
 			/**
 			* Forces the rotation quaternion to be rebuilt.
@@ -338,19 +338,19 @@ namespace Polycode {
 			* Returns the current pitch of the entity.
 			* @return Current pitch value.
 			*/																				
-			Number getPitch();
+			Number getPitch() const;
 			
 			/**
 			* Returns the current yaw of the entity.
 			* @return Current yaw value.
 			*/																							
-			Number getYaw();
+			Number getYaw() const;
 			
 			/**
 			* Returns the current roll of the entity.
 			* @return Current roll value.
 			*/																										
-			Number getRoll();
+			Number getRoll() const;
 		
 			/**
 			* Sets the rotation with quaternion value.
@@ -362,7 +362,7 @@ namespace Polycode {
 			* Returns the current rotation as a quaternion.
 			* @return Current rotation value.
 			*/																												
-			Quaternion getRotationQuat();
+			Quaternion getRotationQuat() const;
 			
 			/**
 			* Orients the entity towards the specified location with the provided up vector. The up vector determines which side of the entity will be pointing in that direction.
@@ -383,7 +383,7 @@ namespace Polycode {
 			* Returns the entity's color multiplied by its parent entity's combined color.
 			* @return Entity's combined color.
 			*/
-			Color getCombinedColor();
+			Color getCombinedColor() const;
 			
 			/**
 			* Sets the color of the entity as normalized floating point values.
@@ -429,13 +429,13 @@ namespace Polycode {
 			* Returns the bounding box radius.
 			* @return The bounding box radius.
 			*/			
-			Number getBBoxRadius();
+			Number getBBoxRadius() const;
 			
 			/**
 			* Returns the entity's bounding box radius compounded from its children's bounding box radii.
 			* @return The compound bounding box radius.
 			*/						
-			Number getCompoundBBoxRadius();
+			Number getCompoundBBoxRadius() const;
 			
 			/**
 			* Sets the bounding box radius.
@@ -545,10 +545,10 @@ namespace Polycode {
 				
 			void setBlendingMode(int newBlendingMode);
 				
-			Vector3 getChildCenter();
+			Vector3 getChildCenter() const;
 							
 			vector <EntityProp> entityProps;						
-			String getEntityProp(String propName);		
+			String getEntityProp(const String& propName);
 			
 			void doUpdates();				
 			virtual Matrix4 buildPositionMatrix();
@@ -593,4 +593,4 @@ namespace Polycode {
 		
 			Renderer *renderer;
 	};
-}
+}

+ 4 - 4
Core/Contents/Include/PolyEvent.h

@@ -53,17 +53,17 @@ namespace Polycode {
 			* Returns the event code for this event.
 			* @return Event code for the event.
 			*/ 						
-			int getEventCode();
+			int getEventCode() const;
 			
 			/**
 			* Returns the event dispatcher which originated the event.
 			* @return Event dispatcher which originated the event.
 			*/ 									
-			EventDispatcher *getDispatcher();
+			EventDispatcher *getDispatcher() const;
 			
 			void setEventCode(int eventCode);			
 			void setDispatcher(EventDispatcher *dispatcher);
-			String getEventType();
+			const String& getEventType() const;
 			
 			static const int COMPLETE_EVENT = 0;
 			static const int CHANGE_EVENT = 1;
@@ -75,4 +75,4 @@ namespace Polycode {
 			int eventCode;
 			
 	};
-}
+}

+ 7 - 7
Core/Contents/Include/PolyMatrix4.h

@@ -68,7 +68,7 @@ namespace Polycode {
 			/**
 			* Construct with pointer to 16 Number values.
 			*/ 			
-			Matrix4(Number *m);
+			Matrix4(const Number *m);
 			~Matrix4();			
 			
 			union {
@@ -91,7 +91,7 @@ namespace Polycode {
 			* Rotates a vector by the matrix values.
 			* @param v2 Vector to rotate.
 			*/			
-			inline Vector3 rotateVector(const Vector3 &v2) {
+			inline Vector3 rotateVector(const Vector3 &v2) const {
 				return Vector3(v2.x*m[0][0] + v2.y*m[1][0] + v2.z*m[2][0],
 								v2.x*m[0][1] + v2.y*m[1][1] + v2.z*m[2][1],
 								v2.x*m[0][2] + v2.y*m[1][2] + v2.z*m[2][2]);
@@ -101,7 +101,7 @@ namespace Polycode {
 			* Returns the position from the matrix.
 			* @return Position.
 			*/						
-			inline Vector3 getPosition() {
+			inline Vector3 getPosition() const {
 				Vector3 pos;
 				pos.x = m[3][0];
 				pos.y = m[3][1];
@@ -211,7 +211,7 @@ namespace Polycode {
 			* @param ay Pointer to pitch angle to set.
 			* @param az Pointer to yaw angle to set.
 			*/					
-			inline void getEulerAngles(Number *ax, Number *ay, Number *az) {
+			inline void getEulerAngles(Number *ax, Number *ay, Number *az) const {
 				Number angle_x, angle_y, angle_z,tr_x,tr_y,C;
 				
 				angle_y = asin(m[0][2]);
@@ -246,14 +246,14 @@ namespace Polycode {
 			/**
 			* Returns the inverse of the matrix.
 			*/
-			Matrix4 inverse();
+			Matrix4 inverse() const;
 			
 			/**
 			* Returns the affine inverse of the matrix.
 			*/			
-			Matrix4 inverseAffine();
+			Matrix4 inverseAffine() const;
 	
 		protected:
 		
 	};
-}	
+}	

+ 15 - 15
Core/Contents/Include/PolyString.h

@@ -68,34 +68,34 @@ namespace Polycode {
 			/**
 			* Initializes the string from an STL string.
 			*/												
-			String(string str);
+			String(const string& str);
 			
 			/**
 			* Initializes the string from an STL wstring.
 			*/															
-			String(wstring str);
+			String(const wstring& str);
 		
-			virtual ~String();
+			~String();
 		
 			/**
 			* Return the length of the string.
 			*/														
-			size_t size() { return contents.size(); }
+			size_t size() const { return contents.size(); }
 			
 			/**
 			* Return the length of the string.
 			*/			
-			size_t length() { return contents.size(); }
+			size_t length() const { return contents.size(); }
 		
 			/**
 			* Return the string and an STL string.
 			*/		
-			string getSTLString();
+			const string& getSTLString();
 			
 			/**
 			* Return the string and an STL wstring.
 			*/			
-			wstring getSTLWString();
+			const wstring& getSTLWString() const;
 		
 			/**
 			* Returns the substring of the string.
@@ -141,20 +141,20 @@ namespace Polycode {
 			* Returns the lowercase version of the string.
 			* @return Lowercase version of the stirng.
 			*/															
-			String toLowerCase();
+			String toLowerCase() const;
 			
 			/**
 			* Returns the uppercase version of the string.
 			* @return Uppercase version of the stirng.
 			*/																		
-			String toUpperCase();
+			String toUpperCase() const;
 					
 			/**
 			* Splits the string by the specified delimeter
 			* @param delim The delimeter to split by.
 			* @return An STL vector of the split parts of the string. 
 			*/																				
-			vector<String> split(const String &delim);
+			vector<String> split(const String &delim) const;
 
 			/**
 			* Replaces parts of the string with another string.
@@ -162,7 +162,7 @@ namespace Polycode {
 			* @param withWhat What to replace them with.
 			* @return A new string with the specified matches replaced with the specified string.
 			*/																							
-			String replace(const String &what, const String &withWhat);
+			String replace(const String &what, const String &withWhat) const;
 			
 			/**
 			* Convert a Number to a String.
@@ -181,13 +181,13 @@ namespace Polycode {
 			* Pointer to wchar data.
 			* @return A pointer to wchar data.
 			*/																															
-			const wchar_t *wc_str();
+			const wchar_t *wc_str() const;
 
 			/**
 			* Pointer to wchar data.
 			* @return A pointer to wchar data.
 			*/																																	
-			const wchar_t *data(){ return contents.data(); }
+			const wchar_t *data() const { return contents.data(); }
 
 			/**
 			* Returns data with the specified encoding. Currently the only supported encoding is String::ENCODING_UTF8
@@ -195,7 +195,7 @@ namespace Polycode {
 			* @return A pointer to the data using specified encoding.
 			* @see getDataSizeWithEncoding()
 			*/																															
-			const char *getDataWithEncoding(int encoding);
+			const char *getDataWithEncoding(int encoding) const;
 			
 			/**
 			* Returns the size of the data with the specified encoding. Currently the only supported encoding is String::ENCODING_UTF8
@@ -203,7 +203,7 @@ namespace Polycode {
 			* @return The size the data would take up if returned with this encoding.
 			* @see getDataWithEncoding()
 			*/																																				
-			size_t getDataSizeWithEncoding(int encoding);
+			size_t getDataSizeWithEncoding(int encoding) const;
 					
 			
 			/**

+ 2 - 2
Core/Contents/Include/PolyVector2.h

@@ -44,9 +44,9 @@ namespace Polycode {
 			* @param y Y coordinate.			
 			*/			
 			Vector2(Number x, Number y);
-			virtual ~Vector2();
+			~Vector2();
 					
 		protected:
 
 	};
-}
+}

+ 7 - 13
Core/Contents/Include/PolyVector3.h

@@ -49,7 +49,7 @@ namespace Polycode {
 			* Default constructor.
 			*/ 
 			Vector3();
-			virtual ~Vector3();
+			~Vector3();
 
 			/**
 			* Sets the vector from x,y,z coordinates.
@@ -79,19 +79,13 @@ namespace Polycode {
 			//@{
 			
 
-			inline Vector3& operator * (const Number val) {
-				x *= val;
-				y *= val;
-				z *= val;
-				return *this;				
+			inline Vector3 operator * (const Number val) const {
+				return Vector3(x * val, y * val, z * val);
 			}
 
-			inline Vector3& operator / (const Number val) {
+			inline Vector3 operator / (const Number val) const {
 				assert( val != 0.0 );
-				x /= val;
-				y /= val;
-				z /= val;
-				return *this;				
+				return operator*(1/val);
 			}
 
 			inline Vector3& operator = ( const Vector3& v2)  {
@@ -144,7 +138,7 @@ namespace Polycode {
 			* Returns the dot product with another vector.
 			* @return Dor product with the vector.
 			*/			
-			inline Number dot(Vector3 &u) {
+			inline Number dot(const Vector3 &u) const {
 				return x * u.x + y * u.y + z * u.z;
 			}
 
@@ -183,4 +177,4 @@ namespace Polycode {
 		protected:
 
 	};
-}
+}

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

@@ -295,7 +295,7 @@ void OSBasics::createFolder(String pathString) {
 #endif
 }
 
-bool OSBasics::isFolder(String pathString) {	
+bool OSBasics::isFolder(String pathString) {
 	bool retVal = false;
 #ifdef _WINDOWS
 #else
@@ -308,4 +308,4 @@ bool OSBasics::isFolder(String pathString) {
 	}
 #endif
 	return retVal;
-}
+}

+ 5 - 5
Core/Contents/Source/PolyColor.cpp

@@ -32,7 +32,7 @@ Color::Color(Number r,Number g, Number b, Number a) {
 	setColor(r,g,b,a);
 }
 
-Color::Color(Color *color) {
+Color::Color(const Color *color) {
 	setColor(color->r, color->g, color->b, color->a);
 }
 
@@ -70,7 +70,7 @@ void Color::setColorHex(unsigned int hex) {
 	a = ((Number)ta)/255.0f;	
 }
 
-Number Color::getBrightness() {
+Number Color::getBrightness() const {
 	return (r+g+b) / 3.0f;
 }
 
@@ -115,7 +115,7 @@ void Color::setColorRGBA(int r, int g, int b, int a) {
 	this->a = ((Number)a)/255.0f;
 }
 
-void Color::setColor(Color *color) {
+void Color::setColor(const Color *color) {
 	this->r = color->r;
 	this->g = color->g;
 	this->b = color->b;
@@ -130,7 +130,7 @@ void Color::setColor(Number r, Number g, Number b, Number a) {
 	this->a = a;
 }
 
-unsigned int Color::getUint() {
+unsigned int Color::getUint() const {
 	
 	unsigned int ir = 255.0f*r;
 	unsigned int ig = 255.0f*g;
@@ -143,4 +143,4 @@ unsigned int Color::getUint() {
 
 Color::~Color() {
 
-}
+}

+ 23 - 23
Core/Contents/Source/PolyEntity.cpp

@@ -53,11 +53,11 @@ Entity::Entity() {
 	hasMask = false;
 }
 
-Entity *Entity::getParentEntity() {
+Entity *Entity::getParentEntity() const {
 	return parentEntity;
 }
 
-Color Entity::getCombinedColor() {
+Color Entity::getCombinedColor() const {
 	if(parentEntity) {
 		if(parentEntity->colorAffectsChildren)
 			return color * parentEntity->getCombinedColor();
@@ -137,7 +137,7 @@ void Entity::setBlendingMode(int newBlendingMode) {
 	blendingMode = newBlendingMode;
 }
 
-Number Entity::getBBoxRadius() {
+Number Entity::getBBoxRadius() const {
 	Number compRad;
 	Number biggest = bBoxRadius;
 	for(int i=0;i<children.size();i++) {
@@ -148,7 +148,7 @@ Number Entity::getBBoxRadius() {
 	return biggest;
 }
 
-Number Entity::getCompoundBBoxRadius() {
+Number Entity::getCompoundBBoxRadius() const {
 	Number compRad;
 	Number biggest = bBoxRadius + position.distance(Vector3(0,0,0));
 	for(int i=0;i<children.size();i++) {
@@ -166,7 +166,7 @@ void Entity::setBBoxRadius(Number rad) {
 Entity::~Entity() {
 }
 
-Vector3 Entity::getChildCenter() {
+Vector3 Entity::getChildCenter() const {
 	return childCenter;
 }
 
@@ -216,7 +216,7 @@ void Entity::updateEntityMatrix() {
 	}
 }
 
-Vector3 Entity::getCompoundScale() {
+Vector3 Entity::getCompoundScale() const {
 	if(parentEntity != NULL) {
 		Vector3 parentScale = parentEntity->getCompoundScale();
 		return Vector3(scale.x * parentScale.x, scale.y * parentScale.y,scale.z * parentScale.z);
@@ -227,7 +227,7 @@ Vector3 Entity::getCompoundScale() {
 }
 
 
-Matrix4 Entity::getConcatenatedRollMatrix() {
+Matrix4 Entity::getConcatenatedRollMatrix() const {
 	Quaternion q;
 	q.createFromAxisAngle(0.0f, 0.0f, 1.0f, roll*matrixAdj);
 	Matrix4 transformMatrix = q.createMatrix();	
@@ -385,7 +385,7 @@ void Entity::setRotationQuat(Number w, Number x, Number y, Number z) {
 	matrixDirty = true;
 }
 
-Quaternion Entity::getRotationQuat() {
+Quaternion Entity::getRotationQuat() const {
 	return rotationQuat;
 }
 
@@ -401,18 +401,18 @@ void Entity::setYaw(Number yaw) {
 	matrixDirty = true;
 }
 
-Vector3 Entity::getScale() {
+Vector3 Entity::getScale() const {
 	return scale;
 }
 
-Matrix4 Entity::getConcatenatedMatrix() {
+Matrix4 Entity::getConcatenatedMatrix() const {
 	if(parentEntity != NULL) 
 		return transformMatrix * parentEntity->getConcatenatedMatrix();
 	else
 		return transformMatrix;
 }
 
-Matrix4 Entity::getTransformMatrix() {
+const Matrix4& Entity::getTransformMatrix() const {
 	return transformMatrix;
 }
 
@@ -444,7 +444,7 @@ void Entity::rebuildRotation() {
 	rotationQuat.fromAxes(pitch, yaw, roll);
 }
 
-String Entity::getEntityProp(String propName) {
+String Entity::getEntityProp(const String& propName) {
 	for(int i=0; i < entityProps.size(); i++) {
 		if(entityProps[i].propName == propName) {
 			return entityProps[i].propValue;
@@ -453,7 +453,7 @@ String Entity::getEntityProp(String propName) {
 	return "null";
 }
 
-Vector3 Entity::getCombinedPosition() {
+Vector3 Entity::getCombinedPosition() const {
 	if(parentEntity != NULL)
 		return (parentEntity->getCombinedPosition())+position;
 	else
@@ -464,23 +464,23 @@ void Entity::setParentEntity(Entity *entity) {
 	parentEntity = entity;
 }
 
-Number Entity::getPitch() {
+Number Entity::getPitch() const {
 	return pitch;
 }
 
-Number Entity::getYaw() {
+Number Entity::getYaw() const {
 	return yaw;
 }
 
-Number Entity::getRoll() {
+Number Entity::getRoll() const {
 	return roll;
 }
 
-void Entity::setTransformByMatrixPure(Matrix4 matrix) {
+void Entity::setTransformByMatrixPure(const Matrix4& matrix) {
 	transformMatrix = matrix;
 }
 
-void Entity::setTransformByMatrix(Matrix4 matrix) {
+void Entity::setTransformByMatrix(const Matrix4& matrix) {
 	setPosition(matrix.getPosition());	
 	Number x,y,z;
 	matrix.getEulerAngles(&x,&y,&z);
@@ -565,28 +565,28 @@ void Entity::setScale(Number x, Number y, Number z) {
 	matrixDirty = true;
 }
 
-Vector3 Entity::getPosition() {
+Vector3 Entity::getPosition() const {
 	return position;
 }
 
-Number Entity::getCombinedPitch() {
+Number Entity::getCombinedPitch() const {
 	if(parentEntity != NULL)
 		return parentEntity->getCombinedPitch()+pitch;
 	else
 		return pitch;
 }
 
-Number Entity::getCombinedYaw() {
+Number Entity::getCombinedYaw() const {
 	if(parentEntity != NULL)
 		return parentEntity->getCombinedYaw()+yaw;
 	else
 		return yaw;
 }
 
-Number Entity::getCombinedRoll() {
+Number Entity::getCombinedRoll() const {
 	if(parentEntity != NULL)
 		return parentEntity->getCombinedRoll()+roll;
 	else
 		return roll;
 	
-}
+}

+ 4 - 4
Core/Contents/Source/PolyEvent.cpp

@@ -37,15 +37,15 @@ namespace Polycode {
 		
 	}
 	
-	String Event::getEventType() {
+	const String& Event::getEventType() const {
 		return eventType;
 	}
 	
-	int Event::getEventCode() {
+	int Event::getEventCode() const {
 		return eventCode;
 	}
 	
-	EventDispatcher *Event::getDispatcher() {
+	EventDispatcher *Event::getDispatcher() const {
 		return dispatcher;
 	}
 	
@@ -56,4 +56,4 @@ namespace Polycode {
 	void Event::setEventCode(int eventCode) {
 		this->eventCode = eventCode;
 	}
-}
+}

+ 4 - 4
Core/Contents/Source/PolyMatrix4.cpp

@@ -32,11 +32,11 @@ Matrix4::~Matrix4() {
 
 }
 
-Matrix4::Matrix4(Number *m) {
+Matrix4::Matrix4(const Number *m) {
 	memcpy(ml, m, sizeof(Number)*16);
 }
 
-    Matrix4 Matrix4::inverse() 
+	Matrix4 Matrix4::inverse() const
     {
         Number m00 = m[0][0], m01 = m[0][1], m02 = m[0][2], m03 = m[0][3];
         Number m10 = m[1][0], m11 = m[1][1], m12 = m[1][2], m13 = m[1][3];
@@ -98,7 +98,7 @@ Matrix4::Matrix4(Number *m) {
             d30, d31, d32, d33);
     }
     //-----------------------------------------------------------------------
-    Matrix4 Matrix4::inverseAffine(void) 
+	Matrix4 Matrix4::inverseAffine(void) const
     {
 
         Number m10 = m[1][0], m11 = m[1][1], m12 = m[1][2];
@@ -139,4 +139,4 @@ Matrix4::Matrix4(Number *m) {
             r10, r11, r12, r13,
             r20, r21, r22, r23,
               0,   0,   0,   1);
-    }
+    }

+ 11 - 11
Core/Contents/Source/PolyString.cpp

@@ -43,11 +43,11 @@ String::String(const wchar_t *str, size_t n) {
 	contents = wstring(str, n);
 }
 
-String::String(string str) {
+String::String(const string& str) {
 	contents.assign(str.begin(), str.end());	
 }
 
-String::String(wstring str) {
+String::String(const wstring& str) {
 	contents = str;
 }
 
@@ -55,7 +55,7 @@ String::~String() {
 	
 }
 
-size_t String::getDataSizeWithEncoding(int encoding) {
+size_t String::getDataSizeWithEncoding(int encoding) const {
 	switch(encoding) {
 		case ENCODING_UTF8: {
 			string dest;
@@ -67,7 +67,7 @@ size_t String::getDataSizeWithEncoding(int encoding) {
 	}
 }
 
-const char *String::getDataWithEncoding(int encoding) {
+const char *String::getDataWithEncoding(int encoding) const {
 	switch(encoding) {
 		case ENCODING_UTF8: {
 			string dest;
@@ -92,7 +92,7 @@ void String::setDataWithEncoding(char *data, int encoding) {
 }
 
 
-vector<String> String::split(const String &delim) {
+vector<String> String::split(const String &delim) const {
 	
 	vector<String> tokens;
 	bool trimEmpty = false;
@@ -122,7 +122,7 @@ vector<String> String::split(const String &delim) {
 	return tokens;
 }
 
-String String::replace(const String &what, const String &withWhat) {
+String String::replace(const String &what, const String &withWhat) const {
 	vector<String> arr = split(what);
 	String retString = "";
 	for(int i= 0; i < arr.size(); i++) {
@@ -134,13 +134,13 @@ String String::replace(const String &what, const String &withWhat) {
 	return retString;
 }
 
-String String::toLowerCase() {
+String String::toLowerCase() const {
 	wstring str = contents;
 	std::transform(str.begin(), str.end(), str.begin(),::tolower);	
 	return String(str);
 }
 
-String String::toUpperCase() {
+String String::toUpperCase() const {
 	wstring str = contents;
 	std::transform(str.begin(), str.end(), str.begin(),::toupper);	
 	return String(str);
@@ -154,12 +154,12 @@ String String::NumberToString(Number value) {
 }
 
 
-string String::getSTLString() {
+const string& String::getSTLString() {
 	s_contents.assign(contents.begin(),contents.end());
 	return s_contents;
 }
 
-wstring String::getSTLWString() {
+const wstring& String::getSTLWString() const {
 	return contents;
 }
 
@@ -168,7 +168,7 @@ const char *String::c_str() {
 	return s_contents.c_str();
 }
 
-const wchar_t *String::wc_str() {
+const wchar_t *String::wc_str() const {
 	return contents.c_str();
 }