3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-27 03:12:37 +01:00

Relight using starlight engine on Tuinity

Dieser Commit ist enthalten in:
Hannes Greule 2021-04-10 14:01:02 +02:00
Ursprung 19592df1f6
Commit f0b1b81d4f
12 geänderte Dateien mit 235 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,18 @@
package com.boydti.fawe.bukkit;
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.lighting.Relighter;
import com.boydti.fawe.beta.implementation.lighting.RelighterFactory;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RelightMode;
import com.sk89q.worldedit.world.World;
public class NMSRelighterFactory implements RelighterFactory {
@Override
public Relighter createRelighter(RelightMode relightMode, World world, IQueueExtent<IQueueChunk> queue) {
return new NMSRelighter(queue, Settings.IMP.LIGHTING.DO_HEIGHTMAPS,
relightMode != null ? relightMode : RelightMode.valueOf(Settings.IMP.LIGHTING.MODE));
}
}

Datei anzeigen

@ -0,0 +1,20 @@
package com.boydti.fawe.bukkit.adapter.mc1_16_5;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.lighting.NullRelighter;
import com.boydti.fawe.beta.implementation.lighting.Relighter;
import com.boydti.fawe.beta.implementation.lighting.RelighterFactory;
import com.boydti.fawe.object.RelightMode;
import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
public class TuinityRelighterFactory_1_16_5 implements RelighterFactory {
@Override
public Relighter createRelighter(RelightMode relightMode, World world, IQueueExtent<IQueueChunk> queue) {
org.bukkit.World w = Bukkit.getWorld(world.getName());
if (w == null) return NullRelighter.INSTANCE;
return new TuinityRelighter_1_16_5(((CraftWorld) w).getHandle(), queue);
}
}

Datei anzeigen

@ -0,0 +1,125 @@
package com.boydti.fawe.bukkit.adapter.mc1_16_5;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.chunk.ChunkHolder;
import com.boydti.fawe.beta.implementation.lighting.Relighter;
import com.boydti.fawe.util.TaskManager;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_16_R3.MCUtil;
import net.minecraft.server.v1_16_R3.WorldServer;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
public class TuinityRelighter_1_16_5 implements Relighter {
private static final IntConsumer nothingIntConsumer = i -> {};
private final WorldServer world;
private final MethodHandle relight;
private final ReentrantLock lock = new ReentrantLock();
private final IQueueExtent<IQueueChunk> queue;
public TuinityRelighter_1_16_5(WorldServer world, IQueueExtent<IQueueChunk> queue) {
this.queue = queue;
MethodHandle methodHandle = null;
try {
Method relightMethod = world.getChunkProvider().getLightEngine().getClass().getMethod(
"relight",
Set.class,
Consumer.class,
IntConsumer.class
);
methodHandle = MethodHandles.lookup().unreflect(relightMethod);
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
}
this.relight = methodHandle;
this.world = world;
}
@Override
public boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask) {
List<ChunkCoordIntPair> chunks = MCUtil.getSpiralOutChunks(new BlockPosition(cx << 4, 0, cz << 4), 1);
TaskManager.IMP.task(() ->
{
try {
relight.invoke(world.getChunkProvider().getLightEngine(),
new HashSet<>(chunks),
(Consumer<?>) coord -> sendChunk(cx, cz), // send chunk after lighting was done
nothingIntConsumer
);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
);
return true;
}
private void sendChunk(int cx, int cz) {
ChunkHolder<?> chunk = (ChunkHolder<?>) queue.getOrCreateChunk(cx, cz);
Fawe.imp().getPlatformAdapter().sendChunk(chunk.getOrCreateGet(), -1, false);
}
@Override
public void addLightUpdate(int x, int y, int z) {
}
@Override
public void fixLightingSafe(boolean sky) {
}
@Override
public void clear() {
}
@Override
public void removeLighting() {
}
@Override
public void fixBlockLighting() {
}
@Override
public void fixSkyLighting() {
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public ReentrantLock getLock() {
return this.lock;
}
@Override
public boolean isFinished() {
return true;
}
@Override
public void close() throws Exception {
}
}

Datei anzeigen

@ -19,6 +19,9 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.boydti.fawe.beta.implementation.lighting.RelighterFactory;
import com.boydti.fawe.bukkit.NMSRelighterFactory;
import com.boydti.fawe.bukkit.adapter.mc1_16_5.TuinityRelighterFactory_1_16_5;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.sk89q.bukkit.util.CommandInfo; import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration; import com.sk89q.bukkit.util.CommandRegistration;
@ -60,6 +63,7 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser
public final WorldEditPlugin plugin; public final WorldEditPlugin plugin;
private final CommandRegistration dynamicCommands; private final CommandRegistration dynamicCommands;
private final LazyReference<Watchdog> watchdog; private final LazyReference<Watchdog> watchdog;
private final RelighterFactory religherFactory;
private boolean hookingEvents; private boolean hookingEvents;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) { public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
@ -74,6 +78,14 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser
} }
return null; return null;
}); });
RelighterFactory tempFactory;
try {
Class.forName("com.tuinity.tuinity.config.TuinityConfig");
tempFactory = new TuinityRelighterFactory_1_16_5();
} catch (ClassNotFoundException e) {
tempFactory = new NMSRelighterFactory();
}
this.religherFactory = tempFactory;
} }
CommandRegistration getDynamicCommands() { CommandRegistration getDynamicCommands() {
@ -244,6 +256,11 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser
return SUPPORTED_SIDE_EFFECTS; return SUPPORTED_SIDE_EFFECTS;
} }
@Override
public RelighterFactory getRelighterFactory() {
return this.religherFactory;
}
public void unregisterCommands() { public void unregisterCommands() {
dynamicCommands.unregisterCommands(); dynamicCommands.unregisterCommands();
} }

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.cli; package com.sk89q.worldedit.cli;
import com.boydti.fawe.beta.implementation.lighting.NullRelighter;
import com.boydti.fawe.beta.implementation.lighting.RelighterFactory;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.AbstractPlatform; import com.sk89q.worldedit.extension.platform.AbstractPlatform;
@ -160,6 +162,11 @@ class CLIPlatform extends AbstractPlatform {
return ImmutableSet.of(); return ImmutableSet.of();
} }
@Override
public RelighterFactory getRelighterFactory() {
return (_a, _b, _c) -> NullRelighter.INSTANCE;
}
public void addWorld(World world) { public void addWorld(World world) {
worlds.add(world); worlds.add(world);
} }

Datei anzeigen

@ -2,7 +2,7 @@ package com.boydti.fawe;
import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.lighting.NMSRelighter; import com.boydti.fawe.beta.implementation.lighting.Relighter;
import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent; import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RegionWrapper;
@ -35,6 +35,7 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -45,7 +46,6 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
/** /**
* The FaweAPI class offers a few useful functions.<br> * The FaweAPI class offers a few useful functions.<br>
@ -344,24 +344,29 @@ public class FaweAPI {
} }
} }
NMSRelighter relighter = new NMSRelighter(queue, Settings.IMP.LIGHTING.DO_HEIGHTMAPS); try (Relighter relighter = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING)
for (int x = minX; x <= maxX; x++) { .getRelighterFactory()
for (int z = minZ; z <= maxZ; z++) { .createRelighter(mode, world, queue)) {
relighter.addChunk(x, z, null, 65535);
count++; 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) {
if (mode != RelightMode.NONE) { if (Settings.IMP.LIGHTING.REMOVE_FIRST) {
if (Settings.IMP.LIGHTING.REMOVE_FIRST) { relighter.removeAndRelight(true);
relighter.removeAndRelight(true); } else {
relighter.fixSkyLighting();
relighter.fixBlockLighting();
}
} else { } else {
relighter.fixSkyLighting(); relighter.removeLighting();
relighter.fixBlockLighting();
} }
} else { } catch (Exception ignored) {
relighter.removeLighting();
} }
relighter.flush();
return count; return count;
} }

Datei anzeigen

@ -823,7 +823,8 @@ public class NMSRelighter implements Relighter {
} }
} }
public synchronized void flush() { @Override
public synchronized void close() {
Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator(); Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Map.Entry<Long, Integer> entry = iter.next(); Map.Entry<Long, Integer> entry = iter.next();

Datei anzeigen

@ -58,4 +58,9 @@ public class NullRelighter implements Relighter {
public boolean isFinished() { public boolean isFinished() {
return true; return true;
} }
@Override
public void close() throws Exception {
}
} }

Datei anzeigen

@ -2,7 +2,7 @@ package com.boydti.fawe.beta.implementation.lighting;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
public interface Relighter { public interface Relighter extends AutoCloseable {
/** /**
* Add a chunk to be relit when {@link Relighter#removeLighting} etc are called. * Add a chunk to be relit when {@link Relighter#removeLighting} etc are called.

Datei anzeigen

@ -0,0 +1,12 @@
package com.boydti.fawe.beta.implementation.lighting;
import com.boydti.fawe.beta.IQueueChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.RelightMode;
import com.sk89q.worldedit.world.World;
@FunctionalInterface
public interface RelighterFactory {
Relighter createRelighter(RelightMode relightMode, World world, IQueueExtent<IQueueChunk> queue);
}

Datei anzeigen

@ -34,6 +34,7 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
@ -405,8 +406,9 @@ public class EditSessionBuilder {
} }
// There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks // There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks
if (placeChunks && ((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.IMP.LIGHTING.MODE > 0))) { if (placeChunks && ((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.IMP.LIGHTING.MODE > 0))) {
relighter = new NMSRelighter(queue, Settings.IMP.LIGHTING.DO_HEIGHTMAPS, relighter = WorldEdit.getInstance().getPlatformManager()
relightMode != null ? relightMode : RelightMode.valueOf(Settings.IMP.LIGHTING.MODE)); .queryCapability(Capability.WORLD_EDITING)
.getRelighterFactory().createRelighter(relightMode, world, queue);
extent.addProcessor(new RelightProcessor(relighter)); extent.addProcessor(new RelightProcessor(relighter));
} else { } else {
relighter = NullRelighter.INSTANCE; relighter = NullRelighter.INSTANCE;

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import com.boydti.fawe.beta.implementation.lighting.RelighterFactory;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility; import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
@ -206,4 +207,6 @@ public interface Platform extends Keyed {
* @return A set of supported side effects * @return A set of supported side effects
*/ */
Set<SideEffect> getSupportedSideEffects(); Set<SideEffect> getSupportedSideEffects();
RelighterFactory getRelighterFactory();
} }