kopia lustrzana https://github.com/jameshball/osci-render
Add parallel pre-rendering
rodzic
5067c4747e
commit
0f2be2cee6
|
@ -5,6 +5,7 @@ import engine.Vector3;
|
|||
import engine.WorldObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
import shapes.Shape;
|
||||
import shapes.Shapes;
|
||||
import shapes.Vector2;
|
||||
|
@ -20,20 +21,27 @@ public class AudioClient {
|
|||
// Improve performance of line cleanup with a heuristic.
|
||||
// Pre-render in parallel.
|
||||
|
||||
Camera camera = new Camera(0.8, new Vector3(0, 0, -3));
|
||||
Camera camera = new Camera(0.6, new Vector3(0, 0, -0.08));
|
||||
WorldObject object = new WorldObject(args[0], new Vector3(0, 0, 0), new Vector3());
|
||||
Vector3 rotation = new Vector3(0,Math.PI / 100,Math.PI / 100);
|
||||
List<List<? extends Shape>> preRenderedFrames = new ArrayList<>();
|
||||
|
||||
int numFrames = (int) (Float.parseFloat(args[1]) * TARGET_FRAMERATE);
|
||||
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
for (int i = 0; i < numFrames; i++) {
|
||||
preRenderedFrames.add(Shapes.sortLines(camera.draw(object)));
|
||||
object.rotate(rotation);
|
||||
preRenderedFrames.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
IntStream.range(0, numFrames).parallel().forEach((frameNum) -> {
|
||||
WorldObject clone = object.clone();
|
||||
clone.rotate(rotation.scale(frameNum));
|
||||
preRenderedFrames.set(frameNum, Shapes.sortLines(camera.draw(clone)));
|
||||
});
|
||||
|
||||
System.out.println(System.currentTimeMillis() - start);
|
||||
|
||||
AudioPlayer player = new AudioPlayer(SAMPLE_RATE, preRenderedFrames);
|
||||
//AudioPlayer.setRotateSpeed(1);
|
||||
//AudioPlayer.setTranslation(1, new Vector2(1, 1));
|
||||
|
|
|
@ -136,7 +136,7 @@ public class AudioPlayer extends Thread {
|
|||
}
|
||||
|
||||
private static Shape getCurrentShape() {
|
||||
if (frames.size() == 0) {
|
||||
if (frames.size() == 0 || frames.get(currentFrame).size() == 0) {
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,4 +84,8 @@ public final class Vector3 {
|
|||
|
||||
return mean.scale(1f / (points.size()));
|
||||
}
|
||||
|
||||
public Vector3 clone() {
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,21 @@ public class WorldObject {
|
|||
loadFromFile(filename);
|
||||
}
|
||||
|
||||
public WorldObject(List<Vector3> vertices, List<Integer> edgeData, Vector3 position, Vector3 rotation) {
|
||||
this.vertices = vertices;
|
||||
this.edgeData = edgeData;
|
||||
this.position = position;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public void rotate(Vector3 theta) {
|
||||
rotation = rotation.add(theta);
|
||||
}
|
||||
|
||||
public void resetRotation() {
|
||||
rotation = new Vector3();
|
||||
}
|
||||
|
||||
public List<Vector3> getVertices() {
|
||||
List<Vector3> newVertices = new ArrayList<>();
|
||||
|
||||
|
@ -67,4 +78,20 @@ public class WorldObject {
|
|||
throw new IllegalArgumentException("Cannot load mesh data from: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
public WorldObject clone() {
|
||||
List<Vector3> newVertices = new ArrayList<>();
|
||||
|
||||
for (Vector3 vertex : vertices) {
|
||||
newVertices.add(vertex.clone());
|
||||
}
|
||||
|
||||
List<Integer> newEdgeData = new ArrayList<>();
|
||||
|
||||
for (int edge : edgeData) {
|
||||
newEdgeData.add(edge);
|
||||
}
|
||||
|
||||
return new WorldObject(newVertices, newEdgeData, position.clone(), rotation.clone());
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue