Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.20/dev' into feat/multi-loader-1.20.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
IThundxr committed Jul 3, 2024
2 parents a9127be + 06a2788 commit a9c4e5c
Show file tree
Hide file tree
Showing 38 changed files with 414 additions and 388 deletions.
3 changes: 2 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ gradlePlugin {
}

dependencies {
implementation("dev.architectury.loom:dev.architectury.loom.gradle.plugin:1.6-SNAPSHOT")
// FIXME: This should not hard-code the Loom version.
implementation("dev.architectury.loom:dev.architectury.loom.gradle.plugin:1.6.397")
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package dev.engine_room.flywheel.api.vertex;

import org.joml.Vector3f;
import org.joml.Vector4f;

/**
* A read only view of a vertex buffer.
*
Expand Down Expand Up @@ -40,14 +37,6 @@ public interface VertexList {

float normalZ(int index);

default Vector4f getPos(int i, Vector4f dest) {
return dest.set(x(i), y(i), z(i));
}

default Vector3f getNormal(int i, Vector3f dest) {
return dest.set(normalX(i), normalY(i), normalZ(i));
}

default void write(MutableVertexList dst, int srcIndex, int dstIndex) {
dst.x(dstIndex, x(srcIndex));
dst.y(dstIndex, y(srcIndex));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.engine_room.flywheel.api.visual;

import java.util.List;

import dev.engine_room.flywheel.api.visualization.VisualizationContext;

/**
Expand All @@ -14,5 +16,5 @@ public interface Effect {
* @param ctx The visualization context.
* @return An arbitrary EffectVisual.
*/
EffectVisual<?> visualize(VisualizationContext ctx);
List<EffectVisual<?>> visualize(VisualizationContext ctx, float partialTick);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
*/
public interface LitVisual extends Visual {
/**
* Called when a section this visual is contained in receives a light update.
* Set the notifier object.
*
* <p>Even if multiple sections are updated at the same time, this method will only be called once.</p>
* <p>This method is only called once right after the visual
* is created and before {@link #collectLightSections}.</p>
*
* <p>The implementation is free to parallelize calls to this method, as well as execute the plan
* returned by {@link DynamicVisual#planFrame} simultaneously. It is safe to query/update light here,
* but you must ensure proper synchronization if you want to mutate anything outside this visual or
* anything that is also mutated within {@link DynamicVisual#planFrame}.</p>
* @param notifier The notifier.
*/
void updateLight();
void setLightSectionNotifier(Notifier notifier);

/**
* Collect the sections that this visual is contained in.
Expand All @@ -36,14 +34,18 @@ public interface LitVisual extends Visual {
void collectLightSections(LongConsumer consumer);

/**
* Set the notifier object.
* Called when a section this visual is contained in receives a light update.
*
* <p>This method is only called once, upon visual creation,
* after {@link #init} and before {@link #collectLightSections}.</p>
* <p>Even if multiple sections are updated at the same time, this method will only be called once.</p>
*
* @param notifier The notifier.
* <p>The implementation is free to parallelize calls to this method, as well as execute the plan
* returned by {@link DynamicVisual#planFrame} simultaneously. It is safe to query/update light here,
* but you must ensure proper synchronization if you want to mutate anything outside this visual or
* anything that is also mutated within {@link DynamicVisual#planFrame}.</p>
*
* <p>This method not is invoked automatically after visual creation.</p>
*/
void initLightSectionNotifier(Notifier notifier);
void updateLight(float partialTick);

/**
* A notifier object that can be used to indicate to the impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
* @see LitVisual
*/
public interface Visual {
/**
* Initialize instances here.
*
* <p>This method will be called exactly once upon visual creation.</p>
*/
void init(float partialTick);

/**
* Update instances here.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.engine_room.flywheel.api.visualization;

import java.util.List;

import dev.engine_room.flywheel.api.visual.BlockEntityVisual;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -16,7 +18,7 @@ public interface BlockEntityVisualizer<T extends BlockEntity> {
* @param blockEntity The block entity to construct a visual for.
* @return The visual.
*/
BlockEntityVisual<? super T> createVisual(VisualizationContext ctx, T blockEntity);
List<BlockEntityVisual<? super T>> createVisual(VisualizationContext ctx, T blockEntity, float partialTick);

/**
* Checks if the given block entity should not be rendered with the vanilla {@link BlockEntityRenderer}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.engine_room.flywheel.api.visualization;

import java.util.List;

import dev.engine_room.flywheel.api.visual.EntityVisual;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.world.entity.Entity;
Expand All @@ -16,7 +18,7 @@ public interface EntityVisualizer<T extends Entity> {
* @param entity The entity to construct a visual for.
* @return The visual.
*/
EntityVisual<? super T> createVisual(VisualizationContext ctx, T entity);
List<EntityVisual<? super T>> createVisual(VisualizationContext ctx, T entity, float partialTick);

/**
* Checks if the given entity should not render with the vanilla {@link EntityRenderer}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.engine_room.flywheel.api.instance.InstanceType;
import dev.engine_room.flywheel.api.instance.Instancer;
import dev.engine_room.flywheel.backend.engine.embed.Environment;
import dev.engine_room.flywheel.lib.util.AtomicBitset;
import dev.engine_room.flywheel.lib.util.AtomicBitSet;

public abstract class AbstractInstancer<I extends Instance> implements Instancer<I> {
public final InstanceType<I> type;
Expand All @@ -19,8 +19,8 @@ public abstract class AbstractInstancer<I extends Instance> implements Instancer
protected final ArrayList<I> instances = new ArrayList<>();
protected final ArrayList<InstanceHandleImpl> handles = new ArrayList<>();

protected final AtomicBitset changed = new AtomicBitset();
protected final AtomicBitset deleted = new AtomicBitset();
protected final AtomicBitSet changed = new AtomicBitSet();
protected final AtomicBitSet deleted = new AtomicBitSet();

protected AbstractInstancer(InstanceType<I> type, Environment environment) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.joml.Matrix4f;
import org.lwjgl.system.MemoryUtil;

import dev.engine_room.flywheel.lib.math.MatrixMath;
import dev.engine_room.flywheel.lib.util.ExtraMemoryOps;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -46,7 +46,7 @@ static long writeVec4(long ptr, float x, float y, float z, float w) {
}

static long writeMat4(long ptr, Matrix4f mat) {
MatrixMath.writeUnsafe(ptr, mat);
ExtraMemoryOps.putMatrix4f(ptr, mat);
return ptr + 64;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.engine_room.flywheel.api.instance.InstanceHandle;
import dev.engine_room.flywheel.api.instance.InstanceType;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;

public abstract class ColoredLitInstance extends AbstractInstance implements FlatLit {
Expand All @@ -11,63 +10,57 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla
public byte b = (byte) 0xFF;
public byte a = (byte) 0xFF;

public int packedLight;

public int overlay = OverlayTexture.NO_OVERLAY;
public int light = 0;

public ColoredLitInstance(InstanceType<? extends ColoredLitInstance> type, InstanceHandle handle) {
super(type, handle);
}

public ColoredLitInstance setColor(int color) {
return setColor(color, false);
public ColoredLitInstance color(int color) {
return color(color, false);
}

public ColoredLitInstance setColor(int color, boolean alpha) {
public ColoredLitInstance color(int color, boolean alpha) {
byte r = (byte) ((color >> 16) & 0xFF);
byte g = (byte) ((color >> 8) & 0xFF);
byte b = (byte) (color & 0xFF);

if (alpha) {
byte a = (byte) ((color >> 24) & 0xFF);
return setColor(r, g, b, a);
return color(r, g, b, a);
} else {
return setColor(r, g, b);
return color(r, g, b);
}
}

public ColoredLitInstance setColor(int r, int g, int b) {
return setColor((byte) r, (byte) g, (byte) b);
public ColoredLitInstance color(int r, int g, int b) {
return color((byte) r, (byte) g, (byte) b);
}

public ColoredLitInstance setColor(byte r, byte g, byte b) {
public ColoredLitInstance color(byte r, byte g, byte b) {
this.r = r;
this.g = g;
this.b = b;
return this;
}

public ColoredLitInstance setColor(byte r, byte g, byte b, byte a) {
public ColoredLitInstance color(byte r, byte g, byte b, byte a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
return this;
}

@Override
public ColoredLitInstance light(int blockLight, int skyLight) {
return light(LightTexture.pack(blockLight, skyLight));
}

@Override
public ColoredLitInstance light(int packedLight) {
this.packedLight = packedLight;
public ColoredLitInstance overlay(int overlay) {
this.overlay = overlay;
return this;
}

public ColoredLitInstance setOverlay(int overlay) {
this.overlay = overlay;
@Override
public ColoredLitInstance light(int light) {
this.light = light;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
package dev.engine_room.flywheel.lib.instance;

import java.util.Iterator;
import java.util.stream.Stream;

import org.jetbrains.annotations.Nullable;

import dev.engine_room.flywheel.api.instance.Instance;
import dev.engine_room.flywheel.lib.visual.AbstractVisual;
import dev.engine_room.flywheel.lib.visual.AbstractBlockEntityVisual;
import dev.engine_room.flywheel.lib.visual.AbstractEntityVisual;
import net.minecraft.client.renderer.LightTexture;

/**
* An interface that implementors of {@link Instance} should also implement
* if they wish to make use of the relighting utilities in {@link AbstractVisual}.
* An interface that implementors of {@link Instance} should also implement if they wish to make use of
* {@link #relight} and the relighting utilities in {@link AbstractBlockEntityVisual} and {@link AbstractEntityVisual}.
*/
public interface FlatLit extends Instance {
/**
* Set the block and sky light values for this instance.
* @param blockLight Block light value
* @param skyLight Sky light value
* Set the packed light value for this instance.
* @param packedLight Packed block and sky light per {@link LightTexture#pack(int, int)}
* @return {@code this} for chaining
*/
FlatLit light(int blockLight, int skyLight);
FlatLit light(int packedLight);

/**
* Set the packed light value for this instance.
* @param packedLight Packed block and sky light per {@link LightTexture#pack(int, int)}
* Set the block and sky light values for this instance.
* @param blockLight Block light value
* @param skyLight Sky light value
* @return {@code this} for chaining
*/
FlatLit light(int packedLight);
default FlatLit light(int blockLight, int skyLight) {
return light(LightTexture.pack(blockLight, skyLight));
}

static void relight(int packedLight, @Nullable FlatLit... instances) {
for (FlatLit instance : instances) {
if (instance != null) {
instance.light(packedLight)
.handle()
.setChanged();
}
}
}

static void relight(int packedLight, Iterator<@Nullable FlatLit> instances) {
while (instances.hasNext()) {
FlatLit instance = instances.next();

if (instance != null) {
instance.light(packedLight)
.handle()
.setChanged();
}
}
}

static void relight(int packedLight, Iterable<@Nullable FlatLit> instances) {
relight(packedLight, instances.iterator());
}

static void relight(int packedLight, Stream<@Nullable FlatLit> instances) {
relight(packedLight, instances.iterator());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.engine_room.flywheel.api.layout.FloatRepr;
import dev.engine_room.flywheel.api.layout.IntegerRepr;
import dev.engine_room.flywheel.api.layout.LayoutBuilder;
import dev.engine_room.flywheel.lib.math.MatrixMath;
import dev.engine_room.flywheel.lib.util.ExtraMemoryOps;

public final class InstanceTypes {
public static final InstanceType<TransformedInstance> TRANSFORMED = SimpleInstanceType.builder(TransformedInstance::new)
Expand All @@ -24,12 +24,10 @@ public final class InstanceTypes {
MemoryUtil.memPutByte(ptr + 1, instance.g);
MemoryUtil.memPutByte(ptr + 2, instance.b);
MemoryUtil.memPutByte(ptr + 3, instance.a);
MemoryUtil.memPutShort(ptr + 4, (short) (instance.overlay & 0xFFFF));
MemoryUtil.memPutShort(ptr + 6, (short) (instance.overlay >> 16 & 0xFFFF));
MemoryUtil.memPutShort(ptr + 8, (short) (instance.packedLight & 0xFFFF));
MemoryUtil.memPutShort(ptr + 10, (short) (instance.packedLight >> 16 & 0xFFFF));
MatrixMath.writeUnsafe(ptr + 12, instance.model);
MatrixMath.writeUnsafe(ptr + 76, instance.normal);
ExtraMemoryOps.put2x16(ptr + 4, instance.overlay);
ExtraMemoryOps.put2x16(ptr + 8, instance.light);
ExtraMemoryOps.putMatrix4f(ptr + 12, instance.model);
ExtraMemoryOps.putMatrix3f(ptr + 76, instance.normal);
})
.vertexShader(Flywheel.rl("instance/transformed.vert"))
.cullShader(Flywheel.rl("instance/cull/transformed.glsl"))
Expand All @@ -49,20 +47,15 @@ public final class InstanceTypes {
MemoryUtil.memPutByte(ptr + 1, instance.g);
MemoryUtil.memPutByte(ptr + 2, instance.b);
MemoryUtil.memPutByte(ptr + 3, instance.a);
MemoryUtil.memPutShort(ptr + 4, (short) (instance.overlay & 0xFFFF));
MemoryUtil.memPutShort(ptr + 6, (short) (instance.overlay >> 16 & 0xFFFF));
MemoryUtil.memPutShort(ptr + 8, (short) (instance.packedLight & 0xFFFF));
MemoryUtil.memPutShort(ptr + 10, (short) (instance.packedLight >> 16 & 0xFFFF));
ExtraMemoryOps.put2x16(ptr + 4, instance.overlay);
ExtraMemoryOps.put2x16(ptr + 8, instance.light);
MemoryUtil.memPutFloat(ptr + 12, instance.posX);
MemoryUtil.memPutFloat(ptr + 16, instance.posY);
MemoryUtil.memPutFloat(ptr + 20, instance.posZ);
MemoryUtil.memPutFloat(ptr + 24, instance.pivotX);
MemoryUtil.memPutFloat(ptr + 28, instance.pivotY);
MemoryUtil.memPutFloat(ptr + 32, instance.pivotZ);
MemoryUtil.memPutFloat(ptr + 36, instance.rotation.x);
MemoryUtil.memPutFloat(ptr + 40, instance.rotation.y);
MemoryUtil.memPutFloat(ptr + 44, instance.rotation.z);
MemoryUtil.memPutFloat(ptr + 48, instance.rotation.w);
ExtraMemoryOps.putQuaternionf(ptr + 36, instance.rotation);
})
.vertexShader(Flywheel.rl("instance/oriented.vert"))
.cullShader(Flywheel.rl("instance/cull/oriented.glsl"))
Expand Down
Loading

0 comments on commit a9c4e5c

Please sign in to comment.