Compare commits
No commits in common. "126f2d6bfca60cfeb1c09eabb74ed2c4a1989eaa" and "592d993c4e379f6a1266f43fbb7e1d233fc77926" have entirely different histories.
126f2d6bfc
...
592d993c4e
@ -31,7 +31,9 @@ export class ControlNode extends Node {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class SequenceNode extends ControlNode {
|
export class SequenceNode extends ControlNode {
|
||||||
constructor() { super(); }
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
async tick(blackboard) {
|
async tick(blackboard) {
|
||||||
for (let child of this.children) {
|
for (let child of this.children) {
|
||||||
@ -45,7 +47,6 @@ export class FallbackNode extends ControlNode {
|
|||||||
|
|
||||||
async tick(blackboard) {
|
async tick(blackboard) {
|
||||||
for (let i = 0; i < this.children.length; i += 1) {
|
for (let i = 0; i < this.children.length; i += 1) {
|
||||||
let child = this.children[i];
|
|
||||||
try {
|
try {
|
||||||
await child.tick(blackboard);
|
await child.tick(blackboard);
|
||||||
break;
|
break;
|
||||||
@ -59,7 +60,5 @@ export class FallbackNode extends ControlNode {
|
|||||||
export class ParallelNode extends ControlNode {
|
export class ParallelNode extends ControlNode {
|
||||||
constructor() { super(); }
|
constructor() { super(); }
|
||||||
|
|
||||||
tick(blackboard) {
|
async tick(blackboard) {}
|
||||||
return Promise.all(this.children.map(child => child(blackboard)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,4 +4,3 @@ export { readJsonFile, writeJsonFile, parseLogin, waitEvent,
|
|||||||
export { Queue, QueueEmptyError } from './queue.mjs';
|
export { Queue, QueueEmptyError } from './queue.mjs';
|
||||||
export { AsyncLock } from './async-lock.mjs';
|
export { AsyncLock } from './async-lock.mjs';
|
||||||
export { Task, TaskInteruptedError } from './task.mjs';
|
export { Task, TaskInteruptedError } from './task.mjs';
|
||||||
export { PriorityQueue } from './priority-queue.mjs';
|
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
|
|
||||||
export class PriorityQueue {
|
|
||||||
constructor() {
|
|
||||||
this.val = [null];
|
|
||||||
}
|
|
||||||
|
|
||||||
push(value, priority) {
|
|
||||||
if (priority == null) {
|
|
||||||
priority = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.val.push([value, priority]);
|
|
||||||
let id = this.val.length - 1;
|
|
||||||
while (id > 1 && this.val[id][1] > this.val[id >>> 1][1]) {
|
|
||||||
const kid = id >>> 1;
|
|
||||||
[this.val[id], this.val[kid]] = [this.val[kid], this.val[id]];
|
|
||||||
id = kid;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
pop() {
|
|
||||||
let lv = this.val.pop();
|
|
||||||
if (this.val.length == 1) { return lv; }
|
|
||||||
|
|
||||||
let res = this.val[1];
|
|
||||||
this.val[1] = lv;
|
|
||||||
let id = 1;
|
|
||||||
while (id * 2 < this.val.length) {
|
|
||||||
if (this.val[id][1] > this.val[id * 2][1] && (id * 2 + 1 >= this.val.length || this.val[id][1] > this.val[id * 2 + 1][1])) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let kid = (id * 2 + 1 >= this.val.length || this.val[id * 2][1] > this.val[id * 2 + 1][1]) ? id * 2 : id * 2 + 1;
|
|
||||||
[this.val[id], this.val[kid]] = [this.val[kid], this.val[id]];
|
|
||||||
id = kid;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
top() {
|
|
||||||
return this.val[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
size() {
|
|
||||||
return this.val.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
empty() {
|
|
||||||
return this.size() == 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
x
Reference in New Issue
Block a user