Skip to content

Commit

Permalink
feat: clumping echoes in nuggets
Browse files Browse the repository at this point in the history
Now we have:

- limited number of `Echo`s -- they should be ideally only one per Id,
  for now it is one per one scan; in the future, the label might be also
  stored there
- `BlockEcho` is an `Echo` with a position and ping time.
- _(new)_ `EchoState` is a `BlockEcho`, with information, which sides
  and edges are visible
- _(new)_ `EchoNugget` is a clump of all touching echoes of the same id
- `BlockEchoes` is a container for all known `BlockEcho`es and now a
  container of all known `EchoNugget`s

fixes: #22
closes: #23
  • Loading branch information
mzdun committed Oct 9, 2024
1 parent 1a8b096 commit 1dfd23d
Show file tree
Hide file tree
Showing 35 changed files with 1,616 additions and 272 deletions.
18 changes: 11 additions & 7 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
- [x] `NullPointerException` when a scanner is active and world disappears (bug: #21, pr: #25)
- [ ] clumps of blocks (bug for internal walls: #22, issue: #23, pr: ?)
- [ ] bounds for frustum
- [ ] walls no longer flicker
- [ ] focused clump has an outline (at minimum, `DEBUG_LINES`) — so we have external vertices for camera distance calculation
- [x] walls no longer flicker
- [x] focused clump has an outline (at minimum, `DEBUG_LINES`) — ...
- [ ] ... so we have external vertices for camera distance calculation

## Bugs

- [ ] Settings
- [ ] only one setting at a time is saved
- [x] Settings
- [x] only one setting at a time is saved

- [ ] Scanner
- [ ] internal walls tend to flicker in and out of existence
- [ ] closing app / disconnecting from server ends with a `NullPointerException` if the scanner is active
- [x] Scanner
- [x] internal walls tend to flicker in and out of existence
- [x] closing app / disconnecting from server ends with a `NullPointerException` if the scanner is active

## Features

- [ ] Settings
- [ ] per-world saves on top of common defaults
- [ ] _end of minimal viable code_
- [ ] Scanner
- [ ] clumps of blocks
- [ ] label the clumps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void initialize(Sonar source) {
return;

this.tick(Clock.currentTimeMillis());
this.source.remove(this.source.oldEchoes(new MinecraftClientCore(client)));
if (this.source.remove(this.source.oldEchoes(new MinecraftClientCore(client))))
this.source.splitToNuggets();
});
WorldRenderEvents.LAST.register(this::renderLevel);
}
Expand All @@ -45,6 +46,6 @@ public void apply(List<Shimmers> shimmers) {
private void renderLevel(WorldRenderContext context) {
final var shimmers = new GatherShimmers();
this.run(shimmers);
Pixel.renderLevel(context, source.echoes(), shimmers.cloud);
Pixels.renderLevel(context, source.nuggets(), shimmers.cloud);
}
}
57 changes: 0 additions & 57 deletions fabric/any/src/main/java/com/midnightbits/scanner/fabric/Mesh.java

This file was deleted.

179 changes: 0 additions & 179 deletions fabric/any/src/main/java/com/midnightbits/scanner/fabric/Pixel.java

This file was deleted.

103 changes: 103 additions & 0 deletions fabric/any/src/main/java/com/midnightbits/scanner/fabric/Pixels.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) 2024 Marcin Zdun
// This code is licensed under MIT license (see LICENSE for details)

package com.midnightbits.scanner.fabric;

import java.util.List;

import com.midnightbits.scanner.sonar.EchoNugget;
import com.midnightbits.scanner.sonar.graphics.*;
import net.minecraft.client.render.*;
import net.minecraft.util.math.Box;
import org.joml.Matrix4f;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;

import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;

public class Pixels {

private record GlProgramVertexConsumer(VertexConsumer buffer) implements GlProgramConsumer {
@Override
public void vertexColor(Matrix4f matrix, float x, float y, float z, int argb32) {
buffer.vertex(matrix, x, y, z).color(argb32);
}
}

public static void renderLevel(WorldRenderContext context, List<EchoNugget> nuggets, List<Shimmers> shimmers) {
final var frustum = context.frustum();
if (frustum == null) {
return;
}

final var contextMatrices = context.matrixStack();
if (contextMatrices == null) {
return;
}

final var matrices = new MatrixStack(contextMatrices.peek().getPositionMatrix());

final var camera = context.camera();
final var cameraPos = camera.getPos().toVector3f();

final var frustumFilter = new FrustumFilter() {
@Override
public boolean contains(EchoState.AABB bounds) {
return frustum.isVisible(
new Box(bounds.minX(), bounds.minY(), bounds.minZ(),
bounds.maxX(), bounds.maxY(), bounds.maxZ()));
}
};

final var allShimmers = EchoNugget.group(Shimmers.toEchoStates(shimmers, .5));

final var visibleNuggets = EchoNugget.filterVisible(nuggets, frustumFilter);
final var visibleShimmers = EchoNugget.filterVisible(allShimmers, frustumFilter);

if (visibleNuggets.isEmpty() && visibleShimmers.isEmpty()) {
return;
}

RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFunc(
GlStateManager.SrcFactor.SRC_ALPHA,
GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

final var tessellator = Tessellator.getInstance();
{
final var buffer = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
final var glProgram = new GlProgramVertexConsumer(buffer);

for (final var nugget : visibleShimmers) {
nugget.draw(glProgram, matrices, cameraPos);
}

for (final var nugget: visibleNuggets) {
nugget.draw(glProgram, matrices, cameraPos);
}

final var builtBuffer = buffer.endNullable();
if (builtBuffer != null)
BufferRenderer.drawWithGlobalProgram(builtBuffer);
}

{
final var buffer = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
final var glProgram = new GlProgramVertexConsumer(buffer);

for (final var nugget: visibleNuggets) {
nugget.sketch(glProgram, matrices, cameraPos);
}

final var builtBuffer = buffer.endNullable();
if (builtBuffer != null)
BufferRenderer.drawWithGlobalProgram(builtBuffer);
}

RenderSystem.enableDepthTest();
}
}
Loading

0 comments on commit 1dfd23d

Please sign in to comment.