Scope renderer to instance

This allows usage without global scope to attach a renderer to the VM. It also provides the ability to have multiple VMs/renderers to be used at once.
This commit is contained in:
Ray Schamp 2016-09-20 02:42:05 -04:00
parent c02ee88d02
commit 499ba5235c
5 changed files with 22 additions and 16 deletions
src/engine

View file

@ -19,13 +19,20 @@ var defaultBlockPackages = {
/**
* Manages targets, scripts, and the sequencer.
* @param {!RenderWebGL} renderer Renderer for the VM
*/
function Runtime () {
function Runtime (renderer) {
// Bind event emitter
EventEmitter.call(this);
// State for the runtime
/**
* Renderer
* @type {!RenderWebGL}
*/
this.renderer = renderer;
/**
* Target management and storage.
* @type {Array.<!Target>}
@ -573,8 +580,8 @@ Runtime.prototype.getTargetForStage = function () {
* Handle an animation frame from the main thread.
*/
Runtime.prototype.animationFrame = function () {
if (self.renderer) {
self.renderer.draw();
if (this.renderer) {
this.renderer.draw();
}
};