FIGURED OUT HOW TO UNLOAD CHUNKS \o/
This commit is contained in:
@@ -16,5 +16,4 @@ public class Block {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,20 @@ public class Chunks {
|
||||
public static HashMap<Pair<Integer, Integer>, Block> blocks = new HashMap<>();
|
||||
private long seed = SEED;
|
||||
|
||||
public void ungenerateChunk(int x, int y) {
|
||||
int startX = x << CHUNK_SHIFT;
|
||||
int startY = y << CHUNK_SHIFT;
|
||||
int endX = startX + CHUNK_SIZE;
|
||||
int endY = startY + CHUNK_SIZE;
|
||||
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.remove(new Pair<>(i, j), getTerrain(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateChunk(int x, int y){
|
||||
int startX = x << CHUNK_SHIFT;
|
||||
int startY = y << CHUNK_SHIFT;
|
||||
@@ -119,5 +133,4 @@ public class Chunks {
|
||||
if (moisture < 0.66) return "TropicalSeasonalForest";
|
||||
return "TropicalRainForest";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public static void ungenerateWorld(int x, int y) {
|
||||
Chunks chunks = new Chunks();
|
||||
if (!chunks.isEmpty(x, y)) {
|
||||
chunks.ungenerateChunk(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadChunks() {
|
||||
for (int i = -(RENDER_DISTANCE); i < RENDER_DISTANCE; i++) {
|
||||
for (int j = -(RENDER_DISTANCE); j < RENDER_DISTANCE; j++) {
|
||||
@@ -22,5 +29,37 @@ public class World {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void unloadChunks() {
|
||||
//Down
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE+1; i++) {
|
||||
ungenerateWorld(
|
||||
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+i,
|
||||
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+3
|
||||
);
|
||||
}
|
||||
//Up
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE+1; i++) {
|
||||
ungenerateWorld(
|
||||
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+i,
|
||||
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))-4
|
||||
);
|
||||
}
|
||||
//Right
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE+1; i++) {
|
||||
ungenerateWorld(
|
||||
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)-4,
|
||||
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+i
|
||||
);
|
||||
}
|
||||
//Left
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE+1; i++) {
|
||||
ungenerateWorld(
|
||||
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+3,
|
||||
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+i
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class Main extends ApplicationAdapter {
|
||||
if(delta > RENDER_TIME) {
|
||||
delta -= RENDER_TIME;
|
||||
World.loadChunks();
|
||||
World.unloadChunks();
|
||||
}
|
||||
|
||||
gui.render(batch);
|
||||
|
||||
Reference in New Issue
Block a user