LightPacking utility class

This commit is contained in:
Jozufozu 2021-09-14 13:17:13 -07:00
parent 555cc2e57e
commit cc5949a4bb
4 changed files with 37 additions and 20 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}