Patch to limit cave generation in mgv7

For people working on the C++ code.
Post Reply
User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Patch to limit cave generation in mgv7

by sorcerykid » Post

I reworked the v7 cave generator for Minetest 0.4.13, including the addition of the following mapgen parameters:
  • mgv7_spflags = [nocaverns|caverns], [notunnels|tunnels]
    Flags specifying which v7 cave generator to use; requires that "caves" be enabled in mg_flags
  • caves_bedrock_level = [value]
    Integer specifying the lower boundary for generated tunnels (does not apply to caverns)
  • caves_surface_level = [value]
    Integer specifying the upper boundary for generated tunnels (does not apply to caverns)
I was able to cull quite a bit of redundant and extraneous code from from CaveV7::makeCave( ). I opted to limit the range based upon just the route area (ar), rather than the more obfuscated water_level calculations.

Code: Select all

	// Limit route along y-axis to height of area
	route_y_min = 0;
	route_y_max = ar.Y - 1;

	// Randomize starting position relative to area
	orp = v3f(
		(float)(ps->next() % ar.X) + 0.5,
		(float)(ps->range(route_y_min, route_y_max)) + 0.5,
		(float)(ps->next() % ar.Z) + 0.5
	);
I also fixed the start-point and end-point boundary checks in "CaveV7::makeTunnel( )". The radius (rs) was being added to the absolute position (p), even though the height-map comparison is only applicable along the Y-axis.

Code: Select all

	p = of + orpi + veci;
	if (p.Z >= node_min.Z && p.Z <= node_max.Z &&
			p.X >= node_min.X && p.X <= node_max.X) {
		u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X);
		s16 h = mg->ridge_heightmap[index];
		if (p.Y + rs / 2 > h)
			return; // Ignore section not in our heightmap
	}
	if (p.Y + rs / 2 > surface_level || p.Y - rs / 2 < bedrock_level) {
		return; // Ignore section above surface level or below bedrock level
	}

I tested these changes extensively with a variety of mapgen parameters, and all works as expected. I was also careful to use an unassigned slot in mgv7_spflags, accounting for addition of "floatlands" in 0.4.14.

All of the patched files are in the attachment, with comments delineating the specific changes. I hope it is useful!
Attachments
minetest-cavegen-patch.zip
(19.65 KiB) Downloaded 82 times

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: Patch to limit cave generation in mgv7

by ExeterDad » Post

Nice!
I guess you won't be irked by that any more :P

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Patch to limit cave generation in mgv7

by sorcerykid » Post

My cavegen patch for Minetest 0.4.14 is now available. Bear in mind, I renamed the mapgen parameters for consistency with the official conventions (they are mgv7-specific) and to coincide with the addition of mgv7_cave_width:
  • mgv7_spflags = [nocaverns|caverns], [notunnels|tunnels]
    Flags specifying which v7 cave generator to use; requires that "caves" be enabled in mg_flags
  • mgv7_cave_depth_min = [value]
    Integer specifying the lower boundary for generated tunnels (formerly caves_bedrock_level)
  • mgv7_cave_depth_max = [value]
    Integer specifying the upper boundary for generated tunnels (formerly caves_surface_level)
Simply copy the files from the attached archive into your "minetest-0.4.14/src" directory. Then recompile for the changes to take effect. Enjoy your new customized caves!
Attachments
minetest0414-cavegen-patch.zip
(15.89 KiB) Downloaded 72 times

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: Patch to limit cave generation in mgv7

by Wuzzy » Post

Why don't you go directly to GitHub to this? It is hard to find for the developers otherwise.

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Patch to limit cave generation in mgv7

by sorcerykid » Post

Wuzzy wrote:Why don't you go directly to GitHub to this? It is hard to find for the developers otherwise.
It's just a patch, not a pull request. I made it available for users that compile their own binaries as a drop-in replacement.

On the next update, I'll at least see about placing it into a git repo.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests