Parcourir la source

Converted Entity::tags to a pointer.

The idea is that most entities don't use tags, so wasting space on it when it's not needed isn't a good idea. tags is protected, so this does not affect the public API. All the functions that use tags were updated appropriately.
cib il y a 12 ans
Parent
commit
ccf895f6f0
2 fichiers modifiés avec 23 ajouts et 11 suppressions
  1. 1 1
      Core/Contents/Include/PolyEntity.h
  2. 22 10
      Core/Contents/Source/PolyEntity.cpp

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

@@ -660,7 +660,7 @@ namespace Polycode {
 			//@}		
 		protected:
 		
-			std::vector<String> tags;
+			std::vector<String> *tags;
 		
 			void checkTransformSetters();
 		

+ 22 - 10
Core/Contents/Source/PolyEntity.cpp

@@ -59,6 +59,8 @@ Entity::Entity() : EventDispatcher() {
 	enableScissor = false;
 	
 	editorOnly = false; 
+
+	tags = NULL;
 }
 
 Entity *Entity::getEntityById(String id, bool recursive) {
@@ -109,8 +111,13 @@ void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
 	clone->scissorBox = scissorBox;
 	clone->editorOnly = editorOnly;	
 	clone->id = id;
-	for(int i=0; i < tags.size(); i++) {	
-		clone->addTag(tags[i]);
+	if(tags == NULL) {
+		clone->tags = NULL;
+	} else {
+		clone->tags = new std::vector<String>();
+		for(int i=0; i < tags->size(); i++) {	
+			clone->addTag((*tags)[i]);
+		}
 	}
 	clone->setRenderer(renderer);
 
@@ -286,6 +293,7 @@ Entity::~Entity() {
 			delete children[i];
 		}
 	}
+	if(tags) delete tags;
 }
 
 Vector3 Entity::getChildCenter() const {
@@ -749,29 +757,33 @@ Number Entity::getCombinedRoll() const {
 }
 
 unsigned int Entity::getNumTags() const {
-	return tags.size();
+	if(!tags) return 0;
+	return tags->size();
 }
 
 String Entity::getTagAtIndex(unsigned int index) const {
-	if(index < tags.size())
-		return tags[index];
+	if(!tags) return "";
+	if(index < tags->size())
+		return (*tags)[index];
 	return "";
 }
 
 bool Entity::hasTag(String tag) const {
-
-	for(int i=0; i < tags.size(); i++) {
-		if(tags[i] == tag)
+	if(!tags) return false;
+	for(int i=0; i < tags->size(); i++) {
+		if((*tags)[i] == tag)
 			return true;
 	}
 	return false;
 }
 			
 void Entity::clearTags() {
-	tags.clear();
+	if(!tags) return;
+	tags->clear();
 }
 
 void Entity::addTag(String tag) {
-	tags.push_back(tag);
+	if(!tags) tags = new std::vector<String>();
+	tags->push_back(tag);
 }