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

Best way to control chunk loading? #115

Closed
Heath123 opened this issue Jun 19, 2020 · 9 comments
Closed

Best way to control chunk loading? #115

Heath123 opened this issue Jun 19, 2020 · 9 comments

Comments

@Heath123
Copy link
Contributor

What's the best way to control chunk loading manually rather than having noa request and auto-unload chunks? At the moment I mess with noa's array to force it to request the chunk like this:

if (!mineweb._noa.world._chunkIDsToRequest[`${packet.z}|${y}|${packet.x}`]) {
  mineweb._noa.world._chunkIDsToRequest.push(`${packet.z}|${y}|${packet.x}`);
}

I can't actually tell whether that works or not, though.
I'm trying to unload chunks like this, but it doesn't seem to work:

if (noa.world._chunkIDsKnown[`${packet.chunkZ}|${y}|${packet.chunkZ}`]) {
  noa.world._chunkIDsToRemove.push(`${packet.chunkZ}|${y}|${packet.chunkX}`);
}

Is there a better way? Should I let noa handle it? Should I fork noa and add it?
Thank you

@fenomas
Copy link
Owner

fenomas commented Jun 21, 2020

What is the goal to be accomplished? The process of chunk loading is pretty complex, since there are several asynchronous steps involved, and a lot of edge cases (e.g. a chunk moves out of draw range after it's initialized but before it's finished meshing, etc.). So directly messing around with the chunk queues is really likely to cause bugs, or to break with future versions.

It would make more sense to have the engine expose a hook where you can change what you want to change. Are you wanting to change the order in which chunks are requested, or the size/shape of the area within which chunks get drawn, or what are you trying to do?

@Heath123
Copy link
Contributor Author

I'm trying to make a Minecraft client, and usually the server controls chunk loading in the vanilla game, so I'm trying to replicate that.

@fenomas
Copy link
Owner

fenomas commented Jun 22, 2020

Gotcha, right. Hmm. Can you imagine what kind of API would let you do this right?

E.g.:

// boolean - when true, the engine doesn't check for chunks to load/unload
noa.world.manuallyControlChunkLoading

noa.world.manuallyLoadChunk(x, y, z)  // arguments are world coords within the chunk
noa.world.manuallyUnloadChunk(x, y, z)  // arguments are world coords within the chunk

Or something? To minimize impact, these should probably work within the current queueing system - so when you called manuallyLoad it would add that chunk to the load queue, and then asynchronously later you'd get the worldDataNeeded event for it, and so on. Also note that the manual load/unload methods would throw an error if the boolan flag isn't true - otherwise the automatic system would immediately unload anything you manually loaded, etc.

Does that make sense or can you think of a better API for this?

@Heath123
Copy link
Contributor Author

Yes, something like that would be perfect, thank you. I do need to load chunks immediately but I can store data until it's needed.

@fenomas
Copy link
Owner

fenomas commented Jul 2, 2020

Hi, I have pushed these to #develop, as described above. They function correctly for me, but can you check and confirm whether they cover your use case?

One note: if you test manually loading and unloading single chunks, you may see strange behavior due to the edge cases in how the engine meshes the edges of a chunk whose neighbor doesn't exist yet. But in an actual project where most of the chunks around the player are being requested, any weirdness should only be visible on the edges of distant chunks.

@Heath123
Copy link
Contributor Author

Heath123 commented Jul 2, 2020

Yay, thank you! I'll try that soon.

@Heath123 Heath123 closed this as completed Jul 2, 2020
@Heath123
Copy link
Contributor Author

Heath123 commented Jul 2, 2020

Sorry, not sure if I should reopen this, make a new issue or work it out for myself, but I'm using

noa.world.manuallyControlChunkLoading(x, y, z)

when I get a chunk form the server and multiplying the chunk co-ordinates by 16 (otherwise it doesn't work), and that makes noa very slowly start to load chunks in the the outside in, and stops at the last image.
Screenshot from 2020-07-02 13-18-48
Screenshot from 2020-07-02 13-20-30
Screenshot from 2020-07-02 13-20-54
Do you know why that might be happening? Thank you

@Heath123 Heath123 reopened this Jul 2, 2020
@fenomas
Copy link
Owner

fenomas commented Jul 2, 2020

Hmm, I'm not sure. First thought is to change the order you're requesting things - maybe something is funky with the order being different from usual. Note that the x,y,z coords are world coords, so loading (0,0,0) is the same as loading (10, 10, 10) - just specify any coordinate within the chunk you need.

Other note is, keep in mind that the engine freezes most stuff if the player's current chunk isn't loaded, so if you're not able to move around then that's why.

Other ideas... if the chunks aren't loading at all, I'm not sure, but it might be that they're getting loaded but not meshed, or not meshed in a way you can see. To check, you could try changing voxels in a chunk that should be loaded, since changing a voxel would trigger a remesh, which might fix things and give a clue what's wrong...

@fenomas
Copy link
Owner

fenomas commented Jun 2, 2021

Closing as this is likely no longer current, but please reopen if needed.

@fenomas fenomas closed this as completed Jun 2, 2021
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