Skip to content

Commit f4631f5

Browse files
authored
Improve map grid size handling, fix fullscreen map cutting off (#35)
* make grid size dynamic * refactor: clean grid size leftovers (breaking change) * feat: support different grid width and height * update changelog * remove todo info comment
1 parent 6c82a24 commit f4631f5

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

doc/changelog.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ <h1>JourneyMap ${version} for Minecraft ${mcversion}</h1>
2323

2424
<p>New in ${version}</p>
2525
<ul>
26-
<li>Fixed: Switched to an explicit lambda to fix remapper issues (ah-OOG-ah)</li>
26+
<li>Fixed: Map no longer cuts off on larger screens</li>
2727
</ul>

src/main/java/journeymap/client/render/map/GridRenderer.java

+30-22
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ public class GridRenderer
5454
StatTimer updateTilesTimer1 = StatTimer.get("GridRenderer.updateTiles(1)", 5, 500);
5555
StatTimer updateTilesTimer2 = StatTimer.get("GridRenderer.updateTiles(2)", 5, 500);
5656
private int glErrors = 0;
57-
58-
private int gridSize; // 5 = 2560px.
59-
private double srcSize;
57+
private int gridSizeHeight, gridSizeWidth; // Amount of 512x512 tiles that should be loaded in each direction.
58+
private double srcSizeHeight, srcSizeWidth; // Total pixel height/width of the loaded grid tiles
6059
private Rectangle2D.Double viewPort = null;
6160
private Rectangle2D.Double screenBounds = null;
6261
private int lastHeight = -1;
@@ -74,14 +73,13 @@ public class GridRenderer
7473
private FloatBuffer winPosBuf;
7574
private FloatBuffer objPosBuf;
7675

77-
public GridRenderer(int gridSize)
76+
public GridRenderer()
7877
{
7978
viewportBuf = BufferUtils.createIntBuffer(16);
8079
modelMatrixBuf = BufferUtils.createFloatBuffer(16);
8180
projMatrixBuf = BufferUtils.createFloatBuffer(16);
8281
winPosBuf = BufferUtils.createFloatBuffer(16);
8382
objPosBuf = BufferUtils.createFloatBuffer(16);
84-
setGridSize(gridSize);
8583
}
8684

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

123121
private void populateGrid(Tile centerTile)
124122
{
125-
final int endRow = (gridSize - 1) / 2;
126-
final int endCol = (gridSize - 1) / 2;
123+
final int endRow = (gridSizeHeight - 1) / 2;
124+
final int endCol = (gridSizeWidth - 1) / 2;
127125
final int startRow = -endRow;
128126
final int startCol = -endCol;
129127

@@ -155,15 +153,20 @@ public boolean hasUnloadedTile()
155153
return hasUnloadedTile(false);
156154
}
157155

158-
public int getGridSize()
156+
private void setGridSizes(int gridSizeHeight, int gridSizeWidth)
159157
{
160-
return gridSize;
161-
}
158+
if (this.gridSizeHeight == gridSizeHeight && this.gridSizeWidth == gridSizeWidth) return;
159+
if (gridSizeHeight % 2 == 0) gridSizeHeight++;
160+
if (gridSizeWidth % 2 == 0) gridSizeWidth++;
162161

163-
public void setGridSize(int gridSize)
164-
{
165-
this.gridSize = gridSize; // Must be an odd number so as to have a center tile.
166-
srcSize = gridSize * Tile.TILESIZE;
162+
// Both must be odd so that a center tile exists
163+
this.gridSizeHeight = gridSizeHeight;
164+
this.gridSizeWidth = gridSizeWidth;
165+
166+
this.srcSizeHeight = gridSizeHeight * Tile.TILESIZE;
167+
this.srcSizeWidth = gridSizeWidth * Tile.TILESIZE;
168+
169+
clear();
167170
}
168171

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

236239
// Update screen dimensions
237240
updateBounds(width, height);
241+
updateGridSize();
238242

239243
// Get center tile, check if present and current
240244
Tile centerTile = grid.get(centerPos);
@@ -249,9 +253,9 @@ public void updateTiles(MapType mapType, int zoom, boolean highQuality, int widt
249253
// Derive offsets for centering the map
250254
Point2D blockPixelOffset = centerTile.blockPixelOffsetInTile(centerBlockX, centerBlockZ);
251255
final double blockSizeOffset = Math.pow(2, zoom) / 2;
252-
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".
253256

254-
double displayOffsetX = xOffset + magic - ((srcSize - lastWidth) / 2);
257+
int extraOffsetX = (gridSizeWidth / 2) * Tile.TILESIZE;
258+
double displayOffsetX = xOffset + extraOffsetX - ((srcSizeWidth - lastWidth) / 2);
255259
if (centerBlockX < 0)
256260
{
257261
displayOffsetX -= blockSizeOffset;
@@ -260,7 +264,9 @@ public void updateTiles(MapType mapType, int zoom, boolean highQuality, int widt
260264
{
261265
displayOffsetX += blockSizeOffset;
262266
}
263-
double displayOffsetY = yOffset + magic - ((srcSize - lastHeight) / 2);
267+
268+
int extraOffsetY = (gridSizeHeight / 2) * Tile.TILESIZE;
269+
double displayOffsetY = yOffset + extraOffsetY - ((srcSizeHeight - lastHeight) / 2);
264270
if (centerBlockZ < 0)
265271
{
266272
displayOffsetY -= blockSizeOffset;
@@ -583,6 +589,13 @@ private void updateBounds(int width, int height)
583589
}
584590
}
585591

592+
private void updateGridSize() {
593+
int newGridSizeHeight = (int) Math.ceil(screenBounds.height / Tile.TILESIZE + 0.5);
594+
int newGridSizeWidth = (int) Math.ceil(screenBounds.width / Tile.TILESIZE + 0.5);
595+
596+
setGridSizes(newGridSizeHeight, newGridSizeWidth);
597+
}
598+
586599
private Tile findNeighbor(Tile tile, TilePos pos)
587600
{
588601
if (pos.deltaX == 0 && pos.deltaZ == 0)
@@ -674,11 +687,6 @@ public boolean setZoom(int zoom)
674687
return center(mapType, centerBlockX, centerBlockZ, zoom);
675688
}
676689

677-
public int getRenderSize()
678-
{
679-
return this.gridSize * Tile.TILESIZE;
680-
}
681-
682690
public void clear()
683691
{
684692
grid.clear();

src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
public class Fullscreen extends JmUI
6868
{
6969
final static MapState state = new MapState();
70-
final static GridRenderer gridRenderer = new GridRenderer(5);
70+
final static GridRenderer gridRenderer = new GridRenderer();
7171
final WaypointDrawStepFactory waypointRenderer = new WaypointDrawStepFactory();
7272
final RadarDrawStepFactory radarRenderer = new RadarDrawStepFactory();
7373
final LayerDelegate layerDelegate = new LayerDelegate();

src/main/java/journeymap/client/ui/minimap/MiniMap.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class MiniMap
4848
private static final float lightmapS = (float) (15728880 % 65536) / 1f;
4949
private static final float lightmapT = (float) (15728880 / 65536) / 1f;
5050
private static final long labelRefreshRate = 400;
51-
private final static GridRenderer gridRenderer = new GridRenderer(3);
51+
private final static GridRenderer gridRenderer = new GridRenderer();
5252
private final IForgeHelper forgeHelper = ForgeHelper.INSTANCE;
5353
private final Logger logger = Journeymap.getLogger();
5454
private final Minecraft mc = ForgeHelper.INSTANCE.getClient();
@@ -98,8 +98,6 @@ private void initGridRenderer()
9898

9999
MapType mapType = state.getMapType(showCaves);
100100

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

0 commit comments

Comments
 (0)