1 /** 2 * The Render Engine 3 * PooledMathObject 4 * 5 * @fileoverview A library of math primitive objects, including points, vectors, rectangles, 6 * and circles. 7 * 8 * @author: Brett Fattori (brettf@renderengine.com) 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.math.PooledMathObject", 37 "requires":[ 38 "R.engine.PooledObject" 39 ] 40 }); 41 42 /** 43 * @class The base object class which represents a math object within 44 * the engine. All math objects should extend from this class mainly due to 45 * the fact that the engine can switch between pooling the object and running 46 * transiently. 47 * <p/> 48 * Google's Chrome browser seems to operate better with transient objects while 49 * other browsers appear to run better with pooled objects. 50 * <p/> 51 * 52 * @param name {String} The name of the object 53 * @extends R.engine.PooledObject 54 * @constructor 55 * @description Create a math object. 56 */ 57 R.math.PooledMathObject = function () { 58 "use strict"; 59 return R.engine.PooledObject.extend(/** @scope R.math.PooledMathObject.prototype */{ 60 61 /** @private */ 62 constructor:function (name) { 63 if (!R.Engine.options.transientMathObject) { 64 this.base(name); 65 } 66 }, 67 68 /** 69 * Destroy this object instance (remove it from the Engine). The object's release 70 * method is called after destruction so it will be returned to the pool of objects 71 * to be used again. 72 */ 73 destroy:function () { 74 if (!R.Engine.options.transientMathObject) { 75 this.base(); 76 } 77 } 78 79 }, /** @scope R.math.PooledMathObject.prototype */ { 80 81 /** 82 * Similar to a constructor, all pooled objects implement this method. 83 * The <tt>create()</tt> method will either create a new instance, if no object of the object's 84 * class exists within the pool, or will reuse an existing pooled instance of 85 * the object. Either way, the constructor for the object instance is called so that 86 * instance creation can be maintained in the constructor. 87 * <p/> 88 * Usage: <tt>var obj = [ObjectClass].create(arg1, arg2, arg3...);</tt> 89 * 90 * @memberOf R.math.PooledMathObject 91 */ 92 create:function () { 93 if (R.Engine.options.transientMathObject) { 94 return new this(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9], arguments[10], arguments[11], arguments[12], arguments[13], arguments[14]); 95 } 96 else { 97 return R.engine.PooledObject.create.apply(this, arguments); 98 } 99 }, 100 101 /** 102 * Get the class name of this object 103 * 104 * @return {String} "R.math.PooledMathObject" 105 */ 106 getClassName:function () { 107 return "R.math.PooledMathObject"; 108 } 109 110 }); 111 112 }