Patch to limit cave generation in mgv7

User avatar
sorcerykid
Member
 
Posts: 219
Joined: Fri Aug 26, 2016 15:36
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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 43 times
 

User avatar
ExeterDad
Member
 
Posts: 1121
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad

Re: Patch to limit cave generation in mgv7

by ExeterDad » Sat Dec 17, 2016 11:49

Nice!
I guess you won't be irked by that any more :P
٩(̾●̮̮̃̾•̃̾)۶

Kibbie and I have a beautiful public server now! HOMETOWN
 

User avatar
sorcerykid
Member
 
Posts: 219
Joined: Fri Aug 26, 2016 15:36
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 38 times
 


Return to Minetest Engine

Who is online

Users browsing this forum: No registered users and 1 guest

cron