fix bugs with intervalmaps
parent
cc68d3b434
commit
b9e55f717b
|
@ -14,22 +14,22 @@ public class IntervalMap <V>{
|
|||
if(start >= end) return;
|
||||
|
||||
// take the last key before end
|
||||
Map.Entry<Integer,V> upper_bound = treemap.lowerEntry(end); //'higherEntry' makes sure that there's no equal case, otherwise the node could be removed as soon as it is inserted
|
||||
Map.Entry<Integer,V> end_prev_entry = treemap.lowerEntry(end); //'higherEntry' makes sure that there's no equal case, otherwise the node could be removed as soon as it is inserted
|
||||
|
||||
Map.Entry<Integer, V> upper_entry = treemap.higherEntry(end);
|
||||
Map.Entry<Integer, V> lower_entry = treemap.lowerEntry(start);
|
||||
Map.Entry<Integer, V> end_next_entry = treemap.higherEntry(end);
|
||||
Map.Entry<Integer, V> start_entry = treemap.lowerEntry(start);
|
||||
|
||||
// insert the start key. Replaces whatever value is already there. Do not place if the lowerEntry is of the same value
|
||||
if(lower_entry == null || ( lower_entry.getValue() != null && !lower_entry.getValue().equals(value))) treemap.put(start, value);
|
||||
if(start_entry == null || ( start_entry.getValue() != null && !start_entry.getValue().equals(value))) treemap.put(start, value);
|
||||
|
||||
if(upper_entry == null){
|
||||
if(upper_bound != null ) treemap.put(end+1, upper_bound.getKey() > start ? upper_bound.getValue():null);
|
||||
else treemap.put(end+1, null);
|
||||
if(end_next_entry == null){
|
||||
if(end_prev_entry != null ) treemap.put(end, end_prev_entry.getKey() > start ? end_prev_entry.getValue():null);
|
||||
else treemap.put(end, null);
|
||||
}else{
|
||||
if(upper_entry.getValue() != null && !upper_entry.getValue().equals(value) && upper_entry.getKey() > end + 1) treemap.put(end+1, upper_bound.getValue());
|
||||
else treemap.put(end+1, upper_bound.getValue());
|
||||
if(end_next_entry.getValue() != null && end_next_entry.getKey() > end) treemap.put(end, end_prev_entry.getValue());
|
||||
else treemap.put(end, end_prev_entry.getValue());
|
||||
}
|
||||
for(Integer k : treemap.subMap(start, lower_entry != null && value == lower_entry.getValue(), end, true).keySet()){
|
||||
for(Integer k : treemap.subMap(start, false, end, false).keySet()){
|
||||
treemap.remove(k);
|
||||
}
|
||||
}
|
||||
|
@ -63,9 +63,7 @@ public class IntervalMap <V>{
|
|||
public void print() {
|
||||
System.out.println("-------");
|
||||
for (Integer k : treemap.keySet()) {
|
||||
if (oldK != null) {
|
||||
System.out.println("[" + oldK + ", " + k + ") --> " + oldValue);
|
||||
}
|
||||
if(oldK != null) System.out.println("[" + oldK + ", " + k + ") --> " + oldValue);
|
||||
oldK = k;
|
||||
oldValue = treemap.get(k);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ public class Chunk {
|
|||
chunkNode.setLocalTranslation(posx, posy, posz);
|
||||
chunkNode.setLocalTranslation(chunkNode.getLocalTranslation().mult(Config.CHUNK_SIZE).mult(Config.VOXEL_SIZE));
|
||||
|
||||
blocks.insert(0, Config.CHUNK_3DCOORD_MAX_INDEX, Blocks.AIR);
|
||||
setBlocks(Blocks.AIR, 0, Config.CHUNK_3DCOORD_MAX_INDEX + 1);
|
||||
setState(CHUNK_STATE_EMPTY, true);
|
||||
}
|
||||
|
||||
public void setState(byte nstate, boolean value){
|
||||
|
@ -56,7 +57,8 @@ public class Chunk {
|
|||
* Set blocks. Interval to be intended in the same way as in interval maps
|
||||
*/
|
||||
public void setBlocks(Blocks block, int intLow, int intHigh) {
|
||||
this.blocks.insert( Math.max(0,intLow), Math.min(Config.CHUNK_3DCOORD_MAX_INDEX+1, intHigh),block);
|
||||
if(intHigh > intLow)
|
||||
this.blocks.insert( Math.max(0,intLow), Math.min(Config.CHUNK_3DCOORD_MAX_INDEX+1, intHigh),block);
|
||||
}
|
||||
|
||||
public Blocks getBlock(int x, int y, int z) {
|
||||
|
@ -96,7 +98,7 @@ public class Chunk {
|
|||
prev = array[i];
|
||||
}
|
||||
|
||||
this.setBlocks(prev, start, array.length-1);
|
||||
this.setBlocks(prev, start, array.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue