Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunks disapear #99

Open
CapsE opened this issue Apr 23, 2014 · 2 comments
Open

Chunks disapear #99

CapsE opened this issue Apr 23, 2014 · 2 comments

Comments

@CapsE
Copy link

CapsE commented Apr 23, 2014

I wrote some code for a free camera movement without a player. The voxel-engine code states that if there is no player voxel.js will take the position of the camera to find chunks that are far away and remove them.
So far everything is working fine BUT the chunks won't load when the camera gets close to them again. I tried to force voxel.js to show them but that won't work too.
cp = game.camera.position.toArray();
var chunkX = Math.floor(cp[0]/32);
var chunkY = Math.floor(cp[1]/32);
var chunkZ = Math.floor(cp[2]/32);

console.debug("Update Map around: " + [chunkX, chunkY, chunkZ].toString());

game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY , chunkZ - 1]));
game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ -1]));
game.showChunk(game.getChunkAtPosition([chunkX + 1, chunkY, chunkZ + 1]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ - 1]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ]));
game.showChunk(game.getChunkAtPosition([chunkX -1, chunkY, chunkZ + 1]));
game.showChunk(game.getChunkAtPosition([chunkX, chunkY, chunkZ + 1]));

I used game.setBlock([msg["x"],1 ,msg["y"]], c) to create the blocks. Is this the right way or will it just display the blocks until the chunk is hidden the first time?

@deathcap
Copy link
Collaborator

By default voxel-engine has no persistence layer; setBlock() only modifies the voxel in a loaded chunk but once chunks are unloaded they are not saved anywhere. You can handle this by persisting the chunks to network/disk/memory as they unload, or just regenerate them again. Try using the missingChunk event on game.voxels, and the game.showChunk() method; this example might be helpful: https://github.com/deathcap/voxel-land

@CapsE
Copy link
Author

CapsE commented Jun 20, 2014

Thanks for the feedback. That explains alot :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants