Skip to content

Commit

Permalink
Fixes for lowres lighting and map-purging/saving, tweak default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Aug 14, 2022
1 parent 4be78ff commit 42e53f0
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class WebappConfig {
private int maxZoomDistance = 100000;

private int hiresSliderMax = 500;
private int hiresSliderDefault = 200;
private int hiresSliderMin = 50;
private int hiresSliderDefault = 100;
private int hiresSliderMin = 0;

private int lowresSliderMax = 10000;
private int lowresSliderMax = 7000;
private int lowresSliderDefault = 2000;
private int lowresSliderMin = 500;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import de.bluecolored.bluemap.common.plugin.text.TextFormat;
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
import de.bluecolored.bluemap.common.rendermanager.RenderTask;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.world.World;
import org.apache.commons.lang3.time.DurationFormatUtils;

Expand Down Expand Up @@ -80,6 +79,11 @@ public List<Text> createStatusMessage(){
lines.add(Text.of(TextColor.GRAY, " [" + getRefForTask(task) + "] ", TextColor.GOLD, task.getDescription()));

if (i == 0) {
String detail = task.getDetail().orElse(null);
if (detail != null) {
lines.add(Text.of(TextColor.GRAY, " Detail: ", TextColor.WHITE, detail));
}

lines.add(Text.of(TextColor.GRAY, " Progress: ", TextColor.WHITE,
(Math.round(task.estimateProgress() * 10000) / 100.0) + "%"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@

import de.bluecolored.bluemap.api.debug.DebugDump;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;

@DebugDump
public class CombinedRenderTask<T extends RenderTask> implements RenderTask {
Expand Down Expand Up @@ -105,8 +102,11 @@ public boolean contains(RenderTask task) {

@Override
public String getDescription() {
//return description + " (" + (this.currentTaskIndex + 1) + "/" + tasks.size() + ")";
return description;
}

@Override
public Optional<String> getDetail() {
return Optional.ofNullable(this.tasks.get(this.currentTaskIndex).getDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.bluecolored.bluemap.common.rendermanager;

import de.bluecolored.bluemap.core.map.BmMap;

import java.util.concurrent.atomic.AtomicBoolean;

public class MapSaveTask implements RenderTask {

private final BmMap map;
private final AtomicBoolean saved;

public MapSaveTask(BmMap map) {
this.map = map;
this.saved = new AtomicBoolean(false);
}

@Override
public void doWork() {
if (this.saved.compareAndSet(false, true)) {
map.save();
}
}

@Override
public boolean hasMoreWork() {
return !this.saved.get();
}

@Override
public void cancel() {
this.saved.set(true);
}

@Override
public String getDescription() {
return "Save map '" + map.getId() + "'";
}

@Override
public boolean contains(RenderTask task) {
if (this == task) return true;
if (task == null) return false;
if (getClass() != task.getClass()) return false;
MapSaveTask other = (MapSaveTask) task;
return map.getId().equals(other.map.getId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.stream.Collectors;

@DebugDump
public class MapUpdateTask extends CombinedRenderTask<WorldRegionRenderTask> {
public class MapUpdateTask extends CombinedRenderTask<RenderTask> {

private final BmMap map;
private final Collection<Vector2i> regions;
Expand Down Expand Up @@ -77,17 +77,25 @@ public Collection<Vector2i> getRegions() {
return regions;
}

private static Collection<WorldRegionRenderTask> createTasks(BmMap map, Collection<Vector2i> regions, boolean force) {
List<WorldRegionRenderTask> tasks = new ArrayList<>(regions.size());
regions.forEach(region -> tasks.add(new WorldRegionRenderTask(map, region, force)));
private static Collection<RenderTask> createTasks(BmMap map, Collection<Vector2i> regions, boolean force) {
ArrayList<WorldRegionRenderTask> regionTasks = new ArrayList<>(regions.size());
regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force)));

// get spawn region
World world = map.getWorld();
Vector2i spawnPoint = world.getSpawnPoint().toVector2(true);
Grid regionGrid = world.getRegionGrid();
Vector2i spawnRegion = regionGrid.getCell(spawnPoint);

tasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion));
// sort tasks by distance to the spawn region
regionTasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion));

// save map before and after the whole update
ArrayList<RenderTask> tasks = new ArrayList<>(regionTasks.size() + 2);
tasks.add(new MapSaveTask(map));
tasks.addAll(regionTasks);
tasks.add(new MapSaveTask(map));

return tasks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package de.bluecolored.bluemap.common.rendermanager;

import java.util.Optional;

public interface RenderTask {

void doWork() throws Exception;
Expand Down Expand Up @@ -55,4 +57,8 @@ default boolean contains(RenderTask task) {

String getDescription();

default Optional<String> getDetail() {
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enable-free-flight: true
# The default map and camera-location where a user will start after opening the webapp.
# This is in form of the url-anchor: Open your map in a browser and look at the url, everything after the '#' is the value for this setting.
# Default is "no anchor" -> The camera will start with the topmost map and at that map's starting point.
#start-location: "overworld:0:16:-32:390:0.1:0.19:0:0:perspective"
#start-location: "world:0:16:-32:390:0.1:0.19:0:0:perspective"

# The minimum (closest) and maximum (furthest) distance (in blocks) that the camera can be from the ground
min-zoom-distance: 5
Expand All @@ -42,14 +42,14 @@ resolution-default: 1

# The min, max and default values of the hires render-distance slider (settings-menu)
# The values are in blocks.
# Default is max:500 default:200 and min:50
# Default is max:500 default:100 and min:0
hires-slider-max: 500
hires-slider-default: 200
hires-slider-min: 50
hires-slider-default: 100
hires-slider-min: 0

# The min, max and default values of the lowres render-distance slider (settings-menu)
# The values are in blocks.
# Default is max:10000 default:2000 and min:500
lowres-slider-max: 10000
# Default is max:7000 default:2000 and min:500
lowres-slider-max: 7000
lowres-slider-default: 2000
lowres-slider-min: 500
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public synchronized void save() {
lowresTileManager.save();
saveRenderState();
saveMarkerState();
saveMapSettings();

// only save texture gallery if not present in storage
try {
if (storage.readMeta(id, MetaType.TEXTURES).isEmpty())
saveTextureGallery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ public void render(World world, Vector3i modelMin, Vector3i modelMax, HiresTileM

modelFactory.render(block, blockModel, blockColor);

//update topBlockLight
if (
y >= renderSettings.getRemoveCavesBelowY() ||
(renderSettings.isCaveDetectionUsesBlockLight() ? block.getBlockLightLevel() : block.getSunLightLevel()) > 0
) {
if (blockColor.a > 0) {
topBlockLight = Math.floor(topBlockLight * (1 - blockColor.a));
}
topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel());
} else {
topBlockLight = 0;
}

// skip empty blocks
if (blockModel.getSize() <= 0) continue;

Expand All @@ -95,11 +108,7 @@ public void render(World world, Vector3i modelMin, Vector3i modelMax, HiresTileM
if (blockColor.a > 0) {
maxHeight = y;
columnColor.overlay(blockColor.premultiplied());
topBlockLight = Math.floor(topBlockLight * (1 - blockColor.a));
}

//update topBlockLight
topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel());
}
}

Expand Down

0 comments on commit 42e53f0

Please sign in to comment.