Improved Drone background-processing.

This commit is contained in:
walterhiggins 2014-03-08 21:01:25 +00:00
parent d16487bcc3
commit fae2b6aac7
5 changed files with 65 additions and 47 deletions

View file

@ -884,14 +884,14 @@ present in the CraftBukkit classpath. To use this module, you should
command... command...
```sh ```sh
java -classpath sc-mqtt.jar;craftbukit.jar org.bukkit.craftbukkit.Main java -classpath sc-mqtt.jar;craftbukkit.jar org.bukkit.craftbukkit.Main
``` ```
If you're using Mac OS, create a new craftbukkit-sc-mqtt.command If you're using Mac OS, create a new craftbukkit-sc-mqtt.command
file and edit it (using TextWrangler or another text editor) ... file and edit it (using TextWrangler or another text editor) ...
```sh ```sh
java -classpath sc-mqtt.jar:craftbukkit.jar org.bukit.craftbukkit.Main java -classpath sc-mqtt.jar:craftbukkit.jar org.bukkit.craftbukkit.Main
``` ```
4. Execute the craftbukkit-sc-mqtt batch file / command file to start 4. Execute the craftbukkit-sc-mqtt batch file / command file to start

View file

@ -1,3 +1,11 @@
# 2014 03 08
## Version 2.0.6
Fixed issues #122 #123
Improved background processing of Drone build commands.
# 2014 02 19 # 2014 02 19
## Version 2.0.5 ## Version 2.0.5

View file

@ -548,6 +548,12 @@ function __onEnable ( __engine, __plugin, __script )
global.refresh = function( ) { global.refresh = function( ) {
if ( typeof self !== 'undefined' ) {
if ( !self.op ) {
self.sendMessage('Only operators can refresh()');
return;
}
}
__plugin.pluginLoader.disablePlugin( __plugin ); __plugin.pluginLoader.disablePlugin( __plugin );
__plugin.pluginLoader.enablePlugin( __plugin ); __plugin.pluginLoader.enablePlugin( __plugin );
}; };

View file

@ -750,33 +750,25 @@ exports.Drone = Drone;
exports.blocks = blocks; exports.blocks = blocks;
Drone.queue = []; Drone.queue = [];
Drone.processingQueue = false; Drone.opsPerSec = 10;
Drone.MAX_QUEUE_SIZE = 100000; Drone.processQueue = function(){
Drone.tick = setInterval( function() { var process = Drone.queue.shift();
if ( Drone.processingQueue ) { if (process){
return; try {
process();
} catch( e ) {
console.log('Drone build error: %s', e);
}
} }
var maxOpsPerTick = Math.floor(Math.max(10,Math.sqrt(Drone.queue.length))) ; setTimeout(Drone.processQueue,1000/Drone.opsPerSec);
var op; };
Drone.processingQueue = true; setTimeout(Drone.processQueue,1000/Drone.opsPerSec);
while ( maxOpsPerTick > 0 ) { addUnloadHandler(function(){
op = Drone.queue.shift(); var pendingBuildOps = Drone.queue.length;
if (!op){ if (pendingBuildOps > 0){
Drone.processingQueue = false; console.warn('There were ' + pendingBuildOps + ' pending build operations which were cancelled');
return;
}
var block = op.world.getBlockAt( op.x, op.y, op.z );
block.setTypeIdAndData( op.typeid, op.meta, false );
// wph 20130210 - dont' know if this is a bug in bukkit but for chests,
// the metadata is ignored (defaults to 2 - south facing)
// only way to change data is to set it using property/bean.
block.data = op.meta;
maxOpsPerTick--;
} }
Drone.processingQueue = false; });
return;
}, 1);
// //
// add custom methods to the Drone object using this function // add custom methods to the Drone object using this function
// //
@ -1054,7 +1046,7 @@ Drone.prototype.cuboida = function(/* Array */ blocks, w, h, d, overwrite ) {
faster cuboid because blockid, meta and world must be provided faster cuboid because blockid, meta and world must be provided
use this method when you need to repeatedly place blocks use this method when you need to repeatedly place blocks
*/ */
Drone.prototype.cuboidX = function( blockType, meta, w, h, d ) { Drone.prototype.cuboidX = function( blockType, meta, w, h, d, immediate ) {
if ( typeof h == 'undefined' ) { if ( typeof h == 'undefined' ) {
h = 1; h = 1;
@ -1065,23 +1057,32 @@ Drone.prototype.cuboidX = function( blockType, meta, w, h, d ) {
if ( typeof w == 'undefined' ) { if ( typeof w == 'undefined' ) {
w = 1; w = 1;
} }
if ( ( w * h * d ) >= 1000000 ) {
this.sign([
'Build too Big!',
'width:' + w,
'height:' + h,
'depth:' + d
], 68);
console.warn('Build too big! ' + w + ' X ' + h + ' X ' + d);
return this;
}
var that = this; var that = this;
var dir = this.dir; var dir = this.dir;
if ( !immediate ) {
var clone = Drone.clone(this);
Drone.queue.push(this.cuboidX.bind(clone, blockType, meta, w, h, d, true));;
return this;
}
var depthFunc = function( ) { var depthFunc = function( ) {
var len = Drone.queue.length;
if ( len < Drone.MAX_QUEUE_SIZE ) { var block = that.world.getBlockAt( that.x, that.y, that.z );
Drone.queue.push({ block.setTypeIdAndData( blockType, meta, false );
world: that.world, // wph 20130210 - dont' know if this is a bug in bukkit but for chests,
x: that.x, // the metadata is ignored (defaults to 2 - south facing)
y: that.y, // only way to change data is to set it using property/bean.
z:that.z, block.data = meta;
typeid: blockType,
meta: meta
});
} else {
throw new Error('Drone is too busy!');
}
}; };
var heightFunc = function( ) { var heightFunc = function( ) {
_traverse[dir].depth( that, d, depthFunc ); _traverse[dir].depth( that, d, depthFunc );
@ -1337,7 +1338,6 @@ var _getStrokeDir = function( x,y ) {
if you're drawing anything that bends it ends up here. if you're drawing anything that bends it ends up here.
*/ */
var _arc2 = function( params ) { var _arc2 = function( params ) {
var drone = params.drone; var drone = params.drone;
var orientation = params.orientation?params.orientation:'horizontal'; var orientation = params.orientation?params.orientation:'horizontal';
var quadrants = params.quadrants?params.quadrants:{ var quadrants = params.quadrants?params.quadrants:{
@ -1490,12 +1490,13 @@ var _cylinder0 = function( block,radius,height,exactParams ) {
radius: radius, radius: radius,
fill: false, fill: false,
orientation: 'horizontal', orientation: 'horizontal',
stack: height, stack: height
}; };
if ( exactParams ) { if ( exactParams ) {
arcParams.blockType = exactParams.blockType; for ( var p in exactParams ) {
arcParams.meta = exactParams.meta; arcParams[p] = exactParams[p];
}
}else{ }else{
var md = this._getBlockIdAndMeta(block ); var md = this._getBlockIdAndMeta(block );
arcParams.blockType = md[0]; arcParams.blockType = md[0];
@ -1825,7 +1826,10 @@ for ( var p in _trees ) {
}; };
}(_trees[p] ) ); }(_trees[p] ) );
} }
Drone.clone = function(origin) {
var result = {x: origin.x, y: origin.y, z: origin.z, world: origin.world, dir: origin.dir};
return result;
};
// //
// Drone's clipboard // Drone's clipboard
// //

View file

@ -74,7 +74,7 @@ Drone.extend( 'sphere', function( block, radius ) {
this.up( v ) this.up( v )
.fwd( h ) .fwd( h )
.right( h ) .right( h )
.cylinder( block, sr, sh, { blockType: bm[0], meta: bm[1] } ) .cylinder( block, sr, sh, { blockType: bm[0], meta: bm[1]} )
.left( h ) .left( h )
.back( h ) .back( h )
.down( v ); .down( v );