-
Notifications
You must be signed in to change notification settings - Fork 0
/
inert.tests.js
103 lines (83 loc) · 2.33 KB
/
inert.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('inert.tests');
* mod.thing == 'a thing'; // true
*/
let logger = require("screeps.logger");
logger = new logger("INeRT.process");
logger.color = COLOR_GREY;
let processClass = require("INeRT.process");
let threadClass = require("INeRT.thread");
class testProc extends processClass {
initThreads() {
return [this.createThread("run", "empire")];
}
run(kernel) {
for(let i=0;i<5;i++) {
let procName = "calc" + i;
let proc = this.kernel.getProcess(procName);
let data = {
startFrom:i
};
if (!proc) {
proc = new calcProc(procName, data);
kernel.startProcess(proc);
}
proc.data = data;
}
return threadClass.TICKDONE;
}
}
class calcProc extends processClass {
initThreads() {
return [this.createThread("run", "work"),this.createThread("run2", "creepAct")];
}
run() {
let sum = 0;
for(let i=0;i<10000;i++) {
sum += i;
}
return threadClass.DONE;
}
run2() {
logger.log(this.memory)
if (!this.memory.count)
this.memory.count = this.data.startFrom;
logger.log(this.name,"gonna count", this.memory.count, JSON.stringify(this.data));
this.memory.count++;
if (this.memory.count > 10) {
return threadClass.DONE;
}
logger.log("counted", this.memory.count);
}
}
class init extends processClass{
/**
* Init code, do setup here
*
* called once during init
*/
init(kernel) {
logger.log(this.name, "init");
let test = new testProc("test");
kernel.startProcess(test);
}
/**
* create and return starting threads for kernel to run.
*
* called once during init
*/
initThreads() {
let initThreads = [];
initThreads.push(this.createThread("run", "init"));
return initThreads;
}
run() {
logger.log(this.name, "run");
return threadClass.DONE;
}
}
module.exports = init;