use of org.pepsoft.worldpainter.layers.Layer in project WorldPainter by Captain-Chaos.
the class SimpleTheme method initCaches.
private void initCaches() {
if (layerMap != null) {
List<Layer> layers = new ArrayList<>(layerMap.size());
List<Layer> bitLayers = new ArrayList<>(layerMap.size());
List<int[]> layerLevels = new ArrayList<>(layerMap.size());
List<int[]> bitLayerLevels = new ArrayList<>(layerMap.size());
layerLevelCache = new int[layerMap.size()][maxHeight];
for (Map.Entry<Filter, Layer> entry : layerMap.entrySet()) {
Layer layer = entry.getValue();
Filter filter = entry.getKey();
int[] levels = new int[maxHeight];
for (int z = 0; z < maxHeight; z++) {
levels[z] = filter.getLevel(0, 0, z, 15);
}
if (layer.getDataSize() == Layer.DataSize.BIT) {
bitLayers.add(layer);
bitLayerLevels.add(levels);
} else if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
layers.add(layer);
layerLevels.add(levels);
} else {
throw new IllegalArgumentException("Layer with unsupported data size " + layer.getDataSize() + " encountered");
}
}
if (!layers.isEmpty()) {
layerCache = layers.toArray(new Layer[layers.size()]);
layerLevelCache = layerLevels.toArray(new int[layerLevels.size()][]);
} else {
layerCache = null;
layerLevelCache = null;
}
if (!bitLayers.isEmpty()) {
bitLayerCache = bitLayers.toArray(new Layer[bitLayers.size()]);
bitLayerLevelCache = bitLayerLevels.toArray(new int[bitLayerLevels.size()][]);
} else {
bitLayerCache = null;
bitLayerLevelCache = null;
}
} else {
layerCache = null;
bitLayerCache = null;
layerLevelCache = null;
bitLayerLevelCache = null;
}
}
use of org.pepsoft.worldpainter.layers.Layer in project WorldPainter by Captain-Chaos.
the class FillDialog method clearLayer.
private void clearLayer(ProgressReceiver progressReceiver) throws OperationCancelled {
Layer layer = (Layer) comboBoxClearLayer.getSelectedItem();
if (filter == null) {
dimension.clearLayerData(layer);
} else {
if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
dimension.visitTiles().forFilter(filter).andDo(tile -> {
final int worldTileX = tile.getX() << TILE_SIZE_BITS;
final int worldTileY = tile.getY() << TILE_SIZE_BITS;
for (int x = 0; x < TILE_SIZE; x++) {
for (int y = 0; y < TILE_SIZE; y++) {
int oldLayervalue = tile.getLayerValue(layer, x, y);
int layerValue;
if (filter == null) {
layerValue = 0;
} else {
layerValue = Math.min(oldLayervalue, 15 - (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * 15));
}
if (oldLayervalue != layerValue) {
tile.setLayerValue(layer, x, y, layerValue);
}
}
}
}, progressReceiver);
} else if (layer.getDataSize() == Layer.DataSize.BIT) {
dimension.visitTiles().forFilter(filter).andDo(tile -> {
final int worldTileX = tile.getX() << TILE_SIZE_BITS;
final int worldTileY = tile.getY() << TILE_SIZE_BITS;
for (int x = 0; x < TILE_SIZE; x++) {
for (int y = 0; y < TILE_SIZE; y++) {
boolean set;
if (filter == null) {
set = true;
} else {
float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
set = (strength > 0.95f) || (Math.random() < strength);
}
if (set && tile.getBitLayerValue(layer, x, y)) {
tile.setBitLayerValue(layer, x, y, false);
}
}
}
}, progressReceiver);
} else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
dimension.visitTiles().forFilter(filter).andDo(tile -> {
final int worldTileX = tile.getX() << TILE_SIZE_BITS;
final int worldTileY = tile.getY() << TILE_SIZE_BITS;
for (int x = 0; x < TILE_SIZE; x += 16) {
for (int y = 0; y < TILE_SIZE; y += 16) {
boolean set;
if (filter == null) {
set = true;
} else {
float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
set = (strength > 0.95f) || (Math.random() < strength);
}
if (set && tile.getBitLayerValue(layer, x, y)) {
tile.setBitLayerValue(layer, x, y, false);
}
}
}
}, progressReceiver);
} else {
throw new UnsupportedOperationException();
}
}
}
use of org.pepsoft.worldpainter.layers.Layer in project WorldPainter by Captain-Chaos.
the class WorldFactory method createDefaultWorldWithoutTiles.
public static World2 createDefaultWorldWithoutTiles(final Configuration config, final long seed) {
final HeightMapTileFactory tileFactory;
if (config.isHilly()) {
tileFactory = TileFactoryFactory.createNoiseTileFactory(seed, config.getSurface(), config.getDefaultMaxHeight(), config.getLevel(), config.getWaterLevel(), config.isLava(), config.isBeaches(), config.getDefaultRange(), config.getDefaultScale());
} else {
tileFactory = TileFactoryFactory.createFlatTileFactory(seed, config.getSurface(), config.getDefaultMaxHeight(), config.getLevel(), config.getWaterLevel(), config.isLava(), config.isBeaches());
}
final Dimension defaults = config.getDefaultTerrainAndLayerSettings();
if ((defaults.getTileFactory() instanceof HeightMapTileFactory) && ((((HeightMapTileFactory) defaults.getTileFactory()).getTheme() instanceof SimpleTheme) && ((SimpleTheme) ((HeightMapTileFactory) defaults.getTileFactory()).getTheme()).getTerrainRanges() != null)) {
HeightMapTileFactory defaultTileFactory = (HeightMapTileFactory) defaults.getTileFactory();
SimpleTheme defaultTheme = (SimpleTheme) defaultTileFactory.getTheme();
SimpleTheme theme = (SimpleTheme) tileFactory.getTheme();
theme.setTerrainRanges(new TreeMap<>(defaultTheme.getTerrainRanges()));
theme.setRandomise(defaultTheme.isRandomise());
}
final World2 world = new World2(config.getDefaultPlatform(), World2.DEFAULT_OCEAN_SEED, tileFactory, tileFactory.getMaxHeight());
world.addHistoryEntry(HistoryEntry.WORLD_CREATED);
final ResourceBundle strings = ResourceBundle.getBundle("org.pepsoft.worldpainter.resources.strings");
world.setName(strings.getString("generated.world"));
// Export settings
world.setCreateGoodiesChest(config.isDefaultCreateGoodiesChest());
Generator generator = config.getDefaultGenerator();
if ((world.getMaxHeight() == DEFAULT_MAX_HEIGHT_1) && (generator == Generator.LARGE_BIOMES)) {
generator = Generator.DEFAULT;
} else if ((world.getMaxHeight() == DEFAULT_MAX_HEIGHT_2) && (generator == Generator.DEFAULT)) {
generator = Generator.LARGE_BIOMES;
}
world.setGenerator(generator);
if (generator == Generator.FLAT) {
world.setGeneratorOptions(config.getDefaultGeneratorOptions());
}
world.setMapFeatures(config.isDefaultMapFeatures());
world.setGameType(config.getDefaultGameType());
world.setAllowCheats(config.isDefaultAllowCheats());
final Dimension dim0 = world.getDimension(0);
dim0.setEventsInhibited(true);
try {
dim0.setBorder(defaults.getBorder());
dim0.setBorderSize(defaults.getBorderSize());
dim0.setBedrockWall(defaults.isBedrockWall());
dim0.setBorderLevel(defaults.getBorderLevel());
dim0.setSubsurfaceMaterial(defaults.getSubsurfaceMaterial());
dim0.setPopulate(defaults.isPopulate());
for (Map.Entry<Layer, ExporterSettings> entry : defaults.getAllLayerSettings().entrySet()) {
dim0.setLayerSettings(entry.getKey(), entry.getValue().clone());
}
dim0.setGridEnabled(config.isDefaultGridEnabled());
dim0.setGridSize(config.getDefaultGridSize());
dim0.setContoursEnabled(config.isDefaultContoursEnabled());
dim0.setContourSeparation(config.getDefaultContourSeparation());
dim0.setTopLayerMinDepth(defaults.getTopLayerMinDepth());
dim0.setTopLayerVariation(defaults.getTopLayerVariation());
dim0.setBottomless(defaults.isBottomless());
dim0.setCoverSteepTerrain(defaults.isCoverSteepTerrain());
} finally {
dim0.setEventsInhibited(false);
}
world.setDirty(false);
return world;
}
use of org.pepsoft.worldpainter.layers.Layer in project WorldPainter by Captain-Chaos.
the class Configuration method readObject.
@SuppressWarnings("deprecation")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
// Legacy config
if ((border != null) && (border2 == null)) {
border2 = Border.valueOf(border.name());
border = null;
}
if (customMaterials == null) {
customMaterials = new Material[] { Material.DIRT, Material.DIRT, Material.DIRT, Material.DIRT, Material.DIRT };
}
if (minecraftJars == null) {
minecraftJars = new HashMap<>();
minecraft1_9_p3Jar = null;
}
if (uuid == null) {
uuid = UUID.randomUUID();
}
if (undoLevels == 0) {
checkForUpdates = true;
undoEnabled = true;
defaultContoursEnabled = true;
undoLevels = 100;
defaultGridSize = 128;
defaultContourSeparation = 10;
defaultWidth = 5;
defaultHeight = 5;
defaultMaxHeight = DEFAULT_MAX_HEIGHT_2;
}
if (defaultTerrainAndLayerSettings == null) {
defaultTerrainAndLayerSettings = new Dimension(World2.DEFAULT_OCEAN_SEED, TileFactoryFactory.createNoiseTileFactory(new Random().nextLong(), surface, defaultMaxHeight, level, waterLevel, lava, beaches, 20, 1.0), Constants.DIM_NORMAL, defaultMaxHeight);
}
// New legacy mechanism with version number
if (version < 1) {
worldFileBackups = 3;
}
if (version < 2) {
defaultRange = 20;
defaultScale = 1.0;
defaultLightOrigin = LightOrigin.NORTHWEST;
}
if (version < 3) {
String maxRadiusStr = System.getProperty("org.pepsoft.worldpainter.maxRadius");
if ((maxRadiusStr != null) && (!maxRadiusStr.trim().isEmpty())) {
try {
maximumBrushSize = Integer.parseInt(maxRadiusStr);
} catch (NumberFormatException e) {
maximumBrushSize = 300;
}
} else {
maximumBrushSize = 300;
}
}
if (version < 4) {
// Turn on smooth snow for everyone once
FrostSettings frostSettings = (FrostSettings) defaultTerrainAndLayerSettings.getLayerSettings(Frost.INSTANCE);
if (frostSettings != null) {
frostSettings.setMode(FrostSettings.MODE_SMOOTH);
}
}
if (version < 5) {
// Reset the Resource setting preferences once, which might have
// been unintentionally altered due to a bug
defaultTerrainAndLayerSettings.setLayerSettings(Resources.INSTANCE, new ResourcesExporterSettings(defaultMaxHeight));
}
if (version < 6) {
if (!Boolean.FALSE.equals(pingAllowed)) {
eventLog = new LinkedList<>();
}
}
if (version < 7) {
customLayers = new ArrayList<>();
mixedMaterials = new ArrayList<>();
}
if (version < 8) {
// continue to the top of the map
if ((defaultTerrainAndLayerSettings.getTileFactory() instanceof HeightMapTileFactory) && (((HeightMapTileFactory) defaultTerrainAndLayerSettings.getTileFactory()).getTheme() instanceof SimpleTheme)) {
SimpleTheme theme = (SimpleTheme) ((HeightMapTileFactory) defaultTerrainAndLayerSettings.getTileFactory()).getTheme();
// luck; it's not worth migrating them as well
if (theme.getTerrainRanges() != null) {
SortedMap<Integer, Terrain> terrainRanges = theme.getTerrainRanges();
Map<Filter, Layer> layerMap = new HashMap<>();
boolean frostAdded = false;
for (Map.Entry<Integer, Terrain> entry : terrainRanges.entrySet()) {
if (entry.getValue() == Terrain.SNOW) {
if (!frostAdded) {
layerMap.put(new HeightFilter(defaultMaxHeight, entry.getKey(), defaultMaxHeight - 1, theme.isRandomise()), Frost.INSTANCE);
frostAdded = true;
}
entry.setValue(Terrain.ROCK);
}
}
if (!layerMap.isEmpty()) {
theme.setLayerMap(layerMap);
}
}
}
}
if (version < 9) {
// Set default export settings
defaultCreateGoodiesChest = true;
defaultGenerator = Generator.DEFAULT;
defaultMapFeatures = true;
defaultGameType = 0;
}
if (version < 10) {
if (defaultTerrainAndLayerSettings.getSubsurfaceMaterial() == Terrain.STONE) {
defaultTerrainAndLayerSettings.setSubsurfaceMaterial(Terrain.STONE_MIX);
}
}
if (version < 11) {
switch(SystemUtils.getOS()) {
case WINDOWS:
accelerationType = AccelerationType.DIRECT3D;
break;
case MAC:
accelerationType = AccelerationType.DEFAULT;
break;
case LINUX:
accelerationType = AccelerationType.XRENDER;
break;
default:
accelerationType = AccelerationType.DEFAULT;
break;
}
// Previous default; principle of least surprise:
overlayType = OverlayType.SCALE_ON_LOAD;
}
if (version < 12) {
defaultJideLayoutData = null;
jideLayoutData = null;
showCalloutCount = 3;
}
if (version < 13) {
backgroundImageMode = TiledImageViewer.BackgroundImageMode.REPEAT;
backgroundColour = -1;
showBiomes = showBorders = true;
}
if (version < 14) {
if (defaultGameType >= 0) {
defaultGameTypeObj = GameType.values()[defaultGameType];
defaultGameType = -1;
} else {
// Not sure how this could have happened, but it has been
// observed
defaultGameTypeObj = GameType.SURVIVAL;
defaultGameType = -1;
}
}
if (version < 15) {
defaultPlatform = DefaultPlugin.JAVA_ANVIL;
exportDirectories = new HashMap<>();
if (exportDirectory != null) {
exportDirectories.put(DefaultPlugin.JAVA_ANVIL, exportDirectory);
exportDirectories.put(DefaultPlugin.JAVA_MCREGION, exportDirectory);
exportDirectory = null;
}
}
version = CURRENT_VERSION;
// Bug fix: make sure terrain ranges map conforms to surface material setting
TileFactory tileFactory = defaultTerrainAndLayerSettings.getTileFactory();
if ((tileFactory instanceof HeightMapTileFactory) && (((HeightMapTileFactory) tileFactory).getTheme() instanceof SimpleTheme)) {
SortedMap<Integer, Terrain> defaultTerrainRanges = ((SimpleTheme) ((HeightMapTileFactory) tileFactory).getTheme()).getTerrainRanges();
// Find what is probably meant to be the surface material. With the
// default settings this should be -1, but if someone configured a
// default underwater material, try not to change that
int surfaceLevel = defaultTerrainRanges.headMap(waterLevel + 3).lastKey();
defaultTerrainRanges.put(surfaceLevel, surface);
}
}
use of org.pepsoft.worldpainter.layers.Layer in project WorldPainter by Captain-Chaos.
the class HeightMapImporter method importToNewWorld.
/**
* Create a new WorldPainter world from the configured height map and import
* settings.
*
* @param progressReceiver The progress receiver to report progress to and
* check for cancellation with.
* @return A new WorldPainter world based on the specified height map.
* @throws org.pepsoft.util.ProgressReceiver.OperationCancelled If and when
* the specified progress received throws it (when the user cancels the
* operation).
*/
public World2 importToNewWorld(ProgressReceiver progressReceiver) throws ProgressReceiver.OperationCancelled {
Rectangle extent = heightMap.getExtent();
logger.info("Importing world from height map {} (size: {}x{})", name, extent.width, extent.height);
final boolean highRes = (imageHighLevel >= maxHeight) && (worldHighLevel < maxHeight);
final World2 world = new World2((maxHeight == DEFAULT_MAX_HEIGHT_2) ? JAVA_ANVIL : JAVA_MCREGION, World2.DEFAULT_OCEAN_SEED, tileFactory, maxHeight);
world.addHistoryEntry(HistoryEntry.WORLD_IMPORTED_FROM_HEIGHT_MAP, imageFile);
int p = name.lastIndexOf('.');
if (p != -1) {
name = name.substring(0, p);
}
world.setName(name);
final Dimension dimension = world.getDimension(0);
// Export settings
final Configuration config = Configuration.getInstance();
final boolean minecraft11Only = dimension.getMaxHeight() != DEFAULT_MAX_HEIGHT_2;
world.setCreateGoodiesChest(config.isDefaultCreateGoodiesChest());
Generator generator = config.getDefaultGenerator();
if (minecraft11Only && (generator == Generator.LARGE_BIOMES)) {
generator = Generator.DEFAULT;
} else if ((!minecraft11Only) && (generator == Generator.DEFAULT)) {
generator = Generator.LARGE_BIOMES;
}
world.setGenerator(generator);
if (generator == Generator.FLAT) {
world.setGeneratorOptions(config.getDefaultGeneratorOptions());
}
world.setMapFeatures(config.isDefaultMapFeatures());
world.setGameType(config.getDefaultGameType());
world.setAllowCheats(config.isDefaultAllowCheats());
// Turn off smooth snow, except for high res imports
if (!highRes) {
FrostExporter.FrostSettings frostSettings = new FrostExporter.FrostSettings();
frostSettings.setMode(FrostExporter.FrostSettings.MODE_FLAT);
dimension.setLayerSettings(Frost.INSTANCE, frostSettings);
}
importToDimension(dimension, true, progressReceiver);
Dimension defaults = config.getDefaultTerrainAndLayerSettings();
dimension.setBorder(defaults.getBorder());
dimension.setBorderSize(defaults.getBorderSize());
dimension.setBorderLevel(worldWaterLevel);
dimension.setBedrockWall(defaults.isBedrockWall());
dimension.setSubsurfaceMaterial(defaults.getSubsurfaceMaterial());
dimension.setPopulate(defaults.isPopulate());
dimension.setTopLayerMinDepth(defaults.getTopLayerMinDepth());
dimension.setTopLayerVariation(defaults.getTopLayerVariation());
dimension.setBottomless(defaults.isBottomless());
for (Map.Entry<Layer, ExporterSettings> entry : defaults.getAllLayerSettings().entrySet()) {
dimension.setLayerSettings(entry.getKey(), entry.getValue().clone());
}
dimension.setGridEnabled(config.isDefaultGridEnabled());
dimension.setGridSize(config.getDefaultGridSize());
dimension.setContoursEnabled(config.isDefaultContoursEnabled());
dimension.setContourSeparation(config.getDefaultContourSeparation());
world.setSpawnPoint(new Point(extent.x + extent.width / 2, extent.y + extent.height / 2));
dimension.setLastViewPosition(world.getSpawnPoint());
world.setDirty(false);
return world;
}
Aggregations