Patch to limit cave generation in mgv7

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

Patch to limit cave generation in mgv7

by sorcerykid » Sat Dec 17, 2016 06:05

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 20 times
 

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

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

Re: Patch to limit cave generation in mgv7

by sorcerykid » Wed Jan 04, 2017 17:59

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 15 times
 

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

Re: Patch to limit cave generation in mgv7

by Wuzzy » Sun Nov 12, 2017 22:59

Why don't you go directly to GitHub to this? It is hard to find for the developers otherwise.
I'm creating MineClone 2, a Minecraft clone for Minetest. I made the Help modpack, adding in-game help to Minetest.
 

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

Re: Patch to limit cave generation in mgv7

by sorcerykid » Wed Nov 15, 2017 00:07

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.
 


Return to Partly official engine development



Who is online

Users browsing this forum: No registered users and 1 guest