Skip to content

Commit

Permalink
Merge pull request #99 from Goby56/dev
Browse files Browse the repository at this point in the history
Correct node insertions
  • Loading branch information
Goby56 authored Aug 24, 2024
2 parents 14c9b82 + eeb13e3 commit a0898e9
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 187 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/goby56/wakes/config/WakesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class WakesConfig {
"mobs", EffectSpawningRule.ONLY_SIMULATION,
"items", EffectSpawningRule.ONLY_SIMULATION
));
public boolean wakesInRunningWater = false;

// Behaviour
public float wavePropagationFactor = 0.95f;
Expand All @@ -38,7 +37,7 @@ public class WakesConfig {

// Debug
public boolean disableMod = false;
public int floodFillDistance = 3;
public int floodFillDistance = 2;
public int ticksBeforeFill = 2;
public boolean pickBoat = true;
public RenderType renderType = RenderType.AUTO;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/goby56/wakes/config/YACLIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public static Screen createScreen(Screen parent) {
.option(effectSpawningRuleOption("other_players", EffectSpawningRule.ONLY_SIMULATION))
.option(effectSpawningRuleOption("mobs", EffectSpawningRule.ONLY_SIMULATION))
.option(effectSpawningRuleOption("items", EffectSpawningRule.ONLY_SIMULATION))
.option(booleanOption("wakes_in_running_water", false)
.binding(false, () -> config.wakesInRunningWater, val -> config.wakesInRunningWater = val)
.build())
.option(booleanOption("spawn_particles", false)
.binding(true, () -> config.spawnParticles, val -> config.spawnParticles = val)
.build())
Expand Down Expand Up @@ -120,7 +117,7 @@ public static Screen createScreen(Screen parent) {
.enumClass(RenderType.class))
.build())
.option(optionOf(Integer.class, "flood_fill_distance", false)
.binding(3, () -> config.floodFillDistance, val -> config.floodFillDistance = val)
.binding(2, () -> config.floodFillDistance, val -> config.floodFillDistance = val)
.controller(opt -> integerSlider(opt, 1, 5))
.build())
.option(optionOf(Integer.class, "ticks_before_fill", false)
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.simulation.WakeNode;
import kroppeb.stareval.function.Type;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.render.debug.DebugRenderer;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class WakeDebugRenderer implements WorldRenderEvents.DebugRender {
Expand All @@ -20,14 +23,13 @@ public void beforeDebugRender(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance();
if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) {
for (var node : wakeHandler.getVisible(context.frustum(), WakeNode.class)) {
Box box = new Box(node.x, node.height - 0.1f, node.z, node.x + 1, node.height - 0.2f, node.z + 1);
DebugRenderer.drawBox(context.matrixStack(), context.consumers(),
box.offset(context.camera().getPos().negate()),
node.toBox().offset(context.camera().getPos().negate()),
1, 0, 1, 0.5f);
}
for (var brick : wakeHandler.getVisible(context.frustum(), Brick.class)) {
Vec3d pos = brick.pos;
Box box = new Box(pos.x, pos.y - 0.2f, pos.z, pos.x + brick.dim, pos.y - 0.3f, pos.z + brick.dim);
Box box = new Box(pos.x, pos.y - (1 - WakeNode.WATER_OFFSET), pos.z, pos.x + brick.dim, pos.y, pos.z + brick.dim);
var col = Color.getHSBColor(new Random(pos.hashCode()).nextFloat(), 1f, 1f).getRGBColorComponents(null);
DebugRenderer.drawBox(context.matrixStack(), context.consumers(),
box.offset(context.camera().getPos().negate()),
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/goby56/wakes/debug/WakesDebugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,22 @@

public class WakesDebugInfo {
public static double nodeLogicTime = 0;
public static double insertionTime = 0;
public static double texturingTime = 0;
public static ArrayList<Long> cullingTime = new ArrayList<>();
public static ArrayList<Long> renderingTime = new ArrayList<>(); // Frames averaged each tick
public static int quadsRendered = 0;
public static int nodeCount = 0;

public static void reset() {
nodeCount = 0;
nodeLogicTime = 0;
insertionTime = 0;
texturingTime = 0;
cullingTime = new ArrayList<>();
renderingTime = new ArrayList<>();
}

public static void show(CallbackInfoReturnable<List<String>> info) {
int q = WakesDebugInfo.quadsRendered;
info.getReturnValue().add(String.format("[Wakes] Rendering %d quads for %d wake nodes", q, WakesDebugInfo.nodeCount));
info.getReturnValue().add(String.format("[Wakes] Rendering %d quads for %d wake nodes", WakesDebugInfo.quadsRendered, WakesDebugInfo.nodeCount));
info.getReturnValue().add(String.format("[Wakes] Node logic: %.2fms/t", 10e-6 * WakesDebugInfo.nodeLogicTime));
info.getReturnValue().add(String.format("[Wakes] Insertion: %.2fms/t", 10e-6 * WakesDebugInfo.insertionTime));
info.getReturnValue().add(String.format("[Wakes] Texturing: %.2fms/t", 10e-6 * WakesDebugInfo.texturingTime));
info.getReturnValue().add(String.format("[Wakes] Culling: %.3fms/f", 10e-6 * WakesDebugInfo.cullingTime.stream().reduce(0L, Long::sum) / WakesDebugInfo.cullingTime.size()));
info.getReturnValue().add(String.format("[Wakes] Rendering: %.3fms/f", 10e-6 * WakesDebugInfo.renderingTime.stream().reduce(0L, Long::sum) / WakesDebugInfo.renderingTime.size()));
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/goby56/wakes/duck/ProducesWake.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface ProducesWake {
boolean onWaterSurface();
float producingHeight();
Float producingWaterLevel();
void setProducingHeight(float h);
Vec3d getPrevPos();
void setPrevPos(Vec3d pos);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/goby56/wakes/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.goby56.wakes.mixin;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.debug.WakesDebugInfo;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,7 +16,11 @@ public abstract class DebugHudMixin {
@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
if (WakesClient.CONFIG_INSTANCE.showDebugInfo) {
WakesDebugInfo.show(info);
if (WakesClient.CONFIG_INSTANCE.disableMod) {
info.getReturnValue().add("[Wakes] Mod disabled!");
} else {
WakesDebugInfo.show(info);
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/LilyPadFallMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.enums.EffectSpawningRule;
import com.goby56.wakes.duck.ProducesWake;
import com.goby56.wakes.simulation.WakeNode;
import com.goby56.wakes.utils.WakesUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -27,7 +28,7 @@ public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity ent
EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(entity);
ProducesWake wakeProducer = (ProducesWake) entity;
if (rule.simulateWakes) {
wakeProducer.setProducingHeight(pos.getY() + world.getFluidState(pos).getHeight());
wakeProducer.setProducingHeight(pos.getY() + WakeNode.WATER_OFFSET);
WakesUtils.placeFallSplash(entity);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setPrevPos(Vec3d pos) {
}

@Override
public float producingHeight() {
public Float producingWaterLevel() {
return this.producingWaterLevel;
}

Expand Down Expand Up @@ -113,8 +113,7 @@ private void tick(CallbackInfo info) {
}

if (this.onWaterSurface && !this.hasRecentlyTeleported) {
if (this.producingWaterLevel == null)
this.producingWaterLevel = WakesUtils.getWaterLevel(this.world, thisEntity);
this.producingWaterLevel = WakesUtils.getWaterLevel(this.world, thisEntity);

Vec3d currPos = new Vec3d(thisEntity.getX(), this.producingWaterLevel, thisEntity.getZ());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.goby56.wakes.particle.custom;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.duck.ProducesWake;
import com.goby56.wakes.particle.WithOwnerParticleType;
import com.goby56.wakes.simulation.WakeNode;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void tick() {

Vec3d particleOffset = new Vec3d(-splashPlane.direction.z, 0f, splashPlane.direction.x).multiply(this.offset * this.owner.getWidth() / 2f);
Vec3d pos = splashPlane.getPos().add(particleOffset).add(splashPlane.direction.multiply(-0.2f));
this.setPos(pos.x, wake.producingHeight(), pos.z);
this.setPos(pos.x, pos.y, pos.z);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.goby56.wakes.particle.ModParticles;
import com.goby56.wakes.particle.WithOwnerParticleType;
import com.goby56.wakes.render.SplashPlaneRenderer;
import com.goby56.wakes.simulation.WakeNode;
import com.goby56.wakes.utils.WakesUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -24,14 +25,10 @@
import net.minecraft.util.math.*;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Random;

public class SplashPlaneParticle extends Particle {
Entity owner;
float yaw;
float prevYaw;
int ticksSinceSplash = 0;

Vec3d direction = Vec3d.ZERO;

Expand Down Expand Up @@ -71,7 +68,6 @@ public void tick() {
}

private void aliveTick(ProducesWake wakeProducer) {
this.ticksSinceSplash++;
if (this.owner instanceof BoatEntity) {
this.yaw = -this.owner.getYaw();
} else {
Expand All @@ -81,7 +77,7 @@ private void aliveTick(ProducesWake wakeProducer) {
this.direction = Vec3d.fromPolar(0, -this.yaw);
Vec3d planeOffset = direction.multiply(this.owner.getWidth() + WakesClient.CONFIG_INSTANCE.splashPlaneOffset);
Vec3d planePos = this.owner.getPos().add(planeOffset);
this.setPos(planePos.x, wakeProducer.producingHeight(), planePos.z);
this.setPos(planePos.x, wakeProducer.producingWaterLevel(), planePos.z);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static <T extends Entity> void render(T entity, float yaw, float tickDelt
matrices.scale(scalar, scalar, scalar);
Matrix4f matrix = matrices.peek().getPositionMatrix();

// TODO MAKE SPLASH PLANE LOOK MORE LIKE WAKES (SIMULATE AND COLOR EACH PIXEL)
Vector3f color = new Vector3f();
int waterCol = BiomeColors.getWaterColor(entity.getWorld(), entity.getBlockPos());
color.x = (float) (waterCol >> 16 & 0xFF) / 255f;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/goby56/wakes/render/WakeRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Resolution.THIRTYTWO, new WakeTexture(Resolution.THIRTYTWO.res)
@Override
public void afterTranslucent(WorldRenderContext context) {
if (WakesClient.CONFIG_INSTANCE.disableMod) {
WakesDebugInfo.quadsRendered = 0;
return;
}

Expand All @@ -35,9 +36,7 @@ public void afterTranslucent(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance();
if (wakeHandler == null || wakeHandler.resolutionResetScheduled) return;

long tCulling = System.nanoTime();
ArrayList<Brick> bricks = wakeHandler.getVisible(context.frustum(), Brick.class);
WakesDebugInfo.cullingTime.add(System.nanoTime() - tCulling);

Matrix4f matrix = context.matrixStack().peek().getPositionMatrix();
RenderSystem.enableBlend();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/goby56/wakes/render/WakeTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goby56.wakes.render.enums.RenderType;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.QuadTree;
import com.goby56.wakes.simulation.WakeNode;
import com.mojang.blaze3d.platform.GlConst;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void render(Matrix4f matrix, Camera camera, Brick brick) {
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);

Vector3f pos = brick.pos.add(camera.getPos().negate()).toVector3f();
Vector3f pos = brick.pos.add(camera.getPos().negate()).toVector3f().add(0, WakeNode.WATER_OFFSET, 0);
int light = LightmapTextureManager.MAX_LIGHT_COORDINATE;
buffer.vertex(matrix, pos.x, pos.y, pos.z)
.color(1f, 1f, 1f, 1f)
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/goby56/wakes/simulation/Age.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/com/goby56/wakes/simulation/Position.java

This file was deleted.

5 changes: 2 additions & 3 deletions src/main/java/com/goby56/wakes/simulation/QuadTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class QuadTree {
private final DecentralizedBounds bounds;
private final int depth;
private Brick brick;
private final float yLevel;
public final float yLevel;

public QuadTree(float y) {
this(ROOT_X, y, ROOT_Z, ROOT_WIDTH, 0, null);
Expand All @@ -38,7 +38,7 @@ private boolean hasLeaf() {

private void initLeaf() {
if (depth >= MAX_DEPTH) {
this.brick = new Brick(bounds.x, yLevel, bounds.z, bounds.width);
this.brick = new Brick(bounds.x, this.yLevel, bounds.z, bounds.width);
this.ROOT.updateAdjacency(this);
}
}
Expand Down Expand Up @@ -97,7 +97,6 @@ public <T> void query(Frustum frustum, ArrayList<T> output, Class<T> type) {
return;
}
if (hasLeaf() && brick.occupied > 0) {
// TODO ADD VISIBLE NODES CHECK
if (type.equals(Brick.class)) {
output.add(type.cast(brick));
}
Expand Down
Loading

0 comments on commit a0898e9

Please sign in to comment.