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

Allow calling minetest.set_mapgen_setting after initialization #14450

Closed
wants to merge 2 commits into from

Conversation

aerkiaga
Copy link
Contributor

@aerkiaga aerkiaga commented Mar 10, 2024

This PR removes a few lines of checks that enforce calling minetest.set_mapgen_setting only during initialization. After a surface-level reading of the code and some testing, it looks like no further changes are needed to add support for this.

These changes allow mods to influence terrain generation dynamically, by passing the mapgen environment arbitrary values at any time. Among all the options considered, this is the one that requires the least changes to the code, and is fully backwards-compatible.

Edit: only custom mapgen code can make use of this, it won't affect hardcoded mapgens.

To do

This PR is Ready for Review.

How to test

Call the function during initialization and then get the values back via minetest.get_mapgen_setting.

For a more complete example, I've created a branch in the Nodeverse repo that makes use of these changes: https://github.com/aerkiaga/nodeverse/tree/parallel_mapgen.

@sfan5
Copy link
Member

sfan5 commented Mar 10, 2024

The engine mapgens do no read the settings more than once during initialization, so how does this possibly work?

@aerkiaga
Copy link
Contributor Author

Isn't the object accessed by reference when minetest.get_mapgen_setting is called from the mapgen environment? Well, intentionally or not, it does indeed work. Althought if that is the case, maybe some sort of atomic lock and a test to make sure the behavior stays this way would be warranted.

@aerkiaga
Copy link
Contributor Author

Oh, sorry @sfan5 I understand now. I didn't mean that mods could modify "regular" mapgen parameters at runtime, but simply that they could pass arbitrary data into the mapgen environment that a custom mapgen could use.

@Zughy Zughy added @ Script API @ Mapgen Feature ✨ PRs that add or enhance a feature Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand labels Mar 10, 2024
@sfan5
Copy link
Member

sfan5 commented Mar 10, 2024

but simply that they could pass arbitrary data into the mapgen environment that a custom mapgen could use.

Mapgen settings are not an IPC, please don't (mis)use them as such.

I get that mods may want to modify their own mapgen behavior at runtime, so I suggest:

  • open an issue with a feature request for passing data into the mapgen env
  • use temporary files in the world folder to realise your use case for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature @ Mapgen Possible close Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand @ Script API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants