lazy chunk loading

This commit is contained in:
Leijurv 2018-08-21 11:54:55 -07:00
parent 7f578bc3bf
commit a64e07685b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 1 additions and 20 deletions

View File

@ -53,7 +53,7 @@ public final class CachedWorld implements ICachedChunkAccess {
@Override
public final PathingBlockType getBlockType(int x, int y, int z) {
CachedRegion region = getRegion(x >> 9, z >> 9);
CachedRegion region = getOrCreateRegion(x >> 9, z >> 9);
if (region != null) {
return region.getBlockType(x & 511, y, z & 511);
}

View File

@ -31,8 +31,6 @@ import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Brady
@ -42,8 +40,6 @@ public enum CachedWorldProvider implements Helper {
INSTANCE;
private static final Pattern REGION_REGEX = Pattern.compile("r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.bcr");
private final Map<String, CachedWorld> singlePlayerWorldCache = new HashMap<>();
private CachedWorld currentWorld;
@ -68,21 +64,6 @@ public enum CachedWorldProvider implements Helper {
}
this.currentWorld = this.singlePlayerWorldCache.computeIfAbsent(dir.toString(), CachedWorld::new);
try {
Files.list(dir).forEach(path -> {
String file = path.getFileName().toString();
Matcher matcher = REGION_REGEX.matcher(file);
if (matcher.matches()) {
int rx = Integer.parseInt(matcher.group(1));
int ry = Integer.parseInt(matcher.group(2));
// Recognize the region for when we load from file
this.currentWorld.getOrCreateRegion(rx, ry);
}
});
} catch (Exception ignored) {}
this.currentWorld.load();
}
// TODO: Store server worlds
}