/* * GDevelop JS Platform * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved. * This project is released under the MIT License. */ /** * The runtimeScene object represents a scene being played and rendered in the browser in a canvas. * * @class RuntimeScene * @memberof gdjs * @param {gdjs.RuntimeGame} runtimeGame The game associated to this scene. */ gdjs.RuntimeScene = function(runtimeGame) { this._eventsFunction = null; this._instances = new Hashtable(); //Contains the instances living on the scene this._instancesCache = new Hashtable(); //Used to recycle destroyed instance instead of creating new ones. this._objects = new Hashtable(); //Contains the objects data stored in the project this._objectsCtor = new Hashtable(); this._layers = new Hashtable(); this._initialBehaviorSharedData = new Hashtable(); this._renderer = new gdjs.RuntimeSceneRenderer(this, runtimeGame ? runtimeGame.getRenderer() : null); this._variables = new gdjs.VariablesContainer(); this._runtimeGame = runtimeGame; this._lastId = 0; this._name = ""; this._timeManager = new gdjs.TimeManager(Date.now()); this._gameStopRequested = false; this._requestedScene = ""; this._isLoaded = false; // True if loadFromScene was called and the scene is being played. this._isJustResumed = false; // True in the first frame after resuming the paused scene /** @type gdjs.RuntimeObject[] */ this._allInstancesList = []; //An array used to create a list of all instance when necessary ( see _constructListOfAllInstances ) /** @type gdjs.RuntimeObject[] */ this._instancesRemoved = []; //The instances removed from the scene and waiting to be sent to the cache. /** @type gdjs.Profiler */ this._profiler = null; // Set to `new gdjs.Profiler()` to have profiling done on the scene. this._onProfilerStopped = null; // The callback function to call when the profiler is stopped. this.onGameResolutionResized(); }; /** * Should be called when the canvas where the scene is rendered has been resized. * See gdjs.RuntimeGame.startGameLoop in particular. * @memberof gdjs.RuntimeScene */ gdjs.RuntimeScene.prototype.onGameResolutionResized = function() { for(var name in this._layers.items) { if (this._layers.items.hasOwnProperty(name)) { /** @type gdjs.Layer */ var theLayer = this._layers.items[name]; theLayer.onGameResolutionResized(); } } this._renderer.onGameResolutionResized(); }; /** * Load the runtime scene from the given scene. * @param {Object} sceneData An object containing the scene data. * @see gdjs.RuntimeGame#getSceneData */ gdjs.RuntimeScene.prototype.loadFromScene = function(sceneData) { if ( sceneData === undefined ) { console.error("loadFromScene was called without a scene"); return; } if ( this._isLoaded ) this.unloadScene(); //Setup main properties if (this._runtimeGame) this._runtimeGame.getRenderer().setWindowTitle(sceneData.title); this._name = sceneData.name; this.setBackgroundColor(parseInt(sceneData.r, 10), parseInt(sceneData.v, 10), parseInt(sceneData.b, 10)); //Load layers for(var i = 0, len = sceneData.layers.length;i cameraCoords[2] || aabb.min[1] > cameraCoords[3] || aabb.max[0] < cameraCoords[0] || aabb.max[1] < cameraCoords[1])) { rendererObject.visible = false; } else { rendererObject.visible = true; } } } } }; /** * Empty the list of the removed objects:
* When an object is removed from the scene, it is still kept in the _instancesRemoved member * of the RuntimeScene.
* This method should be called regularly (after events or behaviors steps) so as to clear this list * and allows the removed objects to be cached (or destroyed if the cache is full).
* The removed objects could not be sent directly to the cache, as events may still be using them after * removing them from the scene for example. * * @private */ gdjs.RuntimeScene.prototype._cacheOrClearRemovedInstances = function() { for(var k =0, lenk=this._instancesRemoved.length;k