From 261b901e8099567ceb5706c6a5dafdf0167dabef Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 14 Sep 2021 13:17:13 -0700 Subject: [PATCH] LightPacking utility class --- .../backend/gl/buffer/MappedBuffer.java | 6 +++++ .../flywheel/backend/gl/buffer/VecBuffer.java | 5 ++++ .../jozufozu/flywheel/light/LightPacking.java | 26 +++++++++++++++++++ .../jozufozu/flywheel/light/LightVolume.java | 20 -------------- 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/light/LightPacking.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java index 2ddedae40..0fa839915 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java @@ -76,6 +76,12 @@ public abstract class MappedBuffer extends VecBuffer implements AutoCloseable { return this; } + public MappedBuffer putShort(short s) { + checkAndMap(); + super.putShort(s); + return this; + } + public MappedBuffer put(byte b) { checkAndMap(); super.put(b); diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java index 2ece691ee..76fcfcccb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java @@ -72,6 +72,11 @@ public class VecBuffer { return this; } + public VecBuffer putShort(short s) { + internal.putShort(s); + return this; + } + public VecBuffer put(byte b) { internal.put(b); return this; diff --git a/src/main/java/com/jozufozu/flywheel/light/LightPacking.java b/src/main/java/com/jozufozu/flywheel/light/LightPacking.java new file mode 100644 index 000000000..c18323b12 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/light/LightPacking.java @@ -0,0 +1,26 @@ +package com.jozufozu.flywheel.light; + +/** + * Utility class for bit-twiddling light. + */ +public class LightPacking { + public static int getBlock(short packed) { + return (packed >> 4) & 0xF; + } + + public static int getSky(short packed) { + return (packed >> 12) & 0xF; + } + + public static byte packLightNibbles(byte block, byte sky) { + return (byte) (block | (sky << 4)); + } + + public static int getBlock(byte packed) { + return packed & 0xF; + } + + public static int getSky(byte packed) { + return (packed >> 4) & 0xF; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java index d434143bb..148a04b04 100644 --- a/src/main/java/com/jozufozu/flywheel/light/LightVolume.java +++ b/src/main/java/com/jozufozu/flywheel/light/LightVolume.java @@ -218,24 +218,4 @@ public class LightVolume implements ImmutableBox, ILightUpdateListener { return ListenerStatus.OKAY; } - public static int unpackBlock(short packed) { - return (packed >> 4) & 0xF; - } - - public static int unpackSky(short packed) { - return (packed >> 12) & 0xF; - } - - public static byte packLight(byte block, byte sky) { - return (byte) (block | (sky << 4)); - } - - public static int unpackBlock(byte packed) { - return packed & 0xF; - } - - public static int unpackSky(byte packed) { - return (packed >> 4) & 0xF; - } - }