mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-28 22:04:57 +01:00
LightPacking utility class
This commit is contained in:
parent
fbcc1f0a10
commit
261b901e80
4 changed files with 37 additions and 20 deletions
|
@ -76,6 +76,12 @@ public abstract class MappedBuffer extends VecBuffer implements AutoCloseable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MappedBuffer putShort(short s) {
|
||||||
|
checkAndMap();
|
||||||
|
super.putShort(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MappedBuffer put(byte b) {
|
public MappedBuffer put(byte b) {
|
||||||
checkAndMap();
|
checkAndMap();
|
||||||
super.put(b);
|
super.put(b);
|
||||||
|
|
|
@ -72,6 +72,11 @@ public class VecBuffer {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VecBuffer putShort(short s) {
|
||||||
|
internal.putShort(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public VecBuffer put(byte b) {
|
public VecBuffer put(byte b) {
|
||||||
internal.put(b);
|
internal.put(b);
|
||||||
return this;
|
return this;
|
||||||
|
|
26
src/main/java/com/jozufozu/flywheel/light/LightPacking.java
Normal file
26
src/main/java/com/jozufozu/flywheel/light/LightPacking.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -218,24 +218,4 @@ public class LightVolume implements ImmutableBox, ILightUpdateListener {
|
||||||
return ListenerStatus.OKAY;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue