Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve map grid size handling, fix fullscreen map cutting off #35

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ <h1>JourneyMap ${version} for Minecraft ${mcversion}</h1>

<p>New in ${version}</p>
<ul>
<li>Fixed: Switched to an explicit lambda to fix remapper issues (ah-OOG-ah)</li>
<li>Fixed: Map no longer cuts off on larger screens</li>
</ul>
52 changes: 30 additions & 22 deletions src/main/java/journeymap/client/render/map/GridRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public class GridRenderer
StatTimer updateTilesTimer1 = StatTimer.get("GridRenderer.updateTiles(1)", 5, 500);
StatTimer updateTilesTimer2 = StatTimer.get("GridRenderer.updateTiles(2)", 5, 500);
private int glErrors = 0;

private int gridSize; // 5 = 2560px.
private double srcSize;
private int gridSizeHeight, gridSizeWidth; // Amount of 512x512 tiles that should be loaded in each direction.
private double srcSizeHeight, srcSizeWidth; // Total pixel height/width of the loaded grid tiles
private Rectangle2D.Double viewPort = null;
private Rectangle2D.Double screenBounds = null;
private int lastHeight = -1;
Expand All @@ -74,14 +73,13 @@ public class GridRenderer
private FloatBuffer winPosBuf;
private FloatBuffer objPosBuf;

