From 63712518dcfca6e48a3f1ff0053f3c1ed0944237 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Thu, 31 Jan 2013 22:51:35 +0000 Subject: [PATCH] optimized sphere and blocktype --- src/main/javascript/drone/blocktype.js | 6 ++-- src/main/javascript/drone/drone.js | 45 ++++++++++++++++++-------- src/main/javascript/drone/sphere.js | 9 ++++-- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/main/javascript/drone/blocktype.js b/src/main/javascript/drone/blocktype.js index b5efdbf..f5cab02 100644 --- a/src/main/javascript/drone/blocktype.js +++ b/src/main/javascript/drone/blocktype.js @@ -314,7 +314,7 @@ load(__folder + "drone.js"); var bmbg = null; if (typeof bg != "undefined") bmbg = this._getBlockIdAndMeta(bg); - + var world = this._getWorld(); var lines = message.split("\n"); var lineCount = lines.length; for (var h = 0;h < lineCount; h++) { @@ -330,12 +330,12 @@ load(__folder + "drone.js"); } var charWidth = bits.width; if (typeof bg != "undefined") - this.cuboidX(bmbg[0],bmbg[1],charWidth,7,1); + this.cuboidX(bmbg[0],bmbg[1],world,charWidth,7,1); for (var j = 0;j < bits.pixels.length;j++){ this.chkpt('btbl'); var x = bits.pixels[j][0]; var y = bits.pixels[j][1]; - this.up(6-y).right(x).cuboidX(bmfg[0],bmfg[1]); + this.up(6-y).right(x).cuboidX(bmfg[0],bmfg[1],world); this.move('btbl'); } this.right(charWidth-1); diff --git a/src/main/javascript/drone/drone.js b/src/main/javascript/drone/drone.js index 0ed1afa..44cd8e9 100644 --- a/src/main/javascript/drone/drone.js +++ b/src/main/javascript/drone/drone.js @@ -393,9 +393,10 @@ var Drone = Drone || { }; /* - faster cuboid because blockid and meta must be provided + faster cuboid because blockid, meta and world must be provided + use this method when you need to repeatedly place blocks */ - Drone.prototype.cuboidX = function(blockId, meta, w, h, d){ + Drone.prototype.cuboidX = function(blockId, meta, world, w, h, d){ if (typeof h == "undefined") h = 1; @@ -405,9 +406,6 @@ var Drone = Drone || { w = 1; var that = this; var dir = this.dir; - var pl = org.bukkit.entity.Player; - var cs = org.bukkit.command.BlockCommandSender; - var world = (self instanceof pl)?self.location.world:(self instanceof cs)?self.block.location.world:null; var depthFunc = function(){ var block = world.getBlockAt(that.x,that.y,that.z); @@ -424,11 +422,16 @@ var Drone = Drone || { return this; }; + Drone.prototype._getWorld = function(){ + var pl = org.bukkit.entity.Player; + var cs = org.bukkit.command.BlockCommandSender; + var world = (self instanceof pl)?self.location.world:(self instanceof cs)?self.block.location.world:null; + return world; + }; Drone.prototype.cuboid = function(block,w,h,d){ var bm = _getBlockIdAndMeta(block); - - return this.cuboidX(bm[0],bm[1],w,h,d); + return this.cuboidX(bm[0],bm[1],this._getWorld(), w,h,d); }; Drone.prototype.cuboid0 = function(block,w,h,d){ this.chkpt('start_point'); @@ -592,9 +595,23 @@ var Drone = Drone || { // ======================================================================== // Private variables and functions // ======================================================================== - var _cylinderX = function(block,radius,height,drone,fill) + var _cylinderX = function(block,radius,height,drone,fill,exactParams) { drone.chkpt('cylinderX'); + var world = null; + var blockType = null; + var meta = 0; + if (typeof exactParams == "undefined"){ + world = drone._getWorld(); + bm = drone._getBlockIdAndMeta(block); + blockType = bm[0]; + meta = bm[1]; + }else{ + world = exactParams.world; + blockType = exactParams.blockType; + meta = exactParams.meta; + } + var x0, y0, gotoxy; drone.right(radius).fwd(radius).chkpt('center'); switch (drone.dir){ @@ -628,11 +645,11 @@ var Drone = Drone || { if (yo < 0){ drone .fwd(yo).right(xo) - .box(block,1,height,Math.abs(yo*2)+1) + .cuboidX(blockType,meta,world,1,height,Math.abs(yo*2)+1) .back(yo).left(xo); } }else{ - gotoxy(xo,yo).box(block,1,height,1).move('center'); + gotoxy(xo,yo).cuboidX(blockType,meta,world,1,height,1).move('center'); } }; // @@ -675,11 +692,11 @@ var Drone = Drone || { } return drone.move('cylinderX'); } - var _cylinder0 = function(block,radius,height){ - return _cylinderX(block,radius,height,this,false); + var _cylinder0 = function(block,radius,height,exactParams){ + return _cylinderX(block,radius,height,this,false,exactParams); }; - var _cylinder1 = function(block,radius,height){ - return _cylinderX(block,radius,height,this,true); + var _cylinder1 = function(block,radius,height,exactParams){ + return _cylinderX(block,radius,height,this,true,exactParams); }; var _getDirFromRotation = function(r){ // 0 = east, 1 = south, 2 = west, 3 = north diff --git a/src/main/javascript/drone/sphere.js b/src/main/javascript/drone/sphere.js index 35e28ad..ef207d3 100644 --- a/src/main/javascript/drone/sphere.js +++ b/src/main/javascript/drone/sphere.js @@ -5,6 +5,9 @@ Drone.extend('sphere', function(block,radius) var lastRadius = radius; var slices = [[radius,0]]; var diameter = radius*2; + var world = this._getWorld(); + var bm = this._getBlockIdAndMeta(block); + var r2 = radius*radius; for (var i = 0; i <= radius;i++){ var newRadius = Math.round(Math.sqrt(r2 - i*i)); @@ -19,7 +22,7 @@ Drone.extend('sphere', function(block,radius) // mid section // this.up(radius - slices[0][1]) - .cylinder(block,radius,(slices[0][1]*2)-1) + .cylinder(block,radius,(slices[0][1]*2)-1,{blockType: bm[0],meta: bm[1],world: world}) .down(radius-slices[0][1]); var yOffset = -1; @@ -31,13 +34,13 @@ Drone.extend('sphere', function(block,radius) var v = radius + yOffset, h = radius-sr; // northern hemisphere this.up(v).fwd(h).right(h) - .cylinder(block,sr,sh) + .cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1],world: world}) .left(h).back(h).down(v); // southern hemisphere v = radius - (yOffset+sh+1); this.up(v).fwd(h).right(h) - .cylinder(block,sr,sh) + .cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1],world: world}) .left(h).back(h). down(v); } return this.move('sphere');