mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Added documentation in CachedFrameProcessor
This commit is contained in:
parent
fa626532ba
commit
fa4e96e7e5
@ -208,7 +208,6 @@
|
||||
|
||||
ns.PreviewFilmController.prototype.getCanvasForFrame = function (frame) {
|
||||
var canvas = this.cachedFrameProcessor.get(frame, this.zoom);
|
||||
canvas.classList.add('tile-view', 'canvas');
|
||||
return canvas;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.model.frame');
|
||||
|
||||
var DEFAULT_RESET_INTERVAL = 10 * 60 *1000;
|
||||
|
||||
var DEFAULT_CLEAR_INTERVAL = 10 * 60 *1000;
|
||||
|
||||
var DEFAULT_FRAME_PROCESSOR = function (frame) {
|
||||
return pskl.utils.FrameUtils.toImage(frame);
|
||||
@ -13,7 +14,7 @@
|
||||
|
||||
ns.CachedFrameProcessor = function (cacheResetInterval) {
|
||||
this.cache_ = {};
|
||||
this.cacheResetInterval = cacheResetInterval || DEFAULT_RESET_INTERVAL;
|
||||
this.cacheResetInterval = cacheResetInterval || DEFAULT_CLEAR_INTERVAL;
|
||||
this.frameProcessor = DEFAULT_FRAME_PROCESSOR;
|
||||
this.outputCloner = DEFAULT_OUTPUT_CLONER;
|
||||
|
||||
@ -24,14 +25,32 @@
|
||||
this.cache_ = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the processor function that will be called when there is a cache miss
|
||||
* Function with 1 argument : pskl.model.Frame
|
||||
* @param {Function} frameProcessor
|
||||
*/
|
||||
ns.CachedFrameProcessor.prototype.setFrameProcessor = function (frameProcessor) {
|
||||
this.frameProcessor = frameProcessor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the cloner that will be called when there is a miss on the 1st level cache
|
||||
* but a hit on the 2nd level cache.
|
||||
* Function with 2 arguments : cached value, frame
|
||||
* @param {Function} outputCloner
|
||||
*/
|
||||
ns.CachedFrameProcessor.prototype.setOutputCloner = function (outputCloner) {
|
||||
this.outputCloner = outputCloner;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the processed frame from the cache, in the (optional) namespace
|
||||
* If the first level cache is empty, attempt to clone it from 2nd level cache. If second level cache is empty process the frame.
|
||||
* @param {pskl.model.Frame} frame
|
||||
* @param {String} namespace
|
||||
* @return {Object} the processed frame
|
||||
*/
|
||||
ns.CachedFrameProcessor.prototype.get = function (frame, namespace) {
|
||||
var processedFrame = null;
|
||||
namespace = namespace || DEFAULT_NAMESPACE;
|
||||
@ -48,7 +67,7 @@
|
||||
} else {
|
||||
var frameAsString = JSON.stringify(frame.getPixels());
|
||||
if (this.cache_[frameAsString]) {
|
||||
processedFrame = this.outputCloner(this.cache_[frameAsString]);
|
||||
processedFrame = this.outputCloner(this.cache_[frameAsString], frame);
|
||||
} else {
|
||||
processedFrame = this.frameProcessor(frame);
|
||||
this.cache_[frameAsString] = processedFrame;
|
||||
|
Loading…
Reference in New Issue
Block a user