[Mod][Library] Biome generator for Lua mapgens [biomegen]

Post Reply
User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

[Mod][Library] Biome generator for Lua mapgens [biomegen]

by Gael de Sailly » Post

Hello,

This mod aims at re-implementing core biome system (biomes, decorations and dust) for Lua mapgens. It is a library (it does not do anything standalone), providing functions intended to be used in Lua mapgen mods, at the end of mapgen loop.

It reads biomes and decorations registered by minetest.register_biome and minetest.register_decoration, so it is natively compatible with minetest_game and all mods/games using these functions to add content.

It applies to mapgens that generate only stone, water, river water and air, and requires to add biomegen as a dependency (mandatory or optional) of the mapgen mod.

Image
^ biomegen used by a Lua mapgen, under vanilla Minetest Game

The main function is biomegen.generate_all(data, area, vm, minp, maxp, seed), to be added after mapgen loop, but before writing vm to map. It generates biomes, decorations, ores and dust (for now using core function for ores). Other function do these steps separately, check Readme for more details.

Example:

Code: Select all

local data = {}

minetest.register_on_generated(function(minp, maxp, seed)
	local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
	local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
	vm:get_data(data)

	------------------------
	-- [MAPGEN LOOP HERE] --
	------------------------

	-- Generate biomes, decorations, ores and dust
	biomegen.generate_all(data, area, vm, minp, maxp, seed)

	-- Calculate lighting for what has been created.
	vm:calc_lighting()
	-- Write what has been created to the world.
	vm:write_to_map()
	-- Liquid nodes were placed so set them flowing.
	vm:update_liquids()
end)
Example mod to see it in action: lvm_example-biomegen (modified version of Paramat's lvm_example). The screenshot comes from it.

Dependencies: None!

License: GNU LGPL Version 3

Download zip / Browse the code
Last edited by Gael de Sailly on Wed Jun 23, 2021 20:50, edited 1 time in total.
Just realize how bored we would be if the world was perfect.

snowyu
Member
Posts: 25
Joined: Mon Jun 07, 2021 06:42
GitHub: snowyu

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by snowyu » Post

The Biome can not work with https://gitlab.com/gaelysam/mapgen_rive ... ainlib_lua branch.

decorations.lua#91

Code: Select all

local function cid(name)
    local result
    pcall(function() --< try
      result = minetest.get_content_id(name)
    end)
    return result
end
  ...
            local v = cid(name)
            if v then ilist[v] = true end
  ...
  else
    local v = cid(node)
    if v then ilist[v] = true end
end

User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Gael de Sailly » Post

Thank you for your feedback, will test the fix, it should do the trick. For code cleanliness I'd have preferred to avoid pcall and functions inside functions, but I don't think there is a better way to do.
There are some other issues that need to be fixed, like some decorations appearing more often at chunk borders (which I can really not explain for now).

I moved the links from Github to Gitlab (because I forgot to do it when moving my code last year).
To move it for your local git repo: git remote set-url origin https://gitlab.com/gaelysam/biomegen.git
Just realize how bored we would be if the world was perfect.

User avatar
Eris
Member
Posts: 175
Joined: Thu Nov 19, 2020 23:12
IRC: definitelya Ovalo
In-game: Eris_still_crafts

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Eris » Post

I have a problem where my RAM gets maxed out in as little as 1-2 minutes, starting right after the world boot. I tested a world with only mapgen_rivers in and found the problem is mainly with biomegen, it seems.
Ofc, me having only 4 gigs could be a factor. ;)

Congrats on this awesome mod, I use it with mapgen_rivers and the worlds look gorgeous!
I may consider upgrading my RAM if this resource hunger is the intended behavior, It's SO good.
Jump in the caac

User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Gael de Sailly » Post

Eris wrote:
Sat Jul 10, 2021 10:39
I have a problem where my RAM gets maxed out in as little as 1-2 minutes, starting right after the world boot. I tested a world with only mapgen_rivers in and found the problem is mainly with biomegen, it seems.
For now I don't really see what could eat up your RAM at this point, I'm a bit surprised. It is a quite heavy mod, like most of mapgen-related mods, but it is supposed to reuse large table objects and not accumulate any data, which should prevent memory leaks. I may have to check if this works as intended.
mapgen_rivers has some piece of code that may accumulate cached data, but the amount should remain very reasonable unless you have a ridiculously large map or low value for blocksize. This is also to be checked.
Eris wrote:
Sat Jul 10, 2021 10:39
Ofc, me having only 4 gigs could be a factor. ;)
[...]
I may consider upgrading my RAM if this resource hunger is the intended behavior
I did most of my tests on a 1.8 GB laptop and, even if it tends to go a bit on the swap, it runs generally fine, so I would expect it to be OK on a 4 GB computer. If it's not, there is probably something unexpected with the code, unless your OS is really heavy.

Well, I still have a bunch of things to check/fix on biomegen, that will have to be done before I "officially" release mapgen_rivers (as they are linked), but I haven't found the time to do it, yet.
Eris wrote:
Sat Jul 10, 2021 10:39
Congrats on this awesome mod, I use it with mapgen_rivers and the worlds look gorgeous!
Thanks, you're giving me just enough motivation to fix up the last things and finally do the long-awaited release ;)
Just realize how bored we would be if the world was perfect.

User avatar
Eris
Member
Posts: 175
Joined: Thu Nov 19, 2020 23:12
IRC: definitelya Ovalo
In-game: Eris_still_crafts

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Eris » Post

Gael de Sailly wrote:
Sat Jul 10, 2021 13:02
...mapgen_rivers has some piece of code that may accumulate cached data, but the amount should remain very reasonable unless you have a ridiculously large map or low value for blocksize. This is also to be checked.
Aha, of course it was just that... I put a higher value in the python generation script, yep.
Gael de Sailly wrote:
Sat Jul 10, 2021 13:02
I did most of my tests on a 1.8 GB laptop and, even if it tends to go a bit on the swap, it runs generally fine, so I would expect it to be OK on a 4 GB computer. If it's not, there is probably something unexpected with the code, unless your OS is really heavy.

Well, I still have a bunch of things to check/fix on biomegen, that will have to be done before I "officially" release mapgen_rivers (as they are linked), but I haven't found the time to do it, yet.
Nah, I'm on Lubuntu, so it's light. Using latest dev release.

It works pretty well everytime I make a new world, don't stress yourself ahah.
Gael de Sailly wrote:
Sat Jul 10, 2021 13:02
Thanks, you're giving me just enough motivation to fix up the last things and finally do the long-awaited release ;)
Sorry it was a simple error I made, but I'm glad I got you inspired to work on this and mapgen_rivers.
Happy coding!
Jump in the caac

User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Gael de Sailly » Post

Updated. Latest git version now supports biomemap and other mapgen objects (heatmap, humitidymap, gennotify).
This improves compatibility with other mods, for example Everness.

Image
^ mapgen_rivers + biomegen + everness
Just realize how bored we would be if the world was perfect.

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: [Mod][Library] Biome generator for Lua mapgens [biomegen]

by Sokomine » Post

Glad to hear! The other mapgen objects could really be useful in some cases. If that spreads to more mapgens, mods based on mapgen could use this information.
A list of my mods can be found here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 21 guests