-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_example.d
48 lines (37 loc) · 1.37 KB
/
client_example.d
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
import std.stdio;
import std.process;
import std.stream;
// This code was not tested at all (hell, I don't know if it even copiles), just a demonstration of how the communication could work
void main()
{
immutable string[] args = [
"ac_worldgen"
"--blockMapping", "block.stone=1,block.dirt=2",
"--sourceFile", "world.woglac",
"--lookupDirectory", "voxFiles",
"--seed", "0"
];
// Spawn the worldgen process
auto worldgenProcess = pipeProcess(args, Redirect.stdin | Redirect.stdout);
// List of chunks we want to get data of
string[] chunkRequests = [
"0 0 0", "0 0 1", "0 0 2"
];
// Write all the requests to the process stdin. We want to get the data of the export named "resultBlock" of type "Block"
foreach(string req; chunkRequests)
worldgenProcess.stdin.writeln("getData ", req, " resultBlock Block");
// The chunks will be asynchronously generated
// Process the responses
while(true) {
int x, y, z;
size_t payloadSize;
// Read the response message in the given format
worldgenProcess.stdout.readf!"data %d %d %d resultBlock %d\n"(x, y, z, payloadSize);
// Rad the payload
blockIDs = new ushort[payloadSize / ushort.sizeof];
worldgenProcess.stdout.rawRead(blockIDs);
writeln("Generated chunk ", x, " ", y, " ", z);
}
// Close the stdin of the worldgen to indicate it's done, the worldgen process should shut down
worldgenProcess.stdin.close();
}