Skip to content

Commit

Permalink
Maintain a validity interval (ticks) of an entry in an efficient way.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Nov 26, 2016
1 parent ea9c5a1 commit c26c3cb
Showing 1 changed file with 14 additions and 2 deletions.
Expand Up @@ -154,6 +154,11 @@ public static class BlockChangeEntry {
public final int tick, x, y, z;
public final Direction direction;
public final IBlockCacheNode previousState;
/**
* The tick value of the next entry, allowing to determine an interval
* of validity for this state.
*/
public int nextEntryTick = -1;

/**
* A block change entry.
Expand Down Expand Up @@ -552,8 +557,15 @@ private void addBlockChange(final long changeId, final int tick, final WorldNode
}
else {
// Lazy expiration check for this block.
if (!entries.isEmpty() && entries.getFirst().tick < tick - expirationAgeTicks) {
worldNode.size -= expireEntries(tick - expirationAgeTicks, entries);
if (!entries.isEmpty()) {
if (entries.getFirst().tick < tick - expirationAgeTicks) {
worldNode.size -= expireEntries(tick - expirationAgeTicks, entries);
}
// Re-check in case of invalidation.
if (!entries.isEmpty()) {
// Update the nextEntryTick for the last entry in the list.
entries.getLast().nextEntryTick = tick;
}
}
}
// With tracking actual block states/shapes, an entry for the previous state must be present (update last time or replace last or create first).
Expand Down

0 comments on commit c26c3cb

Please sign in to comment.