Skip to content

Commit

Permalink
Use an IBLockCacheNode for passing a node + private constants.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
asofold committed Nov 23, 2016
1 parent 85460d5 commit d01951a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Expand Up @@ -45,7 +45,7 @@
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;

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ public static class BlockChangeEntry {
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.
Expand All @@ -163,7 +163,7 @@ public static class BlockChangeEntry {
* @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;
Expand Down Expand Up @@ -453,7 +453,7 @@ private void addPistonBlock(final long changeId, final int tick, final WorldNode
* 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);
Expand Down
Expand Up @@ -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 boolean isIdFetched();

public boolean isDataFetched();

public boolean isBoundsFetched();

public int getId();

public int getData();

public double[] getBounds();

}

public static class BlockCacheNode implements IBlockCacheNode {

public static final short FETCHED_ID = 0x01;
public static final short FETCHED_DATA = 0x02;
public static final short FETCHED_BOUNDS = 0x04;
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;
}
Expand Down Expand Up @@ -332,7 +359,7 @@ public double[] getBounds(final int x, final int y, final int z) {
* 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()) {
Expand Down

0 comments on commit d01951a

Please sign in to comment.