mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 11:10:44 +00:00
unload chunks, progress on #127
This commit is contained in:
parent
d1c1c9d77f
commit
fb5450e3ca
1 changed files with 17 additions and 0 deletions
|
|
@ -68,6 +68,18 @@ module.exports.player=function(player,serv) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
player.unloadChunk = (chunkX,chunkZ) =>
|
||||||
|
{
|
||||||
|
delete player.loadedChunks[chunkX+","+chunkZ];
|
||||||
|
player._client.write('map_chunk', {
|
||||||
|
x: chunkX,
|
||||||
|
z: chunkZ,
|
||||||
|
groundUp: true,
|
||||||
|
bitMap: 0x0000,
|
||||||
|
chunkData: new Buffer(0)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
player.sendChunk = (chunkX,chunkZ,column) =>
|
player.sendChunk = (chunkX,chunkZ,column) =>
|
||||||
{
|
{
|
||||||
return player.behavior('sendChunk', {
|
return player.behavior('sendChunk', {
|
||||||
|
|
@ -101,6 +113,11 @@ module.exports.player=function(player,serv) {
|
||||||
var playerChunkX=Math.floor(player.position.x/16/32);
|
var playerChunkX=Math.floor(player.position.x/16/32);
|
||||||
var playerChunkZ=Math.floor(player.position.z/16/32);
|
var playerChunkZ=Math.floor(player.position.z/16/32);
|
||||||
|
|
||||||
|
Object.keys(player.loadedChunks)
|
||||||
|
.map((key) => key.split(","))
|
||||||
|
.filter(([x,z]) => Math.abs(x-playerChunkX)>view || Math.abs(z-playerChunkZ)>view)
|
||||||
|
.forEach(([x,z]) => player.unloadChunk(x,z));
|
||||||
|
|
||||||
return spiral([view*2,view*2])
|
return spiral([view*2,view*2])
|
||||||
.map(t => ({
|
.map(t => ({
|
||||||
chunkX:playerChunkX+t[0]-view,
|
chunkX:playerChunkX+t[0]-view,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue