Bläddra i källkod

Made SceneLine inherit from SceneMesh, moved child order operations to Entity

Ivan Safrin 12 år sedan
förälder
incheckning
b016efd8ed

+ 14 - 0
Core/Contents/Include/PolyEntity.h

@@ -159,6 +159,20 @@ namespace Polycode {
 			*/
 			//@{			
 			
+				/**
+			 * @name Child position operations.
+			 * 
+			 * Move a child in the list of children. Affects display
+			 * order of entities(entities further down in the list will
+			 * appear on top).
+			 */
+			//@{	
+			void moveChildUp(Entity *child);
+			void moveChildDown(Entity *child);
+			void moveChildTop(Entity *child);
+			void moveChildBottom(Entity *child);
+			//}@	
+			
 			/**
 			* @see addChild()
 			*/		

+ 5 - 7
Core/Contents/Include/PolySceneLine.h

@@ -23,7 +23,7 @@ THE SOFTWARE.
 #pragma once
 #include "PolyString.h"
 #include "PolyGlobals.h"
-#include "PolySceneEntity.h"
+#include "PolySceneMesh.h"
 #include "PolyCoreServices.h"
 #include "PolyMesh.h"
 
@@ -32,7 +32,7 @@ namespace Polycode {
 	/**
 	* 3D line class. Can connect two SceneEntity classes with a line.
 	*/ 
-	class _PolyExport SceneLine : public SceneEntity {
+	class _PolyExport SceneLine : public SceneMesh {
 		public:
 			/**
 			* Constructs the line with two taraget entities.
@@ -59,15 +59,13 @@ namespace Polycode {
 			
 			void setStart(Vector3 start);
 			void setEnd(Vector3 end);
-						
-			void Render();
 			
-			Number lineWidth;
-			bool lineSmooth;				
+			void Update();
+				
 			
 		protected:		
 		
-			Mesh *mesh;
+			void initLine();		
 			
 			Vector3 start;
 			Vector3 end;			

+ 0 - 14
Core/Contents/Include/PolyScreenEntity.h

@@ -212,20 +212,6 @@ class _PolyExport ScreenEntity : public Entity {
 		 */
 		void focusNextChild();
 
-		/**
-		 * @name Child position operations.
-		 * 
-		 * Move a child in the list of children. Affects display
-		 * order of entities(entities further down in the list will
-		 * appear on top).
-		 */
-		//@{	
-		void moveChildUp(ScreenEntity *child);
-		void moveChildDown(ScreenEntity *child);
-		void moveChildTop(ScreenEntity *child);
-		void moveChildBottom(ScreenEntity *child);
-		//}@
-
 		/**
 		 * Same semantics as getPosition(), but returns only the x and y coordinates.
 		 * 

+ 42 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -227,6 +227,48 @@ void Entity::removeChild(Entity *entityToRemove) {
 	}	
 }
 
+void Entity::moveChildUp(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i < children.size()-1) {
+			Entity *next = (Entity*)children[i+1];
+			children[i+1] = child;
+			children[i] = next;
+			break;
+		}
+	}
+}
+
+void Entity::moveChildDown(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i > 0) {
+			Entity *prev = (Entity*)children[i-1];
+			children[i-1] = child;
+			children[i] = prev;
+			break;
+		}
+	}
+}
+
+void Entity::moveChildTop(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i < children.size()-1) {
+			children.erase(children.begin()+i);
+			children.push_back(child);
+			break;
+		}
+	}
+}
+
+void Entity::moveChildBottom(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i > 0) {
+			children.erase(children.begin()+i);
+			children.insert(children.begin(), child);
+			break;
+		}
+	}
+}
+
 unsigned int Entity::getNumChildren() {
 	return children.size();
 }

+ 18 - 47
Core/Contents/Source/PolySceneLine.cpp

@@ -26,43 +26,29 @@
 
 using namespace Polycode;
 
-SceneLine::SceneLine(Vector3 start, Vector3 end) : SceneEntity() {
+SceneLine::SceneLine(Vector3 start, Vector3 end) : SceneMesh(Mesh::LINE_MESH) {
 	this->ent1 = NULL;
-	this->ent2 = NULL;	
-	
+	this->ent2 = NULL;
 	this->start = start;
 	this->end = end;	
-	
-	mesh = new Mesh(Mesh::LINE_MESH);	
-	
-	Polygon *poly = new Polygon();
-	poly->addVertex(0,0,0);
-	poly->addVertex(0,0,0);	
-	mesh->addPolygon(poly);
-	
+	initLine();
 	ignoreParentMatrix = true;
-	
-	lineWidth = 1.0;
-	lineSmooth = false;
-	
 }
 
-SceneLine::SceneLine(SceneEntity *ent1, SceneEntity *ent2) : SceneEntity() {
+SceneLine::SceneLine(SceneEntity *ent1, SceneEntity *ent2) : SceneMesh(Mesh::LINE_MESH) {
 	this->ent1 = ent1;
 	this->ent2 = ent2;	
+	initLine();
+	ignoreParentMatrix = true;
 
-	mesh = new Mesh(Mesh::LINE_MESH);	
-	
+}
+
+void SceneLine::initLine() { 
 	Polygon *poly = new Polygon();
-	poly->addVertex(0,0,0);
-	poly->addVertex(0,0,0);	
+	poly->addVertex(0,0,0,0,0);
+	poly->addVertex(0,0,0,1,0);	
 	mesh->addPolygon(poly);
-	
-	ignoreParentMatrix = true;
-	
-	lineWidth = 1.0;
-	lineSmooth = false;
-	
+	mesh->arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;		
 }
 
 SceneLine *SceneLine::SceneLineWithPositions(Vector3 start, Vector3 end) {
@@ -70,7 +56,6 @@ SceneLine *SceneLine::SceneLineWithPositions(Vector3 start, Vector3 end) {
 }
 
 SceneLine::~SceneLine() {
-	delete mesh;
 }
 
 void SceneLine::setStart(Vector3 start) {
@@ -81,11 +66,11 @@ void SceneLine::setEnd(Vector3 end) {
 	this->end = end;
 }
 
-void SceneLine::Render() {	
+void SceneLine::Update(){
 
 	Vector3 v1;
-	Vector3 v2;		
-
+	Vector3 v2;
+	
 	if(ent1 != NULL && ent2 != NULL) {
 		v1 = ent1->getConcatenatedMatrix().getPosition();
 		v2 = ent2->getConcatenatedMatrix().getPosition();
@@ -93,22 +78,8 @@ void SceneLine::Render() {
 		v1 = start;
 		v2 = end;
 	}
-
-	
-	mesh->getPolygon(0)->getVertex(0)->set(v1.x,v1.y,v1.z); 
-	mesh->getPolygon(0)->getVertex(1)->set(v2.x,v2.y,v2.z); 	
-	mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
-	
-	Renderer *renderer = CoreServices::getInstance()->getRenderer();
-	
-	renderer->setLineSize(lineWidth);
-	renderer->setLineSmooth(lineSmooth);
-	
-	renderer->setTexture(NULL);	
-	renderer->pushDataArrayForMesh(mesh, RenderDataArray::VERTEX_DATA_ARRAY);
-	renderer->pushDataArrayForMesh(mesh, RenderDataArray::TEXCOORD_DATA_ARRAY);	
-	renderer->pushDataArrayForMesh(mesh, RenderDataArray::NORMAL_DATA_ARRAY);		
-	
-	renderer->drawArrays(mesh->getMeshType());	
 	
+	mesh->getPolygon(0)->getVertex(0)->set(v1.x,v1.y,v1.z);
+	mesh->getPolygon(0)->getVertex(1)->set(v2.x,v2.y,v2.z);
+	mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;	
 }

+ 0 - 42
Core/Contents/Source/PolyScreenEntity.cpp

@@ -143,48 +143,6 @@ void ScreenEntity::focusChild(ScreenEntity *child) {
 	}
 }
 
-void ScreenEntity::moveChildUp(ScreenEntity *child) {
-	for(int i=0; i < children.size(); i++) {
-		if(children[i] == child && i < children.size()-1) {
-			ScreenEntity *next = (ScreenEntity*)children[i+1];
-			children[i+1] = child;
-			children[i] = next;
-			break;
-		}
-	}
-}
-
-void ScreenEntity::moveChildDown(ScreenEntity *child) {
-	for(int i=0; i < children.size(); i++) {
-		if(children[i] == child && i > 0) {
-			ScreenEntity *prev = (ScreenEntity*)children[i-1];
-			children[i-1] = child;
-			children[i] = prev;
-			break;
-		}
-	}
-}
-
-void ScreenEntity::moveChildTop(ScreenEntity *child) {
-	for(int i=0; i < children.size(); i++) {
-		if(children[i] == child && i < children.size()-1) {
-			children.erase(children.begin()+i);
-			children.push_back(child);
-			break;
-		}
-	}
-}
-
-void ScreenEntity::moveChildBottom(ScreenEntity *child) {
-	for(int i=0; i < children.size(); i++) {
-		if(children[i] == child && i > 0) {
-			children.erase(children.begin()+i);
-			children.insert(children.begin(), child);
-			break;
-		}
-	}
-}
-
 bool ScreenEntity::isFocusable() const {
 	return focusable;
 }