Skip to content

Commit

Permalink
Merge pull request #386 from entrylabs/refac/optimize-entry
Browse files Browse the repository at this point in the history
Refac/optimize entry
  • Loading branch information
chanlee authored Jul 12, 2016
2 parents ae65019 + 8da397e commit e1204cd
Show file tree
Hide file tree
Showing 17 changed files with 15,835 additions and 15,551 deletions.
27,425 changes: 13,786 additions & 13,639 deletions dist/entry.js

Large diffs are not rendered by default.

3,710 changes: 1,857 additions & 1,853 deletions dist/entry.min.js

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions extern/util/ndgmr.Collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
this.ndgmr = this.ndgmr || {};

(function() {
var threshold = 2;

var collisionCanvas = document.createElement('canvas');
var collisionCtx = collisionCanvas.getContext('2d');
Expand Down Expand Up @@ -86,21 +87,24 @@ this.ndgmr = this.ndgmr || {};
return intersection;
}

if (intersection.width === 0 || intersection.height == 0)
return false;

alphaThreshold = alphaThreshold || 0;
alphaThreshold = Math.min(0.99999,alphaThreshold);

//setting the canvas size
collisionCanvas.width = intersection.width;
collisionCanvas.height = intersection.height;
collisionCanvas2.width = intersection.width;
collisionCanvas2.height = intersection.height;
collisionCanvas.width = intersection.width / threshold;
collisionCanvas.height = intersection.height / threshold;
collisionCanvas2.width = intersection.width / threshold;
collisionCanvas2.height = intersection.height / threshold;

imageData1 = _intersectingImagePart(intersection,bitmap1,collisionCtx,1);
imageData2 = _intersectingImagePart(intersection,bitmap2,collisionCtx2,2);

//compare the alpha values to the threshold and return the result
// = true if pixels are both > alphaThreshold at one coordinate
pixelIntersection = _compareAlphaValues(imageData1,imageData2,intersection.width,intersection.height,alphaThreshold, getRect);
pixelIntersection = _compareAlphaValues(imageData1,imageData2,intersection.width / threshold,intersection.height,alphaThreshold / threshold, getRect);

if ( pixelIntersection ) {
pixelIntersection.x += intersection.x;
Expand Down Expand Up @@ -147,18 +151,15 @@ this.ndgmr = this.ndgmr || {};
ctx.restore();
ctx.save();
//ctx.clearRect(0,0,intersetion.width,intersetion.height);
ctx.rotate(_getParentalCumulatedProperty(bitmap,'rotation')*(Math.PI/180));
ctx.scale(_getParentalCumulatedProperty(bitmap,'scaleX','*'),_getParentalCumulatedProperty(bitmap,'scaleY','*'));
ctx.translate(-bl.x-intersetion['rect'+i].regX,-bl.y-intersetion['rect'+i].regY);
ctx.rotate(_getParentalCumulatedProperty(bitmap,'rotation')*(Math.PI/181));
ctx.scale(_getParentalCumulatedProperty(bitmap,'scaleX','*') / threshold,_getParentalCumulatedProperty(bitmap,'scaleY','*') / threshold);
ctx.translate((-bl.x-intersetion['rect'+i].regX) / threshold,( -bl.y-intersetion['rect'+i].regY) / threshold);
if ( (sr = bitmap.sourceRect) != undefined ) {
ctx.drawImage(image,sr.x,sr.y,sr.width,sr.height,0,0,sr.width,sr.height);
} else {
ctx.drawImage(image,0,0,image.width,image.height);
ctx.drawImage(image,0,0,image.width / threshold,image.height / threshold);
}
if (intersection.width === 0 || intersection.height == 0)
return false;
else
return ctx.getImageData(0, 0, intersetion.width, intersetion.height).data;
return ctx.getImageData(0, 0, intersetion.width / threshold, intersetion.height / threshold).data;
}

var _compareAlphaValues = function(imageData1,imageData2,width,height,alphaThreshold,getRect) {
Expand Down
1 change: 1 addition & 0 deletions src/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ Entry.Container.prototype.moveElement = function(start, end, isCallFromState) {
this.objects_.splice(endIndex, 0, this.objects_.splice(startIndex, 1)[0]);
this.setCurrentObjects();
Entry.container.updateListView();
Entry.requestUpdate = true;
return new Entry.State(Entry.container,
Entry.container.moveElement,
endIndex, startIndex, true);
Expand Down
16 changes: 13 additions & 3 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Entry.Engine = function() {
this.isUpdating = true;
this.speeds = [1, 15, 30, 45, 60];

this._mouseMoved = false;;

if (Entry.keyPressed)
Entry.keyPressed.attach(this, this.captureKeyEvent);
Expand All @@ -32,8 +33,8 @@ Entry.Engine = function() {
});
if (Entry.type != 'phone') {
Entry.addEventListener('stageMouseMove', function(e){
Entry.engine.updateMouseView();
});
this._mouseMoved = true;
}.bind(this));
Entry.addEventListener('stageMouseOut', function(e){
Entry.engine.hideMouseView();
});
Expand All @@ -57,6 +58,13 @@ Entry.Engine = function() {
if(arrows.indexOf(code) > -1)
e.preventDefault();
}

setInterval(function() {
if (this._mouseMoved) {
this.updateMouseView();
this._mouseMoved = false;
}
}.bind(this), 100)
};

/**
Expand Down Expand Up @@ -645,7 +653,7 @@ Entry.Engine.prototype.raiseKeyEvent = function(entity, param) {
*/
Entry.Engine.prototype.updateMouseView = function() {
var coordinate = Entry.stage.mouseCoordinate;
this.mouseView.innerHTML = 'X : ' + coordinate.x + ', Y : ' + coordinate.y;
this.mouseView.textContent = 'X : ' + coordinate.x + ', Y : ' + coordinate.y;
this.mouseView.removeClass('entryRemove');
};

Expand Down Expand Up @@ -675,6 +683,7 @@ Entry.Engine.prototype.toggleFullscreen = function() {
this.popup.remove();
this.popup = null;
}
Entry.windowResized.notify();
};

