diff options
Diffstat (limited to 'src/main/java/makamys/neodymium/util/BufferWriter.java')
-rw-r--r-- | src/main/java/makamys/neodymium/util/BufferWriter.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/util/BufferWriter.java b/src/main/java/makamys/neodymium/util/BufferWriter.java new file mode 100644 index 0000000..901f5dc --- /dev/null +++ b/src/main/java/makamys/neodymium/util/BufferWriter.java @@ -0,0 +1,46 @@ +package makamys.neodymium.util; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +public class BufferWriter { + + private ByteBuffer buf; + + private FloatBuffer floatBuffer; + private ShortBuffer shortBuffer; + private IntBuffer intBuffer; + + public BufferWriter(ByteBuffer buf) { + this.buf = buf; + this.floatBuffer = buf.asFloatBuffer(); + this.shortBuffer = buf.asShortBuffer(); + this.intBuffer = buf.asIntBuffer(); + } + + private void incrementPosition(int add) { + buf.position(buf.position() + add); + floatBuffer.position(buf.position() / 4); + shortBuffer.position(buf.position() / 2); + intBuffer.position(buf.position() / 4); + } + + public void writeFloat(float x) { + try { + floatBuffer.put(x); + + incrementPosition(4); + } catch(Exception e){ + e.printStackTrace(); + } + } + + public void writeInt(int x) { + intBuffer.put(x); + + incrementPosition(4); + } + +}
\ No newline at end of file |