<commit_before>/**
 *@class Root node of a SceneJS scene graph.
 *@extends SceneJS.Node
 */
SceneJS.Scene = SceneJS.createNodeType("scene");

// @private
SceneJS.Scene.prototype._init = function(params) {
    if (params.canvasId) {
        this._canvasId = document.getElementById(params.canvasId) ? params.canvasId : SceneJS.Scene.DEFAULT_CANVAS_ID;
    } else {
        this._canvasId = SceneJS.Scene.DEFAULT_CANVAS_ID;
    }
    this._loggingElementId = params.loggingElementId;
    this.setLayers(params.layers);
    this._destroyed = false;
    this._scene = this;
};

/** ID of canvas SceneJS looks for when {@link SceneJS.Scene} node does not supply one
 */
SceneJS.Scene.DEFAULT_CANVAS_ID = "_scenejs-default-canvas";

/** ID ("_scenejs-default-logging") of default element to which {@link SceneJS.Scene} node will log to, if found.
 */
SceneJS.Scene.DEFAULT_LOGGING_ELEMENT_ID = "_scenejs-default-logging";

/** Returns the ID of the canvas element that this scene is to bind to. When no canvasId was configured, it will be the
 * the default ID of "_scenejs-default-canvas".
 */
SceneJS.Scene.prototype.getCanvasId = function() {
    return this._canvasId;
};

/** Returns the Z-buffer depth in bits of the webgl context that this scene is to bound to.
 */
SceneJS.Scene.prototype.getZBufferDepth = function() {
    var context;
    if (this._created) {
        context = SceneJS_sceneModule.getSceneContext(this._attr.id);
        return context.getParameter(context.DEPTH_BITS)
    }
    return context;
};

/**
 Sets which layers are included in the each render of the scene, along with their priorities (default priority is 0)
 */
SceneJS.Scene.prototype.setLayers = function(layers) {
    this._layers = layers || {};
};

/**
 Gets which layers are included in the each render of this scene, along with their priorities (default priority is 0)
 */
SceneJS.Scene.prototype.getLayers = function() {
    return this._layers;
};

window.requestAnimFrame = (function() {
    return  window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.oRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function(/* function */ callback, /* DOMElement */ element) {
                window.setTimeout(callback, 1000 / 60);
            };
})();

/**
 * Starts the scene rendering repeatedly in a loop.
 */
SceneJS.Scene.prototype.start = function(cfg) {
    if (this._destroyed) {
        throw SceneJS_errorModule.fatalError(
                SceneJS.errors.NODE_ILLEGAL_STATE,
                "Attempted start on Scene that has been destroyed");
    }

    /*
     * Lazy scene creation
     */
    if (!this._created) {
        SceneJS_sceneModule.createScene(this, {
            canvasId: this._canvasId,
            loggingElementId: this._loggingElementId,
            sceneId: this._attr.id
        });
        this._created = true;
    }

    if (!this._running || this._paused) {
        cfg = cfg || {};

        this._running = true;
        this._paused = false;

        var self = this;
        var fnName = "__scenejs_compileScene" + this._attr.id;

        /* Render loop
         */
        var sleeping = false;

        SceneJS_compileModule.nodeUpdated(this, "start");

        window[fnName] = function() {

            if (self._running && !self._paused) { // idleFunc may have stopped render loop

                if (cfg.idleFunc) {
                    cfg.idleFunc();
                }

                if (SceneJS_compileModule.scheduleCompilations(self._attr.id)) {

                    self._compileWithEvents();

                    sleeping = false;

                } else {
                    if (!sleeping && cfg.sleepFunc) {
                        cfg.sleepFunc();
                    }
                    sleeping = true;
                }
            }
        };

        if (cfg.requestAnimationFrame === true) {
            (function animloop() {
                if (window[fnName]) {
                    window[fnName]();
                    requestAnimFrame(animloop);
                }
            })();
        } else {
            this._pInterval = setInterval("window['" + fnName + "']()", 1000.0 / (cfg.fps || 60));
        }

        this._startCfg = cfg;

        /* Push one frame immediately        
         */
        window[fnName]();
    }
};

/** Pauses/unpauses current render loop that was started with {@link #start}. After this, {@link #isRunning} will return false.
 */
SceneJS.Scene.prototype.pause = function(doPause) {
    if (this._running && this._created) {
        this._paused = doPause;
    }
};

/** Returns true if the scene is currently rendering repeatedly in a loop after being started with {@link #start}.<commit_msg>Fall back on setTimeout instead of setInterval - https://github.com/xeolabs/scenejs/issues/103<commit_after>/**
 *@class Root node of a SceneJS scene graph.
 *@extends SceneJS.Node
 */
