From de6baf4632ac20cd469badfec1be8676e80e1278 Mon Sep 17 00:00:00 2001 From: Tarek Sherif Date: Tue, 24 May 2016 16:31:04 -0400 Subject: [PATCH] Allow compilation to be paused --- src/core/engine.js | 23 +++++++++++++++++++++++ src/core/scene/scene.js | 16 +++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/core/engine.js b/src/core/engine.js index fadce5cc..a8311426 100644 --- a/src/core/engine.js +++ b/src/core/engine.js @@ -64,6 +64,11 @@ var SceneJS_Engine = function (json, options) { */ this._sceneBranchesDirty = false; + /** + * Flag to prevent engine from re-compiling the scene graph + */ + this._compilationPaused = false; + /** * List of nodes scheduled for destruction by #destroyNode * Destructions are done in a batch at the end of each render so as not to disrupt the render. @@ -582,10 +587,28 @@ SceneJS_Engine.prototype._needCompile = function () { || this.sceneDirty); // Whole scene needs recompilation }; +/** + * Prevent engine from compiling the scene graph + */ +SceneJS_Engine.prototype.pauseCompilation = function () { + this._compilationPaused = true; +}; + +/** + * Resume compilation of scene graph + */ +SceneJS_Engine.prototype.resumeCompilation = function () { + this._compilationPaused = false; +}; + /** * Performs any pending scene compilations or display rebuilds */ SceneJS_Engine.prototype.compile = function () { + if (this._compilationPaused) { + return; + } + if (this._sceneBranchesDirty || this.sceneDirty) { // Need scene graph compilation this._sceneBranchesDirty = false; SceneJS_events.fireEvent(SceneJS_events.SCENE_COMPILING, { // Notify compilation support start diff --git a/src/core/scene/scene.js b/src/core/scene/scene.js index d087760f..38954ce5 100755 --- a/src/core/scene/scene.js +++ b/src/core/scene/scene.js @@ -105,10 +105,24 @@ SceneJS.Scene.prototype.renderFrame = function (params) { return this._engine.renderFrame(params); }; +/** + * Prevent re-compilation of scene graph. + */ +SceneJS.Scene.prototype.pauseCompilation = function () { + return this._engine.pauseCompilation(); +}; + +/** + * Resume re-compilation of scene graph. + */ +SceneJS.Scene.prototype.resumeCompilation = function () { + return this._engine.resumeCompilation(); +}; + /** * Force compilation of the scene graph. */ -SceneJS.Scene.prototype.compile = function (params) { +SceneJS.Scene.prototype.compile = function () { return this._engine.compile(); };