Reorg of packages.
authordsc <david.schoonover@gmail.com>
Wed, 10 Nov 2010 06:22:01 +0000 (22:22 -0800)
committerdsc <david.schoonover@gmail.com>
Wed, 10 Nov 2010 06:22:01 +0000 (22:22 -0800)
32 files changed:
index.php
src/Y/type.js
src/Y/y-core.js
src/portal/loop/cooldown.js [moved from src/portal/util/cooldown.js with 100% similarity]
src/portal/loop/eventloop.js [moved from src/portal/util/eventloop.js with 100% similarity]
src/portal/loop/fps.js [moved from src/portal/util/fps.js with 100% similarity]
src/portal/math/vec.js
src/portal/path.js [deleted file]
src/portal/portal.js [deleted file]
src/portal/shape.js [deleted file]
src/portal/shape/circle.js [new file with mode: 0644]
src/portal/shape/line.js [new file with mode: 0644]
src/portal/shape/polygon.js [new file with mode: 0644]
src/portal/shape/rect.js [new file with mode: 0644]
src/portal/shape/shape.js [new file with mode: 0644]
src/portal/transform.js [deleted file]
src/portal/util/tree/pointquadtree.js [moved from src/portal/util/pointquadtree.js with 100% similarity]
src/portal/util/tree/quadtree.js [moved from src/portal/util/quadtree.js with 100% similarity]
src/portal/util/tree/rbtree.js [moved from src/portal/util/rbtree.js with 100% similarity]
src/tanks/calc.js [moved from src/tanks/util/calc.js with 100% similarity]
src/tanks/game/map.game.js [moved from src/tanks/game/map.js with 100% similarity]
src/tanks/lttl.js [deleted file]
src/tanks/main.js [new file with mode: 0644]
src/tanks/map/level.js [moved from src/tanks/game/level.js with 100% similarity]
src/tanks/map/loc.js [moved from src/portal/util/loc.js with 95% similarity]
src/tanks/map/pathmap.js [moved from src/tanks/util/pathmap.js with 100% similarity]
src/tanks/ui.js [deleted file]
src/tanks/ui.main.js [new file with mode: 0644]
src/tanks/ui/grid.js [moved from src/tanks/util/grid.js with 100% similarity]
src/tanks/ui/player.js [moved from src/tanks/game/player.js with 100% similarity]
tanks.php [new file with mode: 0644]
test/math/index.php

index 330dc95..8b6593d 100644 (file)
--- a/index.php
+++ b/index.php
 
 <div id="scripts">
     <!--[if IE]><script type="text/javascript" src="lib/excanvas.min.js"></script><![endif]-->
-<?php
-$scripts = array(
-    "lib/jquery-1.4.3.js",
-    "lib/jquery.sparkline.min.js",
-    "lib/jquery.hotkeys.js",
-    
-    // "http://static.ukijs.org/pkg/0.3.8/uki.js",
-    // "http://static.ukijs.org/pkg/0.3.8/uki-more.js",
-    
-    "src/lessly/future.js",
-    
-    "src/Y/y.js.php",
-    "src/Y/modules/y.event.js",
-    
-    "src/evt/evt.class.js",
-    
-    "src/portal/layer.js",
-    "src/portal/shape.js",
-    
-    "src/portal/math/math.js",
-    "src/portal/math/vec.js",
-    "src/portal/math/line.js",
-    
-    "src/portal/util/loc.js",
-    "src/portal/util/quadtree.js",
-    "src/portal/util/rbtree.js",
-    
-    "src/portal/util/eventloop.js",
-    "src/portal/util/fps.js",
-    "src/portal/util/cooldown.js",
-    
-    "src/tanks/globals.js",
-    "src/tanks/util/calc.js",
-    "src/tanks/util/grid.js",
-    "src/tanks/util/pathmap.js",
-    
-    "src/tanks/game/level.js",
-    "src/tanks/game/game.js",
-    "src/tanks/game/map.js",
-    
-    "src/tanks/thing/thing.js",
-    "src/tanks/thing/bullet.js",
-    "src/tanks/thing/tank.js",
-    "src/tanks/game/player.js",
-    
-    "src/tanks/lttl.js",
-    "src/tanks/ui.js"
-    
-);
-
-function js($src) {
-    echo "    <script src=\"$src\" type=\"text/javascript\"></script>\n";
-}
-
-foreach ($scripts as $s) js($s);
-?>
+<?php require "tanks.php"; Tanks::writeTags( Tanks::ALL_SCRIPTS ); ?>
 </div>
 
 </body>
