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

Merge pull request #265 from CIB/less-memory

Entity memory optimizations
Ivan Safrin 12 лет назад
Родитель
Сommit
1ee703fa48
2 измененных файлов с 24 добавлено и 16 удалено
  1. 2 6
      Core/Contents/Include/PolyEntity.h
  2. 22 10
      Core/Contents/Source/PolyEntity.cpp

+ 2 - 6
Core/Contents/Include/PolyEntity.h

@@ -660,7 +660,7 @@ namespace Polycode {
 			//@}		
 		protected:
 		
-			std::vector<String> tags;
+			std::vector<String> *tags;
 		
 			void checkTransformSetters();
 		
@@ -674,13 +674,9 @@ namespace Polycode {
 			Vector3 _position;
 			Vector3 _scale;		
 			Rotation _rotation;
-			
-			Quaternion qYaw;
-			Quaternion qPitch;
-			Quaternion qRoll;			
+	
 			Quaternion rotationQuat;
 			
-			
 			bool lockMatrix;
 			bool matrixDirty;
 			Matrix4 transformMatrix;		

+ 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);
 }