-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add minetest.generate_biomes #11953
Add minetest.generate_biomes #11953
Conversation
…oise' If generate_ores/decorations is called after generate_biomes, the biome map is taken into account.
I think minetest.calc_biome_noise has no use alone.
- Auto-detect water level - Make noise_filler_depth optional - Check size of chunk and noise buffer, and throw an error if it does not match
…porary one Update documentation (and fix mistake)
and calculate max bounds from provided VoxelManip instead
src/mapgen/mapgen.cpp
Outdated
|
||
c_stone = ndef_p->getId("mapgen_stone"); | ||
c_water_source = ndef_p->getId("mapgen_water_source"); | ||
c_river_water_source = ndef_p->getId("mapgen_river_water_source"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the other class members? Those will contain uninitialized data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will, but I'm only setting what is actually used by generateBiomes
(it uses a temporary object).
I set some other class members from l_generate_biomes()
but I need this function for the protected ones.
I can make ModApiMapgen
a friend class of MapgenBasic
, leave the constructor empty and initialize all class members in l_generate_biomes
if that's better.
EDIT: Doing that right now, it's clearly better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the code changes yet but in general it is better to refactor the code so that such workarounds are not even necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it better with the new commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not yet; continued in another comment)
and group class member assignments in l_generate_biomes also minor codestyle simplification
I've measured biome generation time of this new function against my Lua re-implementation, Test code: lvm_example/timer, and enable/disable With the Lua mod:
With
|
|
||
const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); | ||
|
||
MapgenBasic mg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why couldn't you use mg_current
for this? MapgenBasic() = default;
does not initialize trivial data types which can quickly result in unpredictable/erroneous code.
How about this instead?
MapgenBasic *mg = dynamic_cast<MapgenBasic *>(mg_current);
FATAL_ERROR_IF(!mg, "Bug! This mapgen does not inherit from MapgenBasic.");
.. and make If that does not work, you could still specify MapgenSinglenode
inherit MapgenBasic
like all other mapgens.virtual
functions in Mapgen
which the inherited classes would overwrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought redefining MapgenSinglenode
was out of question, not sure why I was thinking that, maybe paramat was against it a year or so ago. I tried to stay consistent with what was done for l_generate_ores
and l_generate_decorations
but I see why it does not make sense to create a temporary object for biomes: it is a strictly mapgen-time method, that ores and decorations are not.
Will try that. MapgenV6
should also inherit MapgenBasic
in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing existing mapgens to inherit from a class they have no business with just for this does sounds like a bad idea to me.
Where are we with this? With Lua mapgen being slow (and essentially disabling multi threaded generation due to the env lock) any speed improvement is very welcome! |
@Gael-de-Sailly are you gonna apply the requested changes? |
What exactly does the |
@Rick-W-Storm it means that, even if it's not in the roadmap, some core devs will review it and possibly merge it |
Rebased. I have in some way rediscovered this PR today (lol), I can start working again on this and I hope this can be reopened. The current version is working but I did not make any change since last commit, except fixups to follow recent changes in minetest. |
What it does
Implements #8329. Add function
minetest.generate_biomes(vm, pos1, pos2[, noise_filler_depth])
to generate biome nodes in theVoxelManip
from Lua mapgen mods.Also updates
heatmap
,humiditymap
andbiomemap
, so that they can be reused byminetest.generate_decorations
,minetest.generate_ores
andminetest.get_mapgen_object
.My approach creates a temporary
MapgenBasic
object and callsMapgenBasic::generateBiomes()
. The class definition is modified to allow such a usecase.minetest.generate_biomes
must be called during mapgen (register_on_generated
callback), and the X/Z extent ofpos1
-pos2
must match mapgen chunk size, for the buffers to work correctly. I have not found a way to overcome these limitations that would not lead to a much more complex code.Why is it interesting/needed?
To do
I consider this PR as Ready for Review.
I initially planned to include a function to generate dust nodes but this may come in a separate PR, this one is already interesting in itself.
How to test
I have made a modified version of Paramat's
lvm_example
for testing. It generates very simple terrain, with biomes, ores and decorations. You can append other biome mods like Ethereal to see how it reacts.^ This PR + lvm_example + Ethereal NG