1 /**
  2  * The Render Engine
  3  * AbstractSpatialNode
  4  *
  5  * @fileoverview Abstract node class within a broad-phase collision model.
  6  *
  7  * @author: Brett Fattori (brettf@renderengine.com)
  8  *
  9  * @author: $Author: bfattori $
 10  * @version: $Revision: 1555 $
 11  *
 12  * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
 13  *
 14  * Permission is hereby granted, free of charge, to any person obtaining a copy
 15  * of this software and associated documentation files (the "Software"), to deal
 16  * in the Software without restriction, including without limitation the rights
 17  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 18  * copies of the Software, and to permit persons to whom the Software is
 19  * furnished to do so, subject to the following conditions:
 20  *
 21  * The above copyright notice and this permission notice shall be included in
 22  * all copies or substantial portions of the Software.
 23  *
 24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 29  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 30  * THE SOFTWARE.
 31  *
 32  */
 33 
 34 // The class this file defines and its required classes
 35 R.Engine.define({
 36     "class":"R.collision.broadphase.AbstractCollisionNode",
 37     "requires":[
 38         "R.struct.Container"
 39     ]
 40 });
 41 
 42 /**
 43  * @class A node within a broad-phase collision model which contains a list of
 44  *        game objects within it.
 45  *
 46  * @constructor
 47  * @description Abstract class from which broad-phase collision model nodes are derived
 48  */
 49 R.collision.broadphase.AbstractCollisionNode = function () {
 50     "use strict";
 51     return Base.extend(/** @scope R.collision.broadphase.AbstractCollisionNode.prototype */{
 52 
 53         idx:0,
 54         objects:null,
 55         dirty:null,
 56 
 57         /** @private */
 58         constructor:function () {
 59             this.idx = R.collision.broadphase.AbstractCollisionNode.NODE_INDEX++;
 60             this.objects = R.struct.Container.create();
 61             this.dirty = true;
 62         },
 63 
 64         /**
 65          * Get the unique index of this node.
 66          * @return {Number} The index of this node
 67          */
 68         getIndex:function () {
 69             return this.idx;
 70         },
 71 
 72         /**
 73          * Returns <code>true</code> if the node is dirty (has been modified)
 74          * @return {Boolean}
 75          */
 76         isDirty:function () {
 77             return this.dirty;
 78         },
 79 
 80         /**
 81          * Clear the dirty flag after the node has been processed.
 82          */
 83         clearDirty:function () {
 84             this.dirty = false;
 85         },
 86 
 87         /**
 88          * Get a Container which is all objects within this node.
 89          * @return {R.struct.Container} Objects in the node
 90          */
 91         getObjects:function () {
 92             return this.objects;
 93         },
 94 
 95         /**
 96          * Get the count of objects within the node.
 97          * @return {Number}
 98          */
 99         getCount:function () {
100             return this.objects.size();
101         },
102 
103         /**
104          * Add an object to this node.
105          *
106          * @param obj {R.engine.BaseObject} The object to add to this node.
107          */
108         addObject:function (obj) {
109             this.objects.add(obj);
110             this.dirty = true;
111         },
112 
113         /**
114          * Remove an object from this node
115          *
116          * @param obj {R.object.BaseObject} The object to remove from this node
117          */
118         removeObject:function (obj) {
119             this.objects.remove(obj);
120             this.dirty = true;
121         },
122 
123         /**
124          * Returns true if the spatial node contains the point specified.
125          * @param point {R.math.Point2D} The point to check
126          * @return {Boolean}
127          */
128         contains:function (point) {
129             return false;
130         }
131 
132     }, /** @scope R.collision.broadphase.AbstractCollisionNode.prototype */ {
133 
134         /**
135          * Get the class name of this object
136          *
137          * @return {String} "R.collision.broadphase.AbstractCollisionNode"
138          */
139         getClassName:function () {
140             return "R.collision.broadphase.AbstractCollisionNode";
141         },
142 
143         /** @private */
144         resolved:function () {
145             R.collision.broadphase.AbstractCollisionNode.NODE_INDEX = 1;
146         },
147 
148         /** @private */
149         NODE_INDEX:null
150     });
151 }