Add async relighting option

This commit is contained in:
Jesse Boyd 2017-03-05 02:57:59 +11:00
parent b3b86bd3df
commit c325f0745c
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 44 additions and 17 deletions

View File

@ -331,6 +331,7 @@ public class Settings extends Config {
"If packet sending should be delayed until relight is finished",
})
public boolean DELAY_PACKET_SENDING = true;
public boolean ASYNC = true;
@Comment({
"The relighting mode to use:",
" - 0 = None (Do no relighting)",

View File

@ -1,10 +1,13 @@
package com.boydti.fawe.example;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.IntegerTrio;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.ArrayDeque;
@ -220,15 +223,25 @@ public class NMSRelighter implements Relighter{
}
public synchronized void sendChunks() {
Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Integer> entry = iter.next();
long pair = entry.getKey();
int bitMask = entry.getValue();
int x = MathMan.unpairIntX(pair);
int z = MathMan.unpairIntY(pair);
queue.sendChunk(x, z, bitMask);
iter.remove();
RunnableVal<Object> runnable = new RunnableVal<Object>() {
@Override
public void run(Object value) {
Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Integer> entry = iter.next();
long pair = entry.getKey();
int bitMask = entry.getValue();
int x = MathMan.unpairIntX(pair);
int z = MathMan.unpairIntY(pair);
queue.sendChunk(x, z, bitMask);
iter.remove();
}
}
};
if (Settings.IMP.LIGHTING.ASYNC) {
runnable.run();
} else {
TaskManager.IMP.sync(runnable);
}
}

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream;
@ -955,9 +956,15 @@ public class LocalSession {
* @param item the item type ID
* @return the tool, which may be {@link null}
*/
@Deprecated
@Nullable
public Tool getTool(int item) {
return tools.get(item);
return tools.get(FaweCache.getCombined(item, 0));
}
@Nullable
public Tool getTool(int id, int data) {
return tools.get(FaweCache.getCombined(id, data));
}
@Nullable
@ -1007,19 +1014,25 @@ public class LocalSession {
* @param tool the tool to set, which can be {@code null}
* @throws InvalidToolBindException if the item can't be bound to that item
*/
@Deprecated
public void setTool(int item, @Nullable Tool tool) throws InvalidToolBindException {
setTool(item, tool, null);
}
@Deprecated
public void setTool(int item, @Nullable Tool tool, Player player) throws InvalidToolBindException {
if (item > 0 && item < 255) {
throw new InvalidToolBindException(item, "Blocks can't be used");
} else if (item == config.wandItem) {
throw new InvalidToolBindException(item, "Already used for the wand");
} else if (item == config.navigationWand) {
throw new InvalidToolBindException(item, "Already used for the navigation wand");
setTool(item, 0, tool, player);
}
public void setTool(int id, int data, @Nullable Tool tool, Player player) throws InvalidToolBindException {
if (id > 0 && id < 255) {
throw new InvalidToolBindException(id, "Blocks can't be used");
} else if (id == config.wandItem) {
throw new InvalidToolBindException(id, "Already used for the wand");
} else if (id == config.navigationWand) {
throw new InvalidToolBindException(id, "Already used for the navigation wand");
}
Tool previous = this.tools.put(item, tool);
Tool previous = this.tools.put(FaweCache.getCombined(id, data), tool);
if (player != null) {
if (previous instanceof BrushTool) {
BrushTool brushTool = (BrushTool) previous;