diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java b/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java index 74e374cdd..a79bc85f8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java @@ -3,11 +3,26 @@ package com.jozufozu.flywheel.backend.struct; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; +/** + * A StructType contains metadata for a specific instance struct that Flywheel can interface with. + * @param The java representation of the instance struct. + */ public interface StructType { + /** + * @return A new, zeroed instance of the struct. + */ S create(); + /** + * @return The format descriptor of the struct type. + */ VertexFormat format(); + /** + * Create a {@link StructWriter} that will consume instances of S and write them to the given buffer. + * + * @param backing The buffer that the StructWriter will write to. + */ StructWriter getWriter(VecBuffer backing); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java b/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java index adc6c4cba..7c22400f6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java @@ -1,8 +1,17 @@ package com.jozufozu.flywheel.backend.struct; +/** + * StructWriters can quickly consume many instances of S and write them to some backing buffer. + */ public interface StructWriter { + /** + * Write the given struct to the backing array. + */ void write(S struct); + /** + * Seek to the given position. The next write will occur there. + */ void seek(int pos); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriterUnsafe.java b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java similarity index 82% rename from src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriterUnsafe.java rename to src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java index d7b5a0917..485d7a6f8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriterUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java @@ -5,19 +5,21 @@ import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; /** + * This class copied/adapted from jellysquid's + * * An unsafe {@link BufferWriter} implementation which uses direct memory operations to enable fast blitting of * data into memory buffers. Only available on JVMs which support {@link sun.misc.Unsafe}, but generally produces much * better optimized code than other implementations. The implementation does not check for invalid memory accesses, * meaning that errors can corrupt process memory. */ -public abstract class BufferWriterUnsafe extends BufferWriter { +public abstract class UnsafeBufferWriter extends BufferWriter { /** * The write pointer into the buffer storage. This is advanced by the vertex stride every time - * {@link BufferWriterUnsafe#advance()} is called. + * {@link UnsafeBufferWriter#advance()} is called. */ protected long writePointer; - protected BufferWriterUnsafe(VecBuffer backingBuffer, StructType vertexType) { + protected UnsafeBufferWriter(VecBuffer backingBuffer, StructType vertexType) { super(backingBuffer, vertexType); acquireWritePointer(); diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java index ca4f1ee4a..97f1aa3cb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java @@ -3,12 +3,11 @@ package com.jozufozu.flywheel.core.materials.model.writer; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.BufferWriterUnsafe; +import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.backend.struct.BufferWriter; import com.jozufozu.flywheel.core.materials.model.ModelData; -public class UnsafeModelWriter extends BufferWriterUnsafe { +public class UnsafeModelWriter extends UnsafeBufferWriter { public UnsafeModelWriter(VecBuffer backingBuffer, StructType vertexType) { super(backingBuffer, vertexType); diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java index b67ef7d0b..53204c5bf 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java @@ -3,11 +3,11 @@ package com.jozufozu.flywheel.core.materials.oriented.writer; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.BufferWriterUnsafe; +import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; import com.jozufozu.flywheel.backend.struct.StructType; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; -public class UnsafeOrientedWriter extends BufferWriterUnsafe { +public class UnsafeOrientedWriter extends UnsafeBufferWriter { public UnsafeOrientedWriter(VecBuffer backingBuffer, StructType vertexType) { super(backingBuffer, vertexType); }