Made it so that the world doesn't generate if it has already generated in the past
This commit is contained in:
@@ -9,11 +9,17 @@ import static com.mygdx.game.Restrictions.*;
|
||||
|
||||
public class Superchunks {
|
||||
public static HashMap<Pair<Integer, Integer>, Chunks> overworld = new HashMap<>();
|
||||
public static HashMap<Pair<Integer, Integer>, Chunks> loadedChunks = new HashMap<>();
|
||||
|
||||
private Superchunks() {}
|
||||
|
||||
public static void create(){
|
||||
BlockMaterials.create();
|
||||
}
|
||||
|
||||
public static void generateSuperchunk(int x, int y) {
|
||||
Chunks chunks;
|
||||
Chunks chunks = null;
|
||||
Pair<Integer, Integer> pair = null;
|
||||
int startX = x * SUPER_CHUNK_SIZE;
|
||||
int startY = y * SUPER_CHUNK_SIZE;
|
||||
int endX = startX + SUPER_CHUNK_SIZE;
|
||||
@@ -21,12 +27,18 @@ public class Superchunks {
|
||||
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
chunks = new Chunks();
|
||||
BlockMaterials.create();
|
||||
chunks.generateChunk(i, j);
|
||||
overworld.put(new Pair<>(i, j), chunks);
|
||||
pair = new Pair<>(i, j);
|
||||
if(overworld.containsKey(pair)){
|
||||
chunks = overworld.get(pair);
|
||||
}
|
||||
else{
|
||||
chunks = new Chunks();
|
||||
chunks.generateChunk(i, j);
|
||||
}
|
||||
loadedChunks.put(pair,chunks);
|
||||
}
|
||||
}
|
||||
overworld.putAll(loadedChunks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ public class WorldRenderer implements Restrictions {
|
||||
}
|
||||
|
||||
public void drawWorld(Batch batch) {
|
||||
for (Pair<Integer, Integer> worldpair: Superchunks.overworld.keySet()) {
|
||||
Chunks chunks = Superchunks.overworld.get(worldpair);
|
||||
for (Pair<Integer, Integer> worldpair: Superchunks.loadedChunks.keySet()) {
|
||||
Chunks chunks = Superchunks.loadedChunks.get(worldpair);
|
||||
for (Pair<Integer,Integer> chunkpair: chunks.blocks.keySet()) {
|
||||
|
||||
HashMap<Pair<Integer, Integer>, Block> blocks = chunks.getBlocks();
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Main extends ApplicationAdapter {
|
||||
Gdx.graphics.setWindowedMode(1024,576);
|
||||
OrthographicCamera cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
|
||||
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
|
||||
Superchunks.create();
|
||||
|
||||
//Starting location of the player
|
||||
player = new Player(0, 0, cam);
|
||||
@@ -53,7 +54,7 @@ public class Main extends ApplicationAdapter {
|
||||
delta +=Gdx.graphics.getDeltaTime();
|
||||
if(delta > RENDER_TIME) {
|
||||
delta -= RENDER_TIME;
|
||||
Superchunks.overworld.clear();
|
||||
Superchunks.loadedChunks.clear();
|
||||
Superchunks.loadChunks(player);
|
||||
}
|
||||
|
||||
@@ -78,5 +79,6 @@ public class Main extends ApplicationAdapter {
|
||||
worldRenderer.dispose();
|
||||
gui.dispose();
|
||||
batch.dispose();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ public interface Restrictions {
|
||||
int KEY_DELAY = 1;
|
||||
int CHUNK_SIZE = 16;
|
||||
int SUPER_CHUNK_SIZE = 3;
|
||||
int RENDER_DISTANCE = 3;
|
||||
float RENDER_TIME = 1;
|
||||
int RENDER_DISTANCE = 2;
|
||||
float RENDER_TIME = 4f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user