fenomas / noa

Experimental voxel game engine.
MIT License
611 stars 87 forks source link

How to dispose the noa instance? #141

Open Trenki opened 3 years ago

Trenki commented 3 years ago

I'm using VUE build the project, the game is inside a component, and I want to destroy the noa parameters when I destroy the component, so that I can open the component again and run the game.What should I do?

fenomas commented 3 years ago

Hi, do you mean you want to dispose the noa instance, so that it releases all its memory so you can recreate it later? It doesn't have any feature like that currently, though I don't think it would be too hard to make.

On the other hand if you just want to be able to hide/show the game, I think it would be easier to have vue show/hide noa's container element, rather than destroying/recreating it. This would run faster, since destroying/recreating would mean the whole world needs to be regenerated and remeshed, etc.

Trenki commented 3 years ago

Yeah,that's what I mean.I want others to use my blockly to build games, so the game code is different every time and needs to be completely rebuilt.

If I want to dispose the noa instance, what shall I do?Looking forward to your reply,have a nice day :).

fenomas commented 3 years ago

Hi... so the real answer is that the library should have a dispose method, but it doesn't have one yet and I don't have plans to work on it soon. However I think it would be pretty straightforward if someone else wants to try. Basically it would mean disposing the babylon scene and releasing lots of internal references and removing some event listeners.

One alternate answer is, you may be able to use a single noa instance continuously, but just change the world data. You can do this with the noa.worldName (which is normally for things like changing from the overworld to the nether in minecraft). When you change noa.worldName to a different value, the engine will unload all its current chunks and issue events requesting voxel data for the new world.

However changing noa.worldName doesn't reset the registry, just the world's voxel data. If you need to start completely fresh and register different voxel types, then you'll need a proper dispose method.