Use an IBLockCacheNode for passing a node + private constants.

Within BlockProperties BlockCache and IBlockCacheNode ("read only") get
passed, removing id/data/shape from arguments. If a property is not set
in the node, it'll be fetched from the block cache, but the node is not
updated from outside the BlockCache. For subsequent calls, the node
would be updated by the block cache, if it isn't a node stored by the
BlockChangeTracker from an earlier time, and similar.

This way, opportunistic passable checking can be implemented, by
switching to cached nodes instead of id/data/shape arguments with lazy
fetching from BlockCache.

The name IBlockCacheNode seems to be appropriate, since we'll pass it
alongside with a BlockCache anyway.
This commit is contained in:
asofold 2016-11-23 23:51:11 +01:00
parent 85460d5cca
commit d01951a10e
2 changed files with 36 additions and 9 deletions

View File

@ -45,7 +45,7 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
import fr.neatmonster.nocheatplus.utilities.ds.map.LinkedCoordHashMap;
import fr.neatmonster.nocheatplus.utilities.ds.map.LinkedCoordHashMap.MoveOrder;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache.BlockCacheNode;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
/**
@ -151,7 +151,7 @@ public class BlockChangeTracker {
public final long id;
public final int tick, x, y, z;
public final Direction direction;
public final BlockCacheNode previousState;
public final IBlockCacheNode previousState;
/**
* A push entry.
@ -163,7 +163,7 @@ public class BlockChangeTracker {
* @param direction
*/
public BlockChangeEntry(long id, int tick, int x, int y, int z,
Direction direction, BlockCacheNode previousState) {
Direction direction, IBlockCacheNode previousState) {
this.id = id;
this.tick = tick;
this.x = x;
@ -453,7 +453,7 @@ public class BlockChangeTracker {
* If not NONE, pushing into that direction is assumed.
*/
private void addBlockChange(final long changeId, final int tick, final WorldNode worldNode,
final int x, final int y, final int z, final Direction direction, final BlockCacheNode previousState) {
final int x, final int y, final int z, final Direction direction, final IBlockCacheNode previousState) {
worldNode.lastChangeTick = tick;
final BlockChangeEntry entry = new BlockChangeEntry(changeId, tick, x, y, z, direction, previousState);
LinkedList<BlockChangeEntry> entries = worldNode.blocks.get(x, y, z, MoveOrder.END);

View File

@ -35,37 +35,64 @@ public abstract class BlockCache {
/** The Constant ID_AIR. */
private static final int ID_AIR = 0;
public static class BlockCacheNode {
/**
* Read access to a BlockCacheNode.
* @author asofold
*
*/
public static interface IBlockCacheNode {
public static final short FETCHED_ID = 0x01;
public static final short FETCHED_DATA = 0x02;
public static final short FETCHED_BOUNDS = 0x04;
public boolean isIdFetched();
public boolean isDataFetched();
public boolean isBoundsFetched();
public int getId();
public int getData();
public double[] getBounds();
}
public static class BlockCacheNode implements IBlockCacheNode {
private static final short FETCHED_ID = 0x01;
private static final short FETCHED_DATA = 0x02;
private static final short FETCHED_BOUNDS = 0x04;
private short fetched = 0;
private int id = 0;
private int data = 0;
private double[] bounds = null;
@Override
public boolean isIdFetched() {
return (fetched & FETCHED_ID) != 0;
}
@Override
public boolean isDataFetched() {
return (fetched & FETCHED_DATA) != 0;
}
@Override
public boolean isBoundsFetched() {
return (fetched & FETCHED_BOUNDS) != 0;
}
@Override
public int getId() {
return id;
}
@Override
public int getData() {
return data;
}
@Override
public double[] getBounds() {
return bounds;
}
@ -332,7 +359,7 @@ public abstract class BlockCache {
* properties set. If forceSetAll is false, null might be returned,
* if no node is present for the given coordinates.
*/
public BlockCacheNode getBlockCacheNode(int x, int y, int z, boolean forceSetAll) {
public IBlockCacheNode getBlockCacheNode(int x, int y, int z, boolean forceSetAll) {
if (forceSetAll) {
final BlockCacheNode node = getOrCreateNode(x, y, z);
if (!node.isDataFetched()) {