Throttle frameslist and preview rendering

This commit is contained in:
Dávid Szabó 2016-08-24 23:09:24 +02:00 committed by Julian Descottes
parent f5c98cf0b3
commit 6ee23e22df
2 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,8 @@
(function () {
var ns = $.namespace('pskl.controller');
var RENDER_MINIMUM_DELAY = 1000;
var ACTION = {
SELECT : 'select',
CLONE : 'clone',
@ -13,6 +15,7 @@
this.container = container;
this.refreshZoom_();
this.lastRenderTime = 0;
this.redrawFlag = true;
this.cachedFrameProcessor = new pskl.model.frame.CachedFrameProcessor();
@ -41,9 +44,10 @@
};
ns.FramesListController.prototype.render = function () {
if (this.redrawFlag) {
if (this.redrawFlag && (Date.now() - this.lastRenderTime > RENDER_MINIMUM_DELAY)) {
this.createPreviews_();
this.redrawFlag = false;
this.lastRenderTime = Date.now();
}
};

View File

@ -3,6 +3,7 @@
// Preview is a square of PREVIEW_SIZE x PREVIEW_SIZE
var PREVIEW_SIZE = 200;
var RENDER_MINIMUM_DELAY = 1000;
var ONION_SKIN_SHORTCUT = 'alt+O';
var ORIGINAL_SIZE_SHORTCUT = 'alt+1';
@ -17,6 +18,7 @@
this.onionSkinShortcut = pskl.service.keyboard.Shortcuts.MISC.ONION_SKIN;
this.originalSizeShortcut = pskl.service.keyboard.Shortcuts.MISC.X1_PREVIEW;
this.lastRenderTime = 0;
this.renderFlag = true;
/**
@ -173,6 +175,7 @@
var frame = pskl.utils.LayerUtils.mergeFrameAt(this.piskelController.getLayers(), index);
this.renderer.render(frame);
this.renderFlag = false;
this.lastRenderTime = Date.now();
this.popupPreviewController.render(frame);
}
@ -241,7 +244,7 @@
};
ns.PreviewController.prototype.shouldRender_ = function () {
return this.renderFlag || this.popupPreviewController.renderFlag;
return (this.renderFlag || this.popupPreviewController.renderFlag) && (Date.now() - this.lastRenderTime > RENDER_MINIMUM_DELAY);
};
ns.PreviewController.prototype.toggleOnionSkin_ = function () {