summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 20:46:54 -0400
committerNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 20:46:54 -0400
commit6a82960cf77f9eac16c9a1ce13f360d80469799d (patch)
tree92f19e7db55f03b9215081e694972cb401818278
parentd5761b074d0c98c047e7319cf2243a39c7a6a303 (diff)
downloadsnap-6a82960cf77f9eac16c9a1ce13f360d80469799d.tar.gz
snap-6a82960cf77f9eac16c9a1ce13f360d80469799d.zip
Optimize moveBy and friends
This results in realtime speed for dragging where I used to get 10-15 fps before this change.
-rw-r--r--morphic.js43
-rw-r--r--objects.js2
2 files changed, 10 insertions, 35 deletions
diff --git a/morphic.js b/morphic.js
index e23812a..5cc4062 100644
--- a/morphic.js
+++ b/morphic.js
@@ -2398,19 +2398,16 @@ Morph.prototype.visibleBounds = function () {
// Morph accessing - simple changes:
Morph.prototype.moveBy = function (delta) {
- this.changed();
- this.bounds = this.bounds.translateBy(delta);
- this.children.forEach(function (child) {
- child.moveBy(delta);
- });
- this.changed();
+ this.fullChanged();
+ this.silentMoveBy(delta);
+ this.fullChanged();
};
Morph.prototype.silentMoveBy = function (delta) {
this.bounds = this.bounds.translateBy(delta);
- this.children.forEach(function (child) {
- child.silentMoveBy(delta);
- });
+ for (var children = this.children, i = children.length; i--;) {
+ children[i].silentMoveBy(delta);
+ }
};
Morph.prototype.setPosition = function (aPoint) {
@@ -3146,9 +3143,7 @@ Morph.prototype.slideBackTo = function (situation, inSteps) {
this.fps = 0;
this.step = function () {
- myself.fullChanged();
- myself.silentMoveBy(new Point(xStep, yStep));
- myself.fullChanged();
+ myself.moveBy(new Point(xStep, yStep));
stepCount += 1;
if (stepCount === steps) {
situation.origin.add(myself);
@@ -8433,17 +8428,6 @@ FrameMorph.prototype.fullDrawOn = function (aCanvas, aRect) {
});
};
-// FrameMorph scrolling optimization:
-
-FrameMorph.prototype.moveBy = function (delta) {
- this.changed();
- this.bounds = this.bounds.translateBy(delta);
- this.children.forEach(function (child) {
- child.silentMoveBy(delta);
- });
- this.changed();
-};
-
// FrameMorph scrolling support:
FrameMorph.prototype.submorphBounds = function () {
@@ -9274,7 +9258,8 @@ HandMorph.prototype.init = function (aWorld) {
this.contextMenuEnabled = false;
};
-HandMorph.prototype.changed = function () {
+HandMorph.prototype.changed =
+HandMorph.prototype.fullChanged = function () {
var b;
if (this.world !== null) {
b = this.fullBounds();
@@ -9282,7 +9267,6 @@ HandMorph.prototype.changed = function () {
this.world.broken.push(this.fullBounds().spread());
}
}
-
};
// HandMorph navigation:
@@ -9865,15 +9849,6 @@ HandMorph.prototype.destroyTemporaries = function () {
});
};
-// HandMorph dragging optimization
-
-HandMorph.prototype.moveBy = function (delta) {
- Morph.prototype.trackChanges = false;
- HandMorph.uber.moveBy.call(this, delta);
- Morph.prototype.trackChanges = true;
- this.fullChanged();
-};
-
// WorldMorph //////////////////////////////////////////////////////////
diff --git a/objects.js b/objects.js
index 8d11ff6..1e8060e 100644
--- a/objects.js
+++ b/objects.js
@@ -3290,7 +3290,7 @@ SpriteMorph.prototype.nestingBounds = function () {
// SpriteMorph motion primitives
-Morph.prototype.setPosition = function (aPoint, justMe) {
+SpriteMorph.prototype.setPosition = function (aPoint, justMe) {
// override the inherited default to make sure my parts follow
// unless it's justMe
var delta = aPoint.subtract(this.topLeft());