Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
odeyaioo committed Jul 27, 2024
1 parent 46947e6 commit 670c7b8
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/vulkanmod/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Config {
public VideoModeSet.VideoMode videoMode = VideoModeManager.getFirstAvailable().getVideoMode();
public boolean windowedFullscreen = false;

public int advCulling = 2;
public int chunkCulling = 2;
public boolean indirectDraw = false;

public int fogDistance = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import org.lwjgl.glfw.GLFW;

public class CyclingOptionWidget extends OptionWidget<CyclingOption<?>> {
private Button leftButton;
private Button rightButton;

private boolean focused;
private final Button leftButton;
private final Button rightButton;

public CyclingOptionWidget(CyclingOption<?> option, int x, int y, int width, int height, Component name) {
super(x, y, width, height, name);
Expand Down Expand Up @@ -108,16 +106,6 @@ protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY

}

@Override
public void setFocused(boolean bl) {
this.focused = bl;
}

@Override
public boolean isFocused() {
return this.focused;
}

class Button {
int x;
int width;
Expand Down Expand Up @@ -161,18 +149,17 @@ else if(this.active)

bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION);

float h = f;
float w = f - 1.0f;
float yC = y + height * 0.5f;
float xC = x + width * 0.5f;
if (this.direction == Direction.LEFT) {
bufferBuilder.vertex(matrix4f, xC - w, yC, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC + h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC - h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC + f, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC - f, 0).endVertex();
} else {
bufferBuilder.vertex(matrix4f, xC + w, yC, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC - h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC + h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC - f, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC + f, 0).endVertex();
}

tesselator.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
public class RangeOptionWidget extends OptionWidget<RangeOption> {
protected double value;

private boolean focused;

public RangeOptionWidget(RangeOption option, int x, int y, int width, int height, Component name) {
super(x, y, width, height, name);
this.setOption(option);
Expand Down Expand Up @@ -84,16 +82,6 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public void setFocused(boolean bl) {
this.focused = bl;
}

@Override
public boolean isFocused() {
return this.focused;
}

private void setValueFromMouse(double mouseX) {
this.setValue((mouseX - (double) (this.controlX + 4)) / (double) ((this.controlWidth) - 8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.lwjgl.glfw.GLFW;

public class SwitchOptionWidget extends OptionWidget<SwitchOption> {
private boolean focused;

public SwitchOptionWidget(SwitchOption option, int x, int y, int width, int height, Component name) {
super(x, y, width, height, name);
this.option = option;
Expand Down Expand Up @@ -99,15 +97,4 @@ protected void updateDisplayedValue() {
? Component.translatable("options.on")
: Component.translatable("options.off");
}

@Override
public void setFocused(boolean bl) {
this.focused = bl;
}

@Override
public boolean isFocused() {
return this.focused;
}

}
14 changes: 7 additions & 7 deletions src/main/java/net/vulkanmod/config/option/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ public static OptionBlock[] getGraphicsOpts() {
public static OptionBlock[] getOptimizationOpts() {
return new OptionBlock[]{
new OptionBlock("", new Option[]{
new CyclingOption<>(Component.translatable("vulkanmod.options.advCulling"),
new CyclingOption<>(Component.translatable("vulkanmod.options.chunkCulling"),
new Integer[]{1, 2, 3, 10},
value -> config.advCulling = value,
() -> config.advCulling)
value -> config.chunkCulling = value,
() -> config.chunkCulling)
.setTranslator(value -> Component.translatable(switch (value) {
case 1 -> "vulkanmod.options.advCulling.aggressive";
case 2 -> "vulkanmod.options.advCulling.normal";
case 3 -> "vulkanmod.options.advCulling.conservative";
case 1 -> "vulkanmod.options.chunkCulling.aggressive";
case 2 -> "vulkanmod.options.chunkCulling.normal";
case 3 -> "vulkanmod.options.chunkCulling.conservative";
case 10 -> "options.off";
default -> "vulkanmod.options.unknown";
}))
.setTooltip(Component.translatable("vulkanmod.options.advCulling.tooltip")),
.setTooltip(Component.translatable("vulkanmod.options.chunkCulling.tooltip")),
new SwitchOption(Component.translatable("vulkanmod.options.entityCulling"),
value -> config.entityCulling = value,
() -> config.entityCulling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SwitchOption(Component name, Consumer<Boolean> setter, Supplier<Boolean>
}

@Override
public OptionWidget createOptionWidget(int x, int y, int width, int height) {
public OptionWidget<?> createOptionWidget(int x, int y, int width, int height) {
return new SwitchOptionWidget(this, x, y, width, height, this.name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void resetUpdateQueues() {
}

private void updateRenderChunks() {
int maxDirectionsChanges = Initializer.CONFIG.advCulling - 1;
int maxDirectionsChanges = Initializer.CONFIG.chunkCulling - 1;

while (this.sectionQueue.hasNext()) {
RenderSection renderSection = this.sectionQueue.poll();
Expand Down
65 changes: 25 additions & 40 deletions src/main/java/net/vulkanmod/render/profiling/ProfilerOverlay.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package net.vulkanmod.render.profiling;

import com.google.common.base.Strings;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import net.vulkanmod.config.gui.GuiRenderer;
Expand All @@ -31,18 +29,23 @@ public class ProfilerOverlay {
private static Profiler.ProfilerResults lastResults;
private static long lastPollTime;
private static float frametime;

private static String buildStats;
// private static int node = -1;

private static int node = -1;
private final Minecraft minecraft;
private final Font font;

public ProfilerOverlay(Minecraft minecraft) {
this.minecraft = minecraft;
this.font = minecraft.font;
}

public static void createInstance(Minecraft minecraft) {
INSTANCE = new ProfilerOverlay(minecraft);
}

public static void toggle() {
shouldRender = !shouldRender;

Profiler.setActive(shouldRender);
}

Expand All @@ -51,23 +54,15 @@ public static void onKeyPress(int key) {
// node = v >= 0 && v <= 15 ? v-1 : node;
}

Minecraft minecraft;
Font font;

public ProfilerOverlay(Minecraft minecraft) {
this.minecraft = minecraft;
this.font = minecraft.font;
}

public void render(PoseStack poseStack) {
this.drawProfilerInfo(poseStack);
drawProfilerInfo(poseStack);
}

protected void drawProfilerInfo(PoseStack poseStack) {
private void drawProfilerInfo(PoseStack poseStack) {
List<String> infoList = buildInfo();

MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
GuiRenderer.guiGraphics = new GuiGraphics(Minecraft.getInstance(), bufferSource);
GuiRenderer.guiGraphics = new GuiGraphics(this.minecraft, bufferSource);
GuiRenderer.setPoseStack(poseStack);

final int lineHeight = 9;
Expand All @@ -81,17 +76,13 @@ protected void drawProfilerInfo(PoseStack poseStack) {

for (int i = 0; i < infoList.size(); ++i) {
String line = infoList.get(i);
if (Strings.isNullOrEmpty(line)) {
continue;
if (!Strings.isNullOrEmpty(line)) {
int textWidth = this.font.width(line);
int yPosition = xOffset + lineHeight * i;
GuiRenderer.fill(1, yPosition - 1, xOffset + textWidth + 1, yPosition + lineHeight - 1, backgroundColor);
}

int textWidth = this.font.width(line);
int yPosition = xOffset + lineHeight * i;

GuiRenderer.fill(1, yPosition - 1, xOffset + textWidth + 1, yPosition + lineHeight - 1, backgroundColor);
}

bufferSource.endBatch();
RenderSystem.disableBlend();

for (int i = 0; i < infoList.size(); ++i) {
Expand All @@ -101,33 +92,28 @@ protected void drawProfilerInfo(PoseStack poseStack) {
GuiRenderer.drawString(this.font, Component.literal(line), xOffset, yPosition, textColor);
}
}
}

bufferSource.endBatch();
}

private List<String> buildInfo() {
List<String> list = new ArrayList<>();
list.add("");
list.add("Profiler");

updateResults();

if (lastResults == null)
return list;
if (lastResults == null) return list;

int fps = Math.round(1000.0f / frametime);

list.add(String.format("FPS: %d Frametime: %.3f", fps, frametime));
list.add("");

var partialResults = lastResults.getPartialResults();
for (Profiler.Result result : partialResults) {
for (Profiler.Result result : lastResults.getPartialResults()) {
list.add(String.format("%s: %.3f", result.name, result.value));
}

list.add("");
list.add(MemoryManager.getInstance().getHeapStats());

// Section build stats
list.add("");
list.add("");
list.add(String.format("Build time: %.0fms", BuildTimeProfiler.getDeltaTime()));
Expand All @@ -143,26 +129,25 @@ private void updateResults() {
return;

Profiler.ProfilerResults results = Profiler.getMainProfiler().getProfilerResults();

if (results == null)
return;

frametime = results.getResult().value;
lastResults = results;

lastPollTime = System.nanoTime();

if (ChunkTask.BENCH)
buildStats = getBuildStats();
}

private String getBuildStats() {
var resourcesArray = WorldRenderer.getInstance().getTaskDispatcher().getResourcesArray();
BuilderResources[] resourcesArray = WorldRenderer.getInstance().getTaskDispatcher().getResourcesArray();
int totalTime = 0;
int buildCount = 0;

int totalTime = 0, buildCount = 0;
for (BuilderResources resources1 : resourcesArray) {
totalTime += resources1.getTotalBuildTime();
buildCount += resources1.getBuildCount();
for (BuilderResources resources : resourcesArray) {
totalTime += resources.getTotalBuildTime();
buildCount += resources.getBuildCount();
}

return String.format("Builders time: %dms avg %dms (%d builds)",
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/assets/vulkanmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"vulkanmod.options.buttons.apply": "Apply",
"vulkanmod.options.buttons.kofi": "Support me",

"vulkanmod.options.advCulling": "Advanced Chunk Culling",
"vulkanmod.options.advCulling.aggressive": "Aggressive",
"vulkanmod.options.advCulling.conservative": "Conservative",
"vulkanmod.options.advCulling.normal": "Normal",
"vulkanmod.options.advCulling.tooltip": "Use a culling algorithm that might improve performance by reducing the number of non visible chunk sections rendered.",
"vulkanmod.options.chunkCulling": "Advanced Chunk Culling",
"vulkanmod.options.chunkCulling.aggressive": "Aggressive",
"vulkanmod.options.chunkCulling.conservative": "Conservative",
"vulkanmod.options.chunkCulling.normal": "Normal",
"vulkanmod.options.chunkCulling.tooltip": "Use a culling algorithm that might improve performance by reducing the number of non visible chunk sections rendered.",

"vulkanmod.options.ao.subBlock": "ON (Sub-block)",
"vulkanmod.options.ao.subBlock.tooltip": "ON (Sub-block): Enables smooth lighting for non full block (experimental).",
Expand Down

0 comments on commit 670c7b8

Please sign in to comment.