Entry.Engine.prototype.exitFullScreen = function() {
Expand All @@ -685,6 +694,7 @@ Entry.Engine.prototype.exitFullScreen = function() {
Entry.engine.footerView_.removeClass('entryRemove');
Entry.engine.headerView_.removeClass('entryRemove');
}
Entry.windowResized.notify();
};


Expand Down
25 changes: 24 additions & 1 deletion src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Entry.EntityObject.prototype.setX = function(x) {
if (!this.isClone)
this.parent.updateCoordinateView();
this.updateDialog();
Entry.requestUpdate = true;
};

/**
Expand All @@ -204,6 +205,7 @@ Entry.EntityObject.prototype.setY = function(y) {
if (!this.isClone)
this.parent.updateCoordinateView();
this.updateDialog();
Entry.requestUpdate = true;
};

/**
Expand Down Expand Up @@ -246,6 +248,7 @@ Entry.EntityObject.prototype.setDirection = function(direction, flippable) {
if (!this.isClone)
this.parent.updateRotationView();
Entry.dispatchEvent('updateObject');
Entry.requestUpdate = true;
};

/**
Expand All @@ -263,6 +266,7 @@ Entry.EntityObject.prototype.setRotation = function(rotation) {
if (!this.isClone)
this.parent.updateRotationView();
Entry.dispatchEvent('updateObject');
Entry.requestUpdate = true;
};

/**
Expand All @@ -283,7 +287,7 @@ Entry.EntityObject.prototype.setRegX = function(regX) {
/** @type {number} */
this.regX = regX;
this.object.regX = this.regX;

Entry.requestUpdate = true;
};

/**
Expand All @@ -304,6 +308,7 @@ Entry.EntityObject.prototype.setRegY = function(regY) {
/** @type {number} */
this.regY = regY;
this.object.regY = this.regY;
Entry.requestUpdate = true;
};

