Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.19.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java
#	common/src/main/java/xaeroplus/mixin/client/MixinGuiWaypoints.java
  • Loading branch information
rfresh2 committed Sep 6, 2024
2 parents 89c124c + 3685e1e commit 2acc1bf
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 188 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/xaeroplus/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static ResourceKey<Level> getCurrentDimensionId() {
public static ByteArrayOutputStream zipFastByteBuffer = new ByteArrayOutputStream();
public static final Supplier<ExecutorService> cacheRefreshExecutorService = Suppliers.memoize(() -> Executors.newFixedThreadPool(
// limited benefits by refreshing on more threads as it will consume the entire CPU and start lagging the game
Math.max(1, Math.min(Runtime.getRuntime().availableProcessors() / 2, 4)),
Math.max(1, Math.min(Runtime.getRuntime().availableProcessors() / 2, 2)),
new ThreadFactoryBuilder()
.setNameFormat("XaeroPlus-Cache-Refresh-%d")
.setDaemon(true)
Expand Down
41 changes: 26 additions & 15 deletions common/src/main/java/xaeroplus/feature/render/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@
import xaeroplus.util.ChunkUtils;
import xaeroplus.util.ColorHelper;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.IntSupplier;

public class DrawManager {
private final Object2ObjectMap<String, DrawFeature> chunkHighlightDrawFeatures = new Object2ObjectOpenHashMap<>();
private final List<String> sortedKeySet = new ArrayList<>();

public DrawManager() {
XaeroPlus.EVENT_BUS.register(this);
}

public synchronized void registerChunkHighlightProvider(String id, ChunkHighlightSupplier chunkHighlightSupplier, IntSupplier colorSupplier) {
chunkHighlightDrawFeatures.put(id, new DrawFeature(new ChunkHighlightProvider(chunkHighlightSupplier, colorSupplier)));
sortedKeySet.add(id);
// arbitrary order, just needs to be consistent so colors blend consistently
sortedKeySet.sort(Comparator.naturalOrder());
}

public synchronized void unregisterChunkHighlightProvider(String id) {
sortedKeySet.remove(id);
chunkHighlightDrawFeatures.remove(id);
}

Expand Down Expand Up @@ -62,17 +70,18 @@ public synchronized void drawMinimapFeatures(
final VertexConsumer overlayBufferBuilder,
MinimapRendererHelper helper
) {
if (chunkHighlightDrawFeatures.isEmpty()) return;
for (DrawFeature feature : chunkHighlightDrawFeatures.values()) {
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
var feature = chunkHighlightDrawFeatures.get(k);
int color = feature.colorInt();
var a = ColorHelper.getA(color);
if (a == 0.0f) return;
var r = ColorHelper.getR(color);
var g = ColorHelper.getG(color);
var b = ColorHelper.getB(color);
var highlights = feature.getChunkHighlights();
for (int i = 0; i < highlights.size(); i++) {
long highlight = highlights.getLong(i);
for (int j = 0; j < highlights.size(); j++) {
long highlight = highlights.getLong(j);
var chunkPosX = ChunkUtils.longToChunkX(highlight);
var chunkPosZ = ChunkUtils.longToChunkZ(highlight);
var mapTileChunkX = ChunkUtils.chunkCoordToMapTileChunkCoord(chunkPosX);
Expand All @@ -97,31 +106,33 @@ public synchronized void drawMinimapFeatures(
}

public synchronized void drawWorldMapFeatures(
final int minMapRegionX,
final int maxMapRegionX,
final int minMapRegionZ,
final int maxMapRegionZ,
final double minBlockX,
final double maxBlockX,
final double minBlockZ,
final double maxBlockZ,
final int flooredCameraX,
final int flooredCameraZ,
final PoseStack matrixStack,
final VertexConsumer overlayBuffer
) {
for (DrawFeature feature : chunkHighlightDrawFeatures.values()) {
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
var feature = chunkHighlightDrawFeatures.get(k);
int color = feature.colorInt();
var a = ColorHelper.getA(color);
if (a == 0.0f) return;
var r = ColorHelper.getR(color);
var g = ColorHelper.getG(color);
var b = ColorHelper.getB(color);
var highlights = feature.getChunkHighlights();
for (int i = 0; i < highlights.size(); i++) {
long highlight = highlights.getLong(i);
for (int j = 0; j < highlights.size(); j++) {
long highlight = highlights.getLong(j);
var chunkPosX = ChunkUtils.longToChunkX(highlight);
var chunkPosZ = ChunkUtils.longToChunkZ(highlight);
var regionX = ChunkUtils.chunkCoordToMapRegionCoord(chunkPosX);
var regionZ = ChunkUtils.chunkCoordToMapRegionCoord(chunkPosZ);
if (regionX < minMapRegionX || regionX > maxMapRegionX) continue;
if (regionZ < minMapRegionZ || regionZ > maxMapRegionZ) continue;
var blockX = ChunkUtils.chunkCoordToCoord(chunkPosX);
var blockZ = ChunkUtils.chunkCoordToCoord(chunkPosZ);
if (blockX < minBlockX || blockX > maxBlockX) continue;
if (blockZ < minBlockZ || blockZ > maxBlockZ) continue;
final float left = (float) (ChunkUtils.chunkCoordToCoord(chunkPosX) - flooredCameraX);
final float top = (float) (ChunkUtils.chunkCoordToCoord(chunkPosZ) - flooredCameraZ);
final float right = left + 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private synchronized void initializeWorld() {
this.executorService = MoreExecutors.listeningDecorator(
Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder()
.setNameFormat("XaeroPlus-" + databaseName + "-DiskCache-" + worldId)
.setNameFormat(databaseName + "-DiskCache")
.setUncaughtExceptionHandler((t, e) -> {
XaeroPlus.LOGGER.error("Uncaught exception handler in {}", t.getName(), e);
})
Expand Down
89 changes: 22 additions & 67 deletions common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import xaero.common.XaeroMinimapSession;
import xaero.common.graphics.shader.MinimapShaders;
import xaero.hud.HudSession;
import xaero.map.MapProcessor;
import xaero.map.WorldMap;
import xaero.map.animation.SlowingAnimation;
Expand Down Expand Up @@ -60,6 +60,7 @@
import static java.util.Arrays.asList;
import static java.util.Objects.isNull;
import static net.minecraft.world.level.Level.*;
import static org.lwjgl.glfw.GLFW.*;
import static xaeroplus.Globals.getCurrentDimensionId;
import static xaeroplus.util.ChunkUtils.getPlayerX;
import static xaeroplus.util.ChunkUtils.getPlayerZ;
Expand Down Expand Up @@ -207,7 +208,7 @@ public void fixDimensionSwitchCameraCoordsZ(GuiMap owner, double value, @Local(n

@Inject(method = "render", at = @At(value = "FIELD", target = "Lxaero/map/gui/GuiMap;lastStartTime:J", opcode = Opcodes.PUTFIELD, ordinal = 0, shift = At.Shift.AFTER), remap = true)
public void injectFollowMode(final PoseStack guiGraphics, final int scaledMouseX, final int scaledMouseY, final float partialTicks, final CallbackInfo ci) {
if (this.follow && isNull(this.cameraDestination) && isNull(this.cameraDestinationAnimX) && isNull(this.cameraDestinationAnimZ)) {
if (follow && isNull(this.cameraDestination) && isNull(this.cameraDestinationAnimX) && isNull(this.cameraDestinationAnimZ)) {
this.cameraDestination = new int[]{(int) getPlayerX(), (int) getPlayerZ()};
}
}
Expand All @@ -221,15 +222,6 @@ public boolean hideDebugRenderingOnF1(boolean original) {
return original && !Minecraft.getInstance().options.hideGui;
}

// todo: re-benchmark region load perf impact
// @ModifyArg(method = "render", at = @At(
// value = "INVOKE",
// target = "Lxaero/map/misc/Misc;addToListOfSmallest(ILjava/util/List;Ljava/lang/Comparable;)V"),
// index = 0, remap = true)
// public int increaseRegionBuffer(final int i, final List list, final Comparable element) {
// return 100;
// }

@Inject(method = "render",
slice = @Slice(
from = @At(
Expand All @@ -245,51 +237,26 @@ public boolean hideDebugRenderingOnF1(boolean original) {
),
remap = true)
public void drawWorldMapFeatures(final PoseStack guiGraphics, final int scaledMouseX, final int scaledMouseY, final float partialTicks, final CallbackInfo ci,
@Local(name = "minRegX") int minRegX,
@Local(name = "maxRegX") int maxRegX,
@Local(name = "minRegZ") int minRegZ,
@Local(name = "maxRegZ") int maxRegZ,
@Local(name = "textureLevel") int textureLevel,
@Local(name = "leftBorder") double leftBorder,
@Local(name = "rightBorder") double rightBorder,
@Local(name = "topBorder") double topBorder,
@Local(name = "bottomBorder") double bottomBorder,
@Local(name = "flooredCameraX") int flooredCameraX,
@Local(name = "flooredCameraZ") int flooredCameraZ,
@Local(name = "matrixStack") PoseStack matrixStack,
@Local(name = "overlayBuffer") VertexConsumer overlayBuffer) {
if (Minecraft.getInstance().options.hideGui) return;
final int leveledSideInRegions = 1 << textureLevel;
final int minX = minRegX * leveledSideInRegions;
final int maxX = (maxRegX + 1) * leveledSideInRegions;
final int minZ = minRegZ * leveledSideInRegions;
final int maxZ = (maxRegZ + 1) * leveledSideInRegions;
Globals.drawManager.drawWorldMapFeatures(
minX - 1,
maxX + 1,
minZ - 1,
maxZ + 1,
leftBorder,
rightBorder,
topBorder,
bottomBorder,
flooredCameraX,
flooredCameraZ,
matrixStack,
overlayBuffer);
}

// @ModifyConstant(method = "render", constant = @Constant(intValue = 16, ordinal = 0))
// public int increaseRequestedRegionsLimit(final int original) {
// return 64;
// }
//
// todo: re-benchmark region load perf impact
// @Inject(method = "render", at = @At(
// value = "FIELD",
// target = "Lxaero/map/settings/ModSettings;pauseRequests:Z",
// opcode = Opcodes.GETFIELD,
// shift = At.Shift.BY,
// by = 4,
// ordinal = 0
// ))
// public void increaseRequestedRegions(final DrawContext guiGraphics, final int scaledMouseX, final int scaledMouseY, final float partialTicks, final CallbackInfo ci,
// @Local(name = "toRequest") LocalIntRef toRequest) {
// toRequest.set(8);
// }

@WrapWithCondition(method = "render", at = @At(
value = "INVOKE",
target = "Lxaero/map/graphics/MapRenderHelper;renderDynamicHighlight(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;IIIIIIFFFFFFFF)V"
Expand Down Expand Up @@ -384,14 +351,9 @@ public void showRenderDistanceWorldMap(final PoseStack guiGraphics, final int sc
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(xaero.common.graphics.CustomRenderTypes.MAP_LINES);
PoseStack.Pose matrices = matrixStack.last();
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize(mc.getWindow().getWidth(), mc.getWindow().getHeight());
float settingWidth = (float) XaeroMinimapSession.getCurrentSession()
.getModMain()
.getSettings().chunkGridLineWidth;
float settingWidth = (float) HudSession.getCurrentSession().getHudMod().getSettings().chunkGridLineWidth;
float lineScale = (float) Math.max(1.0, Math.min(settingWidth * scale, settingWidth));
RenderSystem.lineWidth(lineScale);

// todo: horizontal lines seem to have a smaller width here for some reason
// also there's some jittering to the position noticeable when you zoom in
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
Expand Down Expand Up @@ -493,7 +455,7 @@ public void onTick(final CallbackInfo ci) {
@Inject(method = "onInputPress", at = @At("HEAD"))
public void panMouseButtonClick(final InputConstants.Type type, final int code, final CallbackInfoReturnable<Boolean> cir) {
if (type != InputConstants.Type.MOUSE) return;
if (code != 2) return;
if (code != GLFW_MOUSE_BUTTON_MIDDLE) return;
pan = true;
var mc = Minecraft.getInstance();
panMouseStartX = Misc.getMouseX(mc, true);
Expand All @@ -503,7 +465,7 @@ public void panMouseButtonClick(final InputConstants.Type type, final int code,
@Inject(method = "onInputRelease", at = @At("HEAD"))
public void panMouseButtonRelease(final InputConstants.Type type, final int code, final CallbackInfoReturnable<Boolean> cir) {
if (type != InputConstants.Type.MOUSE) return;
if (code != 2) return;
if (code != GLFW_MOUSE_BUTTON_MIDDLE) return;
pan = false;
}

Expand All @@ -513,19 +475,10 @@ public void panMapOnRender(final PoseStack matrixStack, final int scaledMouseX,
Minecraft mc = Minecraft.getInstance();
double mouseX = Misc.getMouseX(mc, true);
double mouseY = Misc.getMouseY(mc, true);
double fps = mc.getFps();

double mouseDeltaX = mouseX - panMouseStartX;
double mouseDeltaY = mouseY - panMouseStartY;
double distance = Math.sqrt(Math.pow(mouseDeltaX, 2) + Math.pow(mouseDeltaY, 2));
double accelFactor = (distance / 30.0);
double xVec = mouseDeltaX * accelFactor; // scale vec roughly exponentially
double yVec = mouseDeltaY * accelFactor;

// normalize across fps and map zoom levels
double panDeltaX = (1.0 / (fps / xVec)) / destScale;
double panDeltaZ = (1.0 / (fps / yVec)) / destScale;

double panDeltaX = (partialTicks * mouseDeltaX) / destScale;
double panDeltaZ = (partialTicks * mouseDeltaY) / destScale;
cameraX += panDeltaX;
cameraZ += panDeltaZ;
}
Expand Down Expand Up @@ -556,13 +509,13 @@ public void renderTileSelectionSize(

@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true, remap = true)
public void onInputPress(final int code, final int scanCode, final int modifiers, final CallbackInfoReturnable<Boolean> cir) {
if (code == 290) {
if (code == GLFW_KEY_F1) {
Minecraft.getInstance().options.hideGui = !Minecraft.getInstance().options.hideGui;
cir.setReturnValue(true);
return;
}
if ((xTextEntryField.isVisible() && zTextEntryField.isVisible()) && (xTextEntryField.isFocused() || zTextEntryField.isFocused())) {
if (code == 257) {
if (code == GLFW_KEY_ENTER) {
onGotoCoordinatesButton(null);
cir.setReturnValue(true);
return;
Expand Down Expand Up @@ -627,8 +580,9 @@ public void addColoredLineToExistingBuffer(
vertexBuffer.vertex(matrices.pose(), x2, y2, 0.0F).color(r, g, b, a).normal(matrices.normal(), x2 - x1, y2 - y1, 0.0F).endVertex();
}

@Unique
public void onFollowButton(final Button b) {
this.follow = !this.follow;
follow = !follow;
this.init(Minecraft.getInstance(), width, height);
}

Expand All @@ -639,7 +593,7 @@ public void onGotoCoordinatesButton(final Button b) {
int z = Integer.parseInt(zTextEntryField.getValue());
cameraX = x;
cameraZ = z;
this.follow = false;
follow = false;
this.init(Minecraft.getInstance(), width, height);
} catch (final NumberFormatException e) {
xTextEntryField.setValue("");
Expand All @@ -656,6 +610,7 @@ public void onGotoCoordinatesButton(final Button b) {
}
}

@Unique
private void onSwitchDimensionButton(final ResourceKey<Level> newDimId) {
Globals.switchToDimension(newDimId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xaeroplus.mixin.client;

import com.google.common.base.Objects;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.gui.components.Button;
Expand Down Expand Up @@ -125,17 +124,15 @@ public void drawScreenInject(final PoseStack guiGraphics, final int mouseX, fina

@Redirect(method = "updateButtons", at = @At(value = "INVOKE", target = "Lxaero/common/gui/GuiWaypoints;isOneSelected()Z"))
public boolean shareButtonRedirect(final GuiWaypoints instance) {
if (XaeroPlusSettingRegistry.disableWaypointSharing.getValue()) {
return false;
}
if (XaeroPlusSettingRegistry.disableWaypointSharing.getValue()) return false;
return isOneSelected();
}

@Unique
private void updateSearch() {
if (this.searchField.isFocused()) {
String newValue = this.searchField.getValue();
if (!Objects.equal(this.waypointsSearchFilter, newValue)) {
if (!this.waypointsSearchFilter.equals(newValue)) {
this.waypointsSearchFilter = this.searchField.getValue();
selectedListSet.clear();
updateSortedList();
Expand Down
Loading

0 comments on commit 2acc1bf

Please sign in to comment.