From fb0a659c9ca3479fd6799325498b11f074689936 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Mon, 2 Apr 2012 14:57:31 -0700 Subject: -Namespaced all RDGE javascript. -Removed the following unused files from the build script /core/script/fx/blur.js /core/script/fx/ssao.js /core/script/animation.js - Fully removed the following from the build and from source control as they are unused or no longer needed /core/script/util/dbgpanel.js /core/script/util/fpsTracker.js /core/script/util/statTracker.js /core/script/input.js /core/script/TextureManager.js /core/script/ubershader.js --- js/helper-classes/RDGE/src/core/script/engine.js | 513 ++++++++++------------- 1 file changed, 223 insertions(+), 290 deletions(-) (limited to 'js/helper-classes/RDGE/src/core/script/engine.js') diff --git a/js/helper-classes/RDGE/src/core/script/engine.js b/js/helper-classes/RDGE/src/core/script/engine.js index 5bc9305c..0975fcef 100755 --- a/js/helper-classes/RDGE/src/core/script/engine.js +++ b/js/helper-classes/RDGE/src/core/script/engine.js @@ -4,91 +4,79 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ +var RDGE = RDGE || {}; /* * Manage state instances */ -stateManager = function() -{ - // a stack of states - this.stateStack = []; - - // number of states on the stack - this.stateTop = undefined; - +RDGE.stateManager = function () { + // a stack of states + this.stateStack = []; + + // number of states on the stack + this.stateTop = undefined; + // the states of the context - this.RDGEInitState = null; - this.RDGERunState = null; - - this.currentState = function() - { - if(this.stateTop != undefined) - return this.stateStack[this.stateTop]; - - return null; - } - - /* - * Push new IRuntime state - engine executes the new state - */ - this.PushState = function(state, flags) - { - if(state!=null && typeof state.Init == 'function') - { - if(this.stateTop != undefined) - this.stateStack[this.stateTop].LeaveState(); - - if(flags == undefined || flags != "noInit") - state.Init(); - - this.stateTop = this.stateStack.push(state) - 1; - } - } - - /* - * Remove IRuntime state from stack, engine executes previous state - */ - this.PopState = function() - { - state = this.stateStack.pop(); - if(state!=null) - { - state.Shutdown(); - } - - this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; - - if(this.stateStack[this.stateTop]) - { - this.stateStack[this.stateTop].ReInit(); - } - } - - /* - * Remove all states from the stack - */ - this.PopAll = function() - { - while(this.stateStack[this.stateTop] != null) - { - this.PopState(); - } - } - - this.tick = function(dt) - { - if(this.stateStack[this.stateTop]!=null) - { - this.stateStack[this.stateTop].Update(dt); - this.stateStack[this.stateTop].Resize(); - this.stateStack[this.stateTop].Draw(); - } - } -} - -g_enableBenchmarks = true; -function Engine() -{ + this.RDGEInitState = null; + this.RDGERunState = null; + + this.currentState = function () { + if (this.stateTop != undefined) + return this.stateStack[this.stateTop]; + + return null; + }; + + /* + * Push new IRuntime state - engine executes the new state + */ + this.PushState = function (state, flags) { + if (state != null && typeof state.Init == 'function') { + if (this.stateTop != undefined) + this.stateStack[this.stateTop].LeaveState(); + + if (flags == undefined || flags != "noInit") + state.Init(); + + this.stateTop = this.stateStack.push(state) - 1; + } + }; + + /* + * Remove IRuntime state from stack, engine executes previous state + */ + this.PopState = function () { + state = this.stateStack.pop(); + if (state != null) { + state.Shutdown(); + } + + this.stateTop = this.stateTop > 0 ? this.stateTop - 1 : 0; + + if (this.stateStack[this.stateTop]) { + this.stateStack[this.stateTop].ReInit(); + } + }; + + /* + * Remove all states from the stack + */ + this.PopAll = function () { + while (this.stateStack[this.stateTop] != null) { + this.PopState(); + } + }; + + this.tick = function (dt) { + if (this.stateStack[this.stateTop] != null) { + this.stateStack[this.stateTop].Update(dt); + this.stateStack[this.stateTop].Resize(); + this.stateStack[this.stateTop].Draw(); + } + }; +}; + +RDGE.Engine = function() { // map of scene graphs to names this.sceneMap = []; @@ -105,8 +93,6 @@ function Engine() clearColor = [0.0, 0.0, 0.0, 0.0]; - panelObjectManager = new objectManager(); - this.initializeComplete = false; this.RDGECanvas = null; @@ -130,43 +116,39 @@ function Engine() * regex object to verify runtime object is not some sort of exploit */ invalidObj = new RegExp("([()]|function)"); - - isValidObj = function( name ) - { - // do a quick test make sure user isn't trying to execute a function - if(invalidObj.test(name)) - { - window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); - return false; - } - - return true; - } + + isValidObj = function (name) { + // do a quick test make sure user isn't trying to execute a function + if (invalidObj.test(name)) { + window.console.error("invalid object name passed to RDGE, " + name + " - looks like a function"); + return false; + } + + return true; + }; /* * The context definition - every context shares these parameters */ - contextDef = function() - { - this.id = null; + contextDef = function () { + this.id = null; this.renderer = null; this.ctxStateManager = null; this.startUpState = null; this.sceneGraphMap = []; this.currentScene = null; - this.getScene = function() - { - return this.sceneGraphMap[this.currentScene]; + this.getScene = function () { + return this.sceneGraphMap[this.currentScene]; } - this.debug = + this.debug = { - 'frameCounter' : 0, - 'mat4CallCount': 0 + 'frameCounter': 0, + 'mat4CallCount': 0 } - } + }; // maintains the contexts - contextManager = new objectManager(); + contextManager = new RDGE.objectManager(); this.ctxMan = contextManager; // the context currently being updated @@ -174,219 +156,174 @@ function Engine() contextManager._addObject = contextManager.addObject; contextManager.contextMap = {}; - - contextManager.addObject = function( context ) - { - this.contextMap[context.id] = context; - return this._addObject(context); - } - - contextManager.start = function() - { - var len = this.objects.length; - for(var i = 0; i < len; ++i) - { - // set the current context - contextManager.currentCtx = this.objects[i]; - this.objects[i].ctxStateManager.PushState(this.objects[i].startUpState); - } - } - - contextManager.forEach = function(cb) - { - var len = this.objects.length; - for(var i = 0; i < len; ++i) - { - cb(this.objects[i]); - } - } - - this.getContext = function( optCanvasID ) - { - if(!optCanvasID) - { - return contextManager.currentCtx; - } - else - { - return contextManager.contextMap[optCanvasID]; - } - } + + contextManager.addObject = function (context) { + this.contextMap[context.id] = context; + return this._addObject(context); + }; + + contextManager.start = function () { + var len = this.objects.length; + for (var i = 0; i < len; ++i) { + // set the current context + contextManager.currentCtx = this.objects[i]; + this.objects[i].ctxStateManager.PushState(this.objects[i].startUpState); + } + }; + + contextManager.forEach = function (cb) { + var len = this.objects.length; + for (var i = 0; i < len; ++i) { + cb(this.objects[i]); + } + }; + + this.getContext = function (optCanvasID) { + if (!optCanvasID) { + return contextManager.currentCtx; + } + else { + return contextManager.contextMap[optCanvasID]; + } + }; /* * give the contextID (canvas id) of the context to set */ - this.setContext = function( contextID ) - { + this.setContext = function (contextID) { contextManager.currentCtx = contextManager.contextMap[contextID]; - } - - this.tickContext = function(contextID) { - var savedCtx = contextManager.currentCtx; - contextManager.currentCtx = contextManager.contextMap[contextID]; - this.objects[i].ctxStateManager.tick(dt); - contextManager.currentCtx = savedCtx; - - } - -} + }; + + this.tickContext = function (contextID) { + var savedCtx = contextManager.currentCtx; + contextManager.currentCtx = contextManager.contextMap[contextID]; + this.objects[i].ctxStateManager.tick(dt); + contextManager.currentCtx = savedCtx; + + }; +}; /* * Initialize the RDGE web engine */ -Engine.prototype.init = function(userInitState, userRunState, canvasObject) -{ +RDGE.Engine.prototype.init = function (userInitState, userRunState, canvasObject) { this.GlInit(canvasObject); - globalParamFuncSet = function(param) - { - this.data = param.data; - this.type =param.type; - - this.set = function(v) - { - var len = this.data ? this.data.length : 0; - for(var i=0;i