diff --git a/src/net/buddat/wgenerator/HeightMap.java b/src/net/buddat/wgenerator/HeightMap.java index a6a066c..fd782cf 100644 --- a/src/net/buddat/wgenerator/HeightMap.java +++ b/src/net/buddat/wgenerator/HeightMap.java @@ -186,19 +186,22 @@ private void normalizeHeights() { double maxHeight = 0.0f; for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { - if (getHeight(i, j) > maxHeight) + if (getHeight(i, j) > maxHeight) { maxHeight = getHeight(i, j); + } } } double normalize = 1.0f / maxHeight; - for (int i = 0; i < mapSize; i++) - for (int j = 0; j < mapSize; j++) + for (int i = 0; i < mapSize; i++) { + for (int j = 0; j < mapSize; j++) { setHeight(i, j, getHeight(i, j) * normalize, false); + } + } double normalizeLow = 1.0 / 0.5; double normalizeHigh = 2.0f / 0.5; - for (int i = 0; i < mapSize; i++) + for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { if (getHeight(i, j) < 0.5) { setHeight(i, j, (getHeight(i, j) * normalizeLow) / 3.0, false); @@ -207,6 +210,7 @@ private void normalizeHeights() { setHeight(i, j, newHeight / 3.0, false); } } + } log("HeightMap Normalization (" + mapSize + ") completed in " + (System.currentTimeMillis() - startTime) + "ms."); } @@ -314,6 +318,27 @@ static int clamp(int val, int min, int max) { return Math.max(min, Math.min(max, val)); } + void createPond(int ox, int oy, double water, int baseWidth, int slope) { + if (water <= 0) + water = 0; + if (slope <= 0) + slope = 1; + int size = baseWidth-1; + while (getHeight(ox, oy) > water) { + double dig = slope*singleDirt; + for (int x = ox-size; x <= ox+size; x++) { + for (int y = oy-size; y <= oy+size; y++) { + if (x < 0 || x >= mapSize || y < 0 || y >= mapSize || getHeight(x,y) < water ) + continue; + if (Math.sqrt(Math.pow(x-ox, 2)+Math.pow(y-oy, 2)) <= size) + setHeight(x,y,getHeight(x,y)-dig,false); + } + } + size++; + } + + } + private static void log (String s) { System.out.println(s); } diff --git a/src/net/buddat/wgenerator/MainWindow.java b/src/net/buddat/wgenerator/MainWindow.java index be0efd7..6b439c1 100644 --- a/src/net/buddat/wgenerator/MainWindow.java +++ b/src/net/buddat/wgenerator/MainWindow.java @@ -50,7 +50,7 @@ public class MainWindow extends JFrame { private static final long serialVersionUID = -407206109473532425L; - private static final String version = "2.4.2"; + private static final String version = "2.5"; private WurmAPI api; private HeightMap heightMap; private TileMap tileMap; @@ -60,6 +60,7 @@ public class MainWindow extends JFrame { private String mapName; private String actionsFileDirectory; private JPanel contentPane; + private Constants.VIEW_TYPE defaultView = Constants.VIEW_TYPE.HEIGHT; private JTextField textField_mapSeed; private JTextField textField_mapResolution; @@ -123,7 +124,7 @@ public class MainWindow extends JFrame { private JButton btnLoadActions; private JButton btnViewHeight; private JButton btnViewCave; - private JButton btnTopo; + private JButton btnViewTopo; private JButton btnViewMap; private JTextField textField_cliffRatio; private JButton btnSaveHeightmap; @@ -140,6 +141,13 @@ public class MainWindow extends JFrame { private CardLayout cl_mainPanel; private JPanel mainPanel; private JCheckBox checkbox_paintMode; + private JButton btnGenerateRivers; + private JCheckBox checkbox_paintRivers; + private JTextField textField_riverDepth; + private JTextField textField_riverWidth; + private JTextField textField_riverSlope; + private JButton btnResetRivers; + private JCheckBox checkbox_autoDropDirt; @@ -310,8 +318,8 @@ public void actionPerformed(ActionEvent arg0) { btnViewMap = new JButton("View Map"); viewPanel.add(btnViewMap); - btnTopo = new JButton("View Topo"); - viewPanel.add(btnTopo); + btnViewTopo = new JButton("View Topo"); + viewPanel.add(btnViewTopo); btnViewCave = new JButton("View Cave"); viewPanel.add(btnViewCave); @@ -367,12 +375,12 @@ public void actionPerformed(ActionEvent arg0) { JLabel lblMaxHeight = new JLabel("Max Height"); labelPanel.add(lblMaxHeight); - - JLabel label = new JLabel(""); - labelPanel.add(label); - - JLabel lblNewLabel = new JLabel(""); - labelPanel.add(lblNewLabel); + + JLabel label = new JLabel(""); + labelPanel.add(label); + + JLabel lblNewLabel = new JLabel(""); + labelPanel.add(lblNewLabel); JPanel inputPanel = new JPanel(); panel.add(inputPanel); @@ -407,17 +415,17 @@ public void actionPerformed(ActionEvent arg0) { textField_mapMaxHeight = new JTextField("" + (int) Constants.MAP_HEIGHT); inputPanel.add(textField_mapMaxHeight); textField_mapMaxHeight.setColumns(10); - - checkbox_moreLand = new JCheckBox("More Land", Constants.MORE_LAND); - inputPanel.add(checkbox_moreLand); - - checkbox_mapRandomSeed = new JCheckBox("Random Seed", true); - inputPanel.add(checkbox_mapRandomSeed); - checkbox_mapRandomSeed.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - textField_mapSeed.setEnabled(!checkbox_mapRandomSeed.isSelected()); - } - }); + + checkbox_moreLand = new JCheckBox("More Land", Constants.MORE_LAND); + inputPanel.add(checkbox_moreLand); + + checkbox_mapRandomSeed = new JCheckBox("Random Seed", true); + inputPanel.add(checkbox_mapRandomSeed); + checkbox_mapRandomSeed.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + textField_mapSeed.setEnabled(!checkbox_mapRandomSeed.isSelected()); + } + }); JPanel panel_7 = new JPanel(); @@ -567,6 +575,35 @@ public void actionPerformed(ActionEvent arg0) { JLabel label_4 = new JLabel(""); panel_11.add(label_4); + + JSeparator separator = new JSeparator(); + panel_11.add(separator); + + checkbox_paintRivers = new JCheckBox("Paint Rivers"); + checkbox_paintRivers.setToolTipText("Click and drag on map to draw rivers"); + checkbox_paintRivers.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + mapPanel.setRiverPaintingMode(checkbox_paintRivers.isSelected()); + } + }); + panel_11.add(checkbox_paintRivers); + + checkbox_autoDropDirt = new JCheckBox("Auto Drop Dirt"); + checkbox_autoDropDirt.setToolTipText("Drop dirt after generating rivers"); + checkbox_autoDropDirt.setSelected(true); + panel_11.add(checkbox_autoDropDirt); + + JLabel lblRiverDepth = new JLabel("River depth"); + lblRiverDepth.setToolTipText("Deepest part of the river"); + panel_11.add(lblRiverDepth); + + JLabel lblRiverWidth = new JLabel("River width"); + lblRiverWidth.setToolTipText("Base size at the deepest part"); + panel_11.add(lblRiverWidth); + + JLabel lblRiverSlope = new JLabel("River slope"); + lblRiverSlope.setToolTipText("Lower = gradual, Higher = steep edges"); + panel_11.add(lblRiverSlope); JPanel panel_12 = new JPanel(); panel_10.add(panel_12); @@ -619,6 +656,34 @@ public void actionPerformed(ActionEvent e) { }); panel_12.add(checkbox_biomeRandomSeed); checkbox_biomeRandomSeed.setSelected(true); + + JSeparator separator_1 = new JSeparator(); + panel_12.add(separator_1); + + btnGenerateRivers = new JButton("Generate Rivers"); + btnGenerateRivers.setToolTipText("Alters the heightmap"); + panel_12.add(btnGenerateRivers); + + btnResetRivers = new JButton("Reset Rivers"); + btnResetRivers.setToolTipText("Clear the currently drawn rivers"); + btnResetRivers.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + mapPanel.clearRiverSeeds(); + } + }); + panel_12.add(btnResetRivers); + + textField_riverDepth = new JTextField("" + Constants.RIVER_DEPTH); + panel_12.add(textField_riverDepth); + textField_riverDepth.setColumns(10); + + textField_riverWidth = new JTextField("" + Constants.RIVER_WIDTH); + panel_12.add(textField_riverWidth); + textField_riverWidth.setColumns(10); + + textField_riverSlope = new JTextField("" + Constants.RIVER_SLOPE); + panel_12.add(textField_riverSlope); + textField_riverSlope.setColumns(10); JPanel panel_13 = new JPanel(); @@ -1184,7 +1249,7 @@ public void run() { }.start(); } }); - btnTopo.addActionListener(new ActionListener() { + btnViewTopo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cl_mainPanel.show(mainPanel,"MAP"); if (!actionReady()) @@ -1271,6 +1336,18 @@ public void run() { }.start(); } }); + btnGenerateRivers.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (!actionReady()) + return; + new Thread() { + @Override + public void run() { + actionGenerateRivers(); + } + }.start(); + } + }); btnAddBiome.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!actionReady()) @@ -1448,7 +1525,7 @@ public void actionErodeHeightmap () { heightMap.erode(Integer.parseInt(textField_erodeIterations.getText()), Integer.parseInt(textField_erodeMinSlope.getText()), Integer.parseInt(textField_erodeMaxSlope.getText()), Integer.parseInt(textField_erodeSediment.getText()), progressBar); - updateMapView(false, 0); + updateMapView(); genHistory.add("ERODE:" + textField_erodeIterations.getText() + "," + textField_erodeMinSlope.getText() + "," + textField_erodeSediment.getText()); } catch (NumberFormatException nfe) { @@ -1478,7 +1555,10 @@ public void actionDropDirt () { Integer.parseInt(textField_maxDiagSlope.getText()), Integer.parseInt(textField_maxDirtHeight.getText()), Double.parseDouble(textField_cliffRatio.getText()), checkBox_landSlide.isSelected(), progressBar); - updateMapView(true, 0); + if (defaultView == Constants.VIEW_TYPE.HEIGHT) { + defaultView = Constants.VIEW_TYPE.ISO; + } + updateMapView(); genHistory.add("DROPDIRT:" + textField_biomeSeed.getText() + "," + textField_waterHeight.getText() + "," + textField_dirtPerTile.getText() + "," + textField_maxDirtSlope.getText() + "," + textField_maxDiagSlope.getText() + "," + textField_maxDirtHeight.getText()); @@ -1505,7 +1585,7 @@ public void actionUpdateWater () { lblWater.setText("Water: "+textField_waterHeight.getText()); tileMap.setWaterHeight(Integer.parseInt(textField_waterHeight.getText())); - updateMapView(true, 0); + updateMapView(); genHistory.add("UPDATEWATER:" + textField_waterHeight.getText()); } catch (NumberFormatException nfe) { @@ -1515,6 +1595,36 @@ public void actionUpdateWater () { } } + + public void actionGenerateRivers () { + if (tileMap == null) { + JOptionPane.showMessageDialog(null, "TileMap does not exist - Add Dirt first", "Error Adding Biome", JOptionPane.ERROR_MESSAGE); + return; + } + + startLoading("Generating Rivers"); + try { + double water = (Integer.parseInt(textField_waterHeight.getText())-Integer.parseInt(textField_dirtPerTile.getText())- + Integer.parseInt(textField_riverDepth.getText()))/(double)Integer.parseInt(textField_mapMaxHeight.getText()); + for (Point p:mapPanel.getRiverSeeds()) { + heightMap.createPond(p.x,p.y,water,Integer.parseInt(textField_riverWidth.getText()),Integer.parseInt(textField_riverSlope.getText())); + } + + mapPanel.setRiverPaintingMode(false); + checkbox_paintRivers.setSelected(false); + mapPanel.clearRiverSeeds(); + + if (checkbox_autoDropDirt.isSelected()) { + actionDropDirt(); + } + + } catch (NumberFormatException nfe) { + JOptionPane.showMessageDialog(null, "Error parsing number " + nfe.getMessage().toLowerCase(), "Error Dropping Dirt", JOptionPane.ERROR_MESSAGE); + } finally { + stopLoading(); + } + } + public void actionSeedBiome (Point origin) { if (tileMap == null) { JOptionPane.showMessageDialog(null, "TileMap does not exist - Add Dirt first", "Error Adding Biome", JOptionPane.ERROR_MESSAGE); @@ -1576,7 +1686,7 @@ public void actionSeedBiome (Point origin) { textField_biomeMinHeight.getText() + "," + textField_biomeMaxHeight.getText() + "," + chckbxAroundWater.isSelected()); } - updateMapView(true, 0); + updateMapView(); } catch (NumberFormatException nfe) { @@ -1597,7 +1707,7 @@ public void actionUndoBiome () { tileMap.undoLastBiome(); - updateMapView(true, 0); + updateMapView(); genHistory.add("UNDOBIOME:null"); } finally { @@ -1621,7 +1731,7 @@ public void actionResetBiomes () { } } - updateMapView(true, 0); + updateMapView(); genHistory.add("RESETBIOMES:null"); } finally { @@ -1651,7 +1761,8 @@ public void actionGenerateOres () { tileMap.generateOres(rates, progressBar); - updateMapView(true, 2); + defaultView = Constants.VIEW_TYPE.CAVE; + updateMapView(); genHistory.add("GENORES:" + textField_Rock.getText() + "," + textField_Iron.getText() + "," + textField_Gold.getText() + "," + textField_Silver.getText() + "," + textField_Zinc.getText() + "," + textField_Copper.getText() + "," + @@ -1672,7 +1783,8 @@ public void actionViewMap () { startLoading("Loading"); try { - updateMapView(true, 0); + defaultView = Constants.VIEW_TYPE.ISO; + updateMapView(); } finally { stopLoading(); } @@ -1686,7 +1798,8 @@ public void actionViewTopo () { startLoading("Loading"); try { - updateMapView(true, 1); + defaultView = Constants.VIEW_TYPE.TOPO; + updateMapView(); } finally { stopLoading(); } @@ -1705,7 +1818,8 @@ public void actionViewCave () { startLoading("Loading"); try { - updateMapView(true, 2); + defaultView = Constants.VIEW_TYPE.CAVE; + updateMapView(); } finally { stopLoading(); } @@ -1719,7 +1833,8 @@ public void actionViewHeightmap () { startLoading("Loading"); try { - updateMapView(false, 0); + defaultView = Constants.VIEW_TYPE.HEIGHT; + updateMapView(); } finally { stopLoading(); } @@ -1884,7 +1999,7 @@ public void newHeightMap(File heightImageFile, int mapSize, int maxHeight) throw heightMap = new HeightMap(heightImage, mapSize, maxHeight); heightMap.importHeightImage(); - updateMapView(false, 0); + updateMapView(); } private WurmAPI getAPI() { @@ -1907,11 +2022,12 @@ public void newHeightMap(long seed, int mapSize, double resolution, int iteratio heightMap.generateHeights(progressBar); - updateMapView(false, 0); + updateMapView(); } - private void updateMapView(boolean apiView, int viewType) { - if (!apiView) { + + private void updateMapView() { + if (defaultView == Constants.VIEW_TYPE.HEIGHT) { startLoading("Loading View"); Graphics g = mapPanel.getMapImage().getGraphics(); @@ -1924,12 +2040,12 @@ private void updateMapView(boolean apiView, int viewType) { } } else { updateAPIMap(); - - if (viewType == 1) + + if (defaultView == Constants.VIEW_TYPE.TOPO) mapPanel.setMapImage(getAPI().getMapData().createTopographicDump(true, (short) 250)); - else if (viewType == 2) + else if (defaultView == Constants.VIEW_TYPE.CAVE) mapPanel.setMapImage(getAPI().getMapData().createCaveDump(true)); - else + else if (defaultView == Constants.VIEW_TYPE.ISO) mapPanel.setMapImage(getAPI().getMapData().createMapDump()); } @@ -1938,32 +2054,48 @@ else if (viewType == 2) mapPanel.repaint(); stopLoading(); } - + private void updateAPIMap() { startLoading("Updating Map"); MapData map = getAPI().getMapData(); Random treeRand = new Random(System.currentTimeMillis()); for (int i = 0; i < heightMap.getMapSize(); i++) { - progressBar.setValue((int)((float)i/heightMap.getMapSize()*98f)); + progressBar.setValue((int)((float)i/heightMap.getMapSize()*100f/3)); for (int j = 0; j < heightMap.getMapSize(); j++) { map.setSurfaceHeight(i, j, tileMap.getSurfaceHeight(i, j)); map.setRockHeight(i, j, tileMap.getRockHeight(i, j)); - if (tileMap.hasOres()) + if (tileMap.hasOres()) { map.setCaveTile(i, j, tileMap.getOreType(i, j), tileMap.getOreCount(i, j)); - - if (tileMap.getType(i, j).isTree()) - map.setTree(i, j, tileMap.getType(i, j).getTreeType((byte) 0), - FoliageAge.values()[treeRand.nextInt(FoliageAge.values().length)], GrowthTreeStage.MEDIUM); - else if (tileMap.getType(i, j).isBush()) - map.setBush(i, j, tileMap.getType(i, j).getBushType((byte) 0), - FoliageAge.values()[treeRand.nextInt(FoliageAge.values().length)], GrowthTreeStage.MEDIUM); - else - map.setSurfaceTile(i, j, tileMap.getType(i, j)); + } + map.setSurfaceTile(i, j, Tile.TILE_ROCK); + } + } + for (int i = 0; i < heightMap.getMapSize(); i++) { + progressBar.setValue((int)((float)i/heightMap.getMapSize()*100f/3)+33); + for (int j = 0; j < heightMap.getMapSize(); j++) { + if(tileMap.getType(i, j) != Tile.TILE_ROCK && !tileMap.getType(i, j).isTree() && !tileMap.getType(i, j).isBush()) { + for(int x = i - 1; x <= i + 1; x++) { + for(int y = j - 1; y <= j + 1; y++) { + if(x > 0 && y > 0 && x < heightMap.getMapSize() && y riverSeeds; public MapPanel(MainWindow w) { super(); window = w; + riverSeeds = new ArrayList(); this.setMapSize(1024); @@ -81,7 +85,7 @@ public void mousePressed(MouseEvent e) { startX = e.getX(); startY = e.getY(); - if(e.getButton() == MouseEvent.BUTTON1 && isPaintingMode) { + if(e.getButton() == MouseEvent.BUTTON1 && isBiomePaintingMode) { if (!window.actionReady()) return; new Thread() { @@ -92,9 +96,7 @@ public void run() { window.actionSeedBiome(new Point(paintPosX, paintPosY)); } }.start(); - } - - if (e.getButton() == MouseEvent.BUTTON3) { + } else if (e.getButton() == MouseEvent.BUTTON3) { markerOffsetX = (int)((startX-imageX)/scale); markerOffsetY = (int)((startY-imageY)/scale); showMarker = !showMarker; @@ -107,18 +109,24 @@ public void run() { this.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { - if(e.getX() < startX) - imageX -= (startX - e.getX()); - else if(e.getX() > startX) - imageX += (e.getX() - startX); - if(e.getY() < startY) - imageY -= (startY - e.getY()); - else if(e.getY() > startY) - imageY += (e.getY() - startY); - startX = e.getX(); - startY = e.getY(); - checkBounds(); - repaint(); + + if(isRiverPaintingMode) { + riverSeeds.add(new Point((int)((e.getX()-imageX)/scale),(int)((e.getY()-imageY)/scale))); + repaint(); + } else { + if(e.getX() < startX) + imageX -= (startX - e.getX()); + else if(e.getX() > startX) + imageX += (e.getX() - startX); + if(e.getY() < startY) + imageY -= (startY - e.getY()); + else if(e.getY() > startY) + imageY += (e.getY() - startY); + startX = e.getX(); + startY = e.getY(); + checkBounds(); + repaint(); + } } @Override public void mouseMoved(MouseEvent e) { @@ -129,12 +137,20 @@ public void mouseMoved(MouseEvent e) { } public void setPaintingMode(boolean mode) { - isPaintingMode = mode; + isBiomePaintingMode = mode; } - - public boolean isPaintingMode() - { - return isPaintingMode; + + public void setRiverPaintingMode(boolean mode) { + isRiverPaintingMode = mode; + } + + public ArrayList getRiverSeeds() { + return riverSeeds; + } + + public void clearRiverSeeds() { + riverSeeds.clear(); + repaint(); } public void showGrid(boolean show) { @@ -188,11 +204,6 @@ public void paintComponent(Graphics g) { g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.drawImage(this.mapImage, imageX, imageY, getImageWidth(), getImageHeight(), null); - if (showMarker) { - g.setColor(Color.RED); - g.fillOval((int)((markerOffsetX*scale)+imageX)-4, (int)((markerOffsetY*scale)+imageY)-4, 8, 8); - } - if (showGrid) { double gridScale = mapSize/gridSize*scale; g.setColor(Color.CYAN); @@ -203,6 +214,17 @@ public void paintComponent(Graphics g) { g.drawLine((int)(imageX+y*gridScale), imageY, (int)(imageX+y*gridScale), imageY+(int)(mapSize*scale)); } } + + int riverMarker = 12; + g.setColor(Color.yellow); + for (Point p:riverSeeds) { + g.fillOval((int)(p.x*scale+imageX)-riverMarker/2, (int)(p.y*scale+imageY)-riverMarker/2, riverMarker, riverMarker); + } + + if (showMarker) { + g.setColor(Color.RED); + g.fillOval((int)((markerOffsetX*scale)+imageX)-4, (int)((markerOffsetY*scale)+imageY)-4, 8, 8); + } } public void setMapSize(int newMapSize) { @@ -239,4 +261,7 @@ public void setGridSize(int size) { repaint(); } + public int getMapSize() { + return mapSize; + } } diff --git a/src/net/buddat/wgenerator/TileMap.java b/src/net/buddat/wgenerator/TileMap.java index 2163357..255d3fc 100644 --- a/src/net/buddat/wgenerator/TileMap.java +++ b/src/net/buddat/wgenerator/TileMap.java @@ -42,13 +42,13 @@ public TileMap(HeightMap heightMap) { this.lastBiomeChanges = new HashMap(); } - public void dropDirt(final int dirtCount, final int maxSlope, final int maxDiagSlope, final int maxDirtHeight, final double cliffRatio, final boolean landSlide, JProgressBar progress) { + public void dropDirtQuadrants(final int dirtCount, final int maxSlope, final int maxDiagSlope, final int maxDirtHeight, final double cliffRatio, final boolean landSlide, JProgressBar progress) { final double maxSlopeHeight = maxSlope * singleDirt; final double maxDiagSlopeHeight = maxDiagSlope * singleDirt; final double maxHeight = maxDirtHeight * singleDirt; final double taperHeight = maxHeight - ((dirtCount / 2) * singleDirt); final int mapSize = heightMap.getMapSize(); - + System.out.println("Single dirt: "+singleDirt); final long startTime = System.currentTimeMillis(); int slice = 30; int total = 64; @@ -148,6 +148,78 @@ public void run() { log("Dirt Dropping (" + dirtCount + ") completed in " + (System.currentTimeMillis() - startTime) + "ms."); } + public void dropDirt(final int dirtCount, final int maxSlope, final int maxDiagSlope, final int maxDirtHeight, final double cliffRatio, final boolean landSlide, JProgressBar progress) { + final double maxSlopeHeight = maxSlope * singleDirt; + final double maxDiagSlopeHeight = maxDiagSlope * singleDirt; + final double maxHeight = maxDirtHeight * singleDirt; + final double taperHeight = maxHeight - ((dirtCount / 2) * singleDirt); + final int mapSize = heightMap.getMapSize(); + final long startTime = System.currentTimeMillis(); + dirtDropProgress = 0; + progressBar = progress; + + class Iteration implements Runnable { + int sizex, sizey; + int ix, iy; + + public Iteration(int ix, int iy, int sizex, int sizey) { + this.ix = ix; + this.iy = iy; + this.sizex = sizex; + this.sizey = sizey; + } + + public void run() { + for (int x = ix; x < ix+sizex; x++) { + for (int y = iy; y < iy+sizey; y++) { + + int mod = heightMap.getMapSize()/32; + if ( x%mod == 0 && y%mod == 0) { + dirtDropProgress += mod*mod; + int progressValue = (int)((float)dirtDropProgress/(heightMap.getMapSize()*heightMap.getMapSize()*dirtCount)*100f); + long predict = (int)((System.currentTimeMillis()-startTime)/1000.0*(100.0/progressValue-1)); + progressBar.setValue(progressValue); + progressBar.setString(progressBar.getString().substring(0, progressBar.getString().indexOf("("))+"("+predict+" secs)"); + } + + if (heightMap.getHeight(x, y) > maxHeight) + continue; + + if (heightMap.getHeight(x, y) > taperHeight) + if ((maxHeight - heightMap.getHeight(x, y)) * heightMap.getMaxHeight() < 1) + continue; + + if (landSlide) { + Point dropTile = findDropTile(x, y, maxSlopeHeight, maxDiagSlopeHeight); + addDirt((int) dropTile.getX(), (int) dropTile.getY(), 1); + } else { + Point dropTile = new Point(x,y); + addDirt((int) dropTile.getX(), (int) dropTile.getY(), 1); + } + } + } + } + } + + Thread firstThreads[] = new Thread[dirtCount]; + for (int i = 0; i < dirtCount; i++) { + firstThreads[i] = new Thread(new Iteration(0,0,mapSize,mapSize)); + firstThreads[i].start(); + } + for (Thread thread : firstThreads) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + return; + } + } + + // Reset seed due to drop dirt altering it + setBiomeSeed(biomeSeed); + log("Dirt Dropping (" + dirtCount + ") completed in " + (System.currentTimeMillis() - startTime) + "ms."); + } + private int findDropAmount(int x, int y, double maxSlope, double maxDiagSlope, int dirtCount, double cliffRatio) { @@ -393,8 +465,10 @@ private short getDirt(int x, int y) { } private void setDirt(int x, int y, short newDirt) { - if (newDirt < 0) + if (newDirt < 0) { newDirt = 0; + System.out.println("wtf"); + } if (newDirt > 0) { if (getTileHeight(x, y) >= waterHeight) @@ -406,8 +480,10 @@ private void setDirt(int x, int y, short newDirt) { dirtMap[x][y] = newDirt; } - public void addDirt(int x, int y, int count) { - setDirt(x, y, (short) (getDirt(x, y) + count)); + void addDirt(int x, int y, int count) { + synchronized(this) { + setDirt(x, y, (short) (getDirt(x, y) + count)); + } } private double getDirtHeight(int x, int y) { @@ -418,14 +494,18 @@ private double getTileHeight(int x, int y) { return heightMap.getHeight(x, y) + getDirtHeight(x, y); } - public short getSurfaceHeight(int x, int y) { + short getSurfaceHeight(int x, int y) { return (short) ((getTileHeight(x, y) - getWaterHeight()) * heightMap.getMaxHeight()); } - public short getRockHeight(int x, int y) { + short getRockHeight(int x, int y) { return (short) ((heightMap.getHeight(x, y) - getWaterHeight()) * heightMap.getMaxHeight()); } + public int getMapHeight(int x, int y) { + return (int)(getTileHeight(x, y) * heightMap.getMaxHeight()); + } + private double getDifference(int x1, int y1, int x2, int y2) { return Math.abs(getTileHeight(x1, y1) - getTileHeight(x2, y2)); } @@ -434,7 +514,7 @@ private double getDifference(Point p, Point p2) { return getDifference((int) p.getX(), (int) p.getY(), (int) p2.getX(), (int) p2.getY()); } - public void setBiomeSeed(int newSeed) { + void setBiomeSeed(int newSeed) { biomeSeed = newSeed; biomeRandom = new Random(newSeed); } @@ -443,7 +523,7 @@ private double getWaterHeight() { return waterHeight; } - public void setWaterHeight(int newHeight) { + void setWaterHeight(int newHeight) { this.waterHeight = newHeight * singleDirt; } diff --git a/src/net/buddat/wgenerator/util/Constants.java b/src/net/buddat/wgenerator/util/Constants.java index ca89b9b..99c321e 100644 --- a/src/net/buddat/wgenerator/util/Constants.java +++ b/src/net/buddat/wgenerator/util/Constants.java @@ -28,6 +28,10 @@ public class Constants { public static final int MAX_DIRT_DIAG_SLOPE = 56; public static final int WATER_HEIGHT = 500; public static final int CLIFF_RATIO = 1; + + public static final int RIVER_DEPTH = 40; + public static final int RIVER_WIDTH = 6; + public static final int RIVER_SLOPE = 12; public static final int EROSION_ITERATIONS = 30; public static final int ROCK_WEIGHT = 3800; @@ -56,4 +60,6 @@ public class Constants { public static final int GRID_SIZE = 8; public static final int BIOME_SEED_LIMIT_MULTIPLIER = 10000; + public static enum VIEW_TYPE {ISO,TOPO,CAVE,HEIGHT}; + }