From deed51214078470739b415bb3e55d8ffebe6a8c3 Mon Sep 17 00:00:00 2001 From: Orchaldir Date: Sun, 2 Jun 2019 09:47:35 +0200 Subject: [PATCH] #79: Improved BiomeController. --- .../docs/design/map/polygons-vs-grid.adoc | 4 +++- .../src/jfws/app/demo/biome/BiomeController.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/FantasyWorldSimulation/docs/design/map/polygons-vs-grid.adoc b/FantasyWorldSimulation/docs/design/map/polygons-vs-grid.adoc index ad1fd80..6a8ea50 100644 --- a/FantasyWorldSimulation/docs/design/map/polygons-vs-grid.adoc +++ b/FantasyWorldSimulation/docs/design/map/polygons-vs-grid.adoc @@ -17,6 +17,8 @@ ** Changes to smaller areas can be tracked ** Changes to sea level affect smaller areas * Faster map generation -* Fixed Number of neighbors +* Fixed layout +** Fixed Number of neighbors +** Fast look up of cell at a position |=== \ No newline at end of file diff --git a/FantasyWorldSimulation/src/jfws/app/demo/biome/BiomeController.java b/FantasyWorldSimulation/src/jfws/app/demo/biome/BiomeController.java index a78bae8..d81ef51 100644 --- a/FantasyWorldSimulation/src/jfws/app/demo/biome/BiomeController.java +++ b/FantasyWorldSimulation/src/jfws/app/demo/biome/BiomeController.java @@ -87,6 +87,7 @@ enum SelectedFeature { private ImageBasedVoronoiDiagram voronoiDiagram = new ImageBasedVoronoiDiagram<>(Rectangle.fromSize(SIZE), 2); + private int pixelsPerCell = 1; private int cellMapWidth = 800; private int cellMapHeight = 600; private CellMap2d cellMap; @@ -140,6 +141,8 @@ private Mesh initVoronoiDiagram() { } private void createCellMap() { + cellMapWidth = (int) (SIZE.getX() / (double)pixelsPerCell); + cellMapHeight = (int) (SIZE.getY() / (double)pixelsPerCell); int numberOfCells = cellMapWidth * cellMapHeight; WorldCell[] cells = new WorldCell[numberOfCells]; @@ -148,7 +151,7 @@ private void createCellMap() { } cellMap = new ArrayCellMap2D<>(cellMapWidth, cellMapHeight, cells); - mapper = new ToCellMapper<>(cellMap, 1.0); + mapper = new ToCellMapper<>(cellMap, pixelsPerCell); } private void generateElevation(Mesh mesh) { @@ -227,7 +230,7 @@ public void render() { if(selectedMapType == SelectedMapType.GRID) { WritableImage image = imageRenderer.render(cellMap, colorSelector); - mapCanvas.getGraphicsContext2D().drawImage(image, 0, 0); + mapCanvas.getGraphicsContext2D().drawImage(image, 0, 0, SIZE.getX(), SIZE.getY()); } else { meshRenderer.renderFaces(voronoiDiagram.getMesh(), colorSelector);