public GridRenderer(int gridSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the API as is, use wrappers to clamp the inputs to a new scheme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input will get overwritten anyway when the gridSize gets recalculated next (I think the caller has no useful purpose for passing a gridSize here).
I could leave a constructor that accepts a gridSize but just discards it to call the normal constructor for API compatability (As added initially, removed in second commit)
If that doesn't satisfy, I don't know what you mean; please clarify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did mean to keep public API breakage to an absolute minimum. You never know, where it would be called, and you can't possibly fix every dependent code you don't control.

Copy link
Member

@mysticdrew mysticdrew Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works fine in gtnh pack it can be removed

Copy link
Contributor Author

@leumasme leumasme Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Confirmed compatability with a recent GTNH nightly.
Also confirmed compatability with VisualProspecting overlays.
Compatability with TCNodeTracker overlays couldn't be tested because TCNodeTracker appears to be fully broken in nightly.

I can still restore api compatability if it's preferred (already have that stashed anyway), although methods such as public setGridSize would have to be empty dummy methods.

public GridRenderer()
{
viewportBuf = BufferUtils.createIntBuffer(16);
modelMatrixBuf = BufferUtils.createFloatBuffer(16);
projMatrixBuf = BufferUtils.createFloatBuffer(16);
winPosBuf = BufferUtils.createFloatBuffer(16);
objPosBuf = BufferUtils.createFloatBuffer(16);
setGridSize(gridSize);
}

public static void addDebugMessage(String key, String message)
Expand Down Expand Up @@ -122,8 +120,8 @@ public void setViewPort(Rectangle2D.Double viewPort)

private void populateGrid(Tile centerTile)
{
final int endRow = (gridSize - 1) / 2;
final int endCol = (gridSize - 1) / 2;
final int endRow = (gridSizeHeight - 1) / 2;
final int endCol = (gridSizeWidth - 1) / 2;
final int startRow = -endRow;
final int startCol = -endCol;

Expand Down Expand Up @@ -155,15 +153,20 @@ public boolean hasUnloadedTile()
return hasUnloadedTile(false);
}

public int getGridSize()
private void setGridSizes(int gridSizeHeight, int gridSizeWidth)
{
return gridSize;
}
if (this.gridSizeHeight == gridSizeHeight && this.gridSizeWidth == gridSizeWidth) return;
if (gridSizeHeight % 2 == 0) gridSizeHeight++;
if (gridSizeWidth % 2 == 0) gridSizeWidth++;

public void setGridSize(int gridSize)
{
this.gridSize = gridSize; // Must be an odd number so as to have a center tile.
srcSize = gridSize * Tile.TILESIZE;
// Both must be odd so that a center tile exists
this.gridSizeHeight = gridSizeHeight;
this.gridSizeWidth = gridSizeWidth;

this.srcSizeHeight = gridSizeHeight * Tile.TILESIZE;
this.srcSizeWidth = gridSizeWidth * Tile.TILESIZE;

clear();
}

public boolean hasUnloadedTile(boolean preview)
Expand Down Expand Up @@ -235,6 +238,7 @@ public void updateTiles(MapType mapType, int zoom, boolean highQuality, int widt

// Update screen dimensions
updateBounds(width, height);
updateGridSize();

// Get center tile, check if present and current
Tile centerTile = grid.get(centerPos);
Expand All @@ -249,9 +253,9 @@ public void updateTiles(MapType mapType, int zoom, boolean highQuality, int widt
// Derive offsets for centering the map
Point2D blockPixelOffset = centerTile.blockPixelOffsetInTile(centerBlockX, centerBlockZ);
final double blockSizeOffset = Math.pow(2, zoom) / 2;
final int magic = (gridSize == 5 ? 2 : 1) * Tile.TILESIZE; // TODO: Understand why "2" as it relates to gridSize. If gridSize is 3, this has to be "1".

double displayOffsetX = xOffset + magic - ((srcSize - lastWidth) / 2);
int extraOffsetX = (gridSizeWidth / 2) * Tile.TILESIZE;
leumasme marked this conversation as resolved.
Show resolved Hide resolved
double displayOffsetX = xOffset + extraOffsetX - ((srcSizeWidth - lastWidth) / 2);
if (centerBlockX < 0)
{
displayOffsetX -= blockSizeOffset;
Expand All @@ -260,7 +264,9 @@ public void updateTiles(MapType mapType, int zoom, boolean highQuality, int widt
{
displayOffsetX += blockSizeOffset;
}
double displayOffsetY = yOffset + magic - ((srcSize - lastHeight) / 2);

int extraOffsetY = (gridSizeHeight / 2) * Tile.TILESIZE;
double displayOffsetY = yOffset + extraOffsetY - ((srcSizeHeight - lastHeight) / 2);
if (centerBlockZ < 0)
{
displayOffsetY -= blockSizeOffset;
Expand Down Expand Up @@ -583,6 +589,13 @@ private void updateBounds(int width, int height)
}
}

private void updateGridSize() {
int newGridSizeHeight = (int) Math.ceil(screenBounds.height / Tile.TILESIZE + 0.5);
int newGridSizeWidth = (int) Math.ceil(screenBounds.width / Tile.TILESIZE + 0.5);

setGridSizes(newGridSizeHeight, newGridSizeWidth);
}

private Tile findNeighbor(Tile tile, TilePos pos)
{
if (pos.deltaX == 0 && pos.deltaZ == 0)
Expand Down Expand Up @@ -674,11 +687,6 @@ public boolean setZoom(int zoom)
return center(mapType, centerBlockX, centerBlockZ, zoom);
}

public int getRenderSize()
{
return this.gridSize * Tile.TILESIZE;
}

public void clear()
{
grid.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
public class Fullscreen extends JmUI
{
final static MapState state = new MapState();
final static GridRenderer gridRenderer = new GridRenderer(5);
final static GridRenderer gridRenderer = new GridRenderer();
final WaypointDrawStepFactory waypointRenderer = new WaypointDrawStepFactory();
final RadarDrawStepFactory radarRenderer = new RadarDrawStepFactory();
final LayerDelegate layerDelegate = new LayerDelegate();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/journeymap/client/ui/minimap/MiniMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MiniMap
private static final float lightmapS = (float) (15728880 % 65536) / 1f;
private static final float lightmapT = (float) (15728880 / 65536) / 1f;
private static final long labelRefreshRate = 400;
private final static GridRenderer gridRenderer = new GridRenderer(3);
private final static GridRenderer gridRenderer = new GridRenderer();
private final IForgeHelper forgeHelper = ForgeHelper.INSTANCE;
private final Logger logger = Journeymap.getLogger();
private final Minecraft mc = ForgeHelper.INSTANCE.getClient();
Expand Down Expand Up @@ -98,8 +98,6 @@ private void initGridRenderer()

MapType mapType = state.getMapType(showCaves);

int gridSize = miniMapProperties.getSize() <= 768 ? 3 : 5;
gridRenderer.setGridSize(gridSize);
gridRenderer.setContext(state.getWorldDir(), mapType);
gridRenderer.center(mapType, mc.thePlayer.posX, mc.thePlayer.posZ, miniMapProperties.zoomLevel.get());

Expand Down