index c23970c..11d7360 100644 (file)
@@ -15,16 +15,9 @@ function type_of(obj){
 }
 
 function isFunction(obj) { return type_of(obj) === "function"; }
-
 function isString(obj)   { return type_of(obj) === "string"; }
-
 function isNumber(obj)   { return type_of(obj) === "number"; }
-
-
-// A crude way of determining if an object is a window
-function isWindow( obj ) {
-       return obj && typeof obj === "object" && "setInterval" in obj;
-}
+function isWindow( obj ) { return obj && typeof obj === "object" && "setInterval" in obj; }
 
 function isPlainObject( obj ){
     // Must be an Object.
@@ -42,7 +35,6 @@ function isPlainObject( obj ){
     
     // Own properties are enumerated firstly, so to speed up,
     // if last one is own, then all properties are own.
-    
     var key;
     for ( key in obj ) {}
     
index dced427..ec51cba 100644 (file)
@@ -4,9 +4,10 @@ Y.set    = dset;
 Y.attr   = dattr;
 Y.extend = extend;
 
-Y.isFunction = isFunction;
-Y.isString = isString;
-Y.isNumber = isNumber;
+Y.isString      = isString;
+Y.isNumber      = isNumber;
+Y.isFunction    = isFunction;
+Y.isArray       = isArray;
 Y.isPlainObject = isPlainObject;
 
 
index 7ac8e02..76421f6 100644 (file)
@@ -4,14 +4,12 @@
 math.Vec = new Y.Class('Vec', [], {
     
     init : function init(x, y){
-        if ( Array.isArray(x) ) {
-            y = x[1];
-            x = x[0];
-        }
-        
         this.length = 2;
-        this.x = this[0] = x;
-        this.y = this[1] = y;
+        
+        if ( x instanceof Array ) {
+            y = x[1]; x = x[0];
+        }
+        this.setXY(x,y);
     },
     
     equals : function equals(b){
@@ -22,32 +20,30 @@ math.Vec = new Y.Class('Vec', [], {
         return new math.Vec(this.x, this.y);
     },
     
-    scale : function scale(s){
-        this.x *= s;
-        this.y *= s;
+    setXY : function setXY(x,y){
+        this.x = this[0] = x;
+        this.y = this[1] = y;
         return this;
     },
     
-    invert : function invert(){
-        this.x = -this.x;
-        this.y = -this.y;
-        return this;
+    add : function add(b){
+        return this.setXY(this.x+b.x, this.y+b.y);
     },
     
-    normalize : function normalize(){
-        return this.scale(1 / this.magnitude());
+    subtract : function subtract(b){
+        return this.setXY(this.x-b.x, this.y-b.y);
     },
     
-    add : function add(b){
-        this.x += b.x;
-        this.y += b.y;
-        return this;
+    scale : function scale(s){
+        return this.setXY(this.x*s, this.y*s);
     },
     
-    subtract : function subtract(b){
-        this.x -= b.x;
-        this.y -= b.y;
-        return this;
+    invert : function invert(){
+        return this.setXY(-this.x, -this.y);
+    },
+    
+    normalize : function normalize(){
+        return this.scale(1 / this.magnitude());
     },
     
     magnitude : function magnitude(){
diff --git a/src/portal/path.js b/src/portal/path.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/portal/portal.js b/src/portal/portal.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/portal/shape.js b/src/portal/shape.js
deleted file mode 100644 (file)
index 50d3895..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-Shape = new Y.Class('Shape', Layer, {
-    _cssClasses : 'portal layer shape',
-    fillStyle   : 'rgba(231,48,117, 1)',
-    strokeStyle : 'transparent',
-    lineWidth   : 0,
-    
-    _calcDimension : function _calcDimension(which, values){
-        values.unshift(0);
-        var self = this
-        ,   neg = -1 * Math.min.apply(Math, values)
-        // ,   pos = Math.min(0, Math.max.apply(Max, values) - max)
-        ;
-        
-        self.negBleed.attr(which, neg);
-        // self.posBleed.attr(which, pos);
-        
-        return values.map(function(v, i){
-                return (self[which+i] = v);
-            });
-    }
-    
-});
-
-
-Line = new Y.Class('Line', Shape, {
-    _cssClasses : 'portal layer shape line',
-    
-    useCanvasScaling : true,
-    fillStyle   : 'transparent',
-    strokeStyle : "#000000",
-    lineWidth   : 1,
-    
-    drawDefinitionPoints : false,
-    invertY : false,
-    
-    
-    init : function initLine(x,y){
-        Layer.init.call(this);
-        
-        this.sublayer = jQuery('<div style="overflow:hidden" />')
-            .append(this.canvas)
-            .appendTo(this.layer);
-        
-        this.x2 = x; this.y2 = y;
-        this.position(0,0);
-    },
-    
-    position : function position(left, top){
-        if (top === undefined && left === undefined)
-            return this.line.p1;
-        
-        var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
-        
-        this.x1 = pos.left; this.x2 += this.x1;
-        this.y1 = pos.top;  this.y2 += this.y1;
-        
-        this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
-        
-        return this;
-    },
-    
-    origin : function origin(x,y){
-        var o = this.transform.origin;
-        if (arguments.length === 0)
-            return o.absolute(this.layerWidth, this.layerHeight);
-        
-        o.x = x;
-        o.y = y;
-        this.ctx.translate(x,y);
-        this.dirty = true;
-        return this._applyTransforms();
-    },
-    
-    appendTo : function appendTo(parent){
-        var r = Layer.prototype.appendTo.call(this, parent);
-        this._fixSize();
-        return r;
-    },
-    
-    _fixSize : function _fixSize(){
-        var p  = this.parent
-        ,   pw = p.canvasWidth,    ph = p.canvasHeight
-        ,   w  = this.canvasWidth, h  = this.canvasHeight
-        ;
-        
-        if (w !== pw) {
-            this.width(pw);
-            this.sublayer.width(pw);
-        }
-        if (h !== ph) {
-            this.height(ph);
-            this.sublayer.height(ph);
-        }
-        return this;
-    },
-    
-    drawShape : function drawShape(ctx){
-        this._fixSize();
-        var x1,y1, x2,y2, t = this.transform.translate
-        ,   line = this.line, p1 = line.p1, p2 = line.p2
-        ,   minW = -t.x, minH = -t.y
-        ,   maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
-        ;
-        
-        x1 = minW; y1 = line.calcY(x1);
-        if (isNaN(y1) || !isFinite(y1)) {
-            y1 = minH; x1 = line.calcX(y1);
-        }
-        
-        x2 = maxW; y2 = line.calcY(x2);
-        if (isNaN(y2) || !isFinite(y2)) {
-            y2 = maxH; x2 = line.calcX(y2);
-        }
-        
-        if (this.invertY){
-            y1 = -y1;
-            y2 = -y2;
-        }
-        
-        try {
-            ctx.moveTo(x1,y1);
-            ctx.lineTo(x2,y2);
-            ctx.stroke();
-            ctx.closePath();
-        } catch(e) {
-            console.error(this+'.drawShape()');
-            console.log('  points:', x1,y1, ' ', x2,y2);
-            console.log('  bounds:', minW,minH, ' ', maxW,maxH);
-            console.log('  ::', this, line);
-        }
-        
-        // Show definition points
-        if ( this.drawDefinitionPoints ) {
-            this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
-            this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
-        }
-    },
-    
-    
-    toString : function toString(){
-        return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
-    }
-    
-    
-});
-Line.fromPoints = function fromPoints(x1,y1, x2,y2){
-    return new Line(x2-x1, y2-y1).position(x1,y1);
-};
-
-
-
-Rect = new Y.Class('Rect', Shape, {
-    _cssClasses : 'portal layer shape rect',
-    
-    init : function initRect(w, h){
-        Layer.init.call(this);
-        
-        this.width(w)
-            .height(h);
-            // .origin(w/2, h/2);
-    },
-    
-    drawShape : function drawShape(ctx){
-        ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
-        ctx.fill();
-    }
-    
-});
-
-Circle = new Y.Class('Circle', Shape, {
-    _cssClasses : 'portal layer shape circle',
-    
-    init : function initCircle(radius){
-        Layer.init.call(this);
-        
-        var d = radius * 2;
-        this.radius = this.negBleed.x = this.negBleed.y = radius;
-        this.width(d).height(d);
-            // .origin(radius,radius);
-    },
-    
-    drawShape : function drawShape(ctx){
-        var r  = this.radius;
-        ctx.arc(0,0, r, 0, Math.PI*2, false);
-        ctx.fill();
-        ctx.stroke();
-    }
-    
-});
-
-Polygon = new Y.Class('Polygon', Shape, {
-    _cssClasses : 'portal layer shape polygon',
-    
-    /**
-     * Expects two arrays of coordinate-halfs, which could be zipped
-     * together to make the numbered coordinates.
-     * x0 and y0 will always be 0.
-     */
-    init : function initPolygon(xs, ys){
-        Layer.init.call(this);
-        
-        var xs = this._calcDimension('x', xs)
-        ,   ys = this._calcDimension('y', ys)
-        ,   w  = Math.max.apply(Math, xs)
-        ,   h  = Math.max.apply(Math, ys)
-        ;
-        
-        this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
-        this.width(w)
-            .height(h);
-            // .origin(w/2, h/2);
-    },
-    
-    drawShape : function drawShape(ctx){
-        this.points.forEach(function(loc, i){
-            ctx.lineTo(loc.x, loc.y);
-        });
-        ctx.fill();
-    }
-});
-
-
-Triangle = new Y.Class('Triangle', Polygon, {
-    _cssClasses : 'portal layer shape polygon triangle',
-    
-    init : function initTriangle(x1,y1, x2,y2){
-        Polygon.init.call(this, [x1,x2], [y1,y2]);
-    },
-    
-    circumcenter : function circumcenter(){
-        var offX = this.offsetX, offY = this.offsetY
-        ,   x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
-        ,   x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
-        
-        ,   D = 2 * (x1*y2 - y1*x2)
-        ,   B = Math.pow(x1,2) + Math.pow(y1,2)
-        ,   C = Math.pow(x2,2) + Math.pow(y2,2)
-        ;
-        return { 'x' : offX + (y2*B - y1*C)/D
-               , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
-               };
-    },
-});
-
-Quad = new Y.Class('Quad', Polygon, {
-    _cssClasses : 'portal layer shape polygon quad',
-    
-    init : function initQuad(x1,y1, x2,y2, x3,y3){
-        Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
-    }
-    
-});
diff --git a/src/portal/shape/circle.js b/src/portal/shape/circle.js
new file mode 100644 (file)
index 0000000..10e824f
--- /dev/null
@@ -0,0 +1,21 @@
+
+Circle = new Y.Class('Circle', Shape, {
+    _cssClasses : 'portal layer shape circle',
+    
+    init : function initCircle(radius){
+        Layer.init.call(this);
+        
+        var d = radius * 2;
+        this.radius = this.negBleed.x = this.negBleed.y = radius;
+        this.width(d).height(d);
+            // .origin(radius,radius);
+    },
+    
+    drawShape : function drawShape(ctx){
+        var r  = this.radius;
+        ctx.arc(0,0, r, 0, Math.PI*2, false);
+        ctx.fill();
+        ctx.stroke();
+    }
+    
+});
diff --git a/src/portal/shape/line.js b/src/portal/shape/line.js
new file mode 100644 (file)
index 0000000..fe9ddcd
--- /dev/null
@@ -0,0 +1,130 @@
+
+Line = new Y.Class('Line', Shape, {
+    _cssClasses : 'portal layer shape line',
+    
+    useCanvasScaling : true,
+    fillStyle   : 'transparent',
+    strokeStyle : "#000000",
+    lineWidth   : 1,
+    
+    drawDefinitionPoints : false,
+    invertY : false,
+    
+    
+    init : function initLine(x,y){
+        Layer.init.call(this);
+        
+        this.sublayer = jQuery('<div style="overflow:hidden" />')
+            .append(this.canvas)
+            .appendTo(this.layer);
+        
+        this.x2 = x; this.y2 = y;
+        this.position(0,0);
+    },
+    
+    position : function position(left, top){
+        if (top === undefined && left === undefined)
+            return this.line.p1;
+        
+        var pos = Y.isPlainObject(top) ? top : {'top':top, 'left':left};
+        
+        this.x1 = pos.left; this.x2 += this.x1;
+        this.y1 = pos.top;  this.y2 += this.y1;
+        
+        this.line = new math.Line(this.x1,this.y1, this.x2,this.y2, (this.line||{}).tdist);
+        
+        return this;
+    },
+    
+    origin : function origin(x,y){
+        var o = this.transform.origin;
+        if (arguments.length === 0)
+            return o.absolute(this.layerWidth, this.layerHeight);
+        
+        o.x = x;
+        o.y = y;
+        this.ctx.translate(x,y);
+        this.dirty = true;
+        return this._applyTransforms();
+    },
+    
+    appendTo : function appendTo(parent){
+        var r = Layer.prototype.appendTo.call(this, parent);
+        this._fixSize();
+        return r;
+    },
+    
+    _fixSize : function _fixSize(){
+        var p  = this.parent
+        ,   pw = p.canvasWidth,    ph = p.canvasHeight
+        ,   w  = this.canvasWidth, h  = this.canvasHeight
+        ;
+        
+        if (w !== pw) {
+            this.width(pw);
+            this.sublayer.width(pw);
+        }
+        if (h !== ph) {
+            this.height(ph);
+            this.sublayer.height(ph);
+        }
+        return this;
+    },
+    
+    drawShape : function drawShape(ctx){
+        this._fixSize();
+        var x1,y1, x2,y2
+        ,   line = this.line, p1 = line.p1, p2 = line.p2
+        ,   t = this.transform.translate
+        ,   minW = -t.x, minH = -t.y
+        ,   maxW = this.canvasWidth+minW, maxH = this.canvasHeight+minH
+        ;
+        
+        // We need endpoints at the edges of the viewport to draw the full line.
+        x1 = minW; y1 = line.calcY(x1);
+        if (isNaN(y1) || !isFinite(y1)) {
+            y1 = minH; x1 = line.calcX(y1);
+        }
+        
+        x2 = maxW; y2 = line.calcY(x2);
+        if (isNaN(y2) || !isFinite(y2)) {
+            y2 = maxH; x2 = line.calcX(y2);
+        }
+        
+        if (this.invertY){
+            y1 = -y1;
+            y2 = -y2;
+        }
+        
+        try {
+            ctx.moveTo(x1,y1);
+            ctx.lineTo(x2,y2);
+            ctx.stroke();
+            ctx.closePath();
+        } catch(e) {
+            if (window.console) {
+                console.error(this+'.drawShape()');
+                console.log('  points:', x1,y1, ' ', x2,y2);
+                console.log('  bounds:', minW,minH, ' ', maxW,maxH);
+                console.log('  ::', this, line);
+            }
+        }
+        
+        // Show definition points
+        if ( this.drawDefinitionPoints ) {
+            this.point(p1.x,p1.y, 'rgba(69,150,255,0.4)');
+            this.point(p2.x,p2.y, 'rgba(69,150,255,0.4)');
+        }
+    },
+    
+    
+    toString : function toString(){
+        return this.className+'['+this.x1+','+this.y1+', '+this.x2+','+this.y2+']';
+    }
+    
+    
+});
+Line.fromPoints = function fromPoints(x1,y1, x2,y2){
+    return new Line(x2-x1, y2-y1).position(x1,y1);
+};
+
diff --git a/src/portal/shape/polygon.js b/src/portal/shape/polygon.js
new file mode 100644 (file)
index 0000000..a2cf377
--- /dev/null
@@ -0,0 +1,63 @@
+
+Polygon = new Y.Class('Polygon', Shape, {
+    _cssClasses : 'portal layer shape polygon',
+    
+    /**
+     * Expects two arrays of coordinate-halfs, which could be zipped
+     * together to make the numbered coordinates.
+     * x0 and y0 will always be 0.
+     */
+    init : function initPolygon(xs, ys){
+        Layer.init.call(this);
+        
+        var xs = this._calcDimension('x', xs)
+        ,   ys = this._calcDimension('y', ys)
+        ,   w  = Math.max.apply(Math, xs)
+        ,   h  = Math.max.apply(Math, ys)
+        ;
+        
+        this.points = Y(xs).zip(ys).map(Loc.instantiate, Loc);
+        this.width(w)
+            .height(h);
+            // .origin(w/2, h/2);
+    },
+    
+    drawShape : function drawShape(ctx){
+        this.points.forEach(function(loc, i){
+            ctx.lineTo(loc.x, loc.y);
+        });
+        ctx.fill();
+    }
+});
+
+
+Triangle = new Y.Class('Triangle', Polygon, {
+    _cssClasses : 'portal layer shape polygon triangle',
+    
+    init : function initTriangle(x1,y1, x2,y2){
+        Polygon.init.call(this, [x1,x2], [y1,y2]);
+    },
+    
+    circumcenter : function circumcenter(){
+        var offX = this.offsetX, offY = this.offsetY
+        ,   x1 = this.x1 - offX, y1 = -1 * (this.y1 - offY) // remember, DOM is Y-inverted
+        ,   x2 = this.x2 - offX, y2 = -1 * (this.y2 - offY) // which affects the signs
+        
+        ,   D = 2 * (x1*y2 - y1*x2)
+        ,   B = Math.pow(x1,2) + Math.pow(y1,2)
+        ,   C = Math.pow(x2,2) + Math.pow(y2,2)
+        ;
+        return { 'x' : offX + (y2*B - y1*C)/D
+               , 'y' : offY + (x1*C - x2*B)/D * -1 // fix inverted Y-axis
+               };
+    },
+});
+
+Quad = new Y.Class('Quad', Polygon, {
+    _cssClasses : 'portal layer shape polygon quad',
+    
+    init : function initQuad(x1,y1, x2,y2, x3,y3){
+        Polygon.init.call(this, [x1,x2,x3], [y1,y2,y3]);
+    }
+    
+});
diff --git a/src/portal/shape/rect.js b/src/portal/shape/rect.js
new file mode 100644 (file)
index 0000000..ef21d2d
--- /dev/null
@@ -0,0 +1,18 @@
+
+Rect = new Y.Class('Rect', Shape, {
+    _cssClasses : 'portal layer shape rect',
+    
+    init : function initRect(w, h){
+        Layer.init.call(this);
+        
+        this.width(w)
+            .height(h);
+            // .origin(w/2, h/2);
+    },
+    
+    drawShape : function drawShape(ctx){
+        ctx.rect(0,0, this.canvasWidth,this.canvasHeight);
+        ctx.fill();
+    }
+    
+});
diff --git a/src/portal/shape/shape.js b/src/portal/shape/shape.js
new file mode 100644 (file)
index 0000000..609a74a
--- /dev/null
@@ -0,0 +1,23 @@
+Shape = new Y.Class('Shape', Layer, {
+    _cssClasses : 'portal layer shape',
+    fillStyle   : 'rgba(231,48,117, 1)',
+    strokeStyle : 'transparent',
+    lineWidth   : 0,
+    
+    _calcDimension : function _calcDimension(which, values){
+        values.unshift(0);
+        var self = this
+        ,   neg = -1 * Math.min.apply(Math, values)
+        // ,   pos = Math.min(0, Math.max.apply(Max, values) - max)
+&n