103 lines
2.0 KiB
Java
103 lines
2.0 KiB
Java
package projectzombie.worker;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.OutputStream;
|
|
import java.lang.ProcessBuilder.Redirect;
|
|
import java.nio.ByteBuffer;
|
|
|
|
import bdf.data.BdfDatabase;
|
|
import bdf.types.BdfIndent;
|
|
import bdf.types.BdfNamedList;
|
|
import bdf.types.BdfObject;
|
|
import projectzombie.display.lighting.TileLighting;
|
|
|
|
public class Worker extends Thread
|
|
{
|
|
ProcessBuilder pb;
|
|
Process process;
|
|
|
|
InputStream in;
|
|
OutputStream out;
|
|
|
|
public Worker() throws IOException
|
|
{
|
|
pb = new ProcessBuilder("java", "-jar", "worker.jar");
|
|
pb.redirectError(Redirect.INHERIT);
|
|
pb.redirectOutput(Redirect.PIPE);
|
|
pb.redirectInput(Redirect.PIPE);
|
|
|
|
process = pb.start();
|
|
|
|
in = process.getInputStream();
|
|
out = process.getOutputStream();
|
|
}
|
|
|
|
|
|
|
|
public void processLighting(float[] lights, int width, int height)
|
|
{
|
|
BdfObject bdf = new BdfObject();
|
|
BdfNamedList nl = bdf.getNamedList();
|
|
nl.set("task", BdfObject.withString("light"));
|
|
nl.set("light", BdfObject.withFloatArray(lights));
|
|
nl.set("w", BdfObject.withInteger(width));
|
|
nl.set("h", BdfObject.withInteger(height));
|
|
|
|
byte[] data = bdf.serialize().getBytes();
|
|
|
|
ByteBuffer size_buff = ByteBuffer.allocate(4);
|
|
size_buff.putInt(0, data.length);
|
|
|
|
try
|
|
{
|
|
out.write(size_buff.array());
|
|
out.write(data);
|
|
out.write('\n');
|
|
out.flush();
|
|
}
|
|
|
|
catch(IOException e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
super.run();
|
|
|
|
try
|
|
{
|
|
while(true)
|
|
{
|
|
ByteBuffer size_buff = ByteBuffer.allocate(4);
|
|
byte[] data;
|
|
|
|
in.read(size_buff.array());
|
|
data = new byte[size_buff.getInt(0)];
|
|
in.read(data);
|
|
in.read(new byte[1]);
|
|
|
|
BdfObject bdf = new BdfObject(new BdfDatabase(data));
|
|
BdfNamedList nl = bdf.getNamedList();
|
|
|
|
switch(nl.get("task").getString())
|
|
{
|
|
case "light":
|
|
TileLighting.updateLighting(bdf);
|
|
break;
|
|
}
|
|
|
|
System.out.println("Hello");
|
|
}
|
|
}
|
|
|
|
catch(IOException e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|