-
Notifications
You must be signed in to change notification settings - Fork 0
/
INeRT.process.js
93 lines (80 loc) · 2.37 KB
/
INeRT.process.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
/*
* 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.process');
* mod.thing == 'a thing'; // true
*/
let logger = require("screeps.logger");
logger = new logger("INeRT.process");
logger.enabled = false;
logger.color = COLOR_GREY;
let stat = require("util.stat");
let threadClass = require("INeRT.thread");
class process {
constructor(name, data = {}) { // class constructor
this.kernel=false; //set by kernel
//handled by the kernel, not this class
this.threads = [];
this.name = name;
this.data = data;
this.cpuUsed = new stat();
this.killed = false;
this.parentProc = false; //set in kernel->startProcess
}
set memory(value) {
value.lastTouch = Game.time;
this.kernel.memory.procMem[this.name] = value;
}
get memory() {
if (!this.kernel.memory.procMem[this.name]) {
this.kernel.memory.procMem[this.name] = {
lastTouch: Game.time
};
}
return this.kernel.memory.procMem[this.name];
}
/**
* Init code, do setup here
*
* called once during init
*/
init() {
logger.log(this.name, "base init")
}
/**
* create and return starting threads for kernel to run.
*
* called once during init
*/
initThreads() {
logger.log(this.name, "base init threads", this.run);
let defaultThreads = [];
if (this.initTick) {
defaultThreads.push(this.createThread("initTick", "init"));
}
if (this.run) {
defaultThreads.push(this.createThread("run", "empire"));
}
if (this.endTick) {
defaultThreads.push(this.createThread("endTick", "work"));
}
//logger.log("base init threads got", JSON.stringify(defaultThreads))
return defaultThreads;
}
createThread(method, queueName) {
let thread = new threadClass(this, method, queueName);
return thread;
}
getRoom() {
let roomName = this.data.roomName;
let room = Game.rooms[roomName];
if (room) {
return room;
} else {
return false;
}
}
}
module.exports = process;