kopia lustrzana https://github.com/backface/turtlestitch
Optimize moveBy and friends
This results in realtime speed for dragging where I used to get 10-15 fps before this change.pull/3/merge
rodzic
d5761b074d
commit
6a82960cf7
43
morphic.js
43
morphic.js
|
@ -2398,19 +2398,16 @@ Morph.prototype.visibleBounds = function () {
|
||||||
// Morph accessing - simple changes:
|
// Morph accessing - simple changes:
|
||||||
|
|
||||||
Morph.prototype.moveBy = function (delta) {
|
Morph.prototype.moveBy = function (delta) {
|
||||||
this.changed();
|
this.fullChanged();
|
||||||
this.bounds = this.bounds.translateBy(delta);
|
this.silentMoveBy(delta);
|
||||||
this.children.forEach(function (child) {
|
this.fullChanged();
|
||||||
child.moveBy(delta);
|
|
||||||
});
|
|
||||||
this.changed();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Morph.prototype.silentMoveBy = function (delta) {
|
Morph.prototype.silentMoveBy = function (delta) {
|
||||||
this.bounds = this.bounds.translateBy(delta);
|
this.bounds = this.bounds.translateBy(delta);
|
||||||
this.children.forEach(function (child) {
|
for (var children = this.children, i = children.length; i--;) {
|
||||||
child.silentMoveBy(delta);
|
children[i].silentMoveBy(delta);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Morph.prototype.setPosition = function (aPoint) {
|
Morph.prototype.setPosition = function (aPoint) {
|
||||||
|
@ -3146,9 +3143,7 @@ Morph.prototype.slideBackTo = function (situation, inSteps) {
|
||||||
|
|
||||||
this.fps = 0;
|
this.fps = 0;
|
||||||
this.step = function () {
|
this.step = function () {
|
||||||
myself.fullChanged();
|
myself.moveBy(new Point(xStep, yStep));
|
||||||
myself.silentMoveBy(new Point(xStep, yStep));
|
|
||||||
myself.fullChanged();
|
|
||||||
stepCount += 1;
|
stepCount += 1;
|
||||||
if (stepCount === steps) {
|
if (stepCount === steps) {
|
||||||
situation.origin.add(myself);
|
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 scrolling support:
|
||||||
|
|
||||||
FrameMorph.prototype.submorphBounds = function () {
|
FrameMorph.prototype.submorphBounds = function () {
|
||||||
|
@ -9274,7 +9258,8 @@ HandMorph.prototype.init = function (aWorld) {
|
||||||
this.contextMenuEnabled = false;
|
this.contextMenuEnabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
HandMorph.prototype.changed = function () {
|
HandMorph.prototype.changed =
|
||||||
|
HandMorph.prototype.fullChanged = function () {
|
||||||
var b;
|
var b;
|
||||||
if (this.world !== null) {
|
if (this.world !== null) {
|
||||||
b = this.fullBounds();
|
b = this.fullBounds();
|
||||||
|
@ -9282,7 +9267,6 @@ HandMorph.prototype.changed = function () {
|
||||||
this.world.broken.push(this.fullBounds().spread());
|
this.world.broken.push(this.fullBounds().spread());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// HandMorph navigation:
|
// 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 //////////////////////////////////////////////////////////
|
// WorldMorph //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -3290,7 +3290,7 @@ SpriteMorph.prototype.nestingBounds = function () {
|
||||||
|
|
||||||
// SpriteMorph motion primitives
|
// 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
|
// override the inherited default to make sure my parts follow
|
||||||
// unless it's justMe
|
// unless it's justMe
|
||||||
var delta = aPoint.subtract(this.topLeft());
|
var delta = aPoint.subtract(this.topLeft());
|
||||||
|
|
Ładowanie…
Reference in New Issue