3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-17 00:20:09 +01:00

History: Read change positions at once (#2542)

Dieser Commit ist enthalten in:
Hannes Greule 2024-01-25 09:31:45 +01:00 committet von dordsor21
Ursprung b4635e85c9
Commit 0e88bb438b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
4 geänderte Dateien mit 50 neuen und 69 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,16 @@
package com.fastasyncworldedit.core.history.change;
import com.sk89q.worldedit.history.change.Change;
import org.jetbrains.annotations.ApiStatus;
/**
* Represents a change that is associated with {@code (x, y, z)} block coordinates.
* @since TODO
*/
@ApiStatus.Internal
public sealed abstract class BlockPositionChange implements Change
permits MutableBlockChange, MutableFullBlockChange {
public int x;
public int y;
public int z;
}

Datei anzeigen

@ -2,17 +2,13 @@ package com.fastasyncworldedit.core.history.change;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import org.jetbrains.annotations.ApiStatus;
public class MutableBlockChange implements Change { @ApiStatus.Internal
public final class MutableBlockChange extends BlockPositionChange {
public int z;
public int y;
public int x;
public int ordinal; public int ordinal;
public MutableBlockChange(int x, int y, int z, int ordinal) { public MutableBlockChange(int x, int y, int z, int ordinal) {
this.x = x; this.x = x;
this.y = y; this.y = y;

Datei anzeigen

@ -4,15 +4,12 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException; import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.jetbrains.annotations.ApiStatus;
public class MutableFullBlockChange implements Change { @ApiStatus.Internal
public final class MutableFullBlockChange extends BlockPositionChange {
public int z;
public int y;
public int x;
public int from; public int from;
public int to; public int to;
public BlockBag blockBag; public BlockBag blockBag;

Datei anzeigen

@ -7,6 +7,7 @@ import com.fastasyncworldedit.core.history.change.MutableBlockChange;
import com.fastasyncworldedit.core.history.change.MutableEntityChange; import com.fastasyncworldedit.core.history.change.MutableEntityChange;
import com.fastasyncworldedit.core.history.change.MutableFullBlockChange; import com.fastasyncworldedit.core.history.change.MutableFullBlockChange;
import com.fastasyncworldedit.core.history.change.MutableTileChange; import com.fastasyncworldedit.core.history.change.MutableTileChange;
import com.fastasyncworldedit.core.history.change.BlockPositionChange;
import com.fastasyncworldedit.core.internal.exception.FaweSmallEditUnsupportedException; import com.fastasyncworldedit.core.internal.exception.FaweSmallEditUnsupportedException;
import com.fastasyncworldedit.core.internal.io.FaweInputStream; import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream; import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
@ -22,6 +23,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -30,7 +32,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -42,6 +43,7 @@ import java.util.function.BiConsumer;
/** /**
* FAWE stream ChangeSet offering support for extended-height worlds * FAWE stream ChangeSet offering support for extended-height worlds
*/ */
@ApiStatus.Internal
public abstract class FaweStreamChangeSet extends AbstractChangeSet { public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public static final int HEADER_SIZE = 9; public static final int HEADER_SIZE = 9;
@ -85,19 +87,15 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
} }
} }
public interface FaweStreamPositionDelegate { interface FaweStreamPositionDelegate {
void write(OutputStream out, int x, int y, int z) throws IOException; void write(OutputStream out, int x, int y, int z) throws IOException;
int readX(FaweInputStream in) throws IOException; void read(FaweInputStream in, BlockPositionChange change) throws IOException;
int readY(FaweInputStream in) throws IOException;
int readZ(FaweInputStream in) throws IOException;
} }
public interface FaweStreamIdDelegate { interface FaweStreamIdDelegate {
void writeChange(FaweOutputStream out, int from, int to) throws IOException; void writeChange(FaweOutputStream out, int from, int to) throws IOException;
@ -155,6 +153,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
} }
if (mode == 1 || mode == 4) { // small if (mode == 1 || mode == 4) { // small
posDel = new FaweStreamPositionDelegate() { posDel = new FaweStreamPositionDelegate() {
final byte[] buffer = new byte[4];
int lx; int lx;
int ly; int ly;
int lz; int lz;
@ -179,23 +178,14 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
out.write(b4); out.write(b4);
} }
final byte[] buffer = new byte[4];
@Override @Override
public int readX(FaweInputStream in) throws IOException { public void read(final FaweInputStream in, final BlockPositionChange change) throws IOException {
in.readFully(buffer); in.readFully(buffer);
return lx = lx + ((((buffer[1] & 0xFF) | ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20); change.x = lx = lx + ((((buffer[1] & 0xFF) | ((MathMan.unpair16x(buffer[3])) << 8)) << 20) >> 20);
change.y = (ly = ly + buffer[0]) & 0xFF;
change.z = lz = lz + ((((buffer[2] & 0xFF) | ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20);
} }
@Override
public int readY(FaweInputStream in) {
return (ly = ly + buffer[0]) & 0xFF;
}
@Override
public int readZ(FaweInputStream in) throws IOException {
return lz = lz + ((((buffer[2] & 0xFF) | ((MathMan.unpair16y(buffer[3])) << 8)) << 20) >> 20);
}
}; };
} else { } else {
posDel = new FaweStreamPositionDelegate() { posDel = new FaweStreamPositionDelegate() {
@ -232,25 +222,11 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
} }
@Override @Override
public int readX(FaweInputStream is) throws IOException { public void read(final FaweInputStream in, final BlockPositionChange change) throws IOException {
is.readFully(buffer); in.readFully(buffer);
// Don't break reading version 1 history (just in case) change.x = lx = lx + ((buffer[0] & 0xFF) | (buffer[1] << 8));
if (version == 2 && Arrays.equals(buffer, MAGIC_NEW_RELATIVE)) { change.z = lz = lz + ((buffer[2] & 0xFF) | (buffer[3]) << 8);
lx = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read()); change.y = ly = ly + ((buffer[4] & 0xFF) | (buffer[5]) << 8);
lz = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
is.readFully(buffer);
}
return lx = lx + ((buffer[0] & 0xFF) | (buffer[1] << 8));
}
@Override
public int readY(FaweInputStream is) throws IOException {
return ly = ly + ((buffer[4] & 0xFF) | (buffer[5]) << 8);
}
@Override
public int readZ(FaweInputStream is) throws IOException {
return lz = lz + ((buffer[2] & 0xFF) | (buffer[3]) << 8);
} }
}; };
} }
@ -453,9 +429,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public MutableBlockChange read() { public MutableBlockChange read() {
try { try {
change.x = posDel.readX(is) + originX; posDel.read(is, change);
change.y = posDel.readY(is); change.x += originX;
change.z = posDel.readZ(is) + originZ; change.z += originZ;
idDel.readCombined(is, change, dir); idDel.readCombined(is, change, dir);
return change; return change;
} catch (EOFException ignored) { } catch (EOFException ignored) {
@ -570,9 +546,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
public MutableFullBlockChange read() { public MutableFullBlockChange read() {
try { try {
change.x = posDel.readX(is) + originX; posDel.read(is, change);
change.y = posDel.readY(is); change.x += originX;
change.z = posDel.readZ(is) + originZ; change.z += originZ;
idDel.readCombined(is, change); idDel.readCombined(is, change);
return change; return change;
} catch (EOFException ignored) { } catch (EOFException ignored) {
@ -872,10 +848,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
@Override @Override
public @Nullable MutableFullBlockChange populate(@NotNull final MutableFullBlockChange change) { public @Nullable MutableFullBlockChange populate(@NotNull final MutableFullBlockChange change) {
try { try {
change.x = posDel.readX(is) + originX;
change.y = posDel.readY(is);
change.z = posDel.readZ(is) + originZ;
idDel.readCombined(is, change); idDel.readCombined(is, change);
change.x += originX;
change.z += originZ;
return change; return change;
} catch (EOFException ignored) { } catch (EOFException ignored) {
} catch (Exception e) { } catch (Exception e) {
@ -914,10 +889,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
@Override @Override
public @Nullable MutableBlockChange populate(@NotNull final MutableBlockChange change) { public @Nullable MutableBlockChange populate(@NotNull final MutableBlockChange change) {
try { try {
change.x = posDel.readX(is) + originX;
change.y = posDel.readY(is);
change.z = posDel.readZ(is) + originZ;
idDel.readCombined(is, change, dir); idDel.readCombined(is, change, dir);
change.x += originX;
change.z += originZ;
return change; return change;
} catch (EOFException ignored) { } catch (EOFException ignored) {
} catch (Exception e) { } catch (Exception e) {
@ -1068,11 +1042,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
int amount = (Settings.settings().HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9; int amount = (Settings.settings().HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9;
MutableFullBlockChange change = new MutableFullBlockChange(null, 0, false); MutableFullBlockChange change = new MutableFullBlockChange(null, 0, false);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
int x = posDel.readX(fis) + ox; posDel.read(fis, change);
int y = posDel.readY(fis);
int z = posDel.readZ(fis) + ox;
idDel.readCombined(fis, change); idDel.readCombined(fis, change);
summary.add(x, z, change.to); summary.add(change.x + ox, change.z + oz, change.to);
} }
} }
} catch (EOFException ignored) { } catch (EOFException ignored) {