Fix relight and removelight (#475)

* Start work on lighting engine (does not build)

* Implement getLighting

* Setting, flushing light etc works. Getting light should be working..?

* Better queue/chunk handling

* Use correct location for lighting update

* Correct set location, remove debug

* cleanup a little

* Fix fixlight

* Apply to all versions for the numpties

* Remove lighting extent if not using

* Actually bitmask blocks when setting in chunks

* Initialise Maps and Dequeues with inital size

* format

* Documentation maybe
This commit is contained in:
dordsor21
2020-05-27 11:45:08 +01:00
committed by GitHub
parent 1ff5e7761b
commit bdc14c10c7
27 changed files with 1910 additions and 93 deletions

View File

@ -2,8 +2,11 @@ package com.boydti.fawe;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.lighting.NMSRelighter;
import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RelightMode;
import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.changeset.SimpleChangeSetSummary;
import com.boydti.fawe.object.exception.FaweException;
@ -28,10 +31,13 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
@ -43,7 +49,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.annotation.Nullable;
/**
* The FaweAPI class offers a few useful functions.<br>
@ -387,12 +392,52 @@ public class FaweAPI {
* - Relights in parallel (if enabled) for best performance<br>
* - Also resends chunks<br>
*
* @param world
* @param selection (assumes cuboid)
* @return
* @param world World to relight in
* @param selection Region to relight
* @param queue Queue to relight in/from
* @param mode The mode to relight with
* @return Chunks changed
*/
public static int fixLighting(World world, Region selection, @Nullable IQueueExtent queue) {
throw new UnsupportedOperationException();
public static int fixLighting(World world, Region selection, @Nullable IQueueExtent<IQueueChunk> queue, final RelightMode mode) {
final BlockVector3 bot = selection.getMinimumPoint();
final BlockVector3 top = selection.getMaximumPoint();
final int minX = bot.getBlockX() >> 4;
final int minZ = bot.getBlockZ() >> 4;
final int maxX = top.getBlockX() >> 4;
final int maxZ = top.getBlockZ() >> 4;
int count = 0;
if (queue == null) {
World unwrapped = WorldWrapper.unwrap(world);
if (unwrapped instanceof IQueueExtent) {
queue = (IQueueExtent) unwrapped;
} else if (Settings.IMP.QUEUE.PARALLEL_THREADS > 1) {
ParallelQueueExtent parallel =
new ParallelQueueExtent(Fawe.get().getQueueHandler(), world, true);
queue = parallel.getExtent();
} else {
queue = Fawe.get().getQueueHandler().getQueue(world);
}
}
NMSRelighter relighter = new NMSRelighter(queue);
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
relighter.addChunk(x, z, null, 65535);
count++;
}
}
if (mode != RelightMode.NONE) {
relighter.fixSkyLighting();
relighter.fixBlockLighting();
} else {
relighter.removeLighting();
}
relighter.sendChunks();
return count;
}
/**