Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Goby56 committed Aug 18, 2024
2 parents ada3530 + c23bdf5 commit c6d1b43
Show file tree
Hide file tree
Showing 41 changed files with 935 additions and 803 deletions.
9 changes: 9 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Changes
- Added bricks. Variable sized storage containers for wake nodes which should provide faster node retrievals and reduce drawing times as there are fewer quads rendered. This may fix issue #41.
- One quad rendered per brick, was originally one quad per node.
- As the nodes are no longer rendered per block the correct light information while rendering can't be provided. The light color is, therefore, baked into the actual pixel colors which are calculated once per tick.
- Every brick now has its texture storage which does use up a bit more memory than just having one texture. But this enables per tick coloring as opposed to per frame coloring which is much faster.
- Also removed memory leak caused by texture pointers being allocated but not deallocated. #89 This was when the textures was stored in each node (0.2.5)
- Removed LODs as the implementation didn't provide any performance benefits.
- Improved splashes at the front of the boat. The planes are now static for boats, have fixed splash clouds at the front and stationary clouds at paddle splashes.
- Shader compatibilty has probably been changed due to the new lighting method. A slider in the wake appearance config tab allowing the user to manually fine tune the look has been added.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.2
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.15.11

# Fabric API
fabric_version=0.100.4+1.21
fabric_version=0.102.1+1.21.1

# Mod Properties
mod_version=0.2.5+1.21
mod_version=0.3.0+1.20.1
maven_group=com.goby56.wakes
archives_base_name=wakes

Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/goby56/wakes/WakesClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.goby56.wakes;

