Permalink
Browse files

Cleaned up reference to arguments.callee which breaks strict mode in …

…base.js

Added methods to check for undefined and null in the R. scope
Reworking jasmine tests
  • Loading branch information...
1 parent 3f5e663 commit 5202435291c9209d3ebd2a0d3d2d2f7e22a6c326 @bfattori committed Mar 8, 2013
@@ -51,27 +51,28 @@ R.debug.ConsoleRef = Base.extend(/** @scope R.debug.ConsoleRef.prototype */{
return out;
},
- cleanup:function (o) {
- if (typeof o === "undefined") {
+ cleanup:function (sourceObject) {
+ var str, element;
+ if (R.isUndefined(sourceObject)) {
return "";
- } else if (o === null) {
+ } else if (R.isNull(sourceObject)) {
return "null";
- } else if (typeof o == "function") {
+ } else if (R.isFunction(sourceObject)) {
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]);
+ } else if (R.isArray(sourceObject)) { // An array
+ str = "[";
+ for (element in sourceObject) {
+ str += (str.length > 1 ? "," : "") + this.cleanup(sourceObject[element]);
}
- return s + "]";
- } else if (typeof o === "object") {
- var s = "{\n";
- for (var e in o) {
- s += e + ": " + this.cleanup(o[e]) + "\n";
+ return str + "]";
+ } else if (typeof sourceObject === "object") {
+ str = "{\n";
+ for (element in sourceObject) {
+ str += element + ": " + this.cleanup(sourceObject[element]) + "\n";
}
- return s + "}\n";
+ return str + "}\n";
} else {
- return o.toString();
+ return sourceObject.toString();
}
},
@@ -169,13 +169,34 @@ R.isNumber = function (obj) {
};
/**
+ * Check if the given object is undefined. Cannot check properties
+ * of an object unless the object is known to be defined.
+ * @param obj {Object} The object to test
+ * @returns {boolean}
+ * @memberOf R
+ */
+R.isUndefined = function(obj) {
+ return typeof obj === "undefined";
+};
+
+/**
+ * Check if the given object is null.
+ * @param obj {Object} The object to test
+ * @returns {boolean}
+ * @memberOf R
+ */
+R.isNull = function(obj) {
+ return obj === null;
+};
+
+/**
* Test if the object is undefined, null, or a string and is empty
* @param obj {Object} The object to test
* @return {Boolean}
* @memberOf R
*/
R.isEmpty = function (obj) {
- return typeof obj === "undefined" || obj === null || (R.isString(obj) && $.trim(obj) === "");
+ return R.isUndefined(obj) || R.isNull(obj) || (R.isString(obj) && $.trim(obj) === "");
};
/**
View
@@ -0,0 +1,30 @@
+// This file is used to define the namespaces available in the R context
+// DO NOT INCLUDE IN COMPILATION OF ENGINE RUNTIME!!
+R.debug = {};
+R.lang = {};
+R.struct = {};
+R.math = {};
+R.engine = {};
+R.collision = {};
+R.collision.broadphase = {};
+R.components = {};
+R.components.input = {};
+R.components.transform = {};
+R.components.logic = {};
+R.components.logic.behaviors = {};
+R.components.collision = {};
+R.components.render = {};
+R.components.physics = {};
+R.objects = {};
+R.particles = {};
+R.physics = {};
+R.rendercontexts = {};
+R.resources = {};
+R.resources.loaders = {};
+R.resources.types = {};
+R.sound = {};
+R.storage = {};
+R.text = {};
+R.ui = {};
+R.util = {};
+R.util.console = {};
@@ -0,0 +1,157 @@
+/**
+ * The Render Engine
+ * Bounds
+ *
+ * @fileoverview A component which stores the state of multiple bounding types, such as OBB, AABB, and WBB.
+ *
+ * @author: Brett Fattori (brettf@renderengine.com)
+ * @author: $Author: bfattori $
+ * @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
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+// The class this file defines and its required classes
+R.Engine.define({
+ "class":"R.components.logic.Bounds",
+ "requires":[
+ "R.components.Logic",
+ "R.engine.GameObject",
+ "R.math.Circle2D",
+ "R.math.Math2D"
+ ]
+});
+
+/**
+ * @class .
+ *
+ * @param name {String} The name of the component
+ * @param [priority=1.0] {Number} The priority of this component
+ * @extends R.components.Logic
+ * @constructor
+ * @description Creates a <tt>R.components.Host</tt> which can contain {@link R.engine.GameObject GameObjects}.
+ * This allows a component to embed other game objects within it. Each time the
+ * component is executed, each game object will be given a chance to update as well.
+ */
+R.components.logic.Bounds = function () {
+ "use strict";
+ return R.components.Logic.extend(/** @scope R.components.logic.Bounds.prototype */{
+
+ bBox:null,
+ AABB:null,
+ wBox:null,
+ wCircle:null,
+
+ /**
+ * @private
+ */
+ constructor:function (name, priority) {
+ this.base(name, priority || 1.0);
+ this.objects = R.struct.HashContainer.create();
+ },
+
+ /**
+ * Releases the component back into the object pool. See {@link R.engine.PooledObject#release}
+ * for more information.
+ */
+ release:function () {
+ this.base();
+ this.objects = null;
+ },
+
+ /**
+ * Destroys the container which refers to the game objects.
+ */
+ destroy:function () {
+ this.objects.destroy();
+ this.base();
+ },
+
+ /**
+ * Add a {@link R.engine.GameObject} to the component to be processed when
+ * this component is executed. Objects will be updated in the order in
+ * which they are added.
+ *
+ * @param name {String} A unique name to refer to the object by
+ * @param obj {R.engine.GameObject} The game object reference
+ */
+ add:function (name, obj) {
+ Assert((obj instanceof R.engine.GameObject), "You can only add GameObject to a Host component");
+ this.objects.add(name.toUpperCase(), obj);
+ },
+
+ /**
+ * Retrieve the {@link R.engine.GameObject} that is associated with the
+ * given name from the component.
+ *
+ * @param name {String} The unique name of the object
+ * @return {R.engine.GameObject}
+ */
+ get:function (name) {
+ return this.objects.get(name.toUpperCase());
+ },
+
+ /**
+ * Remove the game object from the component.
+ *
+ * @param obj {R.engine.GameObject} The game object reference
+ * @return {R.engine.GameObject} The object which was removed
+ */
+ remove:function (obj) {
+ return this.objects.remove(obj);
+ },
+
+ /**
+ * Update each of the game objects within this component. The order
+ * in which game objects are updated is equivalent to the order in which
+ * the objects were added.
+ *
+ * @param renderContext {R.rendercontexts.AbstractRenderContext} The rendering context
+ * @param time {Number} The engine time in milliseconds
+ * @param dt {Number} The delta between the world time and the last time the world was updated
+ * in milliseconds.
+ */
+ execute:function (renderContext, time, dt) {
+ var objs = this.objects.getObjects();
+ for (var c in objs) {
+
+ // Make sure the game object's render context matches
+ // this component's game object's context
+ if (objs[c].getRenderContext() == null) {
+ objs[c].setRenderContext(renderContext);
+ R.debug.Console.info(this.getGameObject().getId() + "[" + this.getName() + "]: SetRenderContext '" + renderContext.getId() + "'");
+ }
+
+ objs[c].update(renderContext, time, dt);
+ }
+ }
+ }, /** @scope R.components.logic.Host.prototype */{
+ /**
+ * Get the class name of this object
+ *
+ * @return {String} "R.components.logic.Host"
+ */
+ getClassName:function () {
+ return "R.components.logic.Host";
+ }
+ });
+}
@@ -280,6 +280,7 @@ R.components.Transform2D = function () {
* in milliseconds.
*/
execute:function (renderContext, time, dt) {
+ // TODO: This should really be in a render component only
renderContext.setPosition(this.getRenderPosition());
renderContext.setRotation(this.getRenderRotation());
renderContext.setScale(this.scale.x, this.scale.y);
@@ -306,4 +307,4 @@ R.components.Transform2D = function () {
return "R.components.Transform2D";
}
});
-}
+};
View
@@ -4,7 +4,8 @@
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
var Base = function () {
- arguments.length && (this == window ? Base.prototype.extend.call(arguments[0], arguments.callee.prototype) : this.extend(arguments[0]))
+ //arguments.length && (this == window ? Base.prototype.extend.call(arguments[0], arguments.callee.prototype) : this.extend(arguments[0]))
+ this.extend(arguments[0]);
};
Base.version = "1.0.2";
Base.prototype = {extend:function (b, c) {
View
@@ -5,13 +5,13 @@
*/
var Base = function () {
- if (arguments.length) {
- if (this == window) { // cast an object to this class
- Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
- } else {
+// if (arguments.length) {
+// if (this == window) { // cast an object to this class
+// Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
+// } else {
this.extend(arguments[0]);
- }
- }
+// }
+// }
};
Base.version = "1.0.2";
View
@@ -355,7 +355,8 @@ R.loadGame = function (fileName, className, description) {
License: http://creativecommons.org/licenses/LGPL/2.1/
*/
var Base = function () {
- arguments.length && (this == window ? Base.prototype.extend.call(arguments[0], arguments.callee.prototype) : this.extend(arguments[0]))
+ //arguments.length && (this == window ? Base.prototype.extend.call(arguments[0], arguments.callee.prototype) : this.extend(arguments[0]))
+ this.extend(arguments[0]);
};
Base.version = "1.0.2";
Base.prototype = {extend:function (b, c) {
@@ -58,9 +58,12 @@ R.struct.Container = function () {
/**
* @private
*/
- constructor:function (containerName) {
+ constructor:function (containerName, initial) {
this.base(containerName || "Container");
this.objects = [];
+ if (!R.isUndefined(initial)) {
+ this.addAll(initial);
+ }
},
/**
View
@@ -0,0 +1,12 @@
+server: http://localhost:9876
+
+load:
+ - test/jasmine-1.1.0.js
+ - test/JasmineAdapter-1.1.2.js
+ - engine/runtime/engine.js
+
+test:
+ - test/spec/engineSpec.js
+
+proxy:
+ - {matcher: "test/*", server: "http://localhost/renderengine/"}
@@ -1,20 +0,0 @@
-Copyright (c) 2008-2011 Pivotal Labs
-
-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 AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Oops, something went wrong.

0 comments on commit 5202435

Please sign in to comment.