1
- // Bundle for programs that are logically grouped
2
- interface IPosisBundle < IDefaultRootMemory > {
3
- // host will call that once, possibly outside of main loop, registers all bundle processes here
4
- install ( registry : IPosisProcessRegistry ) : void ;
5
- // image name of root process in the bundle, if any
6
- rootImageName ?: string ;
7
- // function returning default starting memory for root process, doubles as public parameter documentation
8
- makeDefaultRootMemory ?: ( override ?: IDefaultRootMemory ) => IDefaultRootMemory ;
1
+ /** Bundle for programs that are logically grouped */
2
+ declare interface IPosisBundle < IDefaultRootMemory > {
3
+ /** host will call that once, possibly outside of main loop, registers all bundle processes here */
4
+ install ( registry : IPosisProcessRegistry ) : void ;
5
+ /** image name of root process in the bundle, if any */
6
+ rootImageName ?: string ;
7
+ /** function returning default starting memory for root process, doubles as public parameter documentation */
8
+ makeDefaultRootMemory ?: ( override ?: IDefaultRootMemory ) => IDefaultRootMemory ;
9
9
}
10
- interface IPosisExtension { }
11
- interface IPosisKernel extends IPosisExtension {
10
+ declare interface IPosisExtension { }
11
+ declare interface IPosisInterfaces {
12
+ baseKernel : IPosisKernel ;
13
+ spawn : IPosisSpawnExtension ;
14
+ sleep : IPosisSleepExtension ;
15
+ coop : IPosisCooperativeScheduling ;
16
+ }
17
+ declare interface IPosisKernel extends IPosisExtension {
18
+
19
+ /**
20
+ * beings running a process
21
+ * @param imageName registered image for the process constructor
22
+ * @param startContext context for a process
23
+ */
12
24
startProcess ( imageName : string , startContext : any ) : { pid : PosisPID ; process : IPosisProcess } | undefined ;
13
- // killProcess also kills all children of this process
14
- // note to the wise: probably absorb any calls to this that would wipe out your entire process tree.
25
+
26
+ /**
27
+ * killProcess also kills all children of this process
28
+ * note to the wise: probably absorb any calls to this that would wipe out your entire process tree.
29
+ * @param pid
30
+ */
15
31
killProcess ( pid : PosisPID ) : void ;
32
+
33
+ /**
34
+ * gets the instance of a running process
35
+ * @param pid
36
+ * @returns process instance or undefined if the pid is invalid
37
+ */
16
38
getProcessById ( pid : PosisPID ) : IPosisProcess | undefined ;
17
39
18
- // passing undefined as parentId means "make me a root process"
19
- // i.e. one that will not be killed if another process is killed
40
+ /**
41
+ * passing undefined as parentId means "make me a root process"
42
+ * i.e. one that will not be killed if another process is killed
43
+ * @param pid
44
+ * @param parentId
45
+ * @returns `true` if process was successfully reparented
46
+ */
20
47
setParent ( pid : PosisPID , parentId ?: PosisPID ) : boolean ;
21
48
}
22
- interface IPosisLogger {
49
+ declare interface IPosisLogger {
23
50
// because sometimes you don't want to eval arguments to ignore them
24
51
debug ( message : ( ( ) => string ) | string ) : void ;
25
52
info ( message : ( ( ) => string ) | string ) : void ;
26
53
warn ( message : ( ( ) => string ) | string ) : void ;
27
54
error ( message : ( ( ) => string ) | string ) : void ;
28
55
}
29
- interface IPosisProcessContext {
30
- readonly memory : any ; // private memory
31
- readonly imageName : string ; // image name (maps to constructor)
32
- readonly id : PosisPID ; // ID
33
- readonly parentId : PosisPID ; // Parent ID
34
- readonly log : IPosisLogger ; // Logger
35
- queryPosisInterface < T extends keyof PosisInterfaces > ( interfaceId : T ) : PosisInterfaces [ T ] | undefined ;
56
+ declare interface IPosisProcess {
57
+ /**
58
+ * Main function, implement all process logic here.
59
+ */
60
+ run ( ) : void ;
36
61
}
37
-
38
- // Bundle: Don't write to context object (including setting new props on it), host will likely freeze it anyway.
39
- // Host: freeze the thing!
40
- interface PosisProcessConstructor {
41
- new ( context : IPosisProcessContext ) : IPosisProcess ;
62
+ /**
63
+ * Bundle: Don't write to context object (including setting new props on it), host will likely freeze it anyway.
64
+ * Host: freeze the thing!
65
+ */
66
+ declare interface IPosisProcessConstructor {
67
+ new ( context : IPosisProcessContext ) : IPosisProcess ;
42
68
}
43
-
44
- interface IPosisProcess {
45
- // Main function, implement all process logic here.
46
- run ( ) : void ;
69
+ declare interface IPosisProcessContext {
70
+ /** private memory */
71
+ readonly memory : any ;
72
+ /** image name (maps to constructor) */
73
+ readonly imageName : string ;
74
+ /** ID */
75
+ readonly id : PosisPID ;
76
+ /** Parent ID */
77
+ readonly parentId : PosisPID ;
78
+ /** Logger */
79
+ readonly log : IPosisLogger ;
80
+ queryPosisExtension < T extends keyof IPosisInterfaces > ( extensionId : T ) : IPosisInterfaces [ T ] | undefined ;
47
81
}
48
- interface IPosisProcessRegistry {
49
- // name your processes' image names with initials preceding, like ANI/MyCoolPosisProgram (but the actual class name can be whatever you want)
50
- // if your bundle consists of several programs you can pretend that we have a VFS: "ANI/MyBundle/BundledProgram1"
51
- register ( imageName : string , constructor : new ( context : IPosisProcessContext ) => IPosisProcess ) : boolean ;
52
- }
53
- type PosisPID = string | number ;
54
-
55
- interface PosisInterfaces {
56
- baseKernel : IPosisKernel ;
57
- spawn : IPosisSpawnExtension ;
58
- sleep : IPosisSleepExtension ;
59
- coop : IPosisCooperativeScheduling ;
82
+ declare interface IPosisProcessRegistry {
83
+ /**
84
+ * name your processes' image names with initials preceding, like ANI/MyCoolPosisProgram (but the actual class name can be whatever you want)
85
+ * if your bundle consists of several programs you can pretend that we have a VFS: "ANI/MyBundle/BundledProgram1"
86
+ */
87
+ register ( imageName : string , constructor : IPosisProcessConstructor ) : boolean ;
60
88
}
61
- interface IPosisCooperativeScheduling {
62
- // CPU used by process so far. Might include setup time kernel chooses to charge to the process.
89
+ declare type PosisPID = string | number ;
90
+ declare interface IPosisCooperativeScheduling {
91
+ /** CPU used by process so far. Might include setup time kernel chooses to charge to the process. */
63
92
readonly used : number ;
64
- // CPU budget scheduler allocated to this process.
93
+ /** CPU budget scheduler allocated to this process. */
65
94
readonly budget : number ;
66
- // Process can wrap function and yield when it is ready to give up for the tick or can continue if CPU is available.
67
- // optionally yield a shutdown function to perform shutdown tasks like saving current state
95
+ /**
96
+ * Process can wrap function and yield when it is ready to give up for the tick or can continue if CPU is available.
97
+ * optionally yield a shutdown function to perform shutdown tasks like saving current state
98
+ */
68
99
wrap ?( makeIterator : ( ) => IterableIterator < void | ( ( ) => void ) > ) : void ;
69
100
}
70
- interface IPosisSleepExtension {
71
- // puts currently running process to sleep for a given number of ticks
101
+ declare interface IPosisSleepExtension {
102
+ /**
103
+ * puts currently running process to sleep for a given number of ticks
104
+ * @param ticks number of ticks to sleep for
105
+ */
72
106
sleep ( ticks : number ) : void ;
73
107
}
74
108
declare const enum EPosisSpawnStatus {
@@ -77,41 +111,64 @@ declare const enum EPosisSpawnStatus {
77
111
SPAWNING ,
78
112
SPAWNED
79
113
}
80
-
81
- // NOT FINAL, discussions still underway in slack #posis
82
-
83
- // process calls spawnCreep, checks status, if not ERROR, poll
84
- // getStatus until status is SPAWNED (Handling ERROR if it happens),
85
- // then call getCreep to get the creep itself
86
-
87
- interface IPosisSpawnExtension {
88
- // Queues/Spawns the creep and returns an ID
89
- spawnCreep ( opts : {
90
- // - 'rooms' are names of rooms associated with the creep being spawned.
91
- // Must contain at least one room. Host should select spawner based on its own logic
92
- // May contain additional rooms as a hints to host. Host may ignore hints
93
- rooms : string [ ] ,
94
- // - 'body' are body variants of the creep being spawned, at least one must be provided
95
- // Host must guarantee that the spawning creep will have one of provided bodies
96
- // Which body to spawn is up to host to select based on its own logic
97
- // Body templates should be sorted in the order of diminishing desirability
98
- body : string [ ] [ ] ,
99
- // - 'priority' is spawn priority in range -1000 (the highest) to 1000 (the lowest)
100
- // Used as a hint for host's logic. Host may (but not guarantee) spawn creeps in priority order
101
- priority ?: number ,
102
- // - 'pid' is id of the process which is spawned creep associated to
103
- // Used as a hint for host's logic. Host may (but not guarantee) consider currently spawned creeps
104
- // detached, may (but not guarantee) remove scheduled creeps from queue on process termination
105
- pid ?: PosisPID } ) : string ;
106
- // Used to see if its been dropped from queue
114
+ /*
115
+ * NOT FINAL, discussions still underway in slack #posis
116
+ *
117
+ * process calls spawnCreep, checks status, if not ERROR, poll
118
+ * getStatus until status is SPAWNED (Handling ERROR if it happens),
119
+ * then call getCreep to get the creep itself
120
+ */
121
+ declare interface IPosisSpawnExtension {
122
+ /**
123
+ * Queues/Spawns the requested creep
124
+ * @param opts options for how and where to spawn the requested creep
125
+ * @returns a unique id related to this specific creep request
126
+ */
127
+ spawnCreep ( opts : IPosisSpawnOptions ) : string ;
128
+ /**
129
+ * Used to see if its been dropped from queue
130
+ * @param id an id returned by spawnCreep()
131
+ */
107
132
getStatus ( id : string ) : {
108
133
status : EPosisSpawnStatus
109
134
message ?: string
110
- }
135
+ } ;
136
+ /**
137
+ * Get the currently spawning creep
138
+ * @param id an id returned by spawnCreep()
139
+ * @returns Creep object or undefined if the creep does not exist yet
140
+ */
111
141
getCreep ( id : string ) : Creep | undefined ;
112
142
/**
113
- * Cancel a previously ordered Creep (`spawnCreep`).
114
- * Returns `true` if it was cancelled successfully.
115
- */
143
+ * Cancel a previously ordered Creep (`spawnCreep`).
144
+ * @param id an id returned by spawnCreep()
145
+ * @returns `true` if it was cancelled successfully.
146
+ */
116
147
cancelCreep ( id : string ) : boolean ;
117
148
}
149
+ declare interface IPosisSpawnOptions {
150
+ /**
151
+ * names of rooms associated with the creep being spawned.
152
+ * Must contain at least one room. Host should select spawner based on its own logic
153
+ * May contain additional rooms as a hints to host. Host may ignore hints
154
+ */
155
+ rooms : string [ ] ;
156
+ /**
157
+ * body variants of the creep being spawned, at least one must be provided
158
+ * host must guarantee that the spawning creep will have one of provided bodies
159
+ * which body to spawn is up to host to select based on its own logic
160
+ * body templates should be sorted in the order of diminishing desirability
161
+ */
162
+ body : string [ ] [ ] ;
163
+ /**
164
+ * spawn priority in range -1000 (the highest) to 1000 (the lowest)
165
+ * used as a hint for host's logic. Host may (but not guarantee) spawn creeps in priority order
166
+ */
167
+ priority ?: number ;
168
+ /**
169
+ * id of the process which is spawned creep associated to
170
+ * Used as a hint for host's logic. Host may (but not guarantee) consider currently spawned creeps
171
+ * detached, may (but not guarantee) remove scheduled creeps from queue on process termination
172
+ */
173
+ pid ?: PosisPID ;
174
+ }
0 commit comments