import com.goby56.wakes.command.DebugCommand;
import com.goby56.wakes.debug.DebugCommand;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.event.PickBoat;
import com.goby56.wakes.event.WakeTicker;
import com.goby56.wakes.particle.ModParticles;
import com.goby56.wakes.render.SplashPlaneRenderer;
import com.goby56.wakes.render.WakeTextureRenderer;
import com.goby56.wakes.render.debug.WakeDebugRenderer;
import com.goby56.wakes.render.WakeRenderer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
Expand All @@ -33,19 +33,16 @@ public class WakesClient implements ClientModInitializer {
public static WakesConfig CONFIG_INSTANCE;
public static final ManagedCoreShader TRANSLUCENT_NO_LIGHT_DIRECTION_PROGRAM = ShaderEffectManager.getInstance().manageCoreShader(
Identifier.of(MOD_ID, "translucent_no_light_direction"), VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);
public static boolean areShadersEnabled = false;

@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
FabricLoader.getInstance().getModContainer(MOD_ID).ifPresent(container -> METADATA = container.getMetadata());

// Mod configs
// AutoConfig.register(WakesConfig.class, GsonConfigSerializer::new);
CONFIG_INSTANCE = WakesConfig.loadConfig();

// Models
//EntityModelLayerRegistry.registerModelLayer(WakeModel.MODEL_LAYER, WakeModel::getTexturedModelData);

// Particles
ModParticles.registerParticles();

Expand All @@ -54,7 +51,7 @@ public void onInitializeClient() {
ClientPickBlockGatherCallback.EVENT.register(new PickBoat());

// Rendering events
WorldRenderEvents.AFTER_TRANSLUCENT.register(new WakeTextureRenderer());
WorldRenderEvents.AFTER_TRANSLUCENT.register(new WakeRenderer());
WorldRenderEvents.BEFORE_DEBUG_RENDER.register(new WakeDebugRenderer());

ClientLifecycleEvents.CLIENT_STARTED.register(new SplashPlaneRenderer());
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/goby56/wakes/config/WakesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public class WakesConfig {
public boolean disableMod = false;
public int floodFillDistance = 3;
public int ticksBeforeFill = 2;
public boolean debugMode = false;
public boolean pickBoat = true;
public RenderType renderType = RenderType.AUTO;
public boolean useLODs = false;
public boolean drawDebugBoxes = false;
public boolean showDebugInfo = false;
public float shaderLightPassthrough = 0.5f;

// Appearance
public Resolution wakeResolution = Resolution.SIXTEEN;
Expand Down Expand Up @@ -87,13 +88,14 @@ public void setUpper(int upper) {
}

// Splash plane
public float splashPlaneWidth = 3f;
public float splashPlaneWidth = 2f;
public float splashPlaneHeight = 1.5f;
public float splashPlaneDepth = 2f;
public float splashPlaneDepth = 3f;
public float splashPlaneOffset = -0.2f;
public float splashPlaneGap = 1f;
public int splashPlaneResolution = 5;
public float maxSplashPlaneVelocity = 0.5f;
public float splashPlaneScale = 1f;
public float splashPlaneOffset = 0f;
public float splashPlaneScale = 0.8f;

public static WakesConfig loadConfig() {
Jankson jankson = Jankson.builder().build();
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/goby56/wakes/config/YACLIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static Screen createScreen(Screen parent) {
.binding(100, () -> (int) (config.wakeOpacity * 100), val -> config.wakeOpacity = val / 100f)
.controller(opt -> integerSlider(opt, 0, 100))
.build())
.option(optionOf(Float.class, "shader_light_passthrough", true)
.binding(0.5f, () -> config.shaderLightPassthrough, val -> config.shaderLightPassthrough = val)
.controller(opt -> floatSlider(opt, 0, 1, 0.01f))
.build())
.build())
.group(group("effect_spawning")
.option(effectSpawningRuleOption("boat", EffectSpawningRule.SIMULATION_AND_PLANES))
Expand Down Expand Up @@ -68,23 +72,27 @@ public static Screen createScreen(Screen parent) {
.controller(opt -> floatSlider(opt, 0.1f, 2f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.scale", false)
.binding(1f, () -> config.splashPlaneScale, val -> config.splashPlaneScale = val)
.binding(0.8f, () -> config.splashPlaneScale, val -> config.splashPlaneScale = val)
.controller(opt -> floatSlider(opt, 0.1f, 2f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.offset", false)
.binding(0f, () -> config.splashPlaneOffset, val -> config.splashPlaneOffset = val)
.binding(-0.2f, () -> config.splashPlaneOffset, val -> config.splashPlaneOffset = val)
.controller(opt -> floatSlider(opt, -1f, 1f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.gap", false)
.binding(1f, () -> config.splashPlaneGap, val -> config.splashPlaneGap = val)
.controller(opt -> floatSlider(opt, 0f, 2f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.width", false)
.binding(3f, () -> config.splashPlaneWidth, val -> config.splashPlaneWidth = val)
.binding(2f, () -> config.splashPlaneWidth, val -> config.splashPlaneWidth = val)
.controller(opt -> floatSlider(opt, 0f, 10f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.height", false)
.binding(1.5f, () -> config.splashPlaneHeight, val -> config.splashPlaneHeight = val)
.controller(opt -> floatSlider(opt, 0f, 10f, 0.1f))
.build())
.option(optionOf(Float.class, "splash_plane.depth", false)
.binding(2f, () -> config.splashPlaneDepth, val -> config.splashPlaneDepth = val)
.binding(3f, () -> config.splashPlaneDepth, val -> config.splashPlaneDepth = val)
.controller(opt -> floatSlider(opt, 0f, 10f, 0.1f))
.build())
.build())
Expand Down Expand Up @@ -125,12 +133,12 @@ public static Screen createScreen(Screen parent) {
.option(booleanOption("pick_boat", false)
.binding(true, () -> config.pickBoat, val -> config.pickBoat = val)
.build())
.option(booleanOption("show_debug_info", false)
.binding(false, () -> config.showDebugInfo, val -> config.showDebugInfo = val)
.build())
.option(booleanOption("disable_mod", false)
.binding(false, () -> config.disableMod, val -> config.disableMod = val)
.build())
.option(booleanOption("use_lods", false)
.binding(false, () -> config.useLODs, val -> config.useLODs = val)
.build())
.group(intervalGroup(0, WakeColor.TRANSPARENT, -50, -45))
.group(intervalGroup(1, WakeColor.DARK_GRAY, -45, -35))
.group(intervalGroup(2, WakeColor.GRAY, -35, -30))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.goby56.wakes.command;
package com.goby56.wakes.debug;

import com.goby56.wakes.particle.ModParticles;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.simulation.WakeNode;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.fluid.FluidState;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.text.Text;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.Vec3d;
Expand All @@ -27,10 +28,25 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(ClientCommandManager.literal("color")
.executes(DebugCommand::waterColor))
.then(ClientCommandManager.literal("spawn")
.then(ClientCommandManager.literal("splash_cloud_particle")
.executes(DebugCommand::spawnSplashCloudParticle))));
.then(ClientCommandManager.literal("node")
.then(ClientCommandManager.argument("flood_level", IntegerArgumentType.integer(0, 5))
.executes(DebugCommand::spawnWakeNode)))));
//.then(ClientCommandManager.literal("splash_cloud_particle")
//.executes(DebugCommand::spawnSplashCloudParticle)))));
}

public static int spawnWakeNode(CommandContext<FabricClientCommandSource> cmdCtx) throws CommandSyntaxException {
HitResult result = cmdCtx.getSource().getPlayer().raycast(10, 0, true);
Vec3d pos = result.getPos();
if (!result.getType().equals(HitResult.Type.BLOCK)) return 0;
if (!cmdCtx.getSource().getWorld().getFluidState(new BlockPos((int) pos.x, (int) Math.floor(pos.y), (int) pos.z)).isIn(FluidTags.WATER)) return 0;
WakeNode node = new WakeNode(result.getPos(), 100);
node.floodLevel = cmdCtx.getArgument("flood_level", Integer.class);
WakeHandler.getInstance().insert(node);
return 1;
}


public static int lightCoordinate(CommandContext<FabricClientCommandSource> cmdCtx) throws CommandSyntaxException {
World world = cmdCtx.getSource().getWorld();
BlockPos blockPos = cmdCtx.getSource().getPlayer().getBlockPos();
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.goby56.wakes.debug;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.simulation.WakeNode;
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.Random;

public class WakeDebugRenderer implements WorldRenderEvents.DebugRender {

@Override
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()),
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);
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()),
col[0], col[1], col[2], 0.5f);
}
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/goby56/wakes/debug/WakesDebugInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.goby56.wakes.debug;

import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.List;

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] 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: 2 additions & 0 deletions src/main/java/com/goby56/wakes/duck/ProducesWake.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface ProducesWake {

void setRecentlyTeleported(boolean b);

SplashPlaneParticle getSplashPlane();

}
4 changes: 4 additions & 0 deletions src/main/java/com/goby56/wakes/event/WakeTicker.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.goby56.wakes.event;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.render.SplashPlaneRenderer;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.debug.WakesDebugInfo;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.world.ClientWorld;

public class WakeTicker implements ClientTickEvents.EndWorldTick {
@Override
public void onEndTick(ClientWorld world) {
WakesClient.areShadersEnabled = WakesClient.areShadersEnabled();
WakesDebugInfo.reset();
WakeHandler.getInstance().tick();
SplashPlaneRenderer.tick();
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/goby56/wakes/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.goby56.wakes.mixin;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.render.WakeTextureRenderer;
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;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -12,13 +12,12 @@
import java.util.List;

@Mixin(DebugHud.class)
public class DebugHudMixin {
public abstract class DebugHudMixin {

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
if (WakesClient.CONFIG_INSTANCE.debugMode) {
info.getReturnValue().add(String.format("[Wakes] Rendering %d/%d wake nodes", WakeTextureRenderer.nodesRendered, WakeHandler.getInstance().getTotal()));
info.getReturnValue().add(String.format("[Wakes] Max tree depth: %d", WakeHandler.getInstance().getMaxDepth()));
if (WakesClient.CONFIG_INSTANCE.showDebugInfo) {
WakesDebugInfo.show(info);
}
}
}
}
1 change: 0 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/LilyPadFallMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class LilyPadFallMixin {
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance, CallbackInfo ci) {
if (!world.getBlockState(pos.up()).isOf(Blocks.LILY_PAD)) return;
if (WakesClient.CONFIG_INSTANCE.disableMod) return;

EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(entity);
ProducesWake wakeProducer = (ProducesWake) entity;
if (rule.simulateWakes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.goby56.wakes.mixin;

import com.goby56.wakes.duck.ProducesWake;
import net.minecraft.entity.ai.goal.FollowOwnerGoal;
import net.minecraft.entity.passive.TameableEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand Down
Loading

0 comments on commit c6d1b43

Please sign in to comment.