/**
Expand All @@ -324,6 +329,7 @@ Entry.EntityObject.prototype.setScaleX = function(scaleX) {
this.object.scaleX = this.scaleX;
this.parent.updateCoordinateView();
this.updateDialog();
Entry.requestUpdate = true;
};

/**
Expand All @@ -344,6 +350,7 @@ Entry.EntityObject.prototype.setScaleY = function(scaleY) {
this.object.scaleY = this.scaleY;
this.parent.updateCoordinateView();
this.updateDialog();
Entry.requestUpdate = true;
};

/**
Expand All @@ -366,6 +373,7 @@ Entry.EntityObject.prototype.setSize = function(size) {
this.setScaleY(this.getScaleY() * scale);
if (!this.isClone)
this.parent.updateCoordinateView();
Entry.requestUpdate = true;
};

/**
Expand All @@ -388,6 +396,7 @@ Entry.EntityObject.prototype.setWidth = function(width) {
this.textObject.lineWidth = this.width;
this.updateDialog();
this.updateBG();
Entry.requestUpdate = true;
};

/**
Expand All @@ -411,6 +420,7 @@ Entry.EntityObject.prototype.setHeight = function(height) {
}
this.updateDialog();
this.updateBG();
Entry.requestUpdate = true;
};

/**
Expand All @@ -432,6 +442,7 @@ Entry.EntityObject.prototype.setColour = function(colour) {
this.colour = colour;
if (this.textObject)
this.textObject.color = this.colour;
Entry.requestUpdate = true;
};

/**
Expand All @@ -453,6 +464,7 @@ Entry.EntityObject.prototype.setBGColour = function(colour) {
this.bgColor = colour;
this.updateBG();
//this.object.color = this.colour;
Entry.requestUpdate = true;
};

/**
Expand All @@ -468,6 +480,7 @@ Entry.EntityObject.prototype.setUnderLine = function(underLine) {
underLine = false;
this.underLine = underLine;
this.textObject.underLine = underLine;
Entry.requestUpdate = true;
};

Entry.EntityObject.prototype.getUnderLine = function() {
Expand All @@ -479,6 +492,7 @@ Entry.EntityObject.prototype.setStrike = function(strike) {
strike = false;
this.strike = strike;
this.textObject.strike = strike;
Entry.requestUpdate = true;
};

Entry.EntityObject.prototype.getStrike = function() {
Expand Down Expand Up @@ -543,6 +557,7 @@ Entry.EntityObject.prototype.syncFont = function() {
this.setWidth(this.textObject.getMeasuredWidth());
}
Entry.stage.updateObject();
Entry.requestUpdate = true;
};

/**
Expand Down Expand Up @@ -588,6 +603,7 @@ Entry.EntityObject.prototype.setFontSize = function(fontSize) {
*/
Entry.EntityObject.prototype.setFontBold = function(isFontBold) {
this.fontBold = isFontBold;
Entry.requestUpdate = true;
};

/**
Expand All @@ -604,6 +620,7 @@ Entry.EntityObject.prototype.toggleFontBold = function() {
*/
Entry.EntityObject.prototype.setFontItalic = function(isFontItalic) {
this.fontItalic = isFontItalic;
Entry.requestUpdate = true;
};

/**
Expand Down Expand Up @@ -750,6 +767,7 @@ Entry.EntityObject.prototype.setVisible = function(visible) {
this.object.visible = this.visible;
if (this.dialog)
this.syncDialogVisible();
Entry.requestUpdate = true;
return this.visible;
};

Expand Down Expand Up @@ -806,6 +824,7 @@ Entry.EntityObject.prototype.setImage = function(pictureModel) {
thisPointer.object.cache(0,0,thisPointer.getWidth(),thisPointer.getHeight());
//Entry.dispatchEvent('updateObject');
thisPointer = null;
Entry.requestUpdate = true;
};
} else {
Entry.image = image;
Expand Down Expand Up @@ -905,6 +924,7 @@ Entry.EntityObject.prototype.applyFilter = function() {
}
return true;
}
Entry.requestUpdate = true;
};


Expand All @@ -919,6 +939,7 @@ Entry.EntityObject.prototype.resetFilter = function() {
this.object.alpha = this.effect.alpha;

this.object.cache(0,0,this.getWidth(),this.getHeight());
Entry.requestUpdate = true;
};

/**
Expand All @@ -945,6 +966,7 @@ Entry.EntityObject.prototype.loadSnapshot = function() {
this.syncModel_(this.snapshot_);
if (this.parent.objectType == 'sprite')
this.setImage(this.parent.getPicture());
Entry.requestUpdate = true;
};

/**
Expand Down Expand Up @@ -1005,6 +1027,7 @@ Entry.EntityObject.prototype.toJSON = function() {
*/
Entry.EntityObject.prototype.setInitialEffectValue = function () {
this.effect = this.getInitialEffectValue();
Entry.requestUpdate = true;
};

/*
Expand Down
1 change: 1 addition & 0 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Entry.EntryObject = function(model) {
image.onload = function(e) {
Entry.container.cachePicture(picture.id, image);
Entry.Loader.removeQueue();
Entry.requestUpdate = true;
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,10 @@ Entry.Playground.prototype.flushPlayground = function () {

Entry.Playground.prototype.refreshPlayground = function () {
if (Entry.playground && Entry.playground.view_) {
this.injectPicture();
this.injectSound();
if (this.getViewMode() === "picture")
this.injectPicture();
if (this.getViewMode() === "sound")
this.injectSound();
}
};

Expand Down
1 change: 1 addition & 0 deletions src/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Entry.Scene.prototype.selectScene = function(scene) {
Entry.stage.sortZorder();
Entry.container.updateListView();
this.updateView();
Entry.requestUpdate = true;
};

/**
Expand Down
Loading

0 comments on commit e1204cd

Please sign in to comment.