diff --git a/doc/changelog.html b/doc/changelog.html index 51d8109..74e9225 100644 --- a/doc/changelog.html +++ b/doc/changelog.html @@ -23,5 +23,5 @@

JourneyMap ${version} for Minecraft ${mcversion}

New in ${version}

diff --git a/src/main/java/journeymap/client/render/map/GridRenderer.java b/src/main/java/journeymap/client/render/map/GridRenderer.java index 4b76ee3..a6af646 100644 --- a/src/main/java/journeymap/client/render/map/GridRenderer.java +++ b/src/main/java/journeymap/client/render/map/GridRenderer.java @@ -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; @@ -74,14 +73,13 @@ public class GridRenderer private FloatBuffer winPosBuf; private FloatBuffer objPosBuf; - public GridRenderer(int gridSize) + 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) @@ -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; @@ -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) @@ -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); @@ -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; + double displayOffsetX = xOffset + extraOffsetX - ((srcSizeWidth - lastWidth) / 2); if (centerBlockX < 0) { displayOffsetX -= blockSizeOffset; @@ -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; @@ -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) @@ -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(); diff --git a/src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java b/src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java index d538e43..00f1580 100644 --- a/src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java +++ b/src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java @@ -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(); diff --git a/src/main/java/journeymap/client/ui/minimap/MiniMap.java b/src/main/java/journeymap/client/ui/minimap/MiniMap.java index cae6cd5..0ad5a90 100644 --- a/src/main/java/journeymap/client/ui/minimap/MiniMap.java +++ b/src/main/java/journeymap/client/ui/minimap/MiniMap.java @@ -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(); @@ -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());