forked from screepers/screeps-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.kt
34 lines (23 loc) · 750 Bytes
/
Process.kt
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
package example.os
import screeps.api.Game
class Process(val pid: Int, val pri: Int, val program: Program) {
private var sleepUntil: Int = 0
private var cpuUsage = 0.0
private var sleepCount = 0
private val exe = program.execute().iterator()
fun getSleepUntil() = sleepUntil
fun getProgramName() = program.getProgramName()
fun getClassName() = program.getClassName()
fun run() : Signal {
val signal = exe.next()
when(signal) {
is SleepSignal -> {sleepUntil = Game.time + signal.duration; sleepCount++}
}
return signal
}
fun addCpuUsage(spent: Double){
cpuUsage += spent
}
fun getCpuUsage() = cpuUsage
fun getSleepCount() = sleepCount
}