Fixes #51
Fixes #49
This commit is contained in:
Jesse Boyd 2016-04-25 04:54:32 +10:00
parent 0da4f6f63a
commit 912ea44cc8
5 changed files with 64 additions and 9 deletions

View File

@ -458,9 +458,7 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet {
try { try {
NamedTag nt = stream.readNamedTag(); NamedTag nt = stream.readNamedTag();
return nt != null ? ((CompoundTag) nt.getTag()) : null; return nt != null ? ((CompoundTag) nt.getTag()) : null;
} catch (IOException e) { } catch (IOException ignore) {}
e.printStackTrace();
}
} }
return null; return null;
} }

View File

@ -1,4 +1,54 @@
package com.boydti.fawe.object.clipboard; package com.boydti.fawe.object.clipboard;
public class DiskOptimizedClipboard { import com.boydti.fawe.object.IntegerTrio;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/**
* // TODO
* A clipboard with disk backed storage. (lower memory + loads on crash)
* - Uses an auto closable RandomAccessFile for getting / setting id / data
* - I don't know how to reduce nbt / entities to O(1) complexity, so it is stored in memory.
*/
public class DiskOptimizedClipboard extends FaweClipboard {
private final HashMap<IntegerTrio, CompoundTag> nbtMap;
private final HashSet<ClipboardEntity> entities;
public DiskOptimizedClipboard(int width, int height, int length) {
super(width, height, length);
nbtMap = new HashMap<>();
entities = new HashSet<ClipboardEntity>();
}
@Override
public BaseBlock getBlock(int x, int y, int z) {
throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP");
}
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) {
throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP");
}
@Override
public Entity createEntity(Extent world, double x, double y, double z, float yaw, float pitch, BaseEntity entity) {
throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP");
}
@Override
public List<? extends Entity> getEntities() {
throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP");
}
@Override
public boolean remove(ClipboardEntity clipboardEntity) {
throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP");
}
} }

View File

@ -61,8 +61,15 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
public boolean setBlock(int x, int y, int z, BaseBlock block) { public boolean setBlock(int x, int y, int z, BaseBlock block) {
final int id = block.getId(); final int id = block.getId();
switch (id) { switch (id) {
case 0: case 0: {
int i = x + z * width + (y >> 4) * area;
byte[] idArray = ids[i];
if (idArray != null) {
int y2 = y & 0xF;
idArray[y2] = 0;
}
return true; return true;
}
case 54: case 54:
case 130: case 130:
case 142: case 142:

View File

@ -605,8 +605,10 @@ public class EditSession implements Extent {
return FaweCache.CACHE_BLOCK[combinedId4Data]; return FaweCache.CACHE_BLOCK[combinedId4Data];
} }
try { try {
return this.world.getLazyBlock(new Vector(x, y, z)); BaseBlock block = this.world.getBlock(new Vector(x, y, z));
return block;
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
return FaweCache.CACHE_BLOCK[combinedId4Data]; return FaweCache.CACHE_BLOCK[combinedId4Data];
} }
} }
@ -1464,7 +1466,7 @@ public class EditSession implements Extent {
EditSession.this.flushQueue(); EditSession.this.flushQueue();
} }
}, true); }, true);
return this.changes = visitor.getAffected(); return this.changes = copy.getAffected();
} }
/** /**

View File

@ -78,8 +78,6 @@ public class BlockArrayClipboard implements Clipboard {
this.mx = origin.getBlockX(); this.mx = origin.getBlockX();
this.my = origin.getBlockY(); this.my = origin.getBlockY();
this.mz = origin.getBlockZ(); this.mz = origin.getBlockZ();
} }
@Override @Override