Search in sources :

Example 1 with HeightMapTreeModel

use of org.pepsoft.worldpainter.heightMaps.gui.HeightMapTreeModel in project WorldPainter by Captain-Chaos.

the class HeightMapEditor method installHeightMap.

private void installHeightMap(boolean updateTreeModel) {
    switch(viewMode) {
        case HEIGHT_MAP:
            if (tiledImageViewer1.getTileProviderCount() == 0) {
                tiledImageViewer1.setTileProvider(new HeightMapTileProvider(focusHeightMap));
            } else {
                tiledImageViewer1.replaceTileProvider(0, new HeightMapTileProvider(focusHeightMap));
            }
            tiledImageViewer1.setGridColour(Color.GRAY);
            break;
        case TERRAIN:
            TileFactory tileFactory = new HeightMapTileFactory(seed, focusHeightMap, Constants.DEFAULT_MAX_HEIGHT_2, false, theme);
            synchronized (tileCache) {
                tileCache.clear();
            }
            final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {

                @Override
                public Rectangle getExtent() {
                    // Tile factories are endless
                    return null;
                }

                @Override
                public boolean isTilePresent(int x, int y) {
                    // Tile factories are endless and have no holes
                    return true;
                }

                @Override
                public Tile getTile(int x, int y) {
                    Point coords = new Point(x, y);
                    Tile tile;
                    synchronized (tileCache) {
                        tile = tileCache.get(coords);
                        if (tile == RENDERING) {
                            do {
                                try {
                                    tileCache.wait();
                                    tile = tileCache.get(coords);
                                } catch (InterruptedException e) {
                                    throw new RuntimeException("Thread interrupted while waiting for tile to be rendered");
                                }
                            } while (tileCache.get(coords) == RENDERING);
                        }
                        if (tile == null) {
                            tileCache.put(coords, RENDERING);
                        }
                    }
                    if (tile == null) {
                        tile = tileFactory.createTile(x, y);
                        synchronized (tileCache) {
                            tileCache.put(coords, tile);
                            tileCache.notifyAll();
                        }
                    }
                    return tile;
                }
            };
            if (tiledImageViewer1.getTileProviderCount() == 0) {
                tiledImageViewer1.setTileProvider(0, new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), false, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
            } else {
                tiledImageViewer1.replaceTileProvider(0, new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), false, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
            }
            tiledImageViewer1.setGridColour(Color.BLACK);
            break;
    }
    if (updateTreeModel) {
        treeModel = new HeightMapTreeModel(rootHeightMap);
        jTree1.setModel(treeModel);
    }
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) HeightMapTreeModel(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTreeModel) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) HeightMapTileProvider(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTileProvider) HeightMapTileProvider(org.pepsoft.worldpainter.heightMaps.gui.HeightMapTileProvider) org.pepsoft.worldpainter(org.pepsoft.worldpainter)

Aggregations

org.pepsoft.worldpainter (org.pepsoft.worldpainter)1 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)1 DynMapColourScheme (org.pepsoft.worldpainter.colourschemes.DynMapColourScheme)1 HeightMapTileProvider (org.pepsoft.worldpainter.heightMaps.gui.HeightMapTileProvider)1 HeightMapTreeModel (org.pepsoft.worldpainter.heightMaps.gui.HeightMapTreeModel)1