Fixed chunkloading system, chunks are deleted if aren't visited after a long time
This commit is contained in:
@@ -21,10 +21,10 @@ public class InputController implements Restrictions {
|
||||
i++;
|
||||
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.A)) {
|
||||
cam.zoom += 1;
|
||||
cam.zoom += 5;
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
|
||||
cam.zoom -= 1;
|
||||
cam.zoom -= 5;
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) {
|
||||
|
||||
@@ -13,6 +13,7 @@ public class Superchunks {
|
||||
private Superchunks() {}
|
||||
|
||||
public static void generateSuperchunk(int x, int y) {
|
||||
Chunks chunks;
|
||||
int startX = x * SUPER_CHUNK_SIZE;
|
||||
int startY = y * SUPER_CHUNK_SIZE;
|
||||
int endX = startX + SUPER_CHUNK_SIZE;
|
||||
@@ -20,7 +21,7 @@ public class Superchunks {
|
||||
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
Chunks chunks = new Chunks();
|
||||
chunks = new Chunks();
|
||||
BlockMaterials.create();
|
||||
chunks.generateChunk(i, j);
|
||||
overworld.put(new Pair<>(i, j), chunks);
|
||||
@@ -30,6 +31,7 @@ public class Superchunks {
|
||||
|
||||
|
||||
public static void loadChunks(Player player) {
|
||||
|
||||
int chunkY = 0;
|
||||
int chunkX = 0;
|
||||
//Top-right
|
||||
@@ -53,12 +55,15 @@ public class Superchunks {
|
||||
chunkX = ((player.getX()) / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE));
|
||||
}
|
||||
|
||||
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE; i++) {
|
||||
for (int j = -RENDER_DISTANCE; j < RENDER_DISTANCE; j++) {
|
||||
generateSuperchunk(chunkX + i, chunkY + j);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ public class WorldRenderer implements Restrictions {
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch) {
|
||||
try {
|
||||
drawWorld(batch);
|
||||
}catch (Exception e){}
|
||||
|
||||
inputController.handleInput();
|
||||
batch.setProjectionMatrix(cam.combined);
|
||||
cam.update();
|
||||
|
||||
@@ -19,9 +19,9 @@ public class Main extends ApplicationAdapter {
|
||||
private WorldRenderer worldRenderer;
|
||||
private GUI gui;
|
||||
private FitViewport fitViewport;
|
||||
public static float delta = 0;
|
||||
float physicsUpdateSpeed = 1/60f; //how often you want to do a physics-update, in this case every 1/60th of a sec
|
||||
float timeSinceLastUpdate = 0f; //accumulator
|
||||
private float chunkSeconds;
|
||||
private Player player;
|
||||
|
||||
|
||||
@@ -50,12 +50,15 @@ public class Main extends ApplicationAdapter {
|
||||
|
||||
fixedStep();
|
||||
|
||||
chunkSeconds +=Gdx.graphics.getRawDeltaTime();
|
||||
if(chunkSeconds > RENDER_TIME){
|
||||
chunkSeconds -= RENDER_TIME;
|
||||
delta +=Gdx.graphics.getDeltaTime();
|
||||
if(delta > RENDER_TIME) {
|
||||
delta -= RENDER_TIME;
|
||||
Superchunks.overworld.clear();
|
||||
Superchunks.loadChunks(player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
batch.begin();
|
||||
worldRenderer.render(batch);
|
||||
gui.render(batch);
|
||||
|
||||
@@ -9,5 +9,5 @@ public interface Restrictions {
|
||||
int CHUNK_SIZE = 16;
|
||||
int SUPER_CHUNK_SIZE = 3;
|
||||
int RENDER_DISTANCE = 3;
|
||||
int RENDER_TIME = 1;
|
||||
float RENDER_TIME = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user