SceneJS.Scene = SceneJS.createNodeType("scene");

// @private
SceneJS.Scene.prototype._init = function(params) {
    if (params.canvasId) {
        this._canvasId = document.getElementById(params.canvasId) ? params.canvasId : SceneJS.Scene.DEFAULT_CANVAS_ID;
    } else {
        this._canvasId = SceneJS.Scene.DEFAULT_CANVAS_ID;
    }
    this._loggingElementId = params.loggingElementId;
    this.setLayers(params.layers);
    this._destroyed = false;
    this._scene = this;
};

/** ID of canvas SceneJS looks for when {@link SceneJS.Scene} node does not supply one
 */
SceneJS.Scene.DEFAULT_CANVAS_ID = "_scenejs-default-canvas";

/** ID ("_scenejs-default-logging") of default element to which {@link SceneJS.Scene} node will log to, if found.
 */
SceneJS.Scene.DEFAULT_LOGGING_ELEMENT_ID = "_scenejs-default-logging";

/** Returns the ID of the canvas element that this scene is to bind to. When no canvasId was configured, it will be the
 * the default ID of "_scenejs-default-canvas".
 */
SceneJS.Scene.prototype.getCanvasId = function() {
    return this._canvasId;
};

/** Returns the Z-buffer depth in bits of the webgl context that this scene is to bound to.
 */
SceneJS.Scene.prototype.getZBufferDepth = function() {
    var context;
    if (this._created) {
        context = SceneJS_sceneModule.getSceneContext(this._attr.id);
        return context.getParameter(context.DEPTH_BITS)
    }
    return context;
};

/**
 Sets which layers are included in the each render of the scene, along with their priorities (default priority is 0)
 */
SceneJS.Scene.prototype.setLayers = function(layers) {
    this._layers = layers || {};
};

/**
 Gets which layers are included in the each render of this scene, along with their priorities (default priority is 0)
 */
SceneJS.Scene.prototype.getLayers = function() {
    return this._layers;
};

window.requestAnimFrame = (function() {
    return  window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.oRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function(/* function */ callback, /* DOMElement */ element) {
                window.setTimeout(callback, 1000 / 60);
            };
})();

/**
 * Starts the scene rendering repeatedly in a loop.
 */
SceneJS.Scene.prototype.start = function(cfg) {
    if (this._destroyed) {
        throw SceneJS_errorModule.fatalError(
                SceneJS.errors.NODE_ILLEGAL_STATE,
                "Attempted start on Scene that has been destroyed");
    }

    /*
     * Lazy scene creation
     */
    if (!this._created) {
        SceneJS_sceneModule.createScene(this, {
            canvasId: this._canvasId,
            loggingElementId: this._loggingElementId,
            sceneId: this._attr.id
        });
        this._created = true;
    }

    if (!this._running || this._paused) {
        cfg = cfg || {};

        this._running = true;
        this._paused = false;

        var self = this;
        var fnName = "__scenejs_compileScene" + this._attr.id;

        /* Render loop
         */
        var sleeping = false;

        SceneJS_compileModule.nodeUpdated(this, "start");

        window[fnName] = function() {

            if (self._running && !self._paused) { // idleFunc may have stopped render loop

                if (cfg.idleFunc) {
                    cfg.idleFunc();
                }

                if (SceneJS_compileModule.scheduleCompilations(self._attr.id)) {

                    self._compileWithEvents();

                    sleeping = false;

                } else {
                    if (!sleeping && cfg.sleepFunc) {
                        cfg.sleepFunc();
                    }
                    sleeping = true;
                }
            }

            if (!cfg.requestAnimationFrame) {
               window.setTimeout(window[fnName], 1000 / 60);
            }
        };

        if (cfg.requestAnimationFrame === true) {
            (function animloop() {
                if (window[fnName]) {
                    window[fnName]();
                    requestAnimFrame(animloop);
                }
            })();
        } else {
            window[fnName]();
        }

        this._startCfg = cfg;

        /* Push one frame immediately        
         */
        window[fnName]();
    }
};

/** Pauses/unpauses current render loop that was started with {@link #start}. After this, {@link #isRunning} will return false.
 */
SceneJS.Scene.prototype.pause = function(doPause) {
    if (this._running && this._created) {
        this._paused = doPause;
    }
};

/** Returns true if the scene is currently rendering repeatedly in a loop after being started with {@link #start}.
{'fraction_non_alphanumeric': 0.11075819672131147, 'fraction_numerical': 0.003278688524590164, 'mean_word_length': 2.157877709479133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3278557', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2637, 'n_words': 688}