Improved Drone background-processing.
This commit is contained in:
parent
d16487bcc3
commit
fae2b6aac7
5 changed files with 65 additions and 47 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 );
|
||||||
};
|
};
|
||||||
|
|
|
@ -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))) ;
|
|
||||||
var op;
|
|
||||||
Drone.processingQueue = true;
|
|
||||||
while ( maxOpsPerTick > 0 ) {
|
|
||||||
op = Drone.queue.shift();
|
|
||||||
if (!op){
|
|
||||||
Drone.processingQueue = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
var block = op.world.getBlockAt( op.x, op.y, op.z );
|
setTimeout(Drone.processQueue,1000/Drone.opsPerSec);
|
||||||
block.setTypeIdAndData( op.typeid, op.meta, false );
|
};
|
||||||
// wph 20130210 - dont' know if this is a bug in bukkit but for chests,
|
setTimeout(Drone.processQueue,1000/Drone.opsPerSec);
|
||||||
// the metadata is ignored (defaults to 2 - south facing)
|
addUnloadHandler(function(){
|
||||||
// only way to change data is to set it using property/bean.
|
var pendingBuildOps = Drone.queue.length;
|
||||||
block.data = op.meta;
|
if (pendingBuildOps > 0){
|
||||||
maxOpsPerTick--;
|
console.warn('There were ' + pendingBuildOps + ' pending build operations which were cancelled');
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
||||||
var depthFunc = function( ) {
|
if ( !immediate ) {
|
||||||
var len = Drone.queue.length;
|
var clone = Drone.clone(this);
|
||||||
if ( len < Drone.MAX_QUEUE_SIZE ) {
|
Drone.queue.push(this.cuboidX.bind(clone, blockType, meta, w, h, d, true));;
|
||||||
Drone.queue.push({
|
return this;
|
||||||
world: that.world,
|
|
||||||
x: that.x,
|
|
||||||
y: that.y,
|
|
||||||
z:that.z,
|
|
||||||
typeid: blockType,
|
|
||||||
meta: meta
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw new Error('Drone is too busy!');
|
|
||||||
}
|
}
|
||||||
|
var depthFunc = function( ) {
|
||||||
|
|
||||||
|
var block = that.world.getBlockAt( that.x, that.y, that.z );
|
||||||
|
block.setTypeIdAndData( blockType, 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 = meta;
|
||||||
};
|
};
|
||||||
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
|
||||||
//
|
//
|
||||||
|
|
Reference in a new issue