Explorar o código

Removed direct transform vector access in entities due to speed and memory considerations

Ivan Safrin %!s(int64=12) %!d(string=hai) anos
pai
achega
81e87a9001

+ 3 - 10
Core/Contents/Include/PolyEntity.h

@@ -670,11 +670,6 @@ namespace Polycode {
 						
 			bool enableScissor;	
 			Polycode::Rectangle scissorBox;			
-		
-			Vector3 position;
-			Vector3 scale;		
-			Rotation rotation;
-			
 			
 			bool editorOnly;
 	
@@ -719,8 +714,6 @@ namespace Polycode {
 			Number yAdjust;
 			std::vector<String> *tags;
 		
-			void checkTransformSetters();
-		
 			void *userData;
 		
 			std::vector<Entity*> children;
@@ -729,9 +722,9 @@ namespace Polycode {
 			
 			Number bBoxRadius;		
 		
-			Vector3 _position;
-			Vector3 _scale;		
-			Rotation _rotation;
+			Vector3 position;
+			Vector3 scale;		
+			Rotation rotation;
 	
 			Quaternion rotationQuat;
 			

+ 6 - 27
Core/Contents/Source/PolyEntity.cpp

@@ -418,26 +418,7 @@ void Entity::doUpdates() {
 	}	
 }
 
-void Entity::checkTransformSetters() {
-	if(_position != position) {
-		_position = position;
-		matrixDirty = true;
-	}
-
-	if(_scale != scale) {
-		_scale = scale;
-		matrixDirty = true;
-	}
-
-	if(_rotation != rotation) {
-		_rotation = rotation;
-		rebuildRotation();
-		matrixDirty = true;
-	}
-}
-
-void Entity::updateEntityMatrix() {	
-	checkTransformSetters();
+void Entity::updateEntityMatrix() {
 
 	if(matrixDirty)
 		rebuildTransformMatrix();
@@ -450,17 +431,17 @@ void Entity::updateEntityMatrix() {
 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);
+		return Vector3(scale.x * parentScale.x, scale.y * parentScale.y, scale.z * parentScale.z);
 		
+	} else {
+		return scale;
 	}
-	else
-		return scale;	
 }
 
 
 Matrix4 Entity::getConcatenatedRollMatrix() const {
 	Quaternion q;
-	q.createFromAxisAngle(0.0f, 0.0f, 1.0f, _rotation.roll);
+	q.createFromAxisAngle(0.0f, 0.0f, 1.0f, rotation.roll);
 	Matrix4 transformMatrix = q.createMatrix();	
 	
 	if(parentEntity != NULL) 
@@ -614,7 +595,6 @@ Vector3 Entity::getScale() const {
 }
 
 Matrix4 Entity::getConcatenatedMatrixRelativeTo(Entity *relativeEntity) {
-	checkTransformSetters();
 	
 	if(matrixDirty)
 		rebuildTransformMatrix();
@@ -633,7 +613,6 @@ Matrix4 Entity::getAnchorAdjustedMatrix() {
 }
 
 Matrix4 Entity::getConcatenatedMatrix() {
-	checkTransformSetters();
 	if(matrixDirty)
 		rebuildTransformMatrix();
 
@@ -679,7 +658,7 @@ void Entity::setYaw(Number yaw) {
 
 
 void Entity::rebuildRotation() {
-	rotationQuat.fromAxes(_rotation.pitch, _rotation.yaw, _rotation.roll);
+	rotationQuat.fromAxes(rotation.pitch, rotation.yaw, rotation.roll);
 }
 
 void Entity::setEntityProp(const String& propName, const String& propValue) {

+ 1 - 1
Core/Contents/Source/PolyScene.cpp

@@ -118,7 +118,7 @@ bool Scene::isEnabled() {
 
 void Scene::Update() {
 	if(sceneType == SCENE_2D_TOPLEFT) {
-		rootEntity.position.y = -CoreServices::getInstance()->getCore()->getYRes();
+		rootEntity.setPositionY(-CoreServices::getInstance()->getCore()->getYRes());
 	}
 	rootEntity.doUpdates();
 }

+ 9 - 9
IDE/Contents/Source/PolycodeFrame.cpp

@@ -187,15 +187,15 @@ void EditPoint::handleEvent(Event *event) {
 }
 
 void EditPoint::limitPoint(UIImage *point) {
-		if(point->position.x < 0.0)
-			point->position.x = 0.0;
-		if(point->position.x > 610.0)
-			point->position.x = 610.0;
-
-		if(point->position.y > 0.0)
-			point->position.y = 0.0;
-		if(point->position.y < -254.0)
-			point->position.y = -254.0;
+		if(point->getPosition().x < 0.0)
+			point->setPositionX(0.0);
+		if(point->getPosition().x > 610.0)
+			point->setPositionX(610.0);
+
+		if(point->getPosition().y > 0.0)
+			point->setPositionY(0.0);
+		if(point->getPosition().y < -254.0)
+			point->setPositionY(-254.0);
 
 }
 

+ 2 - 2
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -31,7 +31,7 @@ PolycodeClipboard *globalClipboard;
 
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
-	core = new POLYCODE_CORE(view, 1100, 700,false,true, 0, 0,90, -1);	
+	core = new POLYCODE_CORE(view, 1100, 700,false,true, 0, 0,60, -1);	
 //	core->pauseOnLoseFocus = true;
 	
 	CoreServices::getInstance()->getResourceManager()->reloadResourcesOnModify = true;
@@ -665,7 +665,7 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 				core->setFramerate(3);
 			break;		
 			case Core::EVENT_GAINED_FOCUS:
-				core->setFramerate(90);			
+				core->setFramerate(60);			
 			break;					
 			case Core::EVENT_CORE_RESIZE:
 				if(menuBar) {

+ 1 - 1
IDE/Contents/Source/PolycodeMaterialEditor.cpp

@@ -571,7 +571,7 @@ PostPreviewBox::PostPreviewBox() : UIElement() {
 	previewScene->addChild(previewPrimitive);
 	previewPrimitive->setMaterialByName("DefaultHDR");
 	previewPrimitive->setColorInt(0, 0, 255, 255);
-	previewPrimitive->rotation.yaw = 20;
+	previewPrimitive->setYaw(20);
 	previewPrimitive->setPosition(1.0, 1.0, -2.5);
 	
 	previewScene->getDefaultCamera()->setPosition(0,3.0,5);

+ 8 - 8
IDE/Contents/Source/PolycodeProps.cpp

@@ -370,13 +370,13 @@ Vector2Prop::Vector2Prop(String caption) : PropProp(caption, "Vector2") {
 
 void Vector2Prop::setPropWidth(Number width) {
 	labelX->setPosition(0, 6);
-	labelY->setPosition(((width-propContents->position.x-PROP_PADDING)/2.0), 6);	
+	labelY->setPosition(((width-propContents->getPosition().x-PROP_PADDING)/2.0), 6);	
 	
-	positionX->position.x = labelX->position.x + 20;
-	positionX->Resize(floor(((width-propContents->position.x-PROP_PADDING)/2.0)-25), positionX->getHeight());
+	positionX->position.x = labelX->getPosition().x + 20;
+	positionX->Resize(floor(((width-propContents->getPosition().x-PROP_PADDING)/2.0)-25), positionX->getHeight());
 
-	positionY->position.x = labelY->position.x + 20;
-	positionY->Resize(floor(((width-propContents->position.x-PROP_PADDING)/2.0)-25), positionY->getHeight());
+	positionY->position.x = labelY->getPosition().x + 20;
+	positionY->Resize(floor(((width-propContents->getPosition().x-PROP_PADDING)/2.0)-25), positionY->getHeight());
 
 }
 
@@ -538,8 +538,8 @@ SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(captio
 }
 
 void SliderProp::setPropWidth(Number width) {
-	slider->Resize(width - propContents->position.x - PROP_PADDING - 50, slider->getHeight());
-	valueLabel->setPosition(width - propContents->position.x - PROP_PADDING - 30, 5);	
+	slider->Resize(width - propContents->getPosition().x - PROP_PADDING - 50, slider->getHeight());
+	valueLabel->setPosition(width - propContents->getPosition().x - PROP_PADDING - 30, 5);	
 }
 
 void SliderProp::handleEvent(Event *event) {
@@ -689,7 +689,7 @@ ComboProp::ComboProp(String caption) : PropProp(caption, "Combo") {
 }
 
 void ComboProp::setPropWidth(Number width) {
-	comboEntry->Resize(width - propContents->position.x - PROP_PADDING, comboEntry->getHeight());
+	comboEntry->Resize(width - propContents->getPosition().x - PROP_PADDING, comboEntry->getHeight());
 }
 
 void ComboProp::setPropData(PolycodeEditorPropActionData* data) {

+ 2 - 2
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -37,7 +37,7 @@ PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Numbe
 	Vector3 entityScale = entity->getCompoundScale();
 	Matrix4 compoundMatrix = entity->getConcatenatedMatrix();
 	entity->ignoreParentMatrix = true;
-	entity->scale = entityScale;
+	entity->setScale(entityScale);
 	entityScale.x = fabs(entityScale.x);
 	entityScale.y = fabs(entityScale.y);
 	this->worldScale = worldScale;
@@ -47,7 +47,7 @@ PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Numbe
 	// Create body definition---------------------------------------
 	b2BodyDef bodyDef;
 	bodyDef.position.Set(compoundMatrix.getPosition().x/worldScale, compoundMatrix.getPosition().y/worldScale);
-	bodyDef.angle = entity->rotation.roll*(PI/180.0f);	
+	bodyDef.angle = entity->getRoll()*(PI/180.0f);	
 	bodyDef.bullet = isSensor;	
 	bodyDef.fixedRotation = fixedRotation;	
 	if(isStatic)

+ 2 - 2
Modules/Contents/UI/Source/PolyUIColorBox.cpp

@@ -344,8 +344,8 @@ void UIColorPicker::handleEvent(Event *event) {
 			case InputEvent::EVENT_MOUSEDOWN:
 			{
 				InputEvent *inputEvent = (InputEvent*) event;
-				mainSelector->setPosition(inputEvent->getMousePosition().x+mainColorRect->position.x, inputEvent->getMousePosition().y+mainColorRect->position.y);
-				mainSelector->startDrag(inputEvent->mousePosition.x-mainSelector->getPosition().x+mainColorRect->position.x,inputEvent->mousePosition.y-mainSelector->getPosition().y+mainColorRect->position.y);
+				mainSelector->setPosition(inputEvent->getMousePosition().x+mainColorRect->getPosition().x, inputEvent->getMousePosition().y+mainColorRect->getPosition().y);
+				mainSelector->startDrag(inputEvent->mousePosition.x-mainSelector->getPosition().x+mainColorRect->getPosition().x,inputEvent->mousePosition.y-mainSelector->getPosition().y+mainColorRect->getPosition().y);
 			}
 			break;
 			case InputEvent::EVENT_MOUSEUP:

+ 3 - 3
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -665,7 +665,7 @@ void UITextInput::setSyntaxHighlighter(UITextInputSyntaxHighlighter *syntaxHighl
 void UITextInput::doMultilineResize() {
 
 	if(multiLine) {
-		int bufferOffset = -linesContainer->position.y/ ( lineHeight+lineSpacing);	
+		int bufferOffset = -linesContainer->getPosition().y/ ( lineHeight+lineSpacing);	
 		
 		int realLineOffset = -1;
 		if(bufferOffset > 0 && bufferOffset < wordWrapLines.size()) {
@@ -1590,7 +1590,7 @@ void UITextInput::showCurrentLineIfOffscreen() {
 	if(!multiLine)
 		return;
 		
-	int bufferOffset = -linesContainer->position.y/ ( lineHeight+lineSpacing);	
+	int bufferOffset = -linesContainer->getPosition().y/ ( lineHeight+lineSpacing);	
 	int heightInLines = (getHeight() / ( lineHeight+lineSpacing)) + 1;
 			
 	if(lines[actualLineOffset].wordWrapLineIndex > bufferOffset && lines[actualLineOffset].wordWrapLineIndex < bufferOffset + heightInLines) {
@@ -2395,7 +2395,7 @@ void UITextInput::readjustBuffer(int lineStart, int lineEnd) {
 		lineEnd = wordWrapLines.size()-1;
 	}
 
-	int bufferOffset = -linesContainer->position.y/ ( lineHeight+lineSpacing);	
+	int bufferOffset = -linesContainer->getPosition().y/ ( lineHeight+lineSpacing);	
 	Number bufferLineOffset = bufferOffset * ( lineHeight+lineSpacing);	
 
 	for(int i=0; i < bufferLines.size(); i++) {