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

Add "const" to a number of methods

- mostly Clone() and applyClone() methods, which required
  changing Entity which then required touching everything
  that overrode those methods.
- I just wanted to add const to all the obvious methods in
  ScreenEntity but then I touched Clone() and I had to touch
  everything.
Nur Monson 12 лет назад
Родитель
Сommit
4565c409f9

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

@@ -86,12 +86,12 @@ namespace Polycode {
  			* @param ignoreEditorOnly If true, ignore all child entities where editorOnly is set to true (will still clone the entity you call Clone() on even if its editorOnly flag is set to true.
  			* @return The clone of the entity.
  			*/
-			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
 
 			/**
  			* This method must be implemented by all subvlasses implementing Clone.
  			*/
-			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 		
 		
 			// ----------------------------------------------------------------------------------------------------------------
@@ -603,7 +603,7 @@ namespace Polycode {
 			* Returns the user data pointer.
 			* @return User data pointer
 			*/			
-			void *getUserData();
+			void *getUserData() const;
 				
 			/**
 			* Sets the entity's blending mode.
@@ -612,8 +612,8 @@ namespace Polycode {
 			*/
 			void setBlendingMode(int newBlendingMode);
 			
-			Entity *getEntityById(String id, bool recursive);
-			std::vector<Entity*> getEntitiesByTag(String tag, bool recursive);
+			Entity *getEntityById(String id, bool recursive) const;
+			std::vector<Entity*> getEntitiesByTag(String tag, bool recursive) const;
 						
 			Vector3 getChildCenter() const;
 			

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

@@ -228,7 +228,7 @@ namespace Polycode {
 			
 			Number particleSize;
 			
-			Texture *getParticleTexture();
+			Texture *getParticleTexture() const;
 			
 			void setParticleTexture(Texture *texture);
 		
@@ -242,7 +242,7 @@ namespace Polycode {
 							
 			int emitterType;
 			
-			bool getIgnoreParentMatrix();			
+			bool getIgnoreParentMatrix() const;
 			void setIgnoreParentMatrix(bool val);
 											
 		protected:
@@ -332,8 +332,8 @@ namespace Polycode {
 		ScreenParticleEmitter(const String& imageFile, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, ScreenMesh *emitter = NULL);
 		virtual ~ScreenParticleEmitter();		
 		
-		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 		
 		/**
 		* Returns the emitter (helper method for LUA).

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

@@ -53,8 +53,8 @@ class _PolyExport ScreenEntity : public Entity {
 		ScreenEntity();
 		virtual ~ScreenEntity();
 		
-		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 
 		void addEntity(Entity *newChild);
 		
@@ -169,7 +169,7 @@ class _PolyExport ScreenEntity : public Entity {
 		 * Get the position mode.
 		 * @see setPositionMode()
 		 */
-		int getPositionMode();
+		int getPositionMode() const;
 
 		/**
 		 * Set a rectangle to which dragging will be restricted.
@@ -274,7 +274,7 @@ class _PolyExport ScreenEntity : public Entity {
 		 * Note: Make sure only entities of type ScreenEntity have the tag you're
 		 *       querying, or otherwise you will be treating an Entity as ScreenEntity.
 		 */
-		ScreenEntity *getScreenEntityById(String id, bool recursive);
+		ScreenEntity *getScreenEntityById(String id, bool recursive) const;
 
 		/**
 		 * Does the same as getEntitiesByID, but casts each result to ScreenEntity.
@@ -282,7 +282,7 @@ class _PolyExport ScreenEntity : public Entity {
 		 * Note: Make sure only entities of type ScreenEntity have the tag you're
 		 *       querying, or otherwise you will be treating an Entity as ScreenEntity.
 		 */
-		std::vector<ScreenEntity*> getScreenEntitiesByTag(String tag, bool recursive);
+		std::vector<ScreenEntity*> getScreenEntitiesByTag(String tag, bool recursive) const;
 		
 		/**
 		* If set to true, will block mouse events for underlaying entities.
@@ -300,7 +300,7 @@ class _PolyExport ScreenEntity : public Entity {
 		 * Get the hitbox of this ScreenEntity.
 		 * @see setHitBox()
 		 */
-		Rectangle getHitbox();
+		Rectangle getHitbox() const;
 
 
 		void setHitbox(Number width, Number height);

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

@@ -48,8 +48,8 @@ class ScreenEntityInstance : public ScreenEntity {
 
 		virtual ~ScreenEntityInstance();
 	
-		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 		
 		void reloadEntityInstance();
 

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

@@ -63,8 +63,8 @@ namespace Polycode {
 		
 		virtual ~ScreenImage();
 		
-		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 
 		/**
 		* Changes which part of the image is displayed.

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

@@ -45,8 +45,8 @@ namespace Polycode {
 			ScreenLabel(const String& text, int size, const String& fontName = "sans", int amode = 0, bool premultiplyAlpha = false);
 			virtual ~ScreenLabel();		
 		
-			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 					
 			/**
 			* Sets a new text to the screen label.

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

@@ -44,8 +44,8 @@ namespace Polycode {
 			*/
 			ScreenShape(int shapeType, Number option1=0, Number option2=0, Number option3=0, Number option4=0);
 		
-			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 				
 			virtual ~ScreenShape();
 			void Render();

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

@@ -47,8 +47,8 @@ namespace Polycode {
 			ScreenSound(const String& fileName, Number referenceDistance, Number maxDistance);
 			virtual ~ScreenSound();			
 
-			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 
 			void Update();			
 			

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

@@ -75,8 +75,8 @@ class _PolyExport ScreenSprite : public ScreenShape
 		
 		virtual ~ScreenSprite();
 		
-		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
-		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
 
 		/**
 		* Adds a new animation to the sprite. Animations are added by specifying a list of frame indexes and then can be played back by the specified name.

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

@@ -63,7 +63,7 @@ Entity::Entity() : EventDispatcher() {
 	tags = NULL;
 }
 
-Entity *Entity::getEntityById(String id, bool recursive) {
+Entity *Entity::getEntityById(String id, bool recursive) const {
 	for(int i=0;i<children.size();i++) {
 		if(children[i]->id == id) {
 			return children[i];
@@ -79,13 +79,13 @@ Entity *Entity::getEntityById(String id, bool recursive) {
 	return NULL;
 }
 
-Entity *Entity::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *Entity::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	Entity *newEntity = new Entity();
 	applyClone(newEntity, deepClone, ignoreEditorOnly);
 	return newEntity;
 }
 
-void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	clone->ownsChildren = ownsChildren;
 	clone->position = position;
 	clone->rotation = rotation;
@@ -139,7 +139,7 @@ void Entity::setOwnsChildrenRecursive(bool val) {
 	}
 }
 
-std::vector<Entity*> Entity::getEntitiesByTag(String tag, bool recursive) {
+std::vector<Entity*> Entity::getEntitiesByTag(String tag, bool recursive) const {
 
 	std::vector<Entity*> retVector;
 
@@ -162,7 +162,7 @@ void Entity::setUserData(void *userData) {
 	this->userData = userData;
 }
 
-void *Entity::getUserData() {
+void *Entity::getUserData() const {
 	return userData;
 }
 

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

@@ -96,13 +96,13 @@ ScreenParticleEmitter::~ScreenParticleEmitter(){
 	}
 }
 
-Entity *ScreenParticleEmitter::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenParticleEmitter::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenParticleEmitter *newEmitter = new ScreenParticleEmitter("default.png", Particle::BILLBOARD_PARTICLE, ParticleEmitter::CONTINUOUS_EMITTER, 2.0, 0, Vector3(0.0, -40.0, 0.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0), Vector3(10.0, 10.0, 0.0));
 	applyClone(newEmitter, deepClone, ignoreEditorOnly);
 	return newEmitter;
 }
 
-void ScreenParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenParticleEmitter *_clone = (ScreenParticleEmitter*) clone;
 
 	_clone->emitterRadius = this->emitterRadius;
@@ -214,7 +214,7 @@ ParticleEmitter::ParticleEmitter(const String& imageFile, Mesh *particleMesh, in
 	useScaleCurves = false;	
 }
 
-bool ParticleEmitter::getIgnoreParentMatrix() {
+bool ParticleEmitter::getIgnoreParentMatrix() const {
 	return ignoreParentMatrix;
 }
 
@@ -226,7 +226,7 @@ void ParticleEmitter::setIgnoreParentMatrix(bool val) {
 }
 
 
-Texture *ParticleEmitter::getParticleTexture() {
+Texture *ParticleEmitter::getParticleTexture() const {
 	return particleTexture;
 }
 

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

@@ -67,13 +67,13 @@ ScreenEntity::ScreenEntity() : Entity() {
 	
 }
 
-Entity *ScreenEntity::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenEntity::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenEntity *newEntity = new ScreenEntity();
 	applyClone(newEntity, deepClone, ignoreEditorOnly);
 	return newEntity;
 }
 
-void ScreenEntity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenEntity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	Entity::applyClone(clone, deepClone, ignoreEditorOnly);
 
 	ScreenEntity *_clone = (ScreenEntity*) clone;
@@ -330,7 +330,7 @@ void ScreenEntity::_onKeyUp(PolyKEY key, wchar_t charCode) {
 	}
 }
 
-int ScreenEntity::getPositionMode() {
+int ScreenEntity::getPositionMode() const {
 	return positionMode;
 }
 
@@ -348,7 +348,7 @@ void ScreenEntity::clearDragLimits() {
 	dragLimits = NULL;
 }
 
-Rectangle ScreenEntity::getHitbox() {
+Rectangle ScreenEntity::getHitbox() const {
 	return hit;
 }
 
@@ -685,11 +685,11 @@ void ScreenEntity::adjustMatrixForChildren() {
 	}
 }
 
-ScreenEntity *ScreenEntity::getScreenEntityById(String id, bool recursive) {
+ScreenEntity *ScreenEntity::getScreenEntityById(String id, bool recursive) const {
 	return (ScreenEntity*)getEntityById(id, recursive);
 }
 
-std::vector<ScreenEntity*> ScreenEntity::getScreenEntitiesByTag(String tag, bool recursive) {
+std::vector<ScreenEntity*> ScreenEntity::getScreenEntitiesByTag(String tag, bool recursive) const {
 	std::vector<Entity*> entities = getEntitiesByTag(tag, recursive);
 	std::vector<ScreenEntity*> retEntities;
 	for(int i=0; i < entities.size(); i++) {

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

@@ -77,7 +77,7 @@ ScreenEntityInstanceResourceEntry *ScreenEntityInstance::getResourceEntry() {
 	return resourceEntry;
 }
 
-Entity *ScreenEntityInstance::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenEntityInstance::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenEntityInstance *newEntity;
 	if(cloneUsingReload) {
 		newEntity = new ScreenEntityInstance(fileName);
@@ -88,7 +88,7 @@ Entity *ScreenEntityInstance::Clone(bool deepClone, bool ignoreEditorOnly) {
 	return newEntity;
 }
 
-void ScreenEntityInstance::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenEntityInstance::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	if(cloneUsingReload) {
 		ScreenEntity::applyClone(clone, false, ignoreEditorOnly);
 	} else {

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

@@ -79,13 +79,13 @@ ScreenImage::~ScreenImage() {
 
 }
 
-Entity *ScreenImage::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenImage::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenImage *newImage = new ScreenImage(getTexture()->getResourcePath());
 	applyClone(newImage, deepClone, ignoreEditorOnly);
 	return newImage;
 }
 
-void ScreenImage::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenImage::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
 }
 

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

@@ -50,13 +50,13 @@ Label *ScreenLabel::getLabel() const {
 	return label;
 }
 
-Entity *ScreenLabel::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenLabel::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenLabel *newLabel = new ScreenLabel(getText(), label->getSize(), label->getFont()->getFontName(), label->getAntialiasMode());
 	applyClone(newLabel, deepClone, ignoreEditorOnly);
 	return newLabel;
 }
 
-void ScreenLabel::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenLabel::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
 	ScreenLabel *_clone = (ScreenLabel*) clone;
 	_clone->positionAtBaseline = positionAtBaseline;

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

@@ -71,14 +71,14 @@ void ScreenShape::operator=(const ScreenShape& copy) {
 
 }
 
-Entity *ScreenShape::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenShape::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenShape *newEntity = new ScreenShape(ScreenShape::SHAPE_RECT, 1,1);
 	applyClone(newEntity, deepClone, ignoreEditorOnly);
 	return newEntity;
 
 }
 
-void ScreenShape::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenShape::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenEntity::applyClone(clone, deepClone, ignoreEditorOnly);
 	ScreenShape *_clone = (ScreenShape*) clone;
 	*_clone = *this;

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

@@ -50,13 +50,13 @@ void ScreenSoundListener::Update() {
 
 }
 
-Entity *ScreenSound::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenSound *newSound = new ScreenSound(sound->getFileName(), sound->getReferenceDistance(), sound->getMaxDistance());
 	applyClone(newSound, deepClone, ignoreEditorOnly);
 	return newSound;
 }
 
-void ScreenSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenEntity::applyClone(clone, deepClone, ignoreEditorOnly);
 }
 

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

@@ -43,7 +43,7 @@ ScreenSprite::ScreenSprite(const String& fileName) : ScreenShape(ScreenShape::SH
 	loadFromFile(fileName);
 }
 
-Entity *ScreenSprite::Clone(bool deepClone, bool ignoreEditorOnly) {
+Entity *ScreenSprite::Clone(bool deepClone, bool ignoreEditorOnly) const {
 	ScreenSprite *newSprite = new ScreenSprite(getTexture()->getResourcePath(), spriteWidth, spriteHeight);
 	for(int i=0; i < animations.size(); i++) {
 		newSprite->addAnimation(animations[i]->name, animations[i]->frames, animations[i]->speed);
@@ -55,7 +55,7 @@ Entity *ScreenSprite::Clone(bool deepClone, bool ignoreEditorOnly) {
 	return newSprite;
 }
 
-void ScreenSprite::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+void ScreenSprite::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
 	
 }