Skip to content
Browse files

Reformatted code in project

Added "use strict;" to as many files as possible
Cleaning up tutorials to only refer to engine runtime
  • Loading branch information...
1 parent f9fc197 commit 0e0c7d264213332c371f123983b232d7f93ba75b @bfattori committed
Sorry, we could not display the entire diff because it was too big.
View
2 build.xml
@@ -113,7 +113,7 @@
<fileset dir="${engine.src}" includes="engine.linker.js" />
<fileset dir="${engine.src}" includes="engine.main.js" />
<fileset dir="${engine.src}" includes="engine.script.js" />
- <fileset dir="${engine.src}" includes="debug.metrics.stub.js" />
+ <fileset dir="${engine.src}" includes="debug.metrics.js" />
<fileset dir="${engine.src}" includes="engine.init.js" />
</concat>
<replaceregexp match="@BUILD_VERSION" replace="${build.version}" flags="g" byline="true" file="${engine.file}" />
View
625 engine/baseobject.js
@@ -33,11 +33,11 @@
// The class this file defines and its required classes
R.Engine.define({
- "class": "R.engine.BaseObject",
- "requires": [
- "R.engine.PooledObject",
- "R.engine.Events"
- ]
+ "class":"R.engine.BaseObject",
+ "requires":[
+ "R.engine.PooledObject",
+ "R.engine.Events"
+ ]
});
/**
@@ -54,201 +54,202 @@ R.Engine.define({
* this object is ideal to extend from. It has methods for assigning and
* accessing that element.
* <p/>
- * The {@link #update} method is called each time a frame is generated by the engine
- * to update the object within the scene graph. In this method, you'll be able to
+ * The {@link #update} method is called each time a frame is generated by the engine
+ * to update the object within the scene graph. In this method, you'll be able to
* update the internals of the object and perform general housekeeping.
*
* @param name {String} The name of the object
* @extends R.engine.PooledObject
* @constructor
- * @description Create a base object.
+ * @description Create a base object.
*/
-R.engine.BaseObject = function(){
- return R.engine.PooledObject.extend(/** @scope R.engine.BaseObject.prototype */{
-
- element: null,
- jQObject: undefined,
- events: null,
- eventListeners: null,
-
- /** @private */
- constructor: function(name){
- this.base(name);
- this.events = {};
- this.eventListeners = {};
- this.jQObject = undefined;
- },
-
- /**
- * Destroy the object, cleaning up any events that have been
- * attached to this object. Calls the <tt>destroy</tt> event
- * before the object is destroyed.
- */
- destroy: function(){
- // Trigger the "destroy" event before the object is destroyed
- this.triggerEvent("destroyed");
+R.engine.BaseObject = function () {
+ "use strict";
+ return R.engine.PooledObject.extend(/** @scope R.engine.BaseObject.prototype */{
- // We need to make sure to remove any event's attached to us
- // that weren't already cleaned up
- for (var ref in this.events) {
- var fn = this.events[ref];
- var type = ref.split(",")[1];
- if (fn) {
- R.engine.Events.clearHandler(this.getElement(), type, fn);
- }
- }
+ element:null,
+ jQObject:undefined,
+ events:null,
+ eventListeners:null,
- // Clean up non-element event listeners
- this.eventListeners = {};
+ /** @private */
+ constructor:function (name) {
+ this.base(name);
+ this.events = {};
+ this.eventListeners = {};
+ this.jQObject = undefined;
+ },
- if (this.element != null && this.element != document) {
- $(this.element).empty().remove();
- }
-
- this.base();
- },
-
- /**
- * Release the object back into the object pool.
- */
- release: function(){
- this.base();
- this.element = null;
- this.events = null;
- this.eventListeners = null;
- this.jQObject = undefined;
- },
-
- /**
- * Set the element which will represent this object within
- * its rendering context.
- *
- * @param element {HTMLElement} The HTML element this object is associated with.
- */
- setElement: function(element){
- // If it isn't an element (prolly jQuery) then get the root element in the jQuery object
- this.element = element.nodeType ? element : element[0];
- },
-
- /**
- * Get the element which represents this object within its rendering context.
- *
- * @return {HTMLElement} The HTML element
- */
- getElement: function(){
- return this.element;
- },
-
- /**
- * A helper method to provide access to the jQuery object wrapping the
- * element for this object. This allows direct access to the DOM.
- *
- * @return {jQuery} A jQuery object
- */
- jQ: function(){
- if (!this.jQObject) {
- this.jQObject = this.element ? $(this.element) : null;
- }
- return this.jQObject;
- },
-
- /**
- * Abstract update method to set the state of the object. This method
- * will be called each frame that is generated by the engine. The
- * context where the object will be rendered is passed, along with the
- * current engine time. Use this method to update components and
- * perform housekeeping on the object.
- *
- * @param renderContext {R.rendercontexts.AbstractRenderContext} The context the object exists within
- * @param time {Number} The current engine time, in milliseconds
- * @param dt {Number} The delta between the world time and the last time the world was updated
- * in milliseconds.
- */
- update: function(renderContext, time, dt){
- },
-
- /**
- * Add an event handler to this object. Within the
- * event handler, <tt>this</tt> refers to the object upon which the event is being triggered. It is
- * possible to bind an event simply by calling <tt>addEvent</tt> with the type and callback, like
- * so:
- * <pre>
- * this.addEvent("click", function(evt) {
+ /**
+ * Destroy the object, cleaning up any events that have been
+ * attached to this object. Calls the <tt>destroy</tt> event
+ * before the object is destroyed.
+ */
+ destroy:function () {
+ // Trigger the "destroy" event before the object is destroyed
+ this.triggerEvent("destroyed");
+
+ // We need to make sure to remove any event's attached to us
+ // that weren't already cleaned up
+ for (var ref in this.events) {
+ var fn = this.events[ref];
+ var type = ref.split(",")[1];
+ if (fn) {
+ R.engine.Events.clearHandler(this.getElement(), type, fn);
+ }
+ }
+
+ // Clean up non-element event listeners
+ this.eventListeners = {};
+
+ if (this.element != null && this.element != document) {
+ $(this.element).empty().remove();
+ }
+
+ this.base();
+ },
+
+ /**
+ * Release the object back into the object pool.
+ */
+ release:function () {
+ this.base();
+ this.element = null;
+ this.events = null;
+ this.eventListeners = null;
+ this.jQObject = undefined;
+ },
+
+ /**
+ * Set the element which will represent this object within
+ * its rendering context.
+ *
+ * @param element {HTMLElement} The HTML element this object is associated with.
+ */
+ setElement:function (element) {
+ // If it isn't an element (prolly jQuery) then get the root element in the jQuery object
+ this.element = element.nodeType ? element : element[0];
+ },
+
+ /**
+ * Get the element which represents this object within its rendering context.
+ *
+ * @return {HTMLElement} The HTML element
+ */
+ getElement:function () {
+ return this.element;
+ },
+
+ /**
+ * A helper method to provide access to the jQuery object wrapping the
+ * element for this object. This allows direct access to the DOM.
+ *
+ * @return {jQuery} A jQuery object
+ */
+ jQ:function () {
+ if (!this.jQObject) {
+ this.jQObject = this.element ? $(this.element) : null;
+ }
+ return this.jQObject;
+ },
+
+ /**
+ * Abstract update method to set the state of the object. This method
+ * will be called each frame that is generated by the engine. The
+ * context where the object will be rendered is passed, along with the
+ * current engine time. Use this method to update components and
+ * perform housekeeping on the object.
+ *
+ * @param renderContext {R.rendercontexts.AbstractRenderContext} The context the object exists within
+ * @param time {Number} The current engine time, in milliseconds
+ * @param dt {Number} The delta between the world time and the last time the world was updated
+ * in milliseconds.
+ */
+ update:function (renderContext, time, dt) {
+ },
+
+ /**
+ * Add an event handler to this object. Within the
+ * event handler, <tt>this</tt> refers to the object upon which the event is being triggered. It is
+ * possible to bind an event simply by calling <tt>addEvent</tt> with the type and callback, like
+ * so:
+ * <pre>
+ * this.addEvent("click", function(evt) {
* this.doSomething(evt);
* });
- * </pre>
- * However, if you need to reference another object during the binding process, such as when
- * a render context is binding an event to a game object, you could pass a reference object
- * as the first argument:
- * <pre>
- * // "this" refers to the render context
- * someObj.addEvent(this, "click", function(evt) {
+ * </pre>
+ * However, if you need to reference another object during the binding process, such as when
+ * a render context is binding an event to a game object, you could pass a reference object
+ * as the first argument:
+ * <pre>
+ * // "this" refers to the render context
+ * someObj.addEvent(this, "click", function(evt) {
* // Inside the handler, "this" is the target of the event
* this.doSomething(evt);
* });
- * </pre>
- * The purpose behind this is that if the render context assigned the event, it should
- * probably remove the handler, rather than the game object needing to remove the handler.
- * But, if the game object <i>also</i> has a "click" handler, you don't want to remove
- * <i>that handler</i> since the game object may still need it.
- * <p/>
- * If the event handler explicitly returns <code>false</code> (not <code>null</code>, or
- * <code>undefined</code>), further event handlers will not be processed.
- *
- * @param [ref] {Object} The object reference which is assigning the event
- * @param type {String} The event type to respond to
- * @param [data] {Array} Optional data to pass to the handler when it is invoked.
- * @param fn {Function} The function to trigger when the event fires
- */
- addEvent: function(ref, type, data, fn){
+ * </pre>
+ * The purpose behind this is that if the render context assigned the event, it should
+ * probably remove the handler, rather than the game object needing to remove the handler.
+ * But, if the game object <i>also</i> has a "click" handler, you don't want to remove
+ * <i>that handler</i> since the game object may still need it.
+ * <p/>
+ * If the event handler explicitly returns <code>false</code> (not <code>null</code>, or
+ * <code>undefined</code>), further event handlers will not be processed.
+ *
+ * @param [ref] {Object} The object reference which is assigning the event
+ * @param type {String} The event type to respond to
+ * @param [data] {Array} Optional data to pass to the handler when it is invoked.
+ * @param fn {Function} The function to trigger when the event fires
+ */
+ addEvent:function (ref, type, data, fn) {
- // CAUTION: Brain Teaser
- fn = R.isString(ref) ? (R.isFunction(type) ? type : (R.isFunction(data) ? data : fn)) :
+ // CAUTION: Brain Teaser
+ fn = R.isString(ref) ? (R.isFunction(type) ? type : (R.isFunction(data) ? data : fn)) :
R.isFunction(data) ? data : fn;
- data = R.isString(ref) ? (R.isFunction(type) ? null : (R.isFunction(data) ? null : data)) :
- R.isFunction(data) ? null : data;
- type = R.isString(ref) ? ref : type;
- ref = R.isString(ref) ? this : ref;
- // CAUTION -------------
+ data = R.isString(ref) ? (R.isFunction(type) ? null : (R.isFunction(data) ? null : data)) :
+ R.isFunction(data) ? null : data;
+ type = R.isString(ref) ? ref : type;
+ ref = R.isString(ref) ? this : ref;
+ // CAUTION -------------
+
+ if (ref == null) {
+ // This is a global assignment to the document body. Many listeners
+ // may collect data from the event handler.
+ R.debug.Console.info("Global assignment of event '" + type + "'");
+ R.engine.Events.setHandler(document.body, type, data || fn, fn);
+ this.events["document," + type] = fn;
+ }
+ else {
+ R.debug.Console.debug(ref.getName() + " attach event '" + type + "' to " + this.getName());
+ if (this.getElement() && ref instanceof R.rendercontexts.AbstractRenderContext) {
+ R.engine.Events.setHandler(this.getElement(), type, data || fn, fn);
- if (ref == null) {
- // This is a global assignment to the document body. Many listeners
- // may collect data from the event handler.
- R.debug.Console.info("Global assignment of event '" + type + "'");
- R.engine.Events.setHandler(document.body, type, data || fn, fn);
- this.events["document," + type] = fn;
- }
- else {
- R.debug.Console.debug(ref.getName() + " attach event '" + type + "' to " + this.getName());
- if (this.getElement() && ref instanceof R.rendercontexts.AbstractRenderContext) {
- R.engine.Events.setHandler(this.getElement(), type, data || fn, fn);
-
- // Remember the handler by the reference object's name and event type
- this.events[ref.getName() + "," + type] = fn;
- } else {
- // We want to be able to add event handlers to objects which don't
- // have an element associated with them as well
- var listeners = this.eventListeners[type.toUpperCase()];
- if (!listeners) {
- listeners = this.eventListeners[type.toUpperCase()] = [];
- }
+ // Remember the handler by the reference object's name and event type
+ this.events[ref.getName() + "," + type] = fn;
+ } else {
+ // We want to be able to add event handlers to objects which don't
+ // have an element associated with them as well
+ var listeners = this.eventListeners[type.toUpperCase()];
+ if (!listeners) {
+ listeners = this.eventListeners[type.toUpperCase()] = [];
+ }
- // Add the new listener
- listeners.push({
- id: ref.getName() + "," + type,
- data: data,
- callback: fn
- });
+ // Add the new listener
+ listeners.push({
+ id:ref.getName() + "," + type,
+ data:data,
+ callback:fn
+ });
+ }
}
- }
- },
+ },
- /**
- * Helper method to simplify wiring event handlers to event types. You can assign
- * multiple handlers, by name, using object or array notation, for example:
- * <pre>
- * // Shorthand
- * this.addEvents({
+ /**
+ * Helper method to simplify wiring event handlers to event types. You can assign
+ * multiple handlers, by name, using object or array notation, for example:
+ * <pre>
+ * // Shorthand
+ * this.addEvents({
* "keydown": function(evt, which) {
* this.onKeyDown(which);
* },
@@ -256,150 +257,150 @@ R.engine.BaseObject = function(){
* this.onKeyUp(which);
* }
* });
- *
- * // Super shorthand
- * this.addEvents(["onKeyDown", "onKeyUp"]);
- * </pre>
- * Object notation allows you to still be explicit in which handler method to
- * apply or call, and the arguments which are handled. Array notation will
- * simply create a method call which takes the names of the event handlers,
- * removes "on" and then lower cases the remainder to create the event assignment.
- * <p/>
- * In the example above, <tt>onKeyDown</tt> is the name of your method to be
- * called, and <tt>keydown</tt> will be the name of the actual event.
- *
- * @param handlers {Object|Array} The event assignments
- */
- addEvents: function(handlers) {
- var self = this;
- if ($.isArray(handlers)) {
- for (var h = 0; h < handlers.length; h++) {
- var method = this[handlers[h]];
- this.addEvent(handlers[h].substr(2).toLowerCase(), method);
+ *
+ * // Super shorthand
+ * this.addEvents(["onKeyDown", "onKeyUp"]);
+ * </pre>
+ * Object notation allows you to still be explicit in which handler method to
+ * apply or call, and the arguments which are handled. Array notation will
+ * simply create a method call which takes the names of the event handlers,
+ * removes "on" and then lower cases the remainder to create the event assignment.
+ * <p/>
+ * In the example above, <tt>onKeyDown</tt> is the name of your method to be
+ * called, and <tt>keydown</tt> will be the name of the actual event.
+ *
+ * @param handlers {Object|Array} The event assignments
+ */
+ addEvents:function (handlers) {
+ var self = this;
+ if ($.isArray(handlers)) {
+ for (var h = 0; h < handlers.length; h++) {
+ var method = this[handlers[h]];
+ this.addEvent(handlers[h].substr(2).toLowerCase(), method);
+ }
+ } else {
+ $.each(handlers, function (key, value) {
+ self.addEvent(key, value);
+ });
}
- } else {
- $.each(handlers, function(key, value) {
- self.addEvent(key, value);
- });
- }
- },
+ },
- /**
- * Remove the event handler assigned to the object for the given type. The optional
- * <tt>ref</tt> argument is used when another object assigned the event handler, such as:
- * <pre>
- * // Handler #1
- * someObject.addEvent("click", function(evt) {
+ /**
+ * Remove the event handler assigned to the object for the given type. The optional
+ * <tt>ref</tt> argument is used when another object assigned the event handler, such as:
+ * <pre>
+ * // Handler #1
+ * someObject.addEvent("click", function(evt) {
* this.doSomething(evt);
* });
- *
- * // Handler #2
- * someObject.addEvent(anotherObject, "click", function(evt) {
+ *
+ * // Handler #2
+ * someObject.addEvent(anotherObject, "click", function(evt) {
* this.doSomething(evt);
* });
- * </pre>
- * You would remove the "click" handler that <tt>anotherObject</tt> assigned (handler #2),
- * and not one that was bound by <tt>someObject</tt> (handler #1):
- * <pre>
- * someObject.removeEvent(anotherObject, "click");
- * </pre>
- *
- * @param [ref] {Object} The object reference which assigned the event
- * @param type {String} The event type to remove
- */
- removeEvent: function(ref, type){
- var fn;
- ref = R.isString(ref) ? this : ref;
- if (ref == null) {
- // This was a global assignment to the document body. Clean it up
- R.debug.Console.info("Global event '" + type + "' removed");
- fn = this.events["document," + type];
- R.engine.Events.clearHandler(document.body, type, fn);
- }
- else {
- R.debug.Console.info(ref.getName() + " remove event '" + type + "' from " + this.getName());
- var id = ref.getName() + "," + type;
- if (this.getElement() && ref instanceof R.rendercontexts.AbstractRenderContext) {
- // Find the handler to remove
- fn = this.events[id];
- if (fn) {
- R.engine.Events.clearHandler(this.getElement(), type, fn);
- }
- // Remove the reference
- delete this.events[ref.getName() + "," + type];
- } else {
- var listeners = this.eventListeners[type.toUpperCase()];
- if (listeners) {
- listeners = R.engine.Support.filter(listeners, function(e) {
- return e.id !== id;
- });
- }
+ * </pre>
+ * You would remove the "click" handler that <tt>anotherObject</tt> assigned (handler #2),
+ * and not one that was bound by <tt>someObject</tt> (handler #1):
+ * <pre>
+ * someObject.removeEvent(anotherObject, "click");
+ * </pre>
+ *
+ * @param [ref] {Object} The object reference which assigned the event
+ * @param type {String} The event type to remove
+ */
+ removeEvent:function (ref, type) {
+ var fn;
+ ref = R.isString(ref) ? this : ref;
+ if (ref == null) {
+ // This was a global assignment to the document body. Clean it up
+ R.debug.Console.info("Global event '" + type + "' removed");
+ fn = this.events["document," + type];
+ R.engine.Events.clearHandler(document.body, type, fn);
+ }
+ else {
+ R.debug.Console.info(ref.getName() + " remove event '" + type + "' from " + this.getName());
+ var id = ref.getName() + "," + type;
+ if (this.getElement() && ref instanceof R.rendercontexts.AbstractRenderContext) {
+ // Find the handler to remove
+ fn = this.events[id];
+ if (fn) {
+ R.engine.Events.clearHandler(this.getElement(), type, fn);
+ }
+ // Remove the reference
+ delete this.events[ref.getName() + "," + type];
+ } else {
+ var listeners = this.eventListeners[type.toUpperCase()];
+ if (listeners) {
+ listeners = R.engine.Support.filter(listeners, function (e) {
+ return e.id !== id;
+ });
+ }
+ }
}
- }
- },
+ },
- /**
- * Trigger an event on the object. Event handlers assigned with
- * {@link #addEvent} will be triggered and passed the event object
- * and the data. The scope of the listener function will be the
- * object.
- *
- * @param eventName {String} The event to trigger
- * @param [eventObj] {Event} The original event object
- * @param data {Array} An array of data to pass to the event handler
- */
- triggerEvent: function(eventName, eventObj, data) {
- var ret;
- if (this.getElement() && this instanceof R.rendercontexts.AbstractRenderContext) {
- if (eventObj && (eventObj instanceof Event)) {
- ret = this.jQ().trigger(eventObj);
+ /**
+ * Trigger an event on the object. Event handlers assigned with
+ * {@link #addEvent} will be triggered and passed the event object
+ * and the data. The scope of the listener function will be the
+ * object.
+ *
+ * @param eventName {String} The event to trigger
+ * @param [eventObj] {Event} The original event object
+ * @param data {Array} An array of data to pass to the event handler
+ */
+ triggerEvent:function (eventName, eventObj, data) {
+ var ret;
+ if (this.getElement() && this instanceof R.rendercontexts.AbstractRenderContext) {
+ if (eventObj && (eventObj instanceof Event)) {
+ ret = this.jQ().trigger(eventObj);
+ } else {
+ ret = this.jQ().trigger(eventName, eventObj);
+ }
+ return ret
} else {
- ret = this.jQ().trigger(eventName, eventObj);
- }
- return ret
- } else {
- if (this.eventListeners) {
- var listeners = this.eventListeners[eventName.toUpperCase()];
- if (listeners) {
- if (eventObj && R.isArray(eventObj)) {
- data = eventObj;
- eventObj = $.Event({ type: eventName });
- }
- data = data || [];
+ if (this.eventListeners) {
+ var listeners = this.eventListeners[eventName.toUpperCase()];
+ if (listeners) {
+ if (eventObj && R.isArray(eventObj)) {
+ data = eventObj;
+ eventObj = $.Event({ type:eventName });
+ }
+ data = data || [];
- // Make sure the first element is the event
- data.unshift(eventObj);
+ // Make sure the first element is the event
+ data.unshift(eventObj);
- for (var e = 0; e < listeners.length; e++) {
- var listener = listeners[e];
+ for (var e = 0; e < listeners.length; e++) {
+ var listener = listeners[e];
- // Append the predefined listener data to the data object
- if (listener.data) {
- data = data.concat(listener.data);
- }
+ // Append the predefined listener data to the data object
+ if (listener.data) {
+ data = data.concat(listener.data);
+ }
- // Call the listener
- ret = listener.callback.apply(this, data);
- if (ret === false) {
- return false;
- }
- }
- }
+ // Call the listener
+ ret = listener.callback.apply(this, data);
+ if (ret === false) {
+ return false;
+ }
+ }
+ }
+ }
}
- }
- }
-
- }, /** @scope R.engine.BaseObject.prototype */ {
-
- /**
- * Get the class name of this object
- *
- * @return {String} "R.engine.BaseObject"
- */
- getClassName: function(){
- return "R.engine.BaseObject";
- }
-
- });
-
+ }
+
+ }, /** @scope R.engine.BaseObject.prototype */ {
+
+ /**
+ * Get the class name of this object
+ *
+ * @return {String} "R.engine.BaseObject"
+ */
+ getClassName:function () {
+ return "R.engine.BaseObject";
+ }
+
+ });
+
};
View
608 engine/build/debug.console.js
@@ -37,99 +37,99 @@
* browser's console object so the {@link Console} can report to it.
*/
R.debug.ConsoleRef = Base.extend(/** @scope R.debug.ConsoleRef.prototype */{
- constructor: function() {
- },
-
- dumpWindow: null,
-
- /** @private */
- combiner: function() {
- var out = "";
- for (var a = 0; a < arguments.length; a++) {
- out += arguments[a].toString();
- }
- return out;
- },
-
- cleanup: function(o) {
- if (typeof o === "undefined") {
- return "";
- } else if (o === null) {
- return "null";
- } else if (typeof o == "function") {
- return "function";
- } else if (o.constructor == Array || (o.slice && o.join && o.splice)) { // An array
- var s = "[";
- for (var e in o) {
- s += (s.length > 1 ? "," : "") + this.cleanup(o[e]);
- }
- return s + "]";
- } else if (typeof o === "object") {
- var s = "{\n";
- for (var e in o) {
- s += e + ": " + this.cleanup(o[e]) + "\n";
- }
- return s + "}\n";
- } else {
- return o.toString();
- }
- },
-
- /** @private */
- fixArgs: function(a) {
- var x = [];
- for (var i=0; i < a.length; i++) {
- if (!a[i]) {
- x.push("null");
- } else {
- x.push(this.cleanup(a[i]));
- }
- }
- return x.join(" ");
- },
-
- /**
- * Write a debug message to the console. The arguments to the method call will be
- * concatenated into one string message.
- */
- debug: function() {
- },
-
- /**
- * Write an info message to the console. The arguments to the method call will be
- * concatenated into one string message.
- */
- info: function() {
- },
-
- /**
- * Write a warning message to the console. The arguments to the method call will be
- * concatenated into one string message.
- */
- warn: function() {
- },
-
- /**
- * Write an error message to the console. The arguments to the method call will be
- * concatenated into one string message.
- */
- error: function() {
- },
-
- /**
- * Dump a stack trace to the console.
- */
- trace: function() {
- },
-
- /**
- * Get the class name of this object
- *
- * @return {String} The string "ConsoleRef"
- */
- getClassName: function() {
- return "R.debug.ConsoleRef";
- }
+ constructor:function () {
+ },
+
+ dumpWindow:null,
+
+ /** @private */
+ combiner:function () {
+ var out = "";
+ for (var a = 0; a < arguments.length; a++) {
+ out += arguments[a].toString();
+ }
+ return out;
+ },
+
+ cleanup:function (o) {
+ if (typeof o === "undefined") {
+ return "";
+ } else if (o === null) {
+ return "null";
+ } else if (typeof o == "function") {
+ return "function";
+ } else if (o.constructor == Array || (o.slice && o.join && o.splice)) { // An array
+ var s = "[";
+ for (var e in o) {
+ s += (s.length > 1 ? "," : "") + this.cleanup(o[e]);
+ }
+ return s + "]";
+ } else if (typeof o === "object") {
+ var s = "{\n";
+ for (var e in o) {
+ s += e + ": " + this.cleanup(o[e]) + "\n";
+ }
+ return s + "}\n";
+ } else {
+ return o.toString();
+ }
+ },
+
+ /** @private */
+ fixArgs:function (a) {
+ var x = [];
+ for (var i = 0; i < a.length; i++) {
+ if (!a[i]) {
+ x.push("null");
+ } else {
+ x.push(this.cleanup(a[i]));
+ }
+ }
+ return x.join(" ");
+ },
+
+ /**
+ * Write a debug message to the console. The arguments to the method call will be
+ * concatenated into one string message.
+ */
+ debug:function () {
+ },
+
+ /**
+ * Write an info message to the console. The arguments to the method call will be
+ * concatenated into one string message.
+ */
+ info:function () {
+ },
+
+ /**
+ * Write a warning message to the console. The arguments to the method call will be
+ * concatenated into one string message.
+ */
+ warn:function () {
+ },
+
+ /**
+ * Write an error message to the console. The arguments to the method call will be
+ * concatenated into one string message.
+ */
+ error:function () {
+ },
+
+ /**
+ * Dump a stack trace to the console.
+ */
+ trace:function () {
+ },
+
+ /**
+ * Get the class name of this object
+ *
+ * @return {String} The string "ConsoleRef"
+ */
+ getClassName:function () {
+ return "R.debug.ConsoleRef";
+ }
});
@@ -144,50 +144,50 @@ R.debug.ConsoleRef = Base.extend(/** @scope R.debug.ConsoleRef.prototype */{
* </ul>
*/
R.debug.Console = Base.extend(/** @scope R.debug.Console.prototype */{
- constructor: null,
- consoleRef: null,
- enableDebugOutput: null,
-
- /**
- * Output only errors to the console.
- */
- DEBUGLEVEL_ERRORS: 4,
-
- /**
- * Output warnings and errors to the console.
- */
- DEBUGLEVEL_WARNINGS: 3,
-
- /**
- * Output warnings, errors, and debug messages to the console.
- */
- DEBUGLEVEL_DEBUG: 2,
-
- /**
- * Output warnings, errors, debug, and low-level info messages to the console.
- */
- DEBUGLEVEL_INFO: 1,
-
- /**
- * Output all messages to the console.
- */
- DEBUGLEVEL_VERBOSE: 0,
-
- /**
- * Output nothing to the console.
- */
- DEBUGLEVEL_NONE: -1,
-
- /** @private */
- verbosity: null,
-
- /**
- * Starts up the console.
- */
- startup: function() {
- R.debug.Console.verbosity = R.debug.Console.DEBUGLEVEL_ERRORS;
- R.debug.Console.enableDebugOutput = false;
-
+ constructor:null,
+ consoleRef:null,
+ enableDebugOutput:null,
+
+ /**
+ * Output only errors to the console.
+ */
+ DEBUGLEVEL_ERRORS:4,
+
+ /**
+ * Output warnings and errors to the console.
+ */
+ DEBUGLEVEL_WARNINGS:3,
+
+ /**
+ * Output warnings, errors, and debug messages to the console.
+ */
+ DEBUGLEVEL_DEBUG:2,
+
+ /**
+ * Output warnings, errors, debug, and low-level info messages to the console.
+ */
+ DEBUGLEVEL_INFO:1,
+
+ /**
+ * Output all messages to the console.
+ */
+ DEBUGLEVEL_VERBOSE:0,
+
+ /**
+ * Output nothing to the console.
+ */
+ DEBUGLEVEL_NONE:-1,
+
+ /** @private */
+ verbosity:null,
+
+ /**
+ * Starts up the console.
+ */
+ startup:function () {
+ R.debug.Console.verbosity = R.debug.Console.DEBUGLEVEL_ERRORS;
+ R.debug.Console.enableDebugOutput = false;
+
// if (R.engine.Support.checkBooleanParam("debug") && (R.engine.Support.checkBooleanParam("simWii") || R.browser.Wii)) {
// R.debug.Console.consoleRef = new R.debug.HTML();
// }
@@ -205,168 +205,167 @@ R.debug.Console = Base.extend(/** @scope R.debug.Console.prototype */{
// R.debug.Console.consoleRef = new R.debug.Opera();
// }
// else {
- R.debug.Console.consoleRef = new R.debug.ConsoleRef(); // (null console)
+ R.debug.Console.consoleRef = new R.debug.ConsoleRef(); // (null console)
// }
- },
-
- /**
- * Set the console reference object to a new type of console which isn't
- * natively supported.
- *
- * @param refObj {ConsoleRef} A descendent of the <tt>ConsoleRef</tt> class.
- */
- setConsoleRef: function(refObj) {
- if (refObj instanceof R.debug.ConsoleRef) {
- R.debug.Console.consoleRef = refObj;
- }
- },
-
- /**
- * Set the debug output level of the console. The available levels are:
- * <ul>
- * <li><tt>Console.DEBUGLEVEL_ERRORS</tt> = 4</li>
- * <li><tt>Console.DEBUGLEVEL_WARNINGS</tt> = 3</li>
- * <li><tt>Console.DEBUGLEVEL_DEBUG</tt> = 2</li>
- * <li><tt>Console.DEBUGLEVEL_INFO</tt> = 1</li>
- * <li><tt>Console.DEBUGLEVEL_VERBOSE</tt> = 0</li>
- * <li><tt>Console.DEBUGLEVEL_NONE</tt> = -1</li>
- * </ul>
- * Messages of the same (or lower) level as the specified level will be logged.
- * For instance, if you set the level to <tt>DEBUGLEVEL_DEBUG</tt>, errors and warnings
- * will also be logged. The engine must also be in debug mode for warnings,
- * debug, and log messages to be output.
- * <p/>
- * Console messages have been decoupled from engine debugging mode so that messages
- * can be output without the need to enter engine debug mode. To enable engine
- * debugging, see {@link R.Engine#setDebugMode}.
- *
- * @param level {Number} One of the debug levels. Defaults to DEBUGLEVEL_NONE.
- */
- setDebugLevel: function(level) {
- R.debug.Console.verbosity = level;
-
- // Automatically enable output, unless no debugging is specified
- if (level != R.debug.Console.DEBUGLEVEL_NONE) {
- R.debug.Console.enableDebugOutput = true;
- } else {
- R.debug.Console.enableDebugOutput = false;
- }
- },
-
- /**
- * Get the debug level which the console is currently at.
- * @return {Number} The debug level
- */
- getDebugLevel: function() {
- return R.debug.Console.verbosity;
- },
-
- /**
- * Verifies that the debug level is the same as the message to output
- * @private
- */
- checkVerbosity: function(debugLevel) {
- if (!R.debug.Console.enableDebugOutput) return;
-
- return (R.debug.Console.verbosity == R.debug.Console.DEBUGLEVEL_VERBOSE ||
- (debugLevel != R.debug.Console.DEBUGLEVEL_VERBOSE && debugLevel >= R.debug.Console.verbosity));
- },
-
- /**
- * Outputs a log message. These messages will only show when <tt>DEBUGLEVEL_VERBOSE</tt> is the level.
- * You can pass as many parameters as you want to this method. The parameters will be combined into
- * one message to output to the console.
- */
- log: function() {
- if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_VERBOSE))
- R.debug.Console.consoleRef.debug.apply(R.debug.Console.consoleRef, arguments);
- },
-
- /**
- * Outputs an info message. These messages will only show when <tt>DEBUGLEVEL_INFO</tt> is the level.
- * You can pass as many parameters as you want to this method. The parameters will be combined into
- * one message to output to the console.
- */
- info: function() {
- if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_INFO))
- R.debug.Console.consoleRef.debug.apply(R.debug.Console.consoleRef, arguments);
- },
-
- /**
- * Outputs a debug message. These messages will only show when <tt>DEBUGLEVEL_DEBUG</tt> is the level.
- * You can pass as many parameters as you want to this method. The parameters will be combined into
- * one message to output to the console.
- */
- debug: function() {
- if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_DEBUG))
- R.debug.Console.consoleRef.info.apply(R.debug.Console.consoleRef, arguments);
- },
-
- /**
- * Outputs a warning message. These messages will only show when <tt>DEBUGLEVEL_WARNINGS</tt> is the level.
- * You can pass as many parameters as you want to this method. The parameters will be combined into
- * one message to output to the console.
- */
- warn: function() {
- if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_WARNINGS))
- R.debug.Console.consoleRef.warn.apply(R.debug.Console.consoleRef, arguments);
- },
-
- /**
- * Output an error message. These messages always appear unless the debug level is explicitly
- * set to <tt>DEBUGLEVEL_NONE</tt>.
- * You can pass as many parameters as you want to this method. The parameters will be combined into
- * one message to output to the console.
- */
- error: function() {
- if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_ERRORS))
- R.debug.Console.consoleRef.error.apply(R.debug.Console.consoleRef, arguments);
- },
-
- /**
- * @private
- */
- trace: function() {
- R.debug.Console.consoleRef.trace();
- }
+ },
+
+ /**
+ * Set the console reference object to a new type of console which isn't
+ * natively supported.
+ *
+ * @param refObj {ConsoleRef} A descendent of the <tt>ConsoleRef</tt> class.
+ */
+ setConsoleRef:function (refObj) {
+ if (refObj instanceof R.debug.ConsoleRef) {
+ R.debug.Console.consoleRef = refObj;
+ }
+ },
+
+ /**
+ * Set the debug output level of the console. The available levels are:
+ * <ul>
+ * <li><tt>Console.DEBUGLEVEL_ERRORS</tt> = 4</li>
+ * <li><tt>Console.DEBUGLEVEL_WARNINGS</tt> = 3</li>
+ * <li><tt>Console.DEBUGLEVEL_DEBUG</tt> = 2</li>
+ * <li><tt>Console.DEBUGLEVEL_INFO</tt> = 1</li>
+ * <li><tt>Console.DEBUGLEVEL_VERBOSE</tt> = 0</li>
+ * <li><tt>Console.DEBUGLEVEL_NONE</tt> = -1</li>
+ * </ul>
+ * Messages of the same (or lower) level as the specified level will be logged.
+ * For instance, if you set the level to <tt>DEBUGLEVEL_DEBUG</tt>, errors and warnings
+ * will also be logged. The engine must also be in debug mode for warnings,
+ * debug, and log messages to be output.
+ * <p/>
+ * Console messages have been decoupled from engine debugging mode so that messages
+ * can be output without the need to enter engine debug mode. To enable engine
+ * debugging, see {@link R.Engine#setDebugMode}.
+ *
+ * @param level {Number} One of the debug levels. Defaults to DEBUGLEVEL_NONE.
+ */
+ setDebugLevel:function (level) {
+ R.debug.Console.verbosity = level;
+
+ // Automatically enable output, unless no debugging is specified
+ if (level != R.debug.Console.DEBUGLEVEL_NONE) {
+ R.debug.Console.enableDebugOutput = true;
+ } else {
+ R.debug.Console.enableDebugOutput = false;
+ }
+ },
+
+ /**
+ * Get the debug level which the console is currently at.
+ * @return {Number} The debug level
+ */
+ getDebugLevel:function () {
+ return R.debug.Console.verbosity;
+ },
+
+ /**
+ * Verifies that the debug level is the same as the message to output
+ * @private
+ */
+ checkVerbosity:function (debugLevel) {
+ if (!R.debug.Console.enableDebugOutput) return;
+
+ return (R.debug.Console.verbosity == R.debug.Console.DEBUGLEVEL_VERBOSE ||
+ (debugLevel != R.debug.Console.DEBUGLEVEL_VERBOSE && debugLevel >= R.debug.Console.verbosity));
+ },
+
+ /**
+ * Outputs a log message. These messages will only show when <tt>DEBUGLEVEL_VERBOSE</tt> is the level.
+ * You can pass as many parameters as you want to this method. The parameters will be combined into
+ * one message to output to the console.
+ */
+ log:function () {
+ if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_VERBOSE))
+ R.debug.Console.consoleRef.debug.apply(R.debug.Console.consoleRef, arguments);
+ },
+
+ /**
+ * Outputs an info message. These messages will only show when <tt>DEBUGLEVEL_INFO</tt> is the level.
+ * You can pass as many parameters as you want to this method. The parameters will be combined into
+ * one message to output to the console.
+ */
+ info:function () {
+ if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_INFO))
+ R.debug.Console.consoleRef.debug.apply(R.debug.Console.consoleRef, arguments);
+ },
+
+ /**
+ * Outputs a debug message. These messages will only show when <tt>DEBUGLEVEL_DEBUG</tt> is the level.
+ * You can pass as many parameters as you want to this method. The parameters will be combined into
+ * one message to output to the console.
+ */
+ debug:function () {
+ if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_DEBUG))
+ R.debug.Console.consoleRef.info.apply(R.debug.Console.consoleRef, arguments);
+ },
+
+ /**
+ * Outputs a warning message. These messages will only show when <tt>DEBUGLEVEL_WARNINGS</tt> is the level.
+ * You can pass as many parameters as you want to this method. The parameters will be combined into
+ * one message to output to the console.
+ */
+ warn:function () {
+ if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_WARNINGS))
+ R.debug.Console.consoleRef.warn.apply(R.debug.Console.consoleRef, arguments);
+ },
+
+ /**
+ * Output an error message. These messages always appear unless the debug level is explicitly
+ * set to <tt>DEBUGLEVEL_NONE</tt>.
+ * You can pass as many parameters as you want to this method. The parameters will be combined into
+ * one message to output to the console.
+ */
+ error:function () {
+ if (R.debug.Console.checkVerbosity(R.debug.Console.DEBUGLEVEL_ERRORS))
+ R.debug.Console.consoleRef.error.apply(R.debug.Console.consoleRef, arguments);
+ },
+
+ /**
+ * @private
+ */
+ trace:function () {
+ R.debug.Console.consoleRef.trace();
+ }
});
/**
- * Assert that a condition is <tt>true</tt>, stopping the engine if it is <tt>false</tt>.
+ * Assert that a condition is <tt>true</tt>, stopping the engine if it is <tt>false</tt>.
* If the condifion fails an exception will be thrown.
*
* @param test {Boolean} A simple test that should evaluate to <tt>true</tt>
* @param error {String} The error message to throw if the test fails
*/
-var Assert = function(test, error) {
- var fail = false;
- try {
- if (!test)
- {
- fail = true;
- R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_ERRORS);
- if (arguments.length > 1) {
- for (var a = 1; a < arguments.length; a++) {
- R.debug.Console.error("*ASSERT* ", arguments[a]);
- R.debug.Console.trace();
+var Assert = function (test, error) {
+ var fail = false;
+ try {
+ if (!test) {
+ fail = true;
+ R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_ERRORS);
+ if (arguments.length > 1) {
+ for (var a = 1; a < arguments.length; a++) {
+ R.debug.Console.error("*ASSERT* ", arguments[a]);
+ R.debug.Console.trace();
+ }
}
- }
-
- R.Engine.shutdown();
-
- }
- } catch (ex) {
- var pr = R.debug.Console.getDebugLevel();
- R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
- R.debug.Console.warn("*ASSERT* 'test' would result in an exception: ", ex);
- R.debug.Console.setDebugLevel(pr);
- }
-
- // This will provide a stacktrace for browsers that support it
- if (fail) {
- throw new Error(error);
- }
+
+ R.Engine.shutdown();
+
+ }
+ } catch (ex) {
+ var pr = R.debug.Console.getDebugLevel();
+ R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
+ R.debug.Console.warn("*ASSERT* 'test' would result in an exception: ", ex);
+ R.debug.Console.setDebugLevel(pr);
+ }
+
+ // This will provide a stacktrace for browsers that support it
+ if (fail) {
+ throw new Error(error);
+ }
};
/**
@@ -375,23 +374,22 @@ var Assert = function(test, error) {
* @param test {Boolean} A simple test that should evaluate to <tt>true</tt>
* @param error {String} The warning to display if the test fails
*/
-var AssertWarn = function(test, warning) {
- try {
- if (!test)
- {
- R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
- if (arguments.length > 1) {
- for (var a = 1; a < arguments.length; a++) {
- R.debug.Console.warn("*ASSERT-WARN* ", arguments[a]);
+var AssertWarn = function (test, warning) {
+ try {
+ if (!test) {
+ R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
+ if (arguments.length > 1) {
+ for (var a = 1; a < arguments.length; a++) {
+ R.debug.Console.warn("*ASSERT-WARN* ", arguments[a]);
+ }
}
- }
- R.debug.Console.warn(warning);
- }
- } catch (ex) {
- var pr = R.debug.Console.getDebugLevel();
- R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
- R.debug.Console.warn("*ASSERT-WARN* 'test' would result in an exception: ", ex);
- R.debug.Console.setDebugLevel(pr);
- }
+ R.debug.Console.warn(warning);
+ }
+ } catch (ex) {
+ var pr = R.debug.Console.getDebugLevel();
+ R.debug.Console.setDebugLevel(R.debug.Console.DEBUGLEVEL_WARNINGS);
+ R.debug.Console.warn("*ASSERT-WARN* 'test' would result in an exception: ", ex);
+ R.debug.Console.setDebugLevel(pr);
+ }
};
View
522 engine/build/debug.metrics.js
@@ -1,6 +1,6 @@
/**
* The Render Engine
- *
+ *
* An extension to the engine for metrics processing and display.
*
* @author: Brett Fattori (brettf@renderengine.com)
@@ -9,17 +9,17 @@
* @version: $Revision: 1555 $
*
* Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -37,281 +37,299 @@
//====================================================================================================
/**
* @class A static class to be used to measure metrics of engine and game performance. A
- * visual profiler is provided which graphs runtime values of the engine, such as
- * load and visible objects. Additionally a metrics window is provided to show
- * sampled metric data from parts of the engine, as well as user-defined metrics.
+ * visual profiler is provided which graphs runtime values of the engine, such as
+ * load and visible objects. Additionally a metrics window is provided to show
+ * sampled metric data from parts of the engine, as well as user-defined metrics.
* @static
*/
R.debug.Metrics = Base.extend(/** @scope R.debug.Metrics.prototype */{
- constructor: null,
+ constructor:null,
- /*
- * Metrics tracking/display
- */
- metrics: {}, // Tracked metrics
- metricDisplay: null, // The metric display object
- profileDisplay: null, // The profile display object
- metricSampleRate: 10, // Frames between samples
- lastMetricSample: 10, // Last sample frame
- showMetricsWindow: false, // Metrics display flag
- showMetricsProfile: false, // Metrics profile graph display flag
- vObj: 0, // Visible objects
- droppedFrames: 0, // Non-rendered frames/frames dropped
- profilePos: 0,
- profiles: {},
-
+ /*
+ * Metrics tracking/display
+ */
+ metrics:{}, // Tracked metrics
+ metricDisplay:null, // The metric display object
+ profileDisplay:null, // The profile display object
+ metricSampleRate:10, // Frames between samples
+ lastMetricSample:10, // Last sample frame
+ showMetricsWindow:false, // Metrics display flag
+ showMetricsProfile:false, // Metrics profile graph display flag
+ vObj:0, // Visible objects
+ droppedFrames:0, // Non-rendered frames/frames dropped
+ profilePos:0,
+ profiles:{},
- /**
- * Toggle the display of the metrics window. Any metrics
- * that are being tracked will be reported in this window.
- * @memberOf R.debug.Metrics
- */
- toggleMetrics: function() {
- R.debug.Metrics.showMetricsWindow = !R.debug.Metrics.showMetricsWindow;
- },
- /**
- * Show the metrics window
- * @memberOf R.debug.Metrics
- */
- showMetrics: function() {
- R.debug.Metrics.showMetricsWindow = true;
- },
-
- /**
- * Show a graph of the engine profile
- * @memberOf R.debug.Metrics
- */
- showProfile: function() {
- R.debug.Metrics.showMetricsProfile = true;
- },
+ /**
+ * Toggle the display of the metrics window. Any metrics
+ * that are being tracked will be reported in this window.
+ * @memberOf R.debug.Metrics
+ */
+ toggleMetrics:function () {
+ R.debug.Metrics.showMetricsWindow = !R.debug.Metrics.showMetricsWindow;
+ },
- /**
- * Hide the metrics window
- * @memberOf R.debug.Metrics
- */
- hideMetrics: function() {
- R.debug.Metrics.showMetricsWindow = false;
- },
-
- manMetrics: function() {
- if ($("div.metric-button.minimize").length > 0) {
- $("div.metric-button.minimize").removeClass("minimize").addClass("maximize").attr("title", "maximize");
- $("div.metrics").css("height", 17);
- $("div.metrics .items").hide();
- } else {
- $("div.metric-button.maximize").removeClass("maximize").addClass("minimize").attr("title", "minimize");
- $("div.metrics .items").show();
- $("div.metrics").css("height", "auto");
- }
- },
+ /**
+ * Show the metrics window
+ * @memberOf R.debug.Metrics
+ */
+ showMetrics:function () {
+ R.debug.Metrics.showMetricsWindow = true;
+ },
- /**
- * Creates a button for the metrics window
- * @private
- */
- metricButton: function(cssClass, fn) {
- return $("<div class='metric-button " + cssClass + "' title='" + cssClass + "'><!-- --></div>").click(fn);
- },
+ /**
+ * Show a graph of the engine profile
+ * @memberOf R.debug.Metrics
+ */
+ showProfile:function () {
+ R.debug.Metrics.showMetricsProfile = true;
+ },
- /**
- * Render the metrics window
- * @private
- */
- render: function() {
+ /**
+ * Hide the metrics window
+ * @memberOf R.debug.Metrics
+ */
+ hideMetrics:function () {
+ R.debug.Metrics.showMetricsWindow = false;
+ },
- if (R.debug.Metrics.showMetricsWindow && !R.debug.Metrics.metricDisplay) {
- R.debug.Metrics.metricDisplay = $("<div/>").addClass("metrics");
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("run", function() { R.Engine.run(); }));
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("step", function() { R.Engine.step(); }));
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("pause", function() { R.Engine.pause(); }));
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("shutdown", function() { R.Engine.shutdown(); }));
+ manMetrics:function () {
+ if ($("div.metric-button.minimize").length > 0) {
+ $("div.metric-button.minimize").removeClass("minimize").addClass("maximize").attr("title", "maximize");
+ $("div.metrics").css("height", 17);
+ $("div.metrics .items").hide();
+ } else {
+ $("div.metric-button.maximize").removeClass("maximize").addClass("minimize").attr("title", "minimize");
+ $("div.metrics .items").show();
+ $("div.metrics").css("height", "auto");
+ }
+ },
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("close", function() { R.debug.Metrics.hideMetrics(); }));
- R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("minimize", function() { R.debug.Metrics.manMetrics(); }));
+ /**
+ * Creates a button for the metrics window
+ * @private
+ */
+ metricButton:function (cssClass, fn) {
+ return $("<div class='metric-button " + cssClass + "' title='" + cssClass + "'><!-- --></div>").click(fn);
+ },
- R.debug.Metrics.metricDisplay.append($("<div class='items'/>"));
- R.debug.Metrics.metricDisplay.appendTo($("body"));
- }
-
- if ((this.showMetricsWindow || this.showMetricsProfile) && this.lastMetricSample-- == 0)
- {
- // Basic engine metrics
- R.debug.Metrics.add("FPS", R.Engine.getFPS(), false, "#");
- R.debug.Metrics.add("aFPS", R.Engine.getActualFPS(), true, "#");
- R.debug.Metrics.add("availTime", R.Engine.fpsClock, false, "#ms");
- R.debug.Metrics.add("frames", R.Engine.totalFrames, false, "#");
- R.debug.Metrics.add("frameGenTime", R.Engine.frameTime, true, "#ms");
- R.debug.Metrics.add("engineLoad", Math.floor(R.Engine.getEngineLoad() * 100), true, "#%");
- R.debug.Metrics.add("vObj", R.Engine.vObj, false, "#");
- R.debug.Metrics.add("rObj", R.Engine.rObjs, false, "#");
- R.debug.Metrics.add("droppedFrames", R.Engine.droppedFrames, false, "#");
- R.debug.Metrics.add("upTime", Math.floor((R.Engine.worldTime - R.Engine.upTime)/1000), false, "# sec");
- R.debug.Metrics.add("pclRebuilds", R.Engine.pclRebuilds, false, "#");
+ /**
+ * Render the metrics window
+ * @private
+ */
+ render:function () {
- R.debug.Metrics.update();
- R.debug.Metrics.lastMetricSample = R.debug.Metrics.metricSampleRate;
- }
-
- if (R.debug.Metrics.showMetricsProfile && R.engine.Support.sysInfo().browser == "msie" &&
- parseFloat(R.engine.Support.sysInfo().version) < 9) {
- // Profiler not supported in IE
- R.debug.Metrics.showMetricsProfile = false;
- }
-
- if (R.debug.Metrics.showMetricsProfile && !R.debug.Metrics.profileDisplay) {
- R.debug.Metrics.profileDisplay = $("<canvas width='150' height='100'/>").addClass("engine-profile");
- R.debug.Metrics.profileDisplay.appendTo($("body"));
- R.debug.Metrics.profileDisplay[0].getContext('2d').save();
- }
- },
+ if (R.debug.Metrics.showMetricsWindow && !R.debug.Metrics.metricDisplay) {
+ R.debug.Metrics.metricDisplay = $("<div/>").addClass("metrics");
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("run", function () {
+ R.Engine.run();
+ }));
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("step", function () {
+ R.Engine.step();
+ }));
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("pause", function () {
+ R.Engine.pause();
+ }));
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("shutdown", function () {
+ R.Engine.shutdown();
+ }));
- /**
- * Set the interval at which metrics are sampled by the system.
- * The default is for metrics to be calculated every 10 engine frames.
- *
- * @param sampleRate {Number} The number of ticks between samples
- * @memberOf R.debug.Metrics
- */
- setSampleRate: function(sampleRate) {
- R.debug.Metrics.lastMetricSample = 1;
- R.debug.Metrics.metricSampleRate = sampleRate;
- },
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("close", function () {
+ R.debug.Metrics.hideMetrics();
+ }));
+ R.debug.Metrics.metricDisplay.append(R.debug.Metrics.metricButton("minimize", function () {
+ R.debug.Metrics.manMetrics();
+ }));
- /**
- * Add a metric to the game engine that can be displayed
- * while it is running. If smoothing is selected, a 3 point
- * running average will be used to smooth out jitters in the
- * value that is shown. For the <tt>fmt</tt> argument,
- * you can provide a string which contains the pound sign "#"
- * that will be used to determine where the calculated value will
- * occur in the formatted string.
- *
- * @param metricName {String} The name of the metric to track
- * @param value {String/Number} The value of the metric.
- * @param smoothing {Boolean} <tt>true</tt> to use 3 point average smoothing
- * @param fmt {String} The way the value should be formatted in the display (e.g. "#ms")
- * @memberOf R.debug.Metrics
- */
- add: function(metricName, value, smoothing, fmt) {
- if (smoothing) {
- var vals = R.debug.Metrics.metrics[metricName] ? R.debug.Metrics.metrics[metricName].values : [];
- if (vals.length == 0) {
- // Init
- vals.push(value);
- vals.push(value);
+ R.debug.Metrics.metricDisplay.append($("<div class='items'/>"));
+ R.debug.Metrics.metricDisplay.appendTo($("body"));
+ }
+
+ if ((this.showMetricsWindow || this.showMetricsProfile) && this.lastMetricSample-- == 0) {
+ // Basic engine metrics
+ R.debug.Metrics.add("FPS", R.Engine.getFPS(), false, "#");
+ R.debug.Metrics.add("aFPS", R.Engine.getActualFPS(), true, "#");
+ R.debug.Metrics.add("availTime", R.Engine.fpsClock, false, "#ms");
+ R.debug.Metrics.add("frames", R.Engine.totalFrames, false, "#");
+ R.debug.Metrics.add("frameGenTime", R.Engine.frameTime, true, "#ms");
+ R.debug.Metrics.add("engineLoad", Math.floor(R.Engine.getEngineLoad() * 100), true, "#%");
+ R.debug.Metrics.add("vObj", R.Engine.vObj, false, "#");
+ R.debug.Metrics.add("rObj", R.Engine.rObjs, false, "#");
+ R.debug.Metrics.add("droppedFrames", R.Engine.droppedFrames, false, "#");
+ R.debug.Metrics.add("upTime", Math.floor((R.Engine.worldTime - R.Engine.upTime) / 1000), false, "# sec");
+ R.debug.Metrics.add("pclRebuilds", R.Engine.pclRebuilds, false, "#");
+
+ R.debug.Metrics.update();
+ R.debug.Metrics.lastMetricSample = R.debug.Metrics.metricSampleRate;
+ }
+
+ if (R.debug.Metrics.showMetricsProfile && R.engine.Support.sysInfo().browser == "msie" &&
+ parseFloat(R.engine.Support.sysInfo().version) < 9) {
+ // Profiler not supported in IE
+ R.debug.Metrics.showMetricsProfile = false;
+ }
+
+ if (R.debug.Metrics.showMetricsProfile && !R.debug.Metrics.profileDisplay) {
+ R.debug.Metrics.profileDisplay = $("<canvas width='150' height='100'/>").addClass("engine-profile");
+ R.debug.Metrics.profileDisplay.appendTo($("body"));
+ R.debug.Metrics.profileDisplay[0].getContext('2d').save();
+ }
+ },
+
+ /**
+ * Set the interval at which metrics are sampled by the system.
+ * The default is for metrics to be calculated every 10 engine frames.
+ *
+ * @param sampleRate {Number} The number of ticks between samples
+ * @memberOf R.debug.Metrics
+ */
+ setSampleRate:function (sampleRate) {
+ R.debug.Metrics.lastMetricSample = 1;
+ R.debug.Metrics.metricSampleRate = sampleRate;
+ },
+
+ /**
+ * Add a metric to the game engine that can be displayed
+ * while it is running. If smoothing is selected, a 3 point
+ * running average will be used to smooth out jitters in the
+ * value that is shown. For the <tt>fmt</tt> argument,
+ * you can provide a string which contains the pound sign "#"
+ * that will be used to determine where the calculated value will
+ * occur in the formatted string.
+ *
+ * @param metricName {String} The name of the metric to track
+ * @param value {String/Number} The value of the metric.
+ * @param smoothing {Boolean} <tt>true</tt> to use 3 point average smoothing
+ * @param fmt {String} The way the value should be formatted in the display (e.g. "#ms")
+ * @memberOf R.debug.Metrics
+ */
+ add:function (metricName, value, smoothing, fmt) {
+ if (smoothing) {
+ var vals = R.debug.Metrics.metrics[metricName] ? R.debug.Metrics.metrics[metricName].values : [];
+ if (vals.length == 0) {
+ // Init
+ vals.push(value);
+ vals.push(value);
+ vals.push(value);
+ }
+ vals.shift();
vals.push(value);
- }
- vals.shift();
- vals.push(value);
- var v = Math.floor((vals[0] + vals[1] + vals[2]) * 0.33);
- R.debug.Metrics.metrics[metricName] = { val: (fmt ? fmt.replace("#", v) : v), values: vals, act: v };
- } else {
- R.debug.Metrics.metrics[metricName] = { val: (fmt ? fmt.replace("#", value) : value), act: value };
- }
- },
+ var v = Math.floor((vals[0] + vals[1] + vals[2]) * 0.33);
+ R.debug.Metrics.metrics[metricName] = { val:(fmt ? fmt.replace("#", v) : v), values:vals, act:v };
+ } else {
+ R.debug.Metrics.metrics[metricName] = { val:(fmt ? fmt.replace("#", value) : value), act:value };
+ }
+ },
- /**
- * Remove a metric from the display
- *
- * @param metricName {String} The name of the metric to remove
- * @memberOf R.debug.Metrics
- */
- remove: function(metricName) {
- R.debug.Metrics.metrics[metricName] = null;
- delete R.debug.Metrics.metrics[metricName];
- },
+ /**
+ * Remove a metric from the display
+ *
+ * @param metricName {String} The name of the metric to remove
+ * @memberOf R.debug.Metrics
+ */
+ remove:function (metricName) {
+ R.debug.Metrics.metrics[metricName] = null;
+ delete R.debug.Metrics.metrics[metricName];
+ },
- /**
- * Updates the display of the metrics window.
- * @private
- * @memberOf R.debug.Metrics
- */
- update: function() {
- var h = "", ctx;
- if (R.debug.Metrics.showMetricsProfile) {
- ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
- ctx.save();
- ctx.translate(147, 0);
- }
+ /**
+ * Updates the display of the metrics window.
+ * @private
+ * @memberOf R.debug.Metrics
+ */
+ update:function () {
+ var h = "", ctx;
+ if (R.debug.Metrics.showMetricsProfile) {
+ ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
+ ctx.save();
+ ctx.translate(147, 0);
+ }
- for (var m in R.debug.Metrics.metrics)
- {
- if (R.debug.Metrics.showMetricsWindow) {
- h += m + ": " + R.debug.Metrics.metrics[m].val + "<br/>";
- }
- if (R.debug.Metrics.showMetricsProfile) {
- switch (m) {
- case "engineLoad": this.drawProfilePoint("#ffff00", R.debug.Metrics.metrics[m].act); break;
- case "vObj": this.drawProfilePoint("#339933", R.debug.Metrics.metrics[m].act); break;
- case "rObj": this.drawProfilePoint("#ff00ff", R.debug.Metrics.metrics[m].act); break;
- case "poolLoad" : this.drawProfilePoint("#a0a0ff", R.debug.Metrics.metrics[m].act); break;
+ for (var m in R.debug.Metrics.metrics) {
+ if (R.debug.Metrics.showMetricsWindow) {
+ h += m + ": " + R.debug.Metrics.metrics[m].val + "<br/>";
+ }
+ if (R.debug.Metrics.showMetricsProfile) {
+ switch (m) {
+ case "engineLoad":
+ this.drawProfilePoint("#ffff00", R.debug.Metrics.metrics[m].act);
+ break;
+ case "vObj":
+ this.drawProfilePoint("#339933", R.debug.Metrics.metrics[m].act);
+ break;
+ case "rObj":
+ this.drawProfilePoint("#ff00ff", R.debug.Metrics.metrics[m].act);
+ break;
+ case "poolLoad" :
+ this.drawProfilePoint("#a0a0ff", R.debug.Metrics.metrics[m].act);
+ break;
+ }
}
- }
- }
- if (R.debug.Metrics.showMetricsWindow) {
- $(".items", R.debug.Metrics.metricDisplay).html(h);
- }
- if (R.debug.Metrics.showMetricsProfile) {
- ctx.restore();
- R.debug.Metrics.moveProfiler();
- }
- },
+ }
+ if (R.debug.Metrics.showMetricsWindow) {
+ $(".items", R.debug.Metrics.metricDisplay).html(h);
+ }
+ if (R.debug.Metrics.showMetricsProfile) {
+ ctx.restore();
+ R.debug.Metrics.moveProfiler();
+ }
+ },
+
+ /**
+ * @private
+ */
+ drawProfilePoint:function (color, val) {
+ var ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
+ ctx.strokeStyle = color;
+ try {
+ if (!isNaN(val)) {
+ ctx.beginPath();
+ ctx.moveTo(0, R.debug.Metrics.profiles[color] || 100);
+ ctx.lineTo(1, (100 - val < 1 ? 1 : 100 - val));
+ ctx.closePath();
+ ctx.stroke();
+ R.debug.Metrics.profiles[color] = (100 - val < 1 ? 1 : 100 - val);
+ }
+ } catch (ex) {
+
+ }
+ },
+
+ /**
+ * @private
+ */
+ moveProfiler:function () {
+ var ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
+ var imgData = ctx.getImageData(1, 0, 149, 100);
+ ctx.save();
+ ctx.translate(-1, 0);
+ ctx.putImageData(imgData, 0, 0);
+ ctx.restore();
+ },
- /**
- * @private
- */
- drawProfilePoint: function(color, val) {
- var ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
- ctx.strokeStyle = color;
- try {
- if (!isNaN(val)) {
- ctx.beginPath();
- ctx.moveTo(0, R.debug.Metrics.profiles[color] || 100);
- ctx.lineTo(1, (100 - val < 1 ? 1 : 100 - val));
- ctx.closePath();
- ctx.stroke();
- R.debug.Metrics.profiles[color] = (100 - val < 1 ? 1 : 100 - val);
- }
- } catch(ex) {
-
- }
- },
-
- /**
- * @private
- */
- moveProfiler: function() {
- var ctx = R.debug.Metrics.profileDisplay[0].getContext('2d');
- var imgData = ctx.getImageData(1,0,149,100);
- ctx.save();
- ctx.translate(-1,0);
- ctx.putImageData(imgData, 0, 0);
- ctx.restore();
- },
+ /**
+ * Run the metrics display.
+ * @private
+ * @memberOf R.debug.Metrics
+ */
+ doMetrics:function () {
+ // Output any metrics
+ if (R.debug.Metrics.showMetricsWindow || R.debug.Metrics.showMetricsProfile) {
+ R.debug.Metrics.render();
+ } else if (!R.debug.Metrics.showMetricsWindow && R.debug.Metrics.metricDisplay) {
+ R.debug.Metrics.metricDisplay.remove();
+ R.debug.Metrics.metricDisplay = null;
+ }
+ }
- /**
- * Run the metrics display.
- * @private
- * @memberOf R.debug.Metrics
- */
- doMetrics: function() {
- // Output any metrics
- if (R.debug.Metrics.showMetricsWindow || R.debug.Metrics.showMetricsProfile) {
- R.debug.Metrics.render();
- } else if (!R.debug.Metrics.showMetricsWindow && R.debug.Metrics.metricDisplay) {
- R.debug.Metrics.metricDisplay.remove();
- R.debug.Metrics.metricDisplay = null;
- }
- }
-
});
if (R.engine.Support.checkBooleanParam("metrics")) {
- R.debug.Metrics.showMetrics();
+ R.debug.Metrics.showMetrics();
}
if (R.engine.Support.checkBooleanParam("profile")) {
- R.debug.Metrics.showProfile();
+ R.debug.Metrics.showProfile();
}
View
30 engine/build/debug.metrics.stub.js
@@ -34,27 +34,27 @@
* @static
*/
R.debug.Metrics = Base.extend(/** @scope R.debug.Metrics.prototype */{
- constructor: null,
+ constructor:null,
- toggleMetrics: function() {
- },
+ toggleMetrics:function () {
+ },
- hideMetrics: function() {
- },
+ hideMetrics:function () {
+ },
- setSampleRate: function() {
- },
+ setSampleRate:function () {
+ },
- add: function() {
- },
+ add:function () {
+ },
- remove: function() {
- },
+ remove:function () {
+ },
- update: function() {
- },
+ update:function () {
+ },
- doMetrics: function() {
- }
+ doMetrics:function () {
+ }
});
View
246 engine/build/debug.profiler.js
@@ -35,41 +35,41 @@
* @static
*/
R.debug.Profiler = {
- profileStack: [],
- allProfiles: {},
- profiles: [],
- running: false,
- engineStartTime: 0,
- engineFrameStart: 0
+ profileStack:[],
+ allProfiles:{},
+ profiles:[],
+ running:false,
+ engineStartTime:0,
+ engineFrameStart:0
};
/**
* Start the profiler.
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.start = function() {
- R.debug.Profiler.resetProfiles();
- R.debug.Profiler.running = true;
-
- R.debug.Profiler.engineStartTime = R.Engine.worldTime;
- R.debug.Profiler.engineFrameStart = R.Engine.totalFrames;
+R.debug.Profiler.start = function () {
+ R.debug.Profiler.resetProfiles();
+ R.debug.Profiler.running = true;
+
+ R.debug.Profiler.engineStartTime = R.Engine.worldTime;
+ R.debug.Profiler.engineFrameStart = R.Engine.totalFrames;
};
/**
* Stop the profiler, dumping whatever was being profiled.
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.stop = function() {
- R.debug.Profiler.dump();
- R.debug.Profiler.running = false;
+R.debug.Profiler.stop = function () {
+ R.debug.Profiler.dump();
+ R.debug.Profiler.running = false;
};
/**
* Add a profile monitor to the stack of running profiles. A good way to profile code
* is to use the <tt>try/finally</tt> method so that the profile will be exited even
* if the method returns from multiple points.
-<pre>
- function func() {
+ <pre>
+ function func() {
try {
Profiler.enter("func");
@@ -79,29 +79,31 @@ R.debug.Profiler.stop = function() {
Profiler.exit();
}
}
-</pre>
+ </pre>
*
* @param prof {String} The name of the profile
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.enter = function(prof) {
- if (!R.debug.Profiler.running) { return; }
- var profile = R.debug.Profiler.allProfiles[prof];
- if (profile == null) {
- // Create a monitor
- profile = R.debug.Profiler.allProfiles[prof] = {
- name: prof,
- startMS: R.now(),
- execs: 0,
- totalMS: 0,
- instances: 1,
- pushed: false
- };
- } else {
- profile.startMS = profile.instances == 0 ? R.now() : profile.startMS;
- profile.instances++;
- }
- R.debug.Profiler.profileStack.push(profile);
+R.debug.Profiler.enter = function (prof) {
+ if (!R.debug.Profiler.running) {
+ return;
+ }
+ var profile = R.debug.Profiler.allProfiles[prof];
+ if (profile == null) {
+ // Create a monitor
+ profile = R.debug.Profiler.allProfiles[prof] = {
+ name:prof,
+ startMS:R.now(),
+ execs:0,
+ totalMS:0,
+ instances:1,
+ pushed:false
+ };
+ } else {
+ profile.startMS = profile.instances == 0 ? R.now() : profile.startMS;
+ profile.instances++;
+ }
+ R.debug.Profiler.profileStack.push(profile);
};
/**
@@ -113,34 +115,38 @@ R.debug.Profiler.enter = function(prof) {
* result in a stack overflow.
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.exit = function() {
- if (!R.debug.Profiler.running) { return; }
- if (R.debug.Profiler.profileStack.length == 0) {
- var msg = "Profile stack underflow";
- if (typeof console !== "undefined") { console.error(msg); }
- throw(msg);
- }
-
- var profile = R.debug.Profiler.profileStack.pop();
- profile.endMS = new Date();
- profile.execs++;
- profile.instances--;
- profile.totalMS += profile.instances == 0 ? (profile.endMS.getTime() - profile.startMS.getTime()) : 0;
- if (!profile.pushed) {
- // If we haven't remembered it, do that now
- profile.pushed = true;
- R.debug.Profiler.profiles.push(profile);
- }
+R.debug.Profiler.exit = function () {
+ if (!R.debug.Profiler.running) {
+ return;
+ }
+ if (R.debug.Profiler.profileStack.length == 0) {
+ var msg = "Profile stack underflow";
+ if (typeof console !== "undefined") {
+ console.error(msg);
+ }
+ throw(msg);
+ }
+
+ var profile = R.debug.Profiler.profileStack.pop();
+ profile.endMS = new Date();
+ profile.execs++;
+ profile.instances--;
+ profile.totalMS += profile.instances == 0 ? (profile.endMS.getTime() - profile.startMS.getTime()) : 0;
+ if (!profile.pushed) {
+ // If we haven't remembered it, do that now
+ profile.pushed = true;
+ R.debug.Profiler.profiles.push(profile);
+ }
};
/**
* Reset any currently running profiles and clear the stack.
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.resetProfiles = function() {
- R.debug.Profiler.profileStack = [];
- R.debug.Profiler.allProfiles = {};
- R.debug.Profiler.profiles = [];
+R.debug.Profiler.resetProfiles = function () {
+ R.debug.Profiler.profileStack = [];
+ R.debug.Profiler.allProfiles = {};
+ R.debug.Profiler.profiles = [];
};
/**
@@ -148,71 +154,73 @@ R.debug.Profiler.resetProfiles = function() {
* The profile stack will be cleared after the dump.
* @memberOf R.debug.Profiler
*/
-R.debug.Profiler.dump = function() {
- if (!R.debug.Profiler.running) { return; }
- if (R.debug.Profiler.profileStack.length > 0) {
- // overflow - profiles left in stack
- var rProfs = "";
- for (var x in R.debug.Profiler.profileStack) {
- rProfs += (rProfs.length > 0 ? "," : "") + x;
- }
- R.debug.Console.error("Profile stack overflow. Running profiles: ", rProfs);
- }
-
- var d = new Date();
- d = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
-
- var rev = R.debug.Profiler.profiles.reverse();
- var totalTime = 0;
- var out = "";
- for (var r in rev) {
- var avg = Math.round(rev[r].totalMS / rev[r].execs);
- totalTime += rev[r].totalMS;
- out += "# " + rev[r].name + " | "