Skip to content

Commit

Permalink
Code cleanup & formatting
Browse files Browse the repository at this point in the history
Mostly just dead code removal and some automated
passes for code style.
  • Loading branch information
jellysquid3 committed Jul 21, 2023
1 parent a2da746 commit 19cd2c1
Show file tree
Hide file tree
Showing 47 changed files with 62 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription;
import net.minecraft.client.render.VertexConsumer;
import org.lwjgl.system.MemoryStack;
import org.slf4j.Logger;

public interface VertexBufferWriter {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface VertexSerializerRegistry {
VertexSerializerRegistry INSTANCE = DependencyInjection.load(VertexSerializerRegistry.class,
"me.jellysquid.mods.sodium.client.render.vertex.serializers.VertexSerializerRegistryImpl");;
"me.jellysquid.mods.sodium.client.render.vertex.serializers.VertexSerializerRegistryImpl");

static VertexSerializerRegistry instance() {
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean isNormalized() {
}

public boolean isIntType() {
return intType;
return this.intType;
}

public int getStride() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.lwjgl.opengl.GL20C;

public abstract class GlBuffer extends GlObject {
public static final int NULL_BUFFER_ID = 0;

private GlBufferMapping activeMapping;

protected GlBuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public void makeInactive() {
this.isActive = false;
}

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

@Override
public GLCapabilities getCapabilities() {
return GL.getCapabilities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ static void exitManagedCode() {
void makeActive();
void makeInactive();

boolean isActive();

GLCapabilities getCapabilities();

DeviceFunctions getDeviceFunctions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public DeviceFunctions(RenderDevice device) {
}

public BufferStorageFunctions getBufferStorageFunctions() {
return bufferStorageFunctions;
return this.bufferStorageFunctions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ class ShaderWorkarounds {
* <p>Hat tip to fewizz for the find and the fix.
*/
static void safeShaderSource(int glId, CharSequence source) {
final MemoryStack stack = MemoryStack.stackGet();
final int stackPointer = stack.getPointer();

try {
try (MemoryStack stack = MemoryStack.stackPush()) {
final ByteBuffer sourceBuffer = MemoryUtil.memUTF8(source, true);
final PointerBuffer pointers = stack.mallocPointer(1);
pointers.put(sourceBuffer);

GL20C.nglShaderSource(glId, 1, pointers.address0(), 0);
org.lwjgl.system.APIUtil.apiArrayFree(pointers.address0(), 1);
} finally {
stack.setPointer(stackPointer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ public int getFormatId() {
public int getStride() {
return this.stride;
}

public static final GlIndexType[] VALUES = GlIndexType.values();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,6 @@ public static class NotificationSettings {
public boolean hideDonationButton = false;
}

public enum ArenaMemoryAllocator implements TextProvider {
ASYNC("sodium.options.chunk_memory_allocator.async"),
SWAP("sodium.options.chunk_memory_allocator.swap");

private final Text name;

ArenaMemoryAllocator(String name) {
this.name = Text.translatable(name);
}

@Override
public Text getLocalizedName() {
return this.name;
}
}

public enum GraphicsQuality implements TextProvider {
DEFAULT("options.gamma.default"),
FANCY("options.clouds.fancy"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.VideoOptionsScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Language;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.glfw.GLFW;

import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class SodiumOptionsGUI extends Screen {
Expand Down Expand Up @@ -256,7 +253,7 @@ private void renderOptionTooltip(DrawContext drawContext, ControlElement<?> elem
drawContext.fillGradient(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000, 0xE0000000);

for (int i = 0; i < tooltip.size(); i++) {
drawContext.drawTextWithShadow(textRenderer, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
drawContext.drawTextWithShadow(this.textRenderer, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public enum OptionFlag {
REQUIRES_RENDERER_RELOAD,
REQUIRES_RENDERER_UPDATE,
REQUIRES_ASSET_RELOAD,
REQUIRES_GAME_RESTART;
REQUIRES_GAME_RESTART
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Collection<OptionFlag> getFlags() {
return this.flags;
}

public static <S, T> OptionImpl.Builder<S, T> createBuilder(Class<T> type, OptionStorage<S> storage) {
public static <S, T> OptionImpl.Builder<S, T> createBuilder(@SuppressWarnings("unused") Class<T> type, OptionStorage<S> storage) {
return new Builder<>(storage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.apache.commons.lang3.Validate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -103,7 +102,7 @@ private void renderSlider(DrawContext drawContext) {
int sliderWidth = this.sliderBounds.getWidth();
int sliderHeight = this.sliderBounds.getHeight();

this.thumbPosition = this.getThumbPositionForValue(option.getValue());
this.thumbPosition = this.getThumbPositionForValue(this.option.getValue());

double thumbOffset = MathHelper.clamp((double) (this.getIntValue() - this.min) / this.range * sliderWidth, 0, sliderWidth);

Expand Down Expand Up @@ -167,10 +166,10 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (!isFocused()) return false;

if (keyCode == InputUtil.GLFW_KEY_LEFT) {
this.option.setValue(MathHelper.clamp(this.option.getValue() - interval, min, max));
this.option.setValue(MathHelper.clamp(this.option.getValue() - this.interval, this.min, this.max));
return true;
} else if (keyCode == InputUtil.GLFW_KEY_RIGHT) {
this.option.setValue(MathHelper.clamp(this.option.getValue() + interval, min, max));
this.option.setValue(MathHelper.clamp(this.option.getValue() + this.interval, this.min, this.max));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ protected AbstractWidget() {
}

protected void drawString(DrawContext drawContext, String str, int x, int y, int color) {
drawContext.drawTextWithShadow(font, str, x, y, color);
drawContext.drawTextWithShadow(this.font, str, x, y, color);
}

protected void drawString(DrawContext drawContext, Text text, int x, int y, int color) {
drawContext.drawTextWithShadow(font, text, x, y, color);
drawContext.drawTextWithShadow(this.font, text, x, y, color);
}

public boolean isHovered() {
Expand All @@ -46,10 +46,6 @@ protected void playClickSound() {
.play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK.value(), 1.0F));
}

protected int getStringWidth(String text) {
return this.font.getWidth(text);
}

protected int getStringWidth(StringVisitable text) {
return this.font.getWidth(text);
}
Expand All @@ -66,9 +62,9 @@ public Selectable.SelectionType getType() {

@Override
public void appendNarrations(NarrationMessageBuilder builder) {
if (focused) {
if (this.focused) {
builder.put(NarrationPart.USAGE, Text.translatable("narration.button.usage.focused"));
} else if (hovered) {
} else if (this.hovered) {
builder.put(NarrationPart.USAGE, Text.translatable("narration.button.usage.hovered"));
}
}
Expand All @@ -80,7 +76,7 @@ public GuiNavigationPath getNavigationPath(GuiNavigation navigation) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)

this.hovered = this.dim.containsCursor(mouseX, mouseY);

int backgroundColor = this.enabled ? (hovered ? 0xE0000000 : 0x90000000) : 0x60000000;
int backgroundColor = this.enabled ? (this.hovered ? 0xE0000000 : 0x90000000) : 0x60000000;
int textColor = this.enabled ? 0xFFFFFFFF : 0x90FFFFFF;

int strWidth = this.font.getWidth(this.label);
Expand Down Expand Up @@ -105,7 +105,7 @@ public Text getLabel() {

@Override
public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) {
if (!enabled || !visible)
if (!this.enabled || !this.visible)
return null;
return super.getNavigationPath(navigation);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.jellysquid.mods.sodium.client.model.quad.properties;

import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.util.math.Direction;

public class ModelQuadFlags {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@ public class ChunkGraphicsState {

private final VertexRange[] parts;

private final int largestPrimitiveBatchSize;

public ChunkGraphicsState(GlBufferSegment vertexSegment, ChunkMeshData data) {
Validate.notNull(vertexSegment);

this.vertexSegment = vertexSegment;

this.parts = new VertexRange[ModelQuadFacing.COUNT];

int largestPrimitiveBatchSize = 0;

for (Map.Entry<ModelQuadFacing, VertexRange> entry : data.getParts().entrySet()) {
this.parts[entry.getKey().ordinal()] = entry.getValue();
largestPrimitiveBatchSize = Math.max(largestPrimitiveBatchSize, vertexSegment.getLength() / 4);
}

this.largestPrimitiveBatchSize = largestPrimitiveBatchSize;
}

public void delete() {
Expand All @@ -43,8 +36,4 @@ public VertexRange getModelPart(ModelQuadFacing facing) {
public GlBufferSegment getVertexSegment() {
return this.vertexSegment;
}

public int getLargestPrimitiveBatchSize() {
return this.largestPrimitiveBatchSize;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.jellysquid.mods.sodium.client.render.chunk;

import it.unimi.dsi.fastutil.longs.*;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import net.minecraft.util.math.ChunkPos;

import java.util.stream.LongStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class RenderSectionManager {
private final ObjectList<RenderSection> tickableChunks = new ObjectArrayList<>();
private final ObjectList<BlockEntity> visibleBlockEntities = new ObjectArrayList<>();

private final RegionChunkRenderer chunkRenderer;
private final ChunkRenderer chunkRenderer;

private final SodiumWorldRenderer worldRenderer;
private final ClientWorld world;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.jellysquid.mods.sodium.client.render.chunk.compile;

import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import me.jellysquid.mods.sodium.client.gl.util.VertexRange;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses;
Expand All @@ -14,7 +13,6 @@
import me.jellysquid.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import me.jellysquid.mods.sodium.client.util.NativeBuffer;
import org.lwjgl.system.MemoryUtil;

import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.jellysquid.mods.sodium.client.gl.compile;
package me.jellysquid.mods.sodium.client.render.chunk.compile;

import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.jellysquid.mods.sodium.client.render.chunk.compile;

import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gl.compile.ChunkBuildContext;
import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderBuildTask;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import me.jellysquid.mods.sodium.client.util.task.CancellationSource;
Expand Down
Loading

0 comments on commit 19cd2c1

Please sign in to comment.