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 class Superchunks {
|
||||||
public static HashMap<Pair<Integer, Integer>, Chunks> overworld = new HashMap<>();
|
public static HashMap<Pair<Integer, Integer>, Chunks> overworld = new HashMap<>();
|
||||||
|
public static HashMap<Pair<Integer, Integer>, Chunks> loadedChunks = new HashMap<>();
|
||||||
|
|
||||||
private Superchunks() {}
|
private Superchunks() {}
|
||||||
|
|
||||||
|
public static void create(){
|
||||||
|
BlockMaterials.create();
|
||||||
|
}
|
||||||
|
|
||||||
public static void generateSuperchunk(int x, int y) {
|
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 startX = x * SUPER_CHUNK_SIZE;
|
||||||
int startY = y * SUPER_CHUNK_SIZE;
|
int startY = y * SUPER_CHUNK_SIZE;
|
||||||
int endX = startX + 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 i = startX; i != endX; i++) {
|
||||||
for (int j = startY; j != endY; j++) {
|
for (int j = startY; j != endY; j++) {
|
||||||
chunks = new Chunks();
|
pair = new Pair<>(i, j);
|
||||||
BlockMaterials.create();
|
if(overworld.containsKey(pair)){
|
||||||
chunks.generateChunk(i, j);
|
chunks = overworld.get(pair);
|
||||||
overworld.put(new Pair<>(i, j), chunks);
|
}
|
||||||
|
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) {
|
public void drawWorld(Batch batch) {
|
||||||
for (Pair<Integer, Integer> worldpair: Superchunks.overworld.keySet()) {
|
for (Pair<Integer, Integer> worldpair: Superchunks.loadedChunks.keySet()) {
|
||||||
Chunks chunks = Superchunks.overworld.get(worldpair);
|
Chunks chunks = Superchunks.loadedChunks.get(worldpair);
|
||||||
for (Pair<Integer,Integer> chunkpair: chunks.blocks.keySet()) {
|
for (Pair<Integer,Integer> chunkpair: chunks.blocks.keySet()) {
|
||||||
|
|
||||||
HashMap<Pair<Integer, Integer>, Block> blocks = chunks.getBlocks();
|
HashMap<Pair<Integer, Integer>, Block> blocks = chunks.getBlocks();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class Main extends ApplicationAdapter {
|
|||||||
Gdx.graphics.setWindowedMode(1024,576);
|
Gdx.graphics.setWindowedMode(1024,576);
|
||||||
OrthographicCamera cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
|
OrthographicCamera cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
|
||||||
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
|
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
|
||||||
|
Superchunks.create();
|
||||||
|
|
||||||
//Starting location of the player
|
//Starting location of the player
|
||||||
player = new Player(0, 0, cam);
|
player = new Player(0, 0, cam);
|
||||||
@@ -53,7 +54,7 @@ public class Main extends ApplicationAdapter {
|
|||||||
delta +=Gdx.graphics.getDeltaTime();
|
delta +=Gdx.graphics.getDeltaTime();
|
||||||
if(delta > RENDER_TIME) {
|
if(delta > RENDER_TIME) {
|
||||||
delta -= RENDER_TIME;
|
delta -= RENDER_TIME;
|
||||||
Superchunks.overworld.clear();
|
Superchunks.loadedChunks.clear();
|
||||||
Superchunks.loadChunks(player);
|
Superchunks.loadChunks(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,5 +79,6 @@ public class Main extends ApplicationAdapter {
|
|||||||
worldRenderer.dispose();
|
worldRenderer.dispose();
|
||||||
gui.dispose();
|
gui.dispose();
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ public interface Restrictions {
|
|||||||
int KEY_DELAY = 1;
|
int KEY_DELAY = 1;
|
||||||
int CHUNK_SIZE = 16;
|
int CHUNK_SIZE = 16;
|
||||||
int SUPER_CHUNK_SIZE = 3;
|
int SUPER_CHUNK_SIZE = 3;
|
||||||
int RENDER_DISTANCE = 3;
|
int RENDER_DISTANCE = 2;
|
||||||
float RENDER_TIME = 1;
|
float RENDER_TIME